From 8cace3f05003c6cb4d38c36890055f03151c2ad4 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Fri, 16 Oct 2026 02:39:56 +0800 Subject: Remove old code Signed-off-by: Richard Qin --- .clang-format | 35 - .clang-tidy | 23 - Build.mk | 57 - COPYING | 338 ++ LICENSE | 338 -- Makefile | 609 -- README.md | 105 - arch/riscv/Build.mk | 19 - arch/riscv/config.cc | 276 - arch/riscv/defconfig | 39 - arch/riscv/include/arch/config.h | 106 - arch/riscv/include/arch/context.h | 33 - arch/riscv/include/arch/cpu.h | 95 - arch/riscv/include/arch/extable.h | 55 - arch/riscv/include/arch/fpstate.h | 94 - arch/riscv/include/arch/mmu.h | 78 - arch/riscv/include/arch/pmap.h | 49 - arch/riscv/include/arch/random.h | 27 - arch/riscv/include/arch/sbi.h | 111 - arch/riscv/include/arch/tlb.h | 19 - arch/riscv/include/arch/trap.h | 94 - arch/riscv/include/arch/trapframe.h | 140 - arch/riscv/include/asm/csr.h | 37 - arch/riscv/include/asm/page.h | 62 - arch/riscv/include/asm/pgtable.h | 55 - arch/riscv/include/asm/sections.h | 50 - arch/riscv/kernel/asm-offsets.c | 29 - arch/riscv/kernel/head.S | 317 -- arch/riscv/kernel/lumeos.lds.S | 120 - arch/riscv/kernel/signal.cc | 163 - arch/riscv/lib/random.cc | 21 - arch/riscv/mm/init.cc | 241 - arch/riscv/mm/pmap.cc | 361 -- arch/riscv/mm/tlb_md.cc | 17 - arch/riscv/syscall/syscall_md.cc | 42 - arch/riscv/trap/extable.cc | 92 - arch/riscv/trap/fpu.S | 103 - arch/riscv/trap/swtch.S | 96 - arch/riscv/trap/trap_md.cc | 241 - arch/riscv/trap/trap_vector.S | 283 - arch/riscv/uaccess/uaccess_memcpy.S | 117 - docs/debug/debug_slab.md | 94 - docs/debug/debug_slab_1.png | Bin 90366 -> 0 bytes docs/dev/dev_device.md | 23 - docs/dev/dev_memory.md | 37 - docs/specs/00_conventions.md | 368 -- docs/specs/arch_abstraction.md | 223 - docs/specs/atomics.md | 80 - docs/specs/cpp_runtime.md | 55 - docs/specs/fdt.md | 191 - docs/specs/global_init.md | 208 - docs/specs/linker_and_entry.md | 208 - docs/specs/pmm.md | 209 - docs/specs/slab.md | 233 - docs/specs/spinlock.md | 204 - docs/specs/testing_and_ci.md | 83 - docs/specs/vmm.md | 158 - drivers/Build.mk | 17 - drivers/base/bus.cc | 32 - drivers/base/core.cc | 156 - drivers/base/driver.cc | 72 - drivers/base/platform.cc | 248 - drivers/console.cc | 119 - drivers/plic.cc | 259 - drivers/tty/n_tty.cc | 539 -- drivers/tty/tty_core.cc | 536 -- drivers/tty/tty_uart.cc | 251 - drivers/uart.cc | 181 - fdt/Build.mk | 4 - fdt/device_node.cc | 166 - fdt/fdt.cc | 625 --- fs/Build.mk | 8 - fs/chardev.cc | 43 - fs/dcache.cc | 287 - fs/devfs.cc | 137 - fs/fd.cc | 216 - fs/file_table.cc | 164 - fs/fs_struct.cc | 90 - fs/initramfs.cc | 285 - fs/inode.cc | 166 - fs/namei.cc | 250 - fs/pipe.cc | 278 - fs/ramfs/file.cc | 216 - fs/ramfs/inode.cc | 164 - fs/ramfs/super.cc | 154 - fs/super.cc | 95 - fs/vfs_init.cc | 78 - include/libc-shim/bits/alltypes.h | 15 - include/libc-shim/endian.h | 9 - include/libc-shim/features.h | 12 - include/libc-shim/limits.h | 17 - include/libc-shim/stdint.h | 21 - include/libc-shim/string.h | 110 - include/libc-shim/strings.h | 40 - include/lume/addr.h | 91 - include/lume/addr_types.h | 29 - include/lume/args.h | 28 - include/lume/atomic.h | 76 - include/lume/bitops.h | 120 - include/lume/chardev.h | 45 - include/lume/clone.h | 34 - include/lume/compiler.h | 54 - include/lume/config.h | 100 - include/lume/console.h | 77 - include/lume/container_of.h | 17 - include/lume/dcache.h | 143 - include/lume/device.h | 75 - include/lume/device_node.h | 64 - include/lume/driver.h | 24 - include/lume/elf.h | 150 - include/lume/errno.h | 186 - include/lume/fdt.h | 85 - include/lume/fdt_prop.h | 24 - include/lume/fdtable.h | 49 - include/lume/features.h | 40 - include/lume/file.h | 132 - include/lume/fs.h | 310 -- include/lume/fs_struct.h | 39 - include/lume/fs_types.h | 197 - include/lume/init.h | 33 - include/lume/irq.h | 84 - include/lume/kbuild.h | 40 - include/lume/kernel_map.h | 55 - include/lume/klog.h | 200 - include/lume/kobject.h | 57 - include/lume/kprintf.h | 39 - include/lume/kref.h | 46 - include/lume/libfdt.h | 8 - include/lume/libfdt_env.h | 78 - include/lume/limits.h | 48 - include/lume/list.h | 346 -- include/lume/lumeos.lds.h | 193 - include/lume/memblock.h | 53 - include/lume/mm_layout.h | 73 - include/lume/mman.h | 21 - include/lume/mount.h | 52 - include/lume/mutex.h | 63 - include/lume/namei.h | 32 - include/lume/new.h | 18 - include/lume/page.h | 151 - include/lume/page_cache.h | 82 - include/lume/pgrp.h | 125 - include/lume/pgtable_types.h | 69 - include/lume/pid.h | 29 - include/lume/pipe.h | 52 - include/lume/platform_device.h | 64 - include/lume/pmm.h | 108 - include/lume/poll.h | 68 - include/lume/ptrace.h | 76 - include/lume/random.h | 38 - include/lume/rbtree.h | 207 - include/lume/rbtree_augmented.h | 252 - include/lume/rbtree_types.h | 28 - include/lume/sched.h | 102 - include/lume/sched_class.h | 35 - include/lume/selftest.h | 65 - include/lume/setup.h | 42 - include/lume/signal.h | 60 - include/lume/signal_nr.h | 54 - include/lume/signal_types.h | 263 - include/lume/slab.h | 28 - include/lume/smp.h | 74 - include/lume/stdarg.h | 11 - include/lume/stringify.h | 14 - include/lume/syscall.h | 38 - include/lume/syscall_nr.h | 82 - include/lume/task.h | 144 - include/lume/timer.h | 43 - include/lume/tlb.h | 48 - include/lume/trap.h | 109 - include/lume/tty.h | 165 - include/lume/tty_ioctl.h | 202 - include/lume/types.h | 78 - include/lume/uaccess.h | 27 - include/lume/uuid.h | 207 - include/lume/vmm.h | 115 - include/lume/wait.h | 31 - include/lume/waitqueue.h | 79 - include/zircon/LICENSE | 24 - include/zircon/README.lume | 11 - include/zircon/assert.h | 246 - include/zircon/compiler.h | 380 -- kernel/Build.mk | 11 - kernel/exec.cc | 659 --- kernel/irq.cc | 106 - kernel/main.cc | 474 -- kernel/pgrp.cc | 148 - kernel/pid.cc | 63 - kernel/poll.cc | 250 - kernel/ptrace.cc | 92 - kernel/sched_class_o1.cc | 81 - kernel/sched_core.cc | 571 -- kernel/sched_internal.h | 115 - kernel/signal.cc | 442 -- kernel/smp.cc | 112 - kernel/sync/cpu_state.h | 35 - kernel/sync/mutex.cc | 156 - kernel/sync/spinlock.cc | 120 - kernel/sync/spinlock.h | 61 - kernel/sys_fs.cc | 679 --- kernel/sys_info.cc | 49 - kernel/sys_misc.cc | 360 -- kernel/sys_mm.cc | 178 - kernel/sys_process.cc | 185 - kernel/sys_signal.cc | 351 -- kernel/syscall.cc | 208 - kernel/task.cc | 780 --- kernel/timer.cc | 118 - kernel/trap.cc | 258 - kernel/uaccess.cc | 53 - kernel/waitqueue.cc | 144 - lib/Build.mk | 49 - lib/cxx_abi.cc | 37 - lib/fdt.c | 2 - lib/fdt_addresses.c | 2 - lib/fdt_empty_tree.c | 2 - lib/fdt_ro.c | 2 - lib/fdt_rw.c | 2 - lib/fdt_strerror.c | 2 - lib/fdt_sw.c | 2 - lib/fdt_wip.c | 2 - lib/klog.cc | 574 -- lib/kobject.cc | 82 - lib/kprintf.cc | 91 - lib/ktl/LICENSE | 21 - lib/ktl/README.lume | 8 - lib/ktl/README.md | 36 - lib/ktl/include-after/errno.h | 13 - lib/ktl/include-after/wchar.h | 30 - lib/ktl/include/__chrono/system_clock.h | 15 - lib/ktl/include/__config | 53 - lib/ktl/include/__config_site | 81 - lib/ktl/include/__configuration/platform.h | 23 - lib/ktl/include/__external_threading | 35 - lib/ktl/include/climits | 15 - lib/ktl/include/cmath | 53 - lib/ktl/include/cstdint | 18 - lib/ktl/include/cstdio | 21 - lib/ktl/include/cstdlib | 30 - lib/ktl/include/cwchar | 62 - lib/ktl/include/ktl/algorithm.h | 116 - lib/ktl/include/ktl/array.h | 19 - lib/ktl/include/ktl/atomic.h | 40 - lib/ktl/include/ktl/bit.h | 30 - lib/ktl/include/ktl/byte.h | 18 - lib/ktl/include/ktl/concepts.h | 46 - lib/ktl/include/ktl/declval.h | 18 - lib/ktl/include/ktl/enforce.h | 37 - lib/ktl/include/ktl/forward.h | 18 - lib/ktl/include/ktl/functional.h | 19 - lib/ktl/include/ktl/initializer_list.h | 18 - lib/ktl/include/ktl/inplace_vector.h | 18 - lib/ktl/include/ktl/iterator.h | 38 - lib/ktl/include/ktl/limits.h | 18 - lib/ktl/include/ktl/memory.h | 41 - lib/ktl/include/ktl/new.h | 25 - lib/ktl/include/ktl/numeric.h | 20 - lib/ktl/include/ktl/optional.h | 23 - lib/ktl/include/ktl/ranges.h | 25 - lib/ktl/include/ktl/ref.h | 19 - lib/ktl/include/ktl/source_location.h | 18 - lib/ktl/include/ktl/span.h | 26 - lib/ktl/include/ktl/string_view.h | 22 - lib/ktl/include/ktl/tuple.h | 30 - lib/ktl/include/ktl/type_traits.h | 165 - lib/ktl/include/ktl/unique_ptr.h | 37 - lib/ktl/include/ktl/utility.h | 41 - lib/ktl/include/ktl/variant.h | 31 - lib/ktl/include/limits | 110 - lib/ktl/include/time.h | 39 - lib/ktl/include/version | 14 - lib/ktl/include/wchar.h | 23 - lib/ktl/popcount.cc | 135 - lib/ktl/stub-new.cc | 25 - lib/libc/LICENSE | 21 - lib/libc/README.lume | 10 - lib/libc/include-after/ctype.h | 33 - lib/libc/include-after/limits.h | 7 - lib/libc/include/assert.h | 20 - lib/libc/include/inttypes.h | 117 - lib/libc/include/multi-file.h | 50 - lib/libc/include/stdint.h | 278 - lib/libc/include/stdio.h | 102 - lib/libc/include/stdlib.h | 36 - lib/libc/include/string-file.h | 79 - lib/libc/include/string.h | 97 - lib/printf.c | 914 --- lib/printf.h | 129 - lib/random.cc | 152 - lib/rbtree.cc | 596 -- lib/string/COPYRIGHT | 193 - lib/string/aarch64/memcpy.S | 186 - lib/string/aarch64/memset.S | 115 - lib/string/arm/__aeabi_memcpy.s | 45 - lib/string/arm/__aeabi_memset.s | 31 - lib/string/arm/memcpy.S | 479 -- lib/string/bcmp.c | 11 - lib/string/bcopy.c | 11 - lib/string/bzero.c | 11 - lib/string/explicit_bzero.c | 11 - lib/string/i386/memcpy.s | 32 - lib/string/i386/memmove.s | 22 - lib/string/i386/memset.s | 76 - lib/string/index.c | 11 - lib/string/memccpy.c | 37 - lib/string/memchr.c | 30 - lib/string/memcmp.c | 11 - lib/string/memcpy.c | 127 - lib/string/memmem.c | 152 - lib/string/memmove.c | 45 - lib/string/mempcpy.c | 10 - lib/string/memrchr.c | 14 - lib/string/memset.c | 93 - lib/string/rindex.c | 11 - lib/string/stpcpy.c | 32 - lib/string/stpncpy.c | 35 - lib/string/strcat.c | 10 - lib/string/strchr.c | 10 - lib/string/strchrnul.c | 31 - lib/string/strcmp.c | 10 - lib/string/strcpy.c | 10 - lib/string/strcspn.c | 20 - lib/string/strlcat.c | 12 - lib/string/strlcpy.c | 37 - lib/string/strlen.c | 25 - lib/string/strncat.c | 13 - lib/string/strncmp.c | 12 - lib/string/strncpy.c | 10 - lib/string/strnlen.c | 10 - lib/string/strpbrk.c | 10 - lib/string/strrchr.c | 9 - lib/string/strsep.c | 16 - lib/string/strspn.c | 23 - lib/string/strstr.c | 157 - lib/string/strtok.c | 16 - lib/string/strtok_r.c | 15 - lib/string/x86_64/memcpy.s | 25 - lib/string/x86_64/memmove.s | 16 - lib/string/x86_64/memset.s | 72 - mm/Build.mk | 6 - mm/memblock.cc | 257 - mm/page_cache.cc | 252 - mm/pmm.cc | 528 -- mm/slab.cc | 321 -- mm/slab.h | 83 - mm/tlb.cc | 90 - mm/vma.cc | 640 --- mm/vmm.cc | 235 - scripts/Kbuild.include | 159 - scripts/Kconfig.mk | 205 - scripts/build/Build.mk | 10 - scripts/build/archive.sh | 10 - scripts/build/check-kernel-elf.sh | 47 - scripts/build/environments/host.mk | 8 - scripts/build/environments/kernel.mk | 28 - scripts/build/environments/phys.mk | 12 - scripts/build/generate-asm-offsets.sh | 25 - scripts/build/generate-autoconf.sh | 29 - scripts/build/generate-initramfs.sh | 12 - scripts/build/link-kernel.sh | 10 - scripts/build/probe-toolchain.sh | 72 - scripts/build/probes/libc_headers.c | 10 - scripts/build/probes/libc_headers.cc | 12 - scripts/build/probes/libcxx.cc | 16 - scripts/build/run-if-changed.sh | 45 - scripts/build/targets.mk | 81 - scripts/build/tests/host_library.cc | 8 - scripts/build/tests/host_test.cc | 7 - scripts/build/tests/phys_library.cc | 5 - scripts/build/toolchain.mk | 130 - scripts/build/write-compdb.py | 26 - scripts/dtc/libfdt/fdt.c | 347 -- scripts/dtc/libfdt/fdt.h | 66 - scripts/dtc/libfdt/fdt_addresses.c | 101 - scripts/dtc/libfdt/fdt_empty_tree.c | 38 - scripts/dtc/libfdt/fdt_overlay.c | 1101 ---- scripts/dtc/libfdt/fdt_ro.c | 888 --- scripts/dtc/libfdt/fdt_rw.c | 512 -- scripts/dtc/libfdt/fdt_strerror.c | 60 - scripts/dtc/libfdt/fdt_sw.c | 384 -- scripts/dtc/libfdt/fdt_wip.c | 94 - scripts/dtc/libfdt/libfdt.h | 2540 --------- scripts/dtc/libfdt/libfdt_env.h | 69 - scripts/dtc/libfdt/libfdt_internal.h | 202 - scripts/extract-asm-offsets.sed | 18 - scripts/gen_initramfs.sh | 250 - test/Build.mk | 12 - test/selftest.cc | 83 - test/test_atomic.cc | 102 - test/test_dcache.cc | 232 - test/test_driver_model.cc | 214 - test/test_exec.cc | 447 -- test/test_fdt.cc | 50 - test/test_klog.cc | 175 - test/test_mutex.cc | 183 - test/test_namei.cc | 173 - test/test_page_cache.cc | 180 - test/test_pid.cc | 106 - test/test_pipe_devfs.cc | 420 -- test/test_pmm.cc | 283 - test/test_random.cc | 49 - test/test_rbtree.cc | 119 - test/test_sched.cc | 257 - test/test_signal.cc | 193 - test/test_slab.cc | 255 - test/test_smp.cc | 136 - test/test_spinlock.cc | 135 - test/test_sys_fs_extra.cc | 238 - test/test_sys_mm.cc | 178 - test/test_sys_process.cc | 93 - test/test_trap.cc | 197 - test/test_uaccess.cc | 97 - test/test_vfs_io.cc | 345 -- test/test_vma.cc | 282 - test/test_vmm.cc | 58 - test/test_waitqueue.cc | 91 - third_party/libcxx/LICENSE | 2989 ---------- third_party/libcxx/README.lume | 19 - .../include/c++/v1/__algorithm/adjacent_find.h | 60 - .../libcxx/include/c++/v1/__algorithm/all_of.h | 48 - .../libcxx/include/c++/v1/__algorithm/any_of.h | 42 - .../include/c++/v1/__algorithm/binary_search.h | 38 - .../libcxx/include/c++/v1/__algorithm/clamp.h | 44 - .../libcxx/include/c++/v1/__algorithm/comp.h | 57 - .../include/c++/v1/__algorithm/comp_ref_type.h | 67 - .../libcxx/include/c++/v1/__algorithm/copy.h | 135 - .../include/c++/v1/__algorithm/copy_backward.h | 255 - .../libcxx/include/c++/v1/__algorithm/copy_if.h | 50 - .../include/c++/v1/__algorithm/copy_move_common.h | 113 - .../libcxx/include/c++/v1/__algorithm/copy_n.h | 94 - .../libcxx/include/c++/v1/__algorithm/count.h | 95 - .../libcxx/include/c++/v1/__algorithm/count_if.h | 46 - .../libcxx/include/c++/v1/__algorithm/equal.h | 325 -- .../include/c++/v1/__algorithm/equal_range.h | 81 - .../libcxx/include/c++/v1/__algorithm/fill.h | 63 - .../libcxx/include/c++/v1/__algorithm/fill_n.h | 75 - .../libcxx/include/c++/v1/__algorithm/find.h | 240 - .../libcxx/include/c++/v1/__algorithm/find_end.h | 223 - .../include/c++/v1/__algorithm/find_first_of.h | 54 - .../libcxx/include/c++/v1/__algorithm/find_if.h | 43 - .../include/c++/v1/__algorithm/find_if_not.h | 48 - .../include/c++/v1/__algorithm/find_segment_if.h | 61 - .../libcxx/include/c++/v1/__algorithm/for_each.h | 59 - .../libcxx/include/c++/v1/__algorithm/for_each_n.h | 76 - .../c++/v1/__algorithm/for_each_n_segment.h | 63 - .../include/c++/v1/__algorithm/for_each_segment.h | 79 - .../libcxx/include/c++/v1/__algorithm/generate.h | 31 - .../libcxx/include/c++/v1/__algorithm/generate_n.h | 49 - .../include/c++/v1/__algorithm/half_positive.h | 37 - .../include/c++/v1/__algorithm/in_found_result.h | 54 - .../include/c++/v1/__algorithm/in_fun_result.h | 54 - .../include/c++/v1/__algorithm/in_in_out_result.h | 59 - .../include/c++/v1/__algorithm/in_in_result.h | 56 - .../include/c++/v1/__algorithm/in_out_out_result.h | 57 - .../include/c++/v1/__algorithm/in_out_result.h | 56 - .../libcxx/include/c++/v1/__algorithm/includes.h | 78 - .../include/c++/v1/__algorithm/inplace_merge.h | 243 - .../libcxx/include/c++/v1/__algorithm/is_heap.h | 37 - .../include/c++/v1/__algorithm/is_heap_until.h | 62 - .../include/c++/v1/__algorithm/is_partitioned.h | 37 - .../include/c++/v1/__algorithm/is_permutation.h | 309 -- .../libcxx/include/c++/v1/__algorithm/is_sorted.h | 37 - .../include/c++/v1/__algorithm/is_sorted_until.h | 50 - .../libcxx/include/c++/v1/__algorithm/iter_swap.h | 31 - .../c++/v1/__algorithm/iterator_operations.h | 229 - .../c++/v1/__algorithm/lexicographical_compare.h | 129 - .../lexicographical_compare_three_way.h | 125 - .../include/c++/v1/__algorithm/lower_bound.h | 108 - .../libcxx/include/c++/v1/__algorithm/make_heap.h | 72 - .../include/c++/v1/__algorithm/make_projected.h | 104 - .../libcxx/include/c++/v1/__algorithm/max.h | 58 - .../include/c++/v1/__algorithm/max_element.h | 54 - .../libcxx/include/c++/v1/__algorithm/merge.h | 68 - .../libcxx/include/c++/v1/__algorithm/min.h | 58 - .../include/c++/v1/__algorithm/min_element.h | 71 - .../include/c++/v1/__algorithm/min_max_result.h | 56 - .../libcxx/include/c++/v1/__algorithm/minmax.h | 59 - .../include/c++/v1/__algorithm/minmax_element.h | 100 - .../libcxx/include/c++/v1/__algorithm/mismatch.h | 218 - .../libcxx/include/c++/v1/__algorithm/move.h | 128 - .../include/c++/v1/__algorithm/move_backward.h | 134 - .../include/c++/v1/__algorithm/next_permutation.h | 75 - .../libcxx/include/c++/v1/__algorithm/none_of.h | 32 - .../include/c++/v1/__algorithm/nth_element.h | 261 - .../include/c++/v1/__algorithm/out_value_result.h | 56 - .../include/c++/v1/__algorithm/partial_sort.h | 91 - .../include/c++/v1/__algorithm/partial_sort_copy.h | 106 - .../libcxx/include/c++/v1/__algorithm/partition.h | 91 - .../include/c++/v1/__algorithm/partition_copy.h | 43 - .../include/c++/v1/__algorithm/partition_point.h | 44 - .../libcxx/include/c++/v1/__algorithm/pop_heap.h | 81 - .../include/c++/v1/__algorithm/prev_permutation.h | 75 - .../libcxx/include/c++/v1/__algorithm/pstl.h | 688 --- .../libcxx/include/c++/v1/__algorithm/push_heap.h | 84 - .../libcxx/include/c++/v1/__algorithm/radix_sort.h | 431 -- .../c++/v1/__algorithm/ranges_adjacent_find.h | 66 - .../include/c++/v1/__algorithm/ranges_all_of.h | 64 - .../include/c++/v1/__algorithm/ranges_any_of.h | 63 - .../c++/v1/__algorithm/ranges_binary_search.h | 71 - .../include/c++/v1/__algorithm/ranges_clamp.h | 64 - .../include/c++/v1/__algorithm/ranges_contains.h | 64 - .../c++/v1/__algorithm/ranges_contains_subrange.h | 95 - .../include/c++/v1/__algorithm/ranges_copy.h | 68 - .../c++/v1/__algorithm/ranges_copy_backward.h | 67 - .../include/c++/v1/__algorithm/ranges_copy_if.h | 76 - .../include/c++/v1/__algorithm/ranges_copy_n.h | 57 - .../include/c++/v1/__algorithm/ranges_count.h | 64 - .../include/c++/v1/__algorithm/ranges_count_if.h | 67 - .../include/c++/v1/__algorithm/ranges_ends_with.h | 200 - .../include/c++/v1/__algorithm/ranges_equal.h | 98 - .../c++/v1/__algorithm/ranges_equal_range.h | 76 - .../include/c++/v1/__algorithm/ranges_fill.h | 61 - .../include/c++/v1/__algorithm/ranges_fill_n.h | 49 - .../include/c++/v1/__algorithm/ranges_find.h | 78 - .../include/c++/v1/__algorithm/ranges_find_end.h | 101 - .../c++/v1/__algorithm/ranges_find_first_of.h | 104 - .../include/c++/v1/__algorithm/ranges_find_if.h | 64 - .../c++/v1/__algorithm/ranges_find_if_not.h | 62 - .../include/c++/v1/__algorithm/ranges_find_last.h | 170 - .../include/c++/v1/__algorithm/ranges_fold.h | 137 - .../include/c++/v1/__algorithm/ranges_for_each.h | 97 - .../include/c++/v1/__algorithm/ranges_for_each_n.h | 59 - .../include/c++/v1/__algorithm/ranges_generate.h | 69 - .../include/c++/v1/__algorithm/ranges_generate_n.h | 57 - .../include/c++/v1/__algorithm/ranges_includes.h | 94 - .../c++/v1/__algorithm/ranges_inplace_merge.h | 80 - .../include/c++/v1/__algorithm/ranges_is_heap.h | 77 - .../c++/v1/__algorithm/ranges_is_heap_until.h | 77 - .../c++/v1/__algorithm/ranges_is_partitioned.h | 84 - .../c++/v1/__algorithm/ranges_is_permutation.h | 105 - .../include/c++/v1/__algorithm/ranges_is_sorted.h | 65 - .../c++/v1/__algorithm/ranges_is_sorted_until.h | 80 - .../c++/v1/__algorithm/ranges_iterator_concept.h | 56 - .../__algorithm/ranges_lexicographical_compare.h | 107 - .../c++/v1/__algorithm/ranges_lower_bound.h | 71 - .../include/c++/v1/__algorithm/ranges_make_heap.h | 81 - .../libcxx/include/c++/v1/__algorithm/ranges_max.h | 101 - .../c++/v1/__algorithm/ranges_max_element.h | 67 - .../include/c++/v1/__algorithm/ranges_merge.h | 134 - .../libcxx/include/c++/v1/__algorithm/ranges_min.h | 93 - .../c++/v1/__algorithm/ranges_min_element.h | 66 - .../include/c++/v1/__algorithm/ranges_minmax.h | 174 - .../c++/v1/__algorithm/ranges_minmax_element.h | 76 - .../include/c++/v1/__algorithm/ranges_mismatch.h | 98 - .../include/c++/v1/__algorithm/ranges_move.h | 72 - .../c++/v1/__algorithm/ranges_move_backward.h | 74 - .../c++/v1/__algorithm/ranges_next_permutation.h | 74 - .../include/c++/v1/__algorithm/ranges_none_of.h | 73 - .../c++/v1/__algorithm/ranges_nth_element.h | 80 - .../c++/v1/__algorithm/ranges_partial_sort.h | 78 - .../c++/v1/__algorithm/ranges_partial_sort_copy.h | 110 - .../include/c++/v1/__algorithm/ranges_partition.h | 85 - .../c++/v1/__algorithm/ranges_partition_copy.h | 106 - .../c++/v1/__algorithm/ranges_partition_point.h | 89 - .../include/c++/v1/__algorithm/ranges_pop_heap.h | 82 - .../c++/v1/__algorithm/ranges_prev_permutation.h | 74 - .../include/c++/v1/__algorithm/ranges_push_heap.h | 81 - .../include/c++/v1/__algorithm/ranges_remove.h | 66 - .../c++/v1/__algorithm/ranges_remove_copy.h | 77 - .../c++/v1/__algorithm/ranges_remove_copy_if.h | 91 - .../include/c++/v1/__algorithm/ranges_remove_if.h | 86 - .../include/c++/v1/__algorithm/ranges_replace.h | 66 - .../c++/v1/__algorithm/ranges_replace_copy.h | 89 - .../c++/v1/__algorithm/ranges_replace_copy_if.h | 94 - .../include/c++/v1/__algorithm/ranges_replace_if.h | 79 - .../include/c++/v1/__algorithm/ranges_reverse.h | 77 - .../c++/v1/__algorithm/ranges_reverse_copy.h | 69 - .../include/c++/v1/__algorithm/ranges_rotate.h | 67 - .../c++/v1/__algorithm/ranges_rotate_copy.h | 66 - .../include/c++/v1/__algorithm/ranges_sample.h | 70 - .../include/c++/v1/__algorithm/ranges_search.h | 132 - .../include/c++/v1/__algorithm/ranges_search_n.h | 114 - .../c++/v1/__algorithm/ranges_set_difference.h | 104 - .../c++/v1/__algorithm/ranges_set_intersection.h | 110 - .../__algorithm/ranges_set_symmetric_difference.h | 109 - .../include/c++/v1/__algorithm/ranges_set_union.h | 110 - .../include/c++/v1/__algorithm/ranges_shift_left.h | 73 - .../c++/v1/__algorithm/ranges_shift_right.h | 76 - .../include/c++/v1/__algorithm/ranges_shuffle.h | 68 - .../include/c++/v1/__algorithm/ranges_sort.h | 80 - .../include/c++/v1/__algorithm/ranges_sort_heap.h | 81 - .../c++/v1/__algorithm/ranges_stable_partition.h | 89 - .../c++/v1/__algorithm/ranges_stable_sort.h | 80 - .../c++/v1/__algorithm/ranges_starts_with.h | 93 - .../c++/v1/__algorithm/ranges_swap_ranges.h | 95 - .../include/c++/v1/__algorithm/ranges_transform.h | 175 - .../include/c++/v1/__algorithm/ranges_unique.h | 78 - .../c++/v1/__algorithm/ranges_unique_copy.h | 116 - .../c++/v1/__algorithm/ranges_upper_bound.h | 72 - .../libcxx/include/c++/v1/__algorithm/remove.h | 46 - .../include/c++/v1/__algorithm/remove_copy.h | 34 - .../include/c++/v1/__algorithm/remove_copy_if.h | 34 - .../libcxx/include/c++/v1/__algorithm/remove_if.h | 45 - .../libcxx/include/c++/v1/__algorithm/replace.h | 30 - .../include/c++/v1/__algorithm/replace_copy.h | 37 - .../include/c++/v1/__algorithm/replace_copy_if.h | 37 - .../libcxx/include/c++/v1/__algorithm/replace_if.h | 30 - .../libcxx/include/c++/v1/__algorithm/reverse.h | 62 - .../include/c++/v1/__algorithm/reverse_copy.h | 30 - .../libcxx/include/c++/v1/__algorithm/rotate.h | 226 - .../include/c++/v1/__algorithm/rotate_copy.h | 29 - .../libcxx/include/c++/v1/__algorithm/sample.h | 123 - .../libcxx/include/c++/v1/__algorithm/search.h | 192 - .../libcxx/include/c++/v1/__algorithm/search_n.h | 168 - .../include/c++/v1/__algorithm/set_difference.h | 76 - .../include/c++/v1/__algorithm/set_intersection.h | 218 - .../c++/v1/__algorithm/set_symmetric_difference.h | 108 - .../libcxx/include/c++/v1/__algorithm/set_union.h | 104 - .../libcxx/include/c++/v1/__algorithm/shift_left.h | 76 - .../include/c++/v1/__algorithm/shift_right.h | 131 - .../libcxx/include/c++/v1/__algorithm/shuffle.h | 167 - .../libcxx/include/c++/v1/__algorithm/sift_down.h | 119 - .../libcxx/include/c++/v1/__algorithm/simd_utils.h | 193 - .../libcxx/include/c++/v1/__algorithm/sort.h | 958 ---- .../libcxx/include/c++/v1/__algorithm/sort_heap.h | 63 - .../c++/v1/__algorithm/specialized_algorithms.h | 55 - .../include/c++/v1/__algorithm/stable_partition.h | 305 - .../include/c++/v1/__algorithm/stable_sort.h | 323 -- .../include/c++/v1/__algorithm/swap_ranges.h | 70 - .../c++/v1/__algorithm/three_way_comp_ref_type.h | 74 - .../libcxx/include/c++/v1/__algorithm/transform.h | 42 - .../uniform_random_bit_generator_adaptor.h | 58 - .../libcxx/include/c++/v1/__algorithm/unique.h | 66 - .../include/c++/v1/__algorithm/unique_copy.h | 127 - .../include/c++/v1/__algorithm/unwrap_iter.h | 83 - .../include/c++/v1/__algorithm/unwrap_range.h | 70 - .../include/c++/v1/__algorithm/upper_bound.h | 71 - third_party/libcxx/include/c++/v1/__assert | 118 - .../libcxx/include/c++/v1/__assertion_handler | 64 - .../libcxx/include/c++/v1/__atomic/aliases.h | 111 - .../libcxx/include/c++/v1/__atomic/atomic.h | 804 --- .../libcxx/include/c++/v1/__atomic/atomic_flag.h | 165 - .../libcxx/include/c++/v1/__atomic/atomic_init.h | 25 - .../include/c++/v1/__atomic/atomic_lock_free.h | 48 - .../libcxx/include/c++/v1/__atomic/atomic_ref.h | 398 -- .../libcxx/include/c++/v1/__atomic/atomic_sync.h | 261 - .../include/c++/v1/__atomic/atomic_sync_timed.h | 136 - .../c++/v1/__atomic/atomic_waitable_traits.h | 101 - .../include/c++/v1/__atomic/check_memory_order.h | 34 - .../libcxx/include/c++/v1/__atomic/contention_t.h | 56 - third_party/libcxx/include/c++/v1/__atomic/fence.h | 28 - .../c++/v1/__atomic/floating_point_helper.h | 55 - .../include/c++/v1/__atomic/is_always_lock_free.h | 28 - .../include/c++/v1/__atomic/kill_dependency.h | 27 - .../libcxx/include/c++/v1/__atomic/memory_order.h | 65 - .../libcxx/include/c++/v1/__atomic/support.h | 121 - .../libcxx/include/c++/v1/__atomic/support/c11.h | 264 - .../libcxx/include/c++/v1/__atomic/support/gcc.h | 265 - .../libcxx/include/c++/v1/__atomic/to_gcc_order.h | 54 - third_party/libcxx/include/c++/v1/__bit/bit_cast.h | 44 - third_party/libcxx/include/c++/v1/__bit/bit_ceil.h | 54 - .../libcxx/include/c++/v1/__bit/bit_floor.h | 33 - third_party/libcxx/include/c++/v1/__bit/bit_log2.h | 33 - .../libcxx/include/c++/v1/__bit/bit_width.h | 33 - third_party/libcxx/include/c++/v1/__bit/blsr.h | 34 - third_party/libcxx/include/c++/v1/__bit/byteswap.h | 53 - third_party/libcxx/include/c++/v1/__bit/countl.h | 48 - third_party/libcxx/include/c++/v1/__bit/countr.h | 48 - third_party/libcxx/include/c++/v1/__bit/endian.h | 38 - .../libcxx/include/c++/v1/__bit/has_single_bit.h | 37 - .../libcxx/include/c++/v1/__bit/invert_if.h | 30 - third_party/libcxx/include/c++/v1/__bit/popcount.h | 42 - third_party/libcxx/include/c++/v1/__bit/rotate.h | 60 - third_party/libcxx/include/c++/v1/__bit_reference | 873 --- .../include/c++/v1/__charconv/chars_format.h | 61 - .../c++/v1/__charconv/from_chars_floating_point.h | 73 - .../c++/v1/__charconv/from_chars_integral.h | 237 - .../include/c++/v1/__charconv/from_chars_result.h | 39 - .../libcxx/include/c++/v1/__charconv/tables.h | 159 - .../libcxx/include/c++/v1/__charconv/to_chars.h | 25 - .../include/c++/v1/__charconv/to_chars_base_10.h | 184 - .../c++/v1/__charconv/to_chars_floating_point.h | 55 - .../include/c++/v1/__charconv/to_chars_integral.h | 344 -- .../include/c++/v1/__charconv/to_chars_result.h | 48 - .../libcxx/include/c++/v1/__charconv/traits.h | 167 - .../libcxx/include/c++/v1/__chrono/calendar.h | 44 - .../libcxx/include/c++/v1/__chrono/concepts.h | 36 - .../include/c++/v1/__chrono/convert_to_timespec.h | 51 - .../libcxx/include/c++/v1/__chrono/convert_to_tm.h | 241 - third_party/libcxx/include/c++/v1/__chrono/day.h | 112 - .../libcxx/include/c++/v1/__chrono/duration.h | 570 -- .../libcxx/include/c++/v1/__chrono/exception.h | 135 - .../libcxx/include/c++/v1/__chrono/file_clock.h | 82 - .../libcxx/include/c++/v1/__chrono/formatter.h | 1035 ---- .../libcxx/include/c++/v1/__chrono/gps_clock.h | 90 - .../libcxx/include/c++/v1/__chrono/hh_mm_ss.h | 112 - .../c++/v1/__chrono/high_resolution_clock.h | 35 - .../libcxx/include/c++/v1/__chrono/is_clock.h | 72 - .../libcxx/include/c++/v1/__chrono/leap_second.h | 144 - .../libcxx/include/c++/v1/__chrono/literals.h | 45 - .../libcxx/include/c++/v1/__chrono/local_info.h | 50 - third_party/libcxx/include/c++/v1/__chrono/month.h | 128 - .../libcxx/include/c++/v1/__chrono/month_weekday.h | 135 - .../libcxx/include/c++/v1/__chrono/monthday.h | 155 - .../libcxx/include/c++/v1/__chrono/ostream.h | 354 -- .../c++/v1/__chrono/parser_std_format_spec.h | 421 -- .../include/c++/v1/__chrono/statically_widen.h | 52 - .../libcxx/include/c++/v1/__chrono/steady_clock.h | 42 - .../libcxx/include/c++/v1/__chrono/sys_info.h | 51 - .../libcxx/include/c++/v1/__chrono/system_clock.h | 52 - .../libcxx/include/c++/v1/__chrono/tai_clock.h | 108 - .../libcxx/include/c++/v1/__chrono/time_point.h | 255 - .../libcxx/include/c++/v1/__chrono/time_zone.h | 185 - .../include/c++/v1/__chrono/time_zone_link.h | 79 - third_party/libcxx/include/c++/v1/__chrono/tzdb.h | 96 - .../libcxx/include/c++/v1/__chrono/tzdb_list.h | 108 - .../libcxx/include/c++/v1/__chrono/utc_clock.h | 163 - .../libcxx/include/c++/v1/__chrono/weekday.h | 202 - third_party/libcxx/include/c++/v1/__chrono/year.h | 131 - .../libcxx/include/c++/v1/__chrono/year_month.h | 143 - .../include/c++/v1/__chrono/year_month_day.h | 371 -- .../include/c++/v1/__chrono/year_month_weekday.h | 325 -- .../libcxx/include/c++/v1/__chrono/zoned_time.h | 244 - .../c++/v1/__compare/common_comparison_category.h | 86 - .../v1/__compare/compare_partial_order_fallback.h | 75 - .../v1/__compare/compare_strong_order_fallback.h | 72 - .../include/c++/v1/__compare/compare_three_way.h | 40 - .../c++/v1/__compare/compare_three_way_result.h | 46 - .../c++/v1/__compare/compare_weak_order_fallback.h | 73 - .../libcxx/include/c++/v1/__compare/is_eq.h | 34 - .../libcxx/include/c++/v1/__compare/ordering.h | 282 - .../include/c++/v1/__compare/partial_order.h | 77 - .../libcxx/include/c++/v1/__compare/strong_order.h | 125 - .../include/c++/v1/__compare/synth_three_way.h | 53 - .../c++/v1/__compare/three_way_comparable.h | 55 - .../libcxx/include/c++/v1/__compare/weak_order.h | 105 - .../libcxx/include/c++/v1/__concepts/arithmetic.h | 43 - .../libcxx/include/c++/v1/__concepts/assignable.h | 41 - .../include/c++/v1/__concepts/boolean_testable.h | 38 - .../include/c++/v1/__concepts/class_or_enum.h | 34 - .../c++/v1/__concepts/common_reference_with.h | 36 - .../libcxx/include/c++/v1/__concepts/common_with.h | 52 - .../c++/v1/__concepts/comparison_common_type.h | 40 - .../include/c++/v1/__concepts/constructible.h | 55 - .../include/c++/v1/__concepts/convertible_to.h | 33 - .../libcxx/include/c++/v1/__concepts/copyable.h | 41 - .../include/c++/v1/__concepts/derived_from.h | 33 - .../include/c++/v1/__concepts/destructible.h | 32 - .../include/c++/v1/__concepts/different_from.h | 31 - .../c++/v1/__concepts/equality_comparable.h | 57 - .../libcxx/include/c++/v1/__concepts/invocable.h | 40 - .../libcxx/include/c++/v1/__concepts/movable.h | 35 - .../libcxx/include/c++/v1/__concepts/predicate.h | 34 - .../libcxx/include/c++/v1/__concepts/regular.h | 33 - .../libcxx/include/c++/v1/__concepts/relation.h | 43 - .../libcxx/include/c++/v1/__concepts/same_as.h | 35 - .../libcxx/include/c++/v1/__concepts/semiregular.h | 33 - .../libcxx/include/c++/v1/__concepts/swappable.h | 122 - .../include/c++/v1/__concepts/totally_ordered.h | 59 - .../v1/__condition_variable/condition_variable.h | 232 - third_party/libcxx/include/c++/v1/__config | 612 -- .../libcxx/include/c++/v1/__configuration/abi.h | 142 - .../include/c++/v1/__configuration/attributes.h | 466 -- .../include/c++/v1/__configuration/availability.h | 299 - .../include/c++/v1/__configuration/compiler.h | 51 - .../include/c++/v1/__configuration/experimental.h | 38 - .../include/c++/v1/__configuration/hardening.h | 215 - .../include/c++/v1/__configuration/language.h | 59 - .../include/c++/v1/__configuration/platform.h | 56 - .../include/c++/v1/__coroutine/coroutine_handle.h | 177 - .../include/c++/v1/__coroutine/coroutine_traits.h | 48 - .../c++/v1/__coroutine/noop_coroutine_handle.h | 97 - .../c++/v1/__coroutine/trivial_awaitables.h | 40 - third_party/libcxx/include/c++/v1/__cstddef/byte.h | 85 - .../libcxx/include/c++/v1/__cstddef/max_align_t.h | 27 - .../libcxx/include/c++/v1/__cstddef/nullptr_t.h | 24 - .../libcxx/include/c++/v1/__cstddef/ptrdiff_t.h | 24 - .../libcxx/include/c++/v1/__cstddef/size_t.h | 24 - .../c++/v1/__cxx03/__algorithm/adjacent_find.h | 57 - .../include/c++/v1/__cxx03/__algorithm/all_of.h | 32 - .../include/c++/v1/__cxx03/__algorithm/any_of.h | 32 - .../c++/v1/__cxx03/__algorithm/binary_search.h | 39 - .../include/c++/v1/__cxx03/__algorithm/comp.h | 49 - .../c++/v1/__cxx03/__algorithm/comp_ref_type.h | 66 - .../include/c++/v1/__cxx03/__algorithm/copy.h | 117 - .../c++/v1/__cxx03/__algorithm/copy_backward.h | 132 - .../include/c++/v1/__cxx03/__algorithm/copy_if.h | 34 - .../c++/v1/__cxx03/__algorithm/copy_move_common.h | 112 - .../include/c++/v1/__cxx03/__algorithm/copy_n.h | 58 - .../include/c++/v1/__cxx03/__algorithm/count.h | 92 - .../include/c++/v1/__cxx03/__algorithm/count_if.h | 34 - .../include/c++/v1/__cxx03/__algorithm/equal.h | 73 - .../c++/v1/__cxx03/__algorithm/equal_range.h | 85 - .../include/c++/v1/__cxx03/__algorithm/fill.h | 44 - .../include/c++/v1/__cxx03/__algorithm/fill_n.h | 94 - .../include/c++/v1/__cxx03/__algorithm/find.h | 177 - .../include/c++/v1/__cxx03/__algorithm/find_end.h | 225 - .../c++/v1/__cxx03/__algorithm/find_first_of.h | 55 - .../include/c++/v1/__cxx03/__algorithm/find_if.h | 32 - .../c++/v1/__cxx03/__algorithm/find_if_not.h | 32 - .../c++/v1/__cxx03/__algorithm/find_segment_if.h | 62 - .../include/c++/v1/__cxx03/__algorithm/for_each.h | 33 - .../c++/v1/__cxx03/__algorithm/for_each_segment.h | 52 - .../include/c++/v1/__cxx03/__algorithm/generate.h | 28 - .../c++/v1/__cxx03/__algorithm/generate_n.h | 32 - .../c++/v1/__cxx03/__algorithm/half_positive.h | 37 - .../include/c++/v1/__cxx03/__algorithm/includes.h | 79 - .../c++/v1/__cxx03/__algorithm/inplace_merge.h | 240 - .../include/c++/v1/__cxx03/__algorithm/is_heap.h | 38 - .../c++/v1/__cxx03/__algorithm/is_heap_until.h | 62 - .../c++/v1/__cxx03/__algorithm/is_partitioned.h | 37 - .../c++/v1/__cxx03/__algorithm/is_permutation.h | 254 - .../include/c++/v1/__cxx03/__algorithm/is_sorted.h | 37 - .../c++/v1/__cxx03/__algorithm/is_sorted_until.h | 51 - .../include/c++/v1/__cxx03/__algorithm/iter_swap.h | 29 - .../v1/__cxx03/__algorithm/iterator_operations.h | 192 - .../__cxx03/__algorithm/lexicographical_compare.h | 57 - .../c++/v1/__cxx03/__algorithm/lower_bound.h | 109 - .../include/c++/v1/__cxx03/__algorithm/make_heap.h | 59 - .../c++/v1/__cxx03/__algorithm/make_projected.h | 74 - .../include/c++/v1/__cxx03/__algorithm/max.h | 42 - .../c++/v1/__cxx03/__algorithm/max_element.h | 51 - .../include/c++/v1/__cxx03/__algorithm/merge.h | 69 - .../include/c++/v1/__cxx03/__algorithm/min.h | 42 - .../c++/v1/__cxx03/__algorithm/min_element.h | 70 - .../include/c++/v1/__cxx03/__algorithm/minmax.h | 39 - .../c++/v1/__cxx03/__algorithm/minmax_element.h | 99 - .../include/c++/v1/__cxx03/__algorithm/mismatch.h | 171 - .../include/c++/v1/__cxx03/__algorithm/move.h | 120 - .../c++/v1/__cxx03/__algorithm/move_backward.h | 133 - .../c++/v1/__cxx03/__algorithm/next_permutation.h | 74 - .../include/c++/v1/__cxx03/__algorithm/none_of.h | 32 - .../c++/v1/__cxx03/__algorithm/nth_element.h | 261 - .../c++/v1/__cxx03/__algorithm/partial_sort.h | 91 - .../c++/v1/__cxx03/__algorithm/partial_sort_copy.h | 106 - .../include/c++/v1/__cxx03/__algorithm/partition.h | 90 - .../c++/v1/__cxx03/__algorithm/partition_copy.h | 43 - .../c++/v1/__cxx03/__algorithm/partition_point.h | 44 - .../include/c++/v1/__cxx03/__algorithm/pop_heap.h | 80 - .../c++/v1/__cxx03/__algorithm/prev_permutation.h | 74 - .../include/c++/v1/__cxx03/__algorithm/push_heap.h | 83 - .../include/c++/v1/__cxx03/__algorithm/remove.h | 46 - .../c++/v1/__cxx03/__algorithm/remove_copy.h | 34 - .../c++/v1/__cxx03/__algorithm/remove_copy_if.h | 34 - .../include/c++/v1/__cxx03/__algorithm/remove_if.h | 45 - .../include/c++/v1/__cxx03/__algorithm/replace.h | 30 - .../c++/v1/__cxx03/__algorithm/replace_copy.h | 37 - .../c++/v1/__cxx03/__algorithm/replace_copy_if.h | 37 - .../c++/v1/__cxx03/__algorithm/replace_if.h | 30 - .../include/c++/v1/__cxx03/__algorithm/reverse.h | 61 - .../c++/v1/__cxx03/__algorithm/reverse_copy.h | 30 - .../include/c++/v1/__cxx03/__algorithm/rotate.h | 196 - .../c++/v1/__cxx03/__algorithm/rotate_copy.h | 29 - .../include/c++/v1/__cxx03/__algorithm/search.h | 182 - .../include/c++/v1/__cxx03/__algorithm/search_n.h | 153 - .../c++/v1/__cxx03/__algorithm/set_difference.h | 77 - .../c++/v1/__cxx03/__algorithm/set_intersection.h | 211 - .../__cxx03/__algorithm/set_symmetric_difference.h | 108 - .../include/c++/v1/__cxx03/__algorithm/set_union.h | 104 - .../include/c++/v1/__cxx03/__algorithm/shuffle.h | 157 - .../include/c++/v1/__cxx03/__algorithm/sift_down.h | 118 - .../c++/v1/__cxx03/__algorithm/simd_utils.h | 159 - .../include/c++/v1/__cxx03/__algorithm/sort.h | 989 ---- .../include/c++/v1/__cxx03/__algorithm/sort_heap.h | 62 - .../c++/v1/__cxx03/__algorithm/stable_partition.h | 307 - .../c++/v1/__cxx03/__algorithm/stable_sort.h | 273 - .../c++/v1/__cxx03/__algorithm/swap_ranges.h | 62 - .../__cxx03/__algorithm/three_way_comp_ref_type.h | 26 - .../include/c++/v1/__cxx03/__algorithm/transform.h | 42 - .../uniform_random_bit_generator_adaptor.h | 20 - .../include/c++/v1/__cxx03/__algorithm/unique.h | 64 - .../c++/v1/__cxx03/__algorithm/unique_copy.h | 127 - .../c++/v1/__cxx03/__algorithm/unwrap_iter.h | 74 - .../c++/v1/__cxx03/__algorithm/unwrap_range.h | 46 - .../c++/v1/__cxx03/__algorithm/upper_bound.h | 68 - third_party/libcxx/include/c++/v1/__cxx03/__assert | 118 - .../include/c++/v1/__cxx03/__atomic/aliases.h | 85 - .../include/c++/v1/__cxx03/__atomic/atomic.h | 484 -- .../include/c++/v1/__cxx03/__atomic/atomic_base.h | 217 - .../include/c++/v1/__cxx03/__atomic/atomic_flag.h | 184 - .../include/c++/v1/__cxx03/__atomic/atomic_init.h | 21 - .../c++/v1/__cxx03/__atomic/atomic_lock_free.h | 48 - .../include/c++/v1/__cxx03/__atomic/atomic_sync.h | 205 - .../c++/v1/__cxx03/__atomic/check_memory_order.h | 34 - .../include/c++/v1/__cxx03/__atomic/contention_t.h | 32 - .../c++/v1/__cxx03/__atomic/cxx_atomic_impl.h | 498 -- .../libcxx/include/c++/v1/__cxx03/__atomic/fence.h | 28 - .../c++/v1/__cxx03/__atomic/is_always_lock_free.h | 28 - .../c++/v1/__cxx03/__atomic/kill_dependency.h | 27 - .../include/c++/v1/__cxx03/__atomic/memory_order.h | 40 - .../include/c++/v1/__cxx03/__atomic/to_gcc_order.h | 54 - .../libcxx/include/c++/v1/__cxx03/__bit/blsr.h | 30 - .../libcxx/include/c++/v1/__cxx03/__bit/countl.h | 96 - .../libcxx/include/c++/v1/__cxx03/__bit/countr.h | 67 - .../include/c++/v1/__cxx03/__bit/invert_if.h | 29 - .../libcxx/include/c++/v1/__cxx03/__bit/popcount.h | 34 - .../libcxx/include/c++/v1/__cxx03/__bit/rotate.h | 57 - .../libcxx/include/c++/v1/__cxx03/__bit_reference | 965 ---- .../c++/v1/__cxx03/__chrono/convert_to_timespec.h | 51 - .../include/c++/v1/__cxx03/__chrono/duration.h | 418 -- .../v1/__cxx03/__chrono/high_resolution_clock.h | 35 - .../include/c++/v1/__cxx03/__chrono/steady_clock.h | 42 - .../include/c++/v1/__cxx03/__chrono/system_clock.h | 43 - .../include/c++/v1/__cxx03/__chrono/time_point.h | 177 - .../__condition_variable/condition_variable.h | 244 - third_party/libcxx/include/c++/v1/__cxx03/__config | 1077 ---- .../include/c++/v1/__cxx03/__configuration/abi.h | 172 - .../c++/v1/__cxx03/__configuration/availability.h | 400 -- .../c++/v1/__cxx03/__configuration/compiler.h | 51 - .../v1/__cxx03/__configuration/config_site_shim.h | 80 - .../c++/v1/__cxx03/__configuration/language.h | 27 - .../c++/v1/__cxx03/__configuration/platform.h | 54 - .../c++/v1/__cxx03/__debug_utils/randomize_range.h | 40 - .../c++/v1/__cxx03/__debug_utils/sanitizers.h | 104 - .../__debug_utils/strict_weak_ordering_check.h | 77 - .../include/c++/v1/__cxx03/__exception/exception.h | 94 - .../c++/v1/__cxx03/__exception/exception_ptr.h | 177 - .../c++/v1/__cxx03/__exception/nested_exception.h | 99 - .../c++/v1/__cxx03/__exception/operations.h | 38 - .../include/c++/v1/__cxx03/__exception/terminate.h | 22 - .../c++/v1/__cxx03/__functional/binary_function.h | 43 - .../c++/v1/__cxx03/__functional/binary_negate.h | 45 - .../include/c++/v1/__cxx03/__functional/bind.h | 70 - .../c++/v1/__cxx03/__functional/binder1st.h | 49 - .../c++/v1/__cxx03/__functional/binder2nd.h | 49 - .../include/c++/v1/__cxx03/__functional/hash.h | 509 -- .../include/c++/v1/__cxx03/__functional/identity.h | 45 - .../include/c++/v1/__cxx03/__functional/mem_fn.h | 51 - .../c++/v1/__cxx03/__functional/mem_fun_ref.h | 137 - .../c++/v1/__cxx03/__functional/operations.h | 181 - .../__functional/pointer_to_binary_function.h | 38 - .../__functional/pointer_to_unary_function.h | 38 - .../v1/__cxx03/__functional/reference_wrapper.h | 89 - .../c++/v1/__cxx03/__functional/unary_function.h | 40 - .../c++/v1/__cxx03/__functional/unary_negate.h | 38 - .../c++/v1/__cxx03/__functional/weak_result_type.h | 209 - .../libcxx/include/c++/v1/__cxx03/__fwd/array.h | 38 - .../include/c++/v1/__cxx03/__fwd/bit_reference.h | 25 - .../libcxx/include/c++/v1/__cxx03/__fwd/complex.h | 26 - .../libcxx/include/c++/v1/__cxx03/__fwd/deque.h | 26 - .../libcxx/include/c++/v1/__cxx03/__fwd/fstream.h | 53 - .../include/c++/v1/__cxx03/__fwd/functional.h | 28 - .../libcxx/include/c++/v1/__cxx03/__fwd/ios.h | 43 - .../libcxx/include/c++/v1/__cxx03/__fwd/istream.h | 43 - .../libcxx/include/c++/v1/__cxx03/__fwd/memory.h | 25 - .../libcxx/include/c++/v1/__cxx03/__fwd/ostream.h | 35 - .../libcxx/include/c++/v1/__cxx03/__fwd/pair.h | 33 - .../libcxx/include/c++/v1/__cxx03/__fwd/queue.h | 31 - .../libcxx/include/c++/v1/__cxx03/__fwd/sstream.h | 58 - .../libcxx/include/c++/v1/__cxx03/__fwd/stack.h | 26 - .../include/c++/v1/__cxx03/__fwd/streambuf.h | 35 - .../libcxx/include/c++/v1/__cxx03/__fwd/string.h | 73 - .../include/c++/v1/__cxx03/__fwd/string_view.h | 50 - .../libcxx/include/c++/v1/__cxx03/__fwd/tuple.h | 26 - .../libcxx/include/c++/v1/__cxx03/__fwd/vector.h | 26 - .../libcxx/include/c++/v1/__cxx03/__hash_table | 1842 ------ .../libcxx/include/c++/v1/__cxx03/__ios/fpos.h | 76 - .../include/c++/v1/__cxx03/__iterator/access.h | 54 - .../include/c++/v1/__cxx03/__iterator/advance.h | 74 - .../c++/v1/__cxx03/__iterator/aliasing_iterator.h | 127 - .../v1/__cxx03/__iterator/back_insert_iterator.h | 67 - .../c++/v1/__cxx03/__iterator/bounded_iter.h | 247 - .../include/c++/v1/__cxx03/__iterator/distance.h | 47 - .../c++/v1/__cxx03/__iterator/erase_if_container.h | 43 - .../v1/__cxx03/__iterator/front_insert_iterator.h | 65 - .../c++/v1/__cxx03/__iterator/insert_iterator.h | 71 - .../c++/v1/__cxx03/__iterator/istream_iterator.h | 86 - .../v1/__cxx03/__iterator/istreambuf_iterator.h | 94 - .../include/c++/v1/__cxx03/__iterator/iterator.h | 33 - .../c++/v1/__cxx03/__iterator/iterator_traits.h | 246 - .../c++/v1/__cxx03/__iterator/move_iterator.h | 166 - .../include/c++/v1/__cxx03/__iterator/next.h | 39 - .../c++/v1/__cxx03/__iterator/ostream_iterator.h | 67 - .../v1/__cxx03/__iterator/ostreambuf_iterator.h | 64 - .../include/c++/v1/__cxx03/__iterator/prev.h | 54 - .../c++/v1/__cxx03/__iterator/reverse_iterator.h | 203 - .../c++/v1/__cxx03/__iterator/segmented_iterator.h | 79 - .../include/c++/v1/__cxx03/__iterator/wrap_iter.h | 188 - third_party/libcxx/include/c++/v1/__cxx03/__locale | 1495 ----- .../c++/v1/__cxx03/__locale_dir/locale_base_api.h | 98 - .../__cxx03/__locale_dir/locale_base_api/android.h | 45 - .../locale_base_api/bsd_locale_defaults.h | 36 - .../locale_base_api/bsd_locale_fallbacks.h | 126 - .../__cxx03/__locale_dir/locale_base_api/fuchsia.h | 18 - .../v1/__cxx03/__locale_dir/locale_base_api/ibm.h | 108 - .../__locale_dir/locale_base_api/locale_guard.h | 78 - .../v1/__cxx03/__locale_dir/locale_base_api/musl.h | 31 - .../__cxx03/__locale_dir/locale_base_api/newlib.h | 12 - .../__cxx03/__locale_dir/locale_base_api/openbsd.h | 19 - .../__cxx03/__locale_dir/locale_base_api/win32.h | 235 - .../libcxx/include/c++/v1/__cxx03/__math/abs.h | 46 - .../include/c++/v1/__cxx03/__math/copysign.h | 45 - .../c++/v1/__cxx03/__math/error_functions.h | 60 - .../c++/v1/__cxx03/__math/exponential_functions.h | 171 - .../libcxx/include/c++/v1/__cxx03/__math/fdim.h | 48 - .../libcxx/include/c++/v1/__cxx03/__math/fma.h | 55 - .../libcxx/include/c++/v1/__cxx03/__math/gamma.h | 62 - .../c++/v1/__cxx03/__math/hyperbolic_functions.h | 76 - .../libcxx/include/c++/v1/__cxx03/__math/hypot.h | 58 - .../__cxx03/__math/inverse_hyperbolic_functions.h | 76 - .../__math/inverse_trigonometric_functions.h | 99 - .../include/c++/v1/__cxx03/__math/logarithms.h | 124 - .../libcxx/include/c++/v1/__cxx03/__math/min_max.h | 74 - .../libcxx/include/c++/v1/__cxx03/__math/modulo.h | 63 - .../include/c++/v1/__cxx03/__math/remainder.h | 73 - .../libcxx/include/c++/v1/__cxx03/__math/roots.h | 62 - .../c++/v1/__cxx03/__math/rounding_functions.h | 245 - .../libcxx/include/c++/v1/__cxx03/__math/traits.h | 189 - .../v1/__cxx03/__math/trigonometric_functions.h | 76 - .../libcxx/include/c++/v1/__cxx03/__mbstate_t.h | 54 - .../include/c++/v1/__cxx03/__memory/addressof.h | 56 - .../libcxx/include/c++/v1/__cxx03/__memory/align.h | 25 - .../c++/v1/__cxx03/__memory/aligned_alloc.h | 53 - .../c++/v1/__cxx03/__memory/allocate_at_least.h | 36 - .../c++/v1/__cxx03/__memory/allocation_guard.h | 108 - .../include/c++/v1/__cxx03/__memory/allocator.h | 162 - .../c++/v1/__cxx03/__memory/allocator_arg_t.h | 32 - .../c++/v1/__cxx03/__memory/allocator_destructor.h | 40 - .../c++/v1/__cxx03/__memory/allocator_traits.h | 371 -- .../c++/v1/__cxx03/__memory/assume_aligned.h | 41 - .../include/c++/v1/__cxx03/__memory/auto_ptr.h | 88 - .../v1/__cxx03/__memory/builtin_new_allocator.h | 67 - .../c++/v1/__cxx03/__memory/compressed_pair.h | 139 - .../include/c++/v1/__cxx03/__memory/construct_at.h | 77 - .../include/c++/v1/__cxx03/__memory/destruct_n.h | 63 - .../c++/v1/__cxx03/__memory/pointer_traits.h | 217 - .../c++/v1/__cxx03/__memory/raw_storage_iterator.h | 66 - .../include/c++/v1/__cxx03/__memory/shared_ptr.h | 1217 ---- .../c++/v1/__cxx03/__memory/swap_allocator.h | 41 - .../include/c++/v1/__cxx03/__memory/temp_value.h | 45 - .../c++/v1/__cxx03/__memory/temporary_buffer.h | 75 - .../v1/__cxx03/__memory/uninitialized_algorithms.h | 310 -- .../include/c++/v1/__cxx03/__memory/unique_ptr.h | 553 -- .../c++/v1/__cxx03/__memory/uses_allocator.h | 47 - .../include/c++/v1/__cxx03/__memory/voidify.h | 30 - .../include/c++/v1/__cxx03/__mutex/lock_guard.h | 48 - .../libcxx/include/c++/v1/__cxx03/__mutex/mutex.h | 53 - .../include/c++/v1/__cxx03/__mutex/once_flag.h | 102 - .../include/c++/v1/__cxx03/__mutex/tag_types.h | 34 - .../include/c++/v1/__cxx03/__mutex/unique_lock.h | 177 - .../include/c++/v1/__cxx03/__numeric/accumulate.h | 44 - .../c++/v1/__cxx03/__numeric/adjacent_difference.h | 60 - .../c++/v1/__cxx03/__numeric/inner_product.h | 50 - .../libcxx/include/c++/v1/__cxx03/__numeric/iota.h | 29 - .../include/c++/v1/__cxx03/__numeric/partial_sum.h | 58 - .../c++/v1/__cxx03/__ostream/basic_ostream.h | 797 --- .../v1/__cxx03/__random/bernoulli_distribution.h | 118 - .../v1/__cxx03/__random/binomial_distribution.h | 192 - .../c++/v1/__cxx03/__random/cauchy_distribution.h | 133 - .../v1/__cxx03/__random/chi_squared_distribution.h | 120 - .../c++/v1/__cxx03/__random/clamp_to_integral.h | 59 - .../v1/__cxx03/__random/default_random_engine.h | 25 - .../c++/v1/__cxx03/__random/discard_block_engine.h | 161 - .../v1/__cxx03/__random/discrete_distribution.h | 206 - .../v1/__cxx03/__random/exponential_distribution.h | 127 - .../__cxx03/__random/extreme_value_distribution.h | 133 - .../v1/__cxx03/__random/fisher_f_distribution.h | 132 - .../c++/v1/__cxx03/__random/gamma_distribution.h | 175 - .../c++/v1/__cxx03/__random/generate_canonical.h | 46 - .../v1/__cxx03/__random/geometric_distribution.h | 115 - .../v1/__cxx03/__random/independent_bits_engine.h | 197 - .../c++/v1/__cxx03/__random/is_seed_sequence.h | 31 - .../include/c++/v1/__cxx03/__random/is_valid.h | 94 - .../include/c++/v1/__cxx03/__random/knuth_b.h | 26 - .../__cxx03/__random/linear_congruential_engine.h | 378 -- .../libcxx/include/c++/v1/__cxx03/__random/log2.h | 66 - .../v1/__cxx03/__random/lognormal_distribution.h | 121 - .../v1/__cxx03/__random/mersenne_twister_engine.h | 829 --- .../__random/negative_binomial_distribution.h | 152 - .../c++/v1/__cxx03/__random/normal_distribution.h | 170 - .../__random/piecewise_constant_distribution.h | 269 - .../__random/piecewise_linear_distribution.h | 282 - .../c++/v1/__cxx03/__random/poisson_distribution.h | 236 - .../c++/v1/__cxx03/__random/random_device.h | 76 - .../include/c++/v1/__cxx03/__random/ranlux.h | 31 - .../include/c++/v1/__cxx03/__random/seed_seq.h | 159 - .../c++/v1/__cxx03/__random/shuffle_order_engine.h | 222 - .../v1/__cxx03/__random/student_t_distribution.h | 127 - .../__cxx03/__random/subtract_with_carry_engine.h | 270 - .../v1/__cxx03/__random/uniform_int_distribution.h | 253 - .../__cxx03/__random/uniform_real_distribution.h | 132 - .../c++/v1/__cxx03/__random/weibull_distribution.h | 126 - .../libcxx/include/c++/v1/__cxx03/__split_buffer | 544 -- .../include/c++/v1/__cxx03/__std_clang_module | 215 - .../include/c++/v1/__cxx03/__std_mbstate_t.h | 29 - .../include/c++/v1/__cxx03/__string/char_traits.h | 496 -- .../v1/__cxx03/__string/constexpr_c_functions.h | 223 - .../v1/__cxx03/__string/extern_template_lists.h | 133 - .../c++/v1/__cxx03/__support/ibm/gettod_zos.h | 52 - .../c++/v1/__cxx03/__support/ibm/locale_mgmt_zos.h | 53 - .../c++/v1/__cxx03/__support/ibm/nanosleep.h | 55 - .../__cxx03/__support/xlocale/__nop_locale_mgmt.h | 35 - .../__cxx03/__support/xlocale/__posix_l_fallback.h | 107 - .../__support/xlocale/__strtonum_fallback.h | 45 - .../include/c++/v1/__cxx03/__system_error/errc.h | 266 - .../c++/v1/__cxx03/__system_error/error_category.h | 64 - .../c++/v1/__cxx03/__system_error/error_code.h | 123 - .../v1/__cxx03/__system_error/error_condition.h | 109 - .../c++/v1/__cxx03/__system_error/system_error.h | 54 - .../libcxx/include/c++/v1/__cxx03/__thread/id.h | 102 - .../c++/v1/__cxx03/__thread/poll_with_backoff.h | 67 - .../include/c++/v1/__cxx03/__thread/support.h | 123 - .../include/c++/v1/__cxx03/__thread/support/c11.h | 191 - .../c++/v1/__cxx03/__thread/support/external.h | 21 - .../c++/v1/__cxx03/__thread/support/pthread.h | 221 - .../c++/v1/__cxx03/__thread/support/windows.h | 131 - .../include/c++/v1/__cxx03/__thread/this_thread.h | 74 - .../include/c++/v1/__cxx03/__thread/thread.h | 218 - .../c++/v1/__cxx03/__thread/timed_backoff_policy.h | 44 - third_party/libcxx/include/c++/v1/__cxx03/__tree | 2106 ------- .../include/c++/v1/__cxx03/__tuple/find_index.h | 20 - .../c++/v1/__cxx03/__tuple/make_tuple_types.h | 28 - .../c++/v1/__cxx03/__tuple/sfinae_helpers.h | 36 - .../include/c++/v1/__cxx03/__tuple/tuple_element.h | 43 - .../include/c++/v1/__cxx03/__tuple/tuple_indices.h | 20 - .../include/c++/v1/__cxx03/__tuple/tuple_like.h | 26 - .../c++/v1/__cxx03/__tuple/tuple_like_ext.h | 47 - .../v1/__cxx03/__tuple/tuple_like_no_subrange.h | 29 - .../include/c++/v1/__cxx03/__tuple/tuple_size.h | 37 - .../include/c++/v1/__cxx03/__tuple/tuple_types.h | 25 - .../c++/v1/__cxx03/__type_traits/add_const.h | 27 - .../include/c++/v1/__cxx03/__type_traits/add_cv.h | 27 - .../__cxx03/__type_traits/add_lvalue_reference.h | 49 - .../c++/v1/__cxx03/__type_traits/add_pointer.h | 50 - .../__cxx03/__type_traits/add_rvalue_reference.h | 49 - .../c++/v1/__cxx03/__type_traits/add_volatile.h | 27 - .../c++/v1/__cxx03/__type_traits/aligned_storage.h | 129 - .../c++/v1/__cxx03/__type_traits/aligned_union.h | 46 - .../c++/v1/__cxx03/__type_traits/alignment_of.h | 27 - .../c++/v1/__cxx03/__type_traits/can_extract_key.h | 53 - .../c++/v1/__cxx03/__type_traits/common_type.h | 79 - .../c++/v1/__cxx03/__type_traits/conditional.h | 53 - .../c++/v1/__cxx03/__type_traits/conjunction.h | 49 - .../include/c++/v1/__cxx03/__type_traits/copy_cv.h | 51 - .../c++/v1/__cxx03/__type_traits/copy_cvref.h | 43 - .../c++/v1/__cxx03/__type_traits/datasizeof.h | 65 - .../include/c++/v1/__cxx03/__type_traits/decay.h | 68 - .../c++/v1/__cxx03/__type_traits/dependent_type.h | 25 - .../c++/v1/__cxx03/__type_traits/desugars_to.h | 40 - .../c++/v1/__cxx03/__type_traits/disjunction.h | 48 - .../c++/v1/__cxx03/__type_traits/enable_if.h | 32 - .../include/c++/v1/__cxx03/__type_traits/extent.h | 44 - .../__cxx03/__type_traits/has_virtual_destructor.h | 26 - .../v1/__cxx03/__type_traits/integral_constant.h | 39 - .../include/c++/v1/__cxx03/__type_traits/invoke.h | 214 - .../c++/v1/__cxx03/__type_traits/is_abstract.h | 26 - .../c++/v1/__cxx03/__type_traits/is_allocator.h | 34 - .../__cxx03/__type_traits/is_always_bitcastable.h | 85 - .../c++/v1/__cxx03/__type_traits/is_arithmetic.h | 29 - .../c++/v1/__cxx03/__type_traits/is_array.h | 41 - .../c++/v1/__cxx03/__type_traits/is_assignable.h | 37 - .../c++/v1/__cxx03/__type_traits/is_base_of.h | 26 - .../v1/__cxx03/__type_traits/is_bounded_array.h | 29 - .../c++/v1/__cxx03/__type_traits/is_callable.h | 32 - .../v1/__cxx03/__type_traits/is_char_like_type.h | 28 - .../c++/v1/__cxx03/__type_traits/is_class.h | 26 - .../c++/v1/__cxx03/__type_traits/is_compound.h | 36 - .../c++/v1/__cxx03/__type_traits/is_const.h | 37 - .../__cxx03/__type_traits/is_constant_evaluated.h | 26 - .../v1/__cxx03/__type_traits/is_constructible.h | 39 - .../c++/v1/__cxx03/__type_traits/is_convertible.h | 26 - .../v1/__cxx03/__type_traits/is_core_convertible.h | 35 - .../c++/v1/__cxx03/__type_traits/is_destructible.h | 87 - .../c++/v1/__cxx03/__type_traits/is_empty.h | 26 - .../include/c++/v1/__cxx03/__type_traits/is_enum.h | 26 - .../__cxx03/__type_traits/is_equality_comparable.h | 88 - .../v1/__cxx03/__type_traits/is_execution_policy.h | 19 - .../c++/v1/__cxx03/__type_traits/is_final.h | 26 - .../v1/__cxx03/__type_traits/is_floating_point.h | 34 - .../c++/v1/__cxx03/__type_traits/is_function.h | 26 - .../c++/v1/__cxx03/__type_traits/is_fundamental.h | 38 - .../is_implicitly_default_constructible.h | 24 - .../c++/v1/__cxx03/__type_traits/is_integral.h | 64 - .../c++/v1/__cxx03/__type_traits/is_literal_type.h | 26 - .../v1/__cxx03/__type_traits/is_member_pointer.h | 32 - .../__cxx03/__type_traits/is_nothrow_assignable.h | 41 - .../__type_traits/is_nothrow_constructible.h | 41 - .../__type_traits/is_nothrow_destructible.h | 58 - .../c++/v1/__cxx03/__type_traits/is_null_pointer.h | 27 - .../c++/v1/__cxx03/__type_traits/is_object.h | 26 - .../include/c++/v1/__cxx03/__type_traits/is_pod.h | 26 - .../c++/v1/__cxx03/__type_traits/is_pointer.h | 55 - .../c++/v1/__cxx03/__type_traits/is_polymorphic.h | 26 - .../v1/__cxx03/__type_traits/is_primary_template.h | 31 - .../c++/v1/__cxx03/__type_traits/is_reference.h | 48 - .../__cxx03/__type_traits/is_reference_wrapper.h | 32 - .../v1/__cxx03/__type_traits/is_referenceable.h | 41 - .../include/c++/v1/__cxx03/__type_traits/is_same.h | 39 - .../c++/v1/__cxx03/__type_traits/is_scalar.h | 59 - .../c++/v1/__cxx03/__type_traits/is_signed.h | 49 - .../v1/__cxx03/__type_traits/is_signed_integer.h | 35 - .../v1/__cxx03/__type_traits/is_specialization.h | 35 - .../v1/__cxx03/__type_traits/is_standard_layout.h | 26 - .../c++/v1/__cxx03/__type_traits/is_swappable.h | 60 - .../c++/v1/__cxx03/__type_traits/is_trivial.h | 26 - .../__type_traits/is_trivially_assignable.h | 41 - .../__type_traits/is_trivially_constructible.h | 41 - .../__cxx03/__type_traits/is_trivially_copyable.h | 27 - .../__type_traits/is_trivially_destructible.h | 42 - .../is_trivially_lexicographically_comparable.h | 53 - .../__type_traits/is_trivially_relocatable.h | 42 - .../v1/__cxx03/__type_traits/is_unbounded_array.h | 28 - .../c++/v1/__cxx03/__type_traits/is_union.h | 26 - .../c++/v1/__cxx03/__type_traits/is_unsigned.h | 49 - .../v1/__cxx03/__type_traits/is_unsigned_integer.h | 35 - .../v1/__cxx03/__type_traits/is_valid_expansion.h | 31 - .../include/c++/v1/__cxx03/__type_traits/is_void.h | 26 - .../c++/v1/__cxx03/__type_traits/is_volatile.h | 37 - .../include/c++/v1/__cxx03/__type_traits/lazy.h | 25 - .../__cxx03/__type_traits/make_32_64_or_128_bit.h | 46 - .../__cxx03/__type_traits/make_const_lvalue_ref.h | 26 - .../c++/v1/__cxx03/__type_traits/make_signed.h | 84 - .../c++/v1/__cxx03/__type_traits/make_unsigned.h | 89 - .../c++/v1/__cxx03/__type_traits/maybe_const.h | 26 - .../include/c++/v1/__cxx03/__type_traits/nat.h | 24 - .../c++/v1/__cxx03/__type_traits/negation.h | 26 - .../__type_traits/noexcept_move_assign_container.h | 31 - .../include/c++/v1/__cxx03/__type_traits/promote.h | 128 - .../include/c++/v1/__cxx03/__type_traits/rank.h | 41 - .../v1/__cxx03/__type_traits/remove_all_extents.h | 49 - .../c++/v1/__cxx03/__type_traits/remove_const.h | 44 - .../v1/__cxx03/__type_traits/remove_const_ref.h | 27 - .../c++/v1/__cxx03/__type_traits/remove_cv.h | 42 - .../c++/v1/__cxx03/__type_traits/remove_cvref.h | 36 - .../c++/v1/__cxx03/__type_traits/remove_extent.h | 49 - .../c++/v1/__cxx03/__type_traits/remove_pointer.h | 48 - .../v1/__cxx03/__type_traits/remove_reference.h | 42 - .../c++/v1/__cxx03/__type_traits/remove_volatile.h | 44 - .../c++/v1/__cxx03/__type_traits/result_of.h | 31 - .../c++/v1/__cxx03/__type_traits/strip_signature.h | 18 - .../c++/v1/__cxx03/__type_traits/type_identity.h | 30 - .../c++/v1/__cxx03/__type_traits/type_list.h | 42 - .../c++/v1/__cxx03/__type_traits/underlying_type.h | 37 - .../c++/v1/__cxx03/__type_traits/unwrap_ref.h | 37 - .../include/c++/v1/__cxx03/__type_traits/void_t.h | 25 - .../libcxx/include/c++/v1/__cxx03/__undef_macros | 28 - .../include/c++/v1/__cxx03/__utility/as_lvalue.h | 28 - .../include/c++/v1/__cxx03/__utility/auto_cast.h | 22 - .../c++/v1/__cxx03/__utility/convert_to_integral.h | 63 - .../include/c++/v1/__cxx03/__utility/declval.h | 38 - .../include/c++/v1/__cxx03/__utility/empty.h | 24 - .../c++/v1/__cxx03/__utility/exception_guard.h | 136 - .../include/c++/v1/__cxx03/__utility/forward.h | 38 - .../c++/v1/__cxx03/__utility/integer_sequence.h | 48 - .../c++/v1/__cxx03/__utility/is_pointer_in_range.h | 62 - .../c++/v1/__cxx03/__utility/is_valid_range.h | 36 - .../libcxx/include/c++/v1/__cxx03/__utility/move.h | 49 - .../include/c++/v1/__cxx03/__utility/no_destroy.h | 54 - .../libcxx/include/c++/v1/__cxx03/__utility/pair.h | 274 - .../c++/v1/__cxx03/__utility/piecewise_construct.h | 26 - .../c++/v1/__cxx03/__utility/priority_tag.h | 28 - .../v1/__cxx03/__utility/private_constructor_tag.h | 28 - .../include/c++/v1/__cxx03/__utility/rel_ops.h | 46 - .../c++/v1/__cxx03/__utility/small_buffer.h | 26 - .../libcxx/include/c++/v1/__cxx03/__utility/swap.h | 52 - .../include/c++/v1/__cxx03/__utility/unreachable.h | 28 - .../include/c++/v1/__cxx03/__variant/monostate.h | 26 - .../libcxx/include/c++/v1/__cxx03/__verbose_abort | 52 - .../libcxx/include/c++/v1/__cxx03/__verbose_trap | 36 - .../libcxx/include/c++/v1/__cxx03/algorithm | 1924 ------- third_party/libcxx/include/c++/v1/__cxx03/array | 419 -- third_party/libcxx/include/c++/v1/__cxx03/atomic | 627 --- third_party/libcxx/include/c++/v1/__cxx03/bitset | 886 --- third_party/libcxx/include/c++/v1/__cxx03/cassert | 31 - third_party/libcxx/include/c++/v1/__cxx03/ccomplex | 26 - third_party/libcxx/include/c++/v1/__cxx03/cctype | 127 - third_party/libcxx/include/c++/v1/__cxx03/cerrno | 48 - third_party/libcxx/include/c++/v1/__cxx03/cfenv | 90 - third_party/libcxx/include/c++/v1/__cxx03/cfloat | 86 - third_party/libcxx/include/c++/v1/__cxx03/chrono | 969 ---- .../libcxx/include/c++/v1/__cxx03/cinttypes | 270 - third_party/libcxx/include/c++/v1/__cxx03/ciso646 | 24 - third_party/libcxx/include/c++/v1/__cxx03/climits | 48 - third_party/libcxx/include/c++/v1/__cxx03/clocale | 61 - third_party/libcxx/include/c++/v1/__cxx03/cmath | 606 -- third_party/libcxx/include/c++/v1/__cxx03/codecvt | 591 -- third_party/libcxx/include/c++/v1/__cxx03/complex | 1298 ----- .../include/c++/v1/__cxx03/condition_variable | 267 - third_party/libcxx/include/c++/v1/__cxx03/csetjmp | 54 - third_party/libcxx/include/c++/v1/__cxx03/csignal | 64 - third_party/libcxx/include/c++/v1/__cxx03/cstdarg | 54 - third_party/libcxx/include/c++/v1/__cxx03/cstdbool | 31 - third_party/libcxx/include/c++/v1/__cxx03/cstddef | 64 - third_party/libcxx/include/c++/v1/__cxx03/cstdint | 199 - third_party/libcxx/include/c++/v1/__cxx03/cstdio | 172 - third_party/libcxx/include/c++/v1/__cxx03/cstdlib | 147 - third_party/libcxx/include/c++/v1/__cxx03/cstring | 104 - third_party/libcxx/include/c++/v1/__cxx03/ctgmath | 28 - third_party/libcxx/include/c++/v1/__cxx03/ctime | 80 - third_party/libcxx/include/c++/v1/__cxx03/cuchar | 59 - third_party/libcxx/include/c++/v1/__cxx03/cwchar | 256 - third_party/libcxx/include/c++/v1/__cxx03/cwctype | 97 - third_party/libcxx/include/c++/v1/__cxx03/deque | 2134 ------- .../libcxx/include/c++/v1/__cxx03/exception | 96 - .../include/c++/v1/__cxx03/experimental/__config | 45 - .../include/c++/v1/__cxx03/experimental/utility | 40 - .../libcxx/include/c++/v1/__cxx03/ext/__hash | 85 - .../libcxx/include/c++/v1/__cxx03/ext/hash_map | 864 --- .../libcxx/include/c++/v1/__cxx03/ext/hash_set | 583 -- .../libcxx/include/c++/v1/__cxx03/forward_list | 1245 ----- third_party/libcxx/include/c++/v1/__cxx03/fstream | 1464 ----- .../libcxx/include/c++/v1/__cxx03/functional | 576 -- third_party/libcxx/include/c++/v1/__cxx03/future | 1946 ------- third_party/libcxx/include/c++/v1/__cxx03/iomanip | 510 -- third_party/libcxx/include/c++/v1/__cxx03/ios | 877 --- third_party/libcxx/include/c++/v1/__cxx03/iosfwd | 166 - third_party/libcxx/include/c++/v1/__cxx03/iostream | 67 - third_party/libcxx/include/c++/v1/__cxx03/istream | 1345 ----- third_party/libcxx/include/c++/v1/__cxx03/iterator | 718 --- third_party/libcxx/include/c++/v1/__cxx03/limits | 544 -- third_party/libcxx/include/c++/v1/__cxx03/list | 1368 ----- third_party/libcxx/include/c++/v1/__cxx03/locale | 3724 ------------- third_party/libcxx/include/c++/v1/__cxx03/locale.h | 46 - third_party/libcxx/include/c++/v1/__cxx03/map | 1332 ----- third_party/libcxx/include/c++/v1/__cxx03/math.h | 520 -- third_party/libcxx/include/c++/v1/__cxx03/memory | 973 ---- .../libcxx/include/c++/v1/__cxx03/module.modulemap | 2132 ------- third_party/libcxx/include/c++/v1/__cxx03/mutex | 375 -- third_party/libcxx/include/c++/v1/__cxx03/new | 326 -- third_party/libcxx/include/c++/v1/__cxx03/numeric | 187 - third_party/libcxx/include/c++/v1/__cxx03/ostream | 195 - third_party/libcxx/include/c++/v1/__cxx03/queue | 588 -- third_party/libcxx/include/c++/v1/__cxx03/random | 1735 ------ third_party/libcxx/include/c++/v1/__cxx03/ratio | 461 -- third_party/libcxx/include/c++/v1/__cxx03/regex | 5638 ------------------- third_party/libcxx/include/c++/v1/__cxx03/set | 914 --- third_party/libcxx/include/c++/v1/__cxx03/sstream | 906 --- third_party/libcxx/include/c++/v1/__cxx03/stack | 250 - .../libcxx/include/c++/v1/__cxx03/stdatomic.h | 136 - .../libcxx/include/c++/v1/__cxx03/stdexcept | 286 - third_party/libcxx/include/c++/v1/__cxx03/stdint.h | 127 - third_party/libcxx/include/c++/v1/__cxx03/stdlib.h | 151 - .../libcxx/include/c++/v1/__cxx03/streambuf | 445 -- third_party/libcxx/include/c++/v1/__cxx03/string | 3570 ------------ third_party/libcxx/include/c++/v1/__cxx03/string.h | 110 - .../libcxx/include/c++/v1/__cxx03/string_view | 733 --- .../libcxx/include/c++/v1/__cxx03/strstream | 267 - .../libcxx/include/c++/v1/__cxx03/system_error | 166 - third_party/libcxx/include/c++/v1/__cxx03/thread | 123 - .../libcxx/include/c++/v1/__cxx03/type_traits | 497 -- .../libcxx/include/c++/v1/__cxx03/typeindex | 92 - third_party/libcxx/include/c++/v1/__cxx03/typeinfo | 383 -- third_party/libcxx/include/c++/v1/__cxx03/uchar.h | 41 - .../libcxx/include/c++/v1/__cxx03/unordered_map | 1456 ----- .../libcxx/include/c++/v1/__cxx03/unordered_set | 1045 ---- third_party/libcxx/include/c++/v1/__cxx03/utility | 281 - third_party/libcxx/include/c++/v1/__cxx03/valarray | 3197 ----------- third_party/libcxx/include/c++/v1/__cxx03/vector | 2454 -------- third_party/libcxx/include/c++/v1/__cxx03/version | 273 - third_party/libcxx/include/c++/v1/__cxx03/wchar.h | 211 - .../libcxx/include/c++/v1/__cxxabi_config.h | 137 - .../include/c++/v1/__debug_utils/randomize_range.h | 42 - .../include/c++/v1/__debug_utils/sanitizers.h | 129 - .../v1/__debug_utils/strict_weak_ordering_check.h | 77 - .../libcxx/include/c++/v1/__exception/exception.h | 96 - .../include/c++/v1/__exception/exception_ptr.h | 226 - .../include/c++/v1/__exception/nested_exception.h | 100 - .../libcxx/include/c++/v1/__exception/operations.h | 42 - .../libcxx/include/c++/v1/__exception/terminate.h | 22 - .../c++/v1/__expected/bad_expected_access.h | 75 - .../libcxx/include/c++/v1/__expected/expected.h | 1907 ------- .../libcxx/include/c++/v1/__expected/unexpect.h | 32 - .../libcxx/include/c++/v1/__expected/unexpected.h | 127 - .../include/c++/v1/__filesystem/copy_options.h | 69 - .../include/c++/v1/__filesystem/directory_entry.h | 474 -- .../c++/v1/__filesystem/directory_iterator.h | 148 - .../c++/v1/__filesystem/directory_options.h | 60 - .../include/c++/v1/__filesystem/file_status.h | 67 - .../include/c++/v1/__filesystem/file_time_type.h | 31 - .../libcxx/include/c++/v1/__filesystem/file_type.h | 42 - .../include/c++/v1/__filesystem/filesystem_error.h | 87 - .../include/c++/v1/__filesystem/operations.h | 341 -- .../libcxx/include/c++/v1/__filesystem/path.h | 919 --- .../include/c++/v1/__filesystem/path_iterator.h | 110 - .../include/c++/v1/__filesystem/perm_options.h | 57 - .../libcxx/include/c++/v1/__filesystem/perms.h | 80 - .../v1/__filesystem/recursive_directory_iterator.h | 158 - .../include/c++/v1/__filesystem/space_info.h | 38 - .../libcxx/include/c++/v1/__filesystem/u8path.h | 93 - .../libcxx/include/c++/v1/__flat_map/flat_map.h | 1289 ----- .../include/c++/v1/__flat_map/flat_multimap.h | 1081 ---- .../include/c++/v1/__flat_map/key_value_iterator.h | 217 - .../include/c++/v1/__flat_map/sorted_equivalent.h | 31 - .../include/c++/v1/__flat_map/sorted_unique.h | 31 - .../libcxx/include/c++/v1/__flat_map/utils.h | 122 - .../include/c++/v1/__flat_set/flat_multiset.h | 851 --- .../libcxx/include/c++/v1/__flat_set/flat_set.h | 892 --- .../libcxx/include/c++/v1/__flat_set/ra_iterator.h | 157 - .../libcxx/include/c++/v1/__flat_set/utils.h | 82 - .../libcxx/include/c++/v1/__format/buffer.h | 708 --- .../libcxx/include/c++/v1/__format/concepts.h | 69 - .../include/c++/v1/__format/container_adaptor.h | 73 - .../include/c++/v1/__format/enable_insertable.h | 35 - .../include/c++/v1/__format/escaped_output_table.h | 887 --- .../v1/__format/extended_grapheme_cluster_table.h | 1669 ------ .../libcxx/include/c++/v1/__format/fmt_pair_like.h | 42 - .../libcxx/include/c++/v1/__format/format_arg.h | 399 -- .../include/c++/v1/__format/format_arg_store.h | 282 - .../libcxx/include/c++/v1/__format/format_args.h | 78 - .../include/c++/v1/__format/format_context.h | 212 - .../libcxx/include/c++/v1/__format/format_error.h | 50 - .../include/c++/v1/__format/format_functions.h | 722 --- .../include/c++/v1/__format/format_parse_context.h | 105 - .../libcxx/include/c++/v1/__format/format_string.h | 160 - .../include/c++/v1/__format/format_to_n_result.h | 35 - .../libcxx/include/c++/v1/__format/formatter.h | 58 - .../include/c++/v1/__format/formatter_bool.h | 55 - .../include/c++/v1/__format/formatter_bool_impl.h | 60 - .../include/c++/v1/__format/formatter_char.h | 101 - .../c++/v1/__format/formatter_floating_point.h | 792 --- .../include/c++/v1/__format/formatter_integer.h | 126 - .../include/c++/v1/__format/formatter_integral.h | 446 -- .../include/c++/v1/__format/formatter_output.h | 313 -- .../include/c++/v1/__format/formatter_pointer.h | 80 - .../include/c++/v1/__format/formatter_string.h | 173 - .../include/c++/v1/__format/formatter_tuple.h | 148 - .../c++/v1/__format/indic_conjunct_break_table.h | 553 -- .../c++/v1/__format/parser_std_format_spec.h | 1172 ---- .../c++/v1/__format/range_default_formatter.h | 176 - .../libcxx/include/c++/v1/__format/range_format.h | 57 - .../include/c++/v1/__format/range_formatter.h | 265 - .../libcxx/include/c++/v1/__format/unicode.h | 602 -- .../c++/v1/__format/width_estimation_table.h | 275 - .../libcxx/include/c++/v1/__format/write_escaped.h | 242 - .../include/c++/v1/__functional/binary_function.h | 53 - .../include/c++/v1/__functional/binary_negate.h | 51 - .../libcxx/include/c++/v1/__functional/bind.h | 288 - .../libcxx/include/c++/v1/__functional/bind_back.h | 83 - .../include/c++/v1/__functional/bind_front.h | 103 - .../libcxx/include/c++/v1/__functional/binder1st.h | 54 - .../libcxx/include/c++/v1/__functional/binder2nd.h | 54 - .../c++/v1/__functional/boyer_moore_searcher.h | 305 - .../libcxx/include/c++/v1/__functional/compose.h | 53 - .../include/c++/v1/__functional/default_searcher.h | 54 - .../libcxx/include/c++/v1/__functional/function.h | 813 --- .../libcxx/include/c++/v1/__functional/hash.h | 464 -- .../libcxx/include/c++/v1/__functional/identity.h | 65 - .../libcxx/include/c++/v1/__functional/invoke.h | 55 - .../include/c++/v1/__functional/is_transparent.h | 42 - .../libcxx/include/c++/v1/__functional/mem_fn.h | 53 - .../include/c++/v1/__functional/mem_fun_ref.h | 145 - .../libcxx/include/c++/v1/__functional/not_fn.h | 76 - .../include/c++/v1/__functional/operations.h | 569 -- .../include/c++/v1/__functional/perfect_forward.h | 105 - .../v1/__functional/pointer_to_binary_function.h | 43 - .../v1/__functional/pointer_to_unary_function.h | 43 - .../c++/v1/__functional/ranges_operations.h | 122 - .../c++/v1/__functional/reference_wrapper.h | 192 - .../include/c++/v1/__functional/unary_function.h | 50 - .../include/c++/v1/__functional/unary_negate.h | 47 - .../include/c++/v1/__functional/weak_result_type.h | 214 - third_party/libcxx/include/c++/v1/__fwd/array.h | 47 - .../libcxx/include/c++/v1/__fwd/bit_reference.h | 44 - third_party/libcxx/include/c++/v1/__fwd/byte.h | 26 - third_party/libcxx/include/c++/v1/__fwd/complex.h | 42 - third_party/libcxx/include/c++/v1/__fwd/deque.h | 26 - third_party/libcxx/include/c++/v1/__fwd/format.h | 55 - third_party/libcxx/include/c++/v1/__fwd/fstream.h | 53 - .../libcxx/include/c++/v1/__fwd/functional.h | 35 - third_party/libcxx/include/c++/v1/__fwd/get.h | 24 - third_party/libcxx/include/c++/v1/__fwd/ios.h | 43 - third_party/libcxx/include/c++/v1/__fwd/istream.h | 43 - third_party/libcxx/include/c++/v1/__fwd/mdspan.h | 57 - third_party/libcxx/include/c++/v1/__fwd/memory.h | 28 - .../libcxx/include/c++/v1/__fwd/memory_resource.h | 31 - third_party/libcxx/include/c++/v1/__fwd/ostream.h | 35 - third_party/libcxx/include/c++/v1/__fwd/pair.h | 51 - third_party/libcxx/include/c++/v1/__fwd/queue.h | 31 - third_party/libcxx/include/c++/v1/__fwd/span.h | 38 - third_party/libcxx/include/c++/v1/__fwd/sstream.h | 58 - third_party/libcxx/include/c++/v1/__fwd/stack.h | 26 - .../libcxx/include/c++/v1/__fwd/streambuf.h | 35 - third_party/libcxx/include/c++/v1/__fwd/string.h | 107 - .../libcxx/include/c++/v1/__fwd/string_view.h | 50 - third_party/libcxx/include/c++/v1/__fwd/subrange.h | 49 - third_party/libcxx/include/c++/v1/__fwd/tuple.h | 66 - third_party/libcxx/include/c++/v1/__fwd/variant.h | 68 - third_party/libcxx/include/c++/v1/__fwd/vector.h | 29 - third_party/libcxx/include/c++/v1/__hash_table | 2124 ------- third_party/libcxx/include/c++/v1/__ios/fpos.h | 76 - .../libcxx/include/c++/v1/__iterator/access.h | 95 - .../libcxx/include/c++/v1/__iterator/advance.h | 199 - .../include/c++/v1/__iterator/aliasing_iterator.h | 130 - .../c++/v1/__iterator/back_insert_iterator.h | 79 - .../include/c++/v1/__iterator/bounded_iter.h | 289 - .../c++/v1/__iterator/capacity_aware_iterator.h | 186 - .../include/c++/v1/__iterator/common_iterator.h | 301 - .../libcxx/include/c++/v1/__iterator/concepts.h | 324 -- .../include/c++/v1/__iterator/counted_iterator.h | 289 - .../c++/v1/__iterator/cpp17_iterator_concepts.h | 191 - .../libcxx/include/c++/v1/__iterator/data.h | 48 - .../include/c++/v1/__iterator/default_sentinel.h | 30 - .../libcxx/include/c++/v1/__iterator/distance.h | 117 - .../libcxx/include/c++/v1/__iterator/empty.h | 44 - .../include/c++/v1/__iterator/erase_if_container.h | 43 - .../c++/v1/__iterator/front_insert_iterator.h | 77 - .../c++/v1/__iterator/incrementable_traits.h | 79 - .../c++/v1/__iterator/indirectly_comparable.h | 33 - .../include/c++/v1/__iterator/insert_iterator.h | 89 - .../include/c++/v1/__iterator/istream_iterator.h | 103 - .../c++/v1/__iterator/istreambuf_iterator.h | 110 - .../libcxx/include/c++/v1/__iterator/iter_move.h | 104 - .../libcxx/include/c++/v1/__iterator/iter_swap.h | 108 - .../libcxx/include/c++/v1/__iterator/iterator.h | 46 - .../include/c++/v1/__iterator/iterator_traits.h | 479 -- .../include/c++/v1/__iterator/iterator_with_data.h | 105 - .../libcxx/include/c++/v1/__iterator/mergeable.h | 42 - .../include/c++/v1/__iterator/move_iterator.h | 347 -- .../include/c++/v1/__iterator/move_sentinel.h | 61 - .../libcxx/include/c++/v1/__iterator/next.h | 74 - .../include/c++/v1/__iterator/ostream_iterator.h | 69 - .../c++/v1/__iterator/ostreambuf_iterator.h | 94 - .../libcxx/include/c++/v1/__iterator/permutable.h | 34 - .../libcxx/include/c++/v1/__iterator/prev.h | 84 - .../include/c++/v1/__iterator/product_iterator.h | 76 - .../libcxx/include/c++/v1/__iterator/projected.h | 61 - .../c++/v1/__iterator/ranges_iterator_traits.h | 40 - .../include/c++/v1/__iterator/readable_traits.h | 81 - .../include/c++/v1/__iterator/reverse_access.h | 79 - .../include/c++/v1/__iterator/reverse_iterator.h | 324 -- .../include/c++/v1/__iterator/segmented_iterator.h | 80 - .../libcxx/include/c++/v1/__iterator/size.h | 60 - .../libcxx/include/c++/v1/__iterator/sortable.h | 35 - .../c++/v1/__iterator/static_bounded_iter.h | 318 -- .../c++/v1/__iterator/unreachable_sentinel.h | 37 - .../libcxx/include/c++/v1/__iterator/wrap_iter.h | 243 - third_party/libcxx/include/c++/v1/__locale | 1501 ----- .../include/c++/v1/__locale_dir/check_grouping.h | 31 - .../include/c++/v1/__locale_dir/get_c_locale.h | 40 - .../include/c++/v1/__locale_dir/locale_base_api.h | 302 - .../locale_base_api/bsd_locale_fallbacks.h | 130 - .../c++/v1/__locale_dir/locale_base_api/ibm.h | 97 - .../c++/v1/__locale_dir/locale_base_api/openbsd.h | 19 - .../libcxx/include/c++/v1/__locale_dir/messages.h | 143 - .../libcxx/include/c++/v1/__locale_dir/money.h | 873 --- .../libcxx/include/c++/v1/__locale_dir/num.h | 1019 ---- .../include/c++/v1/__locale_dir/pad_and_output.h | 75 - .../include/c++/v1/__locale_dir/scan_keyword.h | 143 - .../include/c++/v1/__locale_dir/support/aix.h | 296 - .../include/c++/v1/__locale_dir/support/apple.h | 20 - .../include/c++/v1/__locale_dir/support/bsd_like.h | 211 - .../include/c++/v1/__locale_dir/support/freebsd.h | 20 - .../include/c++/v1/__locale_dir/support/fuchsia.h | 153 - .../include/c++/v1/__locale_dir/support/linux.h | 244 - .../include/c++/v1/__locale_dir/support/netbsd.h | 20 - .../include/c++/v1/__locale_dir/support/newlib.h | 243 - .../v1/__locale_dir/support/no_locale/characters.h | 92 - .../v1/__locale_dir/support/no_locale/strtonum.h | 40 - .../include/c++/v1/__locale_dir/support/windows.h | 309 -- .../libcxx/include/c++/v1/__locale_dir/time.h | 762 --- .../include/c++/v1/__locale_dir/wbuffer_convert.h | 430 -- .../include/c++/v1/__locale_dir/wstring_convert.h | 254 - .../libcxx/include/c++/v1/__log_hardening_failure | 42 - third_party/libcxx/include/c++/v1/__math/abs.h | 70 - .../libcxx/include/c++/v1/__math/copysign.h | 44 - .../libcxx/include/c++/v1/__math/error_functions.h | 60 - .../include/c++/v1/__math/exponential_functions.h | 171 - third_party/libcxx/include/c++/v1/__math/fdim.h | 48 - third_party/libcxx/include/c++/v1/__math/fma.h | 55 - third_party/libcxx/include/c++/v1/__math/gamma.h | 88 - .../include/c++/v1/__math/hyperbolic_functions.h | 76 - third_party/libcxx/include/c++/v1/__math/hypot.h | 108 - .../c++/v1/__math/inverse_hyperbolic_functions.h | 76 - .../v1/__math/inverse_trigonometric_functions.h | 99 - .../libcxx/include/c++/v1/__math/logarithms.h | 124 - third_party/libcxx/include/c++/v1/__math/min_max.h | 74 - third_party/libcxx/include/c++/v1/__math/modulo.h | 63 - .../libcxx/include/c++/v1/__math/remainder.h | 72 - third_party/libcxx/include/c++/v1/__math/roots.h | 62 - .../include/c++/v1/__math/rounding_functions.h | 245 - .../include/c++/v1/__math/special_functions.h | 84 - third_party/libcxx/include/c++/v1/__math/traits.h | 265 - .../c++/v1/__math/trigonometric_functions.h | 76 - third_party/libcxx/include/c++/v1/__mbstate_t.h | 54 - .../include/c++/v1/__mdspan/aligned_accessor.h | 87 - .../include/c++/v1/__mdspan/default_accessor.h | 65 - .../libcxx/include/c++/v1/__mdspan/extents.h | 536 -- .../libcxx/include/c++/v1/__mdspan/layout_left.h | 203 - .../libcxx/include/c++/v1/__mdspan/layout_right.h | 201 - .../libcxx/include/c++/v1/__mdspan/layout_stride.h | 370 -- .../libcxx/include/c++/v1/__mdspan/mdspan.h | 328 -- .../libcxx/include/c++/v1/__memory/addressof.h | 61 - third_party/libcxx/include/c++/v1/__memory/align.h | 42 - .../include/c++/v1/__memory/allocate_at_least.h | 53 - .../include/c++/v1/__memory/allocation_guard.h | 109 - .../libcxx/include/c++/v1/__memory/allocator.h | 165 - .../include/c++/v1/__memory/allocator_arg_t.h | 75 - .../include/c++/v1/__memory/allocator_destructor.h | 40 - .../include/c++/v1/__memory/allocator_traits.h | 443 -- .../libcxx/include/c++/v1/__memory/array_cookie.h | 123 - .../include/c++/v1/__memory/assume_aligned.h | 50 - .../libcxx/include/c++/v1/__memory/auto_ptr.h | 92 - .../include/c++/v1/__memory/compressed_pair.h | 142 - .../libcxx/include/c++/v1/__memory/concepts.h | 63 - .../libcxx/include/c++/v1/__memory/construct_at.h | 82 - .../libcxx/include/c++/v1/__memory/destroy.h | 71 - .../libcxx/include/c++/v1/__memory/destruct_n.h | 63 - .../libcxx/include/c++/v1/__memory/inout_ptr.h | 109 - .../c++/v1/__memory/is_sufficiently_aligned.h | 39 - .../v1/__memory/noexcept_move_assign_container.h | 37 - .../libcxx/include/c++/v1/__memory/out_ptr.h | 101 - .../include/c++/v1/__memory/pointer_traits.h | 271 - .../include/c++/v1/__memory/ranges_construct_at.h | 72 - .../include/c++/v1/__memory/ranges_destroy.h | 79 - .../v1/__memory/ranges_uninitialized_algorithms.h | 284 - .../include/c++/v1/__memory/raw_storage_iterator.h | 80 - .../libcxx/include/c++/v1/__memory/shared_count.h | 116 - .../libcxx/include/c++/v1/__memory/shared_ptr.h | 1543 ------ .../include/c++/v1/__memory/swap_allocator.h | 54 - .../libcxx/include/c++/v1/__memory/temp_value.h | 57 - .../include/c++/v1/__memory/temporary_buffer.h | 45 - .../c++/v1/__memory/uninitialized_algorithms.h | 577 -- .../libcxx/include/c++/v1/__memory/unique_ptr.h | 813 --- .../c++/v1/__memory/unique_temporary_buffer.h | 93 - .../include/c++/v1/__memory/uses_allocator.h | 52 - .../c++/v1/__memory/uses_allocator_construction.h | 234 - .../libcxx/include/c++/v1/__memory/valid_range.h | 74 - .../c++/v1/__memory_resource/memory_resource.h | 91 - .../__memory_resource/monotonic_buffer_resource.h | 119 - .../v1/__memory_resource/polymorphic_allocator.h | 251 - .../c++/v1/__memory_resource/pool_options.h | 38 - .../__memory_resource/synchronized_pool_resource.h | 95 - .../unsynchronized_pool_resource.h | 106 - .../libcxx/include/c++/v1/__mutex/lock_guard.h | 46 - third_party/libcxx/include/c++/v1/__mutex/mutex.h | 53 - .../libcxx/include/c++/v1/__mutex/once_flag.h | 163 - .../libcxx/include/c++/v1/__mutex/tag_types.h | 44 - .../libcxx/include/c++/v1/__mutex/unique_lock.h | 174 - .../libcxx/include/c++/v1/__new/align_val_t.h | 35 - third_party/libcxx/include/c++/v1/__new/allocate.h | 78 - .../include/c++/v1/__new/destroying_delete_t.h | 29 - .../libcxx/include/c++/v1/__new/exceptions.h | 79 - .../include/c++/v1/__new/global_new_delete.h | 70 - .../include/c++/v1/__new/interference_size.h | 30 - third_party/libcxx/include/c++/v1/__new/launder.h | 34 - .../libcxx/include/c++/v1/__new/new_handler.h | 28 - .../libcxx/include/c++/v1/__new/nothrow_t.h | 29 - .../include/c++/v1/__new/placement_new_delete.h | 34 - third_party/libcxx/include/c++/v1/__node_handle | 210 - .../libcxx/include/c++/v1/__numeric/accumulate.h | 53 - .../include/c++/v1/__numeric/adjacent_difference.h | 68 - .../include/c++/v1/__numeric/exclusive_scan.h | 58 - .../libcxx/include/c++/v1/__numeric/gcd_lcm.h | 120 - .../include/c++/v1/__numeric/inclusive_scan.h | 59 - .../include/c++/v1/__numeric/inner_product.h | 58 - third_party/libcxx/include/c++/v1/__numeric/iota.h | 30 - .../libcxx/include/c++/v1/__numeric/midpoint.h | 83 - .../libcxx/include/c++/v1/__numeric/partial_sum.h | 66 - third_party/libcxx/include/c++/v1/__numeric/pstl.h | 174 - .../libcxx/include/c++/v1/__numeric/ranges_iota.h | 65 - .../libcxx/include/c++/v1/__numeric/reduce.h | 53 - .../c++/v1/__numeric/saturation_arithmetic.h | 154 - .../c++/v1/__numeric/transform_exclusive_scan.h | 42 - .../c++/v1/__numeric/transform_inclusive_scan.h | 52 - .../include/c++/v1/__numeric/transform_reduce.h | 59 - .../include/c++/v1/__ostream/basic_ostream.h | 681 --- .../libcxx/include/c++/v1/__ostream/print.h | 172 - .../c++/v1/__ostream/put_character_sequence.h | 59 - third_party/libcxx/include/c++/v1/__pstl/backend.h | 39 - .../libcxx/include/c++/v1/__pstl/backend_fwd.h | 313 -- .../include/c++/v1/__pstl/backends/default.h | 539 -- .../include/c++/v1/__pstl/backends/libdispatch.h | 402 -- .../libcxx/include/c++/v1/__pstl/backends/serial.h | 185 - .../include/c++/v1/__pstl/backends/std_thread.h | 139 - .../include/c++/v1/__pstl/cpu_algos/any_of.h | 103 - .../include/c++/v1/__pstl/cpu_algos/cpu_traits.h | 89 - .../libcxx/include/c++/v1/__pstl/cpu_algos/fill.h | 70 - .../include/c++/v1/__pstl/cpu_algos/find_if.h | 140 - .../include/c++/v1/__pstl/cpu_algos/for_each.h | 70 - .../libcxx/include/c++/v1/__pstl/cpu_algos/merge.h | 89 - .../include/c++/v1/__pstl/cpu_algos/stable_sort.h | 51 - .../include/c++/v1/__pstl/cpu_algos/transform.h | 156 - .../c++/v1/__pstl/cpu_algos/transform_reduce.h | 219 - .../libcxx/include/c++/v1/__pstl/dispatch.h | 71 - .../include/c++/v1/__pstl/handle_exception.h | 61 - .../c++/v1/__random/bernoulli_distribution.h | 123 - .../c++/v1/__random/binomial_distribution.h | 186 - .../include/c++/v1/__random/cauchy_distribution.h | 139 - .../c++/v1/__random/chi_squared_distribution.h | 125 - .../include/c++/v1/__random/clamp_to_integral.h | 59 - .../c++/v1/__random/default_random_engine.h | 25 - .../include/c++/v1/__random/discard_block_engine.h | 166 - .../c++/v1/__random/discrete_distribution.h | 212 - .../c++/v1/__random/exponential_distribution.h | 132 - .../c++/v1/__random/extreme_value_distribution.h | 139 - .../c++/v1/__random/fisher_f_distribution.h | 138 - .../include/c++/v1/__random/gamma_distribution.h | 181 - .../include/c++/v1/__random/generate_canonical.h | 51 - .../c++/v1/__random/geometric_distribution.h | 120 - .../c++/v1/__random/independent_bits_engine.h | 205 - .../include/c++/v1/__random/is_seed_sequence.h | 31 - .../libcxx/include/c++/v1/__random/is_valid.h | 94 - .../libcxx/include/c++/v1/__random/knuth_b.h | 26 - .../c++/v1/__random/linear_congruential_engine.h | 371 -- third_party/libcxx/include/c++/v1/__random/log2.h | 66 - .../c++/v1/__random/lognormal_distribution.h | 126 - .../c++/v1/__random/mersenne_twister_engine.h | 488 -- .../v1/__random/negative_binomial_distribution.h | 157 - .../include/c++/v1/__random/normal_distribution.h | 176 - .../v1/__random/piecewise_constant_distribution.h | 305 - .../v1/__random/piecewise_linear_distribution.h | 319 -- .../include/c++/v1/__random/poisson_distribution.h | 241 - .../libcxx/include/c++/v1/__random/random_device.h | 81 - .../libcxx/include/c++/v1/__random/ranlux.h | 31 - .../libcxx/include/c++/v1/__random/seed_seq.h | 168 - .../include/c++/v1/__random/shuffle_order_engine.h | 227 - .../c++/v1/__random/student_t_distribution.h | 132 - .../c++/v1/__random/subtract_with_carry_engine.h | 264 - .../c++/v1/__random/uniform_int_distribution.h | 264 - .../c++/v1/__random/uniform_random_bit_generator.h | 44 - .../c++/v1/__random/uniform_real_distribution.h | 138 - .../include/c++/v1/__random/weibull_distribution.h | 132 - .../libcxx/include/c++/v1/__ranges/access.h | 210 - .../c++/v1/__ranges/adjacent_transform_view.h | 406 -- .../libcxx/include/c++/v1/__ranges/adjacent_view.h | 419 -- third_party/libcxx/include/c++/v1/__ranges/all.h | 78 - .../include/c++/v1/__ranges/as_rvalue_view.h | 142 - .../libcxx/include/c++/v1/__ranges/chunk_by_view.h | 235 - .../libcxx/include/c++/v1/__ranges/common_view.h | 142 - .../libcxx/include/c++/v1/__ranges/concepts.h | 182 - .../c++/v1/__ranges/container_compatible_range.h | 33 - .../libcxx/include/c++/v1/__ranges/counted.h | 89 - .../libcxx/include/c++/v1/__ranges/dangling.h | 42 - third_party/libcxx/include/c++/v1/__ranges/data.h | 102 - .../libcxx/include/c++/v1/__ranges/drop_view.h | 329 -- .../include/c++/v1/__ranges/drop_while_view.h | 136 - .../libcxx/include/c++/v1/__ranges/elements_of.h | 49 - .../libcxx/include/c++/v1/__ranges/elements_view.h | 418 -- third_party/libcxx/include/c++/v1/__ranges/empty.h | 71 - .../libcxx/include/c++/v1/__ranges/empty_view.h | 54 - .../c++/v1/__ranges/enable_borrowed_range.h | 40 - .../libcxx/include/c++/v1/__ranges/enable_view.h | 50 - .../libcxx/include/c++/v1/__ranges/filter_view.h | 260 - .../libcxx/include/c++/v1/__ranges/from_range.h | 33 - .../libcxx/include/c++/v1/__ranges/iota_view.h | 423 -- .../libcxx/include/c++/v1/__ranges/istream_view.h | 141 - .../libcxx/include/c++/v1/__ranges/join_view.h | 429 -- .../include/c++/v1/__ranges/join_with_view.h | 459 -- .../include/c++/v1/__ranges/lazy_split_view.h | 442 -- .../libcxx/include/c++/v1/__ranges/movable_box.h | 247 - .../c++/v1/__ranges/non_propagating_cache.h | 103 - .../libcxx/include/c++/v1/__ranges/owning_view.h | 116 - .../libcxx/include/c++/v1/__ranges/range_adaptor.h | 99 - .../libcxx/include/c++/v1/__ranges/rbegin.h | 120 - .../libcxx/include/c++/v1/__ranges/ref_view.h | 89 - third_party/libcxx/include/c++/v1/__ranges/rend.h | 123 - .../libcxx/include/c++/v1/__ranges/repeat_view.h | 274 - .../libcxx/include/c++/v1/__ranges/reverse_view.h | 204 - .../libcxx/include/c++/v1/__ranges/single_view.h | 112 - third_party/libcxx/include/c++/v1/__ranges/size.h | 138 - .../libcxx/include/c++/v1/__ranges/split_view.h | 232 - .../libcxx/include/c++/v1/__ranges/subrange.h | 275 - .../libcxx/include/c++/v1/__ranges/take_view.h | 368 -- .../include/c++/v1/__ranges/take_while_view.h | 170 - third_party/libcxx/include/c++/v1/__ranges/to.h | 248 - .../include/c++/v1/__ranges/transform_view.h | 419 -- .../include/c++/v1/__ranges/view_interface.h | 170 - third_party/libcxx/include/c++/v1/__ranges/views.h | 35 - .../include/c++/v1/__ranges/zip_transform_view.h | 357 -- .../libcxx/include/c++/v1/__ranges/zip_view.h | 499 -- third_party/libcxx/include/c++/v1/__split_buffer | 866 --- .../libcxx/include/c++/v1/__std_mbstate_t.h | 29 - .../c++/v1/__stop_token/atomic_unique_lock.h | 140 - .../c++/v1/__stop_token/intrusive_list_view.h | 85 - .../c++/v1/__stop_token/intrusive_shared_ptr.h | 135 - .../include/c++/v1/__stop_token/stop_callback.h | 102 - .../include/c++/v1/__stop_token/stop_source.h | 91 - .../include/c++/v1/__stop_token/stop_state.h | 236 - .../include/c++/v1/__stop_token/stop_token.h | 63 - .../libcxx/include/c++/v1/__string/char_traits.h | 557 -- .../c++/v1/__string/constexpr_c_functions.h | 236 - .../c++/v1/__string/extern_template_lists.h | 94 - .../include/c++/v1/__support/ibm/gettod_zos.h | 52 - .../include/c++/v1/__support/ibm/locale_mgmt_zos.h | 53 - .../include/c++/v1/__support/ibm/nanosleep.h | 55 - .../c++/v1/__support/xlocale/__nop_locale_mgmt.h | 33 - .../c++/v1/__support/xlocale/__posix_l_fallback.h | 91 - .../c++/v1/__support/xlocale/__strtonum_fallback.h | 37 - .../libcxx/include/c++/v1/__system_error/errc.h | 266 - .../include/c++/v1/__system_error/error_category.h | 75 - .../include/c++/v1/__system_error/error_code.h | 142 - .../c++/v1/__system_error/error_condition.h | 129 - .../include/c++/v1/__system_error/system_error.h | 57 - .../c++/v1/__system_error/throw_system_error.h | 25 - .../libcxx/include/c++/v1/__thread/formatter.h | 80 - third_party/libcxx/include/c++/v1/__thread/id.h | 121 - .../libcxx/include/c++/v1/__thread/jthread.h | 136 - .../include/c++/v1/__thread/poll_with_backoff.h | 86 - .../libcxx/include/c++/v1/__thread/support.h | 123 - .../libcxx/include/c++/v1/__thread/support/c11.h | 191 - .../include/c++/v1/__thread/support/external.h | 21 - .../include/c++/v1/__thread/support/pthread.h | 221 - .../include/c++/v1/__thread/support/windows.h | 131 - .../libcxx/include/c++/v1/__thread/this_thread.h | 79 - .../libcxx/include/c++/v1/__thread/thread.h | 268 - .../include/c++/v1/__thread/timed_backoff_policy.h | 45 - third_party/libcxx/include/c++/v1/__tree | 2386 -------- .../libcxx/include/c++/v1/__tuple/find_index.h | 62 - third_party/libcxx/include/c++/v1/__tuple/ignore.h | 39 - .../libcxx/include/c++/v1/__tuple/sfinae_helpers.h | 99 - .../libcxx/include/c++/v1/__tuple/tuple_element.h | 46 - .../libcxx/include/c++/v1/__tuple/tuple_like.h | 42 - .../c++/v1/__tuple/tuple_like_no_subrange.h | 61 - .../libcxx/include/c++/v1/__tuple/tuple_size.h | 70 - .../include/c++/v1/__tuple/tuple_transform.h | 45 - .../include/c++/v1/__type_traits/add_cv_quals.h | 52 - .../include/c++/v1/__type_traits/add_pointer.h | 65 - .../include/c++/v1/__type_traits/add_reference.h | 58 - .../include/c++/v1/__type_traits/aligned_storage.h | 61 - .../include/c++/v1/__type_traits/aligned_union.h | 50 - .../include/c++/v1/__type_traits/alignment_of.h | 32 - .../c++/v1/__type_traits/common_reference.h | 202 - .../include/c++/v1/__type_traits/common_type.h | 117 - .../include/c++/v1/__type_traits/conditional.h | 64 - .../include/c++/v1/__type_traits/conjunction.h | 70 - .../c++/v1/__type_traits/container_traits.h | 46 - .../libcxx/include/c++/v1/__type_traits/copy_cv.h | 51 - .../include/c++/v1/__type_traits/copy_cvref.h | 45 - .../include/c++/v1/__type_traits/datasizeof.h | 50 - .../libcxx/include/c++/v1/__type_traits/decay.h | 40 - .../include/c++/v1/__type_traits/dependent_type.h | 25 - .../include/c++/v1/__type_traits/desugars_to.h | 73 - .../include/c++/v1/__type_traits/detected_or.h | 36 - .../include/c++/v1/__type_traits/disjunction.h | 58 - .../include/c++/v1/__type_traits/enable_if.h | 43 - .../libcxx/include/c++/v1/__type_traits/extent.h | 54 - .../has_unique_object_representation.h | 35 - .../c++/v1/__type_traits/has_virtual_destructor.h | 32 - .../include/c++/v1/__type_traits/integer_traits.h | 73 - .../c++/v1/__type_traits/integral_constant.h | 44 - .../libcxx/include/c++/v1/__type_traits/invoke.h | 401 -- .../include/c++/v1/__type_traits/is_abstract.h | 31 - .../include/c++/v1/__type_traits/is_aggregate.h | 33 - .../include/c++/v1/__type_traits/is_allocator.h | 33 - .../c++/v1/__type_traits/is_always_bitcastable.h | 83 - .../include/c++/v1/__type_traits/is_arithmetic.h | 34 - .../libcxx/include/c++/v1/__type_traits/is_array.h | 57 - .../include/c++/v1/__type_traits/is_assignable.h | 50 - .../include/c++/v1/__type_traits/is_base_of.h | 43 - .../include/c++/v1/__type_traits/is_callable.h | 32 - .../c++/v1/__type_traits/is_char_like_type.h | 30 - .../libcxx/include/c++/v1/__type_traits/is_class.h | 31 - .../include/c++/v1/__type_traits/is_compound.h | 46 - .../libcxx/include/c++/v1/__type_traits/is_const.h | 31 - .../c++/v1/__type_traits/is_constant_evaluated.h | 32 - .../c++/v1/__type_traits/is_constructible.h | 58 - .../include/c++/v1/__type_traits/is_convertible.h | 41 - .../c++/v1/__type_traits/is_core_convertible.h | 54 - .../include/c++/v1/__type_traits/is_destructible.h | 97 - .../libcxx/include/c++/v1/__type_traits/is_empty.h | 31 - .../libcxx/include/c++/v1/__type_traits/is_enum.h | 41 - .../c++/v1/__type_traits/is_equality_comparable.h | 83 - .../c++/v1/__type_traits/is_execution_policy.h | 59 - .../libcxx/include/c++/v1/__type_traits/is_final.h | 36 - .../c++/v1/__type_traits/is_floating_point.h | 40 - .../include/c++/v1/__type_traits/is_function.h | 31 - .../include/c++/v1/__type_traits/is_fundamental.h | 48 - .../is_generic_transparent_comparator.h | 30 - .../c++/v1/__type_traits/is_implicit_lifetime.h | 35 - .../is_implicitly_default_constructible.h | 46 - .../include/c++/v1/__type_traits/is_integral.h | 74 - .../include/c++/v1/__type_traits/is_literal_type.h | 34 - .../c++/v1/__type_traits/is_member_pointer.h | 43 - .../c++/v1/__type_traits/is_nothrow_assignable.h | 52 - .../v1/__type_traits/is_nothrow_constructible.h | 63 - .../c++/v1/__type_traits/is_nothrow_destructible.h | 61 - .../include/c++/v1/__type_traits/is_null_pointer.h | 37 - .../include/c++/v1/__type_traits/is_object.h | 31 - .../libcxx/include/c++/v1/__type_traits/is_pod.h | 31 - .../include/c++/v1/__type_traits/is_pointer.h | 31 - .../include/c++/v1/__type_traits/is_polymorphic.h | 31 - .../c++/v1/__type_traits/is_primary_template.h | 32 - .../include/c++/v1/__type_traits/is_reference.h | 68 - .../c++/v1/__type_traits/is_reference_wrapper.h | 32 - .../c++/v1/__type_traits/is_referenceable.h | 34 - .../libcxx/include/c++/v1/__type_traits/is_same.h | 44 - .../include/c++/v1/__type_traits/is_scalar.h | 69 - .../include/c++/v1/__type_traits/is_signed.h | 52 - .../c++/v1/__type_traits/is_specialization.h | 41 - .../c++/v1/__type_traits/is_standard_layout.h | 31 - .../include/c++/v1/__type_traits/is_swappable.h | 106 - .../include/c++/v1/__type_traits/is_trivial.h | 35 - .../c++/v1/__type_traits/is_trivially_assignable.h | 56 - .../v1/__type_traits/is_trivially_constructible.h | 64 - .../c++/v1/__type_traits/is_trivially_copyable.h | 35 - .../v1/__type_traits/is_trivially_destructible.h | 47 - .../is_trivially_lexicographically_comparable.h | 63 - .../v1/__type_traits/is_trivially_relocatable.h | 48 - .../libcxx/include/c++/v1/__type_traits/is_union.h | 31 - .../include/c++/v1/__type_traits/is_unqualified.h | 25 - .../include/c++/v1/__type_traits/is_unsigned.h | 52 - .../c++/v1/__type_traits/is_valid_expansion.h | 31 - .../libcxx/include/c++/v1/__type_traits/is_void.h | 31 - .../include/c++/v1/__type_traits/is_volatile.h | 31 - .../c++/v1/__type_traits/is_within_lifetime.h | 29 - .../libcxx/include/c++/v1/__type_traits/lazy.h | 25 - .../c++/v1/__type_traits/make_32_64_or_128_bit.h | 49 - .../c++/v1/__type_traits/make_const_lvalue_ref.h | 26 - .../include/c++/v1/__type_traits/make_signed.h | 84 - .../c++/v1/__type_traits/make_transparent.h | 53 - .../include/c++/v1/__type_traits/make_unsigned.h | 94 - .../include/c++/v1/__type_traits/maybe_const.h | 26 - .../libcxx/include/c++/v1/__type_traits/nat.h | 31 - .../libcxx/include/c++/v1/__type_traits/negation.h | 33 - .../libcxx/include/c++/v1/__type_traits/promote.h | 43 - .../libcxx/include/c++/v1/__type_traits/rank.h | 52 - .../reference_constructs_from_temporary.h | 38 - .../reference_converts_from_temporary.h | 35 - .../c++/v1/__type_traits/remove_all_extents.h | 40 - .../include/c++/v1/__type_traits/remove_const.h | 49 - .../c++/v1/__type_traits/remove_const_ref.h | 27 - .../include/c++/v1/__type_traits/remove_cv.h | 40 - .../include/c++/v1/__type_traits/remove_cvref.h | 45 - .../include/c++/v1/__type_traits/remove_extent.h | 40 - .../include/c++/v1/__type_traits/remove_pointer.h | 53 - .../c++/v1/__type_traits/remove_reference.h | 47 - .../include/c++/v1/__type_traits/remove_volatile.h | 49 - .../include/c++/v1/__type_traits/result_of.h | 43 - .../include/c++/v1/__type_traits/strip_signature.h | 84 - .../include/c++/v1/__type_traits/type_identity.h | 39 - .../include/c++/v1/__type_traits/type_list.h | 47 - .../include/c++/v1/__type_traits/underlying_type.h | 51 - .../include/c++/v1/__type_traits/unwrap_ref.h | 51 - .../libcxx/include/c++/v1/__type_traits/void_t.h | 30 - third_party/libcxx/include/c++/v1/__undef_macros | 28 - .../libcxx/include/c++/v1/__utility/as_const.h | 32 - .../libcxx/include/c++/v1/__utility/as_lvalue.h | 37 - .../libcxx/include/c++/v1/__utility/auto_cast.h | 22 - third_party/libcxx/include/c++/v1/__utility/cmp.h | 93 - .../include/c++/v1/__utility/convert_to_integral.h | 68 - .../libcxx/include/c++/v1/__utility/declval.h | 38 - .../v1/__utility/default_three_way_comparator.h | 70 - .../include/c++/v1/__utility/element_count.h | 27 - .../libcxx/include/c++/v1/__utility/empty.h | 24 - .../include/c++/v1/__utility/exception_guard.h | 143 - .../libcxx/include/c++/v1/__utility/exchange.h | 41 - .../libcxx/include/c++/v1/__utility/forward.h | 38 - .../libcxx/include/c++/v1/__utility/forward_like.h | 63 - .../libcxx/include/c++/v1/__utility/in_place.h | 64 - .../include/c++/v1/__utility/integer_sequence.h | 105 - .../include/c++/v1/__utility/is_pointer_in_range.h | 70 - .../v1/__utility/lazy_synth_three_way_comparator.h | 120 - third_party/libcxx/include/c++/v1/__utility/move.h | 49 - .../libcxx/include/c++/v1/__utility/no_destroy.h | 53 - third_party/libcxx/include/c++/v1/__utility/pair.h | 689 --- .../include/c++/v1/__utility/piecewise_construct.h | 32 - .../libcxx/include/c++/v1/__utility/priority_tag.h | 28 - .../c++/v1/__utility/private_constructor_tag.h | 28 - .../libcxx/include/c++/v1/__utility/rel_ops.h | 46 - .../libcxx/include/c++/v1/__utility/scope_guard.h | 57 - .../libcxx/include/c++/v1/__utility/small_buffer.h | 101 - third_party/libcxx/include/c++/v1/__utility/swap.h | 60 - .../include/c++/v1/__utility/to_underlying.h | 38 - .../include/c++/v1/__utility/try_key_extraction.h | 114 - .../libcxx/include/c++/v1/__utility/unreachable.h | 34 - .../libcxx/include/c++/v1/__variant/monostate.h | 66 - .../libcxx/include/c++/v1/__vector/comparison.h | 71 - .../include/c++/v1/__vector/container_traits.h | 41 - third_party/libcxx/include/c++/v1/__vector/erase.h | 50 - third_party/libcxx/include/c++/v1/__vector/pmr.h | 33 - third_party/libcxx/include/c++/v1/__vector/swap.h | 29 - .../libcxx/include/c++/v1/__vector/vector.h | 1425 ----- .../libcxx/include/c++/v1/__vector/vector_bool.h | 1115 ---- .../c++/v1/__vector/vector_bool_formatter.h | 49 - third_party/libcxx/include/c++/v1/__verbose_abort | 52 - third_party/libcxx/include/c++/v1/__verbose_trap | 36 - third_party/libcxx/include/c++/v1/algorithm | 2087 ------- third_party/libcxx/include/c++/v1/any | 581 -- third_party/libcxx/include/c++/v1/array | 609 -- third_party/libcxx/include/c++/v1/atomic | 643 --- third_party/libcxx/include/c++/v1/barrier | 203 - third_party/libcxx/include/c++/v1/bit | 101 - third_party/libcxx/include/c++/v1/bitset | 982 ---- third_party/libcxx/include/c++/v1/cassert | 35 - third_party/libcxx/include/c++/v1/ccomplex | 35 - third_party/libcxx/include/c++/v1/cctype | 131 - third_party/libcxx/include/c++/v1/cerrno | 52 - third_party/libcxx/include/c++/v1/cfenv | 95 - third_party/libcxx/include/c++/v1/cfloat | 90 - third_party/libcxx/include/c++/v1/charconv | 121 - third_party/libcxx/include/c++/v1/chrono | 1176 ---- third_party/libcxx/include/c++/v1/cinttypes | 275 - third_party/libcxx/include/c++/v1/ciso646 | 33 - third_party/libcxx/include/c++/v1/climits | 53 - third_party/libcxx/include/c++/v1/clocale | 60 - third_party/libcxx/include/c++/v1/cmath | 620 --- third_party/libcxx/include/c++/v1/codecvt | 606 -- third_party/libcxx/include/c++/v1/compare | 177 - third_party/libcxx/include/c++/v1/complex | 1494 ----- third_party/libcxx/include/c++/v1/complex.h | 36 - third_party/libcxx/include/c++/v1/concepts | 174 - .../libcxx/include/c++/v1/condition_variable | 368 -- third_party/libcxx/include/c++/v1/coroutine | 72 - third_party/libcxx/include/c++/v1/csetjmp | 59 - third_party/libcxx/include/c++/v1/csignal | 69 - third_party/libcxx/include/c++/v1/cstdalign | 52 - third_party/libcxx/include/c++/v1/cstdarg | 59 - third_party/libcxx/include/c++/v1/cstdbool | 40 - third_party/libcxx/include/c++/v1/cstddef | 63 - third_party/libcxx/include/c++/v1/cstdint | 198 - third_party/libcxx/include/c++/v1/cstdio | 179 - third_party/libcxx/include/c++/v1/cstdlib | 159 - third_party/libcxx/include/c++/v1/cstring | 109 - third_party/libcxx/include/c++/v1/ctgmath | 37 - third_party/libcxx/include/c++/v1/ctime | 91 - third_party/libcxx/include/c++/v1/ctype.h | 65 - third_party/libcxx/include/c++/v1/cuchar | 80 - third_party/libcxx/include/c++/v1/cwchar | 266 - third_party/libcxx/include/c++/v1/cwctype | 102 - third_party/libcxx/include/c++/v1/cxxabi.h | 197 - third_party/libcxx/include/c++/v1/deque | 2559 --------- third_party/libcxx/include/c++/v1/errno.h | 403 -- third_party/libcxx/include/c++/v1/exception | 105 - third_party/libcxx/include/c++/v1/execution | 163 - third_party/libcxx/include/c++/v1/expected | 60 - .../c++/v1/experimental/__simd/aligned_tag.h | 75 - .../c++/v1/experimental/__simd/declaration.h | 88 - .../include/c++/v1/experimental/__simd/reference.h | 192 - .../include/c++/v1/experimental/__simd/scalar.h | 102 - .../include/c++/v1/experimental/__simd/simd.h | 155 - .../include/c++/v1/experimental/__simd/simd_mask.h | 97 - .../include/c++/v1/experimental/__simd/traits.h | 75 - .../include/c++/v1/experimental/__simd/utility.h | 103 - .../include/c++/v1/experimental/__simd/vec_ext.h | 130 - .../libcxx/include/c++/v1/experimental/iterator | 140 - .../libcxx/include/c++/v1/experimental/memory | 205 - .../include/c++/v1/experimental/propagate_const | 497 -- .../libcxx/include/c++/v1/experimental/simd | 96 - .../libcxx/include/c++/v1/experimental/type_traits | 161 - .../libcxx/include/c++/v1/experimental/utility | 54 - third_party/libcxx/include/c++/v1/ext/__hash | 85 - third_party/libcxx/include/c++/v1/ext/hash_map | 835 --- third_party/libcxx/include/c++/v1/ext/hash_set | 582 -- third_party/libcxx/include/c++/v1/fenv.h | 118 - third_party/libcxx/include/c++/v1/filesystem | 581 -- third_party/libcxx/include/c++/v1/flat_map | 744 --- third_party/libcxx/include/c++/v1/flat_set | 620 --- third_party/libcxx/include/c++/v1/format | 267 - third_party/libcxx/include/c++/v1/forward_list | 1622 ------ third_party/libcxx/include/c++/v1/fstream | 1642 ------ third_party/libcxx/include/c++/v1/functional | 611 -- third_party/libcxx/include/c++/v1/future | 2080 ------- third_party/libcxx/include/c++/v1/initializer_list | 113 - third_party/libcxx/include/c++/v1/inttypes.h | 268 - third_party/libcxx/include/c++/v1/iomanip | 562 -- third_party/libcxx/include/c++/v1/ios | 898 --- third_party/libcxx/include/c++/v1/iosfwd | 191 - third_party/libcxx/include/c++/v1/iostream | 72 - third_party/libcxx/include/c++/v1/istream | 1427 ----- third_party/libcxx/include/c++/v1/iterator | 769 --- third_party/libcxx/include/c++/v1/latch | 137 - third_party/libcxx/include/c++/v1/libcxx.imp | 954 ---- third_party/libcxx/include/c++/v1/limits | 528 -- third_party/libcxx/include/c++/v1/list | 1833 ------ third_party/libcxx/include/c++/v1/locale | 226 - third_party/libcxx/include/c++/v1/map | 2183 -------- third_party/libcxx/include/c++/v1/math.h | 534 -- third_party/libcxx/include/c++/v1/mdspan | 467 -- third_party/libcxx/include/c++/v1/memory | 1008 ---- third_party/libcxx/include/c++/v1/memory_resource | 81 - third_party/libcxx/include/c++/v1/module.modulemap | 2498 --------- third_party/libcxx/include/c++/v1/mutex | 524 -- third_party/libcxx/include/c++/v1/new | 124 - third_party/libcxx/include/c++/v1/numbers | 169 - third_party/libcxx/include/c++/v1/numeric | 212 - third_party/libcxx/include/c++/v1/optional | 1771 ------ third_party/libcxx/include/c++/v1/ostream | 215 - third_party/libcxx/include/c++/v1/print | 396 -- third_party/libcxx/include/c++/v1/queue | 981 ---- third_party/libcxx/include/c++/v1/random | 1746 ------ third_party/libcxx/include/c++/v1/ranges | 517 -- third_party/libcxx/include/c++/v1/ratio | 499 -- third_party/libcxx/include/c++/v1/regex | 5849 -------------------- third_party/libcxx/include/c++/v1/scoped_allocator | 582 -- third_party/libcxx/include/c++/v1/semaphore | 189 - third_party/libcxx/include/c++/v1/set | 1554 ------ third_party/libcxx/include/c++/v1/shared_mutex | 448 -- third_party/libcxx/include/c++/v1/source_location | 90 - third_party/libcxx/include/c++/v1/span | 662 --- third_party/libcxx/include/c++/v1/sstream | 1303 ----- third_party/libcxx/include/c++/v1/stack | 387 -- third_party/libcxx/include/c++/v1/stdatomic.h | 247 - third_party/libcxx/include/c++/v1/stddef.h | 48 - third_party/libcxx/include/c++/v1/stdexcept | 292 - third_party/libcxx/include/c++/v1/stdio.h | 121 - third_party/libcxx/include/c++/v1/stdlib.h | 135 - third_party/libcxx/include/c++/v1/stop_token | 61 - third_party/libcxx/include/c++/v1/streambuf | 445 -- third_party/libcxx/include/c++/v1/string | 4041 -------------- third_party/libcxx/include/c++/v1/string.h | 115 - third_party/libcxx/include/c++/v1/string_view | 984 ---- third_party/libcxx/include/c++/v1/strstream | 363 -- third_party/libcxx/include/c++/v1/syncstream | 523 -- third_party/libcxx/include/c++/v1/system_error | 176 - third_party/libcxx/include/c++/v1/tgmath.h | 39 - third_party/libcxx/include/c++/v1/thread | 133 - third_party/libcxx/include/c++/v1/tuple | 1477 ----- third_party/libcxx/include/c++/v1/type_traits | 575 -- third_party/libcxx/include/c++/v1/typeindex | 113 - third_party/libcxx/include/c++/v1/typeinfo | 399 -- third_party/libcxx/include/c++/v1/uchar.h | 60 - third_party/libcxx/include/c++/v1/unordered_map | 2395 -------- third_party/libcxx/include/c++/v1/unordered_set | 1862 ------- third_party/libcxx/include/c++/v1/utility | 330 -- third_party/libcxx/include/c++/v1/valarray | 3318 ----------- third_party/libcxx/include/c++/v1/variant | 1655 ------ third_party/libcxx/include/c++/v1/vector | 379 -- third_party/libcxx/include/c++/v1/version | 639 --- third_party/libcxx/include/c++/v1/wchar.h | 207 - third_party/libcxx/include/c++/v1/wctype.h | 94 - third_party/libcxx/source_manifest.json | 110 - usr/Build.mk | 4 - usr/default_cpio_list | 24 - usr/gen_init_cpio.c | 781 --- usr/initramfs.S | 17 - 2105 files changed, 338 insertions(+), 381307 deletions(-) delete mode 100644 .clang-format delete mode 100644 .clang-tidy delete mode 100644 Build.mk create mode 100644 COPYING delete mode 100644 LICENSE delete mode 100644 Makefile delete mode 100644 README.md delete mode 100644 arch/riscv/Build.mk delete mode 100644 arch/riscv/config.cc delete mode 100644 arch/riscv/defconfig delete mode 100644 arch/riscv/include/arch/config.h delete mode 100644 arch/riscv/include/arch/context.h delete mode 100644 arch/riscv/include/arch/cpu.h delete mode 100644 arch/riscv/include/arch/extable.h delete mode 100644 arch/riscv/include/arch/fpstate.h delete mode 100644 arch/riscv/include/arch/mmu.h delete mode 100644 arch/riscv/include/arch/pmap.h delete mode 100644 arch/riscv/include/arch/random.h delete mode 100644 arch/riscv/include/arch/sbi.h delete mode 100644 arch/riscv/include/arch/tlb.h delete mode 100644 arch/riscv/include/arch/trap.h delete mode 100644 arch/riscv/include/arch/trapframe.h delete mode 100644 arch/riscv/include/asm/csr.h delete mode 100644 arch/riscv/include/asm/page.h delete mode 100644 arch/riscv/include/asm/pgtable.h delete mode 100644 arch/riscv/include/asm/sections.h delete mode 100644 arch/riscv/kernel/asm-offsets.c delete mode 100644 arch/riscv/kernel/head.S delete mode 100644 arch/riscv/kernel/lumeos.lds.S delete mode 100644 arch/riscv/kernel/signal.cc delete mode 100644 arch/riscv/lib/random.cc delete mode 100644 arch/riscv/mm/init.cc delete mode 100644 arch/riscv/mm/pmap.cc delete mode 100644 arch/riscv/mm/tlb_md.cc delete mode 100644 arch/riscv/syscall/syscall_md.cc delete mode 100644 arch/riscv/trap/extable.cc delete mode 100644 arch/riscv/trap/fpu.S delete mode 100644 arch/riscv/trap/swtch.S delete mode 100644 arch/riscv/trap/trap_md.cc delete mode 100644 arch/riscv/trap/trap_vector.S delete mode 100644 arch/riscv/uaccess/uaccess_memcpy.S delete mode 100644 docs/debug/debug_slab.md delete mode 100644 docs/debug/debug_slab_1.png delete mode 100644 docs/dev/dev_device.md delete mode 100644 docs/dev/dev_memory.md delete mode 100644 docs/specs/00_conventions.md delete mode 100644 docs/specs/arch_abstraction.md delete mode 100644 docs/specs/atomics.md delete mode 100644 docs/specs/cpp_runtime.md delete mode 100644 docs/specs/fdt.md delete mode 100644 docs/specs/global_init.md delete mode 100644 docs/specs/linker_and_entry.md delete mode 100644 docs/specs/pmm.md delete mode 100644 docs/specs/slab.md delete mode 100644 docs/specs/spinlock.md delete mode 100644 docs/specs/testing_and_ci.md delete mode 100644 docs/specs/vmm.md delete mode 100644 drivers/Build.mk delete mode 100644 drivers/base/bus.cc delete mode 100644 drivers/base/core.cc delete mode 100644 drivers/base/driver.cc delete mode 100644 drivers/base/platform.cc delete mode 100644 drivers/console.cc delete mode 100644 drivers/plic.cc delete mode 100644 drivers/tty/n_tty.cc delete mode 100644 drivers/tty/tty_core.cc delete mode 100644 drivers/tty/tty_uart.cc delete mode 100644 drivers/uart.cc delete mode 100644 fdt/Build.mk delete mode 100644 fdt/device_node.cc delete mode 100644 fdt/fdt.cc delete mode 100644 fs/Build.mk delete mode 100644 fs/chardev.cc delete mode 100644 fs/dcache.cc delete mode 100644 fs/devfs.cc delete mode 100644 fs/fd.cc delete mode 100644 fs/file_table.cc delete mode 100644 fs/fs_struct.cc delete mode 100644 fs/initramfs.cc delete mode 100644 fs/inode.cc delete mode 100644 fs/namei.cc delete mode 100644 fs/pipe.cc delete mode 100644 fs/ramfs/file.cc delete mode 100644 fs/ramfs/inode.cc delete mode 100644 fs/ramfs/super.cc delete mode 100644 fs/super.cc delete mode 100644 fs/vfs_init.cc delete mode 100644 include/libc-shim/bits/alltypes.h delete mode 100644 include/libc-shim/endian.h delete mode 100644 include/libc-shim/features.h delete mode 100644 include/libc-shim/limits.h delete mode 100644 include/libc-shim/stdint.h delete mode 100644 include/libc-shim/string.h delete mode 100644 include/libc-shim/strings.h delete mode 100644 include/lume/addr.h delete mode 100644 include/lume/addr_types.h delete mode 100644 include/lume/args.h delete mode 100644 include/lume/atomic.h delete mode 100644 include/lume/bitops.h delete mode 100644 include/lume/chardev.h delete mode 100644 include/lume/clone.h delete mode 100644 include/lume/compiler.h delete mode 100644 include/lume/config.h delete mode 100644 include/lume/console.h delete mode 100644 include/lume/container_of.h delete mode 100644 include/lume/dcache.h delete mode 100644 include/lume/device.h delete mode 100644 include/lume/device_node.h delete mode 100644 include/lume/driver.h delete mode 100644 include/lume/elf.h delete mode 100644 include/lume/errno.h delete mode 100644 include/lume/fdt.h delete mode 100644 include/lume/fdt_prop.h delete mode 100644 include/lume/fdtable.h delete mode 100644 include/lume/features.h delete mode 100644 include/lume/file.h delete mode 100644 include/lume/fs.h delete mode 100644 include/lume/fs_struct.h delete mode 100644 include/lume/fs_types.h delete mode 100644 include/lume/init.h delete mode 100644 include/lume/irq.h delete mode 100644 include/lume/kbuild.h delete mode 100644 include/lume/kernel_map.h delete mode 100644 include/lume/klog.h delete mode 100644 include/lume/kobject.h delete mode 100644 include/lume/kprintf.h delete mode 100644 include/lume/kref.h delete mode 100644 include/lume/libfdt.h delete mode 100644 include/lume/libfdt_env.h delete mode 100644 include/lume/limits.h delete mode 100644 include/lume/list.h delete mode 100644 include/lume/lumeos.lds.h delete mode 100644 include/lume/memblock.h delete mode 100644 include/lume/mm_layout.h delete mode 100644 include/lume/mman.h delete mode 100644 include/lume/mount.h delete mode 100644 include/lume/mutex.h delete mode 100644 include/lume/namei.h delete mode 100644 include/lume/new.h delete mode 100644 include/lume/page.h delete mode 100644 include/lume/page_cache.h delete mode 100644 include/lume/pgrp.h delete mode 100644 include/lume/pgtable_types.h delete mode 100644 include/lume/pid.h delete mode 100644 include/lume/pipe.h delete mode 100644 include/lume/platform_device.h delete mode 100644 include/lume/pmm.h delete mode 100644 include/lume/poll.h delete mode 100644 include/lume/ptrace.h delete mode 100644 include/lume/random.h delete mode 100644 include/lume/rbtree.h delete mode 100644 include/lume/rbtree_augmented.h delete mode 100644 include/lume/rbtree_types.h delete mode 100644 include/lume/sched.h delete mode 100644 include/lume/sched_class.h delete mode 100644 include/lume/selftest.h delete mode 100644 include/lume/setup.h delete mode 100644 include/lume/signal.h delete mode 100644 include/lume/signal_nr.h delete mode 100644 include/lume/signal_types.h delete mode 100644 include/lume/slab.h delete mode 100644 include/lume/smp.h delete mode 100644 include/lume/stdarg.h delete mode 100644 include/lume/stringify.h delete mode 100644 include/lume/syscall.h delete mode 100644 include/lume/syscall_nr.h delete mode 100644 include/lume/task.h delete mode 100644 include/lume/timer.h delete mode 100644 include/lume/tlb.h delete mode 100644 include/lume/trap.h delete mode 100644 include/lume/tty.h delete mode 100644 include/lume/tty_ioctl.h delete mode 100644 include/lume/types.h delete mode 100644 include/lume/uaccess.h delete mode 100644 include/lume/uuid.h delete mode 100644 include/lume/vmm.h delete mode 100644 include/lume/wait.h delete mode 100644 include/lume/waitqueue.h delete mode 100644 include/zircon/LICENSE delete mode 100644 include/zircon/README.lume delete mode 100644 include/zircon/assert.h delete mode 100644 include/zircon/compiler.h delete mode 100644 kernel/Build.mk delete mode 100644 kernel/exec.cc delete mode 100644 kernel/irq.cc delete mode 100644 kernel/main.cc delete mode 100644 kernel/pgrp.cc delete mode 100644 kernel/pid.cc delete mode 100644 kernel/poll.cc delete mode 100644 kernel/ptrace.cc delete mode 100644 kernel/sched_class_o1.cc delete mode 100644 kernel/sched_core.cc delete mode 100644 kernel/sched_internal.h delete mode 100644 kernel/signal.cc delete mode 100644 kernel/smp.cc delete mode 100644 kernel/sync/cpu_state.h delete mode 100644 kernel/sync/mutex.cc delete mode 100644 kernel/sync/spinlock.cc delete mode 100644 kernel/sync/spinlock.h delete mode 100644 kernel/sys_fs.cc delete mode 100644 kernel/sys_info.cc delete mode 100644 kernel/sys_misc.cc delete mode 100644 kernel/sys_mm.cc delete mode 100644 kernel/sys_process.cc delete mode 100644 kernel/sys_signal.cc delete mode 100644 kernel/syscall.cc delete mode 100644 kernel/task.cc delete mode 100644 kernel/timer.cc delete mode 100644 kernel/trap.cc delete mode 100644 kernel/uaccess.cc delete mode 100644 kernel/waitqueue.cc delete mode 100644 lib/Build.mk delete mode 100644 lib/cxx_abi.cc delete mode 100644 lib/fdt.c delete mode 100644 lib/fdt_addresses.c delete mode 100644 lib/fdt_empty_tree.c delete mode 100644 lib/fdt_ro.c delete mode 100644 lib/fdt_rw.c delete mode 100644 lib/fdt_strerror.c delete mode 100644 lib/fdt_sw.c delete mode 100644 lib/fdt_wip.c delete mode 100644 lib/klog.cc delete mode 100644 lib/kobject.cc delete mode 100644 lib/kprintf.cc delete mode 100644 lib/ktl/LICENSE delete mode 100644 lib/ktl/README.lume delete mode 100644 lib/ktl/README.md delete mode 100644 lib/ktl/include-after/errno.h delete mode 100644 lib/ktl/include-after/wchar.h delete mode 100644 lib/ktl/include/__chrono/system_clock.h delete mode 100644 lib/ktl/include/__config delete mode 100644 lib/ktl/include/__config_site delete mode 100644 lib/ktl/include/__configuration/platform.h delete mode 100644 lib/ktl/include/__external_threading delete mode 100644 lib/ktl/include/climits delete mode 100644 lib/ktl/include/cmath delete mode 100644 lib/ktl/include/cstdint delete mode 100644 lib/ktl/include/cstdio delete mode 100644 lib/ktl/include/cstdlib delete mode 100644 lib/ktl/include/cwchar delete mode 100644 lib/ktl/include/ktl/algorithm.h delete mode 100644 lib/ktl/include/ktl/array.h delete mode 100644 lib/ktl/include/ktl/atomic.h delete mode 100644 lib/ktl/include/ktl/bit.h delete mode 100644 lib/ktl/include/ktl/byte.h delete mode 100644 lib/ktl/include/ktl/concepts.h delete mode 100644 lib/ktl/include/ktl/declval.h delete mode 100644 lib/ktl/include/ktl/enforce.h delete mode 100644 lib/ktl/include/ktl/forward.h delete mode 100644 lib/ktl/include/ktl/functional.h delete mode 100644 lib/ktl/include/ktl/initializer_list.h delete mode 100644 lib/ktl/include/ktl/inplace_vector.h delete mode 100644 lib/ktl/include/ktl/iterator.h delete mode 100644 lib/ktl/include/ktl/limits.h delete mode 100644 lib/ktl/include/ktl/memory.h delete mode 100644 lib/ktl/include/ktl/new.h delete mode 100644 lib/ktl/include/ktl/numeric.h delete mode 100644 lib/ktl/include/ktl/optional.h delete mode 100644 lib/ktl/include/ktl/ranges.h delete mode 100644 lib/ktl/include/ktl/ref.h delete mode 100644 lib/ktl/include/ktl/source_location.h delete mode 100644 lib/ktl/include/ktl/span.h delete mode 100644 lib/ktl/include/ktl/string_view.h delete mode 100644 lib/ktl/include/ktl/tuple.h delete mode 100644 lib/ktl/include/ktl/type_traits.h delete mode 100644 lib/ktl/include/ktl/unique_ptr.h delete mode 100644 lib/ktl/include/ktl/utility.h delete mode 100644 lib/ktl/include/ktl/variant.h delete mode 100644 lib/ktl/include/limits delete mode 100644 lib/ktl/include/time.h delete mode 100644 lib/ktl/include/version delete mode 100644 lib/ktl/include/wchar.h delete mode 100644 lib/ktl/popcount.cc delete mode 100644 lib/ktl/stub-new.cc delete mode 100644 lib/libc/LICENSE delete mode 100644 lib/libc/README.lume delete mode 100644 lib/libc/include-after/ctype.h delete mode 100644 lib/libc/include-after/limits.h delete mode 100644 lib/libc/include/assert.h delete mode 100644 lib/libc/include/inttypes.h delete mode 100644 lib/libc/include/multi-file.h delete mode 100644 lib/libc/include/stdint.h delete mode 100644 lib/libc/include/stdio.h delete mode 100644 lib/libc/include/stdlib.h delete mode 100644 lib/libc/include/string-file.h delete mode 100644 lib/libc/include/string.h delete mode 100644 lib/printf.c delete mode 100644 lib/printf.h delete mode 100644 lib/random.cc delete mode 100644 lib/rbtree.cc delete mode 100644 lib/string/COPYRIGHT delete mode 100644 lib/string/aarch64/memcpy.S delete mode 100644 lib/string/aarch64/memset.S delete mode 100644 lib/string/arm/__aeabi_memcpy.s delete mode 100644 lib/string/arm/__aeabi_memset.s delete mode 100644 lib/string/arm/memcpy.S delete mode 100644 lib/string/bcmp.c delete mode 100644 lib/string/bcopy.c delete mode 100644 lib/string/bzero.c delete mode 100644 lib/string/explicit_bzero.c delete mode 100644 lib/string/i386/memcpy.s delete mode 100644 lib/string/i386/memmove.s delete mode 100644 lib/string/i386/memset.s delete mode 100644 lib/string/index.c delete mode 100644 lib/string/memccpy.c delete mode 100644 lib/string/memchr.c delete mode 100644 lib/string/memcmp.c delete mode 100644 lib/string/memcpy.c delete mode 100644 lib/string/memmem.c delete mode 100644 lib/string/memmove.c delete mode 100644 lib/string/mempcpy.c delete mode 100644 lib/string/memrchr.c delete mode 100644 lib/string/memset.c delete mode 100644 lib/string/rindex.c delete mode 100644 lib/string/stpcpy.c delete mode 100644 lib/string/stpncpy.c delete mode 100644 lib/string/strcat.c delete mode 100644 lib/string/strchr.c delete mode 100644 lib/string/strchrnul.c delete mode 100644 lib/string/strcmp.c delete mode 100644 lib/string/strcpy.c delete mode 100644 lib/string/strcspn.c delete mode 100644 lib/string/strlcat.c delete mode 100644 lib/string/strlcpy.c delete mode 100644 lib/string/strlen.c delete mode 100644 lib/string/strncat.c delete mode 100644 lib/string/strncmp.c delete mode 100644 lib/string/strncpy.c delete mode 100644 lib/string/strnlen.c delete mode 100644 lib/string/strpbrk.c delete mode 100644 lib/string/strrchr.c delete mode 100644 lib/string/strsep.c delete mode 100644 lib/string/strspn.c delete mode 100644 lib/string/strstr.c delete mode 100644 lib/string/strtok.c delete mode 100644 lib/string/strtok_r.c delete mode 100644 lib/string/x86_64/memcpy.s delete mode 100644 lib/string/x86_64/memmove.s delete mode 100644 lib/string/x86_64/memset.s delete mode 100644 mm/Build.mk delete mode 100644 mm/memblock.cc delete mode 100644 mm/page_cache.cc delete mode 100644 mm/pmm.cc delete mode 100644 mm/slab.cc delete mode 100644 mm/slab.h delete mode 100644 mm/tlb.cc delete mode 100644 mm/vma.cc delete mode 100644 mm/vmm.cc delete mode 100644 scripts/Kbuild.include delete mode 100644 scripts/Kconfig.mk delete mode 100644 scripts/build/Build.mk delete mode 100755 scripts/build/archive.sh delete mode 100755 scripts/build/check-kernel-elf.sh delete mode 100644 scripts/build/environments/host.mk delete mode 100644 scripts/build/environments/kernel.mk delete mode 100644 scripts/build/environments/phys.mk delete mode 100755 scripts/build/generate-asm-offsets.sh delete mode 100755 scripts/build/generate-autoconf.sh delete mode 100755 scripts/build/generate-initramfs.sh delete mode 100755 scripts/build/link-kernel.sh delete mode 100755 scripts/build/probe-toolchain.sh delete mode 100644 scripts/build/probes/libc_headers.c delete mode 100644 scripts/build/probes/libc_headers.cc delete mode 100644 scripts/build/probes/libcxx.cc delete mode 100755 scripts/build/run-if-changed.sh delete mode 100644 scripts/build/targets.mk delete mode 100644 scripts/build/tests/host_library.cc delete mode 100644 scripts/build/tests/host_test.cc delete mode 100644 scripts/build/tests/phys_library.cc delete mode 100644 scripts/build/toolchain.mk delete mode 100755 scripts/build/write-compdb.py delete mode 100644 scripts/dtc/libfdt/fdt.c delete mode 100644 scripts/dtc/libfdt/fdt.h delete mode 100644 scripts/dtc/libfdt/fdt_addresses.c delete mode 100644 scripts/dtc/libfdt/fdt_empty_tree.c delete mode 100644 scripts/dtc/libfdt/fdt_overlay.c delete mode 100644 scripts/dtc/libfdt/fdt_ro.c delete mode 100644 scripts/dtc/libfdt/fdt_rw.c delete mode 100644 scripts/dtc/libfdt/fdt_strerror.c delete mode 100644 scripts/dtc/libfdt/fdt_sw.c delete mode 100644 scripts/dtc/libfdt/fdt_wip.c delete mode 100644 scripts/dtc/libfdt/libfdt.h delete mode 100644 scripts/dtc/libfdt/libfdt_env.h delete mode 100644 scripts/dtc/libfdt/libfdt_internal.h delete mode 100644 scripts/extract-asm-offsets.sed delete mode 100755 scripts/gen_initramfs.sh delete mode 100644 test/Build.mk delete mode 100644 test/selftest.cc delete mode 100644 test/test_atomic.cc delete mode 100644 test/test_dcache.cc delete mode 100644 test/test_driver_model.cc delete mode 100644 test/test_exec.cc delete mode 100644 test/test_fdt.cc delete mode 100644 test/test_klog.cc delete mode 100644 test/test_mutex.cc delete mode 100644 test/test_namei.cc delete mode 100644 test/test_page_cache.cc delete mode 100644 test/test_pid.cc delete mode 100644 test/test_pipe_devfs.cc delete mode 100644 test/test_pmm.cc delete mode 100644 test/test_random.cc delete mode 100644 test/test_rbtree.cc delete mode 100644 test/test_sched.cc delete mode 100644 test/test_signal.cc delete mode 100644 test/test_slab.cc delete mode 100644 test/test_smp.cc delete mode 100644 test/test_spinlock.cc delete mode 100644 test/test_sys_fs_extra.cc delete mode 100644 test/test_sys_mm.cc delete mode 100644 test/test_sys_process.cc delete mode 100644 test/test_trap.cc delete mode 100644 test/test_uaccess.cc delete mode 100644 test/test_vfs_io.cc delete mode 100644 test/test_vma.cc delete mode 100644 test/test_vmm.cc delete mode 100644 test/test_waitqueue.cc delete mode 100644 third_party/libcxx/LICENSE delete mode 100644 third_party/libcxx/README.lume delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/adjacent_find.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/all_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/any_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/binary_search.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/clamp.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/comp.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/comp_ref_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/copy_backward.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/copy_move_common.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/copy_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/count.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/count_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/equal.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/equal_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/fill.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/fill_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/find.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/find_end.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/find_first_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/find_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/find_if_not.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/find_segment_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/for_each.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/for_each_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/for_each_n_segment.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/for_each_segment.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/generate.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/generate_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/half_positive.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/in_found_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/in_fun_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/in_in_out_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/in_in_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/in_out_out_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/in_out_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/includes.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/inplace_merge.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/is_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/is_heap_until.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/is_partitioned.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/is_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/is_sorted.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/is_sorted_until.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/iter_swap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/iterator_operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare_three_way.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/lower_bound.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/make_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/make_projected.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/max.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/max_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/merge.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/min.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/min_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/min_max_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/minmax.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/minmax_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/mismatch.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/move.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/move_backward.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/next_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/none_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/nth_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/out_value_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/partial_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/partial_sort_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/partition.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/partition_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/partition_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/pop_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/prev_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/pstl.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/push_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/radix_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_adjacent_find.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_all_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_any_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_binary_search.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_clamp.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_contains.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_contains_subrange.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_backward.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_count.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_count_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_ends_with.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_equal.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_equal_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_fill.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_fill_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_find.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_find_end.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_find_first_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if_not.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_find_last.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_fold.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_generate.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_generate_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_includes.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_inplace_merge.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap_until.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_is_partitioned.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_is_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted_until.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_iterator_concept.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_lexicographical_compare.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_lower_bound.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_make_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_max.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_max_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_merge.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_min.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_min_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_mismatch.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_move.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_move_backward.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_next_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_none_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_nth_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_partition.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_pop_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_prev_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_push_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_remove.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_replace.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_sample.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_search.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_search_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_set_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_set_intersection.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_set_symmetric_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_set_union.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_left.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_right.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_shuffle.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_sort_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_partition.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_starts_with.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_swap_ranges.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_transform.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_unique.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_unique_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/ranges_upper_bound.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/remove.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/remove_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/remove_copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/remove_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/replace.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/replace_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/replace_copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/replace_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/reverse.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/reverse_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/rotate.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/rotate_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/sample.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/search.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/search_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/set_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/set_intersection.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/set_symmetric_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/set_union.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/shift_left.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/shift_right.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/shuffle.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/sift_down.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/simd_utils.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/sort_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/specialized_algorithms.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/stable_partition.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/stable_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/swap_ranges.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/three_way_comp_ref_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/transform.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/uniform_random_bit_generator_adaptor.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/unique.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/unique_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/unwrap_iter.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/unwrap_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__algorithm/upper_bound.h delete mode 100644 third_party/libcxx/include/c++/v1/__assert delete mode 100644 third_party/libcxx/include/c++/v1/__assertion_handler delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/aliases.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic_flag.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic_init.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic_lock_free.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic_sync.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic_sync_timed.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/atomic_waitable_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/check_memory_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/contention_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/fence.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/floating_point_helper.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/is_always_lock_free.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/kill_dependency.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/memory_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/support.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/support/c11.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/support/gcc.h delete mode 100644 third_party/libcxx/include/c++/v1/__atomic/to_gcc_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/bit_cast.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/bit_ceil.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/bit_floor.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/bit_log2.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/bit_width.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/blsr.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/byteswap.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/countl.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/countr.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/endian.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/has_single_bit.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/invert_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/popcount.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit/rotate.h delete mode 100644 third_party/libcxx/include/c++/v1/__bit_reference delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/chars_format.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/from_chars_floating_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/from_chars_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/from_chars_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/tables.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/to_chars.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/to_chars_base_10.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/to_chars_floating_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/to_chars_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/to_chars_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__charconv/traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/calendar.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/concepts.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/convert_to_timespec.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/convert_to_tm.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/day.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/duration.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/exception.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/file_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/formatter.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/gps_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/hh_mm_ss.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/high_resolution_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/is_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/leap_second.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/literals.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/local_info.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/month.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/month_weekday.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/monthday.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/ostream.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/parser_std_format_spec.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/statically_widen.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/steady_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/sys_info.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/system_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/tai_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/time_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/time_zone.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/time_zone_link.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/tzdb.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/tzdb_list.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/utc_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/weekday.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/year.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/year_month.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/year_month_day.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/year_month_weekday.h delete mode 100644 third_party/libcxx/include/c++/v1/__chrono/zoned_time.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/common_comparison_category.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/compare_partial_order_fallback.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/compare_strong_order_fallback.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/compare_three_way.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/compare_three_way_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/compare_weak_order_fallback.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/is_eq.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/ordering.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/partial_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/strong_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/synth_three_way.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/three_way_comparable.h delete mode 100644 third_party/libcxx/include/c++/v1/__compare/weak_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/arithmetic.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/assignable.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/boolean_testable.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/class_or_enum.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/common_reference_with.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/common_with.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/comparison_common_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/convertible_to.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/copyable.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/derived_from.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/destructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/different_from.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/equality_comparable.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/invocable.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/movable.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/predicate.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/regular.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/relation.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/same_as.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/semiregular.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/swappable.h delete mode 100644 third_party/libcxx/include/c++/v1/__concepts/totally_ordered.h delete mode 100644 third_party/libcxx/include/c++/v1/__condition_variable/condition_variable.h delete mode 100644 third_party/libcxx/include/c++/v1/__config delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/abi.h delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/attributes.h delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/availability.h delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/compiler.h delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/experimental.h delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/hardening.h delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/language.h delete mode 100644 third_party/libcxx/include/c++/v1/__configuration/platform.h delete mode 100644 third_party/libcxx/include/c++/v1/__coroutine/coroutine_handle.h delete mode 100644 third_party/libcxx/include/c++/v1/__coroutine/coroutine_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__coroutine/noop_coroutine_handle.h delete mode 100644 third_party/libcxx/include/c++/v1/__coroutine/trivial_awaitables.h delete mode 100644 third_party/libcxx/include/c++/v1/__cstddef/byte.h delete mode 100644 third_party/libcxx/include/c++/v1/__cstddef/max_align_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cstddef/nullptr_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cstddef/ptrdiff_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cstddef/size_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/adjacent_find.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/all_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/any_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/binary_search.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp_ref_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_backward.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_move_common.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_end.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_first_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if_not.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_segment_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each_segment.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/half_positive.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/includes.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/inplace_merge.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap_until.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_partitioned.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted_until.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iter_swap.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iterator_operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lexicographical_compare.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lower_bound.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_projected.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/merge.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/mismatch.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move_backward.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/next_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/none_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/nth_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/pop_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/prev_permutation.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/push_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_intersection.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_symmetric_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_union.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/shuffle.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sift_down.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/simd_utils.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort_heap.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_partition.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/swap_ranges.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/three_way_comp_ref_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/transform.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/uniform_random_bit_generator_adaptor.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique_copy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_iter.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__algorithm/upper_bound.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__assert delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/aliases.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_base.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_flag.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_init.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_lock_free.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_sync.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/check_memory_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/contention_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/cxx_atomic_impl.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/fence.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/is_always_lock_free.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/kill_dependency.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/memory_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__atomic/to_gcc_order.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__bit/blsr.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__bit/countl.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__bit/countr.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__bit/invert_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__bit/popcount.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__bit/rotate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__bit_reference delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__chrono/convert_to_timespec.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__chrono/duration.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__chrono/high_resolution_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__chrono/steady_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__chrono/system_clock.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__chrono/time_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__condition_variable/condition_variable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__config delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__configuration/abi.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__configuration/availability.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__configuration/compiler.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__configuration/config_site_shim.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__configuration/language.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__configuration/platform.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/randomize_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/sanitizers.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/strict_weak_ordering_check.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__exception/exception.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__exception/exception_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__exception/nested_exception.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__exception/operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__exception/terminate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_negate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/bind.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/binder1st.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/binder2nd.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/hash.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/identity.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fn.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fun_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_binary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_unary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/reference_wrapper.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_negate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__functional/weak_result_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/array.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/bit_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/complex.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/deque.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/fstream.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/functional.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/ios.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/istream.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/memory.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/ostream.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/pair.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/queue.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/sstream.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/stack.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/streambuf.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/string.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/string_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/tuple.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__fwd/vector.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__hash_table delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__ios/fpos.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/access.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/advance.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/aliasing_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/back_insert_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/bounded_iter.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/distance.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/erase_if_container.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/front_insert_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/insert_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/istream_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/istreambuf_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/move_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/next.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostream_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostreambuf_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/prev.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/reverse_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/segmented_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__iterator/wrap_iter.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/android.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_defaults.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_fallbacks.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/fuchsia.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/ibm.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/locale_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/musl.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/newlib.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/openbsd.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/win32.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/abs.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/copysign.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/error_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/exponential_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/fdim.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/fma.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/gamma.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/hyperbolic_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/hypot.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_hyperbolic_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_trigonometric_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/logarithms.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/min_max.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/modulo.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/remainder.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/roots.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/rounding_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__math/trigonometric_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__mbstate_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/addressof.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/align.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/aligned_alloc.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/allocate_at_least.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/allocation_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_arg_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_destructor.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/assume_aligned.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/auto_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/builtin_new_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/compressed_pair.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/construct_at.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/destruct_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/pointer_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/raw_storage_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/shared_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/swap_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/temp_value.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/temporary_buffer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/uninitialized_algorithms.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/unique_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/uses_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__memory/voidify.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__mutex/lock_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__mutex/mutex.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__mutex/once_flag.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__mutex/tag_types.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__mutex/unique_lock.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__numeric/accumulate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__numeric/adjacent_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__numeric/inner_product.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__numeric/iota.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__numeric/partial_sum.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__ostream/basic_ostream.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/bernoulli_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/binomial_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/cauchy_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/chi_squared_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/clamp_to_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/default_random_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/discard_block_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/discrete_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/exponential_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/extreme_value_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/fisher_f_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/gamma_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/generate_canonical.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/geometric_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/independent_bits_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/is_seed_sequence.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/is_valid.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/knuth_b.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/linear_congruential_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/log2.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/lognormal_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/mersenne_twister_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/negative_binomial_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/normal_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/piecewise_constant_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/piecewise_linear_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/poisson_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/random_device.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/ranlux.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/seed_seq.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/shuffle_order_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/student_t_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/subtract_with_carry_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/uniform_int_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/uniform_real_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__random/weibull_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__split_buffer delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__std_clang_module delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__std_mbstate_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__string/char_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__string/constexpr_c_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__string/extern_template_lists.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__support/ibm/gettod_zos.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__support/ibm/locale_mgmt_zos.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__support/ibm/nanosleep.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__support/xlocale/__nop_locale_mgmt.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__support/xlocale/__posix_l_fallback.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__support/xlocale/__strtonum_fallback.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__system_error/errc.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__system_error/error_category.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__system_error/error_code.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__system_error/error_condition.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__system_error/system_error.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/id.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/poll_with_backoff.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/support.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/support/c11.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/support/external.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/support/pthread.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/support/windows.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/this_thread.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/thread.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__thread/timed_backoff_policy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tree delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/find_index.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/make_tuple_types.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/sfinae_helpers.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/tuple_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/tuple_indices.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/tuple_like.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/tuple_like_ext.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/tuple_like_no_subrange.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/tuple_size.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__tuple/tuple_types.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/add_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/add_cv.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/add_lvalue_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/add_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/add_rvalue_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/add_volatile.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/aligned_storage.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/aligned_union.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/alignment_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/can_extract_key.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/common_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/conditional.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/conjunction.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/copy_cv.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/copy_cvref.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/datasizeof.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/decay.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/dependent_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/desugars_to.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/disjunction.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/enable_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/extent.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/has_virtual_destructor.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/integral_constant.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/invoke.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_abstract.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_always_bitcastable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_arithmetic.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_array.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_assignable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_base_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_bounded_array.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_callable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_char_like_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_class.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_compound.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_constant_evaluated.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_convertible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_core_convertible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_destructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_empty.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_enum.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_equality_comparable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_execution_policy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_final.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_floating_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_fundamental.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_implicitly_default_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_literal_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_member_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_nothrow_assignable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_nothrow_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_nothrow_destructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_null_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_object.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_pod.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_polymorphic.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_primary_template.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_reference_wrapper.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_referenceable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_same.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_scalar.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_signed.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_signed_integer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_specialization.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_standard_layout.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_swappable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_trivial.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_trivially_assignable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_trivially_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_trivially_copyable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_trivially_destructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_trivially_lexicographically_comparable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_trivially_relocatable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_unbounded_array.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_union.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_unsigned.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_unsigned_integer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_valid_expansion.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_void.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/is_volatile.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/lazy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/make_32_64_or_128_bit.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/make_const_lvalue_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/make_signed.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/make_unsigned.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/maybe_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/nat.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/negation.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/noexcept_move_assign_container.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/promote.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/rank.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_all_extents.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_const_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_cv.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_cvref.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_extent.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/remove_volatile.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/result_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/strip_signature.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/type_identity.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/type_list.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/underlying_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/unwrap_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__type_traits/void_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__undef_macros delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/as_lvalue.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/auto_cast.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/convert_to_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/declval.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/empty.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/exception_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/forward.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/integer_sequence.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/is_pointer_in_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/is_valid_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/move.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/no_destroy.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/pair.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/piecewise_construct.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/priority_tag.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/private_constructor_tag.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/rel_ops.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/small_buffer.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/swap.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__utility/unreachable.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__variant/monostate.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__verbose_abort delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/__verbose_trap delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/algorithm delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/array delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/atomic delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/bitset delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cassert delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ccomplex delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cctype delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cerrno delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cfenv delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cfloat delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/chrono delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cinttypes delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ciso646 delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/climits delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/clocale delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cmath delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/codecvt delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/complex delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/condition_variable delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/csetjmp delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/csignal delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cstdarg delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cstdbool delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cstddef delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cstdint delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cstdio delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cstdlib delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cstring delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ctgmath delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ctime delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cuchar delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cwchar delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/cwctype delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/deque delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/exception delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/experimental/__config delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/experimental/utility delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ext/__hash delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ext/hash_map delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ext/hash_set delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/forward_list delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/fstream delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/functional delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/future delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/iomanip delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ios delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/iosfwd delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/iostream delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/istream delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/iterator delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/limits delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/list delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/locale delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/locale.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/map delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/math.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/memory delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/module.modulemap delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/mutex delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/new delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/numeric delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ostream delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/queue delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/random delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/ratio delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/regex delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/set delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/sstream delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/stack delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/stdatomic.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/stdexcept delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/stdint.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/stdlib.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/streambuf delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/string delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/string.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/string_view delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/strstream delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/system_error delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/thread delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/type_traits delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/typeindex delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/typeinfo delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/uchar.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/unordered_map delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/unordered_set delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/utility delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/valarray delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/vector delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/version delete mode 100644 third_party/libcxx/include/c++/v1/__cxx03/wchar.h delete mode 100644 third_party/libcxx/include/c++/v1/__cxxabi_config.h delete mode 100644 third_party/libcxx/include/c++/v1/__debug_utils/randomize_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__debug_utils/sanitizers.h delete mode 100644 third_party/libcxx/include/c++/v1/__debug_utils/strict_weak_ordering_check.h delete mode 100644 third_party/libcxx/include/c++/v1/__exception/exception.h delete mode 100644 third_party/libcxx/include/c++/v1/__exception/exception_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__exception/nested_exception.h delete mode 100644 third_party/libcxx/include/c++/v1/__exception/operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__exception/terminate.h delete mode 100644 third_party/libcxx/include/c++/v1/__expected/bad_expected_access.h delete mode 100644 third_party/libcxx/include/c++/v1/__expected/expected.h delete mode 100644 third_party/libcxx/include/c++/v1/__expected/unexpect.h delete mode 100644 third_party/libcxx/include/c++/v1/__expected/unexpected.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/copy_options.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/directory_entry.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/directory_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/directory_options.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/file_status.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/file_time_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/file_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/filesystem_error.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/path.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/path_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/perm_options.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/perms.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/recursive_directory_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/space_info.h delete mode 100644 third_party/libcxx/include/c++/v1/__filesystem/u8path.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_map/flat_map.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_map/flat_multimap.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_map/key_value_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_map/sorted_equivalent.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_map/sorted_unique.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_map/utils.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_set/flat_multiset.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_set/flat_set.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_set/ra_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__flat_set/utils.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/buffer.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/concepts.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/container_adaptor.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/enable_insertable.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/escaped_output_table.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/extended_grapheme_cluster_table.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/fmt_pair_like.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_arg.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_arg_store.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_args.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_context.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_error.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_parse_context.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_string.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/format_to_n_result.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_bool.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_bool_impl.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_char.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_floating_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_integer.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_output.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_string.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/formatter_tuple.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/indic_conjunct_break_table.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/parser_std_format_spec.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/range_default_formatter.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/range_format.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/range_formatter.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/unicode.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/width_estimation_table.h delete mode 100644 third_party/libcxx/include/c++/v1/__format/write_escaped.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/binary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/binary_negate.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/bind.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/bind_back.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/bind_front.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/binder1st.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/binder2nd.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/boyer_moore_searcher.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/compose.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/default_searcher.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/function.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/hash.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/identity.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/invoke.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/is_transparent.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/mem_fn.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/mem_fun_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/not_fn.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/perfect_forward.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/pointer_to_binary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/pointer_to_unary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/ranges_operations.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/reference_wrapper.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/unary_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/unary_negate.h delete mode 100644 third_party/libcxx/include/c++/v1/__functional/weak_result_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/array.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/bit_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/byte.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/complex.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/deque.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/format.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/fstream.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/functional.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/get.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/ios.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/istream.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/mdspan.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/memory.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/memory_resource.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/ostream.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/pair.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/queue.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/span.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/sstream.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/stack.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/streambuf.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/string.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/string_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/subrange.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/tuple.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/variant.h delete mode 100644 third_party/libcxx/include/c++/v1/__fwd/vector.h delete mode 100644 third_party/libcxx/include/c++/v1/__hash_table delete mode 100644 third_party/libcxx/include/c++/v1/__ios/fpos.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/access.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/advance.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/aliasing_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/back_insert_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/bounded_iter.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/capacity_aware_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/common_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/concepts.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/counted_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/cpp17_iterator_concepts.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/data.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/default_sentinel.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/distance.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/empty.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/erase_if_container.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/front_insert_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/incrementable_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/indirectly_comparable.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/insert_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/istream_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/istreambuf_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/iter_move.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/iter_swap.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/iterator_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/iterator_with_data.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/mergeable.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/move_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/move_sentinel.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/next.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/ostream_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/ostreambuf_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/permutable.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/prev.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/product_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/projected.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/ranges_iterator_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/readable_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/reverse_access.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/reverse_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/segmented_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/size.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/sortable.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/static_bounded_iter.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/unreachable_sentinel.h delete mode 100644 third_party/libcxx/include/c++/v1/__iterator/wrap_iter.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/check_grouping.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/get_c_locale.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/locale_base_api.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/locale_base_api/bsd_locale_fallbacks.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/locale_base_api/ibm.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/locale_base_api/openbsd.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/messages.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/money.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/num.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/pad_and_output.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/scan_keyword.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/aix.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/apple.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/bsd_like.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/freebsd.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/fuchsia.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/linux.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/netbsd.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/newlib.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/no_locale/characters.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/no_locale/strtonum.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/support/windows.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/time.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/wbuffer_convert.h delete mode 100644 third_party/libcxx/include/c++/v1/__locale_dir/wstring_convert.h delete mode 100644 third_party/libcxx/include/c++/v1/__log_hardening_failure delete mode 100644 third_party/libcxx/include/c++/v1/__math/abs.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/copysign.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/error_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/exponential_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/fdim.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/fma.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/gamma.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/hyperbolic_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/hypot.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/inverse_hyperbolic_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/inverse_trigonometric_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/logarithms.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/min_max.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/modulo.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/remainder.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/roots.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/rounding_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/special_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__math/trigonometric_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__mbstate_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__mdspan/aligned_accessor.h delete mode 100644 third_party/libcxx/include/c++/v1/__mdspan/default_accessor.h delete mode 100644 third_party/libcxx/include/c++/v1/__mdspan/extents.h delete mode 100644 third_party/libcxx/include/c++/v1/__mdspan/layout_left.h delete mode 100644 third_party/libcxx/include/c++/v1/__mdspan/layout_right.h delete mode 100644 third_party/libcxx/include/c++/v1/__mdspan/layout_stride.h delete mode 100644 third_party/libcxx/include/c++/v1/__mdspan/mdspan.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/addressof.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/align.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/allocate_at_least.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/allocation_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/allocator_arg_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/allocator_destructor.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/allocator_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/array_cookie.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/assume_aligned.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/auto_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/compressed_pair.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/concepts.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/construct_at.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/destroy.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/destruct_n.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/inout_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/is_sufficiently_aligned.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/noexcept_move_assign_container.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/out_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/pointer_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/ranges_construct_at.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/ranges_destroy.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/ranges_uninitialized_algorithms.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/raw_storage_iterator.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/shared_count.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/shared_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/swap_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/temp_value.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/temporary_buffer.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/uninitialized_algorithms.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/unique_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/unique_temporary_buffer.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/uses_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/uses_allocator_construction.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory/valid_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory_resource/memory_resource.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory_resource/monotonic_buffer_resource.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory_resource/polymorphic_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory_resource/pool_options.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory_resource/synchronized_pool_resource.h delete mode 100644 third_party/libcxx/include/c++/v1/__memory_resource/unsynchronized_pool_resource.h delete mode 100644 third_party/libcxx/include/c++/v1/__mutex/lock_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__mutex/mutex.h delete mode 100644 third_party/libcxx/include/c++/v1/__mutex/once_flag.h delete mode 100644 third_party/libcxx/include/c++/v1/__mutex/tag_types.h delete mode 100644 third_party/libcxx/include/c++/v1/__mutex/unique_lock.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/align_val_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/allocate.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/destroying_delete_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/exceptions.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/global_new_delete.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/interference_size.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/launder.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/new_handler.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/nothrow_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__new/placement_new_delete.h delete mode 100644 third_party/libcxx/include/c++/v1/__node_handle delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/accumulate.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/adjacent_difference.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/exclusive_scan.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/gcd_lcm.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/inclusive_scan.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/inner_product.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/iota.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/midpoint.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/partial_sum.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/pstl.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/ranges_iota.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/reduce.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/saturation_arithmetic.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/transform_exclusive_scan.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/transform_inclusive_scan.h delete mode 100644 third_party/libcxx/include/c++/v1/__numeric/transform_reduce.h delete mode 100644 third_party/libcxx/include/c++/v1/__ostream/basic_ostream.h delete mode 100644 third_party/libcxx/include/c++/v1/__ostream/print.h delete mode 100644 third_party/libcxx/include/c++/v1/__ostream/put_character_sequence.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/backend.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/backend_fwd.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/backends/default.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/backends/libdispatch.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/backends/serial.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/backends/std_thread.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/any_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/cpu_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/fill.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/find_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/for_each.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/merge.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/stable_sort.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/transform.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/cpu_algos/transform_reduce.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/dispatch.h delete mode 100644 third_party/libcxx/include/c++/v1/__pstl/handle_exception.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/bernoulli_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/binomial_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/cauchy_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/chi_squared_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/clamp_to_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/default_random_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/discard_block_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/discrete_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/exponential_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/extreme_value_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/fisher_f_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/gamma_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/generate_canonical.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/geometric_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/independent_bits_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/is_seed_sequence.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/is_valid.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/knuth_b.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/linear_congruential_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/log2.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/lognormal_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/mersenne_twister_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/negative_binomial_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/normal_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/piecewise_constant_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/piecewise_linear_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/poisson_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/random_device.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/ranlux.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/seed_seq.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/shuffle_order_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/student_t_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/subtract_with_carry_engine.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/uniform_int_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/uniform_random_bit_generator.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/uniform_real_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__random/weibull_distribution.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/access.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/adjacent_transform_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/adjacent_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/all.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/as_rvalue_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/chunk_by_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/common_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/concepts.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/container_compatible_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/counted.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/dangling.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/data.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/drop_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/drop_while_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/elements_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/elements_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/empty.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/empty_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/enable_borrowed_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/enable_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/filter_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/from_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/iota_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/istream_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/join_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/join_with_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/lazy_split_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/movable_box.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/non_propagating_cache.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/owning_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/range_adaptor.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/rbegin.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/ref_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/rend.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/repeat_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/reverse_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/single_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/size.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/split_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/subrange.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/take_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/take_while_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/to.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/transform_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/view_interface.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/views.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/zip_transform_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__ranges/zip_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__split_buffer delete mode 100644 third_party/libcxx/include/c++/v1/__std_mbstate_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__stop_token/atomic_unique_lock.h delete mode 100644 third_party/libcxx/include/c++/v1/__stop_token/intrusive_list_view.h delete mode 100644 third_party/libcxx/include/c++/v1/__stop_token/intrusive_shared_ptr.h delete mode 100644 third_party/libcxx/include/c++/v1/__stop_token/stop_callback.h delete mode 100644 third_party/libcxx/include/c++/v1/__stop_token/stop_source.h delete mode 100644 third_party/libcxx/include/c++/v1/__stop_token/stop_state.h delete mode 100644 third_party/libcxx/include/c++/v1/__stop_token/stop_token.h delete mode 100644 third_party/libcxx/include/c++/v1/__string/char_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__string/constexpr_c_functions.h delete mode 100644 third_party/libcxx/include/c++/v1/__string/extern_template_lists.h delete mode 100644 third_party/libcxx/include/c++/v1/__support/ibm/gettod_zos.h delete mode 100644 third_party/libcxx/include/c++/v1/__support/ibm/locale_mgmt_zos.h delete mode 100644 third_party/libcxx/include/c++/v1/__support/ibm/nanosleep.h delete mode 100644 third_party/libcxx/include/c++/v1/__support/xlocale/__nop_locale_mgmt.h delete mode 100644 third_party/libcxx/include/c++/v1/__support/xlocale/__posix_l_fallback.h delete mode 100644 third_party/libcxx/include/c++/v1/__support/xlocale/__strtonum_fallback.h delete mode 100644 third_party/libcxx/include/c++/v1/__system_error/errc.h delete mode 100644 third_party/libcxx/include/c++/v1/__system_error/error_category.h delete mode 100644 third_party/libcxx/include/c++/v1/__system_error/error_code.h delete mode 100644 third_party/libcxx/include/c++/v1/__system_error/error_condition.h delete mode 100644 third_party/libcxx/include/c++/v1/__system_error/system_error.h delete mode 100644 third_party/libcxx/include/c++/v1/__system_error/throw_system_error.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/formatter.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/id.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/jthread.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/poll_with_backoff.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/support.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/support/c11.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/support/external.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/support/pthread.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/support/windows.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/this_thread.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/thread.h delete mode 100644 third_party/libcxx/include/c++/v1/__thread/timed_backoff_policy.h delete mode 100644 third_party/libcxx/include/c++/v1/__tree delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/find_index.h delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/ignore.h delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/sfinae_helpers.h delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_element.h delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_like.h delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_like_no_subrange.h delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_size.h delete mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_transform.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/add_cv_quals.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/add_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/add_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/aligned_storage.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/aligned_union.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/alignment_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/common_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/common_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/conditional.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/conjunction.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/container_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/copy_cv.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/copy_cvref.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/datasizeof.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/decay.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/dependent_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/desugars_to.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/detected_or.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/disjunction.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/enable_if.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/extent.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/has_unique_object_representation.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/has_virtual_destructor.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/integer_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/integral_constant.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/invoke.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_abstract.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_aggregate.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_allocator.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_always_bitcastable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_arithmetic.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_array.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_assignable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_base_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_callable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_char_like_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_class.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_compound.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_constant_evaluated.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_convertible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_core_convertible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_destructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_empty.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_enum.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_equality_comparable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_execution_policy.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_final.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_floating_point.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_function.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_fundamental.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_generic_transparent_comparator.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_implicit_lifetime.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_implicitly_default_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_literal_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_member_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_nothrow_assignable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_nothrow_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_nothrow_destructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_null_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_object.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_pod.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_polymorphic.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_primary_template.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_reference_wrapper.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_referenceable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_same.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_scalar.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_signed.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_specialization.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_standard_layout.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_swappable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_trivial.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_trivially_assignable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_trivially_constructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_trivially_copyable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_trivially_destructible.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_trivially_lexicographically_comparable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_trivially_relocatable.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_union.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_unqualified.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_unsigned.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_valid_expansion.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_void.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_volatile.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/is_within_lifetime.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/lazy.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/make_32_64_or_128_bit.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/make_const_lvalue_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/make_signed.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/make_transparent.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/make_unsigned.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/maybe_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/nat.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/negation.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/promote.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/rank.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/reference_constructs_from_temporary.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/reference_converts_from_temporary.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_all_extents.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_const_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_cv.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_cvref.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_extent.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_pointer.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_reference.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/remove_volatile.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/result_of.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/strip_signature.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/type_identity.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/type_list.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/underlying_type.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/unwrap_ref.h delete mode 100644 third_party/libcxx/include/c++/v1/__type_traits/void_t.h delete mode 100644 third_party/libcxx/include/c++/v1/__undef_macros delete mode 100644 third_party/libcxx/include/c++/v1/__utility/as_const.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/as_lvalue.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/auto_cast.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/cmp.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/convert_to_integral.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/declval.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/default_three_way_comparator.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/element_count.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/empty.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/exception_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/exchange.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/forward.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/forward_like.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/in_place.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/integer_sequence.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/is_pointer_in_range.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/lazy_synth_three_way_comparator.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/move.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/no_destroy.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/pair.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/piecewise_construct.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/priority_tag.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/private_constructor_tag.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/rel_ops.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/scope_guard.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/small_buffer.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/swap.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/to_underlying.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/try_key_extraction.h delete mode 100644 third_party/libcxx/include/c++/v1/__utility/unreachable.h delete mode 100644 third_party/libcxx/include/c++/v1/__variant/monostate.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/comparison.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/container_traits.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/erase.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/pmr.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/swap.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/vector.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/vector_bool.h delete mode 100644 third_party/libcxx/include/c++/v1/__vector/vector_bool_formatter.h delete mode 100644 third_party/libcxx/include/c++/v1/__verbose_abort delete mode 100644 third_party/libcxx/include/c++/v1/__verbose_trap delete mode 100644 third_party/libcxx/include/c++/v1/algorithm delete mode 100644 third_party/libcxx/include/c++/v1/any delete mode 100644 third_party/libcxx/include/c++/v1/array delete mode 100644 third_party/libcxx/include/c++/v1/atomic delete mode 100644 third_party/libcxx/include/c++/v1/barrier delete mode 100644 third_party/libcxx/include/c++/v1/bit delete mode 100644 third_party/libcxx/include/c++/v1/bitset delete mode 100644 third_party/libcxx/include/c++/v1/cassert delete mode 100644 third_party/libcxx/include/c++/v1/ccomplex delete mode 100644 third_party/libcxx/include/c++/v1/cctype delete mode 100644 third_party/libcxx/include/c++/v1/cerrno delete mode 100644 third_party/libcxx/include/c++/v1/cfenv delete mode 100644 third_party/libcxx/include/c++/v1/cfloat delete mode 100644 third_party/libcxx/include/c++/v1/charconv delete mode 100644 third_party/libcxx/include/c++/v1/chrono delete mode 100644 third_party/libcxx/include/c++/v1/cinttypes delete mode 100644 third_party/libcxx/include/c++/v1/ciso646 delete mode 100644 third_party/libcxx/include/c++/v1/climits delete mode 100644 third_party/libcxx/include/c++/v1/clocale delete mode 100644 third_party/libcxx/include/c++/v1/cmath delete mode 100644 third_party/libcxx/include/c++/v1/codecvt delete mode 100644 third_party/libcxx/include/c++/v1/compare delete mode 100644 third_party/libcxx/include/c++/v1/complex delete mode 100644 third_party/libcxx/include/c++/v1/complex.h delete mode 100644 third_party/libcxx/include/c++/v1/concepts delete mode 100644 third_party/libcxx/include/c++/v1/condition_variable delete mode 100644 third_party/libcxx/include/c++/v1/coroutine delete mode 100644 third_party/libcxx/include/c++/v1/csetjmp delete mode 100644 third_party/libcxx/include/c++/v1/csignal delete mode 100644 third_party/libcxx/include/c++/v1/cstdalign delete mode 100644 third_party/libcxx/include/c++/v1/cstdarg delete mode 100644 third_party/libcxx/include/c++/v1/cstdbool delete mode 100644 third_party/libcxx/include/c++/v1/cstddef delete mode 100644 third_party/libcxx/include/c++/v1/cstdint delete mode 100644 third_party/libcxx/include/c++/v1/cstdio delete mode 100644 third_party/libcxx/include/c++/v1/cstdlib delete mode 100644 third_party/libcxx/include/c++/v1/cstring delete mode 100644 third_party/libcxx/include/c++/v1/ctgmath delete mode 100644 third_party/libcxx/include/c++/v1/ctime delete mode 100644 third_party/libcxx/include/c++/v1/ctype.h delete mode 100644 third_party/libcxx/include/c++/v1/cuchar delete mode 100644 third_party/libcxx/include/c++/v1/cwchar delete mode 100644 third_party/libcxx/include/c++/v1/cwctype delete mode 100644 third_party/libcxx/include/c++/v1/cxxabi.h delete mode 100644 third_party/libcxx/include/c++/v1/deque delete mode 100644 third_party/libcxx/include/c++/v1/errno.h delete mode 100644 third_party/libcxx/include/c++/v1/exception delete mode 100644 third_party/libcxx/include/c++/v1/execution delete mode 100644 third_party/libcxx/include/c++/v1/expected delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/aligned_tag.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/declaration.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/reference.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/scalar.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/simd.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/simd_mask.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/traits.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/utility.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/__simd/vec_ext.h delete mode 100644 third_party/libcxx/include/c++/v1/experimental/iterator delete mode 100644 third_party/libcxx/include/c++/v1/experimental/memory delete mode 100644 third_party/libcxx/include/c++/v1/experimental/propagate_const delete mode 100644 third_party/libcxx/include/c++/v1/experimental/simd delete mode 100644 third_party/libcxx/include/c++/v1/experimental/type_traits delete mode 100644 third_party/libcxx/include/c++/v1/experimental/utility delete mode 100644 third_party/libcxx/include/c++/v1/ext/__hash delete mode 100644 third_party/libcxx/include/c++/v1/ext/hash_map delete mode 100644 third_party/libcxx/include/c++/v1/ext/hash_set delete mode 100644 third_party/libcxx/include/c++/v1/fenv.h delete mode 100644 third_party/libcxx/include/c++/v1/filesystem delete mode 100644 third_party/libcxx/include/c++/v1/flat_map delete mode 100644 third_party/libcxx/include/c++/v1/flat_set delete mode 100644 third_party/libcxx/include/c++/v1/format delete mode 100644 third_party/libcxx/include/c++/v1/forward_list delete mode 100644 third_party/libcxx/include/c++/v1/fstream delete mode 100644 third_party/libcxx/include/c++/v1/functional delete mode 100644 third_party/libcxx/include/c++/v1/future delete mode 100644 third_party/libcxx/include/c++/v1/initializer_list delete mode 100644 third_party/libcxx/include/c++/v1/inttypes.h delete mode 100644 third_party/libcxx/include/c++/v1/iomanip delete mode 100644 third_party/libcxx/include/c++/v1/ios delete mode 100644 third_party/libcxx/include/c++/v1/iosfwd delete mode 100644 third_party/libcxx/include/c++/v1/iostream delete mode 100644 third_party/libcxx/include/c++/v1/istream delete mode 100644 third_party/libcxx/include/c++/v1/iterator delete mode 100644 third_party/libcxx/include/c++/v1/latch delete mode 100644 third_party/libcxx/include/c++/v1/libcxx.imp delete mode 100644 third_party/libcxx/include/c++/v1/limits delete mode 100644 third_party/libcxx/include/c++/v1/list delete mode 100644 third_party/libcxx/include/c++/v1/locale delete mode 100644 third_party/libcxx/include/c++/v1/map delete mode 100644 third_party/libcxx/include/c++/v1/math.h delete mode 100644 third_party/libcxx/include/c++/v1/mdspan delete mode 100644 third_party/libcxx/include/c++/v1/memory delete mode 100644 third_party/libcxx/include/c++/v1/memory_resource delete mode 100644 third_party/libcxx/include/c++/v1/module.modulemap delete mode 100644 third_party/libcxx/include/c++/v1/mutex delete mode 100644 third_party/libcxx/include/c++/v1/new delete mode 100644 third_party/libcxx/include/c++/v1/numbers delete mode 100644 third_party/libcxx/include/c++/v1/numeric delete mode 100644 third_party/libcxx/include/c++/v1/optional delete mode 100644 third_party/libcxx/include/c++/v1/ostream delete mode 100644 third_party/libcxx/include/c++/v1/print delete mode 100644 third_party/libcxx/include/c++/v1/queue delete mode 100644 third_party/libcxx/include/c++/v1/random delete mode 100644 third_party/libcxx/include/c++/v1/ranges delete mode 100644 third_party/libcxx/include/c++/v1/ratio delete mode 100644 third_party/libcxx/include/c++/v1/regex delete mode 100644 third_party/libcxx/include/c++/v1/scoped_allocator delete mode 100644 third_party/libcxx/include/c++/v1/semaphore delete mode 100644 third_party/libcxx/include/c++/v1/set delete mode 100644 third_party/libcxx/include/c++/v1/shared_mutex delete mode 100644 third_party/libcxx/include/c++/v1/source_location delete mode 100644 third_party/libcxx/include/c++/v1/span delete mode 100644 third_party/libcxx/include/c++/v1/sstream delete mode 100644 third_party/libcxx/include/c++/v1/stack delete mode 100644 third_party/libcxx/include/c++/v1/stdatomic.h delete mode 100644 third_party/libcxx/include/c++/v1/stddef.h delete mode 100644 third_party/libcxx/include/c++/v1/stdexcept delete mode 100644 third_party/libcxx/include/c++/v1/stdio.h delete mode 100644 third_party/libcxx/include/c++/v1/stdlib.h delete mode 100644 third_party/libcxx/include/c++/v1/stop_token delete mode 100644 third_party/libcxx/include/c++/v1/streambuf delete mode 100644 third_party/libcxx/include/c++/v1/string delete mode 100644 third_party/libcxx/include/c++/v1/string.h delete mode 100644 third_party/libcxx/include/c++/v1/string_view delete mode 100644 third_party/libcxx/include/c++/v1/strstream delete mode 100644 third_party/libcxx/include/c++/v1/syncstream delete mode 100644 third_party/libcxx/include/c++/v1/system_error delete mode 100644 third_party/libcxx/include/c++/v1/tgmath.h delete mode 100644 third_party/libcxx/include/c++/v1/thread delete mode 100644 third_party/libcxx/include/c++/v1/tuple delete mode 100644 third_party/libcxx/include/c++/v1/type_traits delete mode 100644 third_party/libcxx/include/c++/v1/typeindex delete mode 100644 third_party/libcxx/include/c++/v1/typeinfo delete mode 100644 third_party/libcxx/include/c++/v1/uchar.h delete mode 100644 third_party/libcxx/include/c++/v1/unordered_map delete mode 100644 third_party/libcxx/include/c++/v1/unordered_set delete mode 100644 third_party/libcxx/include/c++/v1/utility delete mode 100644 third_party/libcxx/include/c++/v1/valarray delete mode 100644 third_party/libcxx/include/c++/v1/variant delete mode 100644 third_party/libcxx/include/c++/v1/vector delete mode 100644 third_party/libcxx/include/c++/v1/version delete mode 100644 third_party/libcxx/include/c++/v1/wchar.h delete mode 100644 third_party/libcxx/include/c++/v1/wctype.h delete mode 100644 third_party/libcxx/source_manifest.json delete mode 100644 usr/Build.mk delete mode 100644 usr/default_cpio_list delete mode 100644 usr/gen_init_cpio.c delete mode 100644 usr/initramfs.S diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 141e1e2..0000000 --- a/.clang-format +++ /dev/null @@ -1,35 +0,0 @@ -Language: Cpp -Standard: c++23 -BasedOnStyle: Google - -# Core Formatting -IndentWidth: 4 -ColumnLimit: 100 -TabWidth: 4 -UseTab: Never - -# Pointers and References -PointerAlignment: Left -ReferenceAlignment: Left - -# Includes -SortIncludes: true - -# Alignment -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignConsecutiveMacros: true - -# Control Statements -BreakBeforeBraces: Attach -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Empty - -# Spaces -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesInAngles: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -SpaceAfterTemplateKeyword: true diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 1af2c5a..0000000 --- a/.clang-tidy +++ /dev/null @@ -1,23 +0,0 @@ -Checks: > - -*, - clang-analyzer-*, - performance-*, - bugprone-*, - readability-*, - misc-*, - modernize-*, - -modernize-use-trailing-return-type, - -modernize-use-nodiscard, - -readability-identifier-length - -WarningsAsErrors: '' -HeaderFilterRegex: '.*' -FormatStyle: 'file' -CheckOptions: - readability-identifier-naming.ClassCase: PascalCase - readability-identifier-naming.StructCase: PascalCase - readability-identifier-naming.VariableCase: lower_case - readability-identifier-naming.FunctionCase: lower_case - readability-identifier-naming.GlobalVariableCase: lower_case - readability-identifier-naming.GlobalVariablePrefix: g_ - readability-identifier-naming.PrivateMemberSuffix: _ diff --git a/Build.mk b/Build.mk deleted file mode 100644 index f2b374a..0000000 --- a/Build.mk +++ /dev/null @@ -1,57 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -# Explicit directory traversal, following the Kbuild model. New directories do -# not enter a build merely because a file appeared in the source tree. -include arch/$(ARCH)/Build.mk -include kernel/Build.mk -include mm/Build.mk -include fs/Build.mk -include drivers/Build.mk -include fdt/Build.mk -include lib/Build.mk -include test/Build.mk -include usr/Build.mk -include scripts/build/Build.mk - -# The image root is an interface target: it carries the complete dependency -# set but contributes no sources of its own. -targets += generated/autoconf generated/asm-offsets generated/linker-script \ - generated/initramfs-cpio blob/initramfs kernel/image -target.generated/autoconf.kind := generated -target.generated/autoconf.outputs := $(BUILD)/generated/autoconf.h -target.generated/autoconf.inputs := scripts/Kconfig.mk $(KCONFIG_CONFIG) -target.generated/autoconf.action := autoconf - -target.generated/asm-offsets.kind := generated -target.generated/asm-offsets.outputs := $(BUILD)/generated/asm-offsets.h -target.generated/asm-offsets.inputs := arch/$(ARCH)/kernel/asm-offsets.c \ - scripts/extract-asm-offsets.sed -target.generated/asm-offsets.generated-deps := generated/autoconf -target.generated/asm-offsets.action := asm-offsets - -target.generated/linker-script.kind := generated -target.generated/linker-script.outputs := $(BUILD)/lumeos.lds -target.generated/linker-script.inputs := arch/$(ARCH)/kernel/lumeos.lds.S \ - include/lume/lumeos.lds.h -target.generated/linker-script.action := linker-script - -target.generated/initramfs-cpio.kind := generated -target.generated/initramfs-cpio.outputs := $(BUILD)/initramfs.cpio -target.generated/initramfs-cpio.inputs := $(CONFIG_INITRAMFS_SOURCE) \ - scripts/gen_initramfs.sh -target.generated/initramfs-cpio.tool-deps := host/gen_init_cpio -target.generated/initramfs-cpio.action := initramfs - -target.blob/initramfs.kind := binary-blob -target.blob/initramfs.outputs := $(BUILD)/initramfs.o -target.blob/initramfs.inputs := usr/initramfs.S -target.blob/initramfs.generated-deps := generated/initramfs-cpio - -target.kernel/image.kind := product -target.kernel/image.deps := \ - arch/$(ARCH) kernel/core mm/core fs/core drivers/core fdt/core lib/core \ - $(if $(filter y,$(CONFIG_SELFTEST)),test/kernel) -target.kernel/image.generated-deps := \ - generated/autoconf generated/asm-offsets generated/linker-script \ - blob/initramfs -target.kernel/image.outputs := $(VMLUME) $(IMAGE) diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..30a5c90 --- /dev/null +++ b/COPYING @@ -0,0 +1,338 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Moe Ghoul, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 30a5c90..0000000 --- a/LICENSE +++ /dev/null @@ -1,338 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, see . - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Moe Ghoul, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/Makefile b/Makefile deleted file mode 100644 index c21c4ac..0000000 --- a/Makefile +++ /dev/null @@ -1,609 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2026 Richard Qin -# -# LumeOS Kernel Makefile (Non-Recursive) -# -# Usage: -# make - Build kernel ELF -# make run - Run in QEMU -# make debug - Run in QEMU with GDB server -# make clean - Clean build artifacts -# make fmt - Format all source files -# make disasm - Generate disassembly listing -# -# Reference: docs/specs/00_conventions.md §7 - -# ============================================================ -# Build Configuration -# ============================================================ -O ?= build -BUILD := $(patsubst %/,%,$(O)) - -# Make sure `make` with no arguments builds the kernel image, not the -# first rule encountered during makefile parsing. -.DEFAULT_GOAL := all - -# Load command helpers before Kconfig and target evaluation. -include scripts/Kbuild.include - -# Load the O=-scoped configuration and derive compiler definitions. -include scripts/Kconfig.mk - -ARCH ?= $(CONFIG_ARCH) -PLATFORM ?= qemu-virt -BUILD_VARIANT ?= debug - -ifneq ($(filter $(BUILD_VARIANT),debug release),$(BUILD_VARIANT)) -$(error unsupported BUILD_VARIANT '$(BUILD_VARIANT)' (expected debug or release)) -endif - -# Toolchain selection needs the configured architecture but must precede flag -# and module evaluation. -include scripts/build/toolchain.mk - -# Two boot products — same pair as Linux RISC-V's arch/riscv/boot/Makefile -# (vmlinux + Image), but named LumeOS-style: -# VMLUME -> build/vmlume.elf : ELF with .symtab/PT_DYNAMIC/.rela.dyn -# IMAGE -> build/vmlume.bin : raw binary (objcopy -O binary) -VMLUME := $(BUILD)/vmlume.elf -IMAGE := $(BUILD)/vmlume.bin - -# Initramfs paths -INITRAMFS_DIR := $(BUILD)/initramfs -INITRAMFS_CPIO := $(BUILD)/initramfs.cpio -INITRAMFS_OBJ := $(BUILD)/initramfs.o -INITRAMFS_ASM := usr/initramfs.S -USR_INIT_ELF := $(BUILD)/usr/init -# Relocations: linker emits .rela.dyn under -shared -Bsymbolic; boot -# code in arch/riscv/mm/init.cc::relocate_kernel walks it at startup. -LDS_SRC := arch/$(ARCH)/kernel/lumeos.lds.S -LINKER_SCRIPT := $(BUILD)/lumeos.lds -PYTHON ?= python3 - -# Objcopy output formats for binary-to-ELF relocation blob -OBJCOPY_ELF_riscv := elf64-littleriscv -OBJCOPY_ELF_aarch64 := elf64-littleaarch64 -OBJCOPY_ELF_x86_64 := elf64-x86-64 -OBJCOPY_ELF := $(OBJCOPY_ELF_$(ARCH)) - -OBJCOPY_BINARCH_riscv := riscv -OBJCOPY_BINARCH_aarch64 := aarch64 -OBJCOPY_BINARCH_x86_64 := i386:x86-64 -OBJCOPY_BINARCH := $(OBJCOPY_BINARCH_$(ARCH)) - -# Common include roots. Environment-specific flags are defined after target -# usage requirements have been collected. -INCLUDES := -Iinclude -I. - -# ============================================================ -# Declarative Target Graph -# ============================================================ -include scripts/build/targets.mk -include Build.mk -$(eval $(call validate-targets)) - -KERNEL_ROOT := kernel/image -KERNEL_TARGETS := $(sort $(call target-closure,$(KERNEL_ROOT))) -KERNEL_LINK_TARGET_ORDER := $(call unique-words,$(call target-link-order,$(KERNEL_ROOT))) -KERNEL_SOURCE_KINDS := object-library source-set static-library whole-archive kernel-test -KERNEL_SOURCE_TARGETS := $(foreach target,$(KERNEL_TARGETS),\ - $(if $(filter $(KERNEL_SOURCE_KINDS),$(target.$(target).kind)),$(target))) -KERNEL_SOURCES := $(sort $(foreach target,$(KERNEL_SOURCE_TARGETS),\ - $(target.$(target).sources))) - -SRCS_CC := $(filter %.cc,$(KERNEL_SOURCES)) -SRCS_C := $(filter %.c,$(KERNEL_SOURCES)) -SRCS_S := $(filter %.S,$(KERNEL_SOURCES)) -SRCS_s := $(filter %.s,$(KERNEL_SOURCES)) - -# Only public usage requirements propagate. Private include paths and flags are -# attached to the objects belonging to the declaring target below. -INCLUDES += $(addprefix -I,$(call target-public-includes,$(KERNEL_ROOT))) -INCLUDES += $(foreach dir,$(call target-public-after-includes,$(KERNEL_ROOT)),-idirafter $(dir)) - -include scripts/build/environments/kernel.mk -include scripts/build/environments/phys.mk - -# ============================================================ -# Object File Computation -# ============================================================ -# A source may be compiled by multiple targets/environments. Object identity -# therefore includes both the logical target and source path. -source-object = $(BUILD)/obj/$(call target-key,$(1))/$(basename $(2)).o -define apply-target-usage -target.$(1).objects := $$(foreach src,$$(target.$(1).sources),$$(call source-object,$(1),$$(src))) -$$(target.$(1).objects): PRIVATE_INCLUDES := \ - $$(addprefix -I,$$(call target-compile-includes,$(1))) \ - $$(foreach dir,$$(call target-compile-after-includes,$(1)),-idirafter $$(dir)) -$$(target.$(1).objects): PRIVATE_DEFINES := $$(addprefix -D,$$(call target-compile-defines,$(1))) -$$(target.$(1).objects): PRIVATE_CFLAGS := $$(target.$(1).cflags) -$$(target.$(1).objects): PRIVATE_CXXFLAGS := $$(target.$(1).cxxflags) -$$(target.$(1).objects): PRIVATE_ASFLAGS := $$(target.$(1).asflags) -endef -$(foreach target,$(KERNEL_SOURCE_TARGETS),$(eval $(call apply-target-usage,$(target)))) - -define apply-source-identity -$(call source-object,$(1),$(2)): PRIVATE_SOURCE := $(2) -endef -$(foreach target,$(KERNEL_SOURCE_TARGETS),$(foreach src,$(target.$(target).sources),\ - $(eval $(call apply-source-identity,$(target),$(src))))) - -OBJS := $(foreach target,$(KERNEL_SOURCE_TARGETS),$(target.$(target).objects)) -DEPS := $(OBJS:.o=.d) - -# libfdt is freestanding but intentionally does not use the libc-shim include -# overlay used by the imported string implementation. -$(target.lib/libfdt.objects): CFLAGS_LIBC = $(CFLAGS) -std=gnu23 - -KERNEL_STATIC_TARGETS := $(foreach target,$(KERNEL_SOURCE_TARGETS),\ - $(if $(filter static-library,$(target.$(target).kind)),$(target))) -KERNEL_WHOLE_TARGETS := $(foreach target,$(KERNEL_SOURCE_TARGETS),\ - $(if $(filter whole-archive,$(target.$(target).kind)),$(target))) -KERNEL_OBJECT_TARGETS := $(filter-out $(KERNEL_STATIC_TARGETS) $(KERNEL_WHOLE_TARGETS),\ - $(KERNEL_SOURCE_TARGETS)) - -define define-archive -target.$(1).archive := $(BUILD)/lib/$(call target-key,$(1)).a -$$(target.$(1).archive): PRIVATE_ARCHIVE_OBJECTS := $$(target.$(1).objects) -$$(target.$(1).archive): $$(target.$(1).objects) FORCE - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,archive) -endef -$(foreach target,$(KERNEL_STATIC_TARGETS) $(KERNEL_WHOLE_TARGETS),\ - $(eval $(call define-archive,$(target)))) - -KERNEL_LINK_OBJECTS := $(foreach target,$(KERNEL_LINK_TARGET_ORDER),\ - $(if $(filter $(target),$(KERNEL_OBJECT_TARGETS)),$(target.$(target).objects))) -KERNEL_LINK_ARCHIVES := $(foreach target,$(KERNEL_LINK_TARGET_ORDER),\ - $(if $(filter $(target),$(KERNEL_STATIC_TARGETS)),$(target.$(target).archive))) -KERNEL_LINK_WHOLE := $(foreach target,$(KERNEL_LINK_TARGET_ORDER),\ - $(if $(filter $(target),$(KERNEL_WHOLE_TARGETS)),$(target.$(target).archive))) -KERNEL_LINK_INPUTS := $(KERNEL_LINK_OBJECTS) $(KERNEL_LINK_ARCHIVES) \ - $(if $(KERNEL_LINK_WHOLE),--whole-archive $(KERNEL_LINK_WHOLE) --no-whole-archive) - -# ============================================================ -# Build Rules -# ============================================================ -.PHONY: all clean run debug fmt disasm defconfig savedefconfig showconfig \ - help info check-toolchain check-image targets target-info \ - host-libraries host-tests kernel-tests compile_commands \ - phys-libraries toolchain-probe graph FORCE - -FORCE: - -all: $(VMLUME) $(IMAGE) check-image - -check-image: $(VMLUME) - @RE=$(READELF); NM=$(NM); \ - scripts/build/check-kernel-elf.sh $(VMLUME) "$$RE" "$$NM" $(ARCH) - -# Generate autoconf.h before any compilation -$(AUTOCONF_H): scripts/Kconfig.mk $(wildcard $(KCONFIG_CONFIG)) \ - scripts/build/generate-autoconf.sh FORCE - $(Q)mkdir -p $(dir $@) - $(call if_changed,autoconf) - -# ============================================================ -# Generated header: asm-offsets.h -# -# Linux-style trick (mirrors include/linux/kbuild.h + arch/*/kernel/ -# asm-offsets.c + scripts/Makefile.build): compile asm-offsets.c to -# assembly, scrape the magic `->SYM val` markers produced by the -# DEFINE/OFFSET inline-asm macros, rewrite them into `#define` -# directives via sed. head.S and friends then `#include -# ` to access struct field offsets without -# having to hand-maintain them — re-order a struct field, the -# generated constant follows. -# ============================================================ -ASM_OFFSETS_C := arch/$(ARCH)/kernel/asm-offsets.c -ASM_OFFSETS_S := $(BUILD)/arch/$(ARCH)/kernel/asm-offsets.s -ASM_OFFSETS_H := $(BUILD)/generated/asm-offsets.h -ASM_OFFSETS_SED := scripts/extract-asm-offsets.sed - -# Compile asm-offsets.c to *.s only — we never want the .o linked in. -$(ASM_OFFSETS_S): PRIVATE_SOURCE := $(ASM_OFFSETS_C) -$(ASM_OFFSETS_S): $(ASM_OFFSETS_C) $(AUTOCONF_H) FORCE - $(Q)mkdir -p $(dir $@) - $(call if_changed,cc_s_c) - -# Rewrite ->NAME markers into #define lines. Header guard hand-rolled -# at the top, sed body in the middle, closing #endif at the bottom. -$(ASM_OFFSETS_H): $(ASM_OFFSETS_S) $(ASM_OFFSETS_SED) \ - scripts/build/generate-asm-offsets.sh FORCE - $(Q)mkdir -p $(dir $@) - $(call if_changed,gen_asm_offsets) - -# All objects depend on autoconf.h and asm-offsets.h -$(OBJS): $(AUTOCONF_H) $(ASM_OFFSETS_H) FORCE - -# ============================================================ -# Generic %.pi.o post-processing rule -# -# Mirrors arch/riscv/kernel/pi/Makefile §26-30 in Linux: -# -# $(obj)/%.pi.o: OBJCOPYFLAGS := --prefix-symbols=__pi_ -# --remove-section=.note.gnu.property -# --prefix-alloc-sections=.init.pi -# $(obj)/%.pi.o: $(obj)/%.o FORCE -# $(call if_changed,objcopy) -# -# Purpose: take a regular .o produced by the normal compile rule and -# rewrite it so the early position-independent code can coexist with -# the rest of the kernel without symbol clashes: -# -# --prefix-symbols=__pi_ Every global symbol becomes __pi_. -# head.S calls them as __pi_fdt_path_offset -# etc., keeping the pre-MMU namespace -# cleanly isolated. -# -# --prefix-alloc-sections=.init.pi -# All SHF_ALLOC sections get re-prefixed -# so they land in .init.pi in vmlinux.lds.S, -# which positions them where the boot -# loader has already mapped memory. -# -# --remove-section=.note.gnu.property -# Discarded because post-rename it can -# confuse the linker about ELF features. -# -# Generic pattern (`$(BUILD)/%.pi.o`) so any subdir's source can opt in -# by listing a `.pi.o` target in its SRCS. The companion compile-side -# CFLAGS overrides (replacing -fPIE with -fpie, adding -Os, etc.) are -# expected to come from the subdir's own .mk fragment via target- -# specific CFLAGS_LIBC / CXXFLAGS overrides. -# ============================================================ -$(BUILD)/%.pi.o: OBJCOPYFLAGS := --prefix-symbols=__pi_ \ - --remove-section=.note.gnu.property \ - --prefix-alloc-sections=.init.pi - -$(BUILD)/%.pi.o: $(BUILD)/%.o - $(call cmd,objcopy) - -# Preprocess linker script template (.lds.S → .lds) -$(LINKER_SCRIPT): PRIVATE_SOURCE := $(LDS_SRC) -$(LINKER_SCRIPT): $(LDS_SRC) include/lume/lumeos.lds.h FORCE - $(Q)mkdir -p $(dir $@) - $(call if_changed,linker_script) - -# ============================================================ -# Initramfs: pack a root filesystem into a newc cpio. -# -# Pipeline mirrors Linux's Kbuild: -# usr/gen_init_cpio — host C tool, produces cpio bytes -# scripts/gen_initramfs.sh — wrapper that prepares the listing, -# handles directories vs. listing files, -# applies uid/gid remap, then invokes the -# host tool. -# Sourced from $(CONFIG_INITRAMFS_SOURCE) — see scripts/Kconfig.mk. -# ============================================================ - -# Host compiler environment is distinct from the cross kernel environment. -include scripts/build/environments/host.mk - -# Host tools are registered targets and use the host compiler environment. -HOST_TOOL_TARGETS := $(foreach target,$(targets),\ - $(if $(filter host-tool,$(target.$(target).kind)),$(target))) -HOST_LIBRARY_TARGETS := $(foreach target,$(targets),\ - $(if $(filter host-library,$(target.$(target).kind)),$(target))) -HOST_TEST_TARGETS := $(foreach target,$(targets),\ - $(if $(filter host-test,$(target.$(target).kind)),$(target))) -PHYS_LIBRARY_TARGETS := $(foreach target,$(targets),\ - $(if $(filter phys-library,$(target.$(target).kind)),$(target))) -define define-host-tool -target.$(1).output := $(BUILD)/host/$(call target-key,$(1)) -$$(target.$(1).output): PRIVATE_HOST_SOURCE := $$(firstword $$(target.$(1).sources)) -$$(target.$(1).output): PRIVATE_HOST_CFLAGS := $$(target.$(1).host-cflags) -$$(target.$(1).output): $$(target.$(1).sources) FORCE - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,host_tool) -endef -$(foreach target,$(HOST_TOOL_TARGETS),$(eval $(call define-host-tool,$(target)))) - -host-source-object = $(BUILD)/host/obj/$(call target-key,$(1))/$(basename $(2)).o -define define-host-source -$(call host-source-object,$(1),$(2)): PRIVATE_SOURCE := $(2) -$(call host-source-object,$(1),$(2)): $(2) FORCE - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,$(if $(filter %.cc,$(2)),host_cxx_o_cc,host_cc_o_c)) -endef -define define-host-library -target.$(1).objects := $$(foreach src,$$(target.$(1).sources),$$(call host-source-object,$(1),$$(src))) -target.$(1).archive := $(BUILD)/host/lib/$(call target-key,$(1)).a -$$(foreach src,$$(target.$(1).sources),$$(eval $$(call define-host-source,$(1),$$(src)))) -$$(target.$(1).archive): PRIVATE_ARCHIVE_OBJECTS := $$(target.$(1).objects) -$$(target.$(1).archive): $$(target.$(1).objects) FORCE - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,host_archive) -endef -$(foreach target,$(HOST_LIBRARY_TARGETS),$(eval $(call define-host-library,$(target)))) -HOST_DEPS := $(foreach target,$(HOST_LIBRARY_TARGETS),$(target.$(target).objects:.o=.d)) - -define define-host-test -target.$(1).objects := $$(foreach src,$$(target.$(1).sources),$$(call host-source-object,$(1),$$(src))) -target.$(1).output := $(BUILD)/host/test/$(call target-key,$(1)) -$$(foreach src,$$(target.$(1).sources),$$(eval $$(call define-host-source,$(1),$$(src)))) -$$(target.$(1).output): PRIVATE_HOST_OBJECTS := $$(target.$(1).objects) -$$(target.$(1).output): PRIVATE_HOST_LIBS := $$(foreach dep,$$(call target-deps,$(1)),$$(target.$$(dep).archive)) -$$(target.$(1).output): $$(target.$(1).objects) \ - $$(foreach dep,$$(call target-deps,$(1)),$$(target.$$(dep).archive)) FORCE - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,host_link) -endef -$(foreach target,$(HOST_TEST_TARGETS),$(eval $(call define-host-test,$(target)))) -HOST_TEST_DEPS := $(foreach target,$(HOST_TEST_TARGETS),$(target.$(target).objects:.o=.d)) -DEPS += $(HOST_DEPS) $(HOST_TEST_DEPS) - -host-libraries: $(foreach target,$(HOST_LIBRARY_TARGETS),$(target.$(target).archive)) - -host-tests: $(foreach target,$(HOST_TEST_TARGETS),$(target.$(target).output)) - @set -e; $(foreach target,$(HOST_TEST_TARGETS),\ - echo " TEST $(target)"; $(target.$(target).output);) - -phys-source-object = $(BUILD)/phys/obj/$(call target-key,$(1))/$(basename $(2)).o -define define-phys-source -$(call phys-source-object,$(1),$(2)): PRIVATE_SOURCE := $(2) -$(call phys-source-object,$(1),$(2)): $(2) $(AUTOCONF_H) FORCE - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,$(if $(filter %.cc,$(2)),phys_cxx_o_cc,$(if $(filter %.c,$(2)),phys_cc_o_c,phys_as_o_S))) -endef -define define-phys-library -target.$(1).objects := $$(foreach src,$$(target.$(1).sources),$$(call phys-source-object,$(1),$$(src))) -target.$(1).archive := $(BUILD)/phys/lib/$(call target-key,$(1)).a -$$(foreach src,$$(target.$(1).sources),$$(eval $$(call define-phys-source,$(1),$$(src)))) -$$(target.$(1).archive): PRIVATE_ARCHIVE_OBJECTS := $$(target.$(1).objects) -$$(target.$(1).archive): $$(target.$(1).objects) FORCE - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,archive) -endef -$(foreach target,$(PHYS_LIBRARY_TARGETS),$(eval $(call define-phys-library,$(target)))) -PHYS_DEPS := $(foreach target,$(PHYS_LIBRARY_TARGETS),$(target.$(target).objects:.o=.d)) -DEPS += $(PHYS_DEPS) - -phys-libraries: $(foreach target,$(PHYS_LIBRARY_TARGETS),$(target.$(target).archive)) - -kernel-tests: all - @test "$(CONFIG_SELFTEST)" = y || { \ - echo "kernel-tests requires CONFIG_SELFTEST=y in $(KCONFIG_CONFIG)"; exit 2; } - -GEN_INIT_CPIO := $(target.host/gen_init_cpio.output) - -INITRAMFS_SOURCE := $(CONFIG_INITRAMFS_SOURCE) - -# Encode the selected source in the stamp filename. Changing the source changes -# the dependency without writing anything during Makefile parsing. -INITRAMFS_SOURCE_KEY := $(shell printf '%s' '$(INITRAMFS_SOURCE)' | cksum | cut -d' ' -f1) -INITRAMFS_SRC_STAMP := $(BUILD)/.initramfs-source-$(INITRAMFS_SOURCE_KEY) - -$(INITRAMFS_SRC_STAMP): - @mkdir -p $(dir $@) - @touch $@ - -$(INITRAMFS_CPIO): $(INITRAMFS_SOURCE) $(INITRAMFS_SRC_STAMP) \ - $(GEN_INIT_CPIO) scripts/gen_initramfs.sh \ - scripts/build/generate-initramfs.sh FORCE - $(Q)mkdir -p $(dir $@) - $(call if_changed,initramfs) - -$(INITRAMFS_OBJ): PRIVATE_SOURCE := $(INITRAMFS_ASM) -$(INITRAMFS_OBJ): $(INITRAMFS_CPIO) $(INITRAMFS_ASM) FORCE - $(Q)mkdir -p $(dir $@) - $(call if_changed,initramfs_obj) - -# Single-pass kernel link. With `-shared -Bsymbolic`, the linker -# emits `.rela.dyn` containing R_RISCV_RELATIVE entries directly into -# the output ELF — no separate gen_reloc pass. -$(VMLUME): $(OBJS) $(foreach target,$(KERNEL_STATIC_TARGETS) $(KERNEL_WHOLE_TARGETS),\ - $(target.$(target).archive)) \ - $(INITRAMFS_OBJ) $(LINKER_SCRIPT) FORCE - $(Q)mkdir -p $(dir $@) - $(call if_changed,link_vmlume) - -# Image = raw binary, mirrors Linux's `arch/riscv/boot/Image` (objcopy -# vmlinux to raw bytes, no ELF header — what U-Boot or QEMU's `-bios` -# bare-loading would consume). Linux always builds both vmlinux and -# Image; LumeOS follows the same convention. -$(IMAGE): $(VMLUME) FORCE - $(call if_changed,objcopy_bin) - -# Materialize one explicit action per target/source pair. This avoids accidental -# object reuse when the same source is built in more than one environment. -define define-kernel-source -$(call source-object,$(1),$(2)): $(2) - $$(Q)mkdir -p $$(dir $$@) - $$(call if_changed,$(if $(filter %.cc,$(2)),cxx_o_cc,$(if $(filter %.c,$(2)),cc_o_c,as_o_S))) -endef -$(foreach target,$(KERNEL_SOURCE_TARGETS),$(foreach src,$(target.$(target).sources),\ - $(eval $(call define-kernel-source,$(target),$(src))))) - -# Auto-dependency tracking --include $(DEPS) - -# ============================================================ -# Run & Debug -# ============================================================ -ifeq ($(ARCH),riscv) -QEMU := qemu-system-riscv64 -QEMU_MACHINE := -machine virt -smp 4 -m 128M -nographic -QEMU_BIOS := -bios default -else ifeq ($(ARCH),aarch64) -QEMU := qemu-system-aarch64 -QEMU_MACHINE := -machine virt -cpu cortex-a53 -m 128M -nographic -QEMU_BIOS := -else ifeq ($(ARCH),x86_64) -QEMU := qemu-system-x86_64 -QEMU_MACHINE := -m 128M -nographic -QEMU_BIOS := -endif - -run: $(VMLUME) $(IMAGE) - @echo " QEMU Running..." - $(QEMU) $(QEMU_MACHINE) $(QEMU_BIOS) -kernel $(VMLUME) - -debug: $(VMLUME) $(IMAGE) - @echo " QEMU Waiting for GDB on :1234..." - $(QEMU) $(QEMU_MACHINE) $(QEMU_BIOS) -kernel $(VMLUME) -s -S - -# ============================================================ -# Utilities -# ============================================================ -clean: - rm -rf $(BUILD) - -disasm: $(VMLUME) - @echo " OBJDUMP $<" - @$(OBJDUMP) -d -S $(VMLUME) > $(VMLUME).asm - @echo " Written to $(VMLUME).asm" - -fmt: - @echo " FMT Formatting source files..." - @find . -name '*.cc' -o -name '*.h' | xargs clang-format -i 2>/dev/null || true - -lint: - @echo " LINT Generating compile_commands.json via bear..." - @bear -- $(MAKE) all - @echo " LINT Running clang-tidy on C++ sources..." - @clang-tidy -p . $(SRCS_CC) || true - -# Print build info (for debugging Makefile issues) -info: - @echo "LumeOS build configuration" - @echo " ARCH $(ARCH)" - @echo " PLATFORM $(PLATFORM)" - @echo " VARIANT $(BUILD_VARIANT)" - @echo " OUTPUT $(BUILD)" - @echo " COMPILER $(COMPILER_FAMILY): $(CXX)" - @echo " TARGET $(TARGET_TRIPLE)" - @echo " GCC_TOOLCHAIN $(GCC_TOOLCHAIN)" - @echo " SYSROOT $(GCC_SYSROOT)" - @echo " RESOURCE HEADERS $(COMPILER_RESOURCE_INCLUDE)" - @echo " LINKER $(LINKER_FAMILY): $(LD)" - @echo " OBJCOPY $(OBJCOPY)" - @echo " INITRAMFS $(INITRAMFS_SOURCE)" - @echo " C++ STANDARD C++23" - @echo " C++ LIBRARY $(CXX_STDLIB)" - @echo " libc++ HEADERS $(LIBCXX_INCLUDE)" - @echo " KTL CONFIG $(KTL_INCLUDE)" - @echo " KERNEL LIBC $(KERNEL_LIBC_INCLUDE)" - @echo " C++ ABI $(CXX_ABI)" - @echo " COMPILER RUNTIME $(COMPILER_RUNTIME)" - @echo " CONFIG $(KCONFIG_CONFIG)" - @echo " BUILD ROOT $(KERNEL_ROOT)" - @echo " TARGETS $(words $(KERNEL_TARGETS)) selected / $(words $(targets)) registered" - -targets: - @$(foreach target,$(targets),printf '%-24s %-16s %s\n' \ - '$(target)' '$(target.$(target).kind)' '$(target.$(target).deps)';) - -target-info: - @test -n "$(TARGET)" || { echo "usage: make target-info TARGET="; exit 2; } - @$(if $(filter $(TARGET),$(targets)),,echo "unknown target: $(TARGET)"; exit 2;) - @echo "Target: $(TARGET)" - @echo "Kind: $(target.$(TARGET).kind)" - @echo "Dependencies: $(target.$(TARGET).deps)" - @echo "Public deps: $(target.$(TARGET).public-deps)" - @echo "Private deps: $(target.$(TARGET).private-deps)" - @echo "Link deps: $(target.$(TARGET).link-deps)" - @echo "Tool deps: $(target.$(TARGET).tool-deps)" - @echo "Generated deps: $(target.$(TARGET).generated-deps)" - @echo "Closure: $(sort $(call target-closure,$(TARGET)))" - @echo "Public includes: $(target.$(TARGET).public-includes)" - @echo "Private includes: $(target.$(TARGET).private-includes)" - @echo "Sources: $(target.$(TARGET).sources)" - -TARGET_GRAPH := $(BUILD)/targets.dot -graph: - @mkdir -p $(BUILD) - @$(file >$(TARGET_GRAPH),digraph lume_build {) - @$(foreach target,$(targets),$(file >>$(TARGET_GRAPH), "$(target)" [label="$(target)\n$(target.$(target).kind)"];)) - @$(foreach target,$(targets),$(foreach dep,$(call target-deps,$(target)),\ - $(file >>$(TARGET_GRAPH), "$(target)" -> "$(dep)";))) - @$(file >>$(TARGET_GRAPH),}) - @echo " GRAPH $(TARGET_GRAPH)" - -COMPDB := $(BUILD)/compile_commands.json -COMPDB_INPUT := $(BUILD)/.compile_commands.tsv -compile-command = $(if $(filter %.cc,$(2)),$(CXX) $(CXXFLAGS) \ - $(addprefix -I,$(call target-compile-includes,$(1))) \ - $(foreach dir,$(call target-compile-after-includes,$(1)),-idirafter $(dir)) \ - $(addprefix -D,$(call target-compile-defines,$(1))) $(target.$(1).cxxflags),\ - $(CC) $(if $(filter %.c,$(2)),$(CFLAGS_LIBC) \ - $(addprefix -I,$(call target-compile-includes,$(1))) \ - $(foreach dir,$(call target-compile-after-includes,$(1)),-idirafter $(dir)) \ - $(addprefix -D,$(call target-compile-defines,$(1))) $(target.$(1).cflags),\ - $(ASFLAGS) $(addprefix -I,$(call target-compile-includes,$(1))) \ - $(foreach dir,$(call target-compile-after-includes,$(1)),-idirafter $(dir)) \ - $(addprefix -D,$(call target-compile-defines,$(1))) \ - $(target.$(1).asflags))) -c $(2) -o $(call source-object,$(1),$(2)) - -$(BUILD): - @mkdir -p $@ - -$(COMPDB_INPUT): FORCE | $(BUILD) - @$(file >$(COMPDB_INPUT)) - @$(foreach target,$(KERNEL_SOURCE_TARGETS),$(foreach src,$(target.$(target).sources),\ - $(file >>$(COMPDB_INPUT),$(src) $(call source-object,$(target),$(src)) $(call compile-command,$(target),$(src))))) - -compile_commands: $(COMPDB_INPUT) - @$(PYTHON) scripts/build/write-compdb.py $(COMPDB_INPUT) $(COMPDB) - @echo " COMPDB $(COMPDB)" - -check-toolchain: - @command -v $(firstword $(CC)) >/dev/null || { echo "missing C compiler: $(CC)"; exit 1; } - @command -v $(firstword $(CXX)) >/dev/null || { echo "missing C++ compiler: $(CXX)"; exit 1; } - @command -v $(firstword $(LD)) >/dev/null || { echo "missing linker: $(LD)"; exit 1; } - @command -v $(firstword $(OBJCOPY)) >/dev/null || { echo "missing objcopy: $(OBJCOPY)"; exit 1; } - @$(CXX) $(TOOLCHAIN_CFLAGS) $(TOOLCHAIN_CXXFLAGS) -std=c++23 \ - -ffreestanding -fno-exceptions -fno-rtti \ - -Iinclude -I$(KTL_INCLUDE) -I$(KERNEL_LIBC_INCLUDE) \ - -idirafter $(KTL_AFTER_INCLUDE) -idirafter $(KERNEL_LIBC_AFTER_INCLUDE) \ - -fsyntax-only scripts/build/probes/libcxx.cc - @$(CXX) $(TOOLCHAIN_CFLAGS) $(TOOLCHAIN_CXXFLAGS) -std=c++23 \ - -ffreestanding -fno-exceptions -fno-rtti \ - -Iinclude -I$(KTL_INCLUDE) -I$(KERNEL_LIBC_INCLUDE) \ - -idirafter $(KTL_AFTER_INCLUDE) -idirafter $(KERNEL_LIBC_AFTER_INCLUDE) \ - -fsyntax-only scripts/build/probes/libc_headers.cc - @$(CC) $(TOOLCHAIN_CFLAGS) -std=gnu23 -ffreestanding \ - -Iinclude -I$(KERNEL_LIBC_INCLUDE) \ - -idirafter $(KERNEL_LIBC_AFTER_INCLUDE) \ - -fsyntax-only scripts/build/probes/libc_headers.c - @echo "Toolchain OK: $$($(CXX) --version | head -n 1)" - -TOOLCHAIN_REPORT := $(BUILD)/toolchain.report -$(TOOLCHAIN_REPORT): FORCE scripts/build/probe-toolchain.sh - $(Q)mkdir -p $(dir $@) - $(call if_changed,toolchain_probe) - -toolchain-probe: $(TOOLCHAIN_REPORT) - @cat $(TOOLCHAIN_REPORT) - -check-toolchain: $(TOOLCHAIN_REPORT) - -help: - @echo "LumeOS build targets:" - @echo " all Build vmlume.elf and vmlume.bin (default)" - @echo " run Run the selected image in QEMU" - @echo " debug Run QEMU with a GDB server on :1234" - @echo " disasm Generate an interleaved source disassembly" - @echo " info Show the effective build configuration" - @echo " check-toolchain Validate compiler, linker, and C++23 support" - @echo " check-image Validate ELF architecture, symbols, segments, and relocations" - @echo " targets List registered build targets and dependencies" - @echo " target-info Explain TARGET=" - @echo " compile_commands Generate an O= scoped compilation database" - @echo " graph Write the target dependency graph as DOT" - @echo " host-libraries Build registered native static libraries" - @echo " host-tests Build and run registered native tests" - @echo " phys-libraries Build early physical-environment libraries" - @echo " kernel-tests Build the test-enabled kernel (CONFIG_SELFTEST=y)" - @echo " toolchain-probe Probe and cache required compiler capabilities" - @echo " clean Remove only the selected O= output tree" - @echo "" - @echo "Common options:" - @echo " O= Output directory (default: build)" - @echo " LLVM=1 Use Clang with GNU ld" - @echo " LLVM=1 LD_TYPE=lld Use Clang with LLD" - @echo " LLVM_VERSION= Versioned LLVM tools (default: 20)" - @echo " CROSS_COMPILE= Override GNU cross-tool prefix" - @echo " GCC_TOOLCHAIN= GCC installation used by Clang for target headers/builtins" - @echo " V=1 Print full command lines" - @echo " CONFIG_INITRAMFS_SOURCE= Select initramfs input" diff --git a/README.md b/README.md deleted file mode 100644 index 1e0e20a..0000000 --- a/README.md +++ /dev/null @@ -1,105 +0,0 @@ -# Lume OS -**A Lightweight, Educational RISC-V Operating System** -> Luminescence in the Deep Night - -Lume OS is a 64-bit monolithic operating system kernel written in C++ for the RISC-V architecture. Currently designed for educational purposes and kernel hacking, the project is now evolving towards a Tiny Linux-Compatible Kernel capable of running standard Linux userspace binaries (musl libc, BusyBox, etc.) by implementing the Linux Syscall ABI. - -## Note -After studying for a period of time, I have roughly understood the design of some modern operating systems such as Windows, Linux, and BSD. I decided to refactor this operating system to make its architecture clear, scalable, and portable. My goal is to make this system compatible with the Linux ABI, so that musl libc and busybox can be easily ported, thereby introducing the ability to depend on more Linux software. Although this goal is very distant, I still decided to try. I have chosen to use C++ as the development language, even though many people think C++ is not a language for developing kernels, I believe that the object-oriented features of C++ can make system code easier to read and understand. Compared to reading various complex macros, reading some object-oriented code might be easier for people unfamiliar with the kernel. Therefore, I decided to sacrifice some performance along with extra handling for the C++ runtime in order to achieve this; after all, you have to give up something to gain something. - -The actively developed kernel now lives at the repository root. The previous implementation has been archived in `lume-legacy/` for reference. After learning about the development history of Windows NT, I realized the importance of documentation. The NT team spent a lot of time writing documentation before writing the first line of code, and by the time they wrote code, the system was basically finalized. As a student who is not particularly outstanding, I cannot complete the design of the system before starting to write code, but I can decide on its design before starting each part, and then adjust it according to reality. The documents are in `docs/specs/` directory. - -It can basically be concluded that writing an operating system in this era is a thankless task. A personally implemented operating system may never run on machines beyond my own tests, so what is the point of doing this? Perhaps it is just to add color to a monotonous life. However, if you really have ideas, you are welcome to contact me. - -The project still uses the GPL v2 License. Since I plan to use GPL v2-only software such as busybox, I cannot make the entire project GPL v3, but for the parts of the source code that I independently complete, you can use GPL v2 or later versions. We must insist on free software; please support the free software movement. This is not about price, it is about freedom. - -The following content and the original source code are all deprecated, and it is not recommended that you spend time reading that bad stuff. Your time is valuable and should be spent on more meaningful things. - -## 🛠 Build & Run - -### Prerequisites -* Toolchain: `riscv64-linux-gnu-g++` / `gcc` - -* Emulator: `qemu-system-riscv64` - -* Build System: `make` - -### Compiling -```Bash -# Compile kernel and user programs -make all -``` - -### Running in QEMU -```Bash -# Run the OS -make run - -# Debug mode (attaches GDB) -make debug -``` - -## 🏗 System Architecture & Current Features -Based on the current source tree, Lume OS implements the following core subsystems: - -### 1. Kernel Core & Hardware Abstraction -* Architecture: RISC-V 64-bit (Sv39 paging) targeting QEMU `virt` machine. - -* Boot: Device Tree (FDT) parsing for hardware discovery. - -* Concurrency: SMP (Symmetric Multi-Processing) support with per-CPU state management. - -* Traps: Supervisor-mode interrupt and exception handling. - -### 2. Memory Management -* Physical Memory: Buddy System allocator for page-level management. - -* Kernel Heap: SLAB allocator (`kmalloc`/`kfree`) for efficient object management. - -* Virtual Memory: Basic paging support. Current user process memory model is linear (heap grows contiguously via `sbrk`). - -### 3. Process Management -* Scheduling: Round-Robin scheduler with per-CPU runqueues and work stealing mechanisms. - -* Context Switching: Saves callee-saved registers; currently lacks FPU/Vector state saving. - -* Lifecycle: Basic `fork`, `exec`, `exit`, and `wait` system calls. - -### 4. File System & I/O -* VFS: A preliminary Virtual File System abstraction with `inode` polymorphism. - -* Filesystem: FAT32 implementation with basic read/write/create/delete support. - -* Buffer Cache: Block-level caching (Bio) coupled with the VirtIO driver. - -* Drivers: - - * VirtIO: Block device driver (MMIO). - - * UART: 16550A-compatible serial console driver with line buffering. - - * PLIC: Platform-Level Interrupt Controller support. - -### 5. User Space -* Libc: A minimal custom C library (`ulib`) providing stdio (`printf`/`scanf`), stdlib (`malloc`/`free`), and string operations. - -* Shell: A functional shell (`sh`) supporting pipes (`|`), redirection (`<`, `>`), and background execution (`&`). - -* Utils: Standard Unix-like tools: `ls`, `cat`, `echo`, `mkdir`, `rm`, `touch`, `cp`, `mv`. - -## 📄 License - -Lume OS is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -Lume OS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -See the [LICENSE](LICENSE) file for details. diff --git a/arch/riscv/Build.mk b/arch/riscv/Build.mk deleted file mode 100644 index 0a18344..0000000 --- a/arch/riscv/Build.mk +++ /dev/null @@ -1,19 +0,0 @@ -targets += arch/riscv -target.arch/riscv.kind := source-set -target.arch/riscv.public-includes := arch/riscv/include -target.arch/riscv.sources := \ - arch/riscv/mm/pmap.cc \ - arch/riscv/mm/init.cc \ - arch/riscv/config.cc \ - arch/riscv/trap/trap_md.cc \ - arch/riscv/syscall/syscall_md.cc \ - arch/riscv/lib/random.cc \ - arch/riscv/mm/tlb_md.cc \ - arch/riscv/kernel/head.S \ - arch/riscv/trap/swtch.S \ - arch/riscv/trap/fpu.S \ - arch/riscv/trap/trap_vector.S \ - arch/riscv/uaccess/uaccess_memcpy.S \ - arch/riscv/trap/extable.cc \ - arch/riscv/kernel/signal.cc - diff --git a/arch/riscv/config.cc b/arch/riscv/config.cc deleted file mode 100644 index a18a825..0000000 --- a/arch/riscv/config.cc +++ /dev/null @@ -1,276 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * RISC-V Architecture Configuration — runtime state and KASLR - * - * Provides the runtime (post-KASLR) values of the higher-half - * virtual address bases. kaslr_init() is called once during - * early boot, before vmm_init(), to randomise the layout and - * fill the unified KaslrLayout structure. - * - * KASLR slide budget: - * The default Direct Map starts at 0xFFFFFFC0_0000_0000 (VPN[2]=256). - * The default Vmemmap starts at 0xFFFFFFD0_0000_0000 (VPN[2]=320). - * A 1GB superpage occupies one VPN[2] slot. We allow a slide of - * 0..63 slots (0..63 GB) upward, which keeps both regions inside - * the upper canonical half and avoids colliding with the kernel - * text region (linked at VPN[2] = 258 + 2 = ~0xFFFFFFC0_8020_0000). - * - * In practice, with 128MB RAM the kernel+direct map only touches - * VPN[2] 258-259, so a slide of up to 63GB is safe. - */ - -#include -#include -#include -#include -#include -#include -#include - -extern "C" char _stext[], _kernel_end[]; - -namespace arch { - -/* Global KASLR Layout Structure*/ -KaslrLayout g_kaslr_layout = {}; - -/* Runtime bases — updated by kaslr_layout_compute() */ -uint64 g_direct_map_base = kDirectMapBaseDefault; -uint64 g_vmemmap_base = kVmemmapBaseDefault; - -/* VA Range for validation */ -struct VaRange { - const char* name; - uint64 start; - uint64 end; // exclusive -}; - -/* ================================================================ - * Utilities - * ================================================================ */ -static inline uint64 align_down_page(uint64 v) -{ - return v & ~(kPageSize - 1); -} - -static inline uint64 align_up_page(uint64 v) -{ - return (v + kPageSize - 1) & ~(kPageSize - 1); -} - -static uint64 checked_add_u64(uint64 a, uint64 b, const char* detail) -{ - if (a > (~0ULL - b)) { - kernel_panic("kaslr: address overflow", detail); - } - return a + b; -} - -/* Splitmix64: non-plaintext hash derived from seed (used for seed_hash) */ -static uint64 splitmix64(uint64 x) -{ - x += 0x9e3779b97f4a7c15ULL; - x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL; - x = x ^ (x >> 27); - return x * 0x94d049bb133111ebULL; -} - -/* SV39 canonical VA check: bits [63:39] must equal sign bit 38. */ -static bool is_sv39_canonical(uint64 va) -{ - uint64 sign = (va >> 38) & 1ULL; - uint64 upper = va >> 39; - return sign ? (upper == ((1ULL << 25) - 1ULL)) : (upper == 0); -} - -static bool is_sv39_kernel_half(uint64 va) -{ - return is_sv39_canonical(va) && (((va >> 38) & 1ULL) == 1ULL); -} - -static bool ranges_overlap(const VaRange& a, const VaRange& b) -{ - return (a.start < b.end) && (b.start < a.end); -} - -/* ================================================================ - * KASLR Computation (Phase A: Centralized in single function) - * - * This function: - * 1. Generates or derives random seed - * 2. Selects 1GB-aligned slot [0..63] - * 3. Computes seed_hash via splitmix64 - * 4. Fills KaslrLayout structure completely - * 5. Validates ranges (canonical, overlaps) - * 6. Logs according to CONFIG_KASLR_LOG_LEVEL - * ================================================================ */ -static void kaslr_layout_compute() -{ -#ifdef CONFIG_KASLR - constexpr uint64 k1GB = 1ULL << 30; - constexpr uint64 kMaxSlots = 64; - - /* 1. Get seed and source */ - uint64 seed = random_early_seed_value(); - RandomSeedSource rsrc = random_early_seed_source(); - KaslrSeedSource source; - switch (rsrc) { - case RandomSeedSource::FdtProvided: - source = KaslrSeedSource::kFdt; - break; - case RandomSeedSource::HwRandom: - source = KaslrSeedSource::kHardware; - break; - case RandomSeedSource::CycleFallback: - case RandomSeedSource::Unknown: - default: - source = KaslrSeedSource::kCycle; - break; - } - - /* 2. Select random slot and compute slide */ - uint64 raw = get_random_u64(); - uint64 slot = raw % kMaxSlots; - if (slot == 0) { - slot = 1; /* slot=0 causes direct_map to overlap with kernel image VA */ - } - uint64 slide = slot * k1GB; - - /* 3. Compute non-plaintext hash */ - uint64 seed_hash = splitmix64(seed ^ 0xdeadbeefdeadbeefULL); - - /* 4. Compute randomised bases */ - uint64 direct_map_base = kDirectMapBaseDefault + slide; - uint64 vmemmap_base = kVmemmapBaseDefault + slide; - - /* 5. Fill KaslrLayout */ - g_kaslr_layout.seed = seed; - g_kaslr_layout.seed_hash = seed_hash; - g_kaslr_layout.source = source; - g_kaslr_layout.slot = slot; - g_kaslr_layout.slide_bytes = slide; - g_kaslr_layout.policy_id = kKaslrPolicyId; - g_kaslr_layout.direct_map_base = direct_map_base; - g_kaslr_layout.vmemmap_base = vmemmap_base; - g_kaslr_layout.canonical_ok = false; - g_kaslr_layout.overlap_ok = false; - - /* Update global runtime bases */ - g_direct_map_base = direct_map_base; - g_vmemmap_base = vmemmap_base; - - /* 6. Self-check: canonical VA validation and overlap detection */ - uint64 mem_base = 0, mem_size = 0; - fdt_early_get_mem_info(&mem_base, &mem_size); - if (mem_size == 0) { - kernel_panic("kaslr_layout_compute: invalid memory from FDT"); - } - - /* Construct VA ranges */ - uint64 num_pages = mem_size / kPageSize; - uint64 page_bytes = num_pages * sizeof(Page); - uint64 page_span = align_up_page(page_bytes); - - VaRange direct_map { - "direct-map", - checked_add_u64(g_direct_map_base, mem_base, "direct_map start"), - checked_add_u64(checked_add_u64(g_direct_map_base, mem_base, - "direct_map start"), - mem_size, "direct_map end"), - }; - - VaRange vmemmap { - "vmemmap", - g_vmemmap_base, - checked_add_u64(g_vmemmap_base, page_span, "vmemmap end"), - }; - - VaRange kernel_img { - "kernel-image", - align_down_page(reinterpret_cast(_stext)), - align_up_page(reinterpret_cast(_kernel_end)), - }; - - /* Validate each range is canonical */ - auto check_kernel_half = [](const VaRange& r) { - if (r.start >= r.end) { - kernel_panic("kaslr: invalid VA range", r.name); - } - if (!is_sv39_kernel_half(r.start) || !is_sv39_kernel_half(r.end - 1)) { - kernel_panic("kaslr: non-canonical kernel VA range", r.name); - } - }; - - check_kernel_half(direct_map); - check_kernel_half(vmemmap); - check_kernel_half(kernel_img); - - /* Validate no overlaps */ - if (ranges_overlap(direct_map, kernel_img)) { - kernel_panic("kaslr: direct-map overlaps kernel image"); - } - if (ranges_overlap(vmemmap, kernel_img)) { - kernel_panic("kaslr: vmemmap overlaps kernel image"); - } - if (ranges_overlap(direct_map, vmemmap)) { - kernel_panic("kaslr: direct-map overlaps vmemmap"); - } - - /* Mark validation success */ - g_kaslr_layout.canonical_ok = true; - g_kaslr_layout.overlap_ok = true; - - /* 7. Logging according to CONFIG_KASLR_LOG_LEVEL */ - if (kKaslrLogLevel >= 1) { - /* Minimal logging: just the seed and slot (release mode) */ - kprintf("[boot][kaslr] policy_id=%u source=%s slot=%llu\n", - g_kaslr_layout.policy_id, - random_seed_source_name(rsrc), - slot); - } - - if (kKaslrLogLevel >= 2) { - /* Debug logging: full ranges and hashes */ - kprintf("[boot][kaslr] seed=0x%llx seed_hash=0x%llx\n", - seed, seed_hash); - kprintf("[boot][kaslr] direct-map=[0x%llx,0x%llx)\n", - direct_map.start, direct_map.end); - kprintf("[boot][kaslr] vmemmap=[0x%llx,0x%llx)\n", - vmemmap.start, vmemmap.end); - kprintf("[boot][kaslr] kernel-image=[0x%llx,0x%llx)\n", - kernel_img.start, kernel_img.end); - } - -#else /* CONFIG_KASLR disabled */ - g_kaslr_layout.seed = 0; - g_kaslr_layout.seed_hash = 0; - g_kaslr_layout.source = KaslrSeedSource::kCycle; - g_kaslr_layout.slot = 0; - g_kaslr_layout.slide_bytes = 0; - g_kaslr_layout.policy_id = kKaslrPolicyId; - g_kaslr_layout.direct_map_base = kDirectMapBaseDefault; - g_kaslr_layout.vmemmap_base = kVmemmapBaseDefault; - g_kaslr_layout.canonical_ok = true; - g_kaslr_layout.overlap_ok = true; - - g_direct_map_base = kDirectMapBaseDefault; - g_vmemmap_base = kVmemmapBaseDefault; - - if (kKaslrLogLevel >= 1) { - kprintf("[boot][kaslr] disabled policy_id=%u\n", - g_kaslr_layout.policy_id); - } -#endif -} - -/* ================================================================ - * Public entry point - * ================================================================ */ -void kaslr_init() -{ - kaslr_layout_compute(); -} - -} // namespace arch diff --git a/arch/riscv/defconfig b/arch/riscv/defconfig deleted file mode 100644 index 87d3ffd..0000000 --- a/arch/riscv/defconfig +++ /dev/null @@ -1,39 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2026 Richard Qin -# -# LumeOS Default Kernel Configuration — RISC-V (virt) -# -# This is the "golden" default configuration for the RISC-V virt platform. -# To customise, copy this file to the source root as '.config': -# -# cp arch/riscv/defconfig .config -# $EDITOR .config -# make -# -# Any variable not set here inherits its default from scripts/Kconfig.mk. -# ====================================================================== - -# --- Platform ----------------------------------------------------------- -CONFIG_ARCH = riscv - -# --- CPU / SMP ---------------------------------------------------------- -CONFIG_NR_CPUS = 8 - -# --- Scheduler ---------------------------------------------------------- -CONFIG_HZ = 100 -CONFIG_NR_PRIORITIES = 32 - -# --- Memory Management -------------------------------------------------- -CONFIG_PAGE_SIZE = 4096 -CONFIG_MAX_ORDER = 11 -CONFIG_KERNEL_STACK_SIZE = 8192 - -# --- Security / Hardening ----------------------------------------------- -CONFIG_KASLR = y -CONFIG_STACK_CANARY = y - -# --- Debug --------------------------------------------------------------- -CONFIG_DEBUG = y -CONFIG_DEBUG_LOCKS = y -CONFIG_SELFTEST = y -CONFIG_KLOG = y diff --git a/arch/riscv/include/arch/config.h b/arch/riscv/include/arch/config.h deleted file mode 100644 index 8ae0502..0000000 --- a/arch/riscv/include/arch/config.h +++ /dev/null @@ -1,106 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * RISC-V Architecture Configuration - * - * These constants define the architecture-specific memory layout. - * Each arch/ implementation must provide this header with the same symbols. - * - * KASLR: At boot, kaslr_init() randomises g_direct_map_base and - * g_vmemmap_base. All MI code must read these runtime variables - * (via pa_to_va / vmm helpers) rather than the static defaults. - */ - -#include - -namespace arch { - -/* ================================================================ - * Default (compile-time) virtual addresses - * - * SV39 gives a 512GB virtual address space. - * Higher-half layout (defaults before KASLR): - * - * 0xFFFFFFC0_00000000 (256) Direct map (PA+offset) - * 0xFFFFFFD0_00000000 (320) Vmemmap (Page array) - * - * The 64GB gap between them is the KASLR slide range. - * ================================================================ */ -inline constexpr uint64 kDirectMapBaseDefault = 0xFFFFFFC000000000ULL; -inline constexpr uint64 kVmemmapBaseDefault = 0xFFFFFFD000000000ULL; - -/* Physical memory base (where RAM starts on RISC-V virt platform) */ -inline constexpr uint64 kPhysBase = 0x80000000ULL; - -/* Kernel physical load address (= PHYS_BASE in linker script). - * Everything in [kPhysBase, kPhysStart) is firmware territory (PMP-protected). - * Analogous to Linux's CONFIG_PHYSICAL_START. */ -inline constexpr uint64 kPhysStart = 0x80200000ULL; - -/* ================================================================ - * Runtime (post-KASLR) virtual addresses - * - * These start equal to the defaults above. If CONFIG_KASLR is - * enabled, kaslr_init() adds a random, 1GB-aligned offset - * to each, sliding both regions upward in VA space. - * ================================================================ */ -extern uint64 g_direct_map_base; -extern uint64 g_vmemmap_base; - -/* ================================================================ - * KASLR Layout Structure (Phase A: Unified KASLR State) - * - * This struct holds all KASLR results: the random seed, derived - * hash, selected slot, and the randomised virtual address bases. - * It serves as the single source of truth for all KASLR decisions - * and is filled once during boot and read-only thereafter. - * ================================================================ */ - -enum class KaslrSeedSource : uint8 { - kFdt = 0, /* Loaded from FDT /random node */ - kHardware = 1, /* From hardware RNG (e.g., RDRAND) */ - kCycle = 2, /* Fallback: CPU cycle counter */ -}; - -struct KaslrLayout { - /* Seed and provenance */ - uint64 seed; /* 64-bit random seed value */ - uint64 seed_hash; /* Non-plaintext derived hash (splitmix64) */ - KaslrSeedSource source; /* Seed provenance (fdt/hw/cycle) */ - - /* Randomisation parameters */ - uint64 slot; /* Slot index: [0, 63] */ - uint64 slide_bytes; /* Byte offset: slot * 1GB */ - - /* Build-time policy */ - uint32 policy_id; /* CONFIG_KASLR_POLICY_ID at build time */ - - /* Randomised base addresses (post-KASLR) */ - uint64 direct_map_base; /* Direct map VA (kDirectMapBaseDefault + slide) */ - uint64 vmemmap_base; /* Vmemmap VA (kVmemmapBaseDefault + slide) */ - - /* Validation flags (for debug logging) */ - bool canonical_ok; /* All VA ranges passed canonical check */ - bool overlap_ok; /* No overlaps detected between regions */ -}; - -/* ================================================================ - * KASLR entry point - * - * Must be called AFTER random_early_init() and BEFORE vmm_init(). - * Fills g_kaslr_layout with randomised bases and self-check results. - * When CONFIG_KASLR is disabled this is a no-op. - * ================================================================ */ -extern KaslrLayout g_kaslr_layout; - -void kaslr_init(); - -/* Helper to query the KASLR layout safely */ -static inline const KaslrLayout& kaslr_layout_get() { - return g_kaslr_layout; -} - -} // namespace arch diff --git a/arch/riscv/include/arch/context.h b/arch/riscv/include/arch/context.h deleted file mode 100644 index 3d935fa..0000000 --- a/arch/riscv/include/arch/context.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Context Switch Structure (RISC-V 64) - * - * Holds only callee-saved registers for voluntary (non-preemptive) - * context switches between kernel threads / tasks. - * - * Used by: arch::context_switch() in swtch.S - * Reference: docs/specs/arch_abstraction.md §3.1 - */ - -#include - -namespace arch { - -struct Context { - uint64 ra; // 0: Return address - uint64 sp; // 8: Stack pointer - uint64 s[12]; // 16: s0-s11 (callee-saved registers) -}; - -static_assert(sizeof(Context) == 112); - -// Assembly-implemented context switch. -// Saves current CPU registers to old_ctx, loads next_ctx into CPU. -// Defined in arch/riscv/trap/swtch.S -extern "C" void context_switch(Context* old_ctx, Context* next_ctx); - -} // namespace arch diff --git a/arch/riscv/include/arch/cpu.h b/arch/riscv/include/arch/cpu.h deleted file mode 100644 index 8c573ec..0000000 --- a/arch/riscv/include/arch/cpu.h +++ /dev/null @@ -1,95 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * CPU Control & Status Primitives (RISC-V 64) - * - * Provides interrupt enable/disable, CPU ID, timer, and halt. - * All functions are static inline — zero call overhead. - * - * Precondition: tp register must be initialized with CPU ID - * by entry.S before any of these functions are called. - * - * Reference: docs/specs/arch_abstraction.md §4.1 - */ - -#include - -/* RISC-V sstatus register bit definitions */ -#define SSTATUS_SIE (1UL << 1) /* Supervisor Interrupt Enable */ -#define SSTATUS_SPIE (1UL << 5) /* Supervisor Previous Interrupt Enable */ -#define SSTATUS_SPP (1UL << 8) /* Supervisor Previous Privilege (0=U, 1=S) */ - -/* RISC-V sie register bit definitions */ -#define SIE_SSIE (1UL << 1) /* Supervisor Software Interrupt Enable */ -#define SIE_STIE (1UL << 5) /* Supervisor Timer Interrupt Enable */ -#define SIE_SEIE (1UL << 9) /* Supervisor External Interrupt Enable */ - -namespace arch::cpu { - -// Get current CPU ID (from tp register, set by entry.S) -static inline uint64 id() { - uint64 val; - __asm__ volatile("mv %0, tp" : "=r"(val)); - return val; -} - -// Enable interrupts (set sstatus.SIE = 1) -static inline void intr_on() { - __asm__ volatile("csrs sstatus, %0" :: "r"(SSTATUS_SIE)); -} - -// Disable interrupts (clear sstatus.SIE = 0) -static inline void intr_off() { - __asm__ volatile("csrc sstatus, %0" :: "r"(SSTATUS_SIE)); -} - -// Check if interrupts are currently enabled -static inline bool intr_enabled() { - uint64 sstatus; - __asm__ volatile("csrr %0, sstatus" : "=r"(sstatus)); - return (sstatus & SSTATUS_SIE) != 0; -} - -// Halt CPU until next interrupt (wfi instruction) -static inline void halt_until_interrupt() { - __asm__ volatile("wfi"); -} - -// Read hardware monotonic timer (rdtime instruction) -// Returns ticks since boot; frequency from FDT timebase-frequency. -static inline uint64 read_time() { - uint64 val; - __asm__ volatile("rdtime %0" : "=r"(val)); - return val; -} - -// Enable timer interrupt in sie (sie.STIE = 1) -static inline void timer_intr_on() { - __asm__ volatile("csrs sie, %0" :: "r"(SIE_STIE)); -} - -// Disable timer interrupt in sie (sie.STIE = 0) -static inline void timer_intr_off() { - __asm__ volatile("csrc sie, %0" :: "r"(SIE_STIE)); -} - -// Enable software interrupt in sie (sie.SSIE = 1) — needed for IPI -static inline void software_intr_on() { - __asm__ volatile("csrs sie, %0" :: "r"(SIE_SSIE)); -} - -// Enable external interrupt in sie (sie.SEIE = 1) — needed for PLIC (UART, etc.) -static inline void external_intr_on() { - __asm__ volatile("csrs sie, %0" :: "r"(SIE_SEIE)); -} - -// Clear S-mode software interrupt pending bit (sip.SSIP = 0) -// Must be called in the IPI handler to acknowledge the interrupt. -static inline void clear_sip_ssip() { - __asm__ volatile("csrc sip, %0" :: "r"(1UL << 1)); -} - -} // namespace arch::cpu diff --git a/arch/riscv/include/arch/extable.h b/arch/riscv/include/arch/extable.h deleted file mode 100644 index eb2daac..0000000 --- a/arch/riscv/include/arch/extable.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#ifndef __ASSEMBLER__ - -#include - -/* - * Exception table entry. - * insn: offset from this struct to the faulting instruction. - * fixup: offset from this struct to the fixup code. - * - * Using relative offsets avoids absolute relocations and saves space. - */ -struct ExceptionTableEntry { - int32 insn; - int32 fixup; -}; - -/* Search the exception table for a given PC. Returns fixup address, or 0 if not found. */ -uint64 search_extable(uint64 pc); - -/* Sorts the exception table at boot for binary search O(log N). */ -void extable_init(); - -#endif /* __ASSEMBLER__ */ - -/* - * EXTABLE macro for assembly usage. - * Appends an entry to the .extable section. - */ -#ifdef __ASSEMBLER__ - -#define EXTABLE(insn, fixup) \ - .pushsection .extable, "a"; \ - .balign 4; \ - .long insn - .; \ - .long fixup - .; \ - .popsection - -#else /* !__ASSEMBLER__ */ - -/* Stringified macro for inline assembly */ -#define _ASM_EXTABLE(insn, fixup) \ - ".pushsection .extable, \"a\"\n" \ - ".balign 4\n" \ - ".long " #insn " - .\n" \ - ".long " #fixup " - .\n" \ - ".popsection\n" - -#define EXTABLE(insn, fixup) _ASM_EXTABLE(insn, fixup) - -#endif /* __ASSEMBLER__ */ diff --git a/arch/riscv/include/arch/fpstate.h b/arch/riscv/include/arch/fpstate.h deleted file mode 100644 index 4b42a22..0000000 --- a/arch/riscv/include/arch/fpstate.h +++ /dev/null @@ -1,94 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * FPU State — Floating-Point Register Context - * - * Pre-reserved structure for RISC-V F/D extension floating-point state. - * MUST be allocated in every TaskControlBlock so that future FPU - * save/restore logic has a stable destination without restructuring TCB. - * - * RISC-V F/D extension state: - * - 32 FP registers (f0-f31), each 64 bits for D extension - * - fcsr (Floating-point Control and Status Register) - * - * sstatus.FS field management: - * - FS=0 (Off): FPU disabled, any FP instruction traps - * - FS=1 (Initial): FPU enabled, registers are initial state - * - FS=2 (Clean): FPU enabled, registers not modified since last save - * - FS=3 (Dirty): FPU enabled, registers modified (need save) - * - * Current status: Structure defined, save/restore NOT implemented. - * When implemented, trap_dispatch and swtch.S will use lazy - * save/restore based on sstatus.FS dirty tracking. - * - * Reference: RISC-V ISA Manual §3.1.6.5 (FS field) - */ - -#include - -namespace arch { - -struct FpState { - uint64 f[32]; // f0-f31 (64-bit each for D extension) - uint32 fcsr; // Floating-point CSR (frm + fflags) - uint32 _pad; // Alignment padding -}; - -static_assert(sizeof(FpState) == 32 * 8 + 8, "FpState must be 264 bytes"); - -/* - * sstatus.FS field constants - */ -inline constexpr uint64 kSstatusFS_Off = 0ULL << 13; -inline constexpr uint64 kSstatusFS_Initial = 1ULL << 13; -inline constexpr uint64 kSstatusFS_Clean = 2ULL << 13; -inline constexpr uint64 kSstatusFS_Dirty = 3ULL << 13; -inline constexpr uint64 kSstatusFS_Mask = 3ULL << 13; - -/* - * Check if sstatus indicates FPU state is dirty (needs save). - */ -inline bool fpu_state_dirty(uint64 sstatus) { - return (sstatus & kSstatusFS_Mask) == kSstatusFS_Dirty; -} - -/* - * Check if FPU is enabled (FS != Off). - */ -inline bool fpu_enabled(uint64 sstatus) { - return (sstatus & kSstatusFS_Mask) != kSstatusFS_Off; -} - -} // namespace arch - -/* Assembly routines for FPU register save/restore (fpu.S) */ -extern "C" void fpu_save(arch::FpState* state); -extern "C" void fpu_restore(arch::FpState* state); - -namespace arch { - -/* - * Read sstatus.FS field (current FPU state) - */ -inline uint64 fpu_get_fs() { - uint64 sstatus; - __asm__ volatile("csrr %0, sstatus" : "=r"(sstatus)); - return sstatus & kSstatusFS_Mask; -} - -/* - * Set sstatus.FS field. - * @fs: one of kSstatusFS_Off, kSstatusFS_Initial, kSstatusFS_Clean, kSstatusFS_Dirty - */ -inline void fpu_set_fs(uint64 fs) { - __asm__ volatile( - "csrc sstatus, %0\n" - "csrs sstatus, %1\n" - :: "r"(kSstatusFS_Mask), "r"(fs) - ); -} - -} // namespace arch diff --git a/arch/riscv/include/arch/mmu.h b/arch/riscv/include/arch/mmu.h deleted file mode 100644 index f4c9b26..0000000 --- a/arch/riscv/include/arch/mmu.h +++ /dev/null @@ -1,78 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * MMU Hardware Primitives (RISC-V SV39) - * - * Page table switching, TLB flushing, and fault address reading. - * All functions are static inline — zero call overhead. - * - * Note on SMP: flush_tlb_page() only flushes the LOCAL CPU's TLB. - * Cross-CPU TLB shootdown via IPI is not yet implemented. - * - * Reference: docs/specs/arch_abstraction.md §4.2 - */ - -#include - -/* SATP register: mode field for SV39 */ -#define SATP_SV39 (8UL << 60) - -/* SATP PPN mask (bits 43:0) */ -#define SATP_PPN_MASK ((1UL << 44) - 1) - -namespace arch::mmu { - -// Read the faulting virtual address from stval (set by HW on page fault) -static inline uint64 get_fault_address() { - uint64 val; - __asm__ volatile("csrr %0, stval" : "=r"(val)); - return val; -} - -// Switch the top-level page table. -// Takes a PHYSICAL ADDRESS (not PPN); internally shifts right by 12 -// and combines with SV39 mode bits before writing to satp. -static inline void set_page_table(uint64 physical_pgdir_addr) { - uint64 ppn = physical_pgdir_addr >> 12; - uint64 satp_val = SATP_SV39 | ppn; - __asm__ volatile("csrw satp, %0" :: "r"(satp_val)); - // Note: caller should call flush_tlb_all() after this -} - -// Read the current page table physical address. -// Extracts PPN from satp and converts back to physical address. -static inline uint64 get_page_table() { - uint64 satp_val; - __asm__ volatile("csrr %0, satp" : "=r"(satp_val)); - return (satp_val & SATP_PPN_MASK) << 12; -} - -// Read the raw satp CSR value (mode + PPN). -// Used when the caller needs the exact register value (e.g. for TrapFrame metadata). -static inline uint64 read_satp() { - uint64 val; - __asm__ volatile("csrr %0, satp" : "=r"(val)); - return val; -} - -// Flush the entire TLB (all ASIDs, all addresses) -static inline void flush_tlb_all() { - __asm__ volatile("sfence.vma zero, zero" ::: "memory"); -} - -// Flush a single TLB entry for the given virtual address -static inline void flush_tlb_page(uint64 vaddr) { - __asm__ volatile("sfence.vma %0, zero" :: "r"(vaddr) : "memory"); -} - -// Flush the instruction cache. -// Required after loading executable code into memory (e.g. ELF loading). -// sfence.vma only flushes the TLB; fence.i is needed for the I-cache. -static inline void flush_icache() { - __asm__ volatile("fence.i" ::: "memory"); -} - -} // namespace arch::mmu diff --git a/arch/riscv/include/arch/pmap.h b/arch/riscv/include/arch/pmap.h deleted file mode 100644 index 0b43b9e..0000000 --- a/arch/riscv/include/arch/pmap.h +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * pmap — SV39 page table interface (MD layer) - * - * Namespace functions, zero runtime overhead. - * Implementation: arch/riscv/mm/pmap.cc - * - * Reference: docs/specs/vmm.md §3.2 - */ - -#include - -namespace pmap { - -/* PTE permission bits */ -inline constexpr uint64 PTE_V = 1ULL << 0; -inline constexpr uint64 PTE_R = 1ULL << 1; -inline constexpr uint64 PTE_W = 1ULL << 2; -inline constexpr uint64 PTE_X = 1ULL << 3; -inline constexpr uint64 PTE_U = 1ULL << 4; -inline constexpr uint64 PTE_G = 1ULL << 5; -inline constexpr uint64 PTE_A = 1ULL << 6; -inline constexpr uint64 PTE_D = 1ULL << 7; -inline constexpr uint64 PTE_COW = 1ULL << 8; /* Custom RSW bit for Copy-On-Write */ - -uint64 create(); -void destroy(uint64 root_pa); -int map(uint64 root_pa, uint64 va, uint64 pa, uint64 perm); -int map_2mb(uint64 root_pa, uint64 va, uint64 pa, uint64 perm); -void unmap(uint64 root_pa, uint64 va); -int protect(uint64 root_pa, uint64 va, uint64 perm); -int protect_range(uint64 root_pa, uint64 start, uint64 end, uint64 perm); -bool lookup(uint64 root_pa, uint64 va, uint64* pa_out); -uint64 lookup_pte(uint64 root_pa, uint64 va); -bool is_cow(uint64 root_pa, uint64 va); -int make_cow(uint64 root_pa, uint64 va); -void activate(uint64 root_pa); - -/* - * Translate MI-layer VM_* permission flags to hardware PTE bits. - * Called by vma.cc when faulting in a page. - */ -uint64 vm_perm_to_pte(uint64 vm_perm); - -} // namespace pmap diff --git a/arch/riscv/include/arch/random.h b/arch/riscv/include/arch/random.h deleted file mode 100644 index 8c8c051..0000000 --- a/arch/riscv/include/arch/random.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#include - -namespace arch { - -/* - * Get a random 64-bit value from the hardware TRNG. - * Returns true if supported and successful, false otherwise. - */ -bool get_hw_random(uint64& value); - -/* - * Get the current high-resolution hardware cycle counter. - * Used as an entropy fallback (Jitter/Timer). - */ -inline uint64 get_cycles() -{ - uint64 cycles; - __asm__ volatile("rdcycle %0" : "=r"(cycles)); - return cycles; -} - -} // namespace arch diff --git a/arch/riscv/include/arch/sbi.h b/arch/riscv/include/arch/sbi.h deleted file mode 100644 index 80a6d7c..0000000 --- a/arch/riscv/include/arch/sbi.h +++ /dev/null @@ -1,111 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * sbi.h — RISC-V Supervisor Binary Interface (SBI) wrappers - * - * Provides inline ecall wrappers for SBI calls from S-mode. - * Uses the SBI v1.0+ extension-based calling convention. - * - * Reference: RISC-V SBI Specification v2.0 - */ - -#include - -namespace arch::sbi { - -struct sbiret { - long error; - long value; -}; - -/* SBI error codes */ -inline constexpr long SBI_SUCCESS = 0; -inline constexpr long SBI_ERR_NOT_SUPPORTED = -2; - -/* Extension IDs */ -inline constexpr int SBI_EXT_TIME = 0x54494D45; /* "TIME" */ -inline constexpr int SBI_EXT_IPI = 0x735049; /* "sPI" */ -inline constexpr int SBI_EXT_RFENCE = 0x52464E43; /* "RFNC" */ -inline constexpr int SBI_EXT_HSM = 0x48534D; /* "HSM" */ - -static inline sbiret sbi_ecall(int ext, int fid, uint64 arg0 = 0, - uint64 arg1 = 0, uint64 arg2 = 0, - uint64 arg3 = 0, uint64 arg4 = 0, - uint64 arg5 = 0) { - sbiret ret; - register uint64 a0 asm("a0") = arg0; - register uint64 a1 asm("a1") = arg1; - register uint64 a2 asm("a2") = arg2; - register uint64 a3 asm("a3") = arg3; - register uint64 a4 asm("a4") = arg4; - register uint64 a5 asm("a5") = arg5; - register uint64 a6 asm("a6") = fid; - register uint64 a7 asm("a7") = ext; - __asm__ volatile("ecall" - : "+r"(a0), "+r"(a1) - : "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7) - : "memory"); - ret.error = static_cast(a0); - ret.value = static_cast(a1); - return ret; -} - -/* ---- Timer Extension (EID 0x54494D45) ---- */ - -static inline void set_timer(uint64 stime_value) { - sbi_ecall(SBI_EXT_TIME, 0, stime_value); -} - -/* ---- IPI Extension (EID 0x735049) ---- */ - -/* - * sbi_send_ipi — Send S-mode software interrupt to target harts - * - * @hart_mask: bitmask of target harts (relative to hart_mask_base) - * @hart_mask_base: base hart ID for the mask (0 = harts 0-63) - */ -static inline sbiret sbi_send_ipi(uint64 hart_mask, - uint64 hart_mask_base = 0) { - return sbi_ecall(SBI_EXT_IPI, 0, hart_mask, hart_mask_base); -} - -/* ---- Remote Fence Extension (EID 0x52464E43) ---- */ - -/* - * sbi_remote_sfence_vma — Execute SFENCE.VMA on target harts - * - * @hart_mask/base: target harts - * @start_addr: start of VA range to invalidate - * @size: size of range (use ~0UL for full flush) - */ -static inline sbiret sbi_remote_sfence_vma(uint64 hart_mask, - uint64 hart_mask_base, - uint64 start_addr, - uint64 size) { - return sbi_ecall(SBI_EXT_RFENCE, 1, - hart_mask, hart_mask_base, - start_addr, size); -} - -/* ---- HSM Extension (EID 0x48534D) ---- */ - -/* - * sbi_hart_start — Start (wake) a hart that is in STOPPED state - * - * @hartid: target hart ID to start - * @start_addr: PHYSICAL address where the hart should begin execution - * @opaque: passed in a1 register to the hart (e.g. FDT pointer) - * - * OpenSBI v1.0+ parks non-boot harts; they must be explicitly started. - */ -static inline sbiret sbi_hart_start(uint64 hartid, - uint64 start_addr, - uint64 opaque) { - return sbi_ecall(SBI_EXT_HSM, 0, hartid, start_addr, opaque); -} - -} // namespace arch::sbi - diff --git a/arch/riscv/include/arch/tlb.h b/arch/riscv/include/arch/tlb.h deleted file mode 100644 index 46c6b97..0000000 --- a/arch/riscv/include/arch/tlb.h +++ /dev/null @@ -1,19 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#include - -namespace arch::tlb { - -/* - * Perform a cross-CPU TLB flush (shootdown). - * - * @param cpu_mask: Bitmask of CPUs to target. - * @param start: Start virtual address, or 0 for full address space. - * @param size: Size in bytes, or ~0ULL for full address space. - */ -void flush_remote(uint64 cpu_mask, uint64 start, uint64 size); - -} // namespace arch::tlb diff --git a/arch/riscv/include/arch/trap.h b/arch/riscv/include/arch/trap.h deleted file mode 100644 index 8e55250..0000000 --- a/arch/riscv/include/arch/trap.h +++ /dev/null @@ -1,94 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Trap Vector Control Primitives (RISC-V 64) - * - * Set/read the S-mode trap vector (stvec), trap cause (scause), - * and trap value (stval) registers. - * - * Reference: docs/specs/arch_abstraction.md §4.3 - */ - -#include - -/* scause interrupt bit (bit 63): 1 = interrupt, 0 = exception */ -#define SCAUSE_INTERRUPT (1UL << 63) - -/* Exception cause codes (scause with bit 63 = 0) */ -#define EXC_INST_MISALIGNED 0 -#define EXC_INST_ACCESS_FAULT 1 -#define EXC_ILLEGAL_INST 2 -#define EXC_BREAKPOINT 3 -#define EXC_LOAD_MISALIGNED 4 -#define EXC_LOAD_ACCESS_FAULT 5 -#define EXC_STORE_MISALIGNED 6 -#define EXC_STORE_ACCESS_FAULT 7 -#define EXC_ECALL_FROM_U 8 -#define EXC_ECALL_FROM_S 9 -#define EXC_INST_PAGE_FAULT 12 -#define EXC_LOAD_PAGE_FAULT 13 -#define EXC_STORE_PAGE_FAULT 15 - -/* Interrupt cause codes (scause with bit 63 = 1, lower bits) */ -#define IRQ_S_SOFTWARE 1 -#define IRQ_S_TIMER 5 -#define IRQ_S_EXTERNAL 9 - -namespace arch::trap { - -// Set S-mode trap vector base address (writes stvec). -// Mode: Direct (all traps go to handler_addr). -static inline void set_vector(uint64 handler_addr) { - // Lowest 2 bits of stvec = mode. 0 = Direct. - __asm__ volatile("csrw stvec, %0" :: "r"(handler_addr)); -} - -// Read current trap vector base address -static inline uint64 get_vector() { - uint64 val; - __asm__ volatile("csrr %0, stvec" : "=r"(val)); - return val; -} - -// Read trap cause register (scause) -// Bit 63: 1=interrupt, 0=exception. Lower bits: cause code. -static inline uint64 get_cause() { - uint64 val; - __asm__ volatile("csrr %0, scause" : "=r"(val)); - return val; -} - -// Read trap value register (stval) -// Contains faulting address (page faults) or faulting instruction. -static inline uint64 get_value() { - uint64 val; - __asm__ volatile("csrr %0, stval" : "=r"(val)); - return val; -} - -// Check if a scause value represents an interrupt (vs exception) -static inline bool is_interrupt(uint64 cause) { - return (cause & SCAUSE_INTERRUPT) != 0; -} - -// Extract the cause code (strip the interrupt bit) -static inline uint64 cause_code(uint64 cause) { - return cause & ~SCAUSE_INTERRUPT; -} - -// Enable Supervisor User Memory access (set SUM bit in sstatus). -// When SUM=1, S-mode can read/write pages marked PTE_U. -// This is needed for syscall handlers to access user-space buffers. -static inline void enable_sum() { - __asm__ volatile("csrs sstatus, %0" :: "r"(1UL << 18)); -} - -// Disable Supervisor User Memory access (clear SUM bit in sstatus). -static inline void disable_sum() { - __asm__ volatile("csrc sstatus, %0" :: "r"(1UL << 18)); -} - -} // namespace arch::trap diff --git a/arch/riscv/include/arch/trapframe.h b/arch/riscv/include/arch/trapframe.h deleted file mode 100644 index b198646..0000000 --- a/arch/riscv/include/arch/trapframe.h +++ /dev/null @@ -1,140 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Trap Frame Structure (RISC-V 64) - * - * Saved/restored by the assembly trap_vector on every interrupt, - * exception, or system call. Contains the full CPU snapshot needed - * to resume execution after trap handling. - * - * Layout must match the assembly offsets in trap_vector.S exactly. - * Reference: docs/specs/arch_abstraction.md §3.2 - */ - -/* - * TrapFrame field offsets for use in assembly. - * These must be kept in sync with the struct layout below. - * Placed before any C++ code so assembly can #include this file. - */ -#define TF_KERNEL_SATP 0 -#define TF_KERNEL_SP 8 -#define TF_KERNEL_TRAP 16 -#define TF_KERNEL_CPUID 24 -#define TF_EPC 32 -#define TF_SSTATUS 40 -#define TF_RA 48 -#define TF_SP 56 -#define TF_GP 64 -#define TF_TP 72 -#define TF_T0 80 -#define TF_T1 88 -#define TF_T2 96 -#define TF_T3 104 -#define TF_T4 112 -#define TF_T5 120 -#define TF_T6 128 -#define TF_S0 136 -#define TF_S1 144 -#define TF_S2 152 -#define TF_S3 160 -#define TF_S4 168 -#define TF_S5 176 -#define TF_S6 184 -#define TF_S7 192 -#define TF_S8 200 -#define TF_S9 208 -#define TF_S10 216 -#define TF_S11 224 -#define TF_A0 232 -#define TF_A1 240 -#define TF_A2 248 -#define TF_A3 256 -#define TF_A4 264 -#define TF_A5 272 -#define TF_A6 280 -#define TF_A7 288 -#define TF_SIZE 296 - -#ifndef __ASSEMBLER__ - -#include -#include - -namespace arch { - -struct TrapFrame { - /* ---- Kernel metadata (offset 0-39) ---- */ - uint64 kernel_satp; // 0: Kernel page table (written to satp on trap entry) - uint64 kernel_sp; // 8: Top of kernel stack for this task - uint64 kernel_trap; // 16: Address of C++ trap_handler function - uint64 kernel_cpu_id; // 24: CPU ID (loaded into tp on trap entry) - uint64 epc; // 32: Interrupted instruction address (sepc) - - /* ---- CSR backup (offset 40-47) ---- */ - uint64 sstatus; // 40: Privilege status (SPP, SPIE bits) - - /* ---- General-purpose registers (offset 48-295) ---- */ - uint64 ra; // 48: x1 - Return address - uint64 sp; // 56: x2 - User stack pointer - uint64 gp; // 64: x3 - Global pointer - uint64 tp; // 72: x4 - Thread pointer - uint64 t[7]; // 80: x5-x7, x28-x31 (t0-t6, caller-saved temporaries) - uint64 s[12]; // 136: x8-x9, x18-x27 (s0-s11, callee-saved) - uint64 a[8]; // 232: x10-x17 (a0-a7, arguments / syscall params) -}; - -static_assert(sizeof(TrapFrame) == 296, "TrapFrame size mismatch with assembly offsets"); - -} // namespace arch - -/* Forward declaration — defined in trap_md.cc. - * Must be after TrapFrame definition. */ -extern "C" [[noreturn]] void trap_dispatch(arch::TrapFrame*); - -namespace arch { - -/* - * trapframe_init_user — prepare a TrapFrame for returning to user mode. - * - * Sets arch-specific sstatus: - * SPP = 0 (return to U-mode on sret) - * SPIE = 1 (enable interrupts in U-mode) - * FS = Initial (allow FP instructions) - * - * Called from MI exec.cc instead of setting sstatus directly. - */ -static inline void trapframe_init_user(TrapFrame* tf, uint64 entry, uint64 sp) -{ - /* Clear all registers */ - for (auto& t : tf->t) { t = 0; } - for (auto& s : tf->s) { s = 0; } - for (auto& a : tf->a) { a = 0; } - tf->ra = 0; - tf->gp = 0; - tf->tp = 0; - - tf->epc = entry; - tf->sp = sp; - - /* sstatus: SPP=0 (U-mode), SPIE=1 (interrupts), FS=Initial (FP ok) */ - constexpr uint64 kSPIE = (1ULL << 5); - constexpr uint64 kFS_Initial = (1ULL << 13); - tf->sstatus = kSPIE | kFS_Initial; - - /* Kernel metadata used by trap_vector.S on every trap from U-mode. - * These are RISC-V specific — trap_vector reads them from the - * TrapFrame to switch to kernel context. */ - uint64 satp; - asm volatile("csrr %0, satp" : "=r"(satp)); - tf->kernel_satp = satp; - tf->kernel_sp = reinterpret_cast(tf); - tf->kernel_trap = reinterpret_cast(&trap_dispatch); - tf->kernel_cpu_id = cpu::id(); -} - -} // namespace arch - -#endif /* __ASSEMBLER__ */ diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h deleted file mode 100644 index 42f1eb4..0000000 --- a/arch/riscv/include/asm/csr.h +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _ASM_RISCV_CSR_H -#define _ASM_RISCV_CSR_H - -/* - * RISC-V CSR (Control & Status Register) definitions used by the early - * boot / MMU-switch path. - * - * LumeOS-native subset of Linux arch/riscv/include/asm/csr.h. Only the - * symbols head.S and mm/init.cc actually reference are defined — adding - * the rest is straightforward when new code needs them, and skipping the - * Linux ALTERNATIVE / vendor-extension machinery keeps the cascade flat. - */ - -/* SATP (Supervisor Address Translation and Protection) layout — RV64 */ -#define SATP_PPN_MASK 0x00000FFFFFFFFFFFUL /* bits [43:0] = root PPN */ -#define SATP_ASID_SHIFT 44 -#define SATP_MODE_SHIFT 60 - -/* SATP MODE encodings (RV64) */ -#define SATP_MODE_BARE (0UL << SATP_MODE_SHIFT) -#define SATP_MODE_SV39 (8UL << SATP_MODE_SHIFT) -#define SATP_MODE_SV48 (9UL << SATP_MODE_SHIFT) - -/* Compose a SATP value from a page-table physical address. - * Result: MODE | (root_ppn) where root_ppn = pgd_pa >> PAGE_SHIFT. */ -#define MAKE_SATP(mode, pgd_pa) ((mode) | (((pgd_pa) >> 12) & SATP_PPN_MASK)) - -/* SSTATUS bits we touch at boot — disable FP / vector at entry so that an - * accidental FP / V instruction in early code traps cleanly rather than - * silently using dirty state from before reset. */ -#define SR_FS_OFF (0UL << 13) -#define SR_VS_OFF (0UL << 9) - -#endif /* _ASM_RISCV_CSR_H */ diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h deleted file mode 100644 index 7b9f155..0000000 --- a/arch/riscv/include/asm/page.h +++ /dev/null @@ -1,62 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _ASM_RISCV_PAGE_H -#define _ASM_RISCV_PAGE_H - -/* - * RISC-V page / virtual-memory layout constants. - * - * Mirrors the subset of Linux arch/riscv/include/asm/page.h that LumeOS's - * early boot path needs: - * - PAGE_SIZE / PAGE_SHIFT / PAGE_MASK - * - PAGE_OFFSET (start of the higher-half direct map) - * - KERNEL_LINK_ADDR (link-time VA of _start) - * - SV39 PTE flag bits - * - PTRS_PER_PGD (512 for SV39) - * - * Values match Linux RISC-V SV39 defaults so that struct kernel_mapping - * (filled by setup_vm in arch/riscv/mm/init.cc) carries the same numeric - * relations Linux's mm/init.c maintains. - */ - -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE - 1)) - -/* Higher-half base of the kernel direct map. Bottom of the SV39 supervisor - * address space minus the unmapped guard region. Identical to Linux's - * CONFIG_PAGE_OFFSET default on RV64. */ -#define PAGE_OFFSET 0xFFFFFFC000000000UL - -/* Where _start was linked. OpenSBI hands control to PHYS_BASE; the kernel - * runs at KERNEL_LINK_ADDR after relocate_enable_mmu jumps to higher-half. */ -#define PHYS_BASE 0x80200000UL -#define KERNEL_LINK_ADDR 0xFFFFFFC080200000UL - -/* SATP mode field — SV39 = 8, shifted to bits [63:60]. */ -#define SATP_MODE_SV39 (8UL << 60) - -#define PTRS_PER_PGD 512 - -/* 1 GB superpage size — entry.S used to build the early page table with - * these; setup_vm in arch/riscv/mm/init.cc now does the same. */ -#define PGDIR_SHIFT 30 -#define PGDIR_SIZE (1UL << PGDIR_SHIFT) -#define PGDIR_MASK (~(PGDIR_SIZE - 1)) - -/* SV39 PTE flag bits (one byte). */ -#define _PAGE_PRESENT (1UL << 0) /* aka VALID — historic Linux name */ -#define _PAGE_READ (1UL << 1) -#define _PAGE_WRITE (1UL << 2) -#define _PAGE_EXEC (1UL << 3) -#define _PAGE_USER (1UL << 4) -#define _PAGE_GLOBAL (1UL << 5) -#define _PAGE_ACCESSED (1UL << 6) -#define _PAGE_DIRTY (1UL << 7) - -#define PAGE_KERNEL_EXEC \ - (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC | \ - _PAGE_ACCESSED | _PAGE_DIRTY) - -#endif /* _ASM_RISCV_PAGE_H */ diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h deleted file mode 100644 index 28fc4c5..0000000 --- a/arch/riscv/include/asm/pgtable.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _ASM_RISCV_PGTABLE_H -#define _ASM_RISCV_PGTABLE_H - -/* - * Early page-table construction API used by arch/riscv/mm/init.cc::setup_vm. - * - * Mirrors the create_pgd_mapping interface from Linux's - * arch/riscv/mm/init.c — same name, same semantics: - * - * create_pgd_mapping(pgdir, va, pa, sz, prot) - * - * pgdir : root of the page table to populate - * va : virtual address to map - * pa : physical address to map to - * sz : mapping size — must be a supported leaf size (PAGE_SIZE, - * 2 MiB megapage, or 1 GiB gigapage) - * prot : PTE flag bits (PAGE_KERNEL_EXEC etc., from ) - * - * The boot-time variant in this file only supports gigapage (1 GiB) - * mappings — that is all setup_vm needs for the early_pg_dir / trampoline_pg_dir - * built before the slab allocator exists. Finer-grained mappings come - * later via vmm_init(). - */ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { unsigned long pgd; } pgd_t; - -/* Linker-provided early page-table storage (defined in lumeos.lds.S - * ARCH_BSS_EXTRA, lives in .bss so it's zero-initialized). Allocating - * them in the linker script — not in C — mirrors Linux and keeps the - * symbols visible from head.S without a forward C decl mismatch. */ -extern pgd_t early_pg_dir[PTRS_PER_PGD]; -extern pgd_t trampoline_pg_dir[PTRS_PER_PGD]; -extern pgd_t fixmap_pg_dir[PTRS_PER_PGD]; - -/* Install a single PGD entry mapping `va` → `pa` with size `sz` and PTE - * flags `prot`. Only sz == PGDIR_SIZE (1 GiB) is supported in this early - * variant — vmm_init() takes over with create_pgd_mapping_pmd later. */ -void create_pgd_mapping(pgd_t *pgdir, unsigned long va, unsigned long pa, - unsigned long sz, unsigned long prot); - -#ifdef __cplusplus -} -#endif - -#endif /* _ASM_RISCV_PGTABLE_H */ diff --git a/arch/riscv/include/asm/sections.h b/arch/riscv/include/asm/sections.h deleted file mode 100644 index 7067444..0000000 --- a/arch/riscv/include/asm/sections.h +++ /dev/null @@ -1,50 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _ASM_RISCV_SECTIONS_H -#define _ASM_RISCV_SECTIONS_H - -/* - * Linker-emitted symbols that bracket each section of the kernel image. - * - * The lumeos.lds.S linker script defines these as the start / end - * addresses of contiguous regions. Code that walks a section - * (relocate_kernel walks .rela.dyn, the C++ ctor loop walks - * .init_array, the VMM mapping code walks .text vs .rodata, ...) - * imports the pair via this header. - * - * Mirrors Linux arch/riscv/include/asm/sections.h / asm-generic/sections.h. - * Each name and pair is identical to Linux so that direct ports of mm/init.c - * relocate_kernel logic compile unchanged against LumeOS. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -extern char _start[]; -extern char _kernel_end[]; - -extern char _stext[]; -extern char _etext[]; -extern char _srodata[]; -extern char _erodata[]; -extern char _sdata[]; -extern char _edata[]; -extern char _sbss[]; -extern char _ebss[]; - -extern char __init_array_start[]; -extern char __init_array_end[]; - -/* .rela.dyn — array of Elf64_Rela entries emitted by the linker under - * `-shared -Bsymbolic`. relocate_kernel walks this range and patches - * each R_RISCV_RELATIVE slot. */ -extern char __rela_dyn_start[]; -extern char __rela_dyn_end[]; - -#ifdef __cplusplus -} -#endif - -#endif /* _ASM_RISCV_SECTIONS_H */ diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c deleted file mode 100644 index edecab7..0000000 --- a/arch/riscv/kernel/asm-offsets.c +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// Copyright (C) 2026 Richard Qin -// -// arch/riscv/kernel/asm-offsets.c — emit struct field offsets and -// scalar constants for consumption by assembly sources (head.S etc.). -// -// 1:1 with Linux arch/riscv/kernel/asm-offsets.c. The Makefile -// compiles this to an .s file (not .o) and runs -// scripts/extract-asm-offsets.sed over the output to produce -// include/generated/asm-offsets.h. -// -// Adding a new offset: include the struct's header, add an OFFSET() -// or DEFINE() line below, rebuild. head.S can then reference the -// generated #define directly. - -#include -#include - -void asm_offsets(void) -{ - COMMENT("LumeOS asm-offsets — struct kernel_mapping field offsets"); - OFFSET(KERNEL_MAP_VIRT_ADDR, kernel_mapping, virt_addr); - OFFSET(KERNEL_MAP_VIRT_OFFSET, kernel_mapping, virt_offset); - OFFSET(KERNEL_MAP_PHYS_ADDR, kernel_mapping, phys_addr); - OFFSET(KERNEL_MAP_SIZE, kernel_mapping, size); - OFFSET(KERNEL_MAP_VA_PA_OFFSET, kernel_mapping, va_pa_offset); - OFFSET(KERNEL_MAP_PAGE_OFFSET, kernel_mapping, page_offset); - OFFSET(KERNEL_MAP_VA_KERNEL_PA_OFFSET, kernel_mapping, va_kernel_pa_offset); -} diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S deleted file mode 100644 index e04c44c..0000000 --- a/arch/riscv/kernel/head.S +++ /dev/null @@ -1,317 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * RISC-V kernel entry — Linux-aligned layout. - * - * Flow (mirrors arch/riscv/kernel/head.S in Linux): - * - * _start [.head.text, byte 0 of image] - * · 64-byte Boot Protocol Image Header - * · j real_start - * - * real_start [.text] - * · save a0 (hartid) / a1 (dtb_pa) - * · setup gp / per-hart sp - * · BSP/AP election via amoswap - * · BSP: clear BSS, call setup_vm, then relocate_enable_mmu - * · AP: spin-wait, then relocate_enable_mmu - * - * relocate_enable_mmu [C function, arch/riscv/mm/init.cc] - * · csrw satp <- trampoline_pg_dir - * · jump to higher-half VA - * · csrw satp <- early_pg_dir - * · slide sp/ra/gp to higher-half - * · call relocate_kernel (walks .rela.dyn, patches R_RISCV_RELATIVE) - * - * real_start (continued in higher-half) - * · BSP only: call early_cpp_init (walks .init_array) - * · call kernel_main(hartid, dtb_pa) - * - * Register contract from OpenSBI / U-Boot: - * a0 = hart ID - * a1 = FDT physical base - */ - -#include - -#define PAGE_OFFSET 0xFFFFFFC000000000 -#define BOOT_STACK_SIZE 8192 - -/* ======================================================================== - * .head.text — RISC-V Boot Protocol Image Header - * - * Layout per Documentation/arch/riscv/boot-image-header.rst: - * code0/code1 (8 B) : executable code, lands at PC after OpenSBI hand-off - * text_offset (8 B) : load offset from RAM base - * image_size (8 B) : effective image size (0 = unknown) - * flags (8 B) : bit 0: endian - * version (4 B) : major.minor - * res1/res2 (4+8) : reserved - * magic (8 B) : "RISCV\0\0\0" - * magic2 (4 B) : "RSC\x05" - * res3 (4 B) : PE/COFF reserved - * ======================================================================== */ - .section .head.text, "ax" - .globl _start -_start: - j real_start /* code0 */ - .word 0 /* code1 */ - .dword 0x200000 /* text_offset */ - .dword 0 /* image_size (post-link) */ - .dword 0 /* flags */ - .word 0x0002 /* version 0.2 */ - .word 0 /* res1 */ - .dword 0 /* res2 */ - .dword 0x5643534952 /* magic "RISCV\0\0\0" */ - .word 0x05435352 /* magic2 "RSC\x05" */ - .word 0 /* res3 */ - -/* ======================================================================== - * real_start — all harts land here at physical PC - * ======================================================================== */ - .text - .globl real_start -real_start: - /* DEBUG: 'R\n' — UART direct at 0x10000000, MMU off. */ - li t0, 0x10000000 - li t1, 'R' - sb t1, 0(t0) - addi t1, a0, '0' - sb t1, 0(t0) - li t1, '\n' - sb t1, 0(t0) - - /* Mask interrupts and supervisor pending bits. */ - csrw sie, zero - csrw sip, zero - - /* gp for medany — relax must be disabled across the `la`. */ - .option push - .option norelax - la gp, __global_pointer$ - .option pop - - /* per-hart boot stack: sp = boot_stack + (hartid + 1) * STACK_SIZE */ - la t0, boot_stack - li t1, BOOT_STACK_SIZE - addi t2, a0, 1 - mul t1, t1, t2 - add sp, t0, t1 - - /* Save hartid / dtb_pa in callee-saved regs preserved across calls. */ - mv tp, a0 /* tp = hartid */ - mv s0, a1 /* s0 = dtb_pa */ - - /* BSP/AP election: first hart to swap bsp_elected 0→1 is BSP. */ - la t0, bsp_elected - li t1, 1 - amoswap.w.aq t2, t1, (t0) - bnez t2, .Lap_wait /* prev != 0 → we're an AP */ - - /* === BSP path === */ - la t0, bsp_hart_id - sw a0, 0(t0) - - li t3, 0x10000000 - li t4, 'B' - sb t4, 0(t3) - li t4, '\n' - sb t4, 0(t3) - - /* Clear BSS — must precede setup_vm, which writes kernel_map. */ - la t0, _sbss - la t1, _ebss -.Lbss_loop: - bgeu t0, t1, .Lbss_done - sd zero, 0(t0) - addi t0, t0, 8 - j .Lbss_loop -.Lbss_done: - - li t3, 0x10000000 - li t4, 'V' - sb t4, 0(t3) - li t4, '\n' - sb t4, 0(t3) - - /* ---- BSP-only: pre-MMU PIC fixup of .rela.dyn ---- - * - * The kernel is built with -fPIE -shared. All global-data accesses - * compile to GOT-indirect loads (auipc + ld), where the linker - * emits each .got slot's initial value as the link-time VA and a - * companion R_RISCV_RELATIVE entry in .rela.dyn. At this point - * we're running at the physical load address — those link-time VAs - * are not yet mapped, so any global access would fault. - * - * Walk .rela.dyn in pure assembly (PC-relative only — no globals) - * and patch every R_RISCV_RELATIVE slot to addend + (PA - LINK_VA). - * After this, setup_vm can dereference kernel_map / early_pg_dir - * / etc. via the GOT and get correct PA-side pointers. - * - * Mirrors Linux arch/riscv/kernel/head.S — same idea, same loop. - * - * reloc: - * t0 = pa_offset = PA(_start) - KERNEL_LINK_ADDR (negative) - * t1 = &__rela_dyn_start - * t2 = &__rela_dyn_end - * for each 24-byte rela in [t1, t2): - * t3 = r_offset; t4 = r_info; t5 = r_addend - * if (t4 & 0xFFFFFFFF) != R_RISCV_RELATIVE: skip - * slot_pa = r_offset + pa_offset - * *slot_pa = r_addend + pa_offset - */ -#define R_RISCV_RELATIVE 3 - - la t0, _start /* PA of _start */ - li t1, 0xFFFFFFC080200000 /* KERNEL_LINK_ADDR (asm/page.h) */ - sub t0, t0, t1 /* t0 = pa_offset (PA - LINK_VA) */ - - la t1, __rela_dyn_start - la t2, __rela_dyn_end -.Lrela_loop: - bgeu t1, t2, .Lrela_done - ld t3, 0(t1) /* r_offset */ - ld t4, 8(t1) /* r_info */ - ld t5, 16(t1) /* r_addend */ - /* r_info low 32 bits = type */ - li t6, 0xFFFFFFFF - and t4, t4, t6 - li t6, R_RISCV_RELATIVE - bne t4, t6, .Lrela_next - /* slot_pa = r_offset + pa_offset */ - add t3, t3, t0 - /* value = r_addend + pa_offset */ - add t5, t5, t0 - sd t5, 0(t3) -.Lrela_next: - addi t1, t1, 24 /* sizeof(Elf64_Rela) */ - j .Lrela_loop -.Lrela_done: - - /* Memory fence so subsequent loads see the patched slots. */ - fence w, r - - li t3, 0x10000000 - li t4, 'P' - sb t4, 0(t3) - li t4, '\n' - sb t4, 0(t3) - - /* Call setup_vm(load_pa = PA of _start, dtb_pa = s0). - * Both args physical at this point — MMU still off. */ - la a0, _start - mv a1, s0 - call setup_vm - - li t3, 0x10000000 - li t4, 'v' - sb t4, 0(t3) - li t4, '\n' - sb t4, 0(t3) - - /* Release APs once page tables are built. */ - la t0, boot_sync_flag - li t1, 1 - amoswap.w.rl zero, t1, (t0) - j .Lenable_mmu - -/* ======================================================================== - * AP path — spin until BSP signals readiness. - * ======================================================================== */ -.Lap_wait: - la t0, boot_sync_flag -.Lap_spin: - lw t1, 0(t0) - beqz t1, .Lap_spin - fence r, rw - - /* fall through */ - -/* ======================================================================== - * .Lenable_mmu — all harts: enable MMU, jump to higher-half, run reloc. - * - * relocate_enable_mmu does its own SATP write + higher-half jump in - * C (with inline asm), then calls relocate_kernel. After it returns, - * we are at higher-half VA with sp / ra / gp slid up, and .rela.dyn - * is applied (so .init_array pointers are valid). - * ======================================================================== */ -.Lenable_mmu: - la a0, early_pg_dir - call relocate_enable_mmu - /* On return: PC, sp, ra, gp are all at higher-half VA. */ - - li t3, 0x10000000 - li t4, 'M' - sb t4, 0(t3) - li t4, '\n' - sb t4, 0(t3) - - /* Mark MMU enabled for console / pmap layers that check this. */ - call console_set_mmu_enabled - - /* BSP only: walk __init_array and call each C++ ctor. */ - la t0, bsp_hart_id - lw t0, 0(t0) - bne tp, t0, .Lskip_cpp_init - call early_cpp_init -.Lskip_cpp_init: - - /* Hand off to kernel_main(hartid, dtb_pa). */ - mv a0, tp - mv a1, s0 - call kernel_main - - /* kernel_main should not return. */ -.Lhalt: - csrc sstatus, 2 - wfi - j .Lhalt - -/* ======================================================================== - * early_cpp_init — walk .init_array and call each constructor. - * - * Called only by BSP, after relocate_kernel has patched the function - * pointers stored in __init_array. Before relocate_kernel runs those - * pointers are zero-filled by the linker. - * ======================================================================== */ - .globl early_cpp_init -early_cpp_init: - addi sp, sp, -32 - sd ra, 0(sp) - sd s1, 8(sp) - sd s2, 16(sp) - - la s1, __init_array_start - la s2, __init_array_end -.Linit_loop: - bgeu s1, s2, .Linit_done - ld t0, 0(s1) - jalr ra, t0 - addi s1, s1, 8 - j .Linit_loop -.Linit_done: - ld ra, 0(sp) - ld s1, 8(sp) - ld s2, 16(sp) - addi sp, sp, 32 - ret - -/* ======================================================================== - * Election state — in .data so explicit zero survives the BSP BSS clear - * (these are read before BSS is cleared on the BSP, and concurrently by - * APs while BSP is in the clear loop). - * ======================================================================== */ - .section .data - .align 2 - .globl boot_sync_flag -boot_sync_flag: - .word 0 - - .globl bsp_elected -bsp_elected: - .word 0 - - .globl bsp_hart_id -bsp_hart_id: - .word 0 diff --git a/arch/riscv/kernel/lumeos.lds.S b/arch/riscv/kernel/lumeos.lds.S deleted file mode 100644 index 9bd083b..0000000 --- a/arch/riscv/kernel/lumeos.lds.S +++ /dev/null @@ -1,120 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * RISC-V Kernel Linker Script Template - * - * This is a C-preprocessed linker script (.lds.S). The build system - * runs it through CPP to produce the final vmlinux.lds which is - * passed to the linker. - * - * Architecture-specific definitions: - * - OUTPUT_ARCH, ENTRY - * - PAGE_OFFSET, BASE_ADDRESS, PHYS_BASE - * - .head.text placement - * - GP anchor (__global_pointer$ for RISC-V medany) - * - early_pgdir and boot stacks in .bss - * - * Common section macros come from include/lume/vmlinux.lds.h - * - * Reference: docs/specs/linker_and_entry.md - */ - -#include - -/* ===== RISC-V Architecture Constants ===== */ - -OUTPUT_ARCH(riscv) - -PAGE_OFFSET = 0xFFFFFFC000000000; -BASE_ADDRESS = 0xFFFFFFC080200000; -PHYS_BASE = 0x80200000; - -ENTRY(_start) - -/* ===== RISC-V: GP anchor in .data (medany model) ===== */ -#define ARCH_DATA_EXTRA \ - . = ALIGN(16); \ - PROVIDE(__global_pointer$ = . + 0x800); \ - *(.sdata .sdata.*) - -/* ===== RISC-V: page-table storage + per-CPU boot stacks in .bss ===== - * - * Linux RISC-V layout (arch/riscv/kernel/vmlinux.lds.S): - * early_pg_dir — first early page table built by setup_vm, - * used for the rest of boot after MMU enable - * trampoline_pg_dir — single-page table used only during the SATP - * switch from physical to higher-half VA; its - * identity + virt mappings of _start must both - * be valid in the same instruction window - * fixmap_pg_dir — covers the FIXADDR_START range used by the - * early console (UART MMIO before kernel page - * table proper is built) - * - * All three are allocated here so head.S can take their addresses without - * a C definition; their PA == VA mapping covers them during setup_vm. - */ -#define ARCH_BSS_EXTRA \ - . = ALIGN(4096); \ - early_pg_dir = .; \ - . += 4096; \ - trampoline_pg_dir = .; \ - . += 4096; \ - fixmap_pg_dir = .; \ - . += 4096; \ - /* Legacy name retained for any caller still referencing it; */ \ - /* points at the same first 4 KiB as early_pg_dir. */ \ - early_pgdir = early_pg_dir; \ - /* Per-CPU boot stacks: 8KB per CPU, max 8 CPUs */ \ - . = ALIGN(4096); \ - boot_stack = .; \ - . += 8192 * 8; \ - boot_stack_top = .; - -/* ===== Layout ===== */ - -SECTIONS { - . = BASE_ADDRESS; - - /* .head.text: Image Header (must be at byte 0 of the kernel image) */ - .head.text : AT(PHYS_BASE) { - _start = .; - KEEP(*(.head.text)) - } - - TEXT_SECTION - - . = ALIGN(4096); - - /* .rela.dyn lives between .text and .rodata so it ends up in the - * read-only PT_LOAD segment. Mirrors Linux vmlinux.lds.S where - * .rela.dyn sits at the tail of init data, just before RO_DATA. */ - RELA_DYN_SECTION - - . = ALIGN(4096); - - RODATA_SECTION - - . = ALIGN(4096); - - DATA_SECTION - - . = ALIGN(8); - - /* .got lives right after .data in the RW PT_LOAD. All other - * dynamic-linker artefacts (.plt, .dynamic, .dynsym, .dynstr, - * .hash, .gnu.hash, .interp, .dynbss) are discarded by the - * DISCARDS macro — mirrors Linux arch/riscv/kernel/vmlinux.lds.S. */ - GOT_SECTION - - . = ALIGN(4096); - - /* End of file-backed image (BSS follows as NOBITS) */ - __lume_image_end = .; - - BSS_SECTION - - KERNEL_END - - DISCARDS -} diff --git a/arch/riscv/kernel/signal.cc b/arch/riscv/kernel/signal.cc deleted file mode 100644 index 39fe34e..0000000 --- a/arch/riscv/kernel/signal.cc +++ /dev/null @@ -1,163 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * arch/riscv/signal.cc — Signal frame construction and sigreturn - * - * Constructs a signal frame on the user stack before returning to - * the user signal handler. On sigreturn, restores the original - * registers from the saved frame. - * - * Frame layout on user stack (grows downward): - * - * +-----------------------+ <- original sp - * | sigset_t saved_mask | 8 bytes - * | TrapFrame saved_regs | 296 bytes - * | kernel_siginfo info | 128 bytes - * +-----------------------+ <- new sp (16-byte aligned) - * - * Reference: Linux arch/riscv/kernel/signal.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* Signal frame layout */ -/* ================================================================== */ - -struct rt_sigframe { - kernel_siginfo info; /* siginfo for SA_SIGINFO handlers */ - arch::TrapFrame saved_regs; /* saved register state */ - sigset_t saved_mask; /* blocked mask to restore on sigreturn */ -}; - -/* ================================================================== */ -/* Signal trampoline (written to user stack) */ -/* ================================================================== */ - -/* - * When the user's signal handler returns (via `ret`), ra points here. - * This tiny code sequence invokes sys_rt_sigreturn to restore the - * original execution context. - * - * RISC-V instructions (8 bytes): - * li a7, 139 → addi a7, zero, 139 → 0x08b00893 - * ecall → 0x00000073 - */ -static constexpr uint32 sigreturn_trampoline[2] = { - 0x08b00893, /* li a7, 139 (SYS_rt_sigreturn) */ - 0x00000073, /* ecall */ -}; - -/* ================================================================== */ -/* setup_signal_frame */ -/* ================================================================== */ - -int setup_signal_frame(arch::TrapFrame* tf, int signo, - kernel_sigaction* ka, kernel_siginfo* info) -{ - TaskControlBlock* curr = current_task(); - if (!curr) return -EINVAL; - - /* Calculate frame location on user stack */ - uint64 sp = tf->sp; - - /* Reserve space for the trampoline below the frame */ - sp -= sizeof(sigreturn_trampoline); - sp &= ~15ULL; /* 16-byte align */ - uint64 trampoline_addr = sp; - - /* Reserve space for the signal frame */ - sp -= sizeof(rt_sigframe); - sp &= ~15ULL; /* 16-byte align */ - uint64 frame_addr = sp; - - /* Build the frame in kernel memory, then copy to user stack */ - rt_sigframe frame{}; - if (info) { - frame.info = *info; - } - frame.saved_regs = *tf; - frame.saved_mask = curr->blocked; - - /* Copy frame to user stack */ - int err = copy_to_user(frame_addr, &frame, sizeof(frame)); - if (err < 0) return -EFAULT; - - /* Copy trampoline to user stack */ - err = copy_to_user(trampoline_addr, sigreturn_trampoline, - sizeof(sigreturn_trampoline)); - if (err < 0) return -EFAULT; - - /* Set up the trap frame to execute the signal handler */ - tf->epc = ka->sa_handler; - tf->sp = frame_addr; - - /* Arguments to the handler: handler(int signo, siginfo_t*, ucontext_t*) */ - tf->a[0] = static_cast(signo); - - if (ka->sa_flags & SA_SIGINFO) { - /* SA_SIGINFO: pass siginfo and ucontext pointers */ - tf->a[1] = frame_addr; /* &info */ - tf->a[2] = frame_addr + sizeof(kernel_siginfo); /* &saved_regs (as ucontext) */ - } else { - tf->a[1] = 0; - tf->a[2] = 0; - } - - /* Return address: when the handler does `ret`, jump to trampoline */ - if (ka->sa_flags & SA_RESTORER) { - tf->ra = ka->sa_restorer; - } else { - tf->ra = trampoline_addr; - } - - return 0; -} - -/* ================================================================== */ -/* arch_sigreturn — restore state from signal frame */ -/* ================================================================== */ - -int64 arch_sigreturn(arch::TrapFrame* tf) -{ - TaskControlBlock* curr = current_task(); - if (!curr) return -EINVAL; - - /* - * The signal frame is located at the current sp. - * We need to read it back and restore the original state. - */ - uint64 frame_addr = tf->sp; - - rt_sigframe frame{}; - int err = copy_from_user(&frame, frame_addr, sizeof(frame)); - if (err < 0) { - printk(KERN_ERR "sigreturn: failed to read signal frame at %llx\n", - frame_addr); - task_kill_current(SIGSEGV); - return -EFAULT; - } - - /* Restore the saved register state */ - *tf = frame.saved_regs; - - /* Restore the blocked mask */ - curr->blocked = frame.saved_mask; - curr->blocked.del(SIGKILL); - curr->blocked.del(SIGSTOP); - - /* - * Return value: we return the saved a0 from the original context. - * The syscall dispatch will NOT overwrite a0 because sigreturn - * is special — it returns via the restored trap frame directly. - */ - return tf->a[0]; -} diff --git a/arch/riscv/lib/random.cc b/arch/riscv/lib/random.cc deleted file mode 100644 index afc0078..0000000 --- a/arch/riscv/lib/random.cc +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include - -namespace arch { - -bool get_hw_random(uint64& value) -{ - /* - * Real implementation would check for Zkr extension and execute: - * csrr x, seed - * - * Since QEMU virt doesn't guarantee Zkr, we return false to - * force the MI layer to use the timer fallback. - */ - return false; -} - -} // namespace arch diff --git a/arch/riscv/mm/init.cc b/arch/riscv/mm/init.cc deleted file mode 100644 index 30ea45e..0000000 --- a/arch/riscv/mm/init.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * RISC-V early memory-management bootstrap. - * - * Mirrors Linux arch/riscv/mm/init.c — same file name, same C function - * names (setup_vm / relocate_enable_mmu / relocate_kernel), same global - * state (kernel_map, early_pg_dir, trampoline_pg_dir). head.S calls - * setup_vm immediately after BSS-clear, then later calls - * relocate_enable_mmu, which switches SATP, jumps to higher-half VA, - * and finally calls relocate_kernel to apply .rela.dyn. - * - * Differences from Linux: - * - KASLR offset is hard-wired to 0 for now (no pi/ subsystem) — the - * code path that would consume kernel_map.virt_offset is in place - * so adding pi/-based seed reading later only requires populating - * that one field. - * - Only 1 GiB superpages supported in create_pgd_mapping; sufficient - * for the early page tables. Finer-grained mappings come from - * vmm_init() once slab is up. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Global kernel mapping descriptor — single source of truth for the - * runtime-vs-link address relationship. Lives in .data so its initial - * zero contents survive the BSS-clear that runs before setup_vm fills - * the fields. Read by VMM, page-fault handler, ptdump, etc. - * - * Linux equivalent: arch/riscv/mm/init.c::kernel_map - */ -struct kernel_mapping kernel_map __attribute__((section(".data"))); - -/* - * create_pgd_mapping — install one PGD entry covering a 1 GiB region. - * - * Only 1 GiB superpages are supported in this early variant; setup_vm - * needs nothing finer. Identical interface to Linux's same-named - * function in arch/riscv/mm/init.c, restricted in arity. - */ -extern "C" void create_pgd_mapping(pgd_t *pgdir, unsigned long va, - unsigned long pa, unsigned long sz, - unsigned long prot) -{ - /* This early variant only supports 1 GiB superpages. */ - if (sz != PGDIR_SIZE) { - return; - } - - /* SV39 PGD index = (va >> 30) & 0x1FF — see Volume II, §4.4.1. - * Each PGD entry is 8 bytes; pgdir[i] is the slot for that VPN[2]. */ - unsigned long idx = (va >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1); - - /* PTE PPN field: physical page number shifted up by 10 (SV39 PTE - * layout: bits [53:10] = PPN, bits [9:0] = flags). */ - unsigned long ppn = pa >> PAGE_SHIFT; - pgdir[idx].pgd = (ppn << 10) | prot; -} - -/* - * setup_vm — fill kernel_map and build early_pg_dir + trampoline_pg_dir. - * - * Called from head.S after BSS is cleared, with: - * load_pa = runtime physical address of _start - * dtb_pa = physical address of the device tree blob (from a1) - * - * Mirrors Linux arch/riscv/mm/init.c::setup_vm. The actual SATP write - * happens later in relocate_enable_mmu; here we only populate page - * tables and the kernel_map descriptor. - */ -extern "C" void __init setup_vm(uintptr_t load_pa, uintptr_t dtb_pa) -{ - (void)dtb_pa; /* KASLR pi/ subsystem will consume this later. */ - - /* --- 1. Fill kernel_map ----------------------------------------- */ - - /* KASLR offset = 0 in this configuration. */ - kernel_map.virt_offset = 0; - kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset; - kernel_map.phys_addr = load_pa; - kernel_map.size = (uintptr_t)_kernel_end - (uintptr_t)_start; - kernel_map.page_offset = PAGE_OFFSET; - - /* Mirrors Linux: va_pa_offset is the constant added to a physical - * address to obtain its direct-map VA. */ - kernel_map.va_pa_offset = PAGE_OFFSET - load_pa; - - /* va_kernel_pa_offset is the constant added to a load PA to obtain - * the kernel's link VA (used by relocate_enable_mmu to fix sp/ra). */ - kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - load_pa; - - /* --- 2. Build early_pg_dir ------------------------------------- * - * - * SV39 root page table — 4 entries cover identity + higher-half for - * both MMIO (PA 0x0000_0000, 1 GiB) and RAM (PA 0x8000_0000, 1 GiB): - * - * [0] identity PA 0x0000_0000 → VA 0x0000_0000 - * [2] identity PA 0x8000_0000 → VA 0x8000_0000 - * [256] high-half PA 0x0000_0000 → VA 0xFFFFFFC000000000 - * [258] high-half PA 0x8000_0000 → VA 0xFFFFFFC080000000 - * - * Identity mappings keep PC valid right after csrw satp. High-half - * mappings let the post-MMU `jr` to .Lhigher_half resolve. */ - create_pgd_mapping(early_pg_dir, 0x00000000UL, 0x00000000UL, - PGDIR_SIZE, PAGE_KERNEL_EXEC); - create_pgd_mapping(early_pg_dir, 0x80000000UL, 0x80000000UL, - PGDIR_SIZE, PAGE_KERNEL_EXEC); - create_pgd_mapping(early_pg_dir, PAGE_OFFSET + 0x00000000UL, - 0x00000000UL, PGDIR_SIZE, PAGE_KERNEL_EXEC); - create_pgd_mapping(early_pg_dir, PAGE_OFFSET + 0x80000000UL, - 0x80000000UL, PGDIR_SIZE, PAGE_KERNEL_EXEC); - - /* --- 3. Build trampoline_pg_dir -------------------------------- * - * - * The trampoline maps just the gigapage containing _start, both at - * its identity PA and at its higher-half VA. This is the page - * table SATP holds during the single instruction window between - * "MMU off" and "MMU on with early_pg_dir" — the PC must resolve - * under both, so we re-use the same two entries above. */ - create_pgd_mapping(trampoline_pg_dir, load_pa & PGDIR_MASK, - load_pa & PGDIR_MASK, PGDIR_SIZE, PAGE_KERNEL_EXEC); - create_pgd_mapping(trampoline_pg_dir, - (kernel_map.virt_addr) & PGDIR_MASK, - load_pa & PGDIR_MASK, PGDIR_SIZE, PAGE_KERNEL_EXEC); -} - -/* - * relocate_kernel — walk .rela.dyn and apply R_RISCV_RELATIVE entries. - * - * Called from relocate_enable_mmu *after* the SATP switch and the jump - * to higher-half VA — meaning __rela_dyn_start / __rela_dyn_end resolve - * to valid higher-half pointers we can dereference directly. - * - * Mirrors Linux arch/riscv/mm/init.c::relocate_kernel. Key invariant: - * even when kaslr_offset == 0, the slot store MUST still happen — the - * linker leaves R_RISCV_RELATIVE slots zero-filled at link time, and - * only relocate_kernel writes the link-time addend into them. Without - * this pass, .init_array entries (and every other relocated symbol) - * are NULL pointers. - */ -void __init relocate_kernel(void) -{ - auto *rela = (Elf64_Rela *)__rela_dyn_start; - auto *rela_end = (Elf64_Rela *)__rela_dyn_end; - - const uint64 kaslr_offset = kernel_map.virt_offset; - - for (; rela < rela_end; ++rela) { - if (ELF64_R_TYPE(rela->r_info) != R_RISCV_RELATIVE) { - continue; - } - auto *slot = (Elf64_Addr *)(rela->r_offset + kaslr_offset); - *slot = (Elf64_Addr)(rela->r_addend) + kaslr_offset; - } -} - -/* - * relocate_enable_mmu — switch SATP, jump to higher-half, apply relocations. - * - * Called from head.S after setup_vm has filled kernel_map and built the - * page tables. Equivalent to Linux's same-named asmlinkage routine but - * written in C++ so it can share kernel_map / pgtable definitions with - * setup_vm directly. - * - * Three logical steps: - * - * 1. csrw satp ← trampoline_pg_dir. PC continues running at the - * identity PA, which the trampoline still maps; the high-half PA - * mapping is now also live. - * - * 2. la t0, .Lvirt; add t0, t0, va_kernel_pa_offset; jr t0. - * A PC-relative `la` under medany yields the runtime PA of the - * label; adding va_kernel_pa_offset (= link_va - load_pa) converts - * it to the link-time higher-half VA, which the trampoline maps. - * The `jr` then atomically pushes PC into higher-half space. - * - * 3. csrw satp ← early_pg_dir. We're now executing at higher-half - * VA, so the trampoline can be retired in favour of the full - * early page table. sp / ra / gp must be slid to higher-half too, - * otherwise the next ret-or-call uses physical-low addresses - * whose mapping is about to disappear when vmm_init drops the - * identity entries. - * - * 4. Call relocate_kernel — now safe, because all link-time VA - * pointers in __rela_dyn_start[..] dereference correctly. - */ -extern "C" void __init relocate_enable_mmu(pgd_t *pgdir) -{ - (void)pgdir; /* head.S passes early_pg_dir for documentation; we - * read the global symbol directly inside the asm. */ - - const unsigned long va_kernel_pa_offset = kernel_map.va_kernel_pa_offset; - const unsigned long satp_mode = SATP_MODE_SV39; - - asm volatile ( - /* Step 1: csrw satp <- trampoline */ - "la t0, trampoline_pg_dir\n" - "srli t0, t0, 12\n" - "or t0, t0, %[mode]\n" - "csrw satp, t0\n" - "sfence.vma\n" - - /* Step 2: jump to higher-half VA */ - "la t0, 1f\n" - "add t0, t0, %[off]\n" - "jr t0\n" - "1:\n" - - /* Step 3a: csrw satp <- early_pg_dir (now in higher-half) */ - "la t0, early_pg_dir\n" - "srli t0, t0, 12\n" - "or t0, t0, %[mode]\n" - "csrw satp, t0\n" - "sfence.vma\n" - - /* Step 3b: slide sp / ra / gp to higher-half */ - "add sp, sp, %[off]\n" - "add ra, ra, %[off]\n" - ".option push\n" - ".option norelax\n" - "la gp, __global_pointer$\n" - ".option pop\n" - : - : [off] "r"(va_kernel_pa_offset), - [mode] "r"(satp_mode) - : "t0", "memory" - ); - - /* Step 4: apply .rela.dyn now that VA dereferences work. */ - relocate_kernel(); -} diff --git a/arch/riscv/mm/pmap.cc b/arch/riscv/mm/pmap.cc deleted file mode 100644 index f0a6848..0000000 --- a/arch/riscv/mm/pmap.cc +++ /dev/null @@ -1,361 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * pmap.cc — SV39 page table operations (MD layer) - * - * Implements the pmap namespace interface for RISC-V SV39. - * 3-level page table: VPN[2] (9 bits) -> VPN[1] (9 bits) -> VPN[0] (9 bits) - * Each level is a 4KB page containing 512 PTEs of 8 bytes each. - * - * Address conversion: all page table operations work with physical addresses. - * To read/write page table entries we must convert PA to VA via pa_to_va(). - * - * Reference: docs/specs/vmm.md - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace pmap { - -/* - * Before the first pmap::activate(), CPU runs on entry.S bootstrap page table - * (fixed direct-map base). After activation, runtime (KASLR) base is valid. - */ -static bool g_runtime_mapping_ready = false; - -/* PTE bit definitions */ -inline constexpr uint64 PTE_V = 1ULL << 0; -inline constexpr uint64 PTE_R = 1ULL << 1; -inline constexpr uint64 PTE_W = 1ULL << 2; -inline constexpr uint64 PTE_X = 1ULL << 3; -inline constexpr uint64 PTE_U = 1ULL << 4; -inline constexpr uint64 PTE_G = 1ULL << 5; -inline constexpr uint64 PTE_A = 1ULL << 6; -inline constexpr uint64 PTE_D = 1ULL << 7; -inline constexpr uint64 PTE_COW = 1ULL << 8; - -/* SV39: 3 levels, 9 bits per level, 12-bit page offset */ -inline constexpr int kLevels = 3; -inline constexpr int kPtePerPage = 512; - -/* SV39: upper half of VA space (kernel) starts at L2 index 256 */ -inline constexpr int kKernelPgdStart = kPtePerPage / 2; - -/* SATP PPN mask (44 bits) and page shift */ -inline constexpr uint64 kSatpPpnMask = 0xFFFFFFFFFFFULL; -inline constexpr int kPageShift = 12; - -/* Extract VPN[level] from a virtual address */ -static inline uint64 vpn(uint64 va, int level) -{ - return (va >> (12 + 9 * level)) & 0x1FF; -} - -/* Extract PA from a PTE */ -static inline uint64 pte_to_pa(uint64 pte) -{ - return ((pte >> 10) & 0xFFFFFFFFFFFULL) << 12; -} - -/* Create a PTE from a PA and flags */ -static inline uint64 pa_to_pte(uint64 pa, uint64 flags) -{ - return ((pa >> 12) << 10) | flags; -} - -/* Convert PA to kernel VA for accessing page table contents */ -static inline uint64 *pa_to_ptr(uint64 pa) -{ - uint64 va = g_runtime_mapping_ready - ? pa_to_va(phys_addr(pa)).raw - : boot_pa_to_va(phys_addr(pa)).raw; - return reinterpret_cast(va); -} - -/* Allocate a zeroed page for a page table level. - * During early boot (before PMM), uses memblock. - * After PMM init, uses the buddy allocator. - * Returns PA of the new page, or 0 on failure. */ -static uint64 alloc_pt_page() -{ - uint64 pa; - if (memblock_is_active()) { - pa = memblock_alloc(kPageSize, kPageSize); - } else { - Page *page = pmm_alloc_page(); - if (!page) { - return 0; - } - pa = page_to_pa(page).raw; - } - if (!pa) { - return 0; - } - /* Zero the page */ - uint64 *ptr = pa_to_ptr(pa); - for (int i = 0; i < kPtePerPage; i++) { - ptr[i] = 0; - } - return pa; -} - -uint64 create() -{ - uint64 new_root = alloc_pt_page(); - if (!new_root) return 0; - - /* Copy kernel mappings from the current kernel page table. - * In SV39, entries 256..511 (VPN[2] >= 256) cover the upper - * half of the 64-bit VA space where the kernel lives. - * Without these, switching to the new page table would - * immediately fault on any kernel VA access. - * - * Only do this after the runtime page table is active — - * during early boot the bootstrap PT doesn't cover all of - * RAM so pa_to_ptr on the kernel root would fault. */ - if (g_runtime_mapping_ready) { - uint64 kernel_satp; - asm volatile("csrr %0, satp" : "=r"(kernel_satp)); - uint64 kernel_root_pa = (kernel_satp & kSatpPpnMask) << kPageShift; - - uint64 *new_l2 = pa_to_ptr(new_root); - uint64 *kern_l2 = pa_to_ptr(kernel_root_pa); - - for (int i = kKernelPgdStart; i < kPtePerPage; i++) { - new_l2[i] = kern_l2[i]; - } - } - - return new_root; -} - -void destroy(uint64 root_pa) -{ - uint64 *l2 = pa_to_ptr(root_pa); - - /* Only free the user half (entries 0..255). - * Entries 256..511 are shared kernel PGD pointers copied - * from the kernel page table — freeing them would corrupt - * the kernel's own mappings. */ - for (int i = 0; i < kKernelPgdStart; i++) { - if (!(l2[i] & PTE_V)) - continue; - /* Non-leaf L2 entry? (no R/W/X bits = pointer to L1 table) */ - if (!(l2[i] & (PTE_R | PTE_W | PTE_X))) { - uint64 l1_pa = pte_to_pa(l2[i]); - uint64 *l1 = pa_to_ptr(l1_pa); - for (int j = 0; j < kPtePerPage; j++) { - if (!(l1[j] & PTE_V)) - continue; - if (!(l1[j] & (PTE_R | PTE_W | PTE_X))) { - /* L0 page table */ - uint64 l0_pa = pte_to_pa(l1[j]); - pmm_free_page(pa_to_page(phys_addr(l0_pa))); - } - } - pmm_free_page(pa_to_page(phys_addr(l1_pa))); - } - } - pmm_free_page(pa_to_page(phys_addr(root_pa))); -} - -int map(uint64 root_pa, uint64 va, uint64 pa, uint64 perm) -{ - uint64 *table = pa_to_ptr(root_pa); - - /* Walk levels 2 -> 1, creating intermediate tables as needed */ - for (int level = 2; level > 0; level--) { - uint64 idx = vpn(va, level); - if (!(table[idx] & PTE_V)) { - uint64 child_pa = alloc_pt_page(); - if (!child_pa) - return -ENOMEM; /* -ENOMEM */ - table[idx] = pa_to_pte(child_pa, PTE_V); - } - table = pa_to_ptr(pte_to_pa(table[idx])); - } - - /* Level 0: install the leaf PTE */ - uint64 idx = vpn(va, 0); - table[idx] = pa_to_pte(pa, perm | PTE_V | PTE_A | PTE_D); - return 0; -} - -int map_2mb(uint64 root_pa, uint64 va, uint64 pa, uint64 perm) -{ - /* VA and PA must be 2MB-aligned */ - constexpr uint64 k2MB = 2ULL * 1024 * 1024; - if ((va & (k2MB - 1)) != 0 || (pa & (k2MB - 1)) != 0) { - return -EINVAL; /* -EINVAL */ - } - - uint64 *table = pa_to_ptr(root_pa); - - /* Walk L2: create intermediate table if needed */ - uint64 idx2 = vpn(va, 2); - if (!(table[idx2] & PTE_V)) { - uint64 child_pa = alloc_pt_page(); - if (!child_pa) { - return -ENOMEM; /* -ENOMEM */ - } - table[idx2] = pa_to_pte(child_pa, PTE_V); - } - table = pa_to_ptr(pte_to_pa(table[idx2])); - - /* L1: install leaf PTE (2MB mega page) */ - uint64 idx1 = vpn(va, 1); - table[idx1] = pa_to_pte(pa, perm | PTE_V | PTE_A | PTE_D); - return 0; -} - -void unmap(uint64 root_pa, uint64 va) -{ - uint64 *table = pa_to_ptr(root_pa); - for (int level = 2; level > 0; level--) { - uint64 idx = vpn(va, level); - if (!(table[idx] & PTE_V)) - return; - table = pa_to_ptr(pte_to_pa(table[idx])); - } - table[vpn(va, 0)] = 0; -} - -int protect(uint64 root_pa, uint64 va, uint64 perm) -{ - uint64 *table = pa_to_ptr(root_pa); - for (int level = 2; level >= 0; level--) { - uint64 idx = vpn(va, level); - uint64 pte = table[idx]; - if (!(pte & PTE_V)) - return -EFAULT; /* -EFAULT */ - if (pte & (PTE_R | PTE_W | PTE_X)) { - uint64 pa = pte_to_pa(pte); - table[idx] = pa_to_pte(pa, perm | PTE_V); - return 0; - } - table = pa_to_ptr(pte_to_pa(pte)); - } - return -EFAULT; -} - -int protect_range(uint64 root_pa, uint64 start, uint64 end, uint64 perm) -{ - if (end <= start) { - return 0; - } - - uint64 va = page_align_down(start); - uint64 va_end = page_align_up(end); - - for (; va < va_end; va += kPageSize) { - int ret = protect(root_pa, va, perm); - if (ret == -14) { - continue; /* unmapped page: skip */ - } - if (ret < 0) { - return ret; - } - } - - arch::mmu::flush_tlb_all(); - return 0; -} - -bool lookup(uint64 root_pa, uint64 va, uint64 *pa_out) -{ - uint64 *table = pa_to_ptr(root_pa); - for (int level = 2; level >= 0; level--) { - uint64 idx = vpn(va, level); - uint64 pte = table[idx]; - if (!(pte & PTE_V)) - return false; - /* Leaf PTE? (has R, W, or X) */ - if (pte & (PTE_R | PTE_W | PTE_X)) { - if (pa_out) - *pa_out = pte_to_pa(pte); - return true; - } - table = pa_to_ptr(pte_to_pa(pte)); - } - return false; -} - -uint64 lookup_pte(uint64 root_pa, uint64 va) -{ - uint64 *table = pa_to_ptr(root_pa); - for (int level = 2; level >= 0; level--) { - uint64 idx = vpn(va, level); - uint64 pte = table[idx]; - if (!(pte & PTE_V)) - return 0; - if (pte & (PTE_R | PTE_W | PTE_X)) - return pte; // leaf PTE raw value - table = pa_to_ptr(pte_to_pa(pte)); - } - return 0; -} - -bool is_cow(uint64 root_pa, uint64 va) -{ - uint64 *table = pa_to_ptr(root_pa); - for (int level = 2; level >= 0; level--) { - uint64 idx = vpn(va, level); - uint64 pte = table[idx]; - if (!(pte & PTE_V)) - return false; - if (pte & (PTE_R | PTE_W | PTE_X)) { - return (pte & PTE_COW) != 0; - } - table = pa_to_ptr(pte_to_pa(pte)); - } - return false; -} - -int make_cow(uint64 root_pa, uint64 va) -{ - uint64 *table = pa_to_ptr(root_pa); - for (int level = 2; level >= 0; level--) { - uint64 idx = vpn(va, level); - uint64 pte = table[idx]; - if (!(pte & PTE_V)) - return -EFAULT; /* -EFAULT */ - if (pte & (PTE_R | PTE_W | PTE_X)) { - /* Clear write bit, set COW bit */ - pte &= ~PTE_W; - pte |= PTE_COW; - table[idx] = pte; - return 0; - } - table = pa_to_ptr(pte_to_pa(pte)); - } - return -EFAULT; -} - -void activate(uint64 root_pa) -{ - arch::mmu::set_page_table(root_pa); - arch::mmu::flush_tlb_all(); - g_runtime_mapping_ready = true; -} - -uint64 vm_perm_to_pte(uint64 vm_perm) -{ - /* Translate MI VM_* flags to SV39 PTE bits. - * The MI flags are defined in . */ - uint64 pte = PTE_V | PTE_A | PTE_D; // Valid + Accessed + Dirty (avoid HW A/D faults) - if (vm_perm & (1ULL << 0)) pte |= PTE_R; // VM_READ - if (vm_perm & (1ULL << 1)) pte |= PTE_W; // VM_WRITE - if (vm_perm & (1ULL << 2)) pte |= PTE_X; // VM_EXEC - if (vm_perm & (1ULL << 3)) pte |= PTE_U; // VM_USER - return pte; -} - -} // namespace pmap diff --git a/arch/riscv/mm/tlb_md.cc b/arch/riscv/mm/tlb_md.cc deleted file mode 100644 index ed9aa29..0000000 --- a/arch/riscv/mm/tlb_md.cc +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include - -namespace arch::tlb { - -void flush_remote(uint64 cpu_mask, uint64 start, uint64 size) { - if (size == ~0ULL) { - arch::sbi::sbi_remote_sfence_vma(cpu_mask, 0, 0, ~0UL); - } else { - arch::sbi::sbi_remote_sfence_vma(cpu_mask, 0, start, size); - } -} - -} // namespace arch::tlb diff --git a/arch/riscv/syscall/syscall_md.cc b/arch/riscv/syscall/syscall_md.cc deleted file mode 100644 index 26320c8..0000000 --- a/arch/riscv/syscall/syscall_md.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Syscall MD Layer — RISC-V Register Extraction - * - * Extracts syscall number (a7) and arguments (a0-a5) from the TrapFrame, - * calls the MI dispatcher, and writes the return value back to a0. - * - * Reference: docs/specs/syscall.md §5 - */ - -#include -#include -#include -#include - -void syscall_dispatch_md(arch::TrapFrame* tf) -{ - uint64 nr = tf->a[7]; /* RISC-V ABI: syscall number in a7 */ - - uint64 args[6] = { - tf->a[0], tf->a[1], tf->a[2], - tf->a[3], tf->a[4], tf->a[5], - }; - - /* Enable interrupts so timer and preemption work during syscalls */ - arch::cpu::intr_on(); - - int64 ret = syscall_dispatch(nr, args); - - arch::cpu::intr_off(); - - /* sys_rt_sigreturn restores the entire TrapFrame from the signal - * frame on the user stack. Writing ret into a[0] would clobber - * the restored value, so we must skip the writeback. */ - if (nr == static_cast(SYS_rt_sigreturn)){ - return; - } - tf->a[0] = static_cast(ret); /* Return value in a0 */ -} - diff --git a/arch/riscv/trap/extable.cc b/arch/riscv/trap/extable.cc deleted file mode 100644 index 57a3dc1..0000000 --- a/arch/riscv/trap/extable.cc +++ /dev/null @@ -1,92 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include - -extern struct ExceptionTableEntry __extable_start[]; -extern struct ExceptionTableEntry __extable_end[]; - -static void swap_extable_entries(struct ExceptionTableEntry *a, struct ExceptionTableEntry *b) { - uint64 a_insn = reinterpret_cast(&a->insn) + a->insn; - uint64 a_fixup = reinterpret_cast(&a->fixup) + a->fixup; - uint64 b_insn = reinterpret_cast(&b->insn) + b->insn; - uint64 b_fixup = reinterpret_cast(&b->fixup) + b->fixup; - - a->insn = static_cast(b_insn - reinterpret_cast(&a->insn)); - a->fixup = static_cast(b_fixup - reinterpret_cast(&a->fixup)); - b->insn = static_cast(a_insn - reinterpret_cast(&b->insn)); - b->fixup = static_cast(a_fixup - reinterpret_cast(&b->fixup)); -} - -static void sort_extable(size_t left, size_t right) { - if (left >= right) return; - - size_t mid_idx = left + (right - left) / 2; - struct ExceptionTableEntry *pivot = &__extable_start[mid_idx]; - uint64 pivot_val = reinterpret_cast(&pivot->insn) + pivot->insn; - - size_t i = left; - size_t j = right; - - while (i <= j) { - while ((reinterpret_cast(&__extable_start[i].insn) + __extable_start[i].insn) < pivot_val) { - i++; - } - while ((reinterpret_cast(&__extable_start[j].insn) + __extable_start[j].insn) > pivot_val) { - if (j == 0) { - break; - } - j--; - } - if (i <= j) { - swap_extable_entries(&__extable_start[i], &__extable_start[j]); - i++; - if (j == 0) { - break; - } - j--; - } - } - - if (j > left) { - sort_extable(left, j); - } - if (i < right) { - sort_extable(i, right); - } -} - -void extable_init() { - size_t count = __extable_end - __extable_start; - if (count <= 1) return; - sort_extable(0, count - 1); -} - -uint64 search_extable(uint64 pc) { - size_t count = __extable_end - __extable_start; - if (count == 0) return 0; - - size_t left = 0; - size_t right = count - 1; - - /* Binary search */ - while (left <= right) { - size_t mid = left + (right - left) / 2; - const struct ExceptionTableEntry *entry = &__extable_start[mid]; - uint64 mid_pc = reinterpret_cast(&entry->insn) + entry->insn; - - if (mid_pc == pc) { - return reinterpret_cast(&entry->fixup) + entry->fixup; - } - - if (mid_pc < pc) { - left = mid + 1; - } else { - if (mid == 0) break; - right = mid - 1; - } - } - - return 0; -} diff --git a/arch/riscv/trap/fpu.S b/arch/riscv/trap/fpu.S deleted file mode 100644 index 90d96d9..0000000 --- a/arch/riscv/trap/fpu.S +++ /dev/null @@ -1,103 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * FPU Save / Restore (RISC-V D extension) - * - * void fpu_save(FpState* state); - * Saves f0-f31 and fcsr to the FpState structure. - * - * void fpu_restore(FpState* state); - * Restores f0-f31 and fcsr from the FpState structure. - * - * FpState layout: f[0..31] at offset 0 (each 8 bytes), fcsr at offset 256. - * - * Called from schedule() when switching between tasks that have - * used the FPU (sstatus.FS == Dirty on save path). - */ - - .section .text - -/* ====================================================================== - * void fpu_save(FpState* state); // a0 = state pointer - * ====================================================================== */ - .globl fpu_save - .align 2 -fpu_save: - fsd f0, 0(a0) - fsd f1, 8(a0) - fsd f2, 16(a0) - fsd f3, 24(a0) - fsd f4, 32(a0) - fsd f5, 40(a0) - fsd f6, 48(a0) - fsd f7, 56(a0) - fsd f8, 64(a0) - fsd f9, 72(a0) - fsd f10, 80(a0) - fsd f11, 88(a0) - fsd f12, 96(a0) - fsd f13, 104(a0) - fsd f14, 112(a0) - fsd f15, 120(a0) - fsd f16, 128(a0) - fsd f17, 136(a0) - fsd f18, 144(a0) - fsd f19, 152(a0) - fsd f20, 160(a0) - fsd f21, 168(a0) - fsd f22, 176(a0) - fsd f23, 184(a0) - fsd f24, 192(a0) - fsd f25, 200(a0) - fsd f26, 208(a0) - fsd f27, 216(a0) - fsd f28, 224(a0) - fsd f29, 232(a0) - fsd f30, 240(a0) - fsd f31, 248(a0) - frcsr t0 - sw t0, 256(a0) - ret - -/* ====================================================================== - * void fpu_restore(FpState* state); // a0 = state pointer - * ====================================================================== */ - .globl fpu_restore - .align 2 -fpu_restore: - fld f0, 0(a0) - fld f1, 8(a0) - fld f2, 16(a0) - fld f3, 24(a0) - fld f4, 32(a0) - fld f5, 40(a0) - fld f6, 48(a0) - fld f7, 56(a0) - fld f8, 64(a0) - fld f9, 72(a0) - fld f10, 80(a0) - fld f11, 88(a0) - fld f12, 96(a0) - fld f13, 104(a0) - fld f14, 112(a0) - fld f15, 120(a0) - fld f16, 128(a0) - fld f17, 136(a0) - fld f18, 144(a0) - fld f19, 152(a0) - fld f20, 160(a0) - fld f21, 168(a0) - fld f22, 176(a0) - fld f23, 184(a0) - fld f24, 192(a0) - fld f25, 200(a0) - fld f26, 208(a0) - fld f27, 216(a0) - fld f28, 224(a0) - fld f29, 232(a0) - fld f30, 240(a0) - fld f31, 248(a0) - lw t0, 256(a0) - fscsr t0 - ret diff --git a/arch/riscv/trap/swtch.S b/arch/riscv/trap/swtch.S deleted file mode 100644 index dbae43d..0000000 --- a/arch/riscv/trap/swtch.S +++ /dev/null @@ -1,96 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Context Switch & Kernel Thread Trampoline (RISC-V 64) - * - * context_switch: saves/restores callee-saved registers. - * kthread_entry_trampoline: entry point for newly created kernel threads. - * After context_switch loads the new Context, execution lands here via - * Context.ra = kthread_entry_trampoline. The entry function and argument - * are in s0 and s1 respectively, set by sched_init/create_tcb. - * - * The trampoline calls the MI-layer kthread_entry(entry, arg). - * - * Reference: docs/specs/scheduler.md §6 - */ - - .section .text - -/* ======================================================================== - * void context_switch(Context* old_ctx, Context* next_ctx); - * a0 = old_ctx_ptr, a1 = next_ctx_ptr - * ======================================================================== */ - .globl context_switch - .align 2 -context_switch: - sd ra, 0(a0) - sd sp, 8(a0) - sd s0, 16(a0) - sd s1, 24(a0) - sd s2, 32(a0) - sd s3, 40(a0) - sd s4, 48(a0) - sd s5, 56(a0) - sd s6, 64(a0) - sd s7, 72(a0) - sd s8, 80(a0) - sd s9, 88(a0) - sd s10, 96(a0) - sd s11, 104(a0) - - ld ra, 0(a1) - ld sp, 8(a1) - ld s0, 16(a1) - ld s1, 24(a1) - ld s2, 32(a1) - ld s3, 40(a1) - ld s4, 48(a1) - ld s5, 56(a1) - ld s6, 64(a1) - ld s7, 72(a1) - ld s8, 80(a1) - ld s9, 88(a1) - ld s10, 96(a1) - ld s11, 104(a1) - - ret - -/* ======================================================================== - * kthread_entry_trampoline - * - * Reached via context_switch when a new kthread is first scheduled. - * Context was set up by create_tcb(): - * s0 = entry function pointer - * s1 = argument pointer - * - * Calls the MI-layer C++ function: - * void kthread_entry(void (*entry)(void*), void* arg); - * ======================================================================== */ - .globl kthread_entry_trampoline - .align 2 -kthread_entry_trampoline: - mv a0, s0 /* a0 = entry function */ - mv a1, s1 /* a1 = argument */ - call kthread_entry /* MI-layer C++ function */ - - /* kthread_entry should never return, but if it does: */ - wfi - j kthread_entry_trampoline + 12 /* loop on wfi */ - -/* ======================================================================== - * ret_from_fork - * - * Trampoline for newly forked processes. - * Context is set up by fork() so that s0 contains the TrapFrame pointer. - * - * Calls the MI-layer C++ function: - * void fork_child_entry(TrapFrame* tf); - * ======================================================================== */ - .globl ret_from_fork - .align 2 -ret_from_fork: - mv a0, s0 /* a0 = TrapFrame pointer */ - call fork_child_entry /* does not return, eventually calls userret */ - wfi - j ret_from_fork + 8 \ No newline at end of file diff --git a/arch/riscv/trap/trap_md.cc b/arch/riscv/trap/trap_md.cc deleted file mode 100644 index e30aea6..0000000 --- a/arch/riscv/trap/trap_md.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Trap MD Layer (RISC-V 64) - * - * All architecture-specific trap logic lives here: - * - scause/stval reading (CSR access) - * - scause → MI TrapCause translation - * - RISC-V specific fixups (ecall epc += 4, ebreak epc += 2) - * - stvec setup (trap_init / trap_init_ap) - * - kernel_trap_handler (traps from S-mode) - * - * MI layer (kernel/trap.cc) contains ZERO arch-specific code. - * - * Reference: docs/specs/trap.md §7 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* PLIC interface (drivers/plic.cc) */ -uint32 plic_claim(); -void plic_complete(uint32 irq); - -/* trap_vector.S: assembly entry point */ -extern "C" void trap_vector(); - -/* ======================================================================== - * scause → TrapCause translation (RISC-V specific) - * ======================================================================== */ - -static TrapCause scause_to_trap_cause(uint64 scause) -{ - if (arch::trap::is_interrupt(scause)) { - switch (arch::trap::cause_code(scause)) { - case IRQ_S_TIMER: return TrapCause::IrqTimer; - case IRQ_S_SOFTWARE: return TrapCause::IrqSoftware; - case IRQ_S_EXTERNAL: return TrapCause::IrqExternal; - default: return TrapCause::Unknown; - } - } - - /* Exception (synchronous) */ - switch (scause) { - case EXC_INST_PAGE_FAULT: return TrapCause::PageFaultExec; - case EXC_LOAD_PAGE_FAULT: return TrapCause::PageFaultLoad; - case EXC_STORE_PAGE_FAULT: return TrapCause::PageFaultStore; - case EXC_ECALL_FROM_U: return TrapCause::Syscall; - case EXC_ILLEGAL_INST: return TrapCause::IllegalInst; - case EXC_BREAKPOINT: return TrapCause::Breakpoint; - - case EXC_INST_ACCESS_FAULT: - case EXC_LOAD_ACCESS_FAULT: - case EXC_STORE_ACCESS_FAULT: - return TrapCause::AccessFault; - - case EXC_INST_MISALIGNED: - case EXC_LOAD_MISALIGNED: - case EXC_STORE_MISALIGNED: - return TrapCause::AlignFault; - - default: - return TrapCause::Unknown; - } -} - -TrapCause trap_translate_scause(uint64 scause) -{ - return scause_to_trap_cause(scause); -} - -static TrapOrigin origin_from_sstatus(uint64 sstatus) -{ - constexpr uint64 kSstatusSPP = (1ULL << 8); - return (sstatus & kSstatusSPP) ? TrapOrigin::FromKernel - : TrapOrigin::FromUser; -} - -static TrapClass classify_trap(uint64 scause, TrapCause cause) -{ - if (arch::trap::is_interrupt(scause)) { - return TrapClass::Interrupt; - } - if (cause == TrapCause::Syscall) { - return TrapClass::Syscall; - } - if (cause == TrapCause::Unknown) { - return TrapClass::Unknown; - } - return TrapClass::Exception; -} - -static TrapInfo build_trap_info(arch::TrapFrame* tf, - uint64 scause, - uint64 stval, - TrapOrigin origin) -{ - TrapInfo info{}; - info.cause = scause_to_trap_cause(scause); - info.cls = classify_trap(scause, info.cause); - info.origin = origin; - info.val = stval; - info.epc = tf ? tf->epc : 0; - info.scause = scause; - return info; -} - -/* ======================================================================== - * trap_dispatch — user-mode trap entry (called from trap_vector.S) - * - * Reads RISC-V CSRs, translates to MI TrapCause, applies arch-specific - * fixups, then calls MI trap_handle(). - * - * After trap_handle returns, we must return to user mode via userret(). - * The assembly jalr t3 that called us has NO return-to-user code after it, - * so trap_dispatch must never return normally. - * ======================================================================== */ - -extern "C" void userret(arch::TrapFrame* tf); - -extern "C" [[noreturn]] void trap_dispatch(arch::TrapFrame* tf) -{ - /* Switch stvec to kernelvec immediately so that any traps during - * kernel execution (timer IRQs, page faults from copy_from_user) - * go through the kernel trap entry, not the user trap entry. - * This matches Linux which sets stvec to handle_exception (kernel) - * at the top of the user trap path. */ - extern void kernelvec(); - arch::trap::set_vector(reinterpret_cast(&kernelvec)); - - /* Enable SUM so S-mode can access user pages (PTE_U). - * Without this, any dereference of user-space pointers in syscall - * handlers (sys_write buf, sys_read buf, etc.) would page fault. */ - arch::trap::enable_sum(); - - uint64 scause = arch::trap::get_cause(); - uint64 stval = arch::trap::get_value(); - - TrapOrigin origin = origin_from_sstatus(tf->sstatus); - TrapInfo info = build_trap_info(tf, scause, stval, origin); - - /* Per-trap trace from user mode. Stored at KLOG_DEBUG / KLOG_SUBSYS_TRAP - * so it lives in the ring buffer for postmortem but stays off the console - * by default. No more in-band 20-trap window — flip console_level or - * dump the ring on demand instead. */ - if (origin == TrapOrigin::FromUser) { - pr_debug_s(KLOG_SUBSYS_TRAP, - "trap: cause=%u epc=%llx val=%llx\n", - static_cast(info.cause), info.epc, info.val); - } - - /* Save trapframe in TCB for syscall handlers (like fork) */ - TaskControlBlock* curr = current_task(); - if (curr) { - curr->trapframe = tf; - } - - /* RISC-V ecall fix: ecall does not increment sepc. - * Advance epc so sret returns to the instruction AFTER ecall. */ - if (info.cause == TrapCause::Syscall) { - tf->epc += 4; - info.epc = tf->epc; - } - - /* RISC-V ebreak fix: advance past the C.EBREAK instruction (2 bytes). - * This is arch-specific because instruction size depends on the ISA. */ - if (info.cause == TrapCause::Breakpoint) { - tf->epc += 2; - info.epc = tf->epc; - } - - /* Call MI-layer dispatcher (zero inline assembly from here on) */ - trap_handle(tf, info); - - /* Return to user mode. - * Set stvec back to trap_vector for the next user-mode trap, - * then jump to userret which restores registers and does sret. */ - arch::trap::set_vector(reinterpret_cast(&trap_vector)); - userret(tf); - __builtin_unreachable(); -} - -/* ======================================================================== - * kernel_trap_handler — traps taken while already in S-mode - * - * For Phase 2, only timer and external interrupts are expected. - * Exceptions in S-mode are always fatal. - * - * This belongs in MD because it reads scause directly. - * ======================================================================== */ - -extern "C" void kernel_trap_handler(arch::TrapFrame* tf) -{ - uint64 scause = arch::trap::get_cause(); - uint64 stval = arch::trap::get_value(); - - if (scause == EXC_LOAD_PAGE_FAULT || scause == EXC_STORE_PAGE_FAULT) { - uint64 fixup = search_extable(tf->epc); - if (fixup != 0) { - /* Exception table entry found: redirect execution to fixup code */ - tf->epc = fixup; - return; - } - } - - TrapInfo info = build_trap_info(tf, scause, stval, TrapOrigin::FromKernel); - trap_handle(tf, info); -} - -/* kernelvec assembly is in trap_vector.S */ -extern "C" void kernelvec(); - -/* ======================================================================== - * trap_init() — BSP: set stvec, init IrqManager - * ======================================================================== */ - -void trap_init() -{ - g_irq_manager.init(); - arch::trap::set_vector(reinterpret_cast(&kernelvec)); -} - -/* ======================================================================== - * trap_init_ap() — AP: set this CPU's stvec - * ======================================================================== */ - -void trap_init_ap() -{ - arch::trap::set_vector(reinterpret_cast(&kernelvec)); -} - diff --git a/arch/riscv/trap/trap_vector.S b/arch/riscv/trap/trap_vector.S deleted file mode 100644 index 8e45cae..0000000 --- a/arch/riscv/trap/trap_vector.S +++ /dev/null @@ -1,283 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Trap Vector Entry / Exit (RISC-V 64, S-mode) - * - * On trap entry (interrupt / exception / ecall): - * sscratch holds the TrapFrame pointer (set up by kernel before sret). - * We swap sscratch <-> tp, save all 31 GPRs + sstatus + sepc into TrapFrame, - * then load kernel metadata (sp, satp, tp, trap handler) and jump to C++. - * - * On trap return (userret): - * Restore all GPRs + sstatus + sepc from TrapFrame, swap sscratch <-> tp, - * then sret back to user mode. - * - * Layout must match arch::TrapFrame in arch/riscv/include/arch/trapframe.h - * Reference: docs/specs/arch_abstraction.md §7.2 - */ - -#include - - .section .text - .globl trap_vector - .globl userret - .align 4 - -/* - * trap_vector — unified S-mode trap entry point (Direct mode) - * - * Precondition: sscratch = pointer to current task's TrapFrame - */ -trap_vector: - /* Step 1: swap sscratch <-> tp. Now tp = TrapFrame*, sscratch = old tp */ - csrrw tp, sscratch, tp - - /* Step 2: save all 31 general-purpose registers into TrapFrame */ - sd ra, TF_RA(tp) - sd sp, TF_SP(tp) - sd gp, TF_GP(tp) - /* tp (x4) is in sscratch — save it later */ - sd t0, TF_T0(tp) - sd t1, TF_T1(tp) - sd t2, TF_T2(tp) - sd s0, TF_S0(tp) - sd s1, TF_S1(tp) - sd a0, TF_A0(tp) - sd a1, TF_A1(tp) - sd a2, TF_A2(tp) - sd a3, TF_A3(tp) - sd a4, TF_A4(tp) - sd a5, TF_A5(tp) - sd a6, TF_A6(tp) - sd a7, TF_A7(tp) - sd s2, TF_S2(tp) - sd s3, TF_S3(tp) - sd s4, TF_S4(tp) - sd s5, TF_S5(tp) - sd s6, TF_S6(tp) - sd s7, TF_S7(tp) - sd s8, TF_S8(tp) - sd s9, TF_S9(tp) - sd s10, TF_S10(tp) - sd s11, TF_S11(tp) - sd t3, TF_T3(tp) - sd t4, TF_T4(tp) - sd t5, TF_T5(tp) - sd t6, TF_T6(tp) - - /* Save the real tp (user's tp) which is now in sscratch */ - csrr t0, sscratch - sd t0, TF_TP(tp) - - /* Step 3: save sstatus */ - csrr t0, sstatus - sd t0, TF_SSTATUS(tp) - - /* Step 4: save sepc (interrupted PC) */ - csrr t0, sepc - sd t0, TF_EPC(tp) - - /* Step 5: load kernel context from TrapFrame metadata */ - ld sp, TF_KERNEL_SP(tp) /* switch to kernel stack */ - ld t1, TF_KERNEL_SATP(tp) /* kernel page table */ - ld t2, TF_KERNEL_CPUID(tp) /* CPU ID for tp */ - ld t3, TF_KERNEL_TRAP(tp) /* C++ trap_handler address */ - - /* Switch to kernel page table */ - csrw satp, t1 - - /* Step 6: flush TLB after page table switch */ - sfence.vma zero, zero - - /* Step 6.5: restore kernel gp (global pointer). - * The compiler uses gp-relative addressing for global variable access - * (e.g. ld reg, offset(gp)). User mode may have set gp to anything, - * so we MUST reload it before entering any C++ code. */ -.option push -.option norelax - la gp, __global_pointer$ -.option pop - - /* Pass TrapFrame* to C++ handler (a0 = tf) */ - mv a0, tp - - /* Set tp = CPU ID (kernel convention) */ - mv tp, t2 - - /* Step 7: jump to C++ trap_handler */ - jalr t3 - - -/* ======================================================================== - * kernelvec — unified S-mode trap entry point for traps FROM S-MODE - * - * Traps from S-mode already have a valid kernel stack pointer in sp. - * We just allocate a TrapFrame on the stack and save registers. - * ======================================================================== */ - .globl kernelvec - .align 4 -kernelvec: - /* Allocate TrapFrame on stack */ - addi sp, sp, -296 - - /* Save all 31 general-purpose registers into TrapFrame */ - sd ra, TF_RA(sp) - /* Save the OLD sp (before we subtracted 296) */ - addi t0, sp, 296 - sd t0, TF_SP(sp) - sd gp, TF_GP(sp) - sd tp, TF_TP(sp) - sd t0, TF_T0(sp) - sd t1, TF_T1(sp) - sd t2, TF_T2(sp) - sd s0, TF_S0(sp) - sd s1, TF_S1(sp) - sd a0, TF_A0(sp) - sd a1, TF_A1(sp) - sd a2, TF_A2(sp) - sd a3, TF_A3(sp) - sd a4, TF_A4(sp) - sd a5, TF_A5(sp) - sd a6, TF_A6(sp) - sd a7, TF_A7(sp) - sd s2, TF_S2(sp) - sd s3, TF_S3(sp) - sd s4, TF_S4(sp) - sd s5, TF_S5(sp) - sd s6, TF_S6(sp) - sd s7, TF_S7(sp) - sd s8, TF_S8(sp) - sd s9, TF_S9(sp) - sd s10, TF_S10(sp) - sd s11, TF_S11(sp) - sd t3, TF_T3(sp) - sd t4, TF_T4(sp) - sd t5, TF_T5(sp) - sd t6, TF_T6(sp) - - /* Save sstatus and sepc */ - csrr t0, sstatus - sd t0, TF_SSTATUS(sp) - csrr t0, sepc - sd t0, TF_EPC(sp) - - /* Call C++ kernel_trap_handler(TrapFrame* tf) */ - mv a0, sp - call kernel_trap_handler - - /* Restore sstatus and sepc */ - ld t0, TF_SSTATUS(sp) - csrw sstatus, t0 - ld t0, TF_EPC(sp) - csrw sepc, t0 - - /* Restore all 31 general-purpose registers */ - ld ra, TF_RA(sp) - ld gp, TF_GP(sp) - ld tp, TF_TP(sp) - ld t0, TF_T0(sp) - ld t1, TF_T1(sp) - ld t2, TF_T2(sp) - ld s0, TF_S0(sp) - ld s1, TF_S1(sp) - ld a0, TF_A0(sp) - ld a1, TF_A1(sp) - ld a2, TF_A2(sp) - ld a3, TF_A3(sp) - ld a4, TF_A4(sp) - ld a5, TF_A5(sp) - ld a6, TF_A6(sp) - ld a7, TF_A7(sp) - ld s2, TF_S2(sp) - ld s3, TF_S3(sp) - ld s4, TF_S4(sp) - ld s5, TF_S5(sp) - ld s6, TF_S6(sp) - ld s7, TF_S7(sp) - ld s8, TF_S8(sp) - ld s9, TF_S9(sp) - ld s10, TF_S10(sp) - ld s11, TF_S11(sp) - ld t3, TF_T3(sp) - ld t4, TF_T4(sp) - ld t5, TF_T5(sp) - ld t6, TF_T6(sp) - - /* Restore sp last */ - ld sp, TF_SP(sp) - - sret - -/* - * userret — return to user mode - * - * Called from C++ as: userret(TrapFrame* tf) - * a0 = pointer to TrapFrame (with user satp already written by caller) - * - * Precondition: interrupts must be disabled by caller. - */ -userret: - /* a0 = TrapFrame pointer, use it as base */ - - /* Step 1: write back epc -> sepc */ - ld t0, TF_EPC(a0) - csrw sepc, t0 - - /* Step 2: write back sstatus */ - ld t0, TF_SSTATUS(a0) - csrw sstatus, t0 - - /* Step 3: caller is responsible for switching satp to user page table - * and flushing TLB before calling userret. */ - - /* Store TrapFrame address into sscratch for next trap entry */ - csrw sscratch, a0 - - /* Use a0 as base to restore all registers */ - mv tp, a0 - - /* Step 4: restore all 31 general-purpose registers */ - ld ra, TF_RA(tp) - ld sp, TF_SP(tp) - ld gp, TF_GP(tp) - /* defer tp restore — we're using it as base */ - ld t0, TF_T0(tp) - ld t1, TF_T1(tp) - ld t2, TF_T2(tp) - ld s0, TF_S0(tp) - ld s1, TF_S1(tp) - ld a0, TF_A0(tp) - ld a1, TF_A1(tp) - ld a2, TF_A2(tp) - ld a3, TF_A3(tp) - ld a4, TF_A4(tp) - ld a5, TF_A5(tp) - ld a6, TF_A6(tp) - ld a7, TF_A7(tp) - ld s2, TF_S2(tp) - ld s3, TF_S3(tp) - ld s4, TF_S4(tp) - ld s5, TF_S5(tp) - ld s6, TF_S6(tp) - ld s7, TF_S7(tp) - ld s8, TF_S8(tp) - ld s9, TF_S9(tp) - ld s10, TF_S10(tp) - ld s11, TF_S11(tp) - ld t3, TF_T3(tp) - ld t4, TF_T4(tp) - ld t5, TF_T5(tp) - ld t6, TF_T6(tp) - - /* Step 5: restore user tp (swap sscratch <-> tp) */ - /* sscratch currently = TrapFrame address, tp = TrapFrame address */ - /* We need: tp = user's tp, sscratch = TrapFrame address */ - /* Load user tp from TrapFrame first, but we can't use any temp reg now. - * Use the sscratch swap trick: */ - ld tp, TF_TP(tp) - - /* sscratch already holds TrapFrame address (set above with csrw) */ - - /* Step 6: sret — return to user mode */ - sret diff --git a/arch/riscv/uaccess/uaccess_memcpy.S b/arch/riscv/uaccess/uaccess_memcpy.S deleted file mode 100644 index 615680d..0000000 --- a/arch/riscv/uaccess/uaccess_memcpy.S +++ /dev/null @@ -1,117 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include - -/* - * extern "C" int __uaccess_memcpy(void* dst, const void* src, uint64 len); - * - * a0: dst - * a1: src - * a2: len - * Returns: 0 on success, -EFAULT (-14) on page fault. - */ -.global __uaccess_memcpy -.type __uaccess_memcpy, @function -__uaccess_memcpy: - /* If len == 0, return 0 */ - beqz a2, .Lmemcpy_done - - /* Enable SUM (Supervisor User Memory) bit: sstatus.SUM is bit 18 */ - li t0, (1 << 18) - csrs sstatus, t0 - -.Lmemcpy_loop: - /* Load byte from src */ -1: lb t1, 0(a1) - /* Store byte to dst */ -2: sb t1, 0(a0) - - addi a0, a0, 1 - addi a1, a1, 1 - addi a2, a2, -1 - bnez a2, .Lmemcpy_loop - -.Lmemcpy_done: - /* Disable SUM */ - li t0, (1 << 18) - csrc sstatus, t0 - li a0, 0 - ret - -.Lmemcpy_fault: - /* Fixup routine on fault */ - /* Disable SUM */ - li t0, (1 << 18) - csrc sstatus, t0 - li a0, -14 /* -EFAULT */ - ret - -/* Exception table entries */ -EXTABLE(1b, .Lmemcpy_fault) -EXTABLE(2b, .Lmemcpy_fault) - - -/* - * extern "C" int64 __uaccess_strncpy(char* dst, const char* src, uint64 max_len); - * - * a0: dst - * a1: src - * a2: max_len - * Returns: number of bytes copied (excluding null), or -EFAULT (-14) on page fault. - */ -.global __uaccess_strncpy -.type __uaccess_strncpy, @function -__uaccess_strncpy: - /* If max_len == 0, return 0 */ - beqz a2, .Lstrncpy_done_zero - - /* Enable SUM */ - li t0, (1 << 18) - csrs sstatus, t0 - - /* t2 will store the length copied */ - li t2, 0 - -.Lstrncpy_loop: - /* Load byte from src */ -3: lb t1, 0(a1) - /* Store byte to dst */ -4: sb t1, 0(a0) - - /* If it was the null terminator, we're done */ - beqz t1, .Lstrncpy_done - - addi a0, a0, 1 - addi a1, a1, 1 - addi t2, t2, 1 - addi a2, a2, -1 - bnez a2, .Lstrncpy_loop - - /* Reached max_len without finding null */ - /* We must null-terminate at max_len - 1 as per typical strncpy_from_user semantics */ - addi a0, a0, -1 - sb zero, 0(a0) - addi t2, t2, -1 /* length of string without the forced null terminator */ - -.Lstrncpy_done: - /* Disable SUM */ - li t0, (1 << 18) - csrc sstatus, t0 - mv a0, t2 - ret - -.Lstrncpy_done_zero: - li a0, 0 - ret - -.Lstrncpy_fault: - /* Fixup routine on fault */ - li t0, (1 << 18) - csrc sstatus, t0 - li a0, -14 /* -EFAULT */ - ret - -/* Exception table entries */ -EXTABLE(3b, .Lstrncpy_fault) -EXTABLE(4b, .Lstrncpy_fault) diff --git a/docs/debug/debug_slab.md b/docs/debug/debug_slab.md deleted file mode 100644 index b64dca8..0000000 --- a/docs/debug/debug_slab.md +++ /dev/null @@ -1,94 +0,0 @@ -# Debug - -发现user_init加载之后无法正常跳转到shell - -检查fork - -添加调试信息 -```cxx -printf("fork start\n"); -int pid = fork(); -printf("fork suceess, pid=%i\n", pid); -``` -正常打印,fork()没有问题 - -尝试在 'exec(sh_path, argv);' 前后添加调试信息 - -该代码之前有输出,之后无输出 - -尝试解决exec.cc的问题 - -在exec()函数开头处添加调试信息 - -```CXX - Drivers::uart_puts("Enter Exec\n"); - // Get Inode - Inode *raw_ip = VFS::namei(path); - if (!raw_ip) - return -1; - InodeGuard iguard(raw_ip); -``` - -没有输出 - -怀疑是系统注册的问题,但不可能,因为在实现shell之前的简易测试程序证明系统调用没有问题 - -尝试 GDB 调试 - -![alt text](debug_slab_1.png) - -发现卡在 sret 返回的部分,跳转的地址没有问题,但是卡死,说明CPU没有跑飞,可能遇到了死循环 - -检查sys_exec() - -通过在每行代码前后添加打印调试信息,发现问题出在这行代码: -```cxx - kargv.args[i] = (char *)Slab::kmalloc(KernelArgv::MAX_ARG_LEN); -``` -这行代码之后的打印信息没有输出,说明这里一直在执行! - -检查Slab - -像之前一样通过在每行代码前后添加打印调试信息,发现问题出在这里: -```cxx -for (uint i = 0; i < c->obj_count_per_slab - 1; i++) - { - // The content of the i-th object is i+1 - uint16 *ptr = (uint16 *)(base + i * c->obj_size); - *ptr = i + 1; - } -``` -这段代码之前的信息可以输出,之后的不能输出,说明这里出问题了 - -在循环内部打印信息,发现调试信息刷屏 - -证明了在GDB里面看到的消息,并不是CPU跑到了某些神秘地址,而是一直卡在这个死循环! - -这里出现了死循环,说明这里循环终止条件出了问题,根本原因需要排查 - -可能是错误的计算,导致这里成了ull的最大值,即使在 3 GHz CPU 上跑空循环,跑满 unsigned long long 最大值次数也需要 近千年。 - -怀疑之前这个值是0 - -添加代码: -```cxx - if (c->obj_count_per_slab == 0) - Drivers::uart_puts("it is 0"); -``` -证明猜测正确 - -这里检查发现这个值确实是0,但它为什么能是0呢? - -可能是初始化的问题???? - -检查系统初始化main.cc - -发现Slab确实没有初始化,导致c->obj_count_per_slab这个值一直是0! - -初始化! - -正常加载shell - -说明 ELF 加载,只读 FAT32 文件系统 正常实现 - -该bug解决 \ No newline at end of file diff --git a/docs/debug/debug_slab_1.png b/docs/debug/debug_slab_1.png deleted file mode 100644 index 5cb9e66..0000000 Binary files a/docs/debug/debug_slab_1.png and /dev/null differ diff --git a/docs/dev/dev_device.md b/docs/dev/dev_device.md deleted file mode 100644 index 1eb6462..0000000 --- a/docs/dev/dev_device.md +++ /dev/null @@ -1,23 +0,0 @@ -# Dev log -## **3.Device Model & HAL:** -* Interrupt Controller: PLIC: - - * Implement the PLIC (Platform-Level Interrupt Controller) driver. - - * Set the PLIC priority threshold and enable bits during the start() phase. - - * Dispatch Cause 9 (External Interrupt) in kerneltrap/usertrap. - -* Character Device: Interrupt-Driven Console: - - * Implement a Ring Buffer. uart_putc returns immediately after writing to the buffer. - - * UART transmit interrupt: triggers when the serial port is idle, the ISR takes data from the Ring Buffer and writes it to the register. - - * UART receive interrupt: triggers when a key is pressed, the ISR reads the character and wakes up the process waiting to read. - -* Block Device: VirtIO-Blk: - - * Implement a block device driver for the PCI or MMIO transport layer according to the VirtIO 2.0 standard. - - * DMA: Use the Buddy System to allocate contiguous memory as the descriptor table for the Virtqueue. \ No newline at end of file diff --git a/docs/dev/dev_memory.md b/docs/dev/dev_memory.md deleted file mode 100644 index f05e336..0000000 --- a/docs/dev/dev_memory.md +++ /dev/null @@ -1,37 +0,0 @@ -# Dev log -## **1. Process Management:** -The core architecture has been upgraded from a simple single queue to a Per-CPU scheduler, supporting multi-core concurrency. - -* Process lifecycle: A complete process state machine has been implemented, including UNUSED, RUNNABLE, RUNNING, SLEEPING, and ZOMBIE states. - -* Core operations: - * fork(): process cloning, supporting COW (copy-on-write) isolation of memory space between parent and child processes. - * exit(): process termination and resource cleanup. - * wait(): parent process waits for child process to exit. - * sleep()/wakeup(): channel-based sleep and wakeup mechanism. - -* Scheduling algorithm: - * O(1) priority scheduling has been implemented (supporting 4 priority queues). - - * Per-CPU RunQueue: each CPU has its own independent run queue. - - * Supports Work Stealing: idle CPUs can fetch tasks from other CPUs’ queues. - -## **2. Memory Management:** -A complete virtual and physical memory management system has been implemented. - -* Physical Memory (PMM): Implements the Buddy System, supporting memory allocation and deallocation in $2^n$ pages. - -* Virtual Memory (VM): Based on RISC-V Sv39 paging mode. Provides secure data copying from user space to kernel space (copyin). - -* COW (Copy-On-Write): During fork, only page table entries are copied and pages are set to read-only; writes trigger page faults for physical copy, greatly improving process creation efficiency. - -* Kernel heap: Implements a Slab Allocator, providing efficient allocation of small objects (such as struct Proc). - -## **3. Synchronization:** - -* Spinlock: Used to protect very short critical sections (e.g., scheduler lock, PMM lock), supports disabling interrupts to prevent deadlocks. - -* Mutex (sleeping lock): Used for long critical sections (e.g., file I/O), allowing sleep while holding the lock. - -* Lock Handoff: Implements a complex lock handoff mechanism in the scheduler to ensure atomicity of context switches. \ No newline at end of file diff --git a/docs/specs/00_conventions.md b/docs/specs/00_conventions.md deleted file mode 100644 index 47da6f1..0000000 --- a/docs/specs/00_conventions.md +++ /dev/null @@ -1,368 +0,0 @@ -# LumeOS 0 号规范 (Project Conventions) - -本文档是 LumeOS 全项目的出厂规范。所有后续 spec 文档和代码必须遵守此规范。 - ---- - -## 1. 架构总览 - -### 1.1 分层模型 - -``` -┌─────────────────────────────────────────────────────────┐ -│ User Programs │ -│ (Busybox, init, shell) │ -├────────────────────── syscall ABI ──────────────────────┤ -│ kernel/syscall │ kernel/proc │ kernel/sched │ -│ (系统调用分发) │ (任务管理) │ (调度器) │ -├───────────────────┼────────────────┼────────────────────┤ -│ fs/ │ mm/ │ kernel/trap │ -│ (VFS + 具体 FS) │ (PMM/Slab/VMM)│ (MI 异常分发) │ -├───────────────────┴────────────────┴────────────────────┤ -│ drivers/ │ -│ (VirtIO, UART, BlockDevice 实现) │ -├─────────────────────────────────────────────────────────┤ -│ arch/$(ARCH)/ │ -│ (CSR, 上下文切换, pmap, TLB, 中断向量, uaccess) │ -├─────────────────────────────────────────────────────────┤ -│ boot/ + linker.ld │ -│ (entry.S, 多核同步, 高半区跳转) │ -└─────────────────────────────────────────────────────────┘ -``` - -**核心规则:** 依赖方向严格向下。上层模块可以调用下层接口,反之禁止。 -`kernel/`、`fs/`、`mm/` 严禁出现内联汇编或架构特定寄存器操作。 - -### 1.2 多态策略 - -| 层级 | 多态方式 | 理由 | -|------|---------|------| -| CPU 核心层 (arch primitives) | Namespace 函数 + 编译期链接 | 零运行时开销,极热路径 | -| 设备抽象层 (BlockDevice 等) | C++ 纯虚类 | 运行时多态,驱动可替换 | -| 跨平台页表 (pmap) | Namespace 函数 + 编译期链接 | 极热路径,每次 page fault | - -### 1.3 目录结构 - -``` -lumeOS/ -├── include/ # 公共头文件(跨模块可见) -│ ├── lume/ # 内核公共接口命名空间 -│ │ ├── types.h # 基础类型 (uint64, size_t, ssize_t, ...) -│ │ ├── errno.h # 全局错误码 (-EINVAL, -ENOMEM, ...) -│ │ └── config.h # 编译期配置 (PAGE_SIZE, NCPU, ...) -│ └── uapi/ # 用户态/内核态共享 (syscall 编号, ioctl) -│ -├── arch/riscv/ # 架构相关(MD 层) -│ ├── include/arch/ # arch 私有头文件 -│ ├── boot/ # entry.S, trampoline.S -│ ├── mm/ # pmap 实现 (页表操作) -│ ├── trap/ # 中断向量, 上下文保存/恢复 -│ └── uaccess.cc # copy_from_user / exception table -│ -├── mm/ # 内存管理(MI 层) -│ ├── pmm.cc / pmm.h # 物理页分配 (Buddy) -│ ├── slab.cc / slab.h # 字节级分配器 -│ └── vmm.cc / vmm.h # VMA 管理, demand paging -│ -├── kernel/ # 内核核心(MI 层) -│ ├── main.cc # kernel_main 初始化序列 -│ ├── trap/ # MI 异常分发 -│ ├── proc/ # TCB, 生命周期, clone/exec/exit -│ ├── sched/ # 调度器 -│ ├── sync/ # Spinlock, Mutex, WaitQueue -│ └── syscall/ # syscall 跳转表与处理函数 -│ -├── fs/ # 文件系统 -│ ├── vfs.cc / vfs.h # VFS 抽象层, MountTable -│ ├── file.cc / file.h # File 基类与 FileTable -│ └── fat32/ # FatFs 胶水层 -│ -├── drivers/ # 设备驱动 -│ ├── uart/ # 串口 -│ ├── virtio/ # VirtIO Block/Net -│ └── tty/ # TTY + Line Discipline -│ -├── lib/ # 内核通用库 -│ ├── kprintf.cc # 内核格式化输出 -│ ├── string.cc # memcpy, memset, strlen, ... -│ └── rbtree.cc # 红黑树 -│ -├── docs/specs/ # 模块 Spec 文档 -├── linker.ld # 链接脚本 -└── Makefile # 构建系统 -``` - -**头文件规则:** -- 跨模块可见的接口 → `include/lume/` 或 `include/uapi/` -- 模块私有头文件 → 与 `.cc` 同目录(如 `mm/pmm.h`) -- `#pragma once` 替代 include guard - ---- - -## 2. 统一术语表 (Ubiquitous Language) - -以下术语在代码和文档中必须严格一致,不得混用同义词。 - -| 概念 | 术语 | 禁止混用 | -|------|------|---------| -| 物理处理器核心 | `CPU` | ~~Hart, core, processor~~ (RISC-V 文档中 Hart 仅在 arch/ 层内部使用) | -| 逻辑调度单元 | `Task` | ~~Process, Thread~~ (对用户态呈现时可说"进程/线程",内核代码统一用 Task) | -| 任务控制块 | `TaskControlBlock` / `TCB` | ~~Proc, PCB~~ | -| 物理内存页帧 | `Frame` | ~~physical page~~ | -| 虚拟页 | `Page` | 仅在虚拟地址语境使用 | -| 虚拟地址区域 | `VMA` (Virtual Memory Area) | ~~vm_area, segment~~ | -| 页表操作层 | `pmap` | ~~pagetable, mmu~~ | -| 内核地址空间 | `kernel space` | ~~supervisor space~~ (代码中 S-mode 指特权级,不指地址空间) | -| 中断请求号 | `irq` | ~~interrupt number~~ | -| 文件描述符编号 | `fd` | ~~fileno, handle~~ | -| 系统调用编号 | `sysno` | ~~syscall_nr, scall~~ | - ---- - -## 3. 全局错误处理范式 - -**选定方案:Linux 负错误码(方案 A)。全局死守,不得例外。** - -### 3.1 函数返回值约定 - -```cpp -// 返回 int 的函数: -// 成功 → 0 或正数(如 read 返回字节数) -// 失败 → 负的错误码(-EINVAL, -ENOMEM, -EFAULT, ...) -int vfs_read(File *f, char *buf, size_t n); - -// 返回指针的函数(仅当失败原因唯一时允许): -// 成功 → 有效指针 -// 失败 → nullptr -// 适用场景:失败原因显而易见且唯一(如"内存不足") -Frame *pmm_alloc_frame(); - -// 返回指针但失败原因可能有多种时 → 禁止返回裸指针。 -// 必须改为返回 int 错误码 + 出参: -int task_alloc(TaskControlBlock **out); // 成功: *out = 有效指针, 返回 0 - // 失败: *out 不变, 返回 -ENOMEM / -EINVAL -``` - -### 3.2 错误码定义 - -所有错误码定义在 `include/lume/errno.h`,编号严格对齐 Linux `asm-generic/errno-base.h`: - -```cpp -#define EPERM 1 // Operation not permitted -#define ENOENT 2 // No such file or directory -#define ENOMEM 12 // Out of memory -#define EFAULT 14 // Bad address -#define EINVAL 22 // Invalid argument -// ... -``` - -### 3.3 禁止事项 - -- **禁止** 使用布尔值表示可能有多种失败原因的操作 -- **禁止** 使用魔数(如 `-1`)代替命名错误码 -- **禁止** 忽略被调用函数的返回值(必须检查或显式 `(void)` 标记) - ---- - -## 4. C++ 命名与格式规范 - -### 4.1 命名约定 - -| 元素 | 风格 | 示例 | -|------|------|------| -| 类 / 结构体 | `PascalCase` | `TaskControlBlock`, `Spinlock` | -| 函数 / 方法 | `snake_case` | `pmm_alloc_frame()`, `task.get_pid()` | -| 局部变量 | `snake_case` | `page_count`, `vma_entry` | -| 私有成员变量 | `snake_case` + `_` 后缀 | `lock_`, `state_`, `parent_` | -| 全局变量 | `g_` 前缀 | `g_pmm`, `g_sched` | -| 编译期常量 | `k` 前缀 + `PascalCase` | `kPageSize`, `kMaxHarts` | -| 宏 / 枚举值 | `UPPER_SNAKE` | `PAGE_SIZE`, `RUNNABLE` | -| 命名空间 | `snake_case` | `namespace arch`, `namespace pmap` | -| 抽象接口类 | 直接命名,无前缀 | `BlockDevice`(不用 `IBlockDevice`) | - -### 4.2 文件命名 - -- 源文件:`snake_case.cc`(C++)、`snake_case.S`(汇编) -- 头文件:`snake_case.h` -- 一个 `.h` + 一个 `.cc` 组成一个模块单元,文件名一致 - -### 4.3 格式(交给工具) - -- 缩进、花括号、列宽等由 `.clang-format` 统一管控 -- 代码提交前必须通过 `clang-format` 格式化 - -### 4.4 C++ 使用边界 - -| 特性 | 允许 | 禁止 | -|------|------|------| -| 类 / 继承 / 虚函数 | ✅ | | -| 模板(简单泛型) | ✅ | | -| RAII (LockGuard) | ✅ | | -| Placement new | ✅ | | -| 异常 (throw/catch) | | ❌ `-fno-exceptions` | -| RTTI (dynamic_cast) | | ❌ `-fno-rtti` | -| STL 容器 | | ❌ 依赖堆分配器 | -| 全局构造函数(隐式) | | ❌ 使用 Placement New | - ---- - -## 5. 并发与锁约定 - -### 5.1 锁声明要求 - -每个持有锁的数据结构,必须在头文件注释中声明: -```cpp -// 锁契约: -// 持有: pmm_lock_ (内部自旋锁) -// 可能获取: 无 -// 调用方禁止持有: sched_lock (避免反向依赖) -class PhysicalMemoryManager { - Spinlock pmm_lock_; - // ... -}; -``` - -### 5.2 全局锁序 - -各 spec 文档必须声明"本模块持有哪些锁、需要获取哪些外部锁"。 -Phase 2 全部完成后,从各 spec 中提取汇总为 `docs/specs/lock_ordering.md` 全局 DAG。 - -### 5.3 原子操作 - -- 引用计数(`refcount`)使用 `__atomic_fetch_sub` / `__atomic_fetch_add` + `__ATOMIC_ACQ_REL` -- **[强制]** 所有在多核间无锁共享的数据,必须使用 `lume::atomic` 类型封装,并显式指定内存序。 -- Spinlock 的 acquire/release 内含隐式 fence,临界区内无需额外屏障 -- **禁止** 用裸 `volatile` 替代原子操作 -- **禁止** 在代码中直接使用 `__atomic_*` 内建函数,必须通过 `lume::atomic` 包装器。 - ---- - -## 6. Spec 文档标准模板 - -后续每份 spec 文档必须包含以下章节: - -```markdown -# 模块名称 (Module Name) - -## 1. 目标 (Objective) -一句话描述本模块的职责边界。 - -## 2. 前置依赖 (Dependencies) -列出本模块依赖的其他模块及其接口。 - -## 3. 核心数据结构 (Data Structures) -结构体定义、内存布局、字段含义。 - -## 4. 公共 API (Public APIs) -函数签名、参数语义、返回值约定、错误码。 - -## 5. 并发与锁契约 (Concurrency & Locks) -- 本模块持有的锁 -- 本模块可能获取的外部锁 -- 调用方的锁限制 - -## 6. 错误路径 (Error Paths) -每个 API 失败时的副作用(是否回滚已分配资源)。 - -## 7. 状态机 / 时序图 (State Machine / Sequence) -(如适用)关键流程的状态转换或调用时序。 -``` - ---- - -## 7. 构建系统架构 - -### 7.1 工具链 - -| 项目 | 选择 | -|------|------| -| 构建系统 | GNU Make (非递归模式) | -| 编译器 | `riscv64-*-gcc` / `riscv64-*-g++` | -| C++ 标准 | C++23 (`-std=c++23`) | -| 关键编译选项 | `-ffreestanding -nostdlib -fno-exceptions -fno-rtti -mcmodel=medany` | -| 代码格式化 | `clang-format`(`.clang-format` 配置) | -| 静态分析 | `clang-tidy`(通过 `bear -- make` 生成 `compile_commands.json`) | -| 调试 | QEMU + GDB (`make debug`) | -| 许可证 | GPL-2.0-or-later | -| 源文件头 | 必须包含 SPDX 标识符和版权声明 | - -### 7.2 构建模式:非递归 Make + 模块片段 - -采用**单一顶层 Makefile + 各模块 `module.mk` 片段**的非递归模式,兼顾模块化与依赖正确性。 - -**目录结构示例:** -``` -lumeOS/ -├── Makefile # 顶层:定义规则、变量、include 所有 module.mk -├── arch/riscv/module.mk # 声明 arch 层源文件 -├── mm/module.mk # 声明内存管理源文件 -├── kernel/module.mk # 声明内核核心源文件 -├── fs/module.mk # 声明文件系统源文件 -├── drivers/module.mk # 声明驱动源文件 -├── lib/module.mk # 声明通用库源文件 -└── build/ # 编译产出目录 (out-of-tree) -``` - -**模块片段 (`module.mk`) 格式:** -```makefile -# mm/module.mk -# 每个模块只声明自己的源文件列表,追加到全局变量 - -SRCS_CC += mm/pmm.cc mm/slab.cc mm/vmm.cc -SRCS_CC += mm/cow.cc -``` - -**顶层 Makefile 骨架:** -```makefile -# === 变量定义 === -ARCH := riscv -BUILD := build -TARGET := $(BUILD)/kernel.elf - -# === 包含所有模块片段 === -SRCS_CC := -SRCS_S := -include arch/$(ARCH)/module.mk -include mm/module.mk -include kernel/module.mk -include fs/module.mk -include drivers/module.mk -include lib/module.mk - -# === 统一规则 === -OBJS := $(patsubst %.cc,$(BUILD)/%.o,$(SRCS_CC)) \ - $(patsubst %.S,$(BUILD)/%.o,$(SRCS_S)) - -$(TARGET): $(OBJS) linker.ld - $(LD) -T linker.ld -o $@ $(OBJS) - -$(BUILD)/%.o: %.cc - @mkdir -p $(dir $@) - $(CXX) $(CXXFLAGS) -c $< -o $@ - -$(BUILD)/%.o: %.S - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) -c $< -o $@ - -# 自动依赖追踪 --include $(OBJS:.o=.d) -``` - -### 7.3 构建规范 - -- **Out-of-tree 编译:** 所有 `.o` 和 `.d` 文件输出到 `build/` 目录,不污染源码树 -- **自动依赖:** 编译时加 `-MMD -MP` 生成 `.d` 依赖文件,增量构建正确追踪头文件变更 -- **新增模块流程:** 创建目录 → 创建 `module.mk` 声明源文件 → 在顶层 Makefile 一行 `include` → 完成 -- **禁止递归 Make:** 不使用 `$(MAKE) -C subdir`,避免依赖追踪断裂 - -### 7.4 标准 Make Target - -| Target | 含义 | -|--------|------| -| `make` / `make all` | 编译内核 ELF | -| `make run` | QEMU 运行(无 GDB) | -| `make debug` | QEMU 运行 + 等待 GDB 附加 | -| `make clean` | 清理 `build/` 目录 | -| `make fmt` | `clang-format -i` 格式化所有源文件 | -| `make lint` | `clang-tidy` 静态分析 | -| `make test` | QEMU 无头冒烟测试 (Phase 4) | diff --git a/docs/specs/arch_abstraction.md b/docs/specs/arch_abstraction.md deleted file mode 100644 index a90137c..0000000 --- a/docs/specs/arch_abstraction.md +++ /dev/null @@ -1,223 +0,0 @@ -# 架构抽象层 (Architecture Abstraction) - -## 1. 目标 (Objective) - -为 LumeOS 的平台无关层(MI)提供统一的底层硬件原语接口。本模块负责将 RISC-V 架构特有的控制状态寄存器 (CSR) 操作、汇编级上下文切换 (Context Switch)、陷阱帧 (TrapFrame) 布局、以及 TLB 刷新机制进行封装。**本项目所有内联汇编 (Inline Assembly) 严格限定于本模块内部,上层模块禁止直接操作硬件寄存器。** - -## 2. 前置依赖 (Dependencies) - -- **全局类型契约:** 依赖 `include/lume/types.h` 提供的 `uint64` 等标准类型。 - -- **编译器支持:** 依赖 GCC/Clang 的内联汇编能力 (`__asm__ volatile`),必须确保不被过度优化(使用 `memory` clobber 建立编译器屏障)。 - -- **启动序列契约:** `arch::cpu::id()` 依赖 `tp` 寄存器在 `entry.S` 中被正确初始化为当前 CPU 编号(参见 `linker_and_entry.md`)。在 `tp` 初始化之前,禁止调用本模块任何依赖 CPU ID 的函数。 - - -## 3. 核心数据结构 (Data Structures) - -### 3.1 上下文切换结构 (`struct Context`) - -用于调度器在不同内核流(如不同 Task 或 KThread)之间进行主动切换(Switch)。它只保存 Callee-Saved(被调用者保存)寄存器。 - -```cpp -// 定义于 arch/riscv/include/arch/context.h -namespace arch { - struct Context { - uint64 ra; // Return Address (返回地址) - uint64 sp; // Stack Pointer (栈指针) - uint64 s[12]; // s0 ~ s11 (Callee-saved 寄存器) - }; -} -``` - -### 3.2 陷阱帧结构 (`struct TrapFrame`) - -用于在发生中断、异常或系统调用时,由硬件与汇编入口 `trap_vector` 协同保存当前 CPU 的执行快照。此结构同时跨越用户态和内核态,必须精确布局。 - -```cpp -// 定义于 arch/riscv/include/arch/trapframe.h -// 对齐由分配方保证(页对齐或栈对齐),struct 本身不施加 alignas -namespace arch { - struct TrapFrame { - /* 内核元数据区 (偏移 0 - 39) */ - uint64 kernel_satp; // 0: 内核页表地址 (挂载至 satp) - uint64 kernel_sp; // 8: 顶层内核栈地址 - uint64 kernel_trap; // 16: 内核 C++ trap_handler 的绝对地址 - uint64 kernel_cpu_id; // 24: 当前 CPU 编号 (trap 入口加载至 tp) - uint64 epc; // 32: 中断/异常时的指令地址 (sepc) - - /* CSR 备份区 (偏移 40 - 47) */ - uint64 sstatus; // 40: 中断前的特权状态 (含 SPP, SPIE 位) - - /* 通用寄存器备份区 (偏移 48 - 295) */ - uint64 ra; // 48 - uint64 sp; // 56 (用户态的栈指针) - uint64 gp; // 64 - uint64 tp; // 72 - uint64 t[7]; // 80: t0-t6 (Caller-saved 临时寄存器) - uint64 s[12]; // 136: s0-s11 (Callee-saved 寄存器) - uint64 a[8]; // 232: a0-a7 (函数参数/系统调用参数与返回值) - }; - static_assert(sizeof(TrapFrame) == 296); -} -``` - -**相比原版的关键修正:** -- **新增 `sstatus` 字段:** 这是陷阱帧中最容易遗漏但最致命的字段。`sstatus` 包含 `SPP`(之前的特权级)和 `SPIE`(之前的中断使能状态)。若不保存/恢复 `sstatus`,`sret` 返回用户态时将无法正确恢复特权级和中断状态。 -- **将 `kernel_cpu_id` 移入元数据区:** 它不是通用寄存器的备份,而是内核注入的元数据(trap 入口用来设置 `tp`),不应放在"通用寄存器备份区"中。 -- **简化寄存器数组:** 将 `t0_t2[3]` + `t3_t6[4]` 合并为 `t[7]`,将 `s0_s1[2]` + `s2_s11[10]` 合并为 `s[12]`。编译器按偏移访问不受影响,且减少了心智负担。 - - -## 4. 公共 API (Public APIs) - -所有接口统一在 `arch` 及其子命名空间下,通过静态内联函数或汇编实现,实现**零运行时代价**。这些操作不会引发常规意义的"错误"(如不会返回 `-ENOMEM`),因此不采用错误码范式。 - -### 4.1 CPU 控制与状态感知 (`namespace arch::cpu`) - -```cpp -namespace arch::cpu { - // 获取当前 CPU 编号 (从 tp 寄存器中读取) - // 前置条件:tp 必须已在 entry.S 中初始化 - uint64 id(); - - // 开启中断 (设置 sstatus.SIE = 1) - void intr_on(); - - // 关闭中断 (设置 sstatus.SIE = 0) - void intr_off(); - - // 获取当前中断状态 (返回 true 表示中断已开启) - bool intr_enabled(); - - // 使 CPU 进入低功耗睡眠,直到下一个中断到来 (wfi 指令) - void halt_until_interrupt(); - - // 读取硬件单调时钟计数 (rdtime 指令) - // 返回自系统启动以来的 tick 数(频率由 FDT timebase-frequency 决定) - uint64 read_time(); -} -``` - -### 4.2 内存管理硬件原语 (`namespace arch::mmu`) - -```cpp -namespace arch::mmu { - // 读取缺页异常发生时的虚拟地址 (从 stval 寄存器读取) - uint64 get_fault_address(); - - // 切换顶级页表 - // 参数:physical_pgdir_addr 为页表的物理地址(非 PPN), - // 函数内部负责右移 12 位并组装 SV39 模式字段写入 satp - void set_page_table(uint64 physical_pgdir_addr); - - // 读取当前页表物理地址 (从 satp 提取 PPN 并左移还原为物理地址) - uint64 get_page_table(); - - // 刷新整个 TLB (sfence.vma zero, zero) - void flush_tlb_all(); - - // 刷新特定虚拟地址的 TLB 条目 (sfence.vma vaddr, zero) - void flush_tlb_page(uint64 vaddr); -} -``` - -### 4.3 陷阱向量控制 (`namespace arch::trap`) - -```cpp -namespace arch::trap { - // 设置 S-mode 陷阱向量基址 (写入 stvec 寄存器) - // 参数:handler_addr 为汇编 trap_vector 入口的虚拟地址 - // 模式:Direct(所有异常/中断统一入口) - void set_vector(uint64 handler_addr); - - // 读取当前陷阱原因 (scause 寄存器) - uint64 get_cause(); - - // 读取陷阱附加信息 (stval 寄存器) - uint64 get_value(); -} -``` - -### 4.4 上下文切换原语 - -```cpp -namespace arch { - // 汇编实现的上下文切换函数。定义于 arch/riscv/swtch.S - // 语义:将当前 CPU 寄存器保存到 old_ctx,并将 next_ctx 的内容恢复到 CPU - // 本函数由 C++ 调用,汇编实现,绝对不会失败。 - extern "C" void context_switch(Context* old_ctx, Context* next_ctx); -} -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -本模块属于内核的绝对最底层,位于 `Spinlock` 模块的下方,因此**不感知、不持有、也不获取任何高级锁。** - -- **调用方契约(中断开关):** 上层模块(如 `Spinlock`)需直接依赖 `arch::cpu::intr_off()` 与 `intr_on()` 来防止单核死锁。 - -- **内存屏障契约(Memory Barriers):** `flush_tlb_all` 与 `flush_tlb_page` 的底层 `sfence.vma` 指令本身即为硬件级内存屏障。内联汇编实现中仍须添加编译器屏障(`"memory"` clobber),防止编译器跨越 TLB 刷新点重排内存访问。 - -- **跨核(SMP)同步警告:** 当前 `flush_tlb_page` 仅执行**本地** `sfence.vma`。在实现基于 IPI (核间中断) 的 TLB Shootdown 前,VMM 须确保同一时间只有一个 CPU 在修改共享的页表映射。未来将在本命名空间中增加 `flush_tlb_page_remote()` 接口。 - - -## 6. 错误路径 (Error Paths) - -底层指令级操作无传统错误返回。 - -- `flush_tlb_page` 对任何地址执行 `sfence.vma` 都不会触发异常(仅使对应 TLB 表项失效)。 - -- `context_switch` 若传入无效指针(如 nullptr),加载/存储操作将触发 Store/Load Page Fault,由 Phase 2 的 `trap.md` 规定的异常分发层兜底并触发 `Panic`。 - -- `set_page_table` 传入非法物理地址将导致后续的所有内存访问引发 Page Fault。此类错误属于编程逻辑错误,无法在本层恢复。 - - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -### 7.1 上下文切换时序 (`context_switch`) - -调度器在选择出新的 `Task` 后,调用此接口的时序如下: - -``` -[当前 Task A] (执行 sched() 决定放弃 CPU) - │ - ▼ -[调用 arch::context_switch(&TaskA->context, &TaskB->context)] - │ - ├─> 1. 保存 ra, sp, s0-s11 到 TaskA->context 内存区块中 - ├─> 2. 从 TaskB->context 内存区块中加载 ra, sp, s0-s11 到物理寄存器 - └─> 3. ret (返回到被加载的 ra 地址) - │ - ▼ -[恢复至 Task B] (PC 从 Task B 上次挂起的 sched() 处继续执行) -``` - -### 7.2 陷阱帧保存/恢复时序 (trap_vector) - -``` -[用户态正在运行] - │ - ├─ 中断/异常/ecall 触发 - ▼ -[trap_vector (汇编入口, arch/riscv/trap/trap_vector.S)] - │ - ├─> 1. 交换 sscratch <-> tp (sscratch 预存 TrapFrame 地址) - ├─> 2. 将 31 个通用寄存器写入 TrapFrame - ├─> 3. csrr sstatus → TrapFrame.sstatus (保存特权状态) - ├─> 4. csrr sepc → TrapFrame.epc (保存中断 PC) - ├─> 5. 加载 kernel_sp, kernel_satp, kernel_cpu_id 到 sp, satp, tp - ├─> 6. sfence.vma (切换到内核页表后刷新 TLB) - └─> 7. jalr TrapFrame.kernel_trap (跳转至 C++ trap_handler) - │ - ▼ -[MI 层 trap_handler()] → 分发至 syscall / page fault / IRQ 处理 - │ - ▼ -[usertrapret: 恢复用户态] - │ - ├─> 1. 写回 TrapFrame.epc → sepc - ├─> 2. 写回 TrapFrame.sstatus → sstatus - ├─> 3. 切换回用户页表 (satp) - ├─> 4. 从 TrapFrame 恢复 31 个通用寄存器 - ├─> 5. 交换 sscratch <-> tp (恢复 TrapFrame 地址到 sscratch) - └─> 6. sret (返回用户态) -``` \ No newline at end of file diff --git a/docs/specs/atomics.md b/docs/specs/atomics.md deleted file mode 100644 index 841f287..0000000 --- a/docs/specs/atomics.md +++ /dev/null @@ -1,80 +0,0 @@ -# 原子操作与内存序 (Atomics & Memory Ordering) - -## 1. 目标 (Objective) - -为 LumeOS 在 RISC-V 弱内存模型 (RVWMO) 环境下提供一套安全、可控的原子操作库。本模块旨在通过封装 C++ `std::atomic` 风格的接口,强制开发者在进行无锁编程时显式考虑内存序 (Memory Ordering),以避免因指令重排导致的、难以复现的并发 Bug。 - -## 2. 前置依赖 (Dependencies) - -- **编译器支持:** 依赖 GCC/Clang 的 `__atomic_*` 内建函数。 - -## 3. 核心设计:`lume::atomic` - -### 3.1 问题背景:弱内存模型 (RVWMO) - -RISC-V 采用弱内存模型,允许 CPU 和编译器进行激进的指令重排。在无锁数据结构(如 Per-CPU 缓存的无锁链表)中,如果仅使用简单的原子操作而没有指定正确的内存序,可能发生以下灾难: - -- **场景:** CPU A 分配一个新节点 `node`,填充其数据 `node->data = val`,然后通过原子交换将其链接到链表头 `head.exchange(node)`。 -- **风险:** CPU B 可能先观测到 `head` 指针的更新,但由于指令重排,`node->data` 的写入尚未对 CPU B 可见,导致 CPU B 读取到未初始化的垃圾数据。 - -`Spinlock` 内部的 `fence` 无法保护这种无锁路径。 - -### 3.2 解决方案:封装 `std::atomic` 风格接口 - -LumeOS 将提供 `lume::atomic` 模板类,禁止直接使用 `__atomic_*` 内建函数。 - -1. **定义 `memory_order` 枚举:** - ```cpp - // in include/lume/atomic.h - namespace lume { - enum memory_order { - relaxed = __ATOMIC_RELAXED, - consume = __ATOMIC_CONSUME, - acquire = __ATOMIC_ACQUIRE, - release = __ATOMIC_RELEASE, - acq_rel = __ATOMIC_ACQ_REL, - seq_cst = __ATOMIC_SEQ_CST - }; - } - ``` - -2. **创建 `lume::atomic` 模板类:** - ```cpp - // in include/lume/atomic.h - namespace lume { - template - struct atomic { - T value; - - T load(memory_order order = seq_cst) const { - return __atomic_load_n(&value, order); - } - - void store(T desired, memory_order order = seq_cst) { - __atomic_store_n(&value, desired, order); - } - - T fetch_add(T arg, memory_order order = seq_cst) { - return __atomic_fetch_add(&value, arg, order); - } - // ... 其他 fetch_*, exchange, compare_exchange_strong 等方法 - }; - } - ``` - -3. **强制使用规范:** - 在 `00_conventions.md` 中明确规定:所有在多核间无锁共享的数据(如 `Frame::refcount`,PCP 链表头指针),其类型**必须**是 `lume::atomic`,严禁使用原生类型或 `volatile`。 - - **示例 (PMM):** - ```cpp - // in mm/frame.h - #include - struct Frame { - lume::atomic refcount; - // ... - }; - ``` - -## 4. 公共 API - -`lume::atomic` 的 API 设计将严格对齐 C++ 标准库的 `std::atomic`,降低学习成本。 \ No newline at end of file diff --git a/docs/specs/cpp_runtime.md b/docs/specs/cpp_runtime.md deleted file mode 100644 index e3ebd90..0000000 --- a/docs/specs/cpp_runtime.md +++ /dev/null @@ -1,55 +0,0 @@ -# C++ 内核运行时 (C++ Kernel Runtime) - -## 1. 目标 (Objective) - -为 LumeOS 内核提供最小化的 C++ ABI 存根函数。在 `-fno-exceptions -fno-rtti -nostdlib` 环境下,编译器和链接器仍会引用若干 C++ 运行时符号(如纯虚函数陷阱、全局析构注册、DSO handle)。本模块提供这些符号的内核实现,防止链接失败。 - -**职责边界:** -- `operator new/delete` 由 Slab 分配器模块 (`mm/slab.cc`) 提供,**不在本模块**。 -- Placement new 由 `include/lume/new.h` 提供,**不在本模块**。 -- 本模块仅提供 ABI 存根和编译器辅助符号。 - -## 2. 前置依赖 (Dependencies) - -- **Panic 机制 (`lib/panic.cc`):** 依赖 `kernel_panic()` 在遇到不可恢复错误时终止系统。 -- **项目约定 (`00_conventions.md`):** 遵循 `-fno-exceptions -fno-rtti` 编译约束。 - -## 3. 核心数据结构 (Data Structures) - -无。本模块仅实现全局函数和符号。 - -## 4. 公共 API (Public APIs) - -这些符号由编译器/链接器隐式引用,内核代码不应直接调用。 - -```cpp -// 定义于 lib/cxx_abi.cc - -// 当代码通过基类指针调用未实现的纯虚函数时, -// 编译器生成的 vtable 条目会引用此符号。 -// 这是不可恢复的编程错误。 -extern "C" void __cxa_pure_virtual(); - -// 全局对象析构注册。内核不支持全局对象析构(全局对象 -// 通过 Placement New 手动管理生命周期)。若编译器生成 -// 对此符号的调用,说明代码中存在违规的全局对象。 -extern "C" int __cxa_atexit(void (*func)(void*), void* arg, void* dso_handle); - -// DSO handle — 链接器在某些情况下引用此符号 -// (与 __cxa_atexit 配合标识动态共享对象)。 -// 内核为静态链接,此符号仅需存在即可。 -extern "C" void* __dso_handle; -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -无。所有函数要么立即 panic,要么是静态符号。 - -## 6. 错误路径 (Error Paths) - -- `__cxa_pure_virtual()` → 立即 `kernel_panic("pure virtual function call")`。 -- `__cxa_atexit()` → 立即 `kernel_panic("__cxa_atexit called in kernel")`。 - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -无复杂时序。所有路径均为:检测到违规 → panic。 diff --git a/docs/specs/fdt.md b/docs/specs/fdt.md deleted file mode 100644 index 2a1d542..0000000 --- a/docs/specs/fdt.md +++ /dev/null @@ -1,191 +0,0 @@ -# 设备树 (Flattened Device Tree) - -## 1. 目标 (Objective) - -为 LumeOS 提供一套标准的硬件发现与配置机制,彻底摆脱硬编码的物理地址。本模块负责解析由 Bootloader 传入的 FDT 二进制数据,并分两个阶段将其转化为内核可用的数据结构: - -1. **早期扫描 (Early Scan):** 在内存管理(PMM)初始化之前,以只读、无分配的方式扫描 FDT,提取启动所必需的核心信息(如物理内存布局)。 -2. **对象化展开 (Unflattening):** 在内存管理(PMM/Slab)就绪后,将完整的 FDT 解析为一个常驻内存的 C++ `DeviceNode` 对象树,为后续的驱动探测(Driver Probing)提供面向对象的接口。 - -## 2. 前置依赖 (Dependencies) - -- **引导协议契约 (`linker_and_entry.md`):** 依赖 Bootloader 在跳转至内核时,将 FDT 的物理基址置于 `a1` 寄存器。 -- **全局初始化契约 (`global_init.md`):** `fdt_init()` 在 `console_init()` 之后、`pmm_init()` 之前被 BSP 调用。`pmm_init()` 自身会回调 FDT 的早期扫描接口。 -- **内存管理契约 (`pmm.md`, `slab.md`):** 对象化展开阶段依赖 Slab 分配器(`operator new`)来动态创建 `DeviceNode` 对象。 -- **项目约定 (`00_conventions.md`):** 遵循所有命名、错误处理和 API 设计规范。 - -## 3. 核心数据结构 (Data Structures) - -### 3.1 FDT 属性 (`struct FdtProperty`) - -表示设备节点中的一个属性(如 `reg`, `compatible`)。 - -```cpp -// 定义于 include/lume/fdt_prop.h -struct FdtProperty { - const char* name; // 属性名 - const void* value; // 指向 FDT blob 中原始数据的指针 - int len; // 数据长度(字节) - list_node link; // 链接到下一个属性 -}; -``` - -### 3.2 设备节点 (`class DeviceNode`) - -FDT 对象树的核心,代表一个硬件设备或总线。 - -```cpp -// 定义于 include/lume/device_node.h -class DeviceNode { -public: - // 构造/析构 - DeviceNode(DeviceNode* parent, const char* name); - ~DeviceNode(); - - // 属性访问 - const FdtProperty* get_prop(const char* name) const; - uint32_t get_prop_u32(const char* name, uint32_t default_val = 0) const; - uint64 get_prop_u64(const char* name, uint64 default_val = 0) const; - const char* get_prop_string(const char* name) const; - - // 子节点遍历 - DeviceNode* find_child(const char* name); - void for_each_child(void (*callback)(DeviceNode*)); - - // 内部接口,供 FdtManager 构建树时使用 - void add_child(DeviceNode* child); - void add_prop(FdtProperty* prop); - -private: - const char* name_; - DeviceNode* parent_; - list_node children_list_; // list_head of children - list_node props_list_; // list_head of properties - list_node sibling_link_; // link in parent's children_list_ -}; -``` - -### 3.3 FDT 管理器 (`class FdtManager`) - -全局单例,负责 FDT 的解析与查询。 - -```cpp -// 定义于 include/lume/fdt.h -class FdtManager { -public: - // 由 fdt_init() 通过 Placement New 调用 - FdtManager(uint64 fdt_paddr); - - // 阶段二:对象化展开 - void unflatten(); - - // 驱动探测接口 - DeviceNode* find_compatible(const char* compat_string); - DeviceNode* get_node_by_path(const char* path); - - // 阶段一:早期扫描接口 (静态,无状态) - static void early_scan_mem(uint64 fdt_paddr, uint64* base, uint64* size); - static void early_scan_uart(uint64 fdt_paddr, uint64* uart_addr); - -private: - uint64 fdt_paddr_; - DeviceNode* root_ = nullptr; - bool is_unflattened_ = false; -}; - -// 全局 FDT 管理器实例指针 -extern FdtManager* g_fdt; -``` - -## 4. 公共 API (Public APIs) - -```cpp -// === 初始化 API (由 kernel_main 调用) === - -// 阶段一和阶段二的入口。仅保存 FDT 地址,真正的解析被推迟。 -void fdt_init(uint64 fdt_paddr); - -// 在 Slab 就绪后调用,执行对象化展开。 -void fdt_unflatten(); - - -// === 驱动探测 API (供各驱动 init 函数调用) === - -// 根据 "compatible" 字符串查找第一个匹配的设备节点。 -// 返回值:成功则为 DeviceNode 指针,失败为 nullptr。 -DeviceNode* fdt_find_compatible(const char* compat_string); - -// 根据完整路径查找设备节点。 -DeviceNode* fdt_get_node_by_path(const char* path); - - -// === 早期扫描 API (供 PMM 和早期控制台调用) === - -// 扫描 FDT blob 获取 /memory 节点的 base 和 size。 -// 失败则 panic。 -void fdt_early_get_mem_info(uint64* base, uint64* size); - -// 扫描 FDT blob 获取 /chosen/stdout-path 对应的 UART 物理地址。 -void fdt_early_get_uart_info(uint64* uart_addr); -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -- **无锁设计:** FDT 的所有初始化和解析操作(`fdt_init`, `fdt_unflatten`)均由 BSP 在多核启动前的**绝对单核期**完成。 - -- **只读安全:** 一旦 `fdt_unflatten()` 完成,`DeviceNode` 对象树即被视为**全局只读**数据。任何 CPU 都可以随时无锁访问它进行驱动探测和属性查询。 - -- **禁止修改:** 任何模块在初始化之后都**不得**修改 `DeviceNode` 树的内容。 - -## 6. 错误路径 (Error Paths) - -- **FDT 损坏:** 在 `fdt_init()` 或 `fdt_unflatten()` 中,如果检测到 FDT 的 magic number 无效或结构损坏,必须立即调用 `kernel_panic()`。 - -- **关键节点缺失:** `fdt_early_get_mem_info()` 如果找不到 `/memory` 节点,说明无法确定物理内存大小,属于致命错误,必须 `kernel_panic()`。 - -- **内存分配失败:** `fdt_unflatten()` 在使用 `new` 创建 `DeviceNode` 时如果 Slab 返回 `nullptr`,说明内存耗尽,必须 `kernel_panic()`。 - -- **查询失败:** `fdt_find_compatible()` 或 `fdt_get_node_by_path()` 在未找到匹配节点时,安全地返回 `nullptr`。调用方(驱动)负责处理此情况(通常意味着该硬件不存在,驱动不进行初始化)。 - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -### FDT 二阶段解析时序 - -``` -[entry.S] -> a1 = fdt_paddr - │ - ▼ -[kernel_main on BSP] - │ - ├─> 1. fdt_init(fdt_paddr) - │ └─ g_fdt = new FdtManager(fdt_paddr); // Placement New - │ (仅保存地址,不进行任何解析) - │ - ├─> 2. pmm_init() - │ └─ fdt_early_get_mem_info(&base, &size); - │ └─ FdtManager::early_scan_mem(fdt_paddr, ...); - │ ├─ 遍历原始 FDT blob (无内存分配) - │ ├─ 找到 /memory 节点 - │ └─ 返回 reg 属性值 - │ - ├─> 3. slab_init() - │ └─ operator new 可用 - │ - ├─> 4. (稍后) fdt_unflatten() - │ └─ g_fdt->unflatten(); - │ ├─ 再次遍历原始 FDT blob - │ ├─ for each node: new DeviceNode(...) - │ ├─ for each prop: new FdtProperty(...) - │ └─ 构建完整的 C++ 对象树 - │ - ▼ -[驱动初始化阶段, e.g., plic_init()] - │ - ├─> node = fdt_find_compatible("riscv,plic0"); - │ └─ g_fdt->find_compatible(...); - │ └─ 遍历已构建的 DeviceNode C++ 对象树 (只读, 无锁) - │ - ├─> reg_prop = node->get_prop("reg"); - │ - └─> (使用 reg_prop->value 初始化 PLIC 驱动) -``` \ No newline at end of file diff --git a/docs/specs/global_init.md b/docs/specs/global_init.md deleted file mode 100644 index cd14dae..0000000 --- a/docs/specs/global_init.md +++ /dev/null @@ -1,208 +0,0 @@ -# 全局初始化序列 (Global Initialization) - -## 1. 目标 (Objective) - -统筹 LumeOS 从汇编跃迁至 C++ 后的全局初始化流程。定义子系统间的严格启动顺序、全局对象的生命周期管理范式、以及 BSP/AP 的两阶段同步协议。 - -## 2. 前置依赖 (Dependencies) - -- **汇编环境契约:** 依赖 `linker_and_entry.md` 保证的执行环境:BSS 段已被清零、高半区虚拟内存(`early_pgdir`)已映射、`tp` 寄存器已保存当前 CPU ID、`gp` 寄存器已就绪。注意:`early_cpp_init()` 已在 `entry.S` 中由 BSP 调用完毕(在 `kernel_main` 之前),不在本模块的管辖范围内。 - -- **全局基础契约:** 依赖 `00_conventions.md` 中禁用了 C++ 异常与 RTTI 的环境。 - -- **并发同步契约:** 依赖 `spinlock.md` 提供的 `Spinlock`(但在 BSP 独占期不使用)。 - - -## 3. 核心数据结构与生命周期范式 (Data Structures & Lifecycle) - -在内核早期,物理内存管理 (PMM) 和字节级分配器 (Slab) 尚未就绪,传统的 `new` 和隐式的全局构造函数极易引发缺页崩溃或顺序未定义行为。 - -### 3.1 显式生命周期模型 (Placement New 范式) - -对于所有复杂的内核全局单例(如 `PhysicalMemoryManager`, `Scheduler`),**严禁**直接定义为全局变量依赖 `.init_array` 隐式构造。必须采用以下静态缓冲区分配 + 显式 Placement New 的范式: - -```cpp -// 示例:kernel/mm/pmm_global.cc - -// Placement new 声明(freestanding 环境无 头文件,自行提供) -// 定义于 include/lume/new.h -inline void* operator new(size_t, void* ptr) noexcept { return ptr; } -inline void operator delete(void*, void*) noexcept {} - -// 1. 在 .bss 段静态分配对齐的内存区块,不触发任何构造函数 -alignas(PhysicalMemoryManager) uint8 g_pmm_buf[sizeof(PhysicalMemoryManager)]; - -// 2. 暴露全局指针供外部访问 -PhysicalMemoryManager* g_pmm = nullptr; - -// 3. 在 kernel_main 的严格时序中被显式调用 -void pmm_init(uint64 fdt_paddr) { - // 使用 Placement New 在预分配的内存上执行构造函数 - g_pmm = new (g_pmm_buf) PhysicalMemoryManager(fdt_paddr); -} -``` - -**关于 `` 头文件:** 在 `-ffreestanding -nostdlib` 编译环境下,`` 可能不可用或行为不一致。LumeOS 在 `include/lume/new.h` 中自行提供 placement new 声明,不依赖任何标准库头文件。 - -### 3.2 简单数据结构的按需初始化 - -对于没有复杂依赖的 Plain Old Data (POD) 或简单锁对象: - -- `Spinlock` 等对象直接作为 BSS 段全局变量,由 `entry.S` 清零。随后在所属子系统的 `init()` 方法中调用 `lock.init("name")` 赋予身份。 - -### 3.3 `.init_array` 的使用边界 - -`early_cpp_init()` 在 `entry.S` 中遍历 `.init_array`。只有满足以下**全部**条件的全局构造函数才允许出现在此表中: - -- 构造函数不依赖任何子系统(PMM、Slab、VMM、Scheduler 均未初始化)。 -- 构造函数不分配动态内存。 -- 构造函数不获取任何锁。 - -实际上,应该尽量让 `.init_array` 为空。绝大多数全局对象应走 §3.1 的 Placement New 路径。 - - -## 4. 公共 API (Public APIs) - -### 4.1 内核 C++ 唯一入口 - -```cpp -// 定义于 kernel/main.cc -// 被 entry.S 中的 real_start 在开启 MMU、调用 early_cpp_init 后跳转 -// 所有 CPU 从此入口进入 C++ 世界 -// a0 = cpu_id, a1 = fdt_paddr -extern "C" void kernel_main(uint64 cpu_id, uint64 fdt_paddr) __attribute__((noreturn)); -``` - -### 4.2 子系统初始化签名规范 - -所有子系统的初始化入口必须遵循统一签名,并在 `kernel/main.cc` 内部按图谱依次调用。每个 `xxx_init()` 函数成功时无返回值,失败时直接 `kernel_panic()`: - -```cpp -void console_init(); // 1. UART 就绪,此后 kprintf/kernel_panic 可输出 -void fdt_init(uint64 fdt_paddr); // 2. 解析 FDT,构建设备节点表 -void pmm_init(); // 3. 从 FDT 获取内存布局,建立 Buddy 分配器 -void slab_init(); // 4. 建立 kmem_cache,此后 operator new 可用 -void vmm_init(); // 5. 建立精细化内核页表,废弃 early_pgdir -void trap_init(); // 6. 设置 stvec,注册 IRQ 分发器 -void plic_init(); // 7. 配置 PLIC 中断控制器(阈值、优先级、使能位) -void timer_init(); // 8. 配置定时器中断(调度器时钟源) -void sched_init(); // 9. 构造 BSP 的 Idle Task 和初始就绪队列 -``` - -### 4.3 AP 初始化签名 - -AP 在 BSP 完成全局初始化后执行,仅限 Per-CPU 私有数据: - -```cpp -void vmm_init_ap(); // 切换 satp 至 BSP 建好的内核页表 -void trap_init_ap(); // 设置本 CPU 的 stvec -void plic_init_ap(); // 配置本 CPU 在 PLIC 上的 Context 使能 -void timer_init_ap(); // 启动本 CPU 的定时器中断 -void sched_init_ap(); // 初始化本 CPU 的 O(1) 就绪队列、创建 Idle Task -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -这是整个内核生命周期中**唯一一段不受自旋锁约束的特殊时期**,必须严格遵循以下阶段隔离: - -### 5.1 两阶段同步协议 - -LumeOS 启动过程中存在**两个独立的同步屏障**,不要混淆: - -| 同步点 | 位置 | 变量 | 含义 | -|--------|------|------|------| -| 第一道 | `entry.S` (汇编层) | `boot_sync_flag` | AP 等待 BSP 建立 `early_pgdir`,完成后所有 CPU 齐步进入虚拟地址空间 | -| 第二道 | `kernel_main` (C++ 层) | `ap_boot_sync` | AP 等待 BSP 完成全部子系统初始化,完成后 AP 开始 Per-CPU 初始化 | - -### 5.2 绝对单核期 (BSP 独占) - -- 在 `kernel_main` 启动初期,AP 卡在第二道屏障 `ap_boot_sync` 处自旋。 - -- BSP 拥有对全局数据结构的**绝对独占权**。在此期间调用 `pmm_init`、`vmm_init` 等函数时,**无需获取该子系统的 `Spinlock`**(也不应获取,因为锁可能尚未初始化)。 - -### 5.3 多核唤醒与并发期 (AP 启动) - -- BSP 完成所有全局初始化后,通过 `__atomic_store_n(&ap_boot_sync, 1, __ATOMIC_RELEASE)` 唤醒 AP。`RELEASE` 语义保证 AP 读到 `ap_boot_sync == 1` 时,所有全局单例对象必然已构造完毕。 - -- AP 进入后,**只能执行 Per-CPU 的局部初始化**(如设置自身的 `stvec`、初始化 PLIC Context、创建 Per-CPU Idle Task)。 - -- 一旦 AP 的 Per-CPU 初始化完成并开启中断,所有子系统对全局数据的访问必须严格遵守 `spinlock.md` 契约。 - - -## 6. 错误路径 (Error Paths) - -初始化阶段的错误处理极度苛刻: - -- **console_init 之前的 Panic:** 此时 UART 尚未就绪,`kernel_panic()` 无法输出任何信息。唯一行为是关中断 + `wfi` 死循环(静默死亡)。可通过 JTAG/GDB 附加调试。 - -- **console_init 之后的 Panic:** 可输出 Panic 消息和调用栈信息后死循环。 - -- 任何子系统的 `init` 方法如果检测到硬件缺失(如 FDT 解析不到内存节点)或关键资源耗尽(Slab 无法建立早期缓存),必须**立即调用 `kernel_panic()`**。 - -- 此阶段系统尚未具备任务调度与资源回收能力,无后路可退。 - - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -### 7.1 全局初始化依赖 DAG 图 - -`kernel_main` 必须严格按照自顶向下的单向依赖顺序执行,任何逆序调用将导致 `kernel_panic` 或缺页崩溃。 - -``` - entry.S (汇编世界) - │ - early_cpp_init() ← 遍历 .init_array (应尽量为空) - │ - ════════════════ - kernel_main() - ════════════════ - │ - ┌─────────────┴──────────────┐ - │ │ - [BSP (cpu_id == 0)] [AP (cpu_id != 0)] - │ │ - 1. console_init() 自旋等待 - └─ UART 就绪 ap_boot_sync == 1 - └─ 此后 Panic 可输出 │ - │ │ - 2. fdt_init(fdt_paddr) │ - └─ 解析 FDT 设备树 │ - │ │ - 3. pmm_init() │ - └─ Buddy 分配器就绪 │ - │ │ - 4. slab_init() │ - └─ operator new 可用 │ - │ │ - 5. vmm_init() │ - └─ 完整内核页表就绪 │ - └─ 废弃 early_pgdir 恒等映射 │ - │ │ - 6. trap_init() │ - └─ stvec 挂载 trap_vector │ - │ │ - 7. plic_init() │ - └─ PLIC 中断控制器就绪 │ - │ │ - 8. timer_init() │ - └─ 定时器中断就绪 │ - │ │ - 9. sched_init() │ - └─ Idle Task (Task 0) 创建 │ - └─ Per-CPU 就绪队列初始化 │ - │ │ - ──[RELEASE 屏障]──────────────────> 读到 1 - ap_boot_sync = 1 │ - │ 1. vmm_init_ap() - │ 2. trap_init_ap() - │ 3. plic_init_ap() - │ 4. timer_init_ap() - │ 5. sched_init_ap() - │ │ - ▼ ▼ - arch::cpu::intr_on() arch::cpu::intr_on() - BSP 变为 Idle Task AP 变为 Idle Task - 进入调度循环 进入调度循环 -``` - -**BSP 进入调度的方式:** BSP 在 `sched_init()` 中将自身的执行上下文注册为 CPU 0 的 Idle Task (Task 0)。开启中断后,第一个定时器中断触发调度器接管执行流。不是通过 `sched_yield()` 主动让出,而是被定时器中断被动抢占进入调度循环。 \ No newline at end of file diff --git a/docs/specs/linker_and_entry.md b/docs/specs/linker_and_entry.md deleted file mode 100644 index a59d28d..0000000 --- a/docs/specs/linker_and_entry.md +++ /dev/null @@ -1,208 +0,0 @@ -# 链接器与引导入口 (Linker & Entry) - -## 1. 目标 (Objective) - -定义 LumeOS 在 RISC-V 64 架构上的早期内存布局与汇编启动序列。负责兼容多种 Bootloader(OpenSBI、GRUB、U-Boot),建立高半区内核(Higher-Half Kernel)映射,初始化早期 C++ 运行环境(BSS、GP 寄存器、全局构造函数),并安全地将各个 CPU 同步导入虚拟地址空间的 `kernel_main`。 - -## 2. 前置依赖 (Dependencies) - -- **引导协议契约 (Boot Protocol):** 为了同时支持 OpenSBI(直接跳转偏移 0)和 GRUB/U-Boot(解析元数据后引导),LumeOS 采用 **RISC-V Linux Boot Protocol**。内核文件起始处必须包含标准的 64 字节 Image Header。 - -- **寄存器传参契约:** 无论哪种引导器,在跳转至内核执行的第一条指令时,必须保证 `a0` = 当前 CPU ID (Hart ID),`a1` = FDT (Device Tree) 的物理基址。 - -- **编译模型契约:** 内核必须使用 `-mcmodel=medany` 编译,以支持基于 PC 的相对寻址,确保在 MMU 开启前后代码均能正确执行。 - -- **硬件 MMU 契约:** 目标硬件必须支持 RISC-V SV39 分页模式。 - - -## 3. 核心数据结构与内存布局 (Data Structures & Memory Map) - -### 3.1 虚拟与物理地址基址 - -- **物理加载基址 (Physical Base):** `0x80200000` (跳过低地址的 OpenSBI 固件区,对齐 2MB 以支持大页映射)。 - -- **内核虚拟基址 (Virtual Base):** `0xFFFFFFC080200000` (SV39 地址空间顶部,硬编码偏移量 `PAGE_OFFSET = 0xFFFFFFC000000000`)。 - -- **虚拟-物理偏移常量:** `KERNEL_VA_OFFSET = 0xFFFFFFC000000000`,用于虚拟/物理地址互转:`VA = PA + KERNEL_VA_OFFSET`,`PA = VA - KERNEL_VA_OFFSET`。 - - -### 3.2 链接脚本段分布 (`linker.ld`) - -必须在所有代码之前放置 `.head.text` 段,以确保 Image Header 绝对位于二进制文件的第 0 字节处。所有段强制 4KB 对齐: - -``` -+-----------------------+ 0xFFFFFFC080200000 (Virtual) / 0x80200000 (Physical) -| .head.text (镜像头) | -> 严格位于内核入口 0 字节处,包含 Linux Boot Header -+-----------------------+ -| .text (执行代码) | -> ALIGN(4096), 权限: RX -+-----------------------+ -| .rodata (只读数据) | -> ALIGN(4096), 权限: R- -| (含 __init_array) | -> 全局构造函数指针表 -+-----------------------+ -| .data (已初始化数据) | -> ALIGN(4096), 权限: RW -| (含 __global_pointer$)| -> 位于 .sdata 附近,用于优化全局变量访问 -| (含 early_pgdir) | -> 4KB 静态早期页表 -+-----------------------+ -| .bss (未初始化数据) | -> ALIGN(4096), 权限: RW -+-----------------------+ -| boot_stack (早期栈) | -> ALIGN(4096), 为每个 CPU 预留 8KB 栈空间 -+-----------------------+ -``` - -**链接脚本必须导出的符号:** - -| 符号名 | 含义 | -|--------|------| -| `_start` | 内核入口点(Image Header 首字节) | -| `_stext` / `_etext` | .text 段边界 | -| `_srodata` / `_erodata` | .rodata 段边界 | -| `_sdata` / `_edata` | .data 段边界 | -| `_sbss` / `_ebss` | .bss 段边界(用于启动清零) | -| `__global_pointer$` | GP 寄存器锚点 | -| `__init_array_start` / `__init_array_end` | C++ 全局构造函数表边界 | -| `_kernel_end` | 内核镜像结束地址(PMM 初始化起点) | - -### 3.3 早期页表 (Early Page Table) - -- **`early_pgdir`:** 一块静态分配的 4KB `.data` 内存,用作初始顶级页表 (Root Page Table)。 - -- 内含两个 1GB 的超级大页(Giga Page)映射: - - 1. **恒等映射 (Identity Map):** `0x80000000 -> 0x80000000`,保证开启 MMU 瞬间下一条指令能正确取指。 - - 2. **高半区映射 (Higher-Half Map):** `0xFFFFFFC080000000 -> 0x80000000`,供后续 C++ 代码正常运行。 - -- **生命周期:** 此恒等映射为临时性过渡,在 VMM 建立完整页表后必须被撤销。高半区映射将被 VMM 接管并细化为 4KB 粒度的精确权限映射。 - - -## 4. 公共 API 与核心符号 (Public APIs & Symbols) - -### 4.1 RISC-V OS Image Header 规范 - -在 `entry.S` 的最开始(`.head.text` 段),必须按照以下结构手写 64 字节的元数据。 -定义参照 Linux `arch/riscv/include/asm/image.h` 中的 `struct riscv_image_header`: - -```asm - .section .head.text, "ax" - .globl _start -_start: - /* code0 (u32, offset 0): 可执行跳转指令,OpenSBI 裸启入口 */ - j real_start - /* code1 (u32, offset 4): 保留 */ - .word 0 - /* text_offset (u64, offset 8): Image 加载偏移 */ - .dword 0x200000 - /* image_size (u64, offset 16): 镜像大小,链接后由脚本填充,初期可写 0 */ - .dword 0 - /* flags (u64, offset 24): 内核标志位 (bit 0: 0=LE, 1=BE) */ - .dword 0 - /* version (u32, offset 32): Header 版本 (major << 16 | minor),当前 0.2 */ - .word 0x0002 - /* res1 (u32, offset 36): 保留 */ - .word 0 - /* res2 (u64, offset 40): 保留 */ - .dword 0 - /* magic (u64, offset 48): RISCV_IMAGE_MAGIC = "RISCV\0\0\0" (LE) */ - .dword 0x5643534952 - /* magic2 (u32, offset 56): RISCV_IMAGE_MAGIC2 = "RSC\x05" (LE) */ - .word 0x05435352 - /* res3 (u32, offset 60): 预留给 PE/COFF 偏移 (UEFI),目前填 0 */ - .word 0 -``` - -### 4.2 汇编函数签名 - -```cpp -// 定义于 arch/riscv/boot/entry.S -// _start 中的 `j real_start` 跳转目标,执行早期硬件初始化。 -void real_start() __attribute__((noreturn)); // 汇编实现,无 C++ 调用约定 - -// 定义于 arch/riscv/boot/entry.S 或 kernel/main.cc -// 仅由 CPU 0 调用,遍历 .init_array 执行全局构造函数。 -void early_cpp_init(); - -// 定义于 kernel/main.cc -// C++ 内核总入口。各 CPU 在开启 MMU 后汇聚于此。 -// 参数:cpu_id = 当前 CPU 编号,fdt_paddr = FDT 物理基址。 -void kernel_main(uint64 cpu_id, uint64 fdt_paddr) __attribute__((noreturn)); -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -此时 `Spinlock` 尚未初始化,必须使用汇编级的极简同步机制来避免多核访问冲突。 - -- **本模块持有的锁:** 无高级锁。 - -- **本模块可能获取的外部锁:** 无。 - -- **原子同步契约 (SMP Sync):** - - 1. 在 `.data` 段定义一个全局标志 `uint32 boot_sync_flag = 0;`。 - - 2. 只有 **CPU 0** (或 `a0` 读取到的第一个 CPU) 作为主核心 (BSP),获准执行 BSS 清零、早期页表填充等破坏性操作。 - - 3. **副核心 (AP, Application Processors)** 必须使用原子加载指令在汇编层盲等 `boot_sync_flag` 变为 1。具体实现为 `lw` + 循环比较(不需要 `amoswap`,因为只有 BSP 写入,AP 只读)。 - - 4. BSP 完成 `early_pgdir` 写入并唤醒 AP 前,必须执行 `fence rw, rw` 以保证所有先前的内存写入对其他 CPU 可见,随后使用 `fence.i` 刷新指令缓存(如有需要),最后将 `boot_sync_flag` 设为 1。 - - -## 6. 错误路径 (Error Paths) - -在早期的裸机启动阶段,内核没有任何错误恢复能力。 - -- **检测点:** 所有 CPU 在 `real_start` 入口处可选地检查 `misa` 或 `marchid` 判断基本硬件兼容性(如 64 位检查)。 - -- **失败行为:** 立即关闭本 CPU 的中断使能(`csrc sstatus, SSTATUS_SIE`),进入 `wfi` 死循环。无串口输出(此时 UART 尚未初始化)。 - -- **无回滚:** 早期启动无任何资源可回收,失败即死。 - - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -以下描述了从底层固件直到进入 `kernel_main` 的全流程: - -``` -[引导分流] - ├──> OpenSBI 裸启: 直接跳转到内存基址 (0x80200000) - │ └─ 命中 _start 处的第一条指令 `j real_start` - │ - └──> GRUB / U-Boot 引导: 解析位于 0x80200000 处的 64 字节 Header - ├─ 验证 magic ("RISCV\0\0\0") 与 magic2 ("RSC\x05") - ├─ 验证 text_offset - └─ 跳转到 0x80200000 (此时 a0=cpu_id, a1=fdt_paddr) - └─ 同样命中 _start 处的第一条指令 `j real_start` - - │ (汇聚点) - ▼ -[real_start] - │ - ├─> 1. 设置 gp 寄存器 (la gp, __global_pointer$) - │ // 极其关键:medany 模型下访问全局变量依赖此寄存器 - │ - ├─> 2. 设置早期内核栈 (la sp, boot_stack + (cpu_id + 1) * 8192) - │ - ├─> 3. 判断是否为主核心 (CPU 0)? - │ ├── [是 (BSP)] - │ │ ├─ 3.1 循环清理 BSS 段 (_sbss 至 _ebss 填 0) - │ │ ├─ 3.2 填充 early_pgdir (建立恒等映射与高半区映射) - │ │ ├─ 3.3 fence rw, rw (确保内存修改对其他 CPU 可见) - │ │ └─ 3.4 释放副核心 (boot_sync_flag = 1) - │ │ - │ └── [否 (AP)] - │ └─ 3.1 汇编级自旋等待,直到 boot_sync_flag == 1 - │ - ├─> 4. 高半区蹦床 (Higher-Half Trampoline - 所有 CPU 执行) - │ ├─ 4.1 将 early_pgdir 物理地址写入 satp 寄存器 (MODE=SV39) - │ ├─ 4.2 执行 sfence.vma 刷新 TLB - │ ├─ 4.3 计算 kernel_main 的高半区虚拟地址 - │ └─ 4.4 jr 绝对跳转至虚拟地址,彻底抛弃低位物理 PC - │ - ▼ -[进入虚拟世界: call early_cpp_init] (仅 BSP 执行) - │ - └─> 遍历 __init_array_start 到 __init_array_end - 依次调用全局构造函数,完成 C++ early runtime setup - │ - ▼ -[跳转至 C++ 逻辑: call kernel_main(a0, a1)] (所有 CPU 汇合) -``` \ No newline at end of file diff --git a/docs/specs/pmm.md b/docs/specs/pmm.md deleted file mode 100644 index 5703e7a..0000000 --- a/docs/specs/pmm.md +++ /dev/null @@ -1,209 +0,0 @@ -# 物理内存管理器 (Physical Memory Manager) - -## 1. 目标 (Objective) - -为 LumeOS 提供对物理内存页帧(Frame)的分配与回收服务。本模块基于伙伴系统(Buddy System)算法管理所有可用物理内存,并引入 Per-CPU 缓存(PCP)机制以降低多核场景下的锁竞争。PMM 是 Slab 分配器和 VMM 的底层基石。 - -## 2. 前置依赖 (Dependencies) - -- **全局初始化契约 (`global_init.md`):** `pmm_init()` 在 `fdt_init()` 之后、`slab_init()` 之前被 BSP 调用。 -- **设备树契约 (`fdt.md`):** 依赖 `fdt_early_get_mem_info()` 获取物理内存的基址和大小。 -- **并发同步契约 (`spinlock.md`):** 依赖 `Spinlock` 实现对全局伙伴系统的互斥访问。 -- **架构抽象契约 (`arch_abstraction.md`):** 依赖 `arch::cpu::id()` 获取当前 CPU 编号以访问 Per-CPU 缓存;依赖 `arch::cpu::intr_off()/intr_on()` 保护 PCP 操作免受中断重入。 -- **项目约定 (`00_conventions.md`):** 遵循所有命名、错误处理和 API 设计规范。 - -## 3. 核心数据结构 (Data Structures) - -### 3.1 物理页帧描述符 (`struct Frame`) - -为了极致地压缩元数据内存占用,`struct Frame` 采用 `union` 设计,并严格保证 `refcount` 独立于 `union` 之外,以支持 COW。 - -```cpp -// 定义于 include/lume/frame.h -#include -#include - -class KmemCache; // 前向声明 - -enum class FrameState : uint8 { - Free, // 空闲,位于 Buddy 或 PCP 链表中 - Allocated, // 已分配给上层(Slab, VMM) - Slab, // 作为 Slab 页使用 -}; - -struct Frame { - uint32 refcount; // 原子引用计数(独立于 union) - FrameState state; // 页帧当前状态 - uint8 order; // 伙伴系统中的阶数 (0-10 for 4KB-4MB) - - union { - // 当 state == FrameState::Free 时 - struct { - list_node free_link; // 用于挂载到 Buddy 或 PCP 的空闲链表 - } free; - - // 当 state == FrameState::Slab 时 - struct { - KmemCache* cache; // 指向所属的 Slab 缓存 - uint32 obj_count; // 已分配对象数量 - } slab; - }; -}; -``` - -### 3.2 Per-CPU 单页缓存 (`struct PerCpuCache`) - -每个 CPU 私有的单页帧空闲链表。**访问 PCP 时必须关闭中断**,防止定时器中断处理函数在同一 CPU 上重入 PCP 操作导致链表损坏。 - -```cpp -// 定义于 mm/pmm.cc (模块私有) -inline constexpr int kPcpHighWatermark = 64; // PCP 缓存上限 -inline constexpr int kPcpBatchSize = 32; // 每次 refill/drain 的批量大小 - -struct PerCpuCache { - list_node free_list; // 单页帧空闲链表头 - uint32 count; // 当前缓存的页帧数量 -}; -``` - -### 3.3 伙伴系统常量 - -```cpp -// 定义于 include/lume/pmm.h -inline constexpr int kMaxOrder = 11; // 阶数 0..10 → 4KB..4MB -``` - -## 4. 公共 API (Public APIs) - -所有分配函数在失败时返回 `nullptr`。 - -```cpp -// === 初始化 === -void pmm_init(); // BSP 调用,从 FDT 发现内存并初始化伙伴系统 - -// === 单页帧操作 (Fast Path via PCP) === -Frame* pmm_alloc_frame(); // 分配一个 4KB 页帧 -void pmm_free_frame(Frame* f); // 释放一个 4KB 页帧 - -// === 多页帧操作 (Slow Path, 直接伙伴系统) === -Frame* pmm_alloc_frames(uint8 order); // 分配 2^order 个连续页帧 -void pmm_free_frames(Frame* f, uint8 order); // 释放 2^order 个连续页帧 - -// === 引用计数操作 (原子, 无锁) === -void frame_incref(Frame* f); // 原子递增引用计数 -void frame_decref(Frame* f); // 原子递减,降至 0 时自动释放 - -// === 地址转换 === -uint64 frame_to_pa(const Frame* f); // Frame* → 物理地址 -Frame* pa_to_frame(uint64 pa); // 物理地址 → Frame* -uint64 frame_to_va(const Frame* f); // Frame* → 内核虚拟地址 -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -- **持有锁:** 模块内部持有一把 `Spinlock` (`g_pmm_lock`)。 - -- **锁的作用域:** `g_pmm_lock` **仅保护**全局伙伴系统 (`g_free_areas[]`)。 - -- **PCP 保护机制:** PCP 操作**必须在中断关闭状态下**执行。这不是"无锁"——而是通过关中断防止同一 CPU 上的重入(定时器中断 → IRQ handler → pmm_alloc_frame → 损坏 PCP 链表)。关中断由 `pmm_alloc_frame()`/`pmm_free_frame()` 内部自动管理。 - -- **加锁慢速路径:** - - 当 PCP 为空时,`refill_pcp()` 获取 `g_pmm_lock` 从伙伴系统批量取页。 - - 当 PCP 达到 `kPcpHighWatermark` 时,`drain_pcp()` 获取 `g_pmm_lock` 归还半数页帧。 - - `pmm_alloc_frames()` 和 `pmm_free_frames()` 因直接操作伙伴系统,**始终需要**获取 `g_pmm_lock`。 - -- **原子操作:** `frame_incref()` / `frame_decref()` 使用 `__atomic_fetch_add/sub` + `__ATOMIC_ACQ_REL`。 - -## 6. 错误路径 (Error Paths) - -- **初始化失败:** `pmm_init()` 若无法从 FDT 找到可用内存,或无法为 `frame_map` 分配空间,则 `kernel_panic()`。 - -- **分配失败:** `pmm_alloc_*()` 在物理内存耗尽时返回 `nullptr`。上层负责处理。 - -- **释放错误:** `pmm_free_*()` 若接收到 `nullptr`,立即 `kernel_panic()`。 - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -### 7.1 单页分配时序 (Fast & Slow Path) - -``` -[pmm_alloc_frame() on CPU X] - │ - ├─> 1. 关闭中断 (防止同 CPU 重入) - │ - ├─> 2. 获取 pcp = &g_pcp[cpu_id] - │ - ├─> 3. if (pcp->count > 0) ? - │ ├── [是 (Fast Path)] - │ │ ├─ 3.1 从 pcp->free_list 弹出一个 Frame - │ │ ├─ 3.2 设置 state=Allocated, refcount=1 - │ │ └─ 3.3 恢复中断, return Frame - │ │ - │ └── [否 (Slow Path)] - │ ├─ 4.1 LockGuard guard(g_pmm_lock); - │ ├─ 4.2 refill_pcp(pcp); // 批量从 Buddy 取 kPcpBatchSize 页 - │ ├─ 4.3 释放锁 - │ └─ 4.4 回到步骤 3 重试 - │ - ▼ -[恢复中断, 返回 Frame* 或 nullptr] -``` - -### 7.2 初始化时序 - -``` -[pmm_init() — BSP 单核期] - │ - ├─> 1. fdt_early_get_mem_info(&base, &size) - │ └─ 获取物理内存基址和大小 - │ - ├─> 2. 计算 frame_map 位置 (紧跟 _kernel_end 之后, 页对齐) - │ └─ frame_map 大小 = num_frames * sizeof(Frame) - │ - ├─> 3. 清零 frame_map - │ - ├─> 4. 初始化 Spinlock 和 Buddy 空闲链表头 - │ - ├─> 5. 初始化所有 PCP 链表头 - │ - └─> 6. 将所有空闲页帧 (frame_map 之后) 按最大对齐阶数插入 Buddy -``` - -### 7.3 写时复制 (COW) 引用计数流程 - -``` -[父进程 fork() 创建子进程] - │ - ├─> 1. 遍历父进程所有可写 VMA - │ - ├─> 2. for each VMA: - │ ├─ 2.1 复制父进程的 PTE 到子进程页表 - │ ├─ 2.2 清除父、子 PTE 的 'Write' 权限位 - │ ├─ 2.3 设置父、子 PTE 的 'COW' 软件标志位 - │ └─ 2.4 frame_incref(pa_to_frame(PTE->paddr)); - │ - ▼ -[子进程尝试写入共享页面] - │ - ├─> 1. 触发 Store Page Fault - │ - ├─> 2. VMM 陷阱处理: - │ ├─ 2.1 检查 PTE,确认是合法的 COW Fault - │ ├─ 2.2 old_frame = pa_to_frame(PTE->paddr) - │ ├─ 2.3 if (old_frame->refcount == 1) ? - │ │ ├── [是] 直接恢复 Write 权限,无需拷贝 - │ │ └── [否] 分配新页, 拷贝, 修改 PTE, frame_decref(old) - │ - ▼ -[返回用户态,写操作成功] -``` - -## 8. 已知缺陷与未来挑战 (Known Weaknesses & Future Challenges) - -### 8.1 内存回收 - -当前 API 在物理内存耗尽时仅返回 `nullptr`,缺乏主动回收机制。未来需引入内存回收器。 - -### 8.2 frame_map 存储 - -当前设计假设单一连续 `frame_map` 数组,适用于 QEMU 线性内存。对于多内存区域的真实硬件,需演进为稀疏内存模型。 diff --git a/docs/specs/slab.md b/docs/specs/slab.md deleted file mode 100644 index dc6953a..0000000 --- a/docs/specs/slab.md +++ /dev/null @@ -1,233 +0,0 @@ -# SLUB 分配器 (SLUB Allocator) - -## 1. 目标 (Objective) - -在物理内存管理器 (PMM) 之上,为内核提供高效的字节级内存分配器。采用 **SLUB** 设计(Simple List of Unfull Blocks),通过复用 PMM 的 `Frame` 描述符存储 per-page 元数据、将空闲链表嵌入对象体内、以及 Per-CPU 活跃页机制,实现低碎片、低锁竞争的小对象分配。本模块是内核 `operator new` 的直接后端。 - -**为何选择 SLUB 而非经典 Slab:** -- `Frame` 结构已包含 `cache` 指针和 `obj_count` 字段,无需额外的 per-page `struct Slab` 头部。 -- 省去 full/partial/empty 三链表管理,仅需一个 partial 链表。 -- Per-CPU 缓存仅需一个"当前活跃页"指针,无需动态分配对象数组(避免 slab_init 的鸡生蛋问题)。 -- Linux 自 2.6.23 起默认 SLUB,6.8 已完全移除经典 Slab。 - -## 2. 前置依赖 (Dependencies) - -- **全局初始化契约 (`global_init.md`):** `slab_init()` 在 `pmm_init()` 之后、`vmm_init()` 之前被 BSP 调用。 -- **物理内存契约 (`pmm.md`):** 依赖 `pmm_alloc_frame()` / `pmm_free_frame()` 以及 `Frame` 描述符中的 `slab.cache` 和 `slab.obj_count` 字段。还依赖 `pa_to_frame()` / `frame_to_pa()` 进行地址转换。 -- **并发同步契约 (`spinlock.md`):** 依赖 `Spinlock` 保护全局 partial 链表。 -- **架构抽象契约 (`arch_abstraction.md`):** 依赖 `arch::cpu::id()` 访问 Per-CPU 缓存;依赖 `arch::cpu::intr_off()/intr_on()` 保护 Per-CPU 操作免受中断重入。 -- **项目约定 (`00_conventions.md`):** 遵循所有命名和类型规范。 - -## 3. 核心数据结构 (Data Structures) - -### 3.1 空闲对象链表(嵌入式) - -空闲对象的前 `sizeof(void*)` 字节存储下一个空闲对象的指针。对象被分配后,该区域归用户使用。因此**最小对象尺寸 = `sizeof(void*)` = 8 字节**。 - -``` -[ Free Object ] [ Free Object ] [ Free Object ] -+-------------+ +-------------+ +-------------+ -| next ---------.------->| next ---------.------->| next = NULL | -| (unused) | | (unused) | | (unused) | -+-------------+ +-------------+ +-------------+ -``` - -### 3.2 Frame 描述符中的 Slab 元数据 - -复用 `include/lume/frame.h` 中已有的字段(无需新增结构体): - -```cpp -// 当 Frame.state == FrameState::Slab 时有效 -struct { - KmemCache* cache; // 此页属于哪个 KmemCache - uint32 obj_count; // 此页上已分配的对象数量 -} slab; -``` - -- 此外,需要在 `Frame` 的 `free` union 成员中增加一个 `void* freelist` 字段,或者直接将 freelist 头指针嵌入 union。为保持 Frame 结构简洁,**freelist 头指针存储在页面固定偏移处(页起始的前 8 字节)**,不侵入 Frame 结构。 - -**修正方案:** 在 `Frame` 的 `slab` union 成员中增加 `void* freelist` 字段: - -```cpp -struct { - KmemCache* cache; // 所属缓存 - uint32 obj_count; // 已分配对象数 - void* freelist; // 页内空闲对象链表头 -} slab; -``` - -### 3.3 Per-CPU 活跃页 - -每个 CPU 对每个 KmemCache 维护一个"当前活跃页"(cpu_slab)。分配时优先从此页的 freelist 弹出对象,无需获取全局锁。 - -```cpp -// 定义于 mm/slab.h (模块私有) -struct PerCpuSlab { - Frame* active; // 当前 CPU 正在使用的 slab 页(可能为 nullptr) -}; -``` - -### 3.4 内核内存缓存 (`class KmemCache`) - -```cpp -// 定义于 mm/slab.h -class KmemCache { -public: - KmemCache() = default; - void init(const char* name, uint32 obj_size, uint32 obj_align); - - void* alloc(); - void free(void* obj); - -private: - Frame* get_partial(); // 从 partial 链表取一个页 - void put_partial(Frame* f); // 将页放入 partial 链表 - Frame* new_slab(); // 从 PMM 申请新页并格式化 - - Spinlock lock_; // 保护 partial 链表 - list_node partial_; // 部分填充的 slab 页链表 - - PerCpuSlab cpu_slab_[kMaxCPUs]; // Per-CPU 活跃页 - - const char* name_ = "uninit"; - uint32 obj_size_ = 0; // 对齐后的对象尺寸 - uint32 obj_align_ = 0; // 对齐要求 - uint32 objs_per_slab_ = 0; // 每页可容纳的对象数 -}; -``` - -### 3.5 通用尺寸缓存 - -```cpp -// 预创建的 2^N 尺寸缓存: 8, 16, 32, 64, 128, 256, 512, 1024, 2048 -inline constexpr int kNumSizeClasses = 9; -inline constexpr uint32 kSizeClasses[kNumSizeClasses] = { - 8, 16, 32, 64, 128, 256, 512, 1024, 2048 -}; - -extern KmemCache g_size_caches[kNumSizeClasses]; -``` - -## 4. 公共 API (Public APIs) - -```cpp -// === 初始化 === -void slab_init(); // 初始化所有通用尺寸缓存 - -// === 对象缓存 API === -void kmem_cache_init(KmemCache* cache, const char* name, - uint32 size, uint32 align); -void* kmem_cache_alloc(KmemCache* cache); -void kmem_cache_free(KmemCache* cache, void* obj); - -// === 通用分配 API === -void* kmalloc(uint32 size); // 自动选择尺寸缓存 -void kfree(void* ptr); // 通过 Frame 反查 cache,自动归还 - -// === C++ Runtime === -void* operator new(size_t size); -void* operator new[](size_t size); -void operator delete(void* ptr) noexcept; -void operator delete[](void* ptr) noexcept; -void operator delete(void* ptr, size_t) noexcept; -void operator delete[](void* ptr, size_t) noexcept; -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -- **持有锁:** 每个 `KmemCache` 持有一把 `Spinlock lock_`。 - -- **锁的作用域:** `lock_` **仅保护** `partial_` 链表。 - -- **Per-CPU 保护:** 访问 `cpu_slab_[cpu_id]` 时必须关闭中断(同 PMM 的 PCP 策略),防止中断重入。 - -- **快速路径(关中断,无锁):** 从当前 CPU 的 `active` 页的 `freelist` 弹出/压入对象。 - -- **慢速路径(需要锁):** - - alloc:当 `active` 页无空闲对象时,获取 `lock_` 从 `partial_` 取页(或调用 PMM 新建)。 - - free:当归还对象使一个页变为完全空闲时,获取 `lock_` 归还 PMM。 - -- **与 PMM 交互:** `new_slab()` 调用 `pmm_alloc_frame()` 时**不持有** `lock_`(先释放锁,申请页,再获取锁挂入链表),避免 Slab lock → PMM lock 嵌套。 - -## 6. 错误路径 (Error Paths) - -- **初始化失败:** `slab_init()` 若 PMM 无法提供页面,`kernel_panic()`。 - -- **分配失败:** `kmalloc()` / `kmem_cache_alloc()` 在 OOM 时返回 `nullptr`。 - -- **释放错误:** `kfree(nullptr)` 为 no-op。传入非法指针(不属于任何 slab 页)时 `kernel_panic()`。 - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -### 7.1 `kmem_cache_alloc` 时序 - -``` -[kmem_cache_alloc(cache) on CPU X] - │ - ├─> 1. 关中断 - ├─> 2. active = cache->cpu_slab_[X].active - │ - ├─> 3. if (active && active->slab.freelist != NULL) ? - │ ├── [是 (Fast Path)] - │ │ ├─ obj = active->slab.freelist - │ │ ├─ active->slab.freelist = *(void**)obj - │ │ ├─ active->slab.obj_count++ - │ │ ├─ 恢复中断 - │ │ └─ return obj - │ │ - │ └── [否 (Slow Path)] - │ ├─ 4.1 将 active (若满) 从 cpu_slab 移出 - │ ├─ (满页不需要跟踪,但其 Frame 中 cache 指针仍有效) - │ ├─ 4.2 恢复中断 - │ ├─ 4.3 LockGuard guard(cache->lock_) - │ ├─ 4.4 new_active = get_partial() // 从 partial 链表取 - │ │ └─ 若无,释放锁 → new_slab() → 重新获取锁 - │ ├─ 4.5 释放锁 - │ ├─ 4.6 关中断 - │ ├─ 4.7 cache->cpu_slab_[X].active = new_active - │ ├─ 4.8 从 new_active->slab.freelist 弹出 obj - │ ├─ 4.9 恢复中断 - │ └─ return obj - │ - ▼ -[返回 obj* 或 nullptr] -``` - -### 7.2 `kfree` 时序 - -``` -[kfree(ptr)] - │ - ├─> 1. pa = ptr 的物理地址 (对于 identity/higher-half,减去偏移) - ├─> 2. frame = pa_to_frame(pa & ~(kPageSize-1)) - ├─> 3. cache = frame->slab.cache - │ - ├─> 4. 关中断 - ├─> 5. 将 obj 压入 frame->slab.freelist - ├─> 6. frame->slab.obj_count-- - │ - ├─> 7. if (obj_count == 0) ? - │ ├── [是:页完全空闲] - │ │ ├─ 若此页是当前 CPU 的 active,清除 active - │ │ ├─ 恢复中断 - │ │ ├─ LockGuard: 从 partial_ 链表移除 (如果在链表中) - │ │ └─ pmm_free_frame(frame) // 归还 PMM - │ │ - │ └── [否] - │ ├─ 若此页不是任何 CPU 的 active 且不在 partial, - │ │ 则需获取锁放入 partial (满→部分满的过渡) - │ └─ 恢复中断 - │ - ▼ -[完成] -``` - -## 8. 已知缺陷与未来挑战 - -### 8.1 缓存收缩 - -当前不主动收缩 partial 链表。未来可增加 `kmem_cache_shrink()` 供内存回收线程调用。 - -### 8.2 大对象分配 - -大于 2048 字节的分配直接退化为 `pmm_alloc_frames()`。当前由 `kmalloc` 透明处理。 diff --git a/docs/specs/spinlock.md b/docs/specs/spinlock.md deleted file mode 100644 index b5dd92b..0000000 --- a/docs/specs/spinlock.md +++ /dev/null @@ -1,204 +0,0 @@ -# 自旋锁与并发同步 (Spinlock & Synchronization) - -## 1. 目标 (Objective) - -为 LumeOS 提供多核环境下的底层互斥机制。本模块实现基于原子操作的自旋锁(Spinlock)和基于 RAII 范式的局部锁守卫(LockGuard)。同时,严格定义锁操作前后的硬件中断屏蔽策略(避免单核中断死锁)以及底层内存序保证(Memory Ordering)。 - -## 2. 前置依赖 (Dependencies) - -- **全局类型契约:** `include/lume/types.h`。 - -- **架构原语契约:** 依赖 `arch_abstraction.md` 中的 `arch::cpu::id()`, `arch::cpu::intr_on()`, `arch::cpu::intr_off()`, `arch::cpu::intr_enabled()`。 - -- **Panic 机制:** 依赖底层的内核崩溃函数 `kernel_panic(const char* msg)`。 - -- **全局初始化契约:** `g_cpu_sync_states[]` 为 BSS 段全局数组,由 `entry.S` 的 BSS 清零保证初始值为零。`Spinlock` 作为全局对象时,必须通过 `init()` 方法显式初始化(参见 `global_init.md`),不得依赖构造函数。 - - -## 3. 核心数据结构 (Data Structures) - -### 3.1 CPU 中断嵌套跟踪器 - -为了支持锁的嵌套(如持有 `A` 锁时去获取 `B` 锁),必须在每 CPU 维度跟踪锁的深度,确保只有释放**最后一把锁**时,才恢复真实的中断状态。 - -```cpp -// 定义于 kernel/sync/cpu_state.h -namespace sync { - struct CpuSyncState { - int lock_depth; // 当前 CPU 持有的自旋锁数量 (嵌套深度) - bool intr_was_on; // 在获取第一把锁之前,中断是否处于开启状态 - }; - // BSS 段全局数组,由 entry.S 清零初始化 - inline constexpr uint64 kInvalidCpuId = ~0ULL; - extern CpuSyncState g_cpu_sync_states[kMaxCPUs]; -} -``` - -### 3.2 自旋锁类 (`Spinlock`) - -```cpp -// 定义于 kernel/sync/spinlock.h -class Spinlock { -public: - // 默认构造:locked_ = 0, name_ = "uninit", cpu_id_ = kInvalidCpuId - // 全局 Spinlock 在 BSS 清零后通过 init() 显式初始化 - Spinlock() = default; - - // 显式初始化(用于全局对象或 Placement New 场景) - void init(const char* name); - - // 禁用拷贝与移动 (锁对象具有固定的内存地址身份) - Spinlock(const Spinlock&) = delete; - Spinlock& operator=(const Spinlock&) = delete; - - void acquire(); - void release(); - bool is_held_by_current_cpu() const; - -private: - uint32 locked_ = 0; // 锁状态:0=空闲, 1=占用 - const char* name_ = "uninit"; // 锁名称 (用于 Panic 输出) - uint64 cpu_id_ = sync::kInvalidCpuId; // 持有者 CPU 编号 -}; -``` - -### 3.3 RAII 锁守卫 (`LockGuard`) - -```cpp -// 定义于 kernel/sync/spinlock.h -class LockGuard { -public: - explicit LockGuard(Spinlock& lock) : lock_(lock) { - lock_.acquire(); - } - - ~LockGuard() { - lock_.release(); - } - - // 禁用拷贝与移动 - LockGuard(const LockGuard&) = delete; - LockGuard& operator=(const LockGuard&) = delete; - -private: - Spinlock& lock_; -}; -``` - -## 4. 公共 API 与中断管理协议 (Public APIs) - -### 4.1 中断压栈/出栈协议 (Internal API) - -**这是 Spinlock 安全性的核心。** 必须在 `Spinlock::acquire()` 和 `release()` 内部隐式调用,严禁外部业务层手动调用。它实现了 `_irqsave` / `_irqrestore` 的语义。 - -```cpp -namespace sync { - /** - * @brief 保存当前中断状态、关闭中断,并增加锁嵌套深度。 - * - * 如果是获取第一把锁 (lock_depth 从 0 变 1),则将当前的中断使能状态 - * (sstatus.SIE) 保存到 per-cpu 的 intr_was_on 字段中。 - * 随后,无论何种情况,都关闭中断。 - */ - void push_intr_save(); - - /** - * @brief 减少锁嵌套深度,并在释放最后一层锁时恢复之前的中断状态。 - * - * 如果锁嵌套深度降为 0,则检查 intr_was_on 字段。只有当获取第一把锁 - * 之前中断是开启的时候,才重新开启中断。 - */ - void pop_intr_restore(); -} -``` - -### 4.2 锁语义约定 - -本模块属于内核生命线,发生任何违反并发契约的行为(如重复加锁、越权解锁)均属于致命代码逻辑错误。 **此类函数无返回值,一旦检测到契约被破坏,直接触发 `kernel_panic()` 宕机。** - -## 5. 并发与锁契约 (Concurrency & Locks) - -### 5.1 内存序保证 (Memory Order Guarantee) - -为了确保临界区内的读写操作不会被编译器或 CPU 的乱序执行(Out-of-Order Execution)重排到临界区外,必须使用带有内存屏障语义的原子操作。 - -- **Acquire 语义:** `Spinlock::acquire()` 内部的原子交换必须使用 `__ATOMIC_ACQUIRE`。在 RISC-V 层面,这将生成带有 `.aq` (Acquire) 后缀的原子指令(如 `amoswap.w.aq`),确保锁获取之后的任何内存读写,都不会被重排到拿锁之前。 - -- **Release 语义:** `Spinlock::release()` 内部的原子写零必须使用 `__ATOMIC_RELEASE`。使用 `__atomic_store_n(&locked_, 0, __ATOMIC_RELEASE)`,在 RISC-V 层面生成 `fence rw, w` + `sw`。注意:release 不需要原子 RMW 指令(`amoswap`),普通的 release-store 即可——因为此时本 CPU 已经是唯一的锁持有者,不存在竞争写。 - -### 5.2 自旋优化 (TTAS: Test-and-Test-and-Set) - -朴素的 `while(__atomic_exchange_n(...))` 会在每次迭代都发出总线级原子操作,导致缓存一致性协议风暴。必须使用 TTAS 模式: - -```cpp -void Spinlock::acquire() { - sync::push_intr(); - // 外层:非原子读,利用本地缓存副本空转,不产生总线流量 - while (true) { - while (__atomic_load_n(&locked_, __ATOMIC_RELAXED)) - ; // 在 L1 cache 上旋转,等待释放信号via cache invalidation - // 内层:看到可能空闲,才发起真正的原子交换 - if (__atomic_exchange_n(&locked_, 1, __ATOMIC_ACQUIRE) == 0) - break; // 成功获取 - } - cpu_id_ = arch::cpu::id(); -} -``` - -### 5.3 业务层使用契约 (Caller Contract) - -1. **禁止睡眠:** 在持有 `Spinlock`(或处于 `LockGuard` 作用域内)的任何期间,**绝对禁止**调用可能导致当前 Task 休眠或主动放弃 CPU 的函数(如 `sleep()`, `yield()`, 或由于分配内存触发了等待)。 - -2. **优先 RAII:** 常规业务逻辑中应通过 `LockGuard` 对象管理锁的生命周期,利用 C++ 析构确保锁在异常或提前 return 时必定释放。`acquire()/release()` 公开暴露仅供**调度器内部**等必须跨函数边界持有锁的特殊场景使用(如 `sleep()` 中释放锁 + 上下文切换 + 醒来后重新获取)。 - -3. **锁序遵守:** 嵌套获取多把 Spinlock 时,必须严格遵循全局锁序 DAG(将在 Phase 2 完成后汇总为 `lock_ordering.md`)。任何违反锁序的代码在 Code Review 中必须被驳回。 - - -## 6. 错误路径与 Panic 触发点 (Error Paths) - -在以下情况下,自旋锁必须立即执行 `kernel_panic()` 阻断系统: - -1. **死锁防御 (Double Lock):** 在 `acquire()` 中,调用 `push_intr()` 关中断后、原子操作前,检查 `is_held_by_current_cpu()`。若为 `true`,说明当前 CPU 试图获取自己持有的锁,必然死锁,立即 Panic。打印锁名称与 CPU ID。 - -2. **越权释放 (Invalid Release):** 在 `release()` 中,若 `is_held_by_current_cpu()` 为 `false`,说明代码逻辑严重错乱(锁未被持有、或被其他 CPU 持有),立即 Panic。 - -3. **中断状态校验:** 在 `acquire()` 入口(`push_intr()` 之前),若中断已被开启但 `lock_depth > 0`,说明存在中断状态泄漏(某处代码在持有锁的同时非法开启了中断),可选 Panic。此检查在 `#ifdef DEBUG` 下启用以避免正式构建的性能损失。 - - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -### 7.1 Spinlock Acquire / Release 硬件级时序 - -``` -[当前 CPU (CPU X) 请求 LockGuard] - │ - ├─> 1. push_intr() - │ ├─ 读取当前中断状态: was_on = arch::cpu::intr_enabled() - │ ├─ 关中断: arch::cpu::intr_off() - │ └─ if (lock_depth == 0) intr_was_on = was_on; lock_depth++ - │ - ├─> 2. 断言: is_held_by_current_cpu() == false (否则 Panic: double lock) - │ - ├─> 3. TTAS 自旋获取 - │ ├─ 外层 while: __atomic_load_n(&locked_, RELAXED) 非原子读空转 - │ └─ 内层 CAS: __atomic_exchange_n(&locked_, 1, ACQUIRE) == 0 → 成功 - │ - ├─> 4. 记录属主: cpu_id_ = arch::cpu::id() - │ - ▼ -[执行临界区 C++ 业务逻辑 (关中断、无休眠)] - │ - ▼ -[LockGuard 析构,触发 release()] - │ - ├─> 1. 断言: is_held_by_current_cpu() == true (否则 Panic: invalid release) - │ - ├─> 2. 擦除属主: cpu_id_ = kInvalidCpuId - │ - ├─> 3. __atomic_store_n(&locked_, 0, __ATOMIC_RELEASE) - │ └─ RISC-V: fence rw, w + sw zero → 临界区写入全局可见后才释放锁 - │ - └─> 4. pop_intr() - ├─ lock_depth-- - └─ if (depth == 0 && intr_was_on) arch::cpu::intr_on() -``` \ No newline at end of file diff --git a/docs/specs/testing_and_ci.md b/docs/specs/testing_and_ci.md deleted file mode 100644 index 9d869d8..0000000 --- a/docs/specs/testing_and_ci.md +++ /dev/null @@ -1,83 +0,0 @@ -# 测试与持续集成 (Testing & CI) - -## 1. 目标 (Objective) - -为 LumeOS 项目定义自底向上的自动化测试标准与持续集成(CI)规范。通过建立在系统早期启动阶段驻留执行的 Boot Self-Test(KUnit)框架,严格确保内存管理、调度器、同步原语等底层基础设施无隐患。配合 `make test` Makefile 目标以及退出码(Exit Code)规范,构筑防止代码腐化的防线。 - -## 2. 前置依赖 (Dependencies) - -- **全局类型契约:** `include/lume/types.h`。 -- **输出机制:** 早期格式化输出需求依赖 `early_puts` 和 `early_putc` 等纯串口驱动原语。 -- **宕机机制:** 依赖 `include/lume/panic.h` 定义的 `kernel_panic` 用于对测试失败执行终端处决。 -- **QEMU CI 环境:** 自动化截取退出码依赖硬件特性的 `sifive_test` 接口(通过 OpenSBI 提供 System Reset/Poweroff 的底层能力)。 - -## 3. 核心机制设计 - -为了不侵入或依赖过于复杂的上下文结构,测试系统在操作系统生命周期的“最初始安全阶段”进行: -- **执行点:** 位于 `kernel_main()` 核心初始化逻辑收尾后(所有关键数据结构已分配完毕),但在多核被唤醒(AP 启动)以及用户态进程加载之前。 -- **单核无中断:** 测试套件固定且绝对运行于 BSP (CPU 0) 的单核互斥环境中。在这些断言执行时,硬件中断是被严格关闭的。 - -## 4. KUnit 宏签名与接口规范 (Public APIs) - -在 `include/lume/selftest.h` 中对外暴露以下断言宏。所有测试文件的断言仅允许使用下述原语: - -### 4.1 核心断言宏 - -所有断言宏若验证通过通常无反馈,一旦发现断言失败即发生 `Panic` 导致系统停机。 - -```cpp -// 最基础的条件真实性断言 -#define ST_ASSERT(cond) - -// 验证两个数值、指针或枚举绝对相等的断言 -// 失败时会自动将变量与地址分别序列化输出以协助排查 -#define ST_ASSERT_EQ(a, b) - -// 验证两个量绝对不相等的断言 -#define ST_ASSERT_NE(a, b) -``` - -### 4.2 控制与排版原语 - -```cpp -// 在每个用例的前置输出 `[test] ... ` -void st_begin(const char* name); - -// 在用例顺利通过后输出 `PASS` 并换行 -void st_pass(); - -// C++ 自检主函数,由各个测试子模块(如 test_pmm.cc)自行声明填充。 -// 必须注册到 kernel_main 中调用的 `selftest_run_all()` 总表中。 -void selftest_xxx(); -``` - -## 5. Panic 退出码与 QEMU CI 自动退出 (Exit Codes) - -为了让 GitHub Actions 或者外部自动化测试流水线有效地判决 LumeOS 是否正确运行,我们需要与 QEMU 沟通,而不是靠正则表达式提取输出文字。 - -### 5.1 失败与宕机 (Panic) - -当某个 `ST_ASSERT` 失效时: -1. `kernel_panic("selftest failed", detail);` 触发。 -2. 串口向屏幕喷出宕机回溯(行号与文件名)。 -3. **调用 SBI 接口终止运行:**内核使用 OpenSBI (EID `0x53525354` System Reset Extension),发起 System Failure 指令并传送特定的退出码(例如 Exit Code 127)。 - -### 5.2 成功退出校验 - -当所有的 `selftest` 在 `make test` 命令中走通并通过所有的断言验证时: -1. 输出 `All self-tests PASSED`。 -2. 不会进入系统的死循环(挂机状态)。 -3. 核发送带有 Exit Code 0 的 SBI 成功关机请求,使得宿主机的 `make test` 返回码为成功,绿灯放行 CI 。 - -## 6. `make test` 规范 (Make Target) - -`make test` 须作为一个专职的自动化冒烟测试管道: - -- `make test` 将编译特制的测试版本(例如自动注册带有 CI 自动关机行为的 Flag )。 -- **屏蔽图形学延误:** 测试应当在 Makefile 使用 `-nographic` 的纯无头界面(Headless)运行 QEMU。 -- **无等待结束:** QEMU 只要执行测试程序,系统即可在极短时间内得到退出码反馈结果,不会陷入一直等待。 -- **集成于构建流:** `make fmt && make lint && make test` 是提交到 Main 分支之前在开发者本地应当成为默认习惯的行为指令链。 - -## 7. 错误路径 (Error Paths) - -因为其测试属性:只要未跑通,便进入灾难模式(Panic)。此时不考虑优雅释放任何当前持有的锁,亦不关闭或清理页表,而是立刻抛血书以保护现场,等待开发者进行后续 GDB 对照排查。 diff --git a/docs/specs/vmm.md b/docs/specs/vmm.md deleted file mode 100644 index 7492a02..0000000 --- a/docs/specs/vmm.md +++ /dev/null @@ -1,158 +0,0 @@ -# 虚拟内存管理器 (Virtual Memory Manager) - -## 1. 目标 (Objective) - -为 LumeOS 管理虚拟地址空间。本模块分两个阶段实现: - -- **Phase 1(本文档重点):** - 1. 在 `vmm_init()` 中建立精细化的内核页表(4KB 粒度、精确权限)。 - 2. 实现基于 Rbtree 和 Slab 的 VMA (Virtual Memory Area) 区间树以管理用户态内存。 - 3. 实现架构无关的按需分页 (Demand Paging) 模拟接口。 -- **Phase 2(未来):** 将 VMM 的按需分页逻辑绑定到真实的 Trap 异常中断系统,并引入进程 (Process/Task) 关联和基于硬件触发的缺页异常处理。 - -采用 pmap(Physical Map)分层模型:MI 层管理地址空间布局逻辑,MD 层(`arch/riscv/mm/pmap.cc`)封装 SV39 页表硬件操作。 - -## 2. 前置依赖 (Dependencies) - -- **全局初始化契约 (`global_init.md`):** `vmm_init()` 在 `slab_init()` 和 `fdt_unflatten()` 之后、`trap_init()` 之前被 BSP 调用。 -- **物理内存契约 (`pmm.md`):** 依赖 `pmm_alloc_frame()` 分配页表页。 -- **Slab 分配器契约 (`slab.md`):** Phase 2 依赖 `kmalloc` 创建 VMA 对象。 -- **架构抽象契约 (`arch_abstraction.md`):** 依赖 `arch::mmu::set_page_table()`, `arch::mmu::flush_tlb_all()` 切换和刷新页表。 -- **链接脚本契约 (`linker_and_entry.md`):** 依赖 `_stext/_etext`, `_srodata/_erodata`, `_sdata/_edata`, `_sbss/_ebss`, `_kernel_end` 确定各段边界。 - -## 3. 核心数据结构 (Data Structures) - -### 3.1 SV39 页表项 (PTE) 格式 - -``` -63 54 53 28 27 19 18 10 9 8 7 6 5 4 3 2 1 0 -+---------+----------+----------+----------+----+-+-+-+-+-+-+-+-+ -| Reserved| PPN[2] | PPN[1] | PPN[0] |RSW |D|A|G|U|X|W|R|V| -| (10) | (26) | (9) | (9) |(2) |1|1|1|1|1|1|1|1| -+---------+----------+----------+----------+----+-+-+-+-+-+-+-+-+ -``` - -权限位常量: - -```cpp -namespace pmap { - inline constexpr uint64 PTE_V = 1 << 0; // Valid - inline constexpr uint64 PTE_R = 1 << 1; // Read - inline constexpr uint64 PTE_W = 1 << 2; // Write - inline constexpr uint64 PTE_X = 1 << 3; // Execute - inline constexpr uint64 PTE_U = 1 << 4; // User-accessible - inline constexpr uint64 PTE_G = 1 << 5; // Global - inline constexpr uint64 PTE_A = 1 << 6; // Accessed - inline constexpr uint64 PTE_D = 1 << 7; // Dirty -} -``` - -### 3.2 pmap 接口 (MD 层, namespace 函数) - -遵循 `00_conventions.md` 的多态策略——pmap 为极热路径,使用 namespace 函数 + 编译期链接。 - -```cpp -// 定义于 arch/riscv/mm/pmap.h (arch 私有头) 和 mm/pmap.h (MI 接口) -namespace pmap { - // 分配并初始化一个新的根页表,返回其物理地址。 - // 失败返回 0。 - uint64 create(); - - // 销毁一个页表及其所有子页表页。 - void destroy(uint64 root_pa); - - // 建立映射:va -> pa,权限为 perm。 - // 自动分配中间页表页。 - // 返回 0 成功,负错误码失败。 - int map(uint64 root_pa, uint64 va, uint64 pa, uint64 perm); - - // 解除 va 处的映射。 - void unmap(uint64 root_pa, uint64 va); - - // 查询 va 对应的 pa。成功返回 true 并写入 *pa_out。 - bool lookup(uint64 root_pa, uint64 va, uint64* pa_out); - - // 将 root_pa 写入 satp 并刷新 TLB。 - void activate(uint64 root_pa); -} -``` - -### 3.3 内核地址空间布局 - -`vmm_init()` 建立的精细内核映射: - -``` -Virtual Address Physical Address Perm Description -───────────────────────────────────────────────────────────────────── -arch::kVAOffset + 0x80200000 0x80200000 R-X .text (代码段) -arch::kVAOffset + _srodata _srodata_pa R-- .rodata (只读数据) -arch::kVAOffset + _sdata _sdata_pa RW- .data + .bss -arch::kVAOffset + frame_map_pa frame_map_pa RW- PMM frame_map 数组 -arch::kVAOffset + 0x10000000 0x10000000 RW- UART MMIO -arch::kVAOffset + 0x0C000000 0x0C000000 RW- PLIC MMIO -arch::kVAOffset + mem_end ... RW- 剩余物理内存 (到 mem_end) -``` - -## 4. 公共 API (Public APIs) - -### 4.1 Phase 1 API - -```cpp -// 初始化内核页表,替代 early_pgdir。 -// 1. 分配新根页表 -// 2. 按段权限映射内核各段 -// 3. 映射 MMIO 区域 -// 4. 激活新页表 -// 5. 旧的 early_pgdir 恒等映射自动失效 -void vmm_init(); - -// AP 切换到 BSP 建好的内核页表 -void vmm_init_ap(); -``` - -### 4.2 Phase 2 API (未来) - -```cpp -// 暂为 stub,Phase 2 实现 -int vmm_map_user(uint64 root_pa, uint64 va, uint64 len, uint64 perm); -int vmm_unmap_user(uint64 root_pa, uint64 va, uint64 len); -int vmm_handle_page_fault(uint64 root_pa, uint64 fault_addr, uint64 cause); -uint64 vmm_clone(uint64 parent_root_pa); -``` - -## 5. 并发与锁契约 (Concurrency & Locks) - -- **Phase 1:** `vmm_init()` 在 BSP 单核期执行,无需锁。 -- **pmap 锁:** 每个根页表关联一把 Spinlock(Phase 2 在 AddressSpace 结构中)。多核操作同一页表必须持有此锁。 -- **TLB Shootdown:** Phase 1 仅有内核页表且在单核期建立,无需 shootdown。Phase 2 需实现。 - -## 6. 错误路径 (Error Paths) - -- `pmap::create()` 或 `pmap::map()` 中 `pmm_alloc_frame()` 失败 → `kernel_panic()`(内核页表映射失败不可恢复)。 -- `vmm_init()` 中任何映射步骤失败 → `kernel_panic()`。 - -## 7. 状态机 / 时序图 (State Machine / Sequence) - -### 7.1 vmm_init 时序 - -``` -[kernel_main on BSP, after slab_init + fdt_unflatten] - │ - ├─> 1. root_pa = pmap::create() // 分配新根页表 - │ - ├─> 2. 映射内核 .text 段 (RX) - │ for (pa = _stext_pa; pa < _etext_pa; pa += PAGE_SIZE) - │ pmap::map(root_pa, pa + arch::kVAOffset, pa, PTE_R|PTE_X|PTE_G) - │ - ├─> 3. 映射 .rodata 段 (R-) - ├─> 4. 映射 .data + .bss 段 (RW) - ├─> 5. 映射 frame_map 区域 (RW) - ├─> 6. 映射剩余物理内存 (RW) - ├─> 7. 映射 MMIO: UART 0x10000000, PLIC 0x0C000000 (RW) - │ - ├─> 8. pmap::activate(root_pa) // 写 satp, sfence.vma - │ └─ 此刻 early_pgdir 的恒等映射失效 - │ └─ 代码继续执行(因为高半区映射已建立) - │ - └─> 9. 保存 root_pa 到全局变量 g_kernel_pgtbl -``` diff --git a/drivers/Build.mk b/drivers/Build.mk deleted file mode 100644 index 342f02b..0000000 --- a/drivers/Build.mk +++ /dev/null @@ -1,17 +0,0 @@ -targets += drivers/base drivers/tty drivers/core -target.drivers/base.kind := source-set -target.drivers/base.sources := \ - drivers/base/bus.cc drivers/base/core.cc drivers/base/driver.cc \ - drivers/base/platform.cc - -target.drivers/tty.kind := source-set -target.drivers/tty.sources := \ - drivers/tty/tty_core.cc drivers/tty/n_tty.cc drivers/tty/tty_uart.cc - -target.drivers/core.kind := source-set -target.drivers/core.deps := drivers/base drivers/tty -target.drivers/core.sources := drivers/uart.cc drivers/console.cc -ifeq ($(ARCH),riscv) -target.drivers/core.sources += drivers/plic.cc -endif - diff --git a/drivers/base/bus.cc b/drivers/base/bus.cc deleted file mode 100644 index 975f676..0000000 --- a/drivers/base/bus.cc +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * drivers/base/bus.cc — bus_type registration. - * - * Mirrors Linux drivers/base/bus.c. Trivial in this iteration: - * initialize the device/driver lists and the per-bus spinlock. - * - * Reference: docs/specs/storage_stack.md §4.3 - */ - -#include -#include -#include -#include - -int bus_register(bus_type* bus) -{ - if (bus == nullptr || bus->name == nullptr) { - return -EINVAL; - } - if (bus->registered) { - return 0; - } - bus->devices.init(); - bus->drivers.init(); - bus->lock.init(bus->name); - bus->registered = true; - kprintf("[bus] '%s' registered\n", bus->name); - return 0; -} diff --git a/drivers/base/core.cc b/drivers/base/core.cc deleted file mode 100644 index f92b2a4..0000000 --- a/drivers/base/core.cc +++ /dev/null @@ -1,156 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * drivers/base/core.cc — device core. - * - * Mirrors Linux drivers/base/core.c (greatly simplified). Provides - * device_initialize, device_register, device_unregister, and the - * try_bind helper shared with driver registration. - * - * Reference: docs/specs/storage_stack.md §4.3 - */ - -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* device ktype — generic release (no-op; subclasses override) */ -/* ------------------------------------------------------------------ */ - -static void device_release(kobject* kobj) -{ - /* Concrete device flavors (platform_device, virtio_device, ...) are - * expected to allocate via kmalloc and free in their own release - * paths after device_unregister + final kobject_put. The generic - * device kobj_type only fires for stack-allocated devices used in - * tests — nothing to do. */ - (void)kobj; -} - -static const kobj_type device_ktype = { - .release = device_release, -}; - -/* ------------------------------------------------------------------ */ -/* device_initialize / device_register */ -/* ------------------------------------------------------------------ */ - -void device_initialize(device* dev) -{ - if (dev == nullptr) { - return; - } - kobject_init(&dev->kobj, &device_ktype); - dev->parent = nullptr; - dev->driver = nullptr; - dev->driver_data = nullptr; - dev->platform_data = nullptr; - dev->devt = 0; - dev->bus_list.init(); - dev->driver_list.init(); -} - -const char* dev_name(const device* dev) -{ - if (dev == nullptr) { - return "(null)"; - } - if (dev->kobj.name != nullptr) { - return dev->kobj.name; - } - if (dev->init_name != nullptr) { - return dev->init_name; - } - return "(unnamed)"; -} - -/* try_bind: attempt to match `dev` against `drv` and probe. - * Returns 1 on successful bind, 0 otherwise. - * Caller must hold bus->lock. */ -int device_try_bind(device* dev, device_driver* drv); - -int device_try_bind(device* dev, device_driver* drv) -{ - bus_type* bus = dev->bus; - - if (bus->match != nullptr && bus->match(dev, drv) == 0) { - return 0; - } - - dev->driver = drv; - - int rc = 0; - if (bus->probe != nullptr) { - rc = bus->probe(dev); - } else if (drv->probe != nullptr) { - rc = drv->probe(dev); - } - - if (rc == 0) { - list_add_tail(&dev->driver_list, &drv->devices); - return 1; - } - dev->driver = nullptr; - return 0; -} - -int device_register(device* dev) -{ - if (dev == nullptr || dev->bus == nullptr) { - return -EINVAL; - } - if (!dev->bus->registered) { - kprintf("[device] register '%s' fail: bus '%s' not registered\n", - dev_name(dev), - dev->bus->name != nullptr ? dev->bus->name : "?"); - return -ENODEV; - } - - /* device_initialize is idempotent — safe to call again, but most - * paths will already have initialized. Detect via ktype set. */ - if (dev->kobj.ktype == nullptr) { - device_initialize(dev); - } - if (dev->kobj.name == nullptr) { - kobject_add(&dev->kobj, nullptr, dev->init_name); - } - dev->bus_list.init(); - dev->driver_list.init(); - - LockGuard g(dev->bus->lock); - list_add_tail(&dev->bus_list, &dev->bus->devices); - - list_node* cur = dev->bus->drivers.next; - while (cur != &dev->bus->drivers) { - device_driver* drv = - list_entry(cur); - cur = cur->next; - if (device_try_bind(dev, drv) != 0) { - break; - } - } - return 0; -} - -void device_unregister(device* dev) -{ - if (dev == nullptr || dev->bus == nullptr) { - return; - } - - LockGuard g(dev->bus->lock); - - if (dev->driver != nullptr) { - if (dev->driver->remove != nullptr) { - dev->driver->remove(dev); - } - list_del_init(&dev->driver_list); - dev->driver = nullptr; - } - list_del_init(&dev->bus_list); -} diff --git a/drivers/base/driver.cc b/drivers/base/driver.cc deleted file mode 100644 index ce15b6d..0000000 --- a/drivers/base/driver.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * drivers/base/driver.cc — driver_register / driver_unregister. - * - * Mirrors Linux drivers/base/driver.c. Registers a device_driver on - * its bus and tries to bind any unbound matching devices. - * - * Reference: docs/specs/storage_stack.md §4.3 - */ - -#include -#include -#include -#include -#include - -/* Implemented in core.cc — bind a device to a driver on its bus. - * Returns 1 on success, 0 on no-match-or-probe-fail. */ -int device_try_bind(device* dev, device_driver* drv); - -int driver_register(device_driver* drv) -{ - if (drv == nullptr || drv->bus == nullptr) { - return -EINVAL; - } - if (!drv->bus->registered) { - kprintf("[driver] register '%s' fail: bus '%s' not registered\n", - drv->name != nullptr ? drv->name : "?", - drv->bus->name != nullptr ? drv->bus->name : "?"); - return -ENODEV; - } - - drv->bus_node.init(); - drv->devices.init(); - - LockGuard g(drv->bus->lock); - list_add_tail(&drv->bus_node, &drv->bus->drivers); - - /* Try to bind any unbound devices already on the bus. */ - list_node* cur = drv->bus->devices.next; - while (cur != &drv->bus->devices) { - device* dev = list_entry(cur); - cur = cur->next; - if (dev->driver == nullptr) { - device_try_bind(dev, drv); - } - } - return 0; -} - -void driver_unregister(device_driver* drv) -{ - if (drv == nullptr || drv->bus == nullptr) { - return; - } - - LockGuard g(drv->bus->lock); - - /* Unbind every device bound to this driver. */ - while (!drv->devices.is_empty()) { - list_node* first = drv->devices.next; - device* dev = list_entry(first); - if (drv->remove != nullptr) { - drv->remove(dev); - } - list_del_init(&dev->driver_list); - dev->driver = nullptr; - } - list_del_init(&drv->bus_node); -} diff --git a/drivers/base/platform.cc b/drivers/base/platform.cc deleted file mode 100644 index fae8af6..0000000 --- a/drivers/base/platform.cc +++ /dev/null @@ -1,248 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * drivers/base/platform.cc — platform bus + FDT-driven device creation. - * - * Mirrors Linux drivers/base/platform.c. Provides: - * - platform_bus — the bus_type instance - * - platform_match — compatible-string matching via of_match_table - * - platform_dispatch — bus->probe forwarder that down-casts and calls - * platform_driver::probe(platform_device*) - * - driver_probe_all() — boot entry: register bus, register linker-set - * drivers, walk FDT, register platform_devices - * - * Reference: docs/specs/storage_stack.md §4.3 - */ - -#include -#include -#include -#include -#include - -/* kmalloc is declared extern "C" in , but mm/slab.cc defines - * it WITHOUT extern "C" (i.e. C++-mangled). Declare locally with C++ - * linkage so the symbol matches what mm/slab.o exports. */ -void* kmalloc(uint32 size); -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Linker-section registry */ -/* ------------------------------------------------------------------ */ - -extern "C" { - extern platform_driver* __drivers_start[]; - extern platform_driver* __drivers_end[]; -} - -/* ------------------------------------------------------------------ */ -/* platform_bus_type */ -/* ------------------------------------------------------------------ */ - -static int platform_match(device* dev, device_driver* drv) -{ - platform_device* pdev = to_platform_device(dev); - platform_driver* pdrv = to_platform_driver(drv); - - if (pdrv->of_match_table == nullptr || pdev->of_node == nullptr) { - return 0; - } - const FdtProperty* compat_prop = pdev->of_node->get_prop("compatible"); - if (compat_prop == nullptr || compat_prop->value == nullptr || - compat_prop->len == 0) { - return 0; - } - - const char* compat_list = static_cast(compat_prop->value); - const uint32 compat_len = static_cast(compat_prop->len); - for (const of_device_id* id = pdrv->of_match_table; - id->compatible != nullptr; ++id) { - uint32 offset = 0; - while (offset < compat_len) { - const char* node_compat = compat_list + offset; - uint32 remaining = compat_len - offset; - uint32 length = 0; - while (length < remaining && node_compat[length] != '\0') { - ++length; - } - if (length == remaining) { - break; /* malformed property without a terminating NUL */ - } - if (strcmp(id->compatible, node_compat) == 0) { - return 1; - } - offset += length + 1; - } - } - return 0; -} - -static int platform_dispatch(device* dev) -{ - platform_device* pdev = to_platform_device(dev); - platform_driver* pdrv = to_platform_driver(dev->driver); - if (pdrv->probe == nullptr) { - return 0; - } - return pdrv->probe(pdev); -} - -bus_type platform_bus = { - .name = "platform", - .match = platform_match, - .probe = platform_dispatch, - .devices = {}, - .drivers = {}, - .lock = {}, - .registered = false, -}; - -void platform_bus_init() -{ - bus_register(&platform_bus); -} - -/* ------------------------------------------------------------------ */ -/* platform_driver_register / platform_device_register */ -/* ------------------------------------------------------------------ */ - -int platform_driver_register(platform_driver* pdrv) -{ - if (pdrv == nullptr) { - return -EINVAL; - } - pdrv->driver.bus = &platform_bus; - /* driver.probe is unused — we route through bus->probe. Set name - * from the first of_match if not already provided. */ - if (pdrv->driver.name == nullptr && pdrv->of_match_table != nullptr) { - pdrv->driver.name = pdrv->of_match_table[0].compatible; - } - return driver_register(&pdrv->driver); -} - -int platform_device_register(platform_device* pdev) -{ - if (pdev == nullptr) { - return -EINVAL; - } - pdev->dev.bus = &platform_bus; - if (pdev->dev.init_name == nullptr && pdev->of_node != nullptr) { - pdev->dev.init_name = pdev->of_node->get_prop_string("compatible"); - } - device_initialize(&pdev->dev); - return device_register(&pdev->dev); -} - -/* ------------------------------------------------------------------ */ -/* FDT-driven device instantiation */ -/* ------------------------------------------------------------------ */ - -static platform_device* alloc_platform_device_from_node(DeviceNode* node, - const char* compat) -{ - auto* pdev = static_cast( - kmalloc(static_cast(sizeof(platform_device)))); - if (pdev == nullptr) { - return nullptr; - } - memset(pdev, 0, sizeof(*pdev)); - pdev->of_node = node; - pdev->mmio_base = node->get_prop_u64("reg", 0); - /* "reg" second cell is size — for now we don't bother parsing it - * separately; drivers that need it pull from of_node directly. */ - pdev->mmio_size = 0; - pdev->irq = -1; - pdev->dev.init_name = compat; - return pdev; -} - -/* For each registered platform_driver, walk its of_match_table and - * spawn a platform_device for each FDT compatible match found. - * - * NOTE: This is a simplified FDT walker — it only finds the FIRST FDT - * node matching each compatible string (delegating to - * fdt_find_compatible). Devices with multiple FDT instances of the - * same compatible will only see one bound here. A full FDT tree walk - * is left for when virtio-mmio or multi-instance UART arrives. - */ -static void instantiate_devices_for_driver(platform_driver* pdrv) -{ - if (pdrv == nullptr || pdrv->of_match_table == nullptr) { - return; - } - for (const of_device_id* id = pdrv->of_match_table; - id->compatible != nullptr; ++id) { - DeviceNode* node = fdt_find_compatible(id->compatible); - if (node == nullptr) { - continue; - } - platform_device* pdev = - alloc_platform_device_from_node(node, id->compatible); - if (pdev == nullptr) { - kprintf("[platform] OOM allocating pdev for %s\n", id->compatible); - continue; - } - kprintf("[platform] instantiating '%s' -> pdev mmio=0x%llx\n", - id->compatible, pdev->mmio_base); - platform_device_register(pdev); - } -} - -/* ------------------------------------------------------------------ */ -/* Boot entry — replaces the old driver_probe_all() */ -/* ------------------------------------------------------------------ */ - -void driver_probe_all() -{ - kprintf("[dpa] step 1: &platform_bus=%p (link 0xffffffc08033a0a8)\n", - &platform_bus); - kprintf("[dpa] step 1: pre-touch platform_bus.name slot...\n"); - const char** name_slot = &platform_bus.name; - kprintf("[dpa] step 1: name_slot=%p\n", name_slot); - kprintf("[dpa] step 1: about to deref *name_slot\n"); - const char* nm = *name_slot; - kprintf("[dpa] step 1: *name_slot=%p\n", nm); - kprintf("[dpa] step 1: about to read first byte of nm\n"); - char first = nm != nullptr ? nm[0] : '!'; - kprintf("[dpa] step 1: nm[0]='%c'\n", first); - - kprintf("[dpa] step 1: platform_bus_init enter\n"); - platform_bus_init(); - kprintf("[dpa] step 1: platform_bus_init done\n"); - - platform_driver** start = __drivers_start; - platform_driver** end = __drivers_end; - kprintf("[dpa] step 2: __drivers_start=%p __drivers_end=%p count=%lld\n", - start, end, (long long)(end - start)); - - for (platform_driver** slot = start; slot < end; ++slot) { - kprintf("[dpa] step 2: slot=%p *slot=%p\n", slot, *slot); - if (*slot != nullptr) { - platform_driver* pdrv = *slot; - kprintf("[dpa] step 2: pdrv->of_match_table=%p\n", - pdrv->of_match_table); - if (pdrv->of_match_table != nullptr) { - kprintf("[dpa] step 2: pdrv->of_match_table[0].compatible=%p\n", - pdrv->of_match_table[0].compatible); - if (pdrv->of_match_table[0].compatible != nullptr) { - kprintf("[dpa] step 2: compatible='%s'\n", - pdrv->of_match_table[0].compatible); - } - } - platform_driver_register(pdrv); - kprintf("[dpa] step 2: registered\n"); - } - } - - kprintf("[dpa] step 3: instantiate devices\n"); - for (platform_driver** slot = start; slot < end; ++slot) { - if (*slot != nullptr) { - instantiate_devices_for_driver(*slot); - } - } - kprintf("[dpa] done\n"); -} diff --git a/drivers/console.cc b/drivers/console.cc deleted file mode 100644 index f741dd2..0000000 --- a/drivers/console.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * console.cc — Console character device (/dev/console) - * - * Wraps the existing early_putc() UART driver as a file_operations - * chardev. read() is a stub for now (returns 0 = EOF). - * write() sends each byte through early_putc(). - */ - -#include -#include -#include - -extern "C" void early_putc(char c); - -/* ================================================================== */ -/* console_write */ -/* ================================================================== */ - -static int64 console_write(file* fp, const char* buf, uint64 count, int64* pos) -{ - (void)fp; - (void)pos; - - for (uint64 i = 0; i < count; i++) { - early_putc(buf[i]); - } - - return static_cast(count); -} - -/* ================================================================== */ -/* console_read — stub (returns 0 = EOF for now) */ -/* ================================================================== */ - -static int64 console_read(file* fp, char* buf, uint64 count, int64* pos) -{ - (void)fp; - (void)buf; - (void)count; - (void)pos; - /* TODO: implement UART RX polling/IRQ-based blocking read */ - return 0; -} - -/* ================================================================== */ -/* null device — /dev/null */ -/* ================================================================== */ - -static int64 null_read(file* /*fp*/, char* /*buf*/, uint64 /*count*/, int64* /*pos*/) -{ - return 0; /* EOF */ -} - -static int64 null_write(file* /*fp*/, const char* /*buf*/, uint64 count, int64* /*pos*/) -{ - return static_cast(count); /* discard */ -} - -/* ================================================================== */ -/* zero device — /dev/zero */ -/* ================================================================== */ - -static int64 zero_read(file* /*fp*/, char* buf, uint64 count, int64* /*pos*/) -{ - for (uint64 i = 0; i < count; i++) { - buf[i] = 0; - } - return static_cast(count); -} - -static int64 zero_write(file* /*fp*/, const char* /*buf*/, uint64 count, int64* /*pos*/) -{ - return static_cast(count); /* discard */ -} - -/* ================================================================== */ -/* Registration — runtime init (no static initializers!) */ -/* ================================================================== */ - -static file_operations console_fops; -static file_operations null_fops; -static file_operations zero_fops; - -static cdev console_cdev; -static cdev null_cdev; -static cdev zero_cdev; - -void console_cdev_init() -{ - /* Console: major=5, minor=1 */ - console_fops.read = console_read; - console_fops.write = console_write; - - console_cdev.name = "console"; - console_cdev.dev = MKDEV(5, 1); - console_cdev.fops = &console_fops; - cdev_register(&console_cdev); - - /* /dev/null: major=1, minor=3 */ - null_fops.read = null_read; - null_fops.write = null_write; - - null_cdev.name = "null"; - null_cdev.dev = MKDEV(1, 3); - null_cdev.fops = &null_fops; - cdev_register(&null_cdev); - - /* /dev/zero: major=1, minor=5 */ - zero_fops.read = zero_read; - zero_fops.write = zero_write; - - zero_cdev.name = "zero"; - zero_cdev.dev = MKDEV(1, 5); - zero_cdev.fops = &zero_fops; - cdev_register(&zero_cdev); -} diff --git a/drivers/plic.cc b/drivers/plic.cc deleted file mode 100644 index 2818700..0000000 --- a/drivers/plic.cc +++ /dev/null @@ -1,259 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * plic.cc — Platform-Level Interrupt Controller (RISC-V) - * - * QEMU virt platform PLIC: - * Base PA: 0x0C000000 - * Size: 0x04000000 (64MB) - * - * Register layout (per RISC-V PLIC spec): - * 0x000000: Priority registers (source 0..1023, 4 bytes each) - * 0x001000: Pending bits (source 0..1023, bit per source) - * 0x002000: Enable bits per context - * 0x200000: Threshold + claim/complete per context - * - * Context mapping for QEMU virt: - * Context 2*hartid + 1 = S-mode context for hart N - * - * Reference: docs/specs/trap.md §5.1 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* PLIC virtual base (after MMIO mapping) */ -static uint64 plic_va; - -extern "C" uint32 bsp_hart_id; - -/* PLIC register offsets */ -static constexpr uint64 PLIC_PRIORITY_BASE = 0x000000; -static constexpr uint64 PLIC_PENDING_BASE = 0x001000; -static constexpr uint64 PLIC_ENABLE_BASE = 0x002000; -static constexpr uint64 PLIC_THRESHOLD_BASE = 0x200000; -static constexpr uint64 PLIC_CLAIM_BASE = 0x200004; - -/* Each context's enable/threshold/claim region is 0x80 bytes apart for enable, - * and 0x1000 bytes apart for threshold/claim. */ -static constexpr uint64 PLIC_ENABLE_STRIDE = 0x80; -static constexpr uint64 PLIC_CONTEXT_STRIDE = 0x1000; - -/* Dynamic S-mode context mapping */ -static uint32 g_s_context[kMaxCpus]; - -static inline uint64 s_context(uint64 hart_id) { - if (hart_id < kMaxCpus) - return g_s_context[hart_id]; - return 2 * hart_id + 1; /* safe fallback */ -} - -static bool str_equals_plic(const char *a, const char *b) { - if (!a || !b) - return false; - while (*a && *a == *b) { - a++; - b++; - } - return *a == *b; -} - -/* Read a 32-bit MMIO register */ -static inline uint32 plic_read32(uint64 offset) { - return *reinterpret_cast(plic_va + offset); -} - -/* Write a 32-bit MMIO register */ -static inline void plic_write32(uint64 offset, uint32 val) { - *reinterpret_cast(plic_va + offset) = val; -} - -/* ======================================================================== - * Public API - * ======================================================================== */ - -static void plic_probe(DeviceNode* node) { - uint64 plic_pa = 0; - - /* Initialize default fallback mapping */ - for (uint32 i = 0; i < kMaxCpus; i++) { - g_s_context[i] = 2 * i + 1; - } - - /* Dynamically discover PLIC base address and context mapping from FDT */ - if (node) { - plic_pa = node->get_prop_u64("reg", plic_pa); - - /* Build phandle to hart_id map */ - struct PhandleMap { - uint32 phandle; - uint32 hart_id; - } pmap[kMaxCpus]; - int num_cpus = 0; - - DeviceNode *cpus_node = fdt_get_node_by_path("/cpus"); - if (cpus_node) { - list_node *cur = cpus_node->children_list_head(); - list_node *end = cpus_node->children_list_sentinel(); - while (cur != end && num_cpus < kMaxCpus) { - DeviceNode *cpu = - list_entry(cur); - cur = cur->next; - - const char *type = cpu->get_prop_string("device_type"); - if (type && str_equals_plic(type, "cpu")) { - uint32 hart_id = cpu->get_prop_u32("reg"); - DeviceNode *intc = cpu->find_child("interrupt-controller"); - if (intc) { - uint32 phandle = intc->get_prop_u32("phandle"); - if (phandle == 0) - phandle = intc->get_prop_u32("linux,phandle"); - if (phandle != 0) { - pmap[num_cpus].phandle = phandle; - pmap[num_cpus].hart_id = hart_id; - num_cpus++; - } - } - } - } - } - - /* Parse interrupts-extended */ - const FdtProperty *ie_prop = node->get_prop("interrupts-extended"); - if (ie_prop && ie_prop->len > 0) { - uint32 len = ie_prop->len; - const uint8 *val = static_cast(ie_prop->value); - int context_idx = 0; - /* Each entry is 2 cells (8 bytes): [phandle, interrupt_type] */ - for (uint32 i = 0; i + 7 < len; i += 8) { - uint32 phandle = (uint32(val[i]) << 24) | (uint32(val[i + 1]) << 16) | - (uint32(val[i + 2]) << 8) | val[i + 3]; - uint32 irq_type = (uint32(val[i + 4]) << 24) | - (uint32(val[i + 5]) << 16) | - (uint32(val[i + 6]) << 8) | val[i + 7]; - - if (irq_type == 9) { /* IRQ_S_EXTERNAL */ - for (int h = 0; h < num_cpus; h++) { - if (pmap[h].phandle == phandle) { - if (pmap[h].hart_id < kMaxCpus) { - g_s_context[pmap[h].hart_id] = context_idx; - } - break; - } - } - } - context_idx++; - } - } - } - - if (plic_pa == 0) return; - - /* Map PLIC MMIO */ - vmm_map_kernel_mmio(plic_pa, 0x4000000); - plic_va = pa_to_va(phys_addr(plic_pa)).raw; - - /* Use the actual BSP hart ID (it may not be hart 0) */ - uint64 ctx = s_context(bsp_hart_id); - - /* Set priority for all sources to 1 (minimum non-zero = enabled) */ - for (uint32 irq = 1; irq < IrqManager::kMaxIrqs; irq++) { - plic_write32(PLIC_PRIORITY_BASE + irq * 4, 1); - } - - /* Set threshold to 0 for BSP context (accept all priorities > 0) */ - plic_write32(PLIC_THRESHOLD_BASE + ctx * PLIC_CONTEXT_STRIDE, 0); -} - -static void plic_init_ap() { - uint64 ctx = s_context(arch::cpu::id()); - - /* Set threshold to 0 for this AP's context */ - plic_write32(PLIC_THRESHOLD_BASE + ctx * PLIC_CONTEXT_STRIDE, 0); -} - -static void plic_enable(uint32 irq) { - if (irq == 0 || irq >= IrqManager::kMaxIrqs) { - return; - } - - uint64 ctx = s_context(arch::cpu::id()); - uint64 offset = PLIC_ENABLE_BASE + ctx * PLIC_ENABLE_STRIDE; - uint32 word_index = irq / 32; - uint32 bit_index = irq % 32; - - uint32 val = plic_read32(offset + word_index * 4); - val |= (1U << bit_index); - plic_write32(offset + word_index * 4, val); -} - -static void plic_disable(uint32 irq) { - if (irq == 0 || irq >= IrqManager::kMaxIrqs) { - return; - } - - uint64 ctx = s_context(arch::cpu::id()); - uint64 offset = PLIC_ENABLE_BASE + ctx * PLIC_ENABLE_STRIDE; - uint32 word_index = irq / 32; - uint32 bit_index = irq % 32; - - uint32 val = plic_read32(offset + word_index * 4); - val &= ~(1U << bit_index); - plic_write32(offset + word_index * 4, val); -} - -static void plic_set_priority(uint32 irq, uint32 priority) { - if (irq == 0 || irq >= IrqManager::kMaxIrqs) - return; - plic_write32(PLIC_PRIORITY_BASE + (irq * 4), priority); -} - -static uint32 plic_claim() { - uint64 ctx = s_context(arch::cpu::id()); - return plic_read32(PLIC_CLAIM_BASE + ctx * PLIC_CONTEXT_STRIDE); -} - -static void plic_complete(uint32 irq) { - uint64 ctx = s_context(arch::cpu::id()); - plic_write32(PLIC_CLAIM_BASE + ctx * PLIC_CONTEXT_STRIDE, irq); -} - -static const IrqChip plic_chip = { - "riscv,plic0", - plic_claim, - plic_complete, - plic_init_ap, - plic_enable, - plic_disable, - plic_set_priority -}; - -static int plic_platform_probe(platform_device* pdev) { - plic_probe(pdev->of_node); - g_irq_manager.set_chip(&plic_chip); - return 0; -} - -static const of_device_id plic_of_match[] = { - { .compatible = "riscv,plic0", .data = nullptr }, - { .compatible = nullptr, .data = nullptr }, /* sentinel */ -}; - -platform_driver plic_driver = { - .driver = { .name = "plic", .bus = nullptr, - .probe = nullptr, .remove = nullptr, - .bus_node = {}, .devices = {} }, - .probe = plic_platform_probe, - .remove = nullptr, - .of_match_table = plic_of_match, -}; - -PLATFORM_DRIVER(plic_driver); diff --git a/drivers/tty/n_tty.cc b/drivers/tty/n_tty.cc deleted file mode 100644 index 0e312b0..0000000 --- a/drivers/tty/n_tty.cc +++ /dev/null @@ -1,539 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * n_tty.cc — N_TTY line discipline - * - * Implements the standard terminal line discipline: - * - * Canonical mode (ICANON): - * Input is buffered until newline/EOF. Backspace (VERASE) and - * kill-line (VKILL) editing are supported. - * - * Raw mode (!ICANON): - * Characters are available immediately (subject to VMIN/VTIME). - * - * Signal generation (ISIG): - * VINTR → SIGINT, VQUIT → SIGQUIT, VSUSP → SIGTSTP - * - * Echo (ECHO): - * Typed characters are reflected to output. - * - * Input processing (c_iflag): - * ICRNL: CR → NL mapping - * INLCR: NL → CR mapping - * IGNCR: ignore CR - * ISTRIP: strip high bit - * - * Output processing (c_oflag): - * OPOST + ONLCR: NL → CR+NL on output - * - * Reference: Linux drivers/tty/n_tty.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef ENOIOCTLCMD -#define ENOIOCTLCMD 515 -#endif - -extern void schedule(); - -/* ================================================================== */ -/* N_TTY internal data */ -/* ================================================================== */ - -inline constexpr int N_TTY_BUF_SIZE = 4096; - -struct n_tty_data { - char read_buf[N_TTY_BUF_SIZE]; - int read_head; /* producer writes here (from receive_buf) */ - int read_tail; /* consumer reads from here (from read()) */ - int canon_head; /* in canonical mode: end of last complete line */ - bool eof_pending; /* Ctrl+D was pressed */ - Spinlock lock; -}; - -static inline int buf_count(const n_tty_data* d) -{ - return (d->read_head - d->read_tail + N_TTY_BUF_SIZE) % N_TTY_BUF_SIZE; -} - -static inline int canon_count(const n_tty_data* d) -{ - return (d->canon_head - d->read_tail + N_TTY_BUF_SIZE) % N_TTY_BUF_SIZE; -} - -static inline bool buf_full(const n_tty_data* d) -{ - return buf_count(d) >= N_TTY_BUF_SIZE - 1; -} - -static inline void buf_put(n_tty_data* d, char c) -{ - d->read_buf[d->read_head] = c; - d->read_head = (d->read_head + 1) % N_TTY_BUF_SIZE; -} - -static inline char buf_get(n_tty_data* d) -{ - char c = d->read_buf[d->read_tail]; - d->read_tail = (d->read_tail + 1) % N_TTY_BUF_SIZE; - return c; -} - -/* ================================================================== */ -/* Output helpers */ -/* ================================================================== */ - -static void tty_put_char(tty_struct* tty, char c) -{ - if (tty->driver && tty->driver->ops && tty->driver->ops->put_char) { - tty->driver->ops->put_char(tty, c); - } -} - -/* - * Process and output a single character, applying c_oflag transformations. - */ -static void tty_output_char(tty_struct* tty, char c) -{ - if (tty->termios_data.c_oflag & OPOST) { - if (c == '\n' && (tty->termios_data.c_oflag & ONLCR)) { - tty_put_char(tty, '\r'); - tty_put_char(tty, '\n'); - return; - } - if (c == '\r' && (tty->termios_data.c_oflag & OCRNL)) { - tty_put_char(tty, '\n'); - return; - } - } - tty_put_char(tty, c); -} - -/* - * Echo a character back to the terminal. - * Control characters are displayed as ^X. - */ -static void echo_char(tty_struct* tty, char c) -{ - if (!(tty->termios_data.c_lflag & ECHO)) - return; - - if (c == '\n') { - tty_output_char(tty, '\n'); - return; - } - - if (c == '\t') { - tty_put_char(tty, '\t'); - return; - } - - /* Control characters: echo as ^X */ - if ((tty->termios_data.c_lflag & ECHOCTL) && c < 0x20 && c != '\t' && c != '\n') { - tty_put_char(tty, '^'); - tty_put_char(tty, c + '@'); - return; - } - - if (c == 0x7f) { /* DEL */ - tty_put_char(tty, '^'); - tty_put_char(tty, '?'); - return; - } - - tty_output_char(tty, c); -} - -/* - * Erase one character visually (backspace + space + backspace). - */ -static void erase_char(tty_struct* tty, char erased) -{ - if (!(tty->termios_data.c_lflag & ECHO)) - return; - - if ((tty->termios_data.c_lflag & ECHOE)) { - /* If the erased char was a control char displayed as ^X, erase 2 cols */ - if ((erased < 0x20 && erased != '\t' && erased != '\n') || erased == 0x7f) { - tty_put_char(tty, '\b'); - tty_put_char(tty, ' '); - tty_put_char(tty, '\b'); - tty_put_char(tty, '\b'); - tty_put_char(tty, ' '); - tty_put_char(tty, '\b'); - } else { - tty_put_char(tty, '\b'); - tty_put_char(tty, ' '); - tty_put_char(tty, '\b'); - } - } -} - -/* ================================================================== */ -/* Input processing — receive_buf (called from IRQ or driver) */ -/* ================================================================== */ - -static void n_tty_receive_buf(tty_struct* tty, const char* cp, int count) -{ - auto* d = static_cast(tty->ldisc.data); - if (!d) return; - - const termios& t = tty->termios_data; - - LockGuard guard(d->lock); - - for (int i = 0; i < count; i++) { - char c = cp[i]; - - /* Strip high bit if requested */ - if (t.c_iflag & ISTRIP) - c &= 0x7f; - - /* Input CR/NL processing */ - if (c == '\r') { - if (t.c_iflag & IGNCR) - continue; - if (t.c_iflag & ICRNL) - c = '\n'; - } else if (c == '\n') { - if (t.c_iflag & INLCR) - c = '\r'; - } - - /* Signal generation */ - if (t.c_lflag & ISIG) { - if (c == t.c_cc[VINTR]) { - tty_signal_pgrp(tty, SIGINT); - echo_char(tty, c); - if (!(t.c_lflag & NOFLSH)) { - /* Flush input buffer */ - d->read_head = d->read_tail; - d->canon_head = d->read_tail; - } - continue; - } - if (c == t.c_cc[VQUIT]) { - tty_signal_pgrp(tty, SIGQUIT); - echo_char(tty, c); - if (!(t.c_lflag & NOFLSH)) { - d->read_head = d->read_tail; - d->canon_head = d->read_tail; - } - continue; - } - if (c == t.c_cc[VSUSP]) { - tty_signal_pgrp(tty, SIGTSTP); - echo_char(tty, c); - continue; - } - } - - /* Canonical mode processing */ - if (t.c_lflag & ICANON) { - /* EOF (Ctrl+D) */ - if (c == t.c_cc[VEOF]) { - d->eof_pending = true; - d->canon_head = d->read_head; - tty->read_wait.wake_all(); - continue; - } - - /* ERASE (backspace/DEL) */ - if (c == t.c_cc[VERASE]) { - if (d->read_head != d->canon_head && - d->read_head != d->read_tail) { - int prev = (d->read_head - 1 + N_TTY_BUF_SIZE) % N_TTY_BUF_SIZE; - char erased = d->read_buf[prev]; - d->read_head = prev; - erase_char(tty, erased); - } - continue; - } - - /* KILL (Ctrl+U — erase entire line) */ - if (c == t.c_cc[VKILL]) { - while (d->read_head != d->canon_head && - d->read_head != d->read_tail) { - int prev = (d->read_head - 1 + N_TTY_BUF_SIZE) % N_TTY_BUF_SIZE; - char erased = d->read_buf[prev]; - d->read_head = prev; - erase_char(tty, erased); - } - if (t.c_lflag & ECHOK) { - tty_output_char(tty, '\n'); - } - continue; - } - - /* WERASE (Ctrl+W — erase word) */ - if ((t.c_lflag & IEXTEN) && c == t.c_cc[VWERASE]) { - /* Skip trailing spaces */ - while (d->read_head != d->canon_head) { - int prev = (d->read_head - 1 + N_TTY_BUF_SIZE) % N_TTY_BUF_SIZE; - if (d->read_buf[prev] != ' ' && d->read_buf[prev] != '\t') - break; - erase_char(tty, d->read_buf[prev]); - d->read_head = prev; - } - /* Erase word */ - while (d->read_head != d->canon_head) { - int prev = (d->read_head - 1 + N_TTY_BUF_SIZE) % N_TTY_BUF_SIZE; - if (d->read_buf[prev] == ' ' || d->read_buf[prev] == '\t') - break; - erase_char(tty, d->read_buf[prev]); - d->read_head = prev; - } - continue; - } - - /* REPRINT (Ctrl+R) */ - if ((t.c_lflag & IEXTEN) && c == t.c_cc[VREPRINT]) { - tty_output_char(tty, '\n'); - int pos = d->canon_head; - while (pos != d->read_head) { - echo_char(tty, d->read_buf[pos]); - pos = (pos + 1) % N_TTY_BUF_SIZE; - } - continue; - } - - /* Regular character — buffer it */ - if (!buf_full(d)) { - buf_put(d, c); - echo_char(tty, c); - } - - /* Line complete on newline or EOL */ - if (c == '\n' || c == t.c_cc[VEOL] || - (t.c_cc[VEOL2] && c == t.c_cc[VEOL2])) { - d->canon_head = d->read_head; - tty->read_wait.wake_all(); - } - } else { - /* Raw / non-canonical mode */ - if (!buf_full(d)) { - buf_put(d, c); - echo_char(tty, c); - tty->read_wait.wake_all(); - } - } - } -} - -/* ================================================================== */ -/* N_TTY read — blocking read from the input buffer */ -/* ================================================================== */ - -static int n_tty_read(tty_struct* tty, file* fp, char* buf, uint64 count) -{ - auto* d = static_cast(tty->ldisc.data); - if (!d) return -EIO; - - const termios& t = tty->termios_data; - TaskControlBlock* curr = current_task(); - int copied = 0; - - if (t.c_lflag & ICANON) { - /* Canonical mode: block until a complete line is available */ - while (canon_count(d) == 0 && !d->eof_pending) { - if (tty->flags & TTY_IO_ERROR) - return -EIO; - - /* Check for pending signals — return -EINTR so the - * trap return path can deliver them via do_signal() */ - if (signal_pending(curr)) - return -EINTR; - - tty->read_wait.prepare_to_wait(curr, TaskState::Sleeping); - if (canon_count(d) == 0 && !d->eof_pending) - schedule(); - tty->read_wait.finish_wait(curr); - } - - if (d->eof_pending && canon_count(d) == 0) { - d->eof_pending = false; - return 0; /* EOF */ - } - - /* Copy up to one line */ - LockGuard guard(d->lock); - while (copied < static_cast(count) && d->read_tail != d->canon_head) { - buf[copied++] = buf_get(d); - } - } else { - /* Non-canonical mode */ - int vmin = t.c_cc[VMIN]; - /* VTIME not implemented (would need timers) */ - - if (vmin == 0) vmin = 1; - - while (buf_count(d) < vmin) { - if (tty->flags & TTY_IO_ERROR) - return -EIO; - - if (signal_pending(curr)) - return -EINTR; - - tty->read_wait.prepare_to_wait(curr, TaskState::Sleeping); - if (buf_count(d) < vmin) - schedule(); - tty->read_wait.finish_wait(curr); - } - - LockGuard guard(d->lock); - while (copied < static_cast(count) && buf_count(d) > 0) { - buf[copied++] = buf_get(d); - } - } - - return copied; -} - -/* ================================================================== */ -/* N_TTY write — output through the driver with post-processing */ -/* ================================================================== */ - -static int n_tty_write(tty_struct* tty, file* fp, const char* buf, uint64 count) -{ - if (!tty->driver || !tty->driver->ops || !tty->driver->ops->write) - return -EIO; - - /* Apply output processing (OPOST) */ - if (tty->termios_data.c_oflag & OPOST) { - for (uint64 i = 0; i < count; i++) { - tty_output_char(tty, buf[i]); - } - return static_cast(count); - } - - /* Raw output: pass directly to driver */ - return tty->driver->ops->write(tty, buf, static_cast(count)); -} - -/* ================================================================== */ -/* N_TTY ioctl */ -/* ================================================================== */ - -static int n_tty_ioctl(tty_struct* tty, unsigned int cmd, uint64 arg) -{ - auto* d = static_cast(tty->ldisc.data); - - switch (cmd) { - case FIONREAD: { - int count = buf_count(d); - auto* p = reinterpret_cast(arg); - *p = count; - return 0; - } - default: - return -ENOIOCTLCMD; - } -} - -/* ================================================================== */ -/* N_TTY open / close */ -/* ================================================================== */ - -static int n_tty_open(tty_struct* tty) -{ - auto* d = new n_tty_data{}; - if (!d) return -ENOMEM; - - d->read_head = 0; - d->read_tail = 0; - d->canon_head = 0; - d->eof_pending = false; - d->lock.init("n_tty"); - - tty->ldisc.data = d; - return 0; -} - -static void n_tty_close(tty_struct* tty) -{ - auto* d = static_cast(tty->ldisc.data); - if (d) { - delete d; - tty->ldisc.data = nullptr; - } -} - -static void n_tty_flush_buffer(tty_struct* tty) -{ - auto* d = static_cast(tty->ldisc.data); - if (!d) return; - LockGuard guard(d->lock); - d->read_head = 0; - d->read_tail = 0; - d->canon_head = 0; - d->eof_pending = false; -} - -static int n_tty_chars_in_buffer(tty_struct* tty) -{ - auto* d = static_cast(tty->ldisc.data); - if (!d) return 0; - return buf_count(d); -} - -/* - * Probe input readiness for poll(). In canonical mode the read syscall - * blocks until a whole line is queued, so we mirror that: POLLIN only - * when canon_count() shows a finalized line (or pending EOF). In raw - * mode any character satisfies VMIN==1 immediately. Without this - * mirror, ppoll() would falsely signal POLLIN on partial canonical - * input, then read() would block — exactly the busy-loop the shell's - * ppoll-then-read pattern is trying to avoid. - */ -bool n_tty_input_ready(tty_struct* tty) -{ - auto* d = static_cast(tty->ldisc.data); - if (!d) return false; - const termios& t = tty->termios_data; - if (t.c_lflag & ICANON) - return canon_count(d) != 0 || d->eof_pending; - int vmin = t.c_cc[VMIN]; - if (vmin == 0) vmin = 1; - return buf_count(d) >= vmin; -} - -static void n_tty_set_termios(tty_struct* /*tty*/, const termios* /*old*/) -{ - /* Nothing special needed for now */ -} - -static void n_tty_hangup(tty_struct* tty) -{ - n_tty_flush_buffer(tty); - tty->read_wait.wake_all(); -} - -/* ================================================================== */ -/* N_TTY ops table */ -/* ================================================================== */ - -const tty_ldisc_ops n_tty_ops = { - .name = "n_tty", - .num = 0, /* N_TTY */ - .open = n_tty_open, - .close = n_tty_close, - .read = n_tty_read, - .write = n_tty_write, - .receive_buf = n_tty_receive_buf, - .ioctl = n_tty_ioctl, - .flush_buffer = n_tty_flush_buffer, - .chars_in_buffer = n_tty_chars_in_buffer, - .set_termios = n_tty_set_termios, - .hangup = n_tty_hangup, -}; diff --git a/drivers/tty/tty_core.cc b/drivers/tty/tty_core.cc deleted file mode 100644 index 5985bd9..0000000 --- a/drivers/tty/tty_core.cc +++ /dev/null @@ -1,536 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * tty_core.cc — TTY subsystem core - * - * Provides the tty_struct lifecycle, file_operations dispatch, - * and ioctl routing between the line discipline and driver. - * - * Call chain: - * sys_read → tty_fops.read → tty_read → ldisc.read - * sys_write → tty_fops.write → tty_write → ldisc.write - * sys_ioctl → tty_fops.ioctl → tty_ioctl → {core / ldisc / driver} - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef ENOIOCTLCMD -#define ENOIOCTLCMD 515 -#endif - -/* ================================================================== */ -/* Global console TTY */ -/* ================================================================== */ - -tty_struct* g_console_tty = nullptr; - -/* ================================================================== */ -/* tty_struct allocation */ -/* ================================================================== */ - -tty_struct* tty_alloc(const tty_driver* driver, int index) -{ - auto* tty = new tty_struct{}; - if (!tty) return nullptr; - - tty->index = index; - tty->driver = driver; - tty->link = nullptr; - tty->pgrp = 0; - tty->session = 0; - tty->write_cnt = 0; - tty->flags = 0; - tty->open_count = 0; - tty->driver_data = nullptr; - - tty_default_termios(&tty->termios_data); - - tty->ws.ws_row = 24; - tty->ws.ws_col = 80; - tty->ws.ws_xpixel = 0; - tty->ws.ws_ypixel = 0; - - tty->lock.init("tty"); - tty->read_wait.init("tty_rd"); - tty->write_wait.init("tty_wr"); - - /* Attach default line discipline (N_TTY) */ - tty->ldisc.ops = &n_tty_ops; - tty->ldisc.data = nullptr; - - return tty; -} - -/* ================================================================== */ -/* tty_open / tty_close */ -/* ================================================================== */ - -int tty_open(tty_struct* tty) -{ - if (!tty) return -EINVAL; - - if (tty->open_count == 0) { - /* Initialize line discipline */ - if (tty->ldisc.ops && tty->ldisc.ops->open) { - int ret = tty->ldisc.ops->open(tty); - if (ret < 0) return ret; - } - - /* Initialize driver */ - if (tty->driver && tty->driver->ops && tty->driver->ops->open) { - int ret = tty->driver->ops->open(tty); - if (ret < 0) { - if (tty->ldisc.ops && tty->ldisc.ops->close) - tty->ldisc.ops->close(tty); - return ret; - } - } - } - - tty->open_count++; - return 0; -} - -void tty_close(tty_struct* tty) -{ - if (!tty) return; - - tty->open_count--; - if (tty->open_count <= 0) { - tty->open_count = 0; - - if (tty->driver && tty->driver->ops && tty->driver->ops->close) - tty->driver->ops->close(tty); - - if (tty->ldisc.ops && tty->ldisc.ops->close) - tty->ldisc.ops->close(tty); - } -} - -/* ================================================================== */ -/* Core I/O */ -/* ================================================================== */ - -int64 tty_read(tty_struct* tty, file* fp, char* buf, uint64 count) -{ - if (!tty || !tty->ldisc.ops || !tty->ldisc.ops->read) - return -EIO; - - return tty->ldisc.ops->read(tty, fp, buf, count); -} - -int64 tty_write(tty_struct* tty, file* fp, const char* buf, uint64 count) -{ - if (!tty || !tty->ldisc.ops || !tty->ldisc.ops->write) - return -EIO; - - return tty->ldisc.ops->write(tty, fp, buf, count); -} - -/* ================================================================== */ -/* tty_receive_buf — called by driver on RX */ -/* ================================================================== */ - -void tty_receive_buf(tty_struct* tty, const char* buf, int count) -{ - if (!tty || !tty->ldisc.ops || !tty->ldisc.ops->receive_buf) - return; - - tty->ldisc.ops->receive_buf(tty, buf, count); -} - -/* ================================================================== */ -/* tty_signal_pgrp — send signal to foreground process group */ -/* ================================================================== */ - -extern int send_signal(int sig, kernel_siginfo* info, TaskControlBlock* task); - -void tty_signal_pgrp(tty_struct* tty, int sig) -{ - if (!tty) return; - - int32 pgid; - { - LockGuard guard(tty->lock); - pgid = tty->pgrp; - } - if (pgid <= 0) return; - - /* Deliver to the leader of every thread group in the foreground - * process group. ldisc paths call this for SIGINT/SIGQUIT/SIGWINCH - * etc.; previously we only signalled the current task, which was - * incorrect when the fg pgrp had multiple processes. */ - kernel_siginfo info{}; - info.si_signo = sig; - info.si_code = 0; /* SI_KERNEL would be 0x80; user rarely checks */ - for_each_pgrp_member(pgid, [&](signal_struct* s) { - if (s->leader) - send_signal(sig, &info, s->leader); - }); -} - -/* ================================================================== */ -/* tty_ioctl — ioctl dispatch */ -/* ================================================================== */ - -long tty_ioctl(tty_struct* tty, file* /*fp*/, unsigned int cmd, uint64 arg) -{ - if (!tty) return -EINVAL; - - switch (cmd) { - case TCGETS: { - auto* p = reinterpret_cast(arg); - if (!p) return -EINVAL; - *p = tty->termios_data; - return 0; - } - - case TCSETS: - case TCSETSW: - case TCSETSF: { - auto* p = reinterpret_cast(arg); - if (!p) return -EINVAL; - termios old = tty->termios_data; - tty->termios_data = *p; - - /* Notify line discipline of termios change */ - if (tty->ldisc.ops && tty->ldisc.ops->set_termios) - tty->ldisc.ops->set_termios(tty, &old); - - /* If TCSETSF, flush input buffer */ - if (cmd == TCSETSF) { - if (tty->ldisc.ops && tty->ldisc.ops->flush_buffer) - tty->ldisc.ops->flush_buffer(tty); - } - return 0; - } - - case TIOCGWINSZ: { - auto* p = reinterpret_cast(arg); - if (!p) return -EINVAL; - *p = tty->ws; - return 0; - } - - case TIOCSWINSZ: { - auto* p = reinterpret_cast(arg); - if (!p) return -EINVAL; - winsize old = tty->ws; - tty->ws = *p; - if (old.ws_row != tty->ws.ws_row || old.ws_col != tty->ws.ws_col) { - tty_signal_pgrp(tty, SIGWINCH); - } - return 0; - } - - case TIOCGPGRP: { - auto* p = reinterpret_cast(arg); - if (!p) return -EINVAL; - - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -ENOTTY; - if (curr->signal->tty != tty) return -ENOTTY; - - int32 pgid; - { - LockGuard guard(tty->lock); - pgid = tty->pgrp != 0 ? tty->pgrp : curr->signal->pgid; - } - *p = pgid; - return 0; - } - - case TIOCSPGRP: { - auto* p = reinterpret_cast(arg); - if (!p) return -EINVAL; - - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -ENOTTY; - if (curr->signal->tty != tty) return -ENOTTY; - - int32 new_pgid = *p; - if (new_pgid <= 0) return -EINVAL; - - /* new_pgid must be in the caller's session. */ - bool ok = false; - for_each_pgrp_member(new_pgid, [&](signal_struct* s) { - if (s->sid == curr->signal->sid) ok = true; - }); - if (!ok) return -EPERM; - - LockGuard guard(tty->lock); - tty->pgrp = new_pgid; - return 0; - } - - case TIOCSCTTY: { - /* Become the controlling terminal of the caller's session. - * Linux: only session leader without ctty may do this; with - * arg==1, CAP_SYS_ADMIN may steal a ctty from another session. - * We support the basic path; "steal" is left unimplemented. */ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -EPERM; - signal_struct* sig = curr->signal; - - if (sig->sid != curr->pid) return -EPERM; /* not leader */ - - LockGuard sg(sig->lock); - if (sig->tty != nullptr) return -EPERM; /* already have one */ - - LockGuard tg(tty->lock); - if (tty->session != 0 && tty->session != sig->sid) { - return -EPERM; /* owned elsewhere */ - } - tty->session = sig->sid; - tty->pgrp = sig->pgid; - sig->tty = tty; - return 0; - } - - case TIOCNOTTY: { - /* Detach from controlling terminal. */ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -ENOTTY; - signal_struct* sig = curr->signal; - if (sig->tty != tty) return -ENOTTY; - - /* Session leader: HUP everyone left in the old fg pgrp. - * Job-control conformance — without this, daemons spawned by - * a relinquishing leader keep blocking on a dead terminal. */ - bool was_leader = (sig->sid == curr->pid); - int32 hup_pgrp = 0; - { - LockGuard tg(tty->lock); - hup_pgrp = tty->pgrp; - if (was_leader) { - tty->session = 0; - tty->pgrp = 0; - } - } - { - LockGuard sg(sig->lock); - sig->tty = nullptr; - } - if (was_leader && hup_pgrp > 0) { - tty_signal_pgrp(tty, SIGHUP); - tty_signal_pgrp(tty, SIGCONT); - (void)hup_pgrp; - } - return 0; - } - - case FIONREAD: { - /* Delegate to line discipline */ - if (tty->ldisc.ops && tty->ldisc.ops->ioctl) { - int ret = tty->ldisc.ops->ioctl(tty, cmd, arg); - if (ret != -ENOIOCTLCMD) - return ret; - } - return 0; - } - - case TCFLSH: { - int queue = static_cast(arg); - if (queue == 0 || queue == 2) { - /* Flush input */ - if (tty->ldisc.ops && tty->ldisc.ops->flush_buffer) - tty->ldisc.ops->flush_buffer(tty); - } - if (queue == 1 || queue == 2) { - /* Flush output */ - if (tty->driver && tty->driver->ops && tty->driver->ops->flush_buffer) - tty->driver->ops->flush_buffer(tty); - } - return 0; - } - - default: - break; - } - - /* Try line discipline ioctl */ - if (tty->ldisc.ops && tty->ldisc.ops->ioctl) { - int ret = tty->ldisc.ops->ioctl(tty, cmd, arg); - if (ret != -ENOIOCTLCMD) - return ret; - } - - /* Try driver ioctl */ - if (tty->driver && tty->driver->ops && tty->driver->ops->ioctl) { - int ret = tty->driver->ops->ioctl(tty, cmd, arg); - if (ret != -ENOIOCTLCMD) - return ret; - } - - return -ENOTTY; -} - -/* ================================================================== */ -/* file_operations for TTY devices */ -/* ================================================================== */ - -static int64 tty_fops_read(file* fp, char* buf, uint64 count, int64* /*pos*/) -{ - auto* tty = static_cast(fp->private_data); - return tty_read(tty, fp, buf, count); -} - -static int64 tty_fops_write(file* fp, const char* buf, uint64 count, int64* /*pos*/) -{ - auto* tty = static_cast(fp->private_data); - return tty_write(tty, fp, buf, count); -} - -static long tty_fops_ioctl(file* fp, unsigned int cmd, uint64 arg) -{ - auto* tty = static_cast(fp->private_data); - return tty_ioctl(tty, fp, cmd, arg); -} - -/* - * tty poll callback — Linux drivers/tty/tty_io.c:tty_poll() does the - * same thing: register tty->read_wait so the poller is woken on input, - * then ask the ldisc whether data is currently available. Write side - * is always considered ready since our writes don't block. - */ -extern bool n_tty_input_ready(tty_struct* tty); -extern void poll_wait(file*, WaitQueue*, poll_table*); - -static uint32 tty_fops_poll(file* fp, void* pt) -{ - auto* tty = static_cast(fp->private_data); - if (!tty) return POLLNVAL; - - poll_wait(fp, &tty->read_wait, static_cast(pt)); - - uint32 mask = POLLOUT | POLLWRNORM; /* always writable */ - if (n_tty_input_ready(tty)) - mask |= POLLIN | POLLRDNORM; - return mask; -} - -/* - * Auto-acquire a controlling terminal on open. - * - * POSIX rule: when a session leader without a controlling tty opens a - * terminal that itself has no controlling session, and the caller did - * not pass O_NOCTTY, that terminal becomes the controlling terminal of - * the caller's session. tty->session and tty->pgrp are seeded from the - * caller's sid/pgid so that the very first tcgetpgrp() call returns a - * value matching the caller's pgid — which is precisely what BusyBox - * ash:setjobctl() needs to exit its setup loop. - * - * Reference: Linux drivers/tty/tty_jobctrl.c:tty_open_proc_set_tty() - */ -static void tty_acquire_ctty(tty_struct* tty, file* fp) -{ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return; - if (fp->f_flags & O_NOCTTY) return; - - signal_struct* sig = curr->signal; - - /* Must be session leader (sid == pid). */ - if (sig->sid != curr->pid) return; - - LockGuard sig_guard(sig->lock); - if (sig->tty != nullptr) return; /* already have one */ - - LockGuard tty_guard(tty->lock); - if (tty->session != 0) return; /* tty owned by another sess */ - - tty->session = sig->sid; - tty->pgrp = sig->pgid; - sig->tty = tty; -} - -static int tty_fops_open(inode* /*ip*/, file* fp) -{ - /* The console TTY is pre-allocated; just attach it */ - if (!g_console_tty) return -ENXIO; - fp->private_data = g_console_tty; - int err = tty_open(g_console_tty); - if (err == 0) { - tty_acquire_ctty(g_console_tty, fp); - } - return err; -} - -static int tty_fops_release(inode* /*ip*/, file* fp) -{ - auto* tty = static_cast(fp->private_data); - tty_close(tty); - return 0; -} - -file_operations tty_fops; - -static void init_tty_fops() -{ - tty_fops.read = tty_fops_read; - tty_fops.write = tty_fops_write; - tty_fops.unlocked_ioctl = tty_fops_ioctl; - tty_fops.poll = tty_fops_poll; - tty_fops.open = tty_fops_open; - tty_fops.release = tty_fops_release; -} - -/* ================================================================== */ -/* TTY chardev registration */ -/* ================================================================== */ - -static cdev tty_cdev; - -void tty_init() -{ - init_tty_fops(); - - /* Allocate the console TTY */ - g_console_tty = tty_alloc(&uart_tty_driver, 0); - if (!g_console_tty) { - return; - } - - /* Open the TTY (initializes ldisc + driver) */ - tty_open(g_console_tty); - - /* Leave tty->session and tty->pgrp at 0. The first session-leader - * to open /dev/console without O_NOCTTY claims it as its controlling - * terminal via tty_acquire_ctty(), which fills both fields. Pre- - * seeding them here (as we used to with the hardcoded pid==1) would - * make every subsequent acquire path see "owned by another session" - * and bail out, leaving sh's tcgetpgrp() returning -ENOTTY and - * disabling job control. */ - - /* Initialize UART RX interrupts */ - uart_tty_init(g_console_tty); - - /* Register UART as a struct console driver. - * After this, printk/klog output goes through console_write_all() - * → uart_console_write() instead of raw early_putc(). */ - extern void uart_register_console(); - uart_register_console(); - - /* Register as /dev/console chardev — replace the old console_cdev. - * We use the same major/minor (5,1) so that existing opens - * to /dev/console will get the TTY fops. */ - tty_cdev.name = "console"; - tty_cdev.dev = MKDEV(5, 1); - tty_cdev.fops = &tty_fops; - cdev_register(&tty_cdev); -} diff --git a/drivers/tty/tty_uart.cc b/drivers/tty/tty_uart.cc deleted file mode 100644 index 973a6e9..0000000 --- a/drivers/tty/tty_uart.cc +++ /dev/null @@ -1,251 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * tty_uart.cc — UART → tty_driver adapter - * - * Bridges the 16550A UART hardware to the TTY subsystem. - * - * TX: Calls early_putc() for each character (same as before). - * RX: Registers a PLIC IRQ handler. On UART RX interrupt, - * reads available bytes and feeds them to the line discipline - * via tty_receive_buf(). - * - * QEMU virt UART: - * - IRQ 10 on the PLIC - * - 16550A register layout at the base address discovered from FDT - */ - -#include -#include -#include -#include -#include -#include -#include - -#ifndef ENOIOCTLCMD -#define ENOIOCTLCMD 515 -#endif - -extern "C" void early_putc(char c); - -/* 16550A register offsets */ -static constexpr int UART_RBR = 0; /* Receive Buffer Register */ -static constexpr int UART_THR = 0; /* Transmit Holding Register */ -static constexpr int UART_IER = 1; /* Interrupt Enable Register */ -static constexpr int UART_IIR = 2; /* Interrupt Identification Register */ -static constexpr int UART_FCR = 2; /* FIFO Control Register */ -static constexpr int UART_LCR = 3; /* Line Control Register */ -static constexpr int UART_MCR = 4; /* Modem Control Register */ -static constexpr int UART_LSR = 5; /* Line Status Register */ - -/* LSR bits */ -static constexpr uint8 UART_LSR_DR = 0x01; /* Data Ready */ -static constexpr uint8 UART_LSR_THRE = 0x20; /* TX Holding Register Empty */ - -/* IER bits */ -static constexpr uint8 UART_IER_RDI = 0x01; /* Received Data Available */ - -/* MCR bits */ -static constexpr uint8 UART_MCR_DTR = 0x01; /* Data Terminal Ready */ -static constexpr uint8 UART_MCR_RTS = 0x02; /* Request To Send */ -static constexpr uint8 UART_MCR_OUT2 = 0x08; /* Auxiliary output 2 — gates the - IRQ pin on PC-style 16550A. - Without this the UART - internally asserts but does - NOT propagate to the PLIC. */ - -/* QEMU virt default UART IRQ */ -static constexpr uint32 UART_IRQ = 10; - -/* UART MMIO base (virtual address) */ -static volatile uint8* g_uart_base; -static tty_struct* g_uart_tty; - -/* ================================================================== */ -/* UART MMIO helpers */ -/* ================================================================== */ - -static inline uint8 uart_read(int reg) -{ - return g_uart_base[reg]; -} - -static inline void uart_write(int reg, uint8 val) -{ - g_uart_base[reg] = val; -} - -static inline bool uart_rx_ready() -{ - return (uart_read(UART_LSR) & UART_LSR_DR) != 0; -} - -static inline char uart_rx_char() -{ - return static_cast(uart_read(UART_RBR)); -} - -/* ================================================================== */ -/* UART RX interrupt handler */ -/* ================================================================== */ - -static void uart_irq_handler(uint32 /*irq*/, void* arg) -{ - auto* tty = static_cast(arg); - - /* Read all available bytes from the FIFO */ - char buf[16]; - int count = 0; - - while (uart_rx_ready() && count < 16) { - buf[count++] = uart_rx_char(); - } - - if (count > 0) { - tty_receive_buf(tty, buf, count); - } -} - -/* ================================================================== */ -/* tty_driver_ops for UART */ -/* ================================================================== */ - -static int uart_tty_open_op(tty_struct* /*tty*/) -{ - return 0; -} - -static void uart_tty_close_op(tty_struct* /*tty*/) -{ - /* Nothing to do */ -} - -static int uart_tty_write_op(tty_struct* /*tty*/, const char* buf, int count) -{ - for (int i = 0; i < count; i++) { - early_putc(buf[i]); - } - return count; -} - -static int uart_tty_write_room_op(tty_struct* /*tty*/) -{ - return TTY_BUF_SIZE; /* Always room (blocking putc) */ -} - -static void uart_tty_put_char_op(tty_struct* /*tty*/, char ch) -{ - early_putc(ch); -} - -static void uart_tty_flush_chars_op(tty_struct* /*tty*/) -{ - /* No buffering in early_putc, nothing to flush */ -} - -static int uart_tty_chars_in_buffer_op(tty_struct* /*tty*/) -{ - return 0; /* No TX buffer */ -} - -static void uart_tty_flush_buffer_op(tty_struct* /*tty*/) -{ - /* No TX buffer to flush */ -} - -static int uart_tty_ioctl_op(tty_struct* /*tty*/, unsigned int /*cmd*/, uint64 /*arg*/) -{ - return -ENOIOCTLCMD; -} - -static void uart_tty_hangup_op(tty_struct* /*tty*/) -{ - /* Disable UART RX interrupts */ - if (g_uart_base) { - uart_write(UART_IER, 0); - } -} - -static const tty_driver_ops uart_ops = { - .open = uart_tty_open_op, - .close = uart_tty_close_op, - .write = uart_tty_write_op, - .write_room = uart_tty_write_room_op, - .put_char = uart_tty_put_char_op, - .flush_chars = uart_tty_flush_chars_op, - .chars_in_buffer = uart_tty_chars_in_buffer_op, - .flush_buffer = uart_tty_flush_buffer_op, - .ioctl = uart_tty_ioctl_op, - .throttle = nullptr, - .unthrottle = nullptr, - .hangup = uart_tty_hangup_op, -}; - -const tty_driver uart_tty_driver = { - .name = "ttyS", - .major = 4, - .minor_start = 64, - .num = 1, - .ops = &uart_ops, -}; - -/* ================================================================== */ -/* UART TTY init — discover base address, enable RX IRQ */ -/* ================================================================== */ - -void uart_tty_init(tty_struct* tty) -{ - g_uart_tty = tty; - - /* Discover UART base from FDT */ - DeviceNode* node = fdt_find_compatible("ns16550a"); - if (!node) { - /* Try alternative compatible string */ - node = fdt_find_compatible("snps,dw-apb-uart"); - } - - uint64 uart_pa = 0; - if (node) { - uart_pa = node->get_prop_u64("reg", 0); - } - - if (uart_pa == 0) { - /* Fallback: QEMU virt default */ - uart_pa = 0x10000000; - } - - g_uart_base = reinterpret_cast( - pa_to_va(phys_addr(uart_pa)).raw); - - /* Set FIFO control: enable FIFOs, clear RX/TX FIFOs, 1-byte trigger */ - uart_write(UART_FCR, 0x07); - - /* MCR: assert OUT2 (gates the IRQ pin on PC-style 16550A), plus - * DTR/RTS for completeness. Mirrors Linux drivers/tty/serial/8250/ - * 8250_port.c: serial8250_do_startup() does the same. */ - uart_write(UART_MCR, UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); - - /* Enable UART receive-data-available interrupt */ - uart_write(UART_IER, UART_IER_RDI); - - /* Register IRQ handler with PLIC */ - uint32 irq = UART_IRQ; - if (node) { - /* Try to get IRQ number from FDT */ - const FdtProperty* irq_prop = node->get_prop("interrupts"); - if (irq_prop && irq_prop->len >= 4) { - const uint8* val = static_cast(irq_prop->value); - irq = (uint32(val[0]) << 24) | (uint32(val[1]) << 16) | - (uint32(val[2]) << 8) | val[3]; - } - } - - g_irq_manager.register_handler(irq, uart_irq_handler, tty); - g_irq_manager.enable(irq); - - printk(KERN_INFO "uart_tty_init: base=0x%llx irq=%u IER=0x%x LSR=0x%x\n", - (unsigned long long)uart_pa, irq, - uart_read(UART_IER), uart_read(UART_LSR)); -} diff --git a/drivers/uart.cc b/drivers/uart.cc deleted file mode 100644 index 467b496..0000000 --- a/drivers/uart.cc +++ /dev/null @@ -1,181 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * uart.cc — 16550a UART driver + console registry - * - * Two roles: - * 1. Early console: early_putc() for pre-init output (panic, kprintf) - * 2. Runtime console: struct console registered with register_console(). - * klog/printk route through console_write_all() → uart_console_write(). - * - * The console registry is a simple linked list of struct console. - * console_write_all() iterates the list and calls each console's write(). - * If no console is registered, it falls back to early_putc(). - * - * Reference: Linux kernel/printk/printk.c, drivers/tty/serial/8250/ - */ - -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* UART state */ -/* ================================================================== */ - -static uint64 g_uart_pa = 0; -static uint64 g_uart_size = 0; -static bool g_runtime_mapping_ready = false; -static bool g_mmu_enabled = false; - -/* ================================================================== */ -/* Early console (Phase 1) */ -/* ================================================================== */ - -extern "C" void console_set_mmu_enabled() { - g_mmu_enabled = true; -} - -extern "C" void early_putc(char c) { - if (!g_uart_pa) return; - - /* - * Before vmm_init() activates the final page table, UART MMIO is only - * reachable via the bootstrap fixed direct map from entry.S. - * After activation, switch to the runtime (possibly KASLR-slid) base. - */ - uint64 uart_va = 0; - if (g_runtime_mapping_ready) { - uart_va = pa_to_va(phys_addr(g_uart_pa)).raw; - } else if (!g_mmu_enabled) { - uart_va = g_uart_pa; - } else { - uart_va = boot_pa_to_va(phys_addr(g_uart_pa)).raw; - } - - volatile auto* uart = reinterpret_cast(uart_va); - *uart = static_cast(c); -} - -extern "C" void early_puts(const char* s) { - while (*s) early_putc(*s++); -} - -void console_early_init(uint64 fdt_paddr) { - uint64 pa = 0; - uint64 size = 0; - FdtManager::early_scan_uart(fdt_paddr, &pa, &size); - if (pa != 0) { - g_uart_pa = pa; - if (size != 0) g_uart_size = size; - } -} - -void console_init() { - /* - * Once vmm_init() activates the new page table, the 1GB identity map is dropped. - * The UART must be explicitly registered into the active page table. - */ - if (g_uart_pa != 0 && g_uart_size != 0) { - vmm_map_kernel_mmio(g_uart_pa, g_uart_size); - } -} - -void console_use_runtime_mapping() { - g_runtime_mapping_ready = true; -} - -/* ================================================================== */ -/* Console registry (Phase 2) — linked list of struct console */ -/* ================================================================== */ - -static list_node g_console_list; -static bool g_console_list_init = false; - -void register_console(console* con) -{ - if (!con) return; - - if (!g_console_list_init) { - g_console_list.init(); - g_console_list_init = true; - } - - con->flags |= CON_ENABLED; - con->list.init(); - - /* Insert at tail */ - list_add_tail(&con->list, &g_console_list); -} - -void unregister_console(console* con) -{ - if (!con) return; - - list_del_init(&con->list); - con->flags &= ~CON_ENABLED; -} - -bool console_drivers_registered() -{ - if (!g_console_list_init) return false; - return !list_empty(&g_console_list); -} - -void console_write_all(const char* s, int count) -{ - if (g_console_list_init && !list_empty(&g_console_list)) { - list_node* pos; - list_for_each(pos, &g_console_list) { - auto* con = container_of(pos, console, list); - if ((con->flags & CON_ENABLED) && con->write) { - con->write(con, s, static_cast(count)); - } - } - } else { - /* Fallback: direct early_putc (pre-registration) */ - for (int i = 0; i < count; i++) { - early_putc(s[i]); - } - } -} - -/* ================================================================== */ -/* UART console driver */ -/* ================================================================== */ - -static void uart_console_write(console* /*con*/, const char* s, unsigned int count) -{ - for (unsigned int i = 0; i < count; i++) { - if (s[i] == '\n') { - early_putc('\r'); - } - early_putc(s[i]); - } -} - -/* - * uart_console must be initialized at RUNTIME, not with static - * aggregate initializers. Reason: KASLR self-relocation processes - * .rela.dyn entries for simple pointer variables, but may not cover - * function pointer fields inside static aggregate initializers. - * A static `{ .write = uart_console_write }` would store the - * pre-relocation address, causing a crash when called. - */ -static console uart_console; - -void uart_register_console() -{ - uart_console.name = "ttyS"; - uart_console.write = uart_console_write; - uart_console.setup = nullptr; - uart_console.flags = CON_ENABLED | CON_BOOT; - uart_console.index = 0; - uart_console.data = nullptr; - uart_console.list.init(); - register_console(&uart_console); -} - diff --git a/fdt/Build.mk b/fdt/Build.mk deleted file mode 100644 index ee8be88..0000000 --- a/fdt/Build.mk +++ /dev/null @@ -1,4 +0,0 @@ -targets += fdt/core -target.fdt/core.kind := source-set -target.fdt/core.sources := fdt/fdt.cc fdt/device_node.cc - diff --git a/fdt/device_node.cc b/fdt/device_node.cc deleted file mode 100644 index 0c8ad46..0000000 --- a/fdt/device_node.cc +++ /dev/null @@ -1,166 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * device_node.cc — DeviceNode implementation - * - * Provides property lookup and child traversal for the unflattened - * device tree. After construction, the tree is globally read-only. - * - * Reference: docs/specs/fdt.md §3.2 - */ - -#include - -/* Minimal strcmp — no lib dependency */ -static bool str_eq(const char *a, const char *b) -{ - while (*a && *a == *b) { a++; b++; } - return *a == *b; -} - -/* ------------------------------------------------------------------ */ -/* Construction / Destruction */ -/* ------------------------------------------------------------------ */ - -DeviceNode::DeviceNode(DeviceNode *parent, const char *name) - : name_(name), parent_(parent) -{ - children_list_.init(); - props_list_.init(); - sibling_link_.init(); -} - -DeviceNode::~DeviceNode() -{ - /* Recursively delete children */ - list_node *cur = children_list_.next; - while (cur != &children_list_) { - list_node *next = cur->next; - /* Recover DeviceNode* from sibling_link_ offset */ - DeviceNode *child = list_entry(cur); - delete child; - cur = next; - } - - /* Delete properties */ - list_node *pc = props_list_.next; - while (pc != &props_list_) { - list_node *pn = pc->next; - FdtProperty *prop = reinterpret_cast( - reinterpret_cast(pc) - - __builtin_offsetof(FdtProperty, link)); - delete prop; - pc = pn; - } -} - -/* ------------------------------------------------------------------ */ -/* Tree construction (used by FdtManager::unflatten) */ -/* ------------------------------------------------------------------ */ - -void DeviceNode::add_child(DeviceNode *child) -{ - /* Append to end of children list */ - list_node *node = &child->sibling_link_; - node->prev = children_list_.prev; - node->next = &children_list_; - children_list_.prev->next = node; - children_list_.prev = node; -} - -void DeviceNode::add_prop(FdtProperty *prop) -{ - list_node *node = &prop->link; - node->prev = props_list_.prev; - node->next = &props_list_; - props_list_.prev->next = node; - props_list_.prev = node; -} - -/* ------------------------------------------------------------------ */ -/* Property access */ -/* ------------------------------------------------------------------ */ - -const FdtProperty *DeviceNode::get_prop(const char *name) const -{ - const list_node *cur = props_list_.next; - while (cur != &props_list_) { - const FdtProperty *prop = reinterpret_cast( - reinterpret_cast(cur) - - __builtin_offsetof(FdtProperty, link)); - if (str_eq(prop->name, name)) - return prop; - cur = cur->next; - } - return nullptr; -} - -/* Big-endian helpers for decoding property values */ -static inline uint32 be32(const void *p) -{ - const uint8 *b = static_cast(p); - return (uint32(b[0]) << 24) | (uint32(b[1]) << 16) | - (uint32(b[2]) << 8) | uint32(b[3]); -} - -static inline uint64 be64(const void *p) -{ - const uint8 *b = static_cast(p); - return (uint64(be32(b)) << 32) | uint64(be32(b + 4)); -} - -uint32 DeviceNode::get_prop_u32(const char *name, uint32 default_val) const -{ - const FdtProperty *p = get_prop(name); - if (!p || p->len < 4) - return default_val; - return be32(p->value); -} - -uint64 DeviceNode::get_prop_u64(const char *name, uint64 default_val) const -{ - const FdtProperty *p = get_prop(name); - if (!p) - return default_val; - if (p->len >= 8) - return be64(p->value); - if (p->len >= 4) - return be32(p->value); - return default_val; -} - -const char *DeviceNode::get_prop_string(const char *name) const -{ - const FdtProperty *p = get_prop(name); - if (!p || p->len == 0) - return nullptr; - return static_cast(p->value); -} - -/* ------------------------------------------------------------------ */ -/* Child traversal */ -/* ------------------------------------------------------------------ */ - -DeviceNode *DeviceNode::find_child(const char *name) -{ - list_node *cur = children_list_.next; - while (cur != &children_list_) { - DeviceNode *child = list_entry(cur); - if (str_eq(child->name_, name)) - return child; - cur = cur->next; - } - return nullptr; -} - -void DeviceNode::for_each_child(void (*callback)(DeviceNode *)) -{ - list_node *cur = children_list_.next; - while (cur != &children_list_) { - list_node *next = cur->next; - DeviceNode *child = list_entry(cur); - callback(child); - cur = next; - } -} diff --git a/fdt/fdt.cc b/fdt/fdt.cc deleted file mode 100644 index d44ebda..0000000 --- a/fdt/fdt.cc +++ /dev/null @@ -1,625 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * fdt.cc — Flattened Device Tree parser implementation - * - * Implements the two-phase FDT parsing strategy described in fdt.md: - * - * Phase 1 (Early Scan): - * Static methods that linearly walk the raw FDT blob in-place, - * performing zero memory allocation. Called before PMM/Slab exist. - * - * Phase 2 (Unflatten): - * Builds a persistent DeviceNode C++ object tree using Slab. - * Stub implementation — will be completed when Slab is available. - * - * Reference: docs/specs/fdt.md - */ - -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Global singleton (Placement New pattern, see global_init.md §3.1) */ -/* ------------------------------------------------------------------ */ - -alignas(FdtManager) uint8 g_fdt_buf[sizeof(FdtManager)]; -FdtManager *g_fdt = nullptr; - -/* ------------------------------------------------------------------ */ -/* FDT binary format constants (DTSpec v0.4) */ -/* ------------------------------------------------------------------ */ - -struct fdt_header { - uint32 magic; - uint32 totalsize; - uint32 off_dt_struct; - uint32 off_dt_strings; - uint32 off_mem_rsvmap; - uint32 version; - uint32 last_comp_version; - uint32 boot_cpuid_phys; - uint32 size_dt_strings; - uint32 size_dt_struct; -}; - -#define FDT_MAGIC 0xd00dfeed -#define FDT_BEGIN_NODE 1 -#define FDT_END_NODE 2 -#define FDT_PROP 3 -#define FDT_NOP 4 -#define FDT_END 9 - -/* ------------------------------------------------------------------ */ -/* Minimal string helpers (no lib/ dependency for early boot) */ -/* ------------------------------------------------------------------ */ - -static inline bool str_starts_with(const char *str, const char *prefix) { - while (*prefix) { - if (*str++ != *prefix++) - return false; - } - return true; -} - -static inline bool str_equals(const char *s1, const char *s2) { - while (*s1 && *s1 == *s2) { - s1++; - s2++; - } - return *s1 == *s2; -} - -/* - * Check whether a null-separated string list (e.g. the "compatible" - * property) contains @target. - */ -static bool prop_contains_string(const char *prop_val, uint32 len, - const char *target) { - uint32 i = 0; - while (i < len) { - const char *s = prop_val + i; - if (str_equals(s, target)) - return true; - while (i < len && prop_val[i] != '\0') - i++; - i++; // skip '\0' separator - } - return false; -} - -/* ------------------------------------------------------------------ */ -/* Byte-swap helpers */ -/* ------------------------------------------------------------------ */ - -/* - * Manual 32-bit big-endian to little-endian conversion. - * We cannot use __builtin_bswap32 because on RISC-V without the Zbb - * extension the compiler emits a call to libgcc's __bswapsi2, which - * is unavailable in a freestanding (-nostdlib) environment. - */ -static inline uint32 bswap32(uint32 x) { - return ((x & 0xFF000000u) >> 24) | ((x & 0x00FF0000u) >> 8) | - ((x & 0x0000FF00u) << 8) | ((x & 0x000000FFu) << 24); -} - -/* - * Read a big-endian cell value from the FDT struct block. - * @cells: number of 32-bit cells (1 or 2). - * 2-cell values are common for 64-bit addresses/sizes. - */ -static inline uint64 read_cells(const uint8 *data, uint32 cells) { - const uint32 *p = reinterpret_cast(data); - if (cells == 2) { - uint64 high = bswap32(p[0]); - uint64 low = bswap32(p[1]); - return (high << 32) | low; - } - return bswap32(p[0]); -} - -/* ------------------------------------------------------------------ */ -/* FdtManager construction */ -/* ------------------------------------------------------------------ */ - -FdtManager::FdtManager(uint64 fdt_paddr) - : fdt_paddr_(fdt_paddr) {} - -/* ------------------------------------------------------------------ */ -/* Phase 1: Early scan — memory layout */ -/* ------------------------------------------------------------------ */ - -/* - * Walk the raw FDT struct block to locate the /memory node and - * extract its "reg" property (base address + size). - * - * Cell sizes (#address-cells, #size-cells) are tracked per depth - * level to correctly decode the "reg" value under any bus topology. - * - * Panics on invalid magic or missing /memory node — there is no - * recovery path this early in boot. - */ -void FdtManager::early_scan_mem(uint64 fdt_paddr, uint64 *base, uint64 *size) { - const fdt_header *hdr = reinterpret_cast(fdt_paddr); - if (bswap32(hdr->magic) != FDT_MAGIC) - kernel_panic("FDT early_scan_mem: invalid magic number", nullptr); - - const uint8 *dt_struct = - reinterpret_cast(fdt_paddr) + bswap32(hdr->off_dt_struct); - const char *dt_strings = - reinterpret_cast(fdt_paddr) + bswap32(hdr->off_dt_strings); - - uint32 offset = 0; - int depth = -1; - - // Per-depth cell sizes (inherit from parent on entry) - uint32 address_cells[16] = {2}; - uint32 size_cells[16] = {1}; - bool in_memory_node = false; - - while (true) { - uint32 token = - bswap32(*reinterpret_cast(dt_struct + offset)); - offset += 4; - - if (token == FDT_BEGIN_NODE) { - const char *name = reinterpret_cast(dt_struct + offset); - uint32 name_len = 0; - while (name[name_len] != '\0') - name_len++; - offset = (offset + name_len + 1 + 3) & ~3u; // align to 4 bytes - - depth++; - - // Inherit parent's cell sizes - if (depth > 0 && depth < 16) { - address_cells[depth] = address_cells[depth - 1]; - size_cells[depth] = size_cells[depth - 1]; - } - - // Match top-level "memory" or "memory@..." nodes - in_memory_node = (depth == 1 && str_starts_with(name, "memory")); - - } else if (token == FDT_END_NODE) { - if (depth >= 0) - depth--; - in_memory_node = false; - - } else if (token == FDT_PROP) { - uint32 len = - bswap32(*reinterpret_cast(dt_struct + offset)); - uint32 nameoff = - bswap32(*reinterpret_cast(dt_struct + offset + 4)); - offset += 8; - - const char *prop_name = dt_strings + nameoff; - const uint8 *prop_val = dt_struct + offset; - - if (depth >= 0 && depth < 16) { - // Track cell size overrides at the current depth - if (str_equals(prop_name, "#address-cells")) { - address_cells[depth] = - bswap32(*reinterpret_cast(prop_val)); - } else if (str_equals(prop_name, "#size-cells")) { - size_cells[depth] = - bswap32(*reinterpret_cast(prop_val)); - } - // Decode the "reg" property using the parent's cell sizes - else if (in_memory_node && str_equals(prop_name, "reg")) { - uint32 p_depth = (depth > 0) ? depth - 1 : 0; - *base = read_cells(prop_val, address_cells[p_depth]); - *size = read_cells(prop_val + address_cells[p_depth] * 4, - size_cells[p_depth]); - return; // Success - } - } - - offset = (offset + len + 3) & ~3u; // align to 4 bytes - - } else if (token == FDT_NOP) { - continue; - } else if (token == FDT_END) { - break; - } else { - kernel_panic("FDT early_scan_mem: unknown token", nullptr); - } - } - - kernel_panic("FDT early_scan_mem: /memory node not found", nullptr); -} - -/* ------------------------------------------------------------------ */ -/* Phase 1: Early scan — UART address */ -/* ------------------------------------------------------------------ */ - -/* - * Locate a UART node by matching compatible = "ns16550a" and return - * its base address from the "reg" property. - * - * Unlike early_scan_mem, failure here is non-fatal: we fall back to - * the platform's default UART address (0x10000000 for QEMU virt). - */ -void FdtManager::early_scan_uart(uint64 fdt_paddr, uint64 *uart_addr, - uint64 *uart_size) { - if (!uart_addr || !uart_size) - return; - - auto set_default_uart = [uart_addr, uart_size]() { - *uart_addr = 0x10000000ULL; - *uart_size = 0x100; - }; - - const fdt_header *hdr = reinterpret_cast(fdt_paddr); - if (bswap32(hdr->magic) != FDT_MAGIC) { - set_default_uart(); - return; - } - - const uint8 *dt_struct = - reinterpret_cast(fdt_paddr) + bswap32(hdr->off_dt_struct); - const char *dt_strings = - reinterpret_cast(fdt_paddr) + bswap32(hdr->off_dt_strings); - - uint32 offset = 0; - int depth = -1; - uint32 address_cells[16] = {2}; - uint32 size_cells[16] = {1}; - bool in_uart_node = false; - bool has_current_node_reg = false; - uint64 current_node_reg = 0; - uint64 current_node_size = 0; - - while (true) { - uint32 token = - bswap32(*reinterpret_cast(dt_struct + offset)); - offset += 4; - - if (token == FDT_BEGIN_NODE) { - const char *name = reinterpret_cast(dt_struct + offset); - uint32 name_len = 0; - while (name[name_len] != '\0') - name_len++; - offset = (offset + name_len + 1 + 3) & ~3u; - - depth++; - if (depth > 0 && depth < 16) { - address_cells[depth] = address_cells[depth - 1]; - size_cells[depth] = size_cells[depth - 1]; - } - in_uart_node = false; - has_current_node_reg = false; - - } else if (token == FDT_END_NODE) { - if (depth >= 0) - depth--; - in_uart_node = false; - has_current_node_reg = false; - - } else if (token == FDT_PROP) { - uint32 len = - bswap32(*reinterpret_cast(dt_struct + offset)); - uint32 nameoff = - bswap32(*reinterpret_cast(dt_struct + offset + 4)); - offset += 8; - - const char *prop_name = dt_strings + nameoff; - const uint8 *prop_val = dt_struct + offset; - - if (depth >= 0 && depth < 16) { - if (str_equals(prop_name, "#address-cells")) { - address_cells[depth] = - bswap32(*reinterpret_cast(prop_val)); - } else if (str_equals(prop_name, "#size-cells")) { - size_cells[depth] = - bswap32(*reinterpret_cast(prop_val)); - } else if (str_equals(prop_name, "compatible")) { - if (prop_contains_string(reinterpret_cast(prop_val), - len, "ns16550a")) { - in_uart_node = true; - if (has_current_node_reg) { - *uart_addr = current_node_reg; - *uart_size = current_node_size; - return; - } - } - } else if (str_equals(prop_name, "reg")) { - uint32 p_depth = (depth > 0) ? depth - 1 : 0; - current_node_reg = read_cells(prop_val, address_cells[p_depth]); - current_node_size = read_cells(prop_val + address_cells[p_depth] * 4, - size_cells[p_depth]); - has_current_node_reg = true; - if (in_uart_node) { - *uart_addr = current_node_reg; - *uart_size = current_node_size; - return; // Found it - } - } - } - - offset = (offset + len + 3) & ~3u; - - } else if (token == FDT_NOP) { - continue; - } else if (token == FDT_END) { - break; - } else { - break; // Unknown token — give up silently - } - } - - set_default_uart(); -} - -/* ------------------------------------------------------------------ */ -/* Phase 2: Unflatten (stub — requires Slab) */ -/* ------------------------------------------------------------------ */ - -void FdtManager::unflatten() { - const uint64 fdt_va = pa_to_va(phys_addr(fdt_paddr_)).raw; - const fdt_header *hdr = reinterpret_cast(fdt_va); - if (bswap32(hdr->magic) != FDT_MAGIC) - kernel_panic("fdt unflatten: invalid magic", nullptr); - - const uint8 *dt_struct = - reinterpret_cast(fdt_va) + bswap32(hdr->off_dt_struct); - const char *dt_strings = - reinterpret_cast(fdt_va) + bswap32(hdr->off_dt_strings); - - uint32 offset = 0; - - /* Stack to track current node at each depth (max 16 levels) */ - DeviceNode *stack[16] = {}; - int depth = -1; - - while (true) { - uint32 token = - bswap32(*reinterpret_cast(dt_struct + offset)); - offset += 4; - - if (token == FDT_BEGIN_NODE) { - const char *name = reinterpret_cast(dt_struct + offset); - uint32 name_len = 0; - while (name[name_len] != '\0') - name_len++; - offset = (offset + name_len + 1 + 3) & ~3u; - - depth++; - if (depth >= 16) - kernel_panic("fdt unflatten: tree too deep", nullptr); - - DeviceNode *parent = (depth > 0) ? stack[depth - 1] : nullptr; - DeviceNode *node = new DeviceNode(parent, name); - if (!node) - kernel_panic("fdt unflatten: OOM creating DeviceNode", nullptr); - - stack[depth] = node; - - if (parent) - parent->add_child(node); - else - root_ = node; /* Root node */ - - } else if (token == FDT_END_NODE) { - if (depth >= 0) - depth--; - - } else if (token == FDT_PROP) { - uint32 len = - bswap32(*reinterpret_cast(dt_struct + offset)); - uint32 nameoff = - bswap32(*reinterpret_cast(dt_struct + offset + 4)); - offset += 8; - - const char *prop_name = dt_strings + nameoff; - const void *prop_val = dt_struct + offset; - - if (depth >= 0 && depth < 16 && stack[depth]) { - FdtProperty *prop = new FdtProperty; - if (!prop) - kernel_panic("fdt unflatten: OOM creating FdtProperty", nullptr); - prop->name = prop_name; - prop->value = prop_val; - prop->len = static_cast(len); - prop->link.init(); - stack[depth]->add_prop(prop); - } - - offset = (offset + len + 3) & ~3u; - - } else if (token == FDT_NOP) { - continue; - } else if (token == FDT_END) { - break; - } else { - kernel_panic("fdt unflatten: unknown token", nullptr); - } - } - - is_unflattened_ = true; -} - -/* Recursive helper: find first node with matching compatible string */ -static DeviceNode *find_compat_recursive(DeviceNode *node, const char *compat) { - const FdtProperty *prop = node->get_prop("compatible"); - if (prop) { - const char *val = static_cast(prop->value); - uint32 i = 0; - while (i < static_cast(prop->len)) { - const char *s = val + i; - if (str_equals(s, compat)) - return node; - while (i < static_cast(prop->len) && val[i] != '\0') - i++; - i++; - } - } - - /* Search children */ - list_node *cur = node->children_list_head(); - list_node *end = node->children_list_sentinel(); - while (cur != end) { - DeviceNode *child = list_entry(cur); - DeviceNode *found = find_compat_recursive(child, compat); - if (found) - return found; - cur = cur->next; - } - return nullptr; -} - -DeviceNode *FdtManager::find_compatible(const char *compat_string) { - if (!is_unflattened_) - kernel_panic("fdt: tree not unflattened yet", nullptr); - if (!root_) - return nullptr; - return find_compat_recursive(root_, compat_string); -} - -DeviceNode *FdtManager::get_node_by_path(const char *path) { - if (!is_unflattened_) - kernel_panic("fdt: tree not unflattened yet", nullptr); - if (!root_ || !path) - return nullptr; - - /* Skip leading '/' */ - if (*path == '/') - path++; - if (*path == '\0') - return root_; - - DeviceNode *cur = root_; - while (*path && cur) { - /* Extract next path component */ - const char *end = path; - while (*end && *end != '/') - end++; - - /* Search children for a name matching this component */ - bool found = false; - list_node *lc = cur->children_list_head(); - list_node *le = cur->children_list_sentinel(); - while (lc != le) { - DeviceNode *child = - list_entry(lc); - /* Compare name up to the component length */ - const char *cn = child->get_name(); - const char *p = path; - const char *e = end; - bool match = true; - while (p < e) { - if (*cn != *p) { - match = false; - break; - } - cn++; - p++; - } - if (match && *cn == '\0') { - cur = child; - found = true; - break; - } - lc = lc->next; - } - - if (!found) - return nullptr; - - path = (*end == '/') ? end + 1 : end; - } - return cur; -} - -/* ------------------------------------------------------------------ */ -/* Public free-function API */ -/* ------------------------------------------------------------------ */ - -void fdt_init(uint64 fdt_paddr) { - const uint32 *magic_ptr = reinterpret_cast(fdt_paddr); - if (bswap32(*magic_ptr) != FDT_MAGIC) - kernel_panic("fdt_init: invalid FDT magic number", nullptr); - - g_fdt = new (g_fdt_buf) FdtManager(fdt_paddr); -} - -void fdt_unflatten() { g_fdt->unflatten(); } - -DeviceNode *fdt_find_compatible(const char *compat_string) { - return g_fdt->find_compatible(compat_string); -} - -DeviceNode *fdt_get_node_by_path(const char *path) { - return g_fdt->get_node_by_path(path); -} - -void fdt_early_get_mem_info(uint64 *base, uint64 *size) { - FdtManager::early_scan_mem(g_fdt->get_paddr(), base, size); -} - -void fdt_early_get_uart_info(uint64 *uart_addr, uint64 *uart_size) { - FdtManager::early_scan_uart(g_fdt->get_paddr(), uart_addr, uart_size); -} - -void FdtManager::early_scan_kaslr(uint64 fdt_paddr, uint64 *seed) -{ - if (!seed) return; - *seed = 0; - - const fdt_header *hdr = reinterpret_cast(fdt_paddr); - if (bswap32(hdr->magic) != FDT_MAGIC) return; - - const uint8 *dt_struct = reinterpret_cast(fdt_paddr) + bswap32(hdr->off_dt_struct); - const char *dt_strings = reinterpret_cast(fdt_paddr) + bswap32(hdr->off_dt_strings); - - uint32 offset = 0; - int depth = -1; - bool in_chosen = false; - - while (true) { - uint32 token = bswap32(*reinterpret_cast(dt_struct + offset)); - offset += 4; - - if (token == FDT_BEGIN_NODE) { - const char *name = reinterpret_cast(dt_struct + offset); - uint32 name_len = 0; - while (name[name_len] != '\0') name_len++; - offset = (offset + name_len + 1 + 3) & ~3u; - - depth++; - if (depth == 1 && str_starts_with(name, "chosen")) { - in_chosen = true; - } else if (depth == 1) { - in_chosen = false; - } - } else if (token == FDT_END_NODE) { - if (depth >= 0) depth--; - if (depth < 1) in_chosen = false; - } else if (token == FDT_PROP) { - uint32 len = bswap32(*reinterpret_cast(dt_struct + offset)); - uint32 nameoff = bswap32(*reinterpret_cast(dt_struct + offset + 4)); - offset += 8; - - if (in_chosen) { - const char *prop_name = dt_strings + nameoff; - if (str_starts_with(prop_name, "kaslr-seed") && len == 8) { - *seed = read_cells(dt_struct + offset, 2); - return; - } - } - offset = (offset + len + 3) & ~3u; - } else if (token == FDT_NOP) { - continue; - } else if (token == FDT_END) { - break; - } else { - break; - } - } -} - -void fdt_early_get_kaslr_seed(uint64 *seed) { - FdtManager::early_scan_kaslr(g_fdt->get_paddr(), seed); -} diff --git a/fs/Build.mk b/fs/Build.mk deleted file mode 100644 index 057d1df..0000000 --- a/fs/Build.mk +++ /dev/null @@ -1,8 +0,0 @@ -targets += fs/core -target.fs/core.kind := source-set -target.fs/core.sources := \ - fs/super.cc fs/inode.cc fs/dcache.cc fs/file_table.cc fs/fd.cc \ - fs/fs_struct.cc fs/namei.cc fs/ramfs/inode.cc fs/ramfs/file.cc \ - fs/ramfs/super.cc fs/vfs_init.cc fs/chardev.cc fs/devfs.cc fs/pipe.cc \ - fs/initramfs.cc - diff --git a/fs/chardev.cc b/fs/chardev.cc deleted file mode 100644 index fa96276..0000000 --- a/fs/chardev.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * chardev.cc — Character device registry - * - * Simple linked list of registered cdevs, searched by dev number. - */ - -#include -#include -#include -#include - -static list_node g_cdev_list; -static Spinlock g_cdev_lock; - -void cdev_init() -{ - list_init(&g_cdev_list); -} - -void cdev_register(cdev* dev) -{ - LockGuard guard(g_cdev_lock); - list_init(&dev->list); - list_add_tail(&dev->list, &g_cdev_list); - printk("[cdev] registered '%s' (%d,%d)\n", - dev->name, MAJOR(dev->dev), MINOR(dev->dev)); -} - -cdev* cdev_find(uint32 dev_nr) -{ - LockGuard guard(g_cdev_lock); - list_node* pos; - for (pos = g_cdev_list.prev; pos != &g_cdev_list; pos = pos->prev) { - cdev* cd = container_of(pos, cdev, list); - if (cd->dev == dev_nr) { - return cd; - } - } - return nullptr; -} diff --git a/fs/dcache.cc b/fs/dcache.cc deleted file mode 100644 index 94ab287..0000000 --- a/fs/dcache.cc +++ /dev/null @@ -1,287 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * dcache.cc — Directory entry cache - * - * Provides dentry allocation, lookup, instantiation, and d_path. - */ - -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* Hash function */ -/* ================================================================== */ - -uint32 full_name_hash(const char* name, uint32 len) -{ - uint32 hash = 0; - for (uint32 i = 0; i < len; i++) - hash = hash * 31 + static_cast(name[i]); - return hash; -} - -/* ================================================================== */ -/* d_set_type — set DCACHE_*_TYPE bits from inode mode */ -/* ================================================================== */ - -void d_set_type(dentry* de, uint32 i_mode) -{ - de->d_flags &= ~DCACHE_ENTRY_TYPE; - - if (S_ISDIR(i_mode)) - de->d_flags |= DCACHE_DIRECTORY_TYPE; - else if (S_ISLNK(i_mode)) - de->d_flags |= DCACHE_SYMLINK_TYPE; - else if (S_ISREG(i_mode)) - de->d_flags |= DCACHE_REGULAR_TYPE; - else - de->d_flags |= DCACHE_SPECIAL_TYPE; -} - -/* ================================================================== */ -/* d_alloc — allocate a dentry under a parent */ -/* ================================================================== */ - -static void dentry_init(dentry* de, dentry* parent, const qstr* name) -{ - de->d_flags = DCACHE_MISS_TYPE; /* negative until instantiated */ - de->d_parent = parent ? parent : de; - de->d_inode = nullptr; - de->d_op = nullptr; - de->d_sb = parent ? parent->d_sb : nullptr; - de->d_time = 0; - de->d_fsdata = nullptr; - de->d_lockref.store(1); - - list_init(&de->d_lru); - list_init(&de->d_child); - list_init(&de->d_children); - list_init(&de->d_alias); - - /* Copy name */ - if (name && name->name && name->len > 0) { - uint32 len = name->len; - if (len < DNAME_INLINE_LEN) { - for (uint32 i = 0; i < len; i++) - de->d_iname[i] = name->name[i]; - de->d_iname[len] = '\0'; - de->d_name.name = reinterpret_cast(de->d_iname); - } else { - /* Heap-allocate for long names */ - char* buf = new char[len + 1]; - for (uint32 i = 0; i < len; i++) - buf[i] = name->name[i]; - buf[len] = '\0'; - de->d_name.name = buf; - } - de->d_name.len = len; - de->d_name.hash = name->hash ? name->hash : full_name_hash(name->name, len); - } else { - de->d_iname[0] = '\0'; - de->d_name.name = reinterpret_cast(de->d_iname); - de->d_name.len = 0; - de->d_name.hash = 0; - } -} - -dentry* d_alloc(dentry* parent, const qstr* name) -{ - auto* de = new dentry{}; - if (!de) return nullptr; - - dentry_init(de, parent, name); - de->d_sb = parent->d_sb; - - /* Use sb default d_op if set */ - if (parent->d_sb->s_d_op) - de->d_op = parent->d_sb->s_d_op; - - /* Link into parent's children list */ - if (parent) { - LockGuard guard(parent->d_lock); - list_add_tail(&de->d_child, &parent->d_children); - dget(parent); /* child holds ref on parent */ - } - - return de; -} - -dentry* d_alloc_anon(super_block* sb) -{ - auto* de = new dentry{}; - if (!de) return nullptr; - - dentry_init(de, nullptr, nullptr); - de->d_sb = sb; - de->d_parent = de; /* root: parent is self */ - - return de; -} - -/* ================================================================== */ -/* d_instantiate — bind an inode to a dentry */ -/* ================================================================== */ - -void d_instantiate(dentry* de, inode* ip) -{ - if (!ip) return; - - LockGuard guard(de->d_lock); - de->d_inode = ip; - d_set_type(de, ip->i_mode); - - /* Add to inode's alias list */ - list_add_tail(&de->d_alias, &ip->i_dentry); -} - -/* ================================================================== */ -/* d_make_root — create root dentry for a superblock */ -/* ================================================================== */ - -dentry* d_make_root(inode* root_inode) -{ - if (!root_inode) return nullptr; - - dentry* de = d_alloc_anon(root_inode->i_sb); - if (!de) { - iput(root_inode); - return nullptr; - } - - d_instantiate(de, root_inode); - return de; -} - -/* ================================================================== */ -/* d_add — combined d_instantiate + d_rehash */ -/* ================================================================== */ - -void d_add(dentry* de, inode* ip) -{ - d_instantiate(de, ip); - /* d_rehash would add to dcache hash table; simplified for now */ -} - -/* ================================================================== */ -/* d_lookup — search children of parent for a name match */ -/* ================================================================== */ - -dentry* d_lookup(const dentry* parent, const qstr* name) -{ - LockGuard guard(const_cast(parent->d_lock)); - - list_node* pos; - list_for_each(pos, &parent->d_children) { - dentry* child = list_entry(pos, dentry, d_child); - - if (child->d_name.len != name->len) - continue; - - /* Compare names */ - const char* a = child->d_name.name; - const char* b = name->name; - uint32 len = name->len; - bool match = true; - for (uint32 i = 0; i < len; i++) { - if (a[i] != b[i]) { match = false; break; } - } - if (match) { - dget(child); - return child; - } - } - - return nullptr; -} - -/* ================================================================== */ -/* dget / dput — dentry reference counting */ -/* ================================================================== */ - -dentry* dget(dentry* de) -{ - if (de) - de->d_lockref.fetch_add(1); - return de; -} - -void dput(dentry* de) -{ - if (!de) return; - - int old = de->d_lockref.fetch_sub(1); - if (old > 1) return; - - /* Last reference — could free, but for ramfs we keep dentries alive. - * A real implementation would check d_op->d_delete and possibly - * add to LRU for later reclaim. For now, just leak (Phase 1). */ -} - -/* ================================================================== */ -/* d_drop / d_delete */ -/* ================================================================== */ - -void d_drop(dentry* de) -{ - /* Remove from parent's children list */ - LockGuard guard(de->d_lock); - if (!list_empty(&de->d_child)) - list_del_init(&de->d_child); -} - -void d_delete(dentry* de) -{ - d_drop(de); -} - -/* ================================================================== */ -/* d_path — build absolute pathname from a path */ -/* ================================================================== */ - -char* d_path(const path* p, char* buf, int buflen) -{ - if (!p || !p->de || buflen <= 0) - return nullptr; - - /* Build path by walking up d_parent chain, writing backwards */ - char* end = buf + buflen - 1; - *end = '\0'; - - dentry* de = p->de; - - if (d_is_root(de)) { - if (end <= buf) return nullptr; - *(--end) = '/'; - return end; - } - - while (!d_is_root(de)) { - uint32 len = de->d_name.len; - end -= len; - if (end <= buf) return nullptr; - - const char* name = de->d_name.name; - for (uint32 i = 0; i < len; i++) - end[i] = name[i]; - - *(--end) = '/'; - de = de->d_parent; - } - - return end; -} - -/* ================================================================== */ -/* dcache_init */ -/* ================================================================== */ - -void dcache_init() -{ - /* Future: init dcache hash table */ -} diff --git a/fs/devfs.cc b/fs/devfs.cc deleted file mode 100644 index b4b2cf3..0000000 --- a/fs/devfs.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * devfs.cc — /dev population and chardev-aware open - * - * Creates /dev as a subdirectory under the ramfs root, then - * populates device nodes. On open(), if the inode is S_IFCHR, - * we look up the cdev by i_rdev and use its fops. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* devfs_create_node — create a char device inode under parent */ -/* ================================================================== */ - -static int devfs_create_node(dentry* parent, const char* name, - uint32 major, uint32 minor) -{ - inode* dir_ip = parent->d_inode; - if (!dir_ip || !dir_ip->i_op || !dir_ip->i_op->mknod) { - return -EPERM; - } - - qstr q{}; - q.name = name; - q.len = 0; - for (const char* s = name; *s; s++) { - q.len++; - } - - dentry* de = d_alloc(parent, &q); - if (!de) { - return -ENOMEM; - } - - int err = dir_ip->i_op->mknod(dir_ip, de, S_IFCHR | 0666, - MKDEV(major, minor)); - if (err) { - return err; - } - - return 0; -} - -/* ================================================================== */ -/* devfs_open — chardev-aware open hook */ -/* ================================================================== */ - -/* - * Called from sys_openat when the inode is S_IFCHR. - * Replaces f_op with the chardev's file_operations. - */ -int devfs_chrdev_open(inode* ip, file* fp) -{ - if (!S_ISCHR(ip->i_mode)) { - return 0; - } - - cdev* cd = cdev_find(ip->i_rdev); - if (!cd || !cd->fops) { - return -ENXIO; /* No such device */ - } - - fp->f_op = cd->fops; - - /* Call the device's own open if it has one */ - if (fp->f_op->open) { - return fp->f_op->open(ip, fp); - } - - return 0; -} - -/* ================================================================== */ -/* devfs_init — create /dev and populate device nodes */ -/* ================================================================== */ - -void devfs_init() -{ - if (!g_root_dentry || !g_root_dentry->d_inode) { - printk(KERN_ERR "[devfs] no root filesystem!\n"); - return; - } - - /* Create /dev directory — or reuse if initramfs already created it. - * Linux: devtmpfs similarly handles pre-existing directories. */ - inode* root_ip = g_root_dentry->d_inode; - - qstr dev_name{}; - dev_name.name = "dev"; - dev_name.len = 3; - dev_name.hash = full_name_hash("dev", 3); - - dentry* dev_de = d_lookup(g_root_dentry, &dev_name); - if (dev_de) { - /* /dev already exists (from initramfs) — reuse it */ - printk("[devfs] reusing existing /dev directory\n"); - } else { - /* Create /dev from scratch */ - if (!root_ip->i_op || !root_ip->i_op->mkdir) { - printk(KERN_ERR "[devfs] root has no mkdir!\n"); - return; - } - - dev_de = d_alloc(g_root_dentry, &dev_name); - if (!dev_de) { - printk(KERN_ERR "[devfs] failed to alloc /dev dentry\n"); - return; - } - - int err = root_ip->i_op->mkdir(root_ip, dev_de, S_IFDIR | 0755); - if (err) { - printk(KERN_ERR "[devfs] mkdir /dev failed: %d\n", err); - return; - } - } - - /* Populate: /dev/console (5,1) */ - devfs_create_node(dev_de, "console", 5, 1); - - /* Populate: /dev/null (1,3) */ - devfs_create_node(dev_de, "null", 1, 3); - - /* Populate: /dev/zero (1,5) */ - devfs_create_node(dev_de, "zero", 1, 5); - - printk("[devfs] /dev populated (console, null, zero)\n"); -} diff --git a/fs/fd.cc b/fs/fd.cc deleted file mode 100644 index 5fc8ab0..0000000 --- a/fs/fd.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * fd.cc — File descriptor table management - */ - -#include -#include -#include -#include - -/* ================================================================== */ -/* Bitmap helpers */ -/* ================================================================== */ - -static inline bool bit_test(const uint64* bmap, int bit) { - return (bmap[bit / 64] >> (bit % 64)) & 1; -} -static inline void bit_set(uint64* bmap, int bit) { - bmap[bit / 64] |= (1ULL << (bit % 64)); -} -static inline void bit_clear(uint64* bmap, int bit) { - bmap[bit / 64] &= ~(1ULL << (bit % 64)); -} - -/* ================================================================== */ -/* alloc_files_struct */ -/* ================================================================== */ - -files_struct* alloc_files_struct() -{ - auto* files = new files_struct{}; - if (!files) return nullptr; - - files->count.store(1); - files->next_fd = 0; - files->max_fds = NR_OPEN_DEFAULT; - - for (int i = 0; i < NR_OPEN_DEFAULT; i++) - files->fd_array[i] = nullptr; - - int bmap_words = (NR_OPEN_DEFAULT + 63) / 64; - for (int i = 0; i < bmap_words; i++) { - files->close_on_exec_init[i] = 0; - files->open_fds_init[i] = 0; - } - - return files; -} - -/* ================================================================== */ -/* put_files_struct — drop reference, free on last */ -/* ================================================================== */ - -void put_files_struct(files_struct* files) -{ - if (!files) return; - - int old = files->count.fetch_sub(1); - if (old > 1) return; - - /* Close all open fds */ - for (int i = 0; i < files->max_fds; i++) { - if (files->fd_array[i]) { - fput(files->fd_array[i]); - files->fd_array[i] = nullptr; - } - } - - delete files; -} - -/* ================================================================== */ -/* dup_fd — duplicate entire fd table (for fork) */ -/* ================================================================== */ - -files_struct* dup_fd(files_struct* old_files) -{ - auto* new_files = alloc_files_struct(); - if (!new_files) return nullptr; - - LockGuard guard(old_files->file_lock); - - for (int i = 0; i < old_files->max_fds; i++) { - file* fp = old_files->fd_array[i]; - if (fp) { - get_file(fp); - new_files->fd_array[i] = fp; - } - } - - /* Copy bitmaps */ - int bmap_words = (NR_OPEN_DEFAULT + 63) / 64; - for (int i = 0; i < bmap_words; i++) { - new_files->open_fds_init[i] = old_files->open_fds_init[i]; - new_files->close_on_exec_init[i] = old_files->close_on_exec_init[i]; - } - - new_files->next_fd = old_files->next_fd; - - return new_files; -} - -/* ================================================================== */ -/* alloc_fd — find lowest free fd >= start */ -/* ================================================================== */ - -int alloc_fd(files_struct* files, unsigned int start) -{ - LockGuard guard(files->file_lock); - - for (int fd = static_cast(start); fd < files->max_fds; fd++) { - if (!bit_test(files->open_fds_init, fd)) { - bit_set(files->open_fds_init, fd); - files->fd_array[fd] = nullptr; /* placeholder, fd_install sets real file */ - if (fd >= files->next_fd) - files->next_fd = fd + 1; - return fd; - } - } - - return -EMFILE; -} - -/* ================================================================== */ -/* fd_install — place a file* at a given fd */ -/* ================================================================== */ - -void fd_install(files_struct* files, int fd, file* fp) -{ - LockGuard guard(files->file_lock); - files->fd_array[fd] = fp; -} - -/* ================================================================== */ -/* fcheck — look up file by fd (no refcount bump) */ -/* ================================================================== */ - -file* fcheck(files_struct* files, int fd) -{ - if (fd < 0 || fd >= files->max_fds) return nullptr; - return files->fd_array[fd]; -} - -/* ================================================================== */ -/* close_fd */ -/* ================================================================== */ - -int close_fd(files_struct* files, int fd) -{ - file* fp; - { - LockGuard guard(files->file_lock); - if (fd < 0 || fd >= files->max_fds) return -EBADF; - - fp = files->fd_array[fd]; - if (!fp) return -EBADF; - - files->fd_array[fd] = nullptr; - bit_clear(files->open_fds_init, fd); - bit_clear(files->close_on_exec_init, fd); - } - - fput(fp); - return 0; -} - -/* ================================================================== */ -/* do_dup2 — duplicate oldfd to newfd */ -/* ================================================================== */ - -int do_dup2(files_struct* files, int oldfd, int newfd, int flags) -{ - if (oldfd == newfd) return -EINVAL; - - file* existing = nullptr; - { - LockGuard guard(files->file_lock); - - if (oldfd < 0 || oldfd >= files->max_fds) return -EBADF; - if (newfd < 0 || newfd >= files->max_fds) return -EBADF; - - file* old_fp = files->fd_array[oldfd]; - if (!old_fp) return -EBADF; - - existing = files->fd_array[newfd]; - - get_file(old_fp); - files->fd_array[newfd] = old_fp; - bit_set(files->open_fds_init, newfd); - - if (flags & O_CLOEXEC) - bit_set(files->close_on_exec_init, newfd); - else - bit_clear(files->close_on_exec_init, newfd); - } - - if (existing) - fput(existing); - - return newfd; -} - -/* ================================================================== */ -/* do_close_on_exec — close all fds with CLOEXEC set */ -/* ================================================================== */ - -void do_close_on_exec(files_struct* files) -{ - for (int fd = 0; fd < files->max_fds; fd++) { - if (bit_test(files->close_on_exec_init, fd)) { - close_fd(files, fd); - } - } -} diff --git a/fs/file_table.cc b/fs/file_table.cc deleted file mode 100644 index 06095c1..0000000 --- a/fs/file_table.cc +++ /dev/null @@ -1,164 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * file_table.cc — Open file allocation and reference counting - */ - -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* alloc_empty_file */ -/* ================================================================== */ - -file* alloc_empty_file(int flags) -{ - auto* fp = new file{}; - if (!fp) return nullptr; - - fp->f_count.store(1); - fp->f_flags = flags; - fp->f_mode = 0; - fp->f_op = nullptr; - fp->f_mapping = nullptr; - fp->f_inode = nullptr; - fp->f_pos = 0; - fp->private_data = nullptr; - fp->f_path.mnt = nullptr; - fp->f_path.de = nullptr; - - /* Derive f_mode from O_* flags */ - int acc = flags & O_ACCMODE; - if (acc == O_RDONLY) - fp->f_mode = FMODE_READ | FMODE_CAN_READ; - else if (acc == O_WRONLY) - fp->f_mode = FMODE_WRITE | FMODE_CAN_WRITE; - else if (acc == O_RDWR) - fp->f_mode = FMODE_READ | FMODE_WRITE | FMODE_CAN_READ | FMODE_CAN_WRITE; - - fp->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; - - return fp; -} - -/* ================================================================== */ -/* get_file / fput */ -/* ================================================================== */ - -file* get_file(file* f) -{ - f->f_count.fetch_add(1); - return f; -} - -void fput(file* fp) -{ - if (!fp) return; - - int old = fp->f_count.fetch_sub(1); - if (old > 1) return; - - /* Last reference — release */ - if (fp->f_op && fp->f_op->release) - fp->f_op->release(fp->f_inode, fp); - - if (fp->f_path.de) - dput(fp->f_path.de); - - /* Future: mntput(fp->f_path.mnt) */ - - delete fp; -} - -/* ================================================================== */ -/* vfs_read / vfs_write / vfs_llseek / vfs_fstat */ -/* ================================================================== */ - -int64 vfs_read(file* fp, char* buf, uint64 count, int64* pos) -{ - if (!(fp->f_mode & FMODE_CAN_READ)) - return -EBADF; - if (!fp->f_op || !fp->f_op->read) - return -EINVAL; - - return fp->f_op->read(fp, buf, count, pos); -} - -int64 vfs_write(file* fp, const char* buf, uint64 count, int64* pos) -{ - if (!(fp->f_mode & FMODE_CAN_WRITE)) - return -EBADF; - if (!fp->f_op || !fp->f_op->write) - return -EINVAL; - - return fp->f_op->write(fp, buf, count, pos); -} - -int64 vfs_llseek(file* fp, int64 offset, int whence) -{ - if (fp->f_op && fp->f_op->llseek) - return fp->f_op->llseek(fp, offset, whence); - return generic_file_llseek(fp, offset, whence); -} - -int64 generic_file_llseek(file* fp, int64 offset, int whence) -{ - int64 new_pos; - switch (whence) { - case SEEK_SET: - new_pos = offset; - break; - case SEEK_CUR: - new_pos = fp->f_pos + offset; - break; - case SEEK_END: - new_pos = fp->f_inode->i_size + offset; - break; - default: - return -EINVAL; - } - - if (new_pos < 0) return -EINVAL; - fp->f_pos = new_pos; - return new_pos; -} - -int vfs_fstat(file* fp, kstat* stat) -{ - inode* ip = file_inode(fp); - if (!ip) return -EBADF; - - if (ip->i_op && ip->i_op->getattr) { - return ip->i_op->getattr(&fp->f_path, stat, 0, 0); - } - - generic_fillattr(ip, stat); - return 0; -} - -/* ================================================================== */ -/* path_get / path_put (simplified) */ -/* ================================================================== */ - -void path_get(const path* p) -{ - if (p->de) dget(p->de); - /* Future: mntget(p->mnt) */ -} - -void path_put(const path* p) -{ - if (p->de) dput(p->de); - /* Future: mntput(p->mnt) */ -} - -/* ================================================================== */ -/* mntget / mntput (stubs for Phase 1) */ -/* ================================================================== */ - -vfsmount* mntget(vfsmount* mnt) { return mnt; } -void mntput(vfsmount*) {} diff --git a/fs/fs_struct.cc b/fs/fs_struct.cc deleted file mode 100644 index 090819f..0000000 --- a/fs/fs_struct.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * fs_struct.cc — Per-task filesystem context (cwd, root) - */ - -#include -#include - -/* ================================================================== */ -/* alloc_fs_struct */ -/* ================================================================== */ - -fs_struct* alloc_fs_struct() -{ - auto* fs = new fs_struct{}; - if (!fs) return nullptr; - - fs->count.store(1); - fs->umask = 022; - fs->root = {nullptr, nullptr}; - fs->pwd = {nullptr, nullptr}; - - return fs; -} - -/* ================================================================== */ -/* put_fs_struct */ -/* ================================================================== */ - -void put_fs_struct(fs_struct* fs) -{ - if (!fs) return; - - int old = fs->count.fetch_sub(1); - if (old > 1) return; - - path_put(&fs->root); - path_put(&fs->pwd); - delete fs; -} - -/* ================================================================== */ -/* copy_fs_struct — for fork without CLONE_FS */ -/* ================================================================== */ - -fs_struct* copy_fs_struct(const fs_struct* old_fs) -{ - auto* fs = alloc_fs_struct(); - if (!fs) return nullptr; - - fs->umask = old_fs->umask; - - fs->root = old_fs->root; - path_get(&fs->root); - - fs->pwd = old_fs->pwd; - path_get(&fs->pwd); - - return fs; -} - -/* ================================================================== */ -/* set_fs_root / set_fs_pwd */ -/* ================================================================== */ - -void set_fs_root(fs_struct* fs, const path* p) -{ - path old_root; - { - LockGuard guard(fs->lock); - old_root = fs->root; - fs->root = *p; - path_get(p); - } - path_put(&old_root); -} - -void set_fs_pwd(fs_struct* fs, const path* p) -{ - path old_pwd; - { - LockGuard guard(fs->lock); - old_pwd = fs->pwd; - fs->pwd = *p; - path_get(p); - } - path_put(&old_pwd); -} diff --git a/fs/initramfs.cc b/fs/initramfs.cc deleted file mode 100644 index ba10a3e..0000000 --- a/fs/initramfs.cc +++ /dev/null @@ -1,285 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * initramfs.cc — Unpack embedded CPIO archive into ramfs - * - * The build system embeds a newc-format CPIO archive into the kernel - * ELF as the section .init.ramfs. The linker script exports - * __initramfs_start / __initramfs_end symbols. - * - * At boot, populate_rootfs() walks the CPIO entries and creates - * directories and files in the already-mounted ramfs root. - * - * Reference: Linux init/initramfs.c - * - * CPIO "newc" header format (110 bytes, ASCII hex fields): - * magic[6] "070701" - * ino[8] mode[8] uid[8] gid[8] nlink[8] mtime[8] - * filesize[8] devmajor[8] devminor[8] rdevmajor[8] rdevminor[8] - * namesize[8] check[8] - * filename (namesize bytes, NUL terminated, padded to 4-byte boundary) - * file data (filesize bytes, padded to 4-byte boundary) - */ - -#include -#include -#include -#include -#include -#include - -/* Linker-provided symbols for the embedded CPIO archive */ -extern "C" const char __initramfs_start[]; -extern "C" const char __initramfs_end[]; - -/* ramfs inode creation (from fs/ramfs/inode.cc) */ -extern inode* ramfs_get_inode(super_block* sb, const inode* dir, - uint32 mode, uint32 rdev); - -/* Global root dentry (from fs/vfs_init.cc) */ -extern dentry* g_root_dentry; - -/* ================================================================== */ -/* CPIO newc header parsing */ -/* ================================================================== */ - -struct cpio_header { - char magic[6]; - char ino[8]; - char mode[8]; - char uid[8]; - char gid[8]; - char nlink[8]; - char mtime[8]; - char filesize[8]; - char devmajor[8]; - char devminor[8]; - char rdevmajor[8]; - char rdevminor[8]; - char namesize[8]; - char check[8]; -}; - -static constexpr int kCpioHeaderSize = 110; - -static uint32 parse_hex8(const char* s) -{ - uint32 val = 0; - for (int i = 0; i < 8; i++) { - char c = s[i]; - uint32 nibble; - if (c >= '0' && c <= '9') nibble = c - '0'; - else if (c >= 'a' && c <= 'f') nibble = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') nibble = c - 'A' + 10; - else return val; - val = (val << 4) | nibble; - } - return val; -} - -static inline uint32 align4(uint32 v) -{ - return (v + 3) & ~3U; -} - -/* ================================================================== */ -/* Path resolution helpers */ -/* ================================================================== */ - -static dentry* cpio_mkdir_p(dentry* root, const char* path, - const char** out_name) -{ - dentry* cur = root; - - while (*path == '/') path++; - - while (true) { - const char* slash = path; - while (*slash && *slash != '/') slash++; - - if (*slash == '\0') { - *out_name = path; - return cur; - } - - uint32 len = static_cast(slash - path); - - qstr name; - name.name = path; - name.len = len; - name.hash = full_name_hash(path, len); - - dentry* child = d_lookup(cur, &name); - if (!child) { - child = d_alloc(cur, &name); - if (!child) return nullptr; - - inode* ip = ramfs_get_inode(cur->d_inode->i_sb, cur->d_inode, - S_IFDIR | 0755, 0); - if (!ip) return nullptr; - - d_instantiate(child, ip); - dget(child); - inc_nlink(cur->d_inode); - } - - cur = child; - path = slash + 1; - while (*path == '/') path++; - } -} - -/* ================================================================== */ -/* populate_rootfs — the main entry point */ -/* ================================================================== */ - -void populate_rootfs() -{ - const char* p = __initramfs_start; - const char* end = __initramfs_end; - uint64 archive_size = static_cast(end - p); - - if (archive_size == 0) { - printk("[initramfs] no embedded archive found\n"); - return; - } - - printk("[initramfs] unpacking %llu bytes...\n", archive_size); - - int file_count = 0; - int dir_count = 0; - - while (p + kCpioHeaderSize <= end) { - auto* hdr = reinterpret_cast(p); - - /* Verify magic */ - if (hdr->magic[0] != '0' || hdr->magic[1] != '7' || - hdr->magic[2] != '0' || hdr->magic[3] != '7' || - hdr->magic[4] != '0' || hdr->magic[5] != '1') { - printk("[initramfs] bad cpio magic at offset %llu\n", - static_cast(p - __initramfs_start)); - break; - } - - uint32 mode = parse_hex8(hdr->mode); - uint32 filesize = parse_hex8(hdr->filesize); - uint32 namesize = parse_hex8(hdr->namesize); - - const char* name = p + kCpioHeaderSize; - uint32 name_padded = align4(kCpioHeaderSize + namesize); - const char* data = p + name_padded; - uint32 data_padded = align4(filesize); - - const char* next = p + name_padded + data_padded; - - /* Check for TRAILER!!! end-of-archive marker */ - if (namesize == 11 && name[0] == 'T' && name[1] == 'R' && - name[2] == 'A' && name[3] == 'I' && name[4] == 'L' && - name[5] == 'E' && name[6] == 'R' && name[7] == '!' && - name[8] == '!' && name[9] == '!') { - break; - } - - /* Skip "." entry */ - if (namesize == 2 && name[0] == '.' && name[1] == '\0') { - p = next; - continue; - } - - /* Resolve parent directory, creating intermediate dirs */ - const char* basename = nullptr; - dentry* parent = cpio_mkdir_p(g_root_dentry, name, &basename); - if (!parent || !basename || basename[0] == '\0') { - p = next; - continue; - } - - /* Build qstr for the final component */ - uint32 blen = 0; - while (basename[blen] && basename[blen] != '/') blen++; - - qstr bname; - bname.name = basename; - bname.len = blen; - bname.hash = full_name_hash(basename, blen); - - if (S_ISDIR(mode)) { - dentry* existing = d_lookup(parent, &bname); - if (!existing) { - dentry* de = d_alloc(parent, &bname); - if (de) { - inode* ip = ramfs_get_inode(parent->d_inode->i_sb, - parent->d_inode, - S_IFDIR | (mode & 0777), 0); - if (ip) { - d_instantiate(de, ip); - dget(de); - inc_nlink(parent->d_inode); - dir_count++; - } - } - } - } else if (S_ISREG(mode)) { - dentry* de = d_alloc(parent, &bname); - if (de) { - inode* ip = ramfs_get_inode(parent->d_inode->i_sb, - parent->d_inode, - S_IFREG | (mode & 0777), 0); - if (ip) { - d_instantiate(de, ip); - dget(de); - - /* Write file content via ramfs write path */ - if (filesize > 0 && ip->i_fop && ip->i_fop->write) { - file tmp_fp = {}; - tmp_fp.f_inode = ip; - tmp_fp.f_path.de = de; - tmp_fp.f_pos = 0; - tmp_fp.f_flags = O_WRONLY; - tmp_fp.f_count.store(1); - - int64 pos = 0; - ip->i_fop->write(&tmp_fp, data, - filesize, &pos); - } - - file_count++; - printk("[initramfs] %s (%u bytes, mode %03o)\n", - name, filesize, mode & 0777); - } - } - } else if (S_ISLNK(mode)) { - /* Symlink: file data is the target path (not NUL-terminated). - * Linux: init/initramfs.c do_symlink() */ - dentry* de = d_alloc(parent, &bname); - if (de) { - inode* ip = ramfs_get_inode(parent->d_inode->i_sb, - parent->d_inode, - S_IFLNK | 0777, 0); - if (ip) { - /* Store symlink target in inode. - * Allocate a kernel buffer and copy the target. */ - char* target = new char[filesize + 1]; - if (target) { - for (uint32 i = 0; i < filesize; i++) - target[i] = data[i]; - target[filesize] = '\0'; - ip->i_link = target; - } - - d_instantiate(de, ip); - dget(de); - file_count++; - printk("[initramfs] %s -> %s (symlink)\n", - name, target ? target : "?"); - } - } - } - - p = next; - } - - printk("[initramfs] done: %d files, %d dirs\n", - file_count, dir_count); -} diff --git a/fs/inode.cc b/fs/inode.cc deleted file mode 100644 index 1d3d006..0000000 --- a/fs/inode.cc +++ /dev/null @@ -1,166 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * inode.cc — Inode allocation, lifecycle, and generic helpers - */ - -#include -#include -#include -#include - -namespace { -lume::atomic g_next_ino{1}; -} // namespace - -/* ================================================================== */ -/* new_inode — allocate a fresh inode on a superblock */ -/* ================================================================== */ - -inode* new_inode(super_block* sb) -{ - inode* ip = nullptr; - - if (sb->s_op && sb->s_op->alloc_inode) - ip = sb->s_op->alloc_inode(sb); - else - ip = new inode{}; - - if (!ip) return nullptr; - - /* Zero-init key fields */ - ip->i_sb = sb; - ip->i_ino = g_next_ino.fetch_add(1); - ip->i_mode = 0; - ip->i_flags = 0; - ip->i_uid = 0; - ip->i_gid = 0; - ip->i_nlink = 1; - ip->i_rdev = 0; - ip->i_size = 0; - ip->i_blocks = 0; - ip->i_bytes = 0; - ip->i_blkbits = sb->s_blocksize_bits; - ip->i_generation = 0; - ip->i_state = I_NEW; - ip->i_count.store(1); - ip->i_writecount.store(0); - - ip->i_atime_sec = ip->i_mtime_sec = ip->i_ctime_sec = 0; - ip->i_atime_nsec = ip->i_mtime_nsec = ip->i_ctime_nsec = 0; - - ip->i_op = nullptr; - ip->i_fop = nullptr; - ip->i_mapping = &ip->i_data; - ip->i_private = nullptr; - ip->i_pipe = nullptr; - - /* Init embedded address_space */ - ip->i_data.host = ip; - ip->i_data.a_ops = nullptr; - ip->i_data.nrpages = 0; - ip->i_data.flags = 0; - - /* Init lists */ - list_init(&ip->i_sb_list); - list_init(&ip->i_dentry); - - /* Add to superblock's inode list */ - { - LockGuard guard(sb->s_inode_list_lock); - list_add_tail(&ip->i_sb_list, &sb->s_inodes); - } - - return ip; -} - -/* ================================================================== */ -/* ihold / iput — reference counting */ -/* ================================================================== */ - -void ihold(inode* ip) -{ - ip->i_count.fetch_add(1); -} - -void iput(inode* ip) -{ - if (!ip) return; - - int old = ip->i_count.fetch_sub(1); - if (old > 1) return; - - /* Last reference dropped — evict */ - if (ip->i_sb->s_op && ip->i_sb->s_op->evict_inode) - ip->i_sb->s_op->evict_inode(ip); - - /* Remove from sb list */ - { - LockGuard guard(ip->i_sb->s_inode_list_lock); - list_del(&ip->i_sb_list); - } - - if (ip->i_sb->s_op && ip->i_sb->s_op->destroy_inode) - ip->i_sb->s_op->destroy_inode(ip); - else - delete ip; -} - -/* ================================================================== */ -/* nlink helpers */ -/* ================================================================== */ - -void set_nlink(inode* ip, uint32 nlink) { ip->i_nlink = nlink; } -void inc_nlink(inode* ip) { ip->i_nlink++; } -void drop_nlink(inode* ip) { ip->i_nlink--; } -void clear_nlink(inode* ip) { ip->i_nlink = 0; } - -/* ================================================================== */ -/* inode_init_owner */ -/* ================================================================== */ - -void inode_init_owner(inode* ip, const inode* dir, uint32 mode) -{ - ip->i_uid = 0; /* Phase 1: always root */ - ip->i_gid = 0; - ip->i_mode = mode; -} - -/* ================================================================== */ -/* generic_fillattr — fill kstat from inode (used by getattr) */ -/* ================================================================== */ - -void generic_fillattr(inode* ip, kstat* stat) -{ - stat->st_dev = ip->i_sb->s_dev; - stat->st_ino = ip->i_ino; - stat->st_mode = ip->i_mode; - stat->st_nlink = ip->i_nlink; - stat->st_uid = ip->i_uid; - stat->st_gid = ip->i_gid; - stat->st_rdev = ip->i_rdev; - stat->__pad = 0; - stat->st_size = ip->i_size; - stat->st_blksize = 1 << ip->i_blkbits; - stat->__pad2 = 0; - stat->st_blocks = ip->i_blocks; - stat->st_atime_sec = ip->i_atime_sec; - stat->st_atime_nsec = ip->i_atime_nsec; - stat->st_mtime_sec = ip->i_mtime_sec; - stat->st_mtime_nsec = ip->i_mtime_nsec; - stat->st_ctime_sec = ip->i_ctime_sec; - stat->st_ctime_nsec = ip->i_ctime_nsec; - stat->__unused[0] = 0; - stat->__unused[1] = 0; -} - -/* ================================================================== */ -/* mark_inode_dirty (stub) */ -/* ================================================================== */ - -void mark_inode_dirty(inode* ip) -{ - ip->i_state |= I_DIRTY_SYNC; - /* Phase 1: no writeback, ramfs is memory-only */ -} diff --git a/fs/namei.cc b/fs/namei.cc deleted file mode 100644 index 9124ea9..0000000 --- a/fs/namei.cc +++ /dev/null @@ -1,250 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * namei.cc — Pathname resolution (path lookup) - * - * Simplified Phase 1: no symlink, no RCU, no mount traversal. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* Helpers */ -/* ================================================================== */ - -static const char* next_component(const char* path, qstr* result) -{ - while (*path == '/') path++; - if (*path == '\0') return nullptr; - - const char* start = path; - while (*path != '\0' && *path != '/') path++; - - uint32 len = static_cast(path - start); - result->name = start; - result->len = len; - result->hash = full_name_hash(start, len); - - return path; -} - -static bool is_dot(const qstr* name) { - return name->len == 1 && name->name[0] == '.'; -} -static bool is_dotdot(const qstr* name) { - return name->len == 2 && name->name[0] == '.' && name->name[1] == '.'; -} - -/* ================================================================== */ -/* walk_component */ -/* ================================================================== */ - -static dentry* walk_component(dentry* parent, const qstr* name) -{ - if (!parent->d_inode || !S_ISDIR(parent->d_inode->i_mode)) - return reinterpret_cast(-ENOTDIR); - - if (is_dot(name)) - return dget(parent); - - if (is_dotdot(name)) - return dget(parent->d_parent); - - /* Try dcache */ - dentry* child = d_lookup(parent, name); - if (child) - return child; - - /* Cache miss — call filesystem lookup */ - inode* dir = parent->d_inode; - if (!dir->i_op || !dir->i_op->lookup) - return reinterpret_cast(-ENOENT); - - child = d_alloc(parent, name); - if (!child) - return reinterpret_cast(-ENOMEM); - - dentry* result = dir->i_op->lookup(dir, child, 0); - if (result) { - dput(child); - return result; - } - - /* If lookup didn't set an inode, this is a negative dentry - * (file doesn't exist). Remove from dcache and return error. */ - if (!child->d_inode) { - d_drop(child); - dput(child); - return reinterpret_cast(-ENOENT); - } - - return child; -} - -/* ================================================================== */ -/* filename_lookup */ -/* ================================================================== */ - -int filename_lookup(int dfd, const char* name, unsigned int flags, path* result) -{ - if (!name || !result) - return -EINVAL; - - TaskControlBlock* task = current_task(); - dentry* start; - - /* Determine starting dentry */ - if (name[0] == '/') { - start = task->fs->root.de; - if (!start) start = g_root_dentry; - name++; - } else if (dfd == AT_FDCWD) { - start = task->fs->pwd.de; - if (!start) start = g_root_dentry; - } else { - file* dir_fp = fcheck(task->files, dfd); - if (!dir_fp) return -EBADF; - start = dir_fp->f_path.de; - if (!start || !start->d_inode || !S_ISDIR(start->d_inode->i_mode)) - return -ENOTDIR; - } - - dentry* current_de = dget(start); - const char* p = name; - - while (p && *p) { - qstr component; - const char* next = next_component(p, &component); - if (!next && component.len == 0) - break; - - const char* after = next; - while (after && *after == '/') after++; - bool is_last = (!after || *after == '\0'); - - if (is_last && (flags & LOOKUP_PARENT)) { - result->de = current_de; - result->mnt = task->fs->root.mnt; - return 0; - } - - dentry* child = walk_component(current_de, &component); - - int64 err = reinterpret_cast(child); - if (err < 0 && err >= -4095) { - dput(current_de); - return static_cast(err); - } - - /* ---- Symlink following (Linux: step_into → pick_link) ---- - * If the resolved component is a symlink, follow it. - * Linux limits this to MAXSYMLINKS (40); we use 8. */ - constexpr int kMaxSymlinks = 8; - int symlink_depth = 0; - while (child->d_inode && S_ISLNK(child->d_inode->i_mode) && - child->d_inode->i_link && symlink_depth < kMaxSymlinks) { - symlink_depth++; - const char* target = child->d_inode->i_link; - dput(child); - - /* Absolute symlink: restart from root. - * Relative symlink: resolve from current parent. */ - dentry* link_start; - if (target[0] == '/') { - link_start = dget(task->fs->root.de ? task->fs->root.de : g_root_dentry); - target++; - } else { - link_start = dget(current_de); - } - - /* Walk each component of the symlink target */ - dentry* link_cur = link_start; - const char* lp = target; - qstr lcomp; - while (lp && *lp) { - const char* lnext = next_component(lp, &lcomp); - if (!lnext && lcomp.len == 0) break; - - dentry* lchild = walk_component(link_cur, &lcomp); - int64 lerr = reinterpret_cast(lchild); - if (lerr < 0 && lerr >= -4095) { - dput(link_cur); - dput(current_de); - return static_cast(lerr); - } - - dput(link_cur); - link_cur = lchild; - lp = lnext; - } - - child = link_cur; - } - - if (symlink_depth >= kMaxSymlinks) { - dput(child); - dput(current_de); - return -ELOOP; - } - - if (!is_last && child->d_inode && !S_ISDIR(child->d_inode->i_mode)) { - dput(child); - dput(current_de); - return -ENOTDIR; - } - - if (!is_last && !child->d_inode) { - dput(child); - dput(current_de); - return -ENOENT; - } - - dput(current_de); - current_de = child; - p = next; - } - - if ((flags & LOOKUP_DIRECTORY) && current_de->d_inode && - !S_ISDIR(current_de->d_inode->i_mode)) { - dput(current_de); - return -ENOTDIR; - } - - /* Negative dentry: the path was walked, but the final component - * does not exist (d_inode == NULL). Return -ENOENT. */ - if (!current_de->d_inode) { - dput(current_de); - return -ENOENT; - } - - result->de = current_de; - result->mnt = task->fs->root.mnt; - return 0; -} - -int kern_path(const char* name, unsigned int flags, path* result) -{ - return filename_lookup(AT_FDCWD, name, flags, result); -} - -dentry* lookup_one_len(const char* name, dentry* parent, int len) -{ - qstr q; - q.name = name; - q.len = static_cast(len); - q.hash = full_name_hash(name, q.len); - - return walk_component(parent, &q); -} - -void namei_init() {} diff --git a/fs/pipe.cc b/fs/pipe.cc deleted file mode 100644 index f7708f5..0000000 --- a/fs/pipe.cc +++ /dev/null @@ -1,278 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * pipe.cc — Pipe implementation - * - * Implements unidirectional byte-stream pipes with blocking I/O. - * Each pipe has a 4KB circular buffer. Reads block when empty, - * writes block when full (unless O_NONBLOCK). - * - * When all writers close, read returns 0 (EOF). - * When all readers close, write returns -EPIPE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* pipe_inode_info lifecycle */ -/* ================================================================== */ - -pipe_inode_info* alloc_pipe_info() -{ - auto* pi = new pipe_inode_info{}; - if (!pi) return nullptr; - - pi->rd_pos = 0; - pi->wr_pos = 0; - pi->len = 0; - pi->rd_wait.init("pipe_rd"); - pi->wr_wait.init("pipe_wr"); - pi->readers.store(0); - pi->writers.store(0); - pi->refcount.store(1); - return pi; -} - -void free_pipe_info(pipe_inode_info* pipe) -{ - delete pipe; -} - -static void pipe_get(pipe_inode_info* pi) -{ - pi->refcount.fetch_add(1); -} - -static void pipe_put(pipe_inode_info* pi) -{ - if (pi->refcount.fetch_sub(1) == 1) { - free_pipe_info(pi); - } -} - -/* ================================================================== */ -/* pipe_read */ -/* ================================================================== */ - -static int64 pipe_read(file* fp, char* buf, uint64 count, int64* /*pos*/) -{ - pipe_inode_info* pi = static_cast(fp->private_data); - if (!pi) return -EBADF; - - while (true) { - pi->lock.acquire(); - - if (pi->len > 0) { - /* Data available — copy out */ - int64 to_read = static_cast(count); - if (to_read > pi->len) to_read = pi->len; - - for (int64 i = 0; i < to_read; i++) { - buf[i] = pi->buf[pi->rd_pos]; - pi->rd_pos = (pi->rd_pos + 1) % PIPE_BUF_SIZE; - } - pi->len -= static_cast(to_read); - - pi->lock.release(); - - /* Wake any blocked writers */ - pi->wr_wait.wake_all(); - return to_read; - } - - /* Buffer empty */ - if (pi->writers.load() == 0) { - /* No writers left — EOF */ - pi->lock.release(); - return 0; - } - - if (fp->f_flags & O_NONBLOCK) { - pi->lock.release(); - return -EAGAIN; - } - - pi->lock.release(); - - /* Sleep until data or writer closes */ - pi->rd_wait.sleep(); - } -} - -/* ================================================================== */ -/* pipe_write */ -/* ================================================================== */ - -static int64 pipe_write(file* fp, const char* buf, uint64 count, int64* /*pos*/) -{ - pipe_inode_info* pi = static_cast(fp->private_data); - if (!pi) return -EBADF; - - if (pi->readers.load() == 0) { - return -EPIPE; /* Broken pipe */ - } - - int64 written = 0; - - while (static_cast(written) < count) { - pi->lock.acquire(); - - if (pi->len < PIPE_BUF_SIZE) { - /* Space available — copy in */ - int avail = PIPE_BUF_SIZE - pi->len; - int64 remaining = static_cast(count) - written; - int to_write = avail < static_cast(remaining) - ? avail - : static_cast(remaining); - - for (int i = 0; i < to_write; i++) { - pi->buf[pi->wr_pos] = buf[written + i]; - pi->wr_pos = (pi->wr_pos + 1) % PIPE_BUF_SIZE; - } - pi->len += to_write; - written += to_write; - - pi->lock.release(); - - /* Wake any blocked readers */ - pi->rd_wait.wake_all(); - continue; - } - - /* Buffer full */ - if (pi->readers.load() == 0) { - pi->lock.release(); - return written > 0 ? written : -EPIPE; - } - - if (fp->f_flags & O_NONBLOCK) { - pi->lock.release(); - return written > 0 ? written : -EAGAIN; - } - - pi->lock.release(); - - /* Sleep until space or reader closes */ - pi->wr_wait.sleep(); - } - - return written; -} - -/* ================================================================== */ -/* pipe_release — called on last fput of a pipe fd */ -/* ================================================================== */ - -static int pipe_read_release(inode* /*ip*/, file* fp) -{ - pipe_inode_info* pi = static_cast(fp->private_data); - if (pi) { - pi->readers.fetch_sub(1); - /* Wake writers so they see readers==0 and get EPIPE */ - pi->wr_wait.wake_all(); - pipe_put(pi); - } - return 0; -} - -static int pipe_write_release(inode* /*ip*/, file* fp) -{ - pipe_inode_info* pi = static_cast(fp->private_data); - if (pi) { - pi->writers.fetch_sub(1); - /* Wake readers so they see writers==0 and get EOF */ - pi->rd_wait.wake_all(); - pipe_put(pi); - } - return 0; -} - -/* ================================================================== */ -/* file_operations tables */ -/* ================================================================== */ - -static file_operations pipe_read_fops; -static file_operations pipe_write_fops; -static bool pipe_fops_initialized = false; - -static void pipe_fops_init() -{ - if (pipe_fops_initialized) return; - - pipe_read_fops = {}; - pipe_read_fops.read = pipe_read; - pipe_read_fops.release = pipe_read_release; - - pipe_write_fops = {}; - pipe_write_fops.write = pipe_write; - pipe_write_fops.release = pipe_write_release; - - pipe_fops_initialized = true; -} - -/* ================================================================== */ -/* do_pipe2 — create a pipe, install two fds */ -/* ================================================================== */ - -int do_pipe2(files_struct* files, int fds[2], int flags) -{ - pipe_fops_init(); - - pipe_inode_info* pi = alloc_pipe_info(); - if (!pi) return -ENOMEM; - - /* Create read-end file */ - file* rd_fp = alloc_empty_file(O_RDONLY | (flags & O_NONBLOCK)); - if (!rd_fp) { - free_pipe_info(pi); - return -ENFILE; - } - rd_fp->f_op = &pipe_read_fops; - rd_fp->private_data = pi; - - /* Create write-end file */ - file* wr_fp = alloc_empty_file(O_WRONLY | (flags & O_NONBLOCK)); - if (!wr_fp) { - fput(rd_fp); - free_pipe_info(pi); - return -ENFILE; - } - wr_fp->f_op = &pipe_write_fops; - wr_fp->private_data = pi; - - /* Bump pipe refcount for the two files */ - pipe_get(pi); /* wr_fp gets second ref */ - pi->readers.store(1); - pi->writers.store(1); - - /* Allocate fds */ - int rd_fd = alloc_fd(files, 0); - if (rd_fd < 0) { - fput(rd_fp); - fput(wr_fp); - return rd_fd; - } - - int wr_fd = alloc_fd(files, 0); - if (wr_fd < 0) { - close_fd(files, rd_fd); - fput(wr_fp); - return wr_fd; - } - - fd_install(files, rd_fd, rd_fp); - fd_install(files, wr_fd, wr_fp); - - fds[0] = rd_fd; - fds[1] = wr_fd; - - return 0; -} diff --git a/fs/ramfs/file.cc b/fs/ramfs/file.cc deleted file mode 100644 index 6d9a070..0000000 --- a/fs/ramfs/file.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * ramfs/file.cc — RamFS file operations (read/write via in-memory pages) - * - * Phase 1: simple flat buffer per-inode via i_private. - * Will migrate to page_cache integration later. - */ - -#include -#include -#include -#include -#include -#include - -/* - * Simplest possible in-memory file storage: - * i_private points to a dynamically grown buffer. - */ -struct ramfs_file_data { - char* buf; - uint64 capacity; -}; - -static ramfs_file_data* get_or_create_data(inode* ip) -{ - if (!ip->i_private) { - auto* data = new ramfs_file_data{}; - data->buf = nullptr; - data->capacity = 0; - ip->i_private = data; - } - return static_cast(ip->i_private); -} - -static int ensure_capacity(ramfs_file_data* data, uint64 needed) -{ - if (needed <= data->capacity) return 0; - - /* Round up to page size */ - uint64 new_cap = (needed + 4095) & ~4095ULL; - char* new_buf = new char[new_cap]; - if (!new_buf) return -ENOMEM; - - /* Copy old data */ - if (data->buf && data->capacity > 0) { - for (uint64 i = 0; i < data->capacity; i++) - new_buf[i] = data->buf[i]; - } - /* Zero new region */ - for (uint64 i = data->capacity; i < new_cap; i++) - new_buf[i] = 0; - - delete[] data->buf; - data->buf = new_buf; - data->capacity = new_cap; - return 0; -} - -/* ================================================================== */ -/* ramfs_read */ -/* ================================================================== */ - -static int64 ramfs_read(file* fp, char* buf, uint64 count, int64* pos) -{ - inode* ip = file_inode(fp); - int64 offset = *pos; - - if (offset < 0) return -EINVAL; - if (offset >= ip->i_size) return 0; - - int64 avail = ip->i_size - offset; - if (static_cast(count) > avail) - count = static_cast(avail); - - auto* data = static_cast(ip->i_private); - if (!data || !data->buf) return 0; - - /* Copy to user buffer. - * TODO: use copy_to_user when called from syscall context */ - for (uint64 i = 0; i < count; i++) - buf[i] = data->buf[offset + i]; - - *pos += count; - return static_cast(count); -} - -/* ================================================================== */ -/* ramfs_write */ -/* ================================================================== */ - -static int64 ramfs_write(file* fp, const char* buf, uint64 count, int64* pos) -{ - inode* ip = file_inode(fp); - int64 offset = *pos; - - if (fp->f_flags & O_APPEND) - offset = ip->i_size; - - if (offset < 0) return -EINVAL; - - auto* data = get_or_create_data(ip); - uint64 end = static_cast(offset) + count; - - int err = ensure_capacity(data, end); - if (err) return err; - - /* Copy from user buffer */ - for (uint64 i = 0; i < count; i++) - data->buf[offset + i] = buf[i]; - - if (static_cast(end) > ip->i_size) - ip->i_size = end; - - *pos = end; - mark_inode_dirty(ip); - return static_cast(count); -} - -/* ================================================================== */ -/* ramfs_dir_iterate — getdents64 */ -/* ================================================================== */ - -static int ramfs_dir_iterate(file* fp, dir_context* ctx) -{ - dentry* dir_de = file_dentry(fp); - inode* dir_ip = file_inode(fp); - int64 pos = ctx->pos; - int count = 0; - - /* pos 0: emit "." */ - if (pos == 0) { - if (!ctx->actor(ctx, ".", 1, pos, dir_ip->i_ino, DT_DIR)) - return 0; - ctx->pos = 1; - pos = 1; - count++; - } - - /* pos 1: emit ".." */ - if (pos == 1) { - uint64 parent_ino = dir_de->d_parent->d_inode - ? dir_de->d_parent->d_inode->i_ino : dir_ip->i_ino; - if (!ctx->actor(ctx, "..", 2, pos, parent_ino, DT_DIR)) - return 0; - ctx->pos = 2; - pos = 2; - count++; - } - - /* pos >= 2: iterate children */ - int64 child_idx = 2; - list_node* node; - list_for_each(node, &dir_de->d_children) { - dentry* child = list_entry(node, dentry, d_child); - - if (!child->d_inode) - continue; /* skip negative dentries */ - - if (child_idx >= pos) { - uint8 d_type = DT_UNKNOWN; - if (S_ISDIR(child->d_inode->i_mode)) d_type = DT_DIR; - else if (S_ISREG(child->d_inode->i_mode)) d_type = DT_REG; - else if (S_ISCHR(child->d_inode->i_mode)) d_type = DT_CHR; - else if (S_ISBLK(child->d_inode->i_mode)) d_type = DT_BLK; - else if (S_ISLNK(child->d_inode->i_mode)) d_type = DT_LNK; - else if (S_ISFIFO(child->d_inode->i_mode)) d_type = DT_FIFO; - - if (!ctx->actor(ctx, child->d_name.name, - static_cast(child->d_name.len), - child_idx, child->d_inode->i_ino, d_type)) - return 0; - - ctx->pos = child_idx + 1; - count++; - } - child_idx++; - } - - return count; -} - -extern file_operations ramfs_file_operations; -extern file_operations ramfs_dir_operations; - -file_operations ramfs_file_operations; -file_operations ramfs_dir_operations; - -void ramfs_file_ops_init() -{ - ramfs_file_operations.llseek = nullptr; - ramfs_file_operations.read = ramfs_read; - ramfs_file_operations.write = ramfs_write; - ramfs_file_operations.iterate_shared = nullptr; - ramfs_file_operations.poll = nullptr; - ramfs_file_operations.unlocked_ioctl = nullptr; - ramfs_file_operations.mmap = nullptr; - ramfs_file_operations.open = nullptr; - ramfs_file_operations.flush = nullptr; - ramfs_file_operations.release = nullptr; - ramfs_file_operations.fsync = nullptr; - - ramfs_dir_operations.llseek = nullptr; - ramfs_dir_operations.read = nullptr; - ramfs_dir_operations.write = nullptr; - ramfs_dir_operations.iterate_shared = ramfs_dir_iterate; - ramfs_dir_operations.poll = nullptr; - ramfs_dir_operations.unlocked_ioctl = nullptr; - ramfs_dir_operations.mmap = nullptr; - ramfs_dir_operations.open = nullptr; - ramfs_dir_operations.flush = nullptr; - ramfs_dir_operations.release = nullptr; - ramfs_dir_operations.fsync = nullptr; -} diff --git a/fs/ramfs/inode.cc b/fs/ramfs/inode.cc deleted file mode 100644 index c5e49bf..0000000 --- a/fs/ramfs/inode.cc +++ /dev/null @@ -1,164 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * ramfs/inode.cc — RamFS inode operations - * - * A simple in-memory filesystem (like Linux tmpfs without swap). - * All data lives in memory via the page cache. - */ - -#include -#include -#include -#include -#include -#include - -/* Forward declarations */ -extern file_operations ramfs_file_operations; -extern file_operations ramfs_dir_operations; -extern inode_operations ramfs_dir_inode_operations; - -/* ================================================================== */ -/* ramfs_get_inode — allocate + init an inode for ramfs */ -/* ================================================================== */ - -inode* ramfs_get_inode(super_block* sb, const inode* dir, uint32 mode, uint32 rdev) -{ - inode* ip = new_inode(sb); - if (!ip) return nullptr; - - inode_init_owner(ip, dir, mode); - /* TODO: set timestamps to current time when we have a time source */ - - switch (mode & S_IFMT) { - case S_IFREG: - ip->i_op = nullptr; /* regular files don't need inode_ops for Phase 1 */ - ip->i_fop = &ramfs_file_operations; - break; - case S_IFDIR: - ip->i_op = &ramfs_dir_inode_operations; - ip->i_fop = &ramfs_dir_operations; - inc_nlink(ip); /* directories start with nlink=2 (. and parent's link) */ - break; - case S_IFLNK: - /* Symlink: stub for Phase 1 */ - break; - default: - /* Character/block devices: i_rdev */ - ip->i_rdev = rdev; - break; - } - - return ip; -} - -/* ================================================================== */ -/* Directory inode operations */ -/* ================================================================== */ - -static dentry* ramfs_lookup(inode* dir, dentry* de, unsigned int flags) -{ - (void)dir; - (void)flags; - /* For ramfs, everything is in dcache. If we get here, it means - * d_lookup() already failed, so this is a negative dentry. - * Just return nullptr to let the caller see de->d_inode == NULL. */ - return nullptr; -} - -static int ramfs_create(inode* dir, dentry* de, uint32 mode, bool excl) -{ - (void)excl; - inode* ip = ramfs_get_inode(dir->i_sb, dir, mode | S_IFREG, 0); - if (!ip) return -ENOMEM; - - d_instantiate(de, ip); - dget(de); - dir->i_size += de->d_name.len; - mark_inode_dirty(dir); - return 0; -} - -static int ramfs_mkdir(inode* dir, dentry* de, uint32 mode) -{ - inode* ip = ramfs_get_inode(dir->i_sb, dir, mode | S_IFDIR, 0); - if (!ip) return -ENOMEM; - - d_instantiate(de, ip); - dget(de); - inc_nlink(dir); - dir->i_size += de->d_name.len; - mark_inode_dirty(dir); - return 0; -} - -static int ramfs_rmdir(inode* dir, dentry* de) -{ - /* Check if directory is empty */ - if (!list_empty(&de->d_children)) - return -ENOTEMPTY; - - drop_nlink(de->d_inode); /* remove . link */ - drop_nlink(de->d_inode); /* remove parent's link */ - drop_nlink(dir); - d_delete(de); - dir->i_size -= de->d_name.len; - mark_inode_dirty(dir); - return 0; -} - -static int ramfs_unlink(inode* dir, dentry* de) -{ - drop_nlink(de->d_inode); - d_delete(de); - dir->i_size -= de->d_name.len; - mark_inode_dirty(dir); - return 0; -} - -static int ramfs_link(dentry* old_de, inode* dir, dentry* new_de) -{ - inode* ip = old_de->d_inode; - if (!ip) return -ENOENT; - - inc_nlink(ip); - ihold(ip); - d_instantiate(new_de, ip); - dget(new_de); - dir->i_size += new_de->d_name.len; - mark_inode_dirty(dir); - return 0; -} - -static int ramfs_mknod(inode* dir, dentry* de, uint32 mode, uint32 rdev) -{ - inode* ip = ramfs_get_inode(dir->i_sb, dir, mode, rdev); - if (!ip) return -ENOMEM; - - d_instantiate(de, ip); - dget(de); - dir->i_size += de->d_name.len; - mark_inode_dirty(dir); - return 0; -} - -inode_operations ramfs_dir_inode_operations; - -void ramfs_dir_inode_ops_init() -{ - ramfs_dir_inode_operations.lookup = ramfs_lookup; - ramfs_dir_inode_operations.create = ramfs_create; - ramfs_dir_inode_operations.link = ramfs_link; - ramfs_dir_inode_operations.unlink = ramfs_unlink; - ramfs_dir_inode_operations.symlink = nullptr; - ramfs_dir_inode_operations.mkdir = ramfs_mkdir; - ramfs_dir_inode_operations.rmdir = ramfs_rmdir; - ramfs_dir_inode_operations.mknod = ramfs_mknod; - ramfs_dir_inode_operations.rename = nullptr; - ramfs_dir_inode_operations.setattr = nullptr; - ramfs_dir_inode_operations.getattr = nullptr; - ramfs_dir_inode_operations.get_link = nullptr; - ramfs_dir_inode_operations.permission = nullptr; -} diff --git a/fs/ramfs/super.cc b/fs/ramfs/super.cc deleted file mode 100644 index 6f929f2..0000000 --- a/fs/ramfs/super.cc +++ /dev/null @@ -1,154 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * ramfs/super.cc — RamFS superblock: mount, fill_super, and init - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern inode* ramfs_get_inode(super_block* sb, const inode* dir, - uint32 mode, uint32 rdev); - -/* Superblock allocation helper (defined in super.cc) */ -extern super_block* alloc_super(file_system_type* type); - -/* ================================================================== */ -/* ramfs super_operations */ -/* ================================================================== */ - -static inode* ramfs_alloc_inode(super_block* sb) -{ - return new inode{}; -} - -static void ramfs_destroy_inode(inode* ip) -{ - /* Free ramfs_file_data if any */ - if (ip->i_private) { - struct ramfs_file_data { - char* buf; - uint64 capacity; - }; - auto* data = static_cast(ip->i_private); - delete[] data->buf; - delete data; - } - delete ip; -} - -static int ramfs_statfs(dentry* de, kstatfs* buf) -{ - /* Simple fake values */ - buf->f_type = 0x858458f6; /* RAMFS_MAGIC */ - buf->f_bsize = 4096; - buf->f_blocks = 0; - buf->f_bfree = 0; - buf->f_bavail = 0; - buf->f_files = 0; - buf->f_ffree = 0; - buf->f_namelen = 255; - buf->f_frsize = 4096; - buf->f_flags = 0; - return 0; -} - -static super_operations ramfs_sops; - -static void ramfs_sops_init() -{ - ramfs_sops.alloc_inode = ramfs_alloc_inode; - ramfs_sops.destroy_inode = ramfs_destroy_inode; - ramfs_sops.free_inode = nullptr; - ramfs_sops.dirty_inode = nullptr; - ramfs_sops.write_inode = nullptr; - ramfs_sops.drop_inode = nullptr; - ramfs_sops.evict_inode = nullptr; - ramfs_sops.put_super = nullptr; - ramfs_sops.sync_fs = nullptr; - ramfs_sops.statfs = ramfs_statfs; - ramfs_sops.umount_begin = nullptr; -} - -/* ================================================================== */ -/* ramfs_fill_super */ -/* ================================================================== */ - -static int ramfs_fill_super(super_block* sb, void* data, int silent) -{ - sb->s_op = &ramfs_sops; - sb->s_magic = 0x858458f6; - sb->s_blocksize = 4096; - sb->s_blocksize_bits = 12; - sb->s_maxbytes = 0x7FFFFFFFFFFFFFFFLL; - sb->s_time_gran = 1; - - /* Create root inode */ - inode* root_ip = ramfs_get_inode(sb, nullptr, S_IFDIR | 0755, 0); - if (!root_ip) return -ENOMEM; - - /* Create root dentry */ - sb->s_root = d_make_root(root_ip); - if (!sb->s_root) - return -ENOMEM; - - return 0; -} - -/* ================================================================== */ -/* ramfs_mount */ -/* ================================================================== */ - -static super_block* ramfs_mount(file_system_type* type, int flags, - const char* dev_name, void* data) -{ - super_block* sb = alloc_super(type); - if (!sb) return nullptr; - - int err = ramfs_fill_super(sb, data, flags & SB_SILENT); - if (err) { - delete sb; - return nullptr; - } - - return sb; -} - -static void ramfs_kill_sb(super_block* sb) -{ - /* Phase 1: no cleanup needed for ramfs */ - (void)sb; -} - -/* ================================================================== */ -/* Filesystem type registration */ -/* ================================================================== */ - -static file_system_type ramfs_fs_type; - -extern void ramfs_file_ops_init(); -extern void ramfs_dir_inode_ops_init(); - -void ramfs_init() -{ - /* Runtime init to avoid un-relocated absolute pointers in .data */ - ramfs_sops_init(); - ramfs_file_ops_init(); - ramfs_dir_inode_ops_init(); - - ramfs_fs_type.name = "ramfs"; - ramfs_fs_type.fs_flags = FS_NO_DEVICE; - ramfs_fs_type.mount = ramfs_mount; - ramfs_fs_type.kill_sb = ramfs_kill_sb; - list_init(&ramfs_fs_type.fs_list); - - register_filesystem(&ramfs_fs_type); -} - diff --git a/fs/super.cc b/fs/super.cc deleted file mode 100644 index 231b57c..0000000 --- a/fs/super.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * super.cc — Superblock lifecycle + filesystem type registry - */ - -#include -#include -#include -#include -#include -#include - -/* Global root filesystem entry points */ -vfsmount* g_root_mnt = nullptr; -dentry* g_root_dentry = nullptr; - -/* ================================================================== */ -/* Filesystem type registry */ -/* ================================================================== */ - -namespace { - -list_head g_fs_types; -Spinlock g_fs_type_lock; - -} // namespace - -int register_filesystem(file_system_type* fs) -{ - LockGuard guard(g_fs_type_lock); - list_add_tail(&fs->fs_list, &g_fs_types); - printk("[vfs] registered filesystem: %s\n", fs->name); - return 0; -} - -file_system_type* get_fs_type(const char* name) -{ - LockGuard guard(g_fs_type_lock); - list_node* pos; - list_for_each(pos, &g_fs_types) { - auto* fs = list_entry(pos, file_system_type, fs_list); - /* Simple strcmp */ - const char* a = fs->name; - const char* b = name; - while (*a && *a == *b) { a++; b++; } - if (*a == '\0' && *b == '\0') - return fs; - } - return nullptr; -} - -/* ================================================================== */ -/* Superblock allocation */ -/* ================================================================== */ - -super_block* alloc_super(file_system_type* type) -{ - auto* sb = new super_block{}; - if (!sb) return nullptr; - - list_init(&sb->s_list); - list_init(&sb->s_inodes); - sb->s_type = type; - sb->s_op = nullptr; - sb->s_root = nullptr; - sb->s_fs_info = nullptr; - sb->s_blocksize = 4096; - sb->s_blocksize_bits = 12; - sb->s_maxbytes = 0x7FFFFFFFFFFFFFFFLL; - sb->s_time_gran = 1; - sb->s_time_min = 0; - sb->s_time_max = 0x7FFFFFFFFFFFFFFFLL; - sb->s_flags = 0; - sb->s_magic = 0; - sb->s_active.store(1); - sb->s_count = 1; - sb->s_max_links = 0; - sb->s_d_op = nullptr; - sb->s_mounts = nullptr; - sb->s_dev = 0; - for (int i = 0; i < 32; i++) sb->s_id[i] = 0; - - return sb; -} - -/* ================================================================== */ -/* Init */ -/* ================================================================== */ - -void super_init() -{ - list_init(&g_fs_types); -} diff --git a/fs/vfs_init.cc b/fs/vfs_init.cc deleted file mode 100644 index ec56e88..0000000 --- a/fs/vfs_init.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * vfs_init.cc — Bootstrap the VFS: mount ramfs root, set global root - * - * Called from kernel_main() after slab_init() and ramfs_init(). - * This is the moral equivalent of Linux's vfs_caches_init() + - * mnt_init() + init_rootfs(). - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* vfs_init — mount ramfs as root filesystem */ -/* ================================================================== */ - -/* - * ramfs_mount is called internally via the file_system_type::mount - * callback registered by ramfs_init(). We look it up by name. - */ -extern file_system_type* get_fs_type(const char* name); -extern super_block* alloc_super(file_system_type* type); - -void vfs_init() -{ - /* 1. Look up the ramfs filesystem type */ - file_system_type* ramfs_type = get_fs_type("ramfs"); - if (!ramfs_type || !ramfs_type->mount) { - printk(KERN_ERR "vfs_init: ramfs not registered!\n"); - return; - } - - /* 2. Mount ramfs */ - super_block* sb = ramfs_type->mount(ramfs_type, 0, "ramfs", nullptr); - if (!sb || !sb->s_root) { - printk(KERN_ERR "vfs_init: failed to mount ramfs!\n"); - return; - } - - /* 3. Set global root */ - g_root_dentry = sb->s_root; - g_root_mnt = nullptr; /* TODO: allocate a proper vfsmount when mount.cc lands */ - - dget(g_root_dentry); /* Hold a reference for the global root */ - - printk(KERN_INFO "[vfs] root filesystem mounted (ramfs)\n"); - - /* 4. Set up VFS state for the current (BSP idle) task, - * which will be inherited by all subsequently created tasks. */ - TaskControlBlock* bsp = current_task(); - if (bsp) { - if (!bsp->files) { - bsp->files = alloc_files_struct(); - } - if (!bsp->fs) { - bsp->fs = alloc_fs_struct(); - if (bsp->fs) { - bsp->fs->root.de = g_root_dentry; - bsp->fs->root.mnt = g_root_mnt; - bsp->fs->pwd.de = g_root_dentry; - bsp->fs->pwd.mnt = g_root_mnt; - dget(g_root_dentry); /* root ref */ - dget(g_root_dentry); /* pwd ref */ - } - } - printk(KERN_INFO "[vfs] BSP task VFS context initialized\n"); - } -} diff --git a/include/libc-shim/bits/alltypes.h b/include/libc-shim/bits/alltypes.h deleted file mode 100644 index cf21a5e..0000000 --- a/include/libc-shim/bits/alltypes.h +++ /dev/null @@ -1,15 +0,0 @@ -/* Shim: provide types musl string functions need */ -#ifndef _BITS_ALLTYPES_H -#define _BITS_ALLTYPES_H - -#ifndef __cplusplus -typedef unsigned long size_t; -#endif - -typedef long ssize_t; -typedef unsigned long uintptr_t; - -/* locale_t stub — unused in kernel, but declared by some headers */ -typedef void *locale_t; - -#endif diff --git a/include/libc-shim/endian.h b/include/libc-shim/endian.h deleted file mode 100644 index 8346386..0000000 --- a/include/libc-shim/endian.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Shim: endianness for musl string functions */ -#ifndef _ENDIAN_H -#define _ENDIAN_H - -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __BYTE_ORDER __LITTLE_ENDIAN /* RISC-V is LE */ - -#endif diff --git a/include/libc-shim/features.h b/include/libc-shim/features.h deleted file mode 100644 index a3466c8..0000000 --- a/include/libc-shim/features.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Shim: musl expects this header */ -#ifndef _FEATURES_H -#define _FEATURES_H - -/* weak_alias: musl uses this for symbol aliasing (e.g. __memrchr -> memrchr) */ -#define weak_alias(old, new) \ - extern __typeof(old) new __attribute__((__weak__, __alias__(#old))) - -/* hidden attribute used by some musl sources */ -#define hidden __attribute__((__visibility__("hidden"))) - -#endif diff --git a/include/libc-shim/limits.h b/include/libc-shim/limits.h deleted file mode 100644 index a1d546e..0000000 --- a/include/libc-shim/limits.h +++ /dev/null @@ -1,17 +0,0 @@ -/* Shim: limits for musl string functions (memmem uses SIZE_MAX) */ -#ifndef _LIMITS_H -#define _LIMITS_H - -#define CHAR_BIT 8 -#define UCHAR_MAX 255 -#define SCHAR_MAX 127 -#define SCHAR_MIN (-128) -#define INT_MAX 2147483647 -#define INT_MIN (-INT_MAX - 1) -#define UINT_MAX 4294967295U -#define LONG_MAX 9223372036854775807L -#define LONG_MIN (-LONG_MAX - 1L) -#define ULONG_MAX 18446744073709551615UL -#define SIZE_MAX ULONG_MAX - -#endif diff --git a/include/libc-shim/stdint.h b/include/libc-shim/stdint.h deleted file mode 100644 index 650bdcf..0000000 --- a/include/libc-shim/stdint.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Shim: stdint types for musl string functions */ -#ifndef _STDINT_H -#define _STDINT_H - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long uint64_t; -typedef signed char int8_t; -typedef signed short int16_t; -typedef signed int int32_t; -typedef signed long int64_t; -typedef unsigned long uintptr_t; -typedef long intptr_t; - -#define UINT8_MAX 0xFF -#define UINT16_MAX 0xFFFF -#define UINT32_MAX 0xFFFFFFFFU -#define UINT64_MAX 0xFFFFFFFFFFFFFFFFUL - -#endif diff --git a/include/libc-shim/string.h b/include/libc-shim/string.h deleted file mode 100644 index 8a86304..0000000 --- a/include/libc-shim/string.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef _STRING_H -#define _STRING_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - -#define __NEED_size_t -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_locale_t -#endif - -#include - -void *memcpy (void *__restrict, const void *__restrict, size_t); -void *memmove (void *, const void *, size_t); -void *memset (void *, int, size_t); -int memcmp (const void *, const void *, size_t); -void *memchr (const void *, int, size_t); - -char *strcpy (char *__restrict, const char *__restrict); -char *strncpy (char *__restrict, const char *__restrict, size_t); - -char *strcat (char *__restrict, const char *__restrict); -char *strncat (char *__restrict, const char *__restrict, size_t); - -int strcmp (const char *, const char *); -int strncmp (const char *, const char *, size_t); - -int strcoll (const char *, const char *); -size_t strxfrm (char *__restrict, const char *__restrict, size_t); - -char *strchr (const char *, int); -char *strrchr (const char *, int); - -size_t strcspn (const char *, const char *); -size_t strspn (const char *, const char *); -char *strpbrk (const char *, const char *); -char *strstr (const char *, const char *); -char *strtok (char *__restrict, const char *__restrict); - -size_t strlen (const char *); - -char *strerror (int); - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#include -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); -int strerror_r (int, char *, size_t); -char *stpcpy(char *__restrict, const char *__restrict); -char *stpncpy(char *__restrict, const char *__restrict, size_t); -size_t strnlen (const char *, size_t); -char *strdup (const char *); -char *strndup (const char *, size_t); -char *strsignal(int); -char *strerror_l (int, locale_t); -int strcoll_l (const char *, const char *, locale_t); -size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); -void *memmem(const void *, size_t, const void *, size_t); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -void *memccpy (void *__restrict, const void *__restrict, int, size_t); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -char *strsep(char **, const char *); -size_t strlcat (char *, const char *, size_t); -size_t strlcpy (char *, const char *, size_t); -void explicit_bzero (void *, size_t); -#endif - -#ifdef _GNU_SOURCE -#define strdupa(x) strcpy(alloca(strlen(x)+1),x) -int strverscmp (const char *, const char *); -char *strchrnul(const char *, int); -char *strcasestr(const char *, const char *); -void *memrchr(const void *, int, size_t); -void *mempcpy(void *, const void *, size_t); -#endif - -/* musl internal symbols used across translation units */ -char *__strchrnul(const char *, int); -void *__memrchr(const void *, int, size_t); -char *__stpcpy(char *__restrict, const char *__restrict); -char *__stpncpy(char *__restrict, const char *__restrict, size_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/libc-shim/strings.h b/include/libc-shim/strings.h deleted file mode 100644 index b7a5ea0..0000000 --- a/include/libc-shim/strings.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _STRINGS_H -#define _STRINGS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_locale_t -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ - || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) -int bcmp (const void *, const void *, size_t); -void bcopy (const void *, void *, size_t); -void bzero (void *, size_t); -char *index (const char *, int); -char *rindex (const char *, int); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int ffs (int); -int ffsl (long); -int ffsll (long long); -#endif - -int strcasecmp (const char *, const char *); -int strncasecmp (const char *, const char *, size_t); - -int strcasecmp_l (const char *, const char *, locale_t); -int strncasecmp_l (const char *, const char *, size_t, locale_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/lume/addr.h b/include/lume/addr.h deleted file mode 100644 index 572b6fe..0000000 --- a/include/lume/addr.h +++ /dev/null @@ -1,91 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Machine-Independent Address Conversion Helpers - * - * All PA↔VA conversions in MI code (mm/, kernel/, etc.) must go through - * these functions. The actual offset is provided by . - * - * Reference: docs/specs/00_conventions.md §1.1 (MI/MD separation) - */ - -#include -#include -#include -#include - -/* Convert physical address to kernel virtual address (direct map). */ -inline VirtAddr pa_to_va(PhysAddr pa) -{ - return VirtAddr{pa.raw + arch::g_direct_map_base}; -} - -/* Convert kernel virtual address to physical address (direct map). */ -inline PhysAddr va_to_pa(VirtAddr va) -{ - return PhysAddr{va.raw - arch::g_direct_map_base}; -} - -/* - * Early-boot conversions pinned to the bootstrap direct-map base. - * - * Use these only before vmm_init() activates the final kernel page table. - * They are required when KASLR has already randomized g_direct_map_base, - * but the CPU is still running on the bootstrap mapping built in entry.S. - */ -inline VirtAddr boot_pa_to_va(PhysAddr pa) -{ - return VirtAddr{pa.raw + arch::kDirectMapBaseDefault}; -} - -inline PhysAddr boot_va_to_pa(VirtAddr va) -{ - return PhysAddr{va.raw - arch::kDirectMapBaseDefault}; -} - -/* Align up to page boundary */ -inline uint64 page_align_up(uint64 addr) -{ - return (addr + kPageSize - 1) & ~(kPageSize - 1); -} - -/* Align down to page boundary */ -inline uint64 page_align_down(uint64 addr) -{ - return addr & ~(kPageSize - 1); -} - -inline PhysAddr page_align_up(PhysAddr addr) -{ - return PhysAddr{page_align_up(addr.raw)}; -} - -inline PhysAddr page_align_down(PhysAddr addr) -{ - return PhysAddr{page_align_down(addr.raw)}; -} - -inline VirtAddr page_align_up(VirtAddr addr) -{ - return VirtAddr{page_align_up(addr.raw)}; -} - -inline VirtAddr page_align_down(VirtAddr addr) -{ - return VirtAddr{page_align_down(addr.raw)}; -} - -/* Convert physical address to page frame number (PFN) */ -inline Pfn pa_to_pfn(PhysAddr pa) -{ - return Pfn{pa.raw / kPageSize}; -} - -/* Convert page frame number (PFN) to physical address */ -inline PhysAddr pfn_to_pa(Pfn pfn) -{ - return PhysAddr{pfn.raw * kPageSize}; -} diff --git a/include/lume/addr_types.h b/include/lume/addr_types.h deleted file mode 100644 index 91a0779..0000000 --- a/include/lume/addr_types.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#include - -struct PhysAddr { - uint64 raw; -}; - -struct VirtAddr { - uint64 raw; -}; - -struct Pfn { - uint64 raw; -}; - -inline constexpr PhysAddr phys_addr(uint64 raw) { return PhysAddr{raw}; } -inline constexpr VirtAddr virt_addr(uint64 raw) { return VirtAddr{raw}; } -inline constexpr Pfn pfn(uint64 raw) { return Pfn{raw}; } - -inline constexpr bool operator==(PhysAddr a, PhysAddr b) { return a.raw == b.raw; } -inline constexpr bool operator!=(PhysAddr a, PhysAddr b) { return a.raw != b.raw; } -inline constexpr bool operator==(VirtAddr a, VirtAddr b) { return a.raw == b.raw; } -inline constexpr bool operator!=(VirtAddr a, VirtAddr b) { return a.raw != b.raw; } -inline constexpr bool operator==(Pfn a, Pfn b) { return a.raw == b.raw; } -inline constexpr bool operator!=(Pfn a, Pfn b) { return a.raw != b.raw; } diff --git a/include/lume/args.h b/include/lume/args.h deleted file mode 100644 index 0562dc5..0000000 --- a/include/lume/args.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -#ifndef _LINUX_ARGS_H -#define _LINUX_ARGS_H - -/* - * How do these macros work? - * - * In __COUNT_ARGS() _0 to _15 are just placeholders from the start - * in order to make sure _n is positioned over the correct number - * from 15 to 0 (depending on X, which is a variadic argument list). - * They serve no purpose other than occupying a position. Since each - * macro parameter must have a distinct identifier, those identifiers - * are as good as any. - * - * In COUNT_ARGS() we use actual integers, so __COUNT_ARGS() returns - * that as _n. - */ - -/* This counts to 15. Any more, it will return 16th argument. */ -#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _n, X...) _n -#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) - -/* Concatenate two parameters, but allow them to be expanded beforehand. */ -#define __CONCAT(a, b) a ## b -#define CONCATENATE(a, b) __CONCAT(a, b) - -#endif /* _LINUX_ARGS_H */ diff --git a/include/lume/atomic.h b/include/lume/atomic.h deleted file mode 100644 index 6e31129..0000000 --- a/include/lume/atomic.h +++ /dev/null @@ -1,76 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * lume::atomic — Thin wrapper over __atomic builtins. - * - * All multi-core shared data that does NOT use a spinlock MUST use - * this wrapper instead of raw __atomic_* builtins. - * - * Reference: docs/specs/00_conventions.md §5.3 - */ - -#include - -namespace lume { - -template -class atomic { -public: - atomic() = default; - explicit atomic(T val) : val_(val) {} - - /* Prevent copies — an atomic value has identity */ - atomic(const atomic&) = delete; - atomic& operator=(const atomic&) = delete; - - /* Load with specified memory ordering */ - T load(int order = __ATOMIC_SEQ_CST) const { - return __atomic_load_n(&val_, order); - } - - /* Store with specified memory ordering */ - void store(T desired, int order = __ATOMIC_SEQ_CST) { - __atomic_store_n(&val_, desired, order); - } - - /* Atomic exchange, returns old value */ - T exchange(T desired, int order = __ATOMIC_SEQ_CST) { - return __atomic_exchange_n(&val_, desired, order); - } - - /* Fetch-and-add, returns old value */ - T fetch_add(T delta, int order = __ATOMIC_ACQ_REL) { - return __atomic_fetch_add(&val_, delta, order); - } - - /* Fetch-and-subtract, returns old value */ - T fetch_sub(T delta, int order = __ATOMIC_ACQ_REL) { - return __atomic_fetch_sub(&val_, delta, order); - } - - /* Fetch-and-or, returns old value */ - T fetch_or(T mask, int order = __ATOMIC_ACQ_REL) { - return __atomic_fetch_or(&val_, mask, order); - } - - /* Fetch-and-and, returns old value */ - T fetch_and(T mask, int order = __ATOMIC_ACQ_REL) { - return __atomic_fetch_and(&val_, mask, order); - } - - /* Compare-and-swap. Returns true on success. */ - bool compare_exchange(T& expected, T desired, - int success_order = __ATOMIC_ACQ_REL, - int failure_order = __ATOMIC_ACQUIRE) { - return __atomic_compare_exchange_n(&val_, &expected, desired, - false, success_order, failure_order); - } - -private: - T val_ = 0; -}; - -} // namespace lume diff --git a/include/lume/bitops.h b/include/lume/bitops.h deleted file mode 100644 index 4227ca3..0000000 --- a/include/lume/bitops.h +++ /dev/null @@ -1,120 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Bit Operations — portable kernel bit manipulation utilities - * - * Provides ctz, clz, ffs, fls and related operations. - * All implementations are manual (no __builtin_ctz) to avoid - * generating libgcc __ctzdi2/__clzdi2 calls in freestanding. - */ - -#include - -namespace lume { - -/* ------------------------------------------------------------------ */ -/* Count Trailing Zeros (ctz) */ -/* Returns the number of trailing 0-bits in val. */ -/* Precondition: val != 0 (undefined if val == 0). */ -/* ------------------------------------------------------------------ */ - -static inline int ctz32(uint32 val) -{ - int n = 0; - if (!(val & 0x0000FFFFU)) { n += 16; val >>= 16; } - if (!(val & 0x000000FFU)) { n += 8; val >>= 8; } - if (!(val & 0x0000000FU)) { n += 4; val >>= 4; } - if (!(val & 0x00000003U)) { n += 2; val >>= 2; } - if (!(val & 0x00000001U)) { n += 1; } - return n; -} - -static inline int ctz64(uint64 val) -{ - if (static_cast(val) != 0) { - return ctz32(static_cast(val)); - } - return 32 + ctz32(static_cast(val >> 32)); -} - -/* ------------------------------------------------------------------ */ -/* Count Leading Zeros (clz) */ -/* Returns the number of leading 0-bits in val. */ -/* Precondition: val != 0 (undefined if val == 0). */ -/* ------------------------------------------------------------------ */ - -static inline int clz32(uint32 val) -{ - int n = 0; - if (!(val & 0xFFFF0000U)) { n += 16; val <<= 16; } - if (!(val & 0xFF000000U)) { n += 8; val <<= 8; } - if (!(val & 0xF0000000U)) { n += 4; val <<= 4; } - if (!(val & 0xC0000000U)) { n += 2; val <<= 2; } - if (!(val & 0x80000000U)) { n += 1; } - return n; -} - -static inline int clz64(uint64 val) -{ - if (static_cast(val >> 32) != 0) { - return clz32(static_cast(val >> 32)); - } - return 32 + clz32(static_cast(val)); -} - -/* ------------------------------------------------------------------ */ -/* Find First Set (ffs) — 1-indexed, returns 0 if val == 0 */ -/* ------------------------------------------------------------------ */ - -static inline int ffs32(uint32 val) -{ - return val ? ctz32(val) + 1 : 0; -} - -static inline int ffs64(uint64 val) -{ - return val ? ctz64(val) + 1 : 0; -} - -/* ------------------------------------------------------------------ */ -/* Find Last Set (fls) — 1-indexed, returns 0 if val == 0 */ -/* Returns the position of the highest set bit. */ -/* ------------------------------------------------------------------ */ - -static inline int fls32(uint32 val) -{ - return val ? 32 - clz32(val) : 0; -} - -static inline int fls64(uint64 val) -{ - return val ? 64 - clz64(val) : 0; -} - -/* ------------------------------------------------------------------ */ -/* Order (log2) — returns floor(log2(val)), val must be > 0 */ -/* ------------------------------------------------------------------ */ - -static inline int ilog2_32(uint32 val) -{ - return fls32(val) - 1; -} - -static inline int ilog2_64(uint64 val) -{ - return fls64(val) - 1; -} - -/* ------------------------------------------------------------------ */ -/* Power-of-two test */ -/* ------------------------------------------------------------------ */ - -static inline bool is_power_of_2(uint64 val) -{ - return val != 0 && (val & (val - 1)) == 0; -} - -} /* namespace lume */ diff --git a/include/lume/chardev.h b/include/lume/chardev.h deleted file mode 100644 index be81ab9..0000000 --- a/include/lume/chardev.h +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * chardev.h — Character device abstraction - * - * Minimal Linux-style cdev registry: each character device has a - * major/minor number and a file_operations table. - */ - -#include -#include - -struct file_operations; - -/* ================================================================== */ -/* MKDEV / MAJOR / MINOR */ -/* ================================================================== */ - -inline constexpr uint32 MKDEV(uint32 ma, uint32 mi) { - return (ma << 8) | (mi & 0xFF); -} -inline constexpr uint32 MAJOR(uint32 dev) { return dev >> 8; } -inline constexpr uint32 MINOR(uint32 dev) { return dev & 0xFF; } - -/* ================================================================== */ -/* cdev — character device descriptor */ -/* ================================================================== */ - -struct cdev { - const char* name; - uint32 dev; /* MKDEV(major, minor) */ - const file_operations* fops; - list_node list; /* global cdev list */ -}; - -/* ================================================================== */ -/* API */ -/* ================================================================== */ - -void cdev_init(); -void cdev_register(cdev* dev); -cdev* cdev_find(uint32 dev); diff --git a/include/lume/clone.h b/include/lume/clone.h deleted file mode 100644 index 156bae4..0000000 --- a/include/lume/clone.h +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Linux-compatible clone(2) flags. - * - * Only the flags relevant to current and near-future use are defined. - * Reference: include/uapi/linux/sched.h - */ - -#include - -/* Signal mask stored in low byte of clone flags */ -inline constexpr uint64 CSIGNAL = 0x000000ffULL; - -/* Sharing flags */ -inline constexpr uint64 CLONE_VM = 0x00000100ULL; // Share address space -inline constexpr uint64 CLONE_FS = 0x00000200ULL; // Share fs info -inline constexpr uint64 CLONE_FILES = 0x00000400ULL; // Share file descriptors -inline constexpr uint64 CLONE_SIGHAND = 0x00000800ULL; // Share signal handlers -inline constexpr uint64 CLONE_PIDFD = 0x00001000ULL; // pidfd -inline constexpr uint64 CLONE_PTRACE = 0x00002000ULL; // Trace child -inline constexpr uint64 CLONE_VFORK = 0x00004000ULL; // Parent blocks until child exits/execs -inline constexpr uint64 CLONE_PARENT = 0x00008000ULL; // Same parent as cloner -inline constexpr uint64 CLONE_THREAD = 0x00010000ULL; // Same thread group -inline constexpr uint64 CLONE_NEWNS = 0x00020000ULL; // New mount namespace -inline constexpr uint64 CLONE_SYSVSEM = 0x00040000ULL; // Share SysV semaphore undo -inline constexpr uint64 CLONE_SETTLS = 0x00080000ULL; // Set TLS -inline constexpr uint64 CLONE_PARENT_SETTID = 0x00100000ULL; // Write TID to parent -inline constexpr uint64 CLONE_CHILD_CLEARTID = 0x00200000ULL; // Clear TID on child exit -inline constexpr uint64 CLONE_DETACHED = 0x00400000ULL; // Unused, historical -inline constexpr uint64 CLONE_CHILD_SETTID = 0x01000000ULL; // Write TID to child diff --git a/include/lume/compiler.h b/include/lume/compiler.h deleted file mode 100644 index 243f0de..0000000 --- a/include/lume/compiler.h +++ /dev/null @@ -1,54 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_COMPILER_H -#define _LUME_COMPILER_H - -/* - * Minimal compiler primitives used across LumeOS. - * - * Provides only what current code actually references: - * - READ_ONCE / WRITE_ONCE memory access opacity for concurrent code - * (rbtree.h, rbtree_augmented.h) - * - likely / unlikely branch hints for hot/cold paths - * - * Implementation mirrors Linux's semantics — same surface, same effect — - * without pulling in Linux's compiler_types.h cascade (KASAN/KCSAN/KMSAN - * sanitizer attribute machinery, BTF type tags, hardened-usercopy hooks). - * LumeOS doesn't build with those sanitizers, so the simpler form is - * sufficient and keeps the dependency graph flat. - */ - -/* Branch prediction hints */ -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) - -/* Compile-time barrier — prevent the compiler from reordering memory - * accesses across this point. Not a CPU fence; for CPU ordering use - * the architecture-specific fence intrinsics. */ -#define barrier() __asm__ __volatile__("" ::: "memory") - -/* - * __always_inline — force the compiler to actually inline a function, - * overriding -fno-inline / -Os / size heuristics. Used by rbtree helper - * templates whose performance depends on the call being inlined into - * the iterating loop. - */ -#define __always_inline inline __attribute__((__always_inline__)) - -/* - * READ_ONCE / WRITE_ONCE — opaque single-access memory operations. - * - * The volatile cast prevents the compiler from: - * - merging adjacent reads/writes to the same location, - * - splitting a load into multiple narrower loads, - * - hoisting reads out of a loop (or sinking writes past one). - * - * Used in lock-free / cross-CPU shared data paths (rbtree color writes, - * future RCU pointers, atomic flag polls). Does NOT imply any CPU-side - * memory ordering — pair with smp_mb()/acquire/release for that. - */ -#define READ_ONCE(x) (*(const volatile __typeof__(x) *)&(x)) -#define WRITE_ONCE(x, val) (*(volatile __typeof__(x) *)&(x) = (val)) - -#endif /* _LUME_COMPILER_H */ diff --git a/include/lume/config.h b/include/lume/config.h deleted file mode 100644 index bde717a..0000000 --- a/include/lume/config.h +++ /dev/null @@ -1,100 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * LumeOS Global Compile-Time Configuration - * - * All kernel-wide tuning constants live here. - * Architecture-specific constants live in . - * - * This header is safe to include from both C++ and assembly files. - * Assembly-visible constants use #define; C++ code gets typed constexpr. - * - * Values are injected by the build system via -DCONFIG_xxx flags - * (see scripts/Kconfig.mk). The #ifndef guards below provide - * safe defaults so the header is self-contained for IDE analysis. - * - * Reference: docs/specs/00_conventions.md §1.3 - */ - -/* ================================================================ - * Defaults — only used when CONFIG_xxx is NOT supplied by -D flag. - * In a normal build, scripts/Kconfig.mk always provides them. - * ================================================================ */ - -#ifndef CONFIG_NR_CPUS -#define CONFIG_NR_CPUS 8 -#endif - -#ifndef CONFIG_PAGE_SIZE -#define CONFIG_PAGE_SIZE 4096 -#endif - -#ifndef CONFIG_MAX_ORDER -#define CONFIG_MAX_ORDER 11 -#endif - -#ifndef CONFIG_KERNEL_STACK_SIZE -#define CONFIG_KERNEL_STACK_SIZE 16384 -#endif - -#ifndef CONFIG_HZ -#define CONFIG_HZ 100 -#endif - -#ifndef CONFIG_NR_PRIORITIES -#define CONFIG_NR_PRIORITIES 32 -#endif - -#ifndef CONFIG_DEFAULT_PRIORITY -#define CONFIG_DEFAULT_PRIORITY (CONFIG_NR_PRIORITIES / 2) -#endif - -#ifndef CONFIG_IDLE_PRIORITY -#define CONFIG_IDLE_PRIORITY (CONFIG_NR_PRIORITIES - 1) -#endif - -#ifndef CONFIG_DEFAULT_TIMESLICE -#define CONFIG_DEFAULT_TIMESLICE (CONFIG_HZ / 10) -#endif - -#ifndef CONFIG_KASLR_POLICY_ID -#define CONFIG_KASLR_POLICY_ID 0 /* Default: basic KASLR policy */ -#endif - -#ifndef CONFIG_KASLR_LOG_LEVEL -#define CONFIG_KASLR_LOG_LEVEL 1 /* 0=off, 1=minimal, 2=debug */ -#endif - -/* ================================================================ - * Legacy compatibility aliases (shared with assembly) - * ================================================================ */ -#define LUME_MAX_CPUS CONFIG_NR_CPUS -#define LUME_PAGE_SIZE CONFIG_PAGE_SIZE - -#ifndef __ASSEMBLER__ - -#include - -/* Maximum number of CPUs supported by the kernel. - * Compile-time limit for static arrays (boot stacks, per-cpu data). - * Actual CPU count is detected at runtime via FDT. */ -inline constexpr int kMaxCpus = CONFIG_NR_CPUS; - -/* Virtual memory page size (4KB, matching SV39 base page). */ -inline constexpr uint64 kPageSize = CONFIG_PAGE_SIZE; - -/* Page shift: log2(kPageSize). Used for PFN ↔ PA conversions. */ -inline constexpr int kPageShift = 12; // 4096 = 1 << 12 - -/* KASLR policy ID and logging level (build-time configurable) */ -inline constexpr uint32 kKaslrPolicyId = CONFIG_KASLR_POLICY_ID; -inline constexpr int kKaslrLogLevel = CONFIG_KASLR_LOG_LEVEL; - -#include - -using arch::kPhysStart; - -#endif /* __ASSEMBLER__ */ \ No newline at end of file diff --git a/include/lume/console.h b/include/lume/console.h deleted file mode 100644 index af187a6..0000000 --- a/include/lume/console.h +++ /dev/null @@ -1,77 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * console.h — Kernel console abstraction - * - * Two-phase design following Linux: - * - * Phase 1 (early boot): - * early_putc() → direct UART MMIO write. Used before MMU and - * before the console registry is ready. kprintf() and panic - * use this path. - * - * Phase 2 (runtime): - * struct console registered via register_console(). printk/klog - * emit through the console driver chain. Multiple consoles can - * be registered (e.g., UART + framebuffer). - * - * Reference: Linux include/linux/console.h - */ - -#include -#include - -/* ================================================================== */ -/* Early console (Phase 1 — direct UART access) */ -/* ================================================================== */ - -extern "C" void early_putc(char c); -extern "C" void early_puts(const char* s); -extern "C" void console_set_mmu_enabled(); - -/* Early UART discovery via raw FDT parsing. */ -void console_early_init(uint64 fdt_paddr); - -/* Full console initialization. Maps MMIO. */ -void console_init(); - -/* - * Notify console that the runtime kernel page table is active. - * After this point early_putc() must use runtime direct-map base - * instead of the bootstrap fixed base. - */ -void console_use_runtime_mapping(); - -/* ================================================================== */ -/* struct console (Phase 2 — registered console drivers) */ -/* ================================================================== */ - -inline constexpr int CON_PRINTBUFFER = (1 << 0); /* Replay klog on register */ -inline constexpr int CON_ENABLED = (1 << 1); -inline constexpr int CON_BOOT = (1 << 2); /* Early boot console */ - -struct console { - const char* name; - void (*write)(console* con, const char* s, unsigned int count); - int (*setup)(console* con, char* options); - int flags; - int index; - void* data; /* driver private data */ - list_node list; -}; - -/* Register / unregister a console driver */ -void register_console(console* con); -void unregister_console(console* con); - -/* - * Write to all registered consoles. - * Falls back to early_putc() if no console is registered. - */ -void console_write_all(const char* s, int count); - -/* Check if any console is registered */ -bool console_drivers_registered(); diff --git a/include/lume/container_of.h b/include/lume/container_of.h deleted file mode 100644 index a6889eb..0000000 --- a/include/lume/container_of.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * container_of.h — Recover containing struct from member pointer - * - * Equivalent to Linux include/linux/container_of.h. - */ - -#include - -#define container_of(ptr, type, member) \ - reinterpret_cast( \ - reinterpret_cast(ptr) - \ - reinterpret_cast(&(reinterpret_cast(0)->member))) diff --git a/include/lume/dcache.h b/include/lume/dcache.h deleted file mode 100644 index a31402e..0000000 --- a/include/lume/dcache.h +++ /dev/null @@ -1,143 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * dcache.h — Directory entry cache - * - * Modeled after Linux include/linux/dcache.h. - * Reference: docs/vfs/03_dentry.md - */ - -#include -#include -#include -#include -#include - -struct inode; -struct super_block; -struct dentry; -struct dentry_operations; -struct path; - -/* ================================================================== */ -/* qstr — quick string (name + precomputed hash + length) */ -/* ================================================================== */ - -struct qstr { - union { - struct { - uint32 hash; - uint32 len; - }; - uint64 hash_len; - }; - const char* name; -}; - -uint32 full_name_hash(const char* name, uint32 len); - -/* ================================================================== */ -/* dentry */ -/* ================================================================== */ - -inline constexpr int DNAME_INLINE_LEN = 40; - -struct dentry { - /* ---- RCU / lookup hot fields ---- */ - unsigned int d_flags; - dentry* d_parent; - qstr d_name; - inode* d_inode; - unsigned char d_iname[DNAME_INLINE_LEN]; - - /* ---- Ref lookup ---- */ - const dentry_operations* d_op; - super_block* d_sb; - unsigned long d_time; - void* d_fsdata; - - /* ---- Refcount + lock ---- */ - lume::atomic d_lockref; - Spinlock d_lock; - - /* ---- Tree linkage ---- */ - list_node d_lru; - list_node d_child; /* Linkage in parent->d_children */ - list_head d_children; /* Children of this dentry */ - - /* ---- Inode alias ---- */ - list_node d_alias; /* Linkage in inode->i_dentry */ -}; - -/* ================================================================== */ -/* dentry_operations */ -/* ================================================================== */ - -struct dentry_operations { - int (*d_revalidate)(dentry* de, unsigned int flags); - int (*d_hash)(const dentry* de, qstr* name); - int (*d_compare)(const dentry* parent, unsigned int len, - const char* str, const qstr* name); - int (*d_delete)(const dentry* de); - int (*d_init)(dentry* de); - void (*d_release)(dentry* de); - void (*d_iput)(dentry* de, inode* ip); -}; - -/* ================================================================== */ -/* Dentry helpers */ -/* ================================================================== */ - -inline bool d_is_negative(const dentry* de) { - return (de->d_flags & DCACHE_ENTRY_TYPE) == DCACHE_MISS_TYPE; -} -inline bool d_is_positive(const dentry* de) { - return !d_is_negative(de); -} -inline bool d_is_dir(const dentry* de) { - return (de->d_flags & DCACHE_ENTRY_TYPE) == DCACHE_DIRECTORY_TYPE; -} -inline bool d_is_reg(const dentry* de) { - return (de->d_flags & DCACHE_ENTRY_TYPE) == DCACHE_REGULAR_TYPE; -} -inline bool d_is_symlink(const dentry* de) { - return (de->d_flags & DCACHE_ENTRY_TYPE) == DCACHE_SYMLINK_TYPE; -} -inline bool d_mountpoint(const dentry* de) { - return (de->d_flags & DCACHE_MOUNTED) != 0; -} -inline bool d_is_root(const dentry* de) { - return de == de->d_parent; -} - -inline inode* d_inode_ptr(const dentry* de) { - return de->d_inode; -} - -/* ================================================================== */ -/* Dcache API */ -/* ================================================================== */ - -dentry* d_alloc(dentry* parent, const qstr* name); -dentry* d_alloc_anon(super_block* sb); -void d_instantiate(dentry* de, inode* ip); -dentry* d_make_root(inode* root_inode); -void d_add(dentry* de, inode* ip); -dentry* d_lookup(const dentry* parent, const qstr* name); -dentry* dget(dentry* de); -void dput(dentry* de); -void d_drop(dentry* de); -void d_delete(dentry* de); -char* d_path(const path* p, char* buf, int buflen); - -/* Set dentry type flags based on inode mode */ -void d_set_type(dentry* de, uint32 i_mode); - -/* ================================================================== */ -/* Dcache init */ -/* ================================================================== */ - -void dcache_init(); diff --git a/include/lume/device.h b/include/lume/device.h deleted file mode 100644 index 46e22e4..0000000 --- a/include/lume/device.h +++ /dev/null @@ -1,75 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Driver model: device, device_driver, bus_type. - * - * Mirrors Linux include/linux/device.h. Every hardware unit embeds a - * `device` and binds to a `device_driver` via a `bus_type` that knows - * how to match the two. Buses we will have: - * - platform: FDT-described memory-mapped devices (this commit) - * - virtio: virtio-mmio devices (P5 of storage_stack.md) - * - * Reference: docs/specs/storage_stack.md §4.3 - */ - -#include -#include -#include -#include - -struct bus_type; -struct device_driver; - -struct device { - kobject kobj; // embedded; first member by convention - device* parent; - const char* init_name; // used until kobj.name is set - bus_type* bus; - device_driver* driver; - void* driver_data; - void* platform_data; - uint32 devt; // for char/block dev_t allocation - list_node bus_list; // node in bus->devices - list_node driver_list; // node in driver->devices -}; - -struct device_driver { - const char* name; - bus_type* bus; - int (*probe)(device*); - void (*remove)(device*); - list_node bus_node; // node in bus->drivers - list_node devices; // head of devices bound to this driver -}; - -struct bus_type { - const char* name; - int (*match)(device*, device_driver*); - /* If non-null, this is the bus-level probe dispatcher. It is called - * before drv->probe and is responsible for downcasting device/driver - * to the concrete bus type and forwarding (e.g. platform_dispatch). */ - int (*probe)(device*); - list_node devices; - list_node drivers; - Spinlock lock; - bool registered; -}; - -int bus_register (bus_type* bus); - -/* device_initialize: kobject_init the embedded kobj with the generic - * device_ktype. device_register calls this automatically if the caller - * hasn't already. Separate entry point for callers that want a half- - * initialized device (so they can take refs before adding). */ -void device_initialize(device* dev); -int device_register (device* dev); -void device_unregister(device* dev); - -int driver_register (device_driver* drv); -void driver_unregister(device_driver* drv); - -/* Convenience accessor — name from kobject if set, else init_name. */ -const char* dev_name(const device* dev); diff --git a/include/lume/device_node.h b/include/lume/device_node.h deleted file mode 100644 index e35f22d..0000000 --- a/include/lume/device_node.h +++ /dev/null @@ -1,64 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * DeviceNode — FDT object tree node - * - * Each DeviceNode represents a single node in the unflattened device tree. - * Nodes form a parent-children hierarchy via intrusive linked lists. - * After unflattening, the tree is globally read-only and requires no locks. - * - * Created when Slab is available. - * - * Reference: docs/specs/fdt.md §3.2 - */ - -#include -#include -#include - -class DeviceNode { -public: - // Construction / destruction (used by FdtManager::unflatten) - DeviceNode(DeviceNode *parent, const char *name); - ~DeviceNode(); - - // --- Property access --- - - // Look up a property by name. Returns nullptr if not found. - const FdtProperty *get_prop(const char *name) const; - - // Convenience helpers that decode the property value. - // Return default_val when the property does not exist. - uint32 get_prop_u32(const char *name, uint32 default_val = 0) const; - uint64 get_prop_u64(const char *name, uint64 default_val = 0) const; - const char *get_prop_string(const char *name) const; - - // --- Child traversal --- - - // Find a direct child by name. Returns nullptr if not found. - DeviceNode *find_child(const char *name); - - // Invoke callback for every direct child. - void for_each_child(void (*callback)(DeviceNode *)); - - // --- Internal (used by FdtManager to build the tree) --- - void add_child(DeviceNode *child); - void add_prop(FdtProperty *prop); - - // --- Accessors for tree traversal --- - const char *get_name() const { return name_; } - list_node *children_list_head() { return children_list_.next; } - list_node *children_list_sentinel() { return &children_list_; } - - // sibling_link_ offset needed by container_of in fdt.cc - list_node sibling_link_; // Link in parent's children_list_ - -private: - const char *name_; // Node name (e.g. "memory@80000000") - DeviceNode *parent_; // Parent node (nullptr for root) - list_node children_list_; // Head of the children linked list - list_node props_list_; // Head of the property linked list -}; diff --git a/include/lume/driver.h b/include/lume/driver.h deleted file mode 100644 index a8bd787..0000000 --- a/include/lume/driver.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * driver.h — boot-time driver probing entry point. - * - * The actual driver-model primitives (kobject, device, bus_type, - * platform_device, platform_driver) live in their own headers: - * , , . - * - * This header just exposes the single boot entry point that - * kernel_main() calls after the slab allocator + FDT unflatten are - * ready. The implementation lives in drivers/base/platform.cc. - * - * Reference: docs/specs/storage_stack.md §4 - */ - -/* Register the platform bus, register every linker-set platform_driver, - * walk the FDT, and instantiate a platform_device for each compatible - * match. Each device is bound to its driver via the platform bus - * match/probe path. Returns after all probes have run. */ -void driver_probe_all(); diff --git a/include/lume/elf.h b/include/lume/elf.h deleted file mode 100644 index 772ad97..0000000 --- a/include/lume/elf.h +++ /dev/null @@ -1,150 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * ELF64 Type Definitions — Minimal set for loading executables - * AND for the kernel's own .rela.dyn relocation walk at boot. - * - * Follows the ELF specification (Tool Interface Standard, TIS). - * Only includes what's needed for static ELF64 executable loading. - * - * Reference: https://refspecs.linuxfoundation.org/elf/elf.pdf - */ - -#include - -/* ================================================================== */ -/* Basic ELF types */ -/* ================================================================== */ - -using Elf64_Addr = uint64; -using Elf64_Off = uint64; -using Elf64_Half = uint16; -using Elf64_Word = uint32; -using Elf64_Sword = int32; -using Elf64_Xword = uint64; -using Elf64_Sxword = int64; - -/* ================================================================== */ -/* ELF Header */ -/* ================================================================== */ - -inline constexpr int EI_NIDENT = 16; - -struct Elf64_Ehdr { - uint8 e_ident[EI_NIDENT]; /* ELF identification */ - Elf64_Half e_type; /* Object file type */ - Elf64_Half e_machine; /* Machine type */ - Elf64_Word e_version; /* Object file version */ - Elf64_Addr e_entry; /* Entry point address */ - Elf64_Off e_phoff; /* Program header table offset */ - Elf64_Off e_shoff; /* Section header table offset */ - Elf64_Word e_flags; /* Processor-specific flags */ - Elf64_Half e_ehsize; /* ELF header size */ - Elf64_Half e_phentsize; /* Program header entry size */ - Elf64_Half e_phnum; /* Number of program headers */ - Elf64_Half e_shentsize; /* Section header entry size */ - Elf64_Half e_shnum; /* Number of section headers */ - Elf64_Half e_shstrndx; /* Section name string table index */ -}; - -/* e_ident[] indices */ -inline constexpr int EI_MAG0 = 0; -inline constexpr int EI_MAG1 = 1; -inline constexpr int EI_MAG2 = 2; -inline constexpr int EI_MAG3 = 3; -inline constexpr int EI_CLASS = 4; -inline constexpr int EI_DATA = 5; -inline constexpr int EI_VERSION = 6; -inline constexpr int EI_OSABI = 7; - -/* e_ident[] magic */ -inline constexpr uint8 ELFMAG0 = 0x7f; -inline constexpr uint8 ELFMAG1 = 'E'; -inline constexpr uint8 ELFMAG2 = 'L'; -inline constexpr uint8 ELFMAG3 = 'F'; - -/* e_ident[EI_CLASS] */ -inline constexpr uint8 ELFCLASS64 = 2; - -/* e_ident[EI_DATA] */ -inline constexpr uint8 ELFDATA2LSB = 1; /* Little-endian */ - -/* e_type */ -inline constexpr Elf64_Half ET_EXEC = 2; /* Executable */ -inline constexpr Elf64_Half ET_DYN = 3; /* Shared object (PIE) */ - -/* e_machine */ -inline constexpr Elf64_Half EM_RISCV = 243; - -/* ================================================================== */ -/* Program Header */ -/* ================================================================== */ - -struct Elf64_Phdr { - Elf64_Word p_type; /* Segment type */ - Elf64_Word p_flags; /* Segment flags */ - Elf64_Off p_offset; /* File offset */ - Elf64_Addr p_vaddr; /* Virtual address */ - Elf64_Addr p_paddr; /* Physical address (unused) */ - Elf64_Xword p_filesz; /* Size in file */ - Elf64_Xword p_memsz; /* Size in memory (>= p_filesz, diff is BSS) */ - Elf64_Xword p_align; /* Alignment */ -}; - -/* p_type values */ -inline constexpr Elf64_Word PT_NULL = 0; -inline constexpr Elf64_Word PT_LOAD = 1; -inline constexpr Elf64_Word PT_DYNAMIC = 2; -inline constexpr Elf64_Word PT_INTERP = 3; -inline constexpr Elf64_Word PT_NOTE = 4; -inline constexpr Elf64_Word PT_PHDR = 6; -inline constexpr Elf64_Word PT_GNU_STACK = 0x6474e551; - -/* p_flags values */ -inline constexpr Elf64_Word PF_X = 0x1; /* Execute */ -inline constexpr Elf64_Word PF_W = 0x2; /* Write */ -inline constexpr Elf64_Word PF_R = 0x4; /* Read */ - -/* ================================================================== */ -/* Auxiliary Vector types */ -/* ================================================================== */ - -struct Elf64_auxv_t { - uint64 a_type; - uint64 a_val; -}; - -inline constexpr uint64 AT_NULL = 0; -inline constexpr uint64 AT_PHDR = 3; -inline constexpr uint64 AT_PHENT = 4; -inline constexpr uint64 AT_PHNUM = 5; -inline constexpr uint64 AT_PAGESZ = 6; -inline constexpr uint64 AT_ENTRY = 9; -inline constexpr uint64 AT_UID = 11; -inline constexpr uint64 AT_EUID = 12; -inline constexpr uint64 AT_GID = 13; -inline constexpr uint64 AT_EGID = 14; -inline constexpr uint64 AT_RANDOM = 25; -inline constexpr uint64 AT_BASE = 7; /* PIE load base address */ - -/* ================================================================== */ -/* RELA relocation entry — used by the kernel's own .rela.dyn walk */ -/* at boot (relocate_kernel in arch/riscv/mm/init.cc). */ -/* ================================================================== */ - -struct Elf64_Rela { - Elf64_Addr r_offset; /* link-time VA of the slot to patch */ - Elf64_Xword r_info; /* r_sym << 32 | r_type */ - Elf64_Sxword r_addend; /* link-time value of the target */ -}; - -#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFFULL) - -/* RISC-V relocation types — only the ones a PIE-linked kernel emits - * into .rela.dyn under `-shared -Bsymbolic`. */ -inline constexpr uint32 R_RISCV_NONE = 0; -inline constexpr uint32 R_RISCV_64 = 2; -inline constexpr uint32 R_RISCV_RELATIVE = 3; diff --git a/include/lume/errno.h b/include/lume/errno.h deleted file mode 100644 index f3bf09f..0000000 --- a/include/lume/errno.h +++ /dev/null @@ -1,186 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_ERRNO_H -#define _LUME_ERRNO_H - -/* - * Error codes — numeric values aligned with Linux's asm-generic/errno-base.h, - * asm-generic/errno.h, and linux/errno.h (kernel-internal codes 512+). - * - * Userspace-visible codes (1..133) match POSIX / Linux exactly so a LumeOS - * binary returning -EINVAL to a user program receives the same number Linux - * would. Kernel-internal codes (>= 512) follow Linux's convention of being - * out of POSIX range; they are translated to a user-visible code (typically - * EINTR) before crossing into user mode. - * - * Defined as plain #define so this header is usable from C, C++, and - * assembly (the macros expand to integer literals, no types). - */ - -/* ===== Base errors (asm-generic/errno-base.h equivalent) ===== */ -#define EPERM 1 /* Operation not permitted */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* I/O error */ -#define ENXIO 6 /* No such device or address */ -#define E2BIG 7 /* Argument list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file number */ -#define ECHILD 10 /* No child processes */ -#define EAGAIN 11 /* Try again */ -#define ENOMEM 12 /* Out of memory */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ENOTBLK 15 /* Block device required */ -#define EBUSY 16 /* Device or resource busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* No such device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* File table overflow */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Not a typewriter */ -#define ETXTBSY 26 /* Text file busy */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ -#define EDOM 33 /* Math argument out of domain */ -#define ERANGE 34 /* Math result not representable */ - -/* ===== Extended errors (asm-generic/errno.h equivalent) ===== */ -#define EDEADLK 35 /* Resource deadlock would occur */ -#define ENAMETOOLONG 36 /* File name too long */ -#define ENOLCK 37 /* No record locks available */ -#define ENOSYS 38 /* Invalid system call number */ -#define ENOTEMPTY 39 /* Directory not empty */ -#define ELOOP 40 /* Too many symbolic links encountered */ -#define EWOULDBLOCK EAGAIN /* Operation would block */ -#define ENOMSG 42 /* No message of desired type */ -#define EIDRM 43 /* Identifier removed */ -#define ECHRNG 44 /* Channel number out of range */ -#define EL2NSYNC 45 /* Level 2 not synchronized */ -#define EL3HLT 46 /* Level 3 halted */ -#define EL3RST 47 /* Level 3 reset */ -#define ELNRNG 48 /* Link number out of range */ -#define EUNATCH 49 /* Protocol driver not attached */ -#define ENOCSI 50 /* No CSI structure available */ -#define EL2HLT 51 /* Level 2 halted */ -#define EBADE 52 /* Invalid exchange */ -#define EBADR 53 /* Invalid request descriptor */ -#define EXFULL 54 /* Exchange full */ -#define ENOANO 55 /* No anode */ -#define EBADRQC 56 /* Invalid request code */ -#define EBADSLT 57 /* Invalid slot */ -#define EDEADLOCK EDEADLK -#define EBFONT 59 /* Bad font file format */ -#define ENOSTR 60 /* Device not a stream */ -#define ENODATA 61 /* No data available */ -#define ETIME 62 /* Timer expired */ -#define ENOSR 63 /* Out of streams resources */ -#define ENONET 64 /* Machine is not on the network */ -#define ENOPKG 65 /* Package not installed */ -#define EREMOTE 66 /* Object is remote */ -#define ENOLINK 67 /* Link has been severed */ -#define EADV 68 /* Advertise error */ -#define ESRMNT 69 /* Srmount error */ -#define ECOMM 70 /* Communication error on send */ -#define EPROTO 71 /* Protocol error */ -#define EMULTIHOP 72 /* Multihop attempted */ -#define EDOTDOT 73 /* RFS specific error */ -#define EBADMSG 74 /* Not a data message */ -#define EOVERFLOW 75 /* Value too large for defined data type */ -#define ENOTUNIQ 76 /* Name not unique on network */ -#define EBADFD 77 /* File descriptor in bad state */ -#define EREMCHG 78 /* Remote address changed */ -#define ELIBACC 79 /* Cannot access a needed shared library */ -#define ELIBBAD 80 /* Accessing a corrupted shared library */ -#define ELIBSCN 81 /* .lib section in a.out corrupted */ -#define ELIBMAX 82 /* Linking in too many shared libraries */ -#define ELIBEXEC 83 /* Cannot exec a shared library directly */ -#define EILSEQ 84 /* Illegal byte sequence */ -#define ERESTART 85 /* Interrupted system call should be restarted */ -#define ESTRPIPE 86 /* Streams pipe error */ -#define EUSERS 87 /* Too many users */ -#define ENOTSOCK 88 /* Socket operation on non-socket */ -#define EDESTADDRREQ 89 /* Destination address required */ -#define EMSGSIZE 90 /* Message too long */ -#define EPROTOTYPE 91 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 92 /* Protocol not available */ -#define EPROTONOSUPPORT 93 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ -#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ -#define ENOTSUP EOPNOTSUPP -#define EPFNOSUPPORT 96 /* Protocol family not supported */ -#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ -#define EADDRINUSE 98 /* Address already in use */ -#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ -#define ENETDOWN 100 /* Network is down */ -#define ENETUNREACH 101 /* Network is unreachable */ -#define ENETRESET 102 /* Network dropped connection because of reset */ -#define ECONNABORTED 103 /* Software caused connection abort */ -#define ECONNRESET 104 /* Connection reset by peer */ -#define ENOBUFS 105 /* No buffer space available */ -#define EISCONN 106 /* Transport endpoint is already connected */ -#define ENOTCONN 107 /* Transport endpoint is not connected */ -#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ -#define ETOOMANYREFS 109 /* Too many references: cannot splice */ -#define ETIMEDOUT 110 /* Connection timed out */ -#define ECONNREFUSED 111 /* Connection refused */ -#define EHOSTDOWN 112 /* Host is down */ -#define EHOSTUNREACH 113 /* No route to host */ -#define EALREADY 114 /* Operation already in progress */ -#define EINPROGRESS 115 /* Operation now in progress */ -#define ESTALE 116 /* Stale file handle */ -#define EUCLEAN 117 /* Structure needs cleaning */ -#define ENOTNAM 118 /* Not a XENIX named type file */ -#define ENAVAIL 119 /* No XENIX semaphores available */ -#define EISNAM 120 /* Is a named type file */ -#define EREMOTEIO 121 /* Remote I/O error */ -#define EDQUOT 122 /* Quota exceeded */ -#define ENOMEDIUM 123 /* No medium found */ -#define EMEDIUMTYPE 124 /* Wrong medium type */ -#define ECANCELED 125 /* Operation Canceled */ -#define ENOKEY 126 /* Required key not available */ -#define EKEYEXPIRED 127 /* Key has expired */ -#define EKEYREVOKED 128 /* Key has been revoked */ -#define EKEYREJECTED 129 /* Key was rejected by service */ -#define EOWNERDEAD 130 /* Owner died (for robust mutexes) */ -#define ENOTRECOVERABLE 131 /* State not recoverable */ -#define ERFKILL 132 /* Operation not possible due to RF-kill */ -#define EHWPOISON 133 /* Memory page has hardware error */ - -/* ===== Kernel-internal errors (linux/errno.h equivalent, >= 512) ===== - * These should never be seen by user programs. signal/syscall layer - * translates them to a user-visible code (typically EINTR) before - * returning to userspace. - */ -#define ERESTARTSYS 512 -#define ERESTARTNOINTR 513 -#define ERESTARTNOHAND 514 /* restart if no signal handler */ -#define ENOIOCTLCMD 515 /* No ioctl command */ -#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */ -#define EPROBE_DEFER 517 /* Driver requests probe retry */ -#define EOPENSTALE 518 /* open() found a stale dentry */ -#define ENOPARAM 519 /* Parameter not supported */ - -/* NFSv3 reserved range (521..531) */ -#define EBADHANDLE 521 /* Illegal NFS file handle */ -#define ENOTSYNC 522 /* Update synchronization mismatch */ -#define EBADCOOKIE 523 /* Cookie is stale */ -#define ENOTSUPP 524 /* Operation is not supported */ -#define ETOOSMALL 525 /* Buffer or request is too small */ -#define ESERVERFAULT 526 /* An untranslatable error occurred */ -#define EBADTYPE 527 /* Type not supported by server */ -#define EJUKEBOX 528 /* Request initiated, will not complete before timeout */ -#define EIOCBQUEUED 529 /* iocb queued, will get completion event */ -#define ERECALLCONFLICT 530 /* conflict with recalled state */ -#define ENOGRACE 531 /* NFS file lock reclaim refused */ - -#endif /* _LUME_ERRNO_H */ diff --git a/include/lume/fdt.h b/include/lume/fdt.h deleted file mode 100644 index 626cc48..0000000 --- a/include/lume/fdt.h +++ /dev/null @@ -1,85 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * FdtManager — Flattened Device Tree parser - * - * Two-phase design: - * Phase 1 (Early Scan): Static methods that walk the raw FDT blob - * without any memory allocation. Used before PMM is available. - * Phase 2 (Unflatten): Builds a persistent C++ DeviceNode object - * tree once Slab is ready. The tree is then globally read-only. - * - * Concurrency: all init is done by BSP in the single-core window. - * After unflattening the tree is immutable — no locks required. - * - * Reference: docs/specs/fdt.md - */ - -#include -#include - -class FdtManager { -public: - // Construct with the physical address of the FDT blob. - // Called via Placement New in fdt_init(). - FdtManager(uint64 fdt_paddr); - - // --- Phase 1: Early scan (static, allocation-free) --- - - // Extract physical memory base and size from the /memory node. - // Panics if the FDT is invalid or /memory is missing. - static void early_scan_mem(uint64 fdt_paddr, uint64 *base, uint64 *size); - - // Extract the UART base address and size by matching compatible = "ns16550a". - // Falls back to platform default on failure. - static void early_scan_uart(uint64 fdt_paddr, uint64 *uart_addr, - uint64 *uart_size); - - static void early_scan_kaslr(uint64 fdt_paddr, uint64 *seed); - - // --- Phase 2: Object tree construction (requires Slab) --- - - // Walk the FDT blob and build the DeviceNode tree. - void unflatten(); - - // --- Query interface (read-only after unflatten) --- - - // Find the first node whose "compatible" property contains the string. - // Returns nullptr if no match. - DeviceNode *find_compatible(const char *compat_string); - - // Look up a node by its full path (e.g. "/soc/uart@10000000"). - // Returns nullptr if not found. - DeviceNode *get_node_by_path(const char *path); - - // Return the stored FDT physical address. - uint64 get_paddr() const { return fdt_paddr_; } - -private: - uint64 fdt_paddr_; // Physical address of the FDT blob - bool is_unflattened_ = false; // True after unflatten() completes - DeviceNode *root_ = nullptr; // Root of the unflattened tree -}; - -/* Global FDT manager singleton (Placement New, see global_init.md §3.1) */ -extern FdtManager *g_fdt; - -// --- Public free-function API --- - -// Save FDT address and validate magic. Called early by BSP. -void fdt_init(uint64 fdt_paddr); - -// Build the DeviceNode object tree. Requires Slab. -void fdt_unflatten(); - -// Driver probing helpers (delegate to g_fdt). -DeviceNode *fdt_find_compatible(const char *compat_string); -DeviceNode *fdt_get_node_by_path(const char *path); - -// Early scan wrappers (delegate to FdtManager static methods). -void fdt_early_get_mem_info(uint64 *base, uint64 *size); -void fdt_early_get_uart_info(uint64 *uart_addr, uint64 *uart_size); -void fdt_early_get_kaslr_seed(uint64 *seed); diff --git a/include/lume/fdt_prop.h b/include/lume/fdt_prop.h deleted file mode 100644 index f8a263c..0000000 --- a/include/lume/fdt_prop.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * FDT Property - * - * Represents a single property within a DeviceNode (e.g. "reg", - * "compatible"). The value pointer points directly into the - * original FDT blob — no copies are made. - * - * Reference: docs/specs/fdt.md §3.1 - */ - -#include -#include - -struct FdtProperty { - const char *name; // Property name (points into FDT strings block) - const void *value; // Raw property data (points into FDT struct block) - int len; // Length of value in bytes - list_node link; // Intrusive link into DeviceNode's property list -}; diff --git a/include/lume/fdtable.h b/include/lume/fdtable.h deleted file mode 100644 index 6159519..0000000 --- a/include/lume/fdtable.h +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * fdtable.h — Per-task file descriptor table - * - * Modeled after Linux include/linux/fdtable.h. - * Reference: docs/vfs/05_fdtable.md - */ - -#include -#include -#include - -struct file; - -/* ================================================================== */ -/* files_struct — per-task open file table */ -/* ================================================================== */ - -inline constexpr int NR_OPEN_DEFAULT = 256; - -struct files_struct { - lume::atomic count; /* Reference count (CLONE_FILES) */ - Spinlock file_lock; - - int next_fd; /* Hint for next free fd */ - int max_fds; /* Current max (= NR_OPEN_DEFAULT) */ - file* fd_array[NR_OPEN_DEFAULT]; - uint64 close_on_exec_init[(NR_OPEN_DEFAULT + 63) / 64]; - uint64 open_fds_init[(NR_OPEN_DEFAULT + 63) / 64]; -}; - -/* ================================================================== */ -/* API */ -/* ================================================================== */ - -files_struct* alloc_files_struct(); -void put_files_struct(files_struct* files); -files_struct* dup_fd(files_struct* old_files); - -int alloc_fd(files_struct* files, unsigned int start); -void fd_install(files_struct* files, int fd, file* fp); -file* fcheck(files_struct* files, int fd); -int close_fd(files_struct* files, int fd); -int do_dup2(files_struct* files, int oldfd, int newfd, int flags); -void do_close_on_exec(files_struct* files); diff --git a/include/lume/features.h b/include/lume/features.h deleted file mode 100644 index 85cfb72..0000000 --- a/include/lume/features.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _FEATURES_H -#define _FEATURES_H - -#if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) -#define _GNU_SOURCE 1 -#endif - -#if defined(_DEFAULT_SOURCE) && !defined(_BSD_SOURCE) -#define _BSD_SOURCE 1 -#endif - -#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ - && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \ - && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__) -#define _BSD_SOURCE 1 -#define _XOPEN_SOURCE 700 -#endif - -#if __STDC_VERSION__ >= 199901L -#define __restrict restrict -#elif !defined(__GNUC__) -#define __restrict -#endif - -#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) -#define __inline inline -#elif !defined(__GNUC__) -#define __inline -#endif - -#if __STDC_VERSION__ >= 201112L -#elif defined(__GNUC__) -#define _Noreturn __attribute__((__noreturn__)) -#else -#define _Noreturn -#endif - -#define __REDIR(x,y) __typeof__(x) x __asm__(#y) - -#endif diff --git a/include/lume/file.h b/include/lume/file.h deleted file mode 100644 index 349059b..0000000 --- a/include/lume/file.h +++ /dev/null @@ -1,132 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * file.h — Open file description + file_operations + path + vfsmount - * - * Modeled after Linux include/linux/fs.h struct file / file_operations. - * Reference: docs/vfs/04_file.md - */ - -#include -#include -#include -#include - -struct inode; -struct dentry; -struct super_block; -struct address_space; -struct dir_context; -struct VmAreaStruct; -struct kstat; - -/* ================================================================== */ -/* vfsmount (public part) */ -/* ================================================================== */ - -struct vfsmount { - dentry* mnt_root; - super_block* mnt_sb; - int mnt_flags; -}; - -vfsmount* mntget(vfsmount* mnt); -void mntput(vfsmount* mnt); - -/* ================================================================== */ -/* path */ -/* ================================================================== */ - -struct path { - vfsmount* mnt; - dentry* de; /* Linux calls this 'dentry' but that conflicts in C++ */ -}; - -void path_get(const path* p); -void path_put(const path* p); - -/* ================================================================== */ -/* file */ -/* ================================================================== */ - -struct file_operations; - -struct file { - Spinlock f_lock; - uint32 f_mode; /* FMODE_* */ - const file_operations* f_op; - address_space* f_mapping; - void* private_data; - inode* f_inode; - unsigned int f_flags; /* O_* */ - - path f_path; - - int64 f_pos; - lume::atomic f_count; -}; - -/* ================================================================== */ -/* Accessors */ -/* ================================================================== */ - -inline inode* file_inode(const file* f) { return f->f_inode; } -inline dentry* file_dentry(const file* f) { return f->f_path.de; } - -file* get_file(file* f); -file* alloc_empty_file(int flags); -void fput(file* fp); - -/* ================================================================== */ -/* dir_context (for iterate_shared / getdents64) */ -/* ================================================================== */ - -struct dir_context; -using filldir_t = bool (*)(dir_context* ctx, const char* name, int namelen, - int64 offset, uint64 ino, unsigned int d_type); - -struct dir_context { - filldir_t actor; - int64 pos; -}; - -/* ================================================================== */ -/* file_operations */ -/* ================================================================== */ - -struct file_operations { - int64 (*llseek)(file* fp, int64 offset, int whence); - int64 (*read)(file* fp, char* buf, uint64 count, int64* pos); - int64 (*write)(file* fp, const char* buf, uint64 count, int64* pos); - int (*iterate_shared)(file* fp, dir_context* ctx); - uint32 (*poll)(file* fp, void* pt); - long (*unlocked_ioctl)(file* fp, unsigned int cmd, uint64 arg); - int (*mmap)(file* fp, VmAreaStruct* vma); - int (*open)(inode* ip, file* fp); - int (*flush)(file* fp); - int (*release)(inode* ip, file* fp); - int (*fsync)(file* fp, int64 start, int64 end, int datasync); -}; - -/* ================================================================== */ -/* VFS read/write/seek */ -/* ================================================================== */ - -int64 vfs_read(file* fp, char* buf, uint64 count, int64* pos); -int64 vfs_write(file* fp, const char* buf, uint64 count, int64* pos); -int64 vfs_llseek(file* fp, int64 offset, int whence); -int vfs_fstat(file* fp, kstat* stat); - -/* Generic helpers for simple fs */ -int64 generic_file_llseek(file* fp, int64 offset, int whence); - -/* ================================================================== */ -/* path helpers */ -/* ================================================================== */ - -inline bool path_equal(const path* a, const path* b) { - return a->mnt == b->mnt && a->de == b->de; -} diff --git a/include/lume/fs.h b/include/lume/fs.h deleted file mode 100644 index 8dac552..0000000 --- a/include/lume/fs.h +++ /dev/null @@ -1,310 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * fs.h — Core VFS data structures - * - * Defines super_block, inode, address_space, and their operations. - * Modeled after Linux include/linux/fs.h + include/linux/fs/super_types.h. - * - * Reference: docs/vfs/01_super_block.md, docs/vfs/02_inode.md - */ - -#include -#include -#include -#include -#include - -/* Forward declarations */ -struct super_block; -struct inode; -struct dentry; -struct file; -struct vfsmount; -struct path; -struct kstat; -struct iattr; -struct file_operations; -struct inode_operations; -struct dentry_operations; -struct dir_context; -struct pipe_inode_info; -struct VmAreaStruct; -struct Page; - -/* ================================================================== */ -/* address_space_operations */ -/* ================================================================== */ - -struct address_space_operations { - int (*read_folio)(file* fp, Page* page); - int (*write_begin)(struct address_space* mapping, int64 pos, - unsigned len, Page** pagep, void** fsdata); - int (*write_end)(struct address_space* mapping, int64 pos, - unsigned len, unsigned copied, - Page* page, void* fsdata); -}; - -/* ================================================================== */ -/* address_space */ -/* ================================================================== */ - -struct address_space { - inode* host; - const address_space_operations* a_ops; - uint64 nrpages; - uint64 flags; - Spinlock i_private_lock; -}; - -/* ================================================================== */ -/* super_operations */ -/* ================================================================== */ - -struct super_operations { - inode* (*alloc_inode)(super_block* sb); - void (*destroy_inode)(inode* ip); - void (*free_inode)(inode* ip); - - void (*dirty_inode)(inode* ip, int flags); - int (*write_inode)(inode* ip, bool sync); - int (*drop_inode)(inode* ip); - void (*evict_inode)(inode* ip); - void (*put_super)(super_block* sb); - int (*sync_fs)(super_block* sb, int wait); - int (*statfs)(dentry* de, struct kstatfs* buf); - void (*umount_begin)(super_block* sb); -}; - -/* ================================================================== */ -/* file_system_type */ -/* ================================================================== */ - -struct file_system_type { - const char* name; - int fs_flags; - super_block* (*mount)(file_system_type* type, int flags, - const char* dev_name, void* data); - void (*kill_sb)(super_block* sb); - list_node fs_list; -}; - -int register_filesystem(file_system_type* fs); -file_system_type* get_fs_type(const char* name); - -/* ================================================================== */ -/* super_block */ -/* ================================================================== */ - -struct mount; - -struct super_block { - list_node s_list; - uint64 s_dev; - uint8 s_blocksize_bits; - uint64 s_blocksize; - int64 s_maxbytes; - file_system_type* s_type; - const super_operations* s_op; - - uint64 s_flags; - uint64 s_magic; - dentry* s_root; - - char s_id[32]; - void* s_fs_info; - - uint32 s_time_gran; - int64 s_time_min; - int64 s_time_max; - - Spinlock s_inode_list_lock; - list_head s_inodes; - - lume::atomic s_active; - int s_count; - - mount* s_mounts; - uint32 s_max_links; - const dentry_operations* s_d_op; -}; - -/* ================================================================== */ -/* inode */ -/* ================================================================== */ - -struct inode { - /* ---- Path-walk hot fields ---- */ - uint32 i_mode; - uint32 i_flags; - uint32 i_uid; - uint32 i_gid; - - const inode_operations* i_op; - super_block* i_sb; - address_space* i_mapping; - - /* ---- Stat data ---- */ - uint64 i_ino; - uint32 i_nlink; /* Use set_nlink/inc_nlink/drop_nlink */ - uint32 i_rdev; - int64 i_size; - - int64 i_atime_sec; - int64 i_mtime_sec; - int64 i_ctime_sec; - uint32 i_atime_nsec; - uint32 i_mtime_nsec; - uint32 i_ctime_nsec; - uint32 i_generation; - - Spinlock i_lock; - unsigned short i_bytes; - uint8 i_blkbits; - int64 i_blocks; - - /* ---- State ---- */ - uint32 i_state; - - /* ---- Lists ---- */ - list_node i_sb_list; - list_head i_dentry; - - /* ---- Counters ---- */ - lume::atomic i_count; - lume::atomic i_writecount; - - /* ---- File ops ---- */ - const file_operations* i_fop; - - /* ---- Embedded address_space ---- */ - address_space i_data; - - /* ---- Type-specific ---- */ - union { - pipe_inode_info* i_pipe; - char* i_link; - uint32 i_dir_seq; - }; - - void* i_private; -}; - -/* ================================================================== */ -/* inode_operations */ -/* ================================================================== */ - -struct inode_operations { - dentry* (*lookup)(inode* dir, dentry* de, unsigned int flags); - int (*create)(inode* dir, dentry* de, uint32 mode, bool excl); - int (*link)(dentry* old_de, inode* dir, dentry* new_de); - int (*unlink)(inode* dir, dentry* de); - int (*symlink)(inode* dir, dentry* de, const char* target); - int (*mkdir)(inode* dir, dentry* de, uint32 mode); - int (*rmdir)(inode* dir, dentry* de); - int (*mknod)(inode* dir, dentry* de, uint32 mode, uint32 rdev); - int (*rename)(inode* old_dir, dentry* old_de, - inode* new_dir, dentry* new_de, unsigned int flags); - int (*setattr)(dentry* de, iattr* attr); - int (*getattr)(const path* p, kstat* stat, uint32 request_mask, - unsigned int query_flags); - const char* (*get_link)(dentry* de, inode* ip); - int (*permission)(inode* ip, int mask); -}; - -/* ================================================================== */ -/* Inode API */ -/* ================================================================== */ - -inode* new_inode(super_block* sb); -inode* iget(super_block* sb, uint64 ino); -void iput(inode* ip); -void ihold(inode* ip); -void mark_inode_dirty(inode* ip); - -void set_nlink(inode* ip, uint32 nlink); -void inc_nlink(inode* ip); -void drop_nlink(inode* ip); -void clear_nlink(inode* ip); - -void inode_init_owner(inode* ip, const inode* dir, uint32 mode); - -/* Generic helpers used by simple filesystems */ -void generic_fillattr(inode* ip, kstat* stat); - -/* ================================================================== */ -/* kstat (matches oscomp ABI layout exactly) */ -/* ================================================================== */ - -struct kstat { - uint64 st_dev; - uint64 st_ino; - uint32 st_mode; - uint32 st_nlink; - uint32 st_uid; - uint32 st_gid; - uint64 st_rdev; - uint64 __pad; - int64 st_size; - int32 st_blksize; - int32 __pad2; - int64 st_blocks; - int64 st_atime_sec; - int64 st_atime_nsec; - int64 st_mtime_sec; - int64 st_mtime_nsec; - int64 st_ctime_sec; - int64 st_ctime_nsec; - uint32 __unused[2]; -}; - -struct kstatfs { - int64 f_type; - int64 f_bsize; - uint64 f_blocks; - uint64 f_bfree; - uint64 f_bavail; - uint64 f_files; - uint64 f_ffree; - int32 f_fsid[2]; - int64 f_namelen; - int64 f_frsize; - int64 f_flags; - int64 f_spare[4]; -}; - -/* ================================================================== */ -/* iattr (for setattr) */ -/* ================================================================== */ - -struct iattr { - unsigned int ia_valid; /* ATTR_* flags */ - uint32 ia_mode; - uint32 ia_uid; - uint32 ia_gid; - int64 ia_size; - int64 ia_atime_sec; - int64 ia_atime_nsec; - int64 ia_mtime_sec; - int64 ia_mtime_nsec; - int64 ia_ctime_sec; - int64 ia_ctime_nsec; -}; - -/* ATTR_* flags */ -inline constexpr uint32 ATTR_MODE = (1U << 0); -inline constexpr uint32 ATTR_UID = (1U << 1); -inline constexpr uint32 ATTR_GID = (1U << 2); -inline constexpr uint32 ATTR_SIZE = (1U << 3); -inline constexpr uint32 ATTR_ATIME = (1U << 4); -inline constexpr uint32 ATTR_MTIME = (1U << 5); -inline constexpr uint32 ATTR_CTIME = (1U << 6); - -/* ================================================================== */ -/* VFS init */ -/* ================================================================== */ - -void vfs_init(); diff --git a/include/lume/fs_struct.h b/include/lume/fs_struct.h deleted file mode 100644 index ba643b5..0000000 --- a/include/lume/fs_struct.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * fs_struct.h — Per-task filesystem context (cwd, root) - * - * Modeled after Linux include/linux/fs_struct.h. - * Reference: docs/vfs/05_fdtable.md - */ - -#include -#include -#include /* struct path */ -#include - -/* ================================================================== */ -/* fs_struct */ -/* ================================================================== */ - -struct fs_struct { - lume::atomic count; /* Reference count (CLONE_FS) */ - Spinlock lock; - int umask; /* File creation mask */ - path root; /* Root directory */ - path pwd; /* Current working directory */ -}; - -/* ================================================================== */ -/* API */ -/* ================================================================== */ - -fs_struct* alloc_fs_struct(); -void put_fs_struct(fs_struct* fs); -fs_struct* copy_fs_struct(const fs_struct* old_fs); - -void set_fs_root(fs_struct* fs, const path* p); -void set_fs_pwd(fs_struct* fs, const path* p); diff --git a/include/lume/fs_types.h b/include/lume/fs_types.h deleted file mode 100644 index 767f37c..0000000 --- a/include/lume/fs_types.h +++ /dev/null @@ -1,197 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * fs_types.h — File mode constants, open flags, seek constants - * - * All values match Linux asm-generic so musl/busybox binaries work. - * Reference: docs/vfs/02_inode.md, docs/vfs/04_file.md - */ - -#include - -/* ================================================================== */ -/* S_IF* — file type in inode::i_mode upper bits */ -/* ================================================================== */ - -inline constexpr uint32 S_IFMT = 0170000; -inline constexpr uint32 S_IFSOCK = 0140000; -inline constexpr uint32 S_IFLNK = 0120000; -inline constexpr uint32 S_IFREG = 0100000; -inline constexpr uint32 S_IFBLK = 0060000; -inline constexpr uint32 S_IFDIR = 0040000; -inline constexpr uint32 S_IFCHR = 0020000; -inline constexpr uint32 S_IFIFO = 0010000; - -inline constexpr uint32 S_ISUID = 04000; -inline constexpr uint32 S_ISGID = 02000; -inline constexpr uint32 S_ISVTX = 01000; - -inline constexpr uint32 S_IRWXU = 00700; -inline constexpr uint32 S_IRUSR = 00400; -inline constexpr uint32 S_IWUSR = 00200; -inline constexpr uint32 S_IXUSR = 00100; -inline constexpr uint32 S_IRWXG = 00070; -inline constexpr uint32 S_IRGRP = 00040; -inline constexpr uint32 S_IWGRP = 00020; -inline constexpr uint32 S_IXGRP = 00010; -inline constexpr uint32 S_IRWXO = 00007; -inline constexpr uint32 S_IROTH = 00004; -inline constexpr uint32 S_IWOTH = 00002; -inline constexpr uint32 S_IXOTH = 00001; - -inline bool S_ISREG(uint32 m) { return (m & S_IFMT) == S_IFREG; } -inline bool S_ISDIR(uint32 m) { return (m & S_IFMT) == S_IFDIR; } -inline bool S_ISCHR(uint32 m) { return (m & S_IFMT) == S_IFCHR; } -inline bool S_ISBLK(uint32 m) { return (m & S_IFMT) == S_IFBLK; } -inline bool S_ISFIFO(uint32 m) { return (m & S_IFMT) == S_IFIFO; } -inline bool S_ISLNK(uint32 m) { return (m & S_IFMT) == S_IFLNK; } -inline bool S_ISSOCK(uint32 m) { return (m & S_IFMT) == S_IFSOCK; } - -/* ================================================================== */ -/* O_* — open(2) flags */ -/* ================================================================== */ - -inline constexpr int O_RDONLY = 00; -inline constexpr int O_WRONLY = 01; -inline constexpr int O_RDWR = 02; -inline constexpr int O_ACCMODE = 03; -inline constexpr int O_CREAT = 0100; -inline constexpr int O_EXCL = 0200; -inline constexpr int O_NOCTTY = 0400; -inline constexpr int O_TRUNC = 01000; -inline constexpr int O_APPEND = 02000; -inline constexpr int O_NONBLOCK = 04000; -inline constexpr int O_DSYNC = 010000; -inline constexpr int O_DIRECTORY = 0200000; -inline constexpr int O_NOFOLLOW = 0400000; -inline constexpr int O_CLOEXEC = 02000000; - -/* ================================================================== */ -/* AT_* — *at() syscall dirfd constants */ -/* ================================================================== */ - -inline constexpr int AT_FDCWD = -100; -inline constexpr int AT_REMOVEDIR = 0x200; -inline constexpr int AT_SYMLINK_NOFOLLOW = 0x100; -inline constexpr int AT_EMPTY_PATH = 0x1000; - -/* ================================================================== */ -/* SEEK_* — lseek(2) whence */ -/* ================================================================== */ - -inline constexpr int SEEK_SET = 0; -inline constexpr int SEEK_CUR = 1; -inline constexpr int SEEK_END = 2; - -/* ================================================================== */ -/* FMODE_* — internal file mode flags */ -/* ================================================================== */ - -inline constexpr uint32 FMODE_READ = (1U << 0); -inline constexpr uint32 FMODE_WRITE = (1U << 1); -inline constexpr uint32 FMODE_LSEEK = (1U << 2); -inline constexpr uint32 FMODE_PREAD = (1U << 3); -inline constexpr uint32 FMODE_PWRITE = (1U << 4); -inline constexpr uint32 FMODE_EXEC = (1U << 5); -inline constexpr uint32 FMODE_CAN_READ = (1U << 17); -inline constexpr uint32 FMODE_CAN_WRITE = (1U << 18); -inline constexpr uint32 FMODE_OPENED = (1U << 19); -inline constexpr uint32 FMODE_CREATED = (1U << 20); -inline constexpr uint32 FMODE_STREAM = (1U << 21); - -/* ================================================================== */ -/* MAY_* — permission check flags */ -/* ================================================================== */ - -inline constexpr int MAY_EXEC = 0x00000001; -inline constexpr int MAY_WRITE = 0x00000002; -inline constexpr int MAY_READ = 0x00000004; -inline constexpr int MAY_OPEN = 0x00000020; -inline constexpr int MAY_CHDIR = 0x00000040; - -/* ================================================================== */ -/* DT_* — directory entry types (for getdents64) */ -/* ================================================================== */ - -inline constexpr uint8 DT_UNKNOWN = 0; -inline constexpr uint8 DT_FIFO = 1; -inline constexpr uint8 DT_CHR = 2; -inline constexpr uint8 DT_DIR = 4; -inline constexpr uint8 DT_BLK = 6; -inline constexpr uint8 DT_REG = 8; -inline constexpr uint8 DT_LNK = 10; -inline constexpr uint8 DT_SOCK = 12; - -/* ================================================================== */ -/* SB_* — super_block flags */ -/* ================================================================== */ - -inline constexpr uint64 SB_RDONLY = (1ULL << 0); -inline constexpr uint64 SB_NOSUID = (1ULL << 1); -inline constexpr uint64 SB_NODEV = (1ULL << 2); -inline constexpr uint64 SB_NOEXEC = (1ULL << 3); -inline constexpr uint64 SB_SYNCHRONOUS = (1ULL << 4); -inline constexpr uint64 SB_NOATIME = (1ULL << 10); -inline constexpr uint64 SB_NODIRATIME = (1ULL << 11); -inline constexpr uint64 SB_SILENT = (1ULL << 15); -inline constexpr uint64 SB_KERNMOUNT = (1ULL << 22); -inline constexpr uint64 SB_LAZYTIME = (1ULL << 25); -inline constexpr uint64 SB_ACTIVE = (1ULL << 30); - -/* ================================================================== */ -/* MNT_* — mount flags */ -/* ================================================================== */ - -inline constexpr int MNT_NOSUID = 0x01; -inline constexpr int MNT_NODEV = 0x02; -inline constexpr int MNT_NOEXEC = 0x04; -inline constexpr int MNT_NOATIME = 0x08; -inline constexpr int MNT_RELATIME = 0x20; -inline constexpr int MNT_READONLY = 0x40; -inline constexpr int MNT_INTERNAL = 0x4000; - -/* ================================================================== */ -/* Inode state flags */ -/* ================================================================== */ - -inline constexpr uint32 I_NEW = (1U << 0); -inline constexpr uint32 I_DIRTY_SYNC = (1U << 4); -inline constexpr uint32 I_DIRTY_DATASYNC = (1U << 5); -inline constexpr uint32 I_DIRTY_PAGES = (1U << 6); -inline constexpr uint32 I_WILL_FREE = (1U << 7); -inline constexpr uint32 I_FREEING = (1U << 8); -inline constexpr uint32 I_CLEAR = (1U << 9); -inline constexpr uint32 I_REFERENCED = (1U << 10); -inline constexpr uint32 I_DIRTY_TIME = (1U << 12); -inline constexpr uint32 I_CREATING = (1U << 15); - -inline constexpr uint32 I_DIRTY_INODE = I_DIRTY_SYNC | I_DIRTY_DATASYNC; -inline constexpr uint32 I_DIRTY = I_DIRTY_INODE | I_DIRTY_PAGES; - -/* ================================================================== */ -/* DCACHE_* — dentry flags */ -/* ================================================================== */ - -inline constexpr uint32 DCACHE_OP_HASH = (1U << 0); -inline constexpr uint32 DCACHE_OP_COMPARE = (1U << 1); -inline constexpr uint32 DCACHE_OP_REVALIDATE = (1U << 2); -inline constexpr uint32 DCACHE_DISCONNECTED = (1U << 5); -inline constexpr uint32 DCACHE_REFERENCED = (1U << 6); -inline constexpr uint32 DCACHE_CANT_MOUNT = (1U << 8); -inline constexpr uint32 DCACHE_MOUNTED = (1U << 15); -inline constexpr uint32 DCACHE_ENTRY_TYPE = (7U << 19); -inline constexpr uint32 DCACHE_MISS_TYPE = (0U << 19); -inline constexpr uint32 DCACHE_DIRECTORY_TYPE = (2U << 19); -inline constexpr uint32 DCACHE_REGULAR_TYPE = (4U << 19); -inline constexpr uint32 DCACHE_SPECIAL_TYPE = (5U << 19); -inline constexpr uint32 DCACHE_SYMLINK_TYPE = (6U << 19); - -/* ================================================================== */ -/* FS_* — file_system_type flags */ -/* ================================================================== */ - -inline constexpr int FS_REQUIRES_DEV = 1; -inline constexpr int FS_NO_DEVICE = 2; diff --git a/include/lume/init.h b/include/lume/init.h deleted file mode 100644 index 541ab96..0000000 --- a/include/lume/init.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_INIT_H -#define _LUME_INIT_H - -/* - * Boot-time section markers. - * - * Mirrors the subset of Linux include/linux/init.h that LumeOS uses: - * - * __init mark a function as boot-only — emitted into .init.text, - * which the kernel can later free once setup_arch / - * start_kernel have finished (LumeOS doesn't yet reclaim - * this memory, but the segment lives so future versions - * can without source changes). - * __initdata same for data, emitted into .init.data. - * asmlinkage ABI marker for C functions called from assembly. On - * RISC-V the default C ABI matches the assembly calling - * convention, so this is empty (matches Linux RISC-V). - * - * No attempt is made to mirror Linux's COMMAND_LINE_SIZE / saved_command_line - * machinery — that belongs in a future . - */ - -#define __init __attribute__((section(".init.text"))) -#define __initdata __attribute__((section(".init.data"))) - -#ifndef asmlinkage -#define asmlinkage /* RISC-V: empty, ABI already matches */ -#endif - -#endif /* _LUME_INIT_H */ diff --git a/include/lume/irq.h b/include/lume/irq.h deleted file mode 100644 index f5f34e4..0000000 --- a/include/lume/irq.h +++ /dev/null @@ -1,84 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * IRQ Manager — Dynamic Interrupt Dispatch - * - * Drivers register ISR callbacks at init time via register_handler(). - * The MI trap layer calls dispatch() when an external interrupt arrives. - * dispatch() runs in interrupt context — handlers must be short and - * non-blocking. - * - * Lock contract: - * - lock_ protects register/unregister (cold path). - * - dispatch() is lock-free: handler pointers are published with RELEASE - * semantics and read with ACQUIRE in dispatch(). - * - Handlers must not acquire VmSpace::lock or sleep. - * - * Reference: docs/specs/trap.md §3.3 - */ - -#include -#include - -/* IRQ handler callback signature */ -using IrqHandler = void (*)(uint32 irq, void *arg); - -/* Abstract Interrupt Controller Interface */ -struct IrqChip { - const char* name; - uint32 (*claim)(); - void (*complete)(uint32 irq); - void (*init_ap)(); - void (*enable)(uint32 irq); - void (*disable)(uint32 irq); - void (*set_priority)(uint32 irq, uint32 priority); -}; - -class IrqManager { -public: - void init(); - - /* Register an ISR for the given IRQ number. - * Returns 0 on success, -EINVAL if irq out of range, -EBUSY if already - * registered. */ - int register_handler(uint32 irq, IrqHandler handler, void *arg); - - /* Unregister the ISR for the given IRQ number. */ - void unregister_handler(uint32 irq); - - /* Dispatch an interrupt to the registered handler. - * Called from MI trap layer in interrupt context. Lock-free. */ - void dispatch(uint32 irq); - - /* Set the active interrupt controller chip */ - void set_chip(const IrqChip* chip); - const IrqChip* get_chip() const { return chip_; } - - /* Architecture-independent claim and complete for the active IRQ chip */ - uint32 claim() const; - void complete(uint32 irq) const; - void init_ap() const; - void enable(uint32 irq) const; - void disable(uint32 irq) const; - void set_priority(uint32 irq, uint32 priority) const; - - /* Check if a handler is registered for the given IRQ. */ - bool has_handler(uint32 irq) const; - - static constexpr uint32 kMaxIrqs = 64; - -private: - struct IrqEntry { - lume::atomic handler_ptr; // Stored as uint64 for atomic access - void *arg = nullptr; - }; - - const IrqChip* chip_ = nullptr; - IrqEntry entries_[kMaxIrqs]; -}; - -/* Global IRQ manager singleton */ -extern IrqManager g_irq_manager; diff --git a/include/lume/kbuild.h b/include/lume/kbuild.h deleted file mode 100644 index 4c3e12a..0000000 --- a/include/lume/kbuild.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_KBUILD_H -#define _LUME_KBUILD_H - -/* - * Helpers for arch//kernel/asm-offsets.c — 1:1 with Linux - * include/linux/kbuild.h. - * - * Trick: each DEFINE/OFFSET emits an inline-asm ".ascii" directive - * containing a literal "->" prefix. When the file is compiled with - * - * $(CC) -S asm-offsets.c -o asm-offsets.s - * - * the resulting assembly contains lines like - * - * ->KERNEL_MAP_VIRT_ADDR $0 offsetof(struct kernel_mapping, virt_addr) - * - * scripts/extract-asm-offsets.sed then rewrites those into proper - * `#define KERNEL_MAP_VIRT_ADDR 0` lines for inclusion from head.S. - * - * The benefit over hand-written #defines is that struct layout changes - * are caught at build time: rearrange a field and the asm offset - * changes automatically. - */ - -#define DEFINE(sym, val) \ - asm volatile("\n.ascii \"->" #sym " %0 " #val "\"" : : "i" (val)) - -#define BLANK() \ - asm volatile("\n.ascii \"->\"" : : ) - -#define OFFSET(sym, str, mem) \ - DEFINE(sym, offsetof(struct str, mem)) - -#define COMMENT(x) \ - asm volatile("\n.ascii \"->#" x "\"") - -#endif /* _LUME_KBUILD_H */ diff --git a/include/lume/kernel_map.h b/include/lume/kernel_map.h deleted file mode 100644 index 7eafe88..0000000 --- a/include/lume/kernel_map.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_KERNEL_MAP_H -#define _LUME_KERNEL_MAP_H - -/* - * struct kernel_mapping — where the kernel image lives in physical and - * virtual memory. Field names and order match Linux's - * arch/riscv/include/asm/page.h struct kernel_mapping so that: - * - * 1. arch/riscv/kernel/head.S can do `la a1, kernel_map` then - * `REG_L a1, KERNEL_MAP_VIRT_ADDR(a1)` and read the virtual - * address. The KERNEL_MAP_* asm constants come from - * , produced by arch/riscv/kernel/ - * asm-offsets.c at build time — re-order the struct and the - * asm offsets follow automatically. - * - * 2. arch/riscv/mm/init.c (Linux origin) populates the same fields - * with the same semantics so no source edits are needed. - */ - -#ifndef __ASSEMBLY__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct kernel_mapping { - unsigned long virt_addr; - unsigned long virt_offset; - uintptr_t phys_addr; - uintptr_t size; - unsigned long va_pa_offset; - unsigned long page_offset; - unsigned long va_kernel_pa_offset; -}; - -extern struct kernel_mapping kernel_map; - -#ifdef __cplusplus -} -#endif - -#else /* __ASSEMBLY__ */ - -/* Assembly sees only the field offsets, picked up from the generated - * header. Including the C struct above would be a parse error. */ -#include - -#endif /* __ASSEMBLY__ */ - -#endif /* _LUME_KERNEL_MAP_H */ diff --git a/include/lume/klog.h b/include/lume/klog.h deleted file mode 100644 index 69ab269..0000000 --- a/include/lume/klog.h +++ /dev/null @@ -1,200 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Kernel Logging Subsystem - * - * All kernel output goes through klog(), which formats messages into - * a fixed-size ring buffer and optionally emits them to the console. - * - * Architecture: - * vsnprintf_() ← pure formatting (mpaland/printf) - * ↓ - * KlogBuffer (ring) ← all messages stored here - * ↓ - * early_putc() (sync) ← current: synchronous UART output - * klogd thread (async) ← future: background flush thread - * /proc/kmsg ← future: userspace dmesg interface - * - * Reference: docs/specs/klog.md - */ - -#include - -/* ======================================================================== - * Log Levels (matches Linux kern_levels.h ordering) - * ======================================================================== */ - -enum KlogLevel : uint8 { - KLOG_EMERG = 0, /* System is unusable */ - KLOG_ALERT = 1, /* Action must be taken immediately */ - KLOG_CRIT = 2, /* Critical conditions */ - KLOG_ERR = 3, /* Error conditions */ - KLOG_WARN = 4, /* Warning conditions */ - KLOG_NOTICE = 5, /* Normal but significant condition */ - KLOG_INFO = 6, /* Informational */ - KLOG_DEBUG = 7, /* Debug-level messages */ -}; - -/* Log subsystems (bitmask-friendly) */ -enum KlogSubsys : uint8 { - KLOG_SUBSYS_GENERIC = 0, - KLOG_SUBSYS_SCHED = 1, - KLOG_SUBSYS_TRAP = 2, - KLOG_SUBSYS_IRQ = 3, - KLOG_SUBSYS_TIMER = 4, - KLOG_SUBSYS_VMM = 5, - KLOG_SUBSYS_PMM = 6, - KLOG_SUBSYS_SLAB = 7, - KLOG_SUBSYS_FS = 8, - KLOG_SUBSYS_DRIVER = 9, - KLOG_SUBSYS_TEST = 10, - KLOG_SUBSYS_SYSCALL = 11, /* per-syscall entry trace */ - KLOG_SUBSYS_EXEC = 12, /* ELF load / exec internals */ - KLOG_SUBSYS_SIGNAL = 13, /* signal delivery trace */ - KLOG_SUBSYS_TTY = 14, /* tty / job-control trace */ - KLOG_SUBSYS_MAX = 15, -}; - -/* Default: show everything up to INFO. DEBUG is compile-gated. */ -#ifndef KLOG_DEFAULT_LEVEL -#define KLOG_DEFAULT_LEVEL KLOG_INFO -#endif - -/* Ring buffer size: 2^KLOG_BUF_SHIFT bytes (default 64KB) */ -#ifndef KLOG_BUF_SHIFT -#define KLOG_BUF_SHIFT 16 -#endif - -#define KLOG_BUF_SIZE (1U << KLOG_BUF_SHIFT) - -/* Maximum length of a single log message (stack-allocated) */ -#define KLOG_LINE_MAX 256 - -struct KlogStats { - uint32 head; - uint32 tail; - uint32 console_tail; - uint32 dropped; - uint32 seq; -}; - -struct KlogRateLimit { - uint64 last_ts; - uint32 interval; - uint32 burst; - uint32 printed; - uint32 suppressed; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -/* ======================================================================== - * Initialization - * ======================================================================== */ - -/* Initialize the ring buffer and console backend. Call once from BSP. */ -void klog_init(void); - -/* ======================================================================== - * Core API - * ======================================================================== */ - -/* Write a leveled log message. Formats into ring buffer, then - * synchronously flushes to console if level <= current threshold. */ -__attribute__((format(printf, 2, 3))) -void klog(KlogLevel level, const char* fmt, ...); - -__attribute__((format(printf, 3, 4))) -void klog_ex(KlogLevel level, KlogSubsys subsys, const char* fmt, ...); - -/* Linux-style printk interface */ -__attribute__((format(printf, 1, 2))) -int printk(const char* fmt, ...); -int vprintk(const char* fmt, __builtin_va_list va); - -/* Set runtime log level filter. Messages above this level are - * still stored in the ring buffer but not printed to console. */ -void klog_set_level(KlogLevel level); - -void klog_set_subsys_mask(uint64 mask); -void klog_enable_subsys(KlogSubsys subsys); -void klog_disable_subsys(KlogSubsys subsys); - -/* ======================================================================== - * Ring Buffer Read (for future dmesg / /proc/kmsg) - * ======================================================================== */ - -/* Read up to 'size' bytes from the ring buffer into 'buf'. - * Returns number of bytes read. Non-destructive peek. */ -int klog_read(char* buf, int size); - -/* Read and consume entries (advances tail). */ -int klog_read_consume(char* buf, int size); - -/* Flush pending entries to console (advances console tail). */ -void klog_flush(void); - -bool klog_ratelimit(KlogRateLimit* rl, uint64 now); - -void klog_stats(KlogStats* out); - -/* ======================================================================== - * Convenience Macros - * ======================================================================== */ - -#define pr_emerg(fmt, ...) klog_ex(KLOG_EMERG, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) -#define pr_alert(fmt, ...) klog_ex(KLOG_ALERT, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) -#define pr_crit(fmt, ...) klog_ex(KLOG_CRIT, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) -#define pr_err(fmt, ...) klog_ex(KLOG_ERR, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) -#define pr_warn(fmt, ...) klog_ex(KLOG_WARN, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) -#define pr_notice(fmt, ...) klog_ex(KLOG_NOTICE, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) -#define pr_info(fmt, ...) klog_ex(KLOG_INFO, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) - -#define pr_emerg_s(subsys, fmt, ...) klog_ex(KLOG_EMERG, subsys, fmt, ##__VA_ARGS__) -#define pr_alert_s(subsys, fmt, ...) klog_ex(KLOG_ALERT, subsys, fmt, ##__VA_ARGS__) -#define pr_crit_s(subsys, fmt, ...) klog_ex(KLOG_CRIT, subsys, fmt, ##__VA_ARGS__) -#define pr_err_s(subsys, fmt, ...) klog_ex(KLOG_ERR, subsys, fmt, ##__VA_ARGS__) -#define pr_warn_s(subsys, fmt, ...) klog_ex(KLOG_WARN, subsys, fmt, ##__VA_ARGS__) -#define pr_notice_s(subsys, fmt, ...) klog_ex(KLOG_NOTICE, subsys, fmt, ##__VA_ARGS__) -#define pr_info_s(subsys, fmt, ...) klog_ex(KLOG_INFO, subsys, fmt, ##__VA_ARGS__) - -#ifdef KLOG_ENABLE_DEBUG -#define pr_debug(fmt, ...) klog_ex(KLOG_DEBUG, KLOG_SUBSYS_GENERIC, fmt, ##__VA_ARGS__) -#else -#define pr_debug(fmt, ...) do {} while (0) -#endif - -/* pr_debug_s: subsystem-tagged debug. Always compiled in (subsys is the gate); - * level KLOG_DEBUG ensures messages stay in the ring buffer but are filtered - * out of the console by default (console_level = KLOG_INFO). Toggle a subsys - * with klog_enable_subsys()/klog_disable_subsys() at runtime — or, to make - * the messages also reach the console for debugging, raise console_level - * via klog_set_level(KLOG_DEBUG). */ -#define pr_debug_s(subsys, fmt, ...) \ - klog_ex(KLOG_DEBUG, subsys, fmt, ##__VA_ARGS__) - -/* Linux kernel loglevel prefixes */ -#define KERN_SOH "\001" -#define KERN_EMERG KERN_SOH "0" -#define KERN_ALERT KERN_SOH "1" -#define KERN_CRIT KERN_SOH "2" -#define KERN_ERR KERN_SOH "3" -#define KERN_WARNING KERN_SOH "4" -#define KERN_NOTICE KERN_SOH "5" -#define KERN_INFO KERN_SOH "6" -#define KERN_DEBUG KERN_SOH "7" - -/* Boot stage log (thin wrapper over printk) */ -#define BOOT_STAGE(n, desc) \ - printk(KERN_INFO "STAGE%u %s\n", (unsigned)(n), (desc)) - -extern "C" [[noreturn]] void kernel_panic(const char* msg, const char* detail = nullptr); - -#ifdef __cplusplus -} -#endif diff --git a/include/lume/kobject.h b/include/lume/kobject.h deleted file mode 100644 index 8581d6e..0000000 --- a/include/lume/kobject.h +++ /dev/null @@ -1,57 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * kobject — generic refcounted object with parent/child relationship. - * - * Mirrors Linux include/linux/kobject.h. Embedded into device, gendisk, - * request_queue, block_device, etc. Each kobject has a kobj_type that - * provides the release callback called when the last reference drops. - * - * sysfs integration is not yet implemented — the sd/sysfs_ops fields are - * reserved for future use. - * - * Reference: docs/specs/storage_stack.md §4.2 - */ - -#include -#include -#include -#include - -struct kobj_type; - -struct kobject { - const char* name; - kobject* parent; - kref refcount; - const kobj_type* ktype; - list_node entry; // node in parent->children - list_node children; // head of children list - Spinlock lock; - bool state_in_sysfs; // reserved, always false for now -}; - -struct kobj_type { - void (*release)(kobject*); - /* sysfs_ops + default_attrs: reserved for future sysfs implementation. */ -}; - -/* Initialize a kobject in place; refcount starts at 1. - * Caller must provide a non-null ktype with a valid release(). */ -void kobject_init(kobject* k, const kobj_type* type); - -/* Link `k` under `parent` (which may be null for a detached root). - * Caller passes a stable `name` pointer (e.g. a static string or an - * already-strdup'd buffer); kobject does not own the name string. */ -int kobject_add(kobject* k, kobject* parent, const char* name); - -/* Unlink from parent. Does NOT drop the final ref — caller decides - * when to kobject_put(). */ -void kobject_del(kobject* k); - -/* Bump / drop reference. */ -void kobject_get(kobject* k); -void kobject_put(kobject* k); diff --git a/include/lume/kprintf.h b/include/lume/kprintf.h deleted file mode 100644 index b158602..0000000 --- a/include/lume/kprintf.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Kernel Formatted Output — kprintf - * - * Provides printf-style formatted output for the kernel. - * Built on top of stb_sprintf for full format string support - * without any libc dependency. - * - * Output is synchronous and directed to the console (UART). - * Safe to call from any context (interrupt or process). - * - * Usage: - * kprintf("Hello %s, addr=0x%lx\n", name, addr); - */ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Formatted print to console (like printf). */ -__attribute__((format(printf, 1, 2))) -int kprintf(const char* fmt, ...); - -/* Formatted print with va_list. */ -int kvprintf(const char* fmt, va_list va); - -/* Formatted snprintf into buffer. */ -__attribute__((format(printf, 3, 4))) -int ksnprintf(char* buf, int count, const char* fmt, ...); - -#ifdef __cplusplus -} -#endif diff --git a/include/lume/kref.h b/include/lume/kref.h deleted file mode 100644 index 13d53f3..0000000 --- a/include/lume/kref.h +++ /dev/null @@ -1,46 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * kref — atomic reference counting. - * - * Mirrors Linux include/linux/kref.h. Use kref_init() to set count=1, - * kref_get() / kref_put() to add/drop refs. kref_put() invokes the - * release callback when the final ref is dropped and returns 1 in that - * case. - * - * Reference: docs/specs/storage_stack.md §4.1 - */ - -#include -#include - -struct kref { - lume::atomic refcount; -}; - -inline void kref_init(kref* k) -{ - k->refcount.store(1, __ATOMIC_RELEASE); -} - -inline void kref_get(kref* k) -{ - k->refcount.fetch_add(1, __ATOMIC_RELAXED); -} - -inline int kref_put(kref* k, void (*release)(kref*)) -{ - if (k->refcount.fetch_sub(1, __ATOMIC_ACQ_REL) == 1) { - release(k); - return 1; - } - return 0; -} - -inline int32 kref_read(const kref* k) -{ - return k->refcount.load(__ATOMIC_RELAXED); -} diff --git a/include/lume/libfdt.h b/include/lume/libfdt.h deleted file mode 100644 index e3496e9..0000000 --- a/include/lume/libfdt.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _INCLUDE_LIBFDT_H_ -#define _INCLUDE_LIBFDT_H_ - -#include -#include "../../scripts/dtc/libfdt/libfdt.h" - -#endif /* _INCLUDE_LIBFDT_H_ */ diff --git a/include/lume/libfdt_env.h b/include/lume/libfdt_env.h deleted file mode 100644 index a95fb1d..0000000 --- a/include/lume/libfdt_env.h +++ /dev/null @@ -1,78 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef LIBFDT_ENV_H -#define LIBFDT_ENV_H - -/* - * Kernel-side adapter for the standalone libfdt sources in - * scripts/dtc/libfdt/. libfdt's *.c files start with - * #include "libfdt_env.h" - * and expect this header to provide: - * - byte-swap helpers (cpu_to_fdt16/32/64, fdt16/32/64_to_cpu) - * - fdt16/32/64_t typedefs (just plain uint types — endianness is - * handled in the helpers above) - * - string / mem helpers (memcpy, memmove, memcmp, strlen, strcmp, - * strchr, strnlen, ...) - * - INT_MAX, UINT32_MAX (libfdt bounds-checks props with these) - * - size_t / uintptr_t (everywhere) - * - * LumeOS-native: no Linux includes. Provides the surface - * libfdt needs and nothing else. - */ - -#include /* uint16_t / uint32_t / uint64_t / size_t */ -#include /* INT_MAX */ -#include /* libc-shim memcpy / memcmp / strlen ... */ - -/* libfdt uses these names; both come from . */ -#define INT32_MAX 2147483647 -#define UINT32_MAX 4294967295U - -/* libfdt's "FDT word" types — opaque big-endian-stored u16/u32/u64. - * The byte-swap helpers below are the only access path. */ -typedef uint16_t fdt16_t; -typedef uint32_t fdt32_t; -typedef uint64_t fdt64_t; - -/* - * Endianness helpers. FDT (Device Tree Blob) is big-endian by spec. - * LumeOS runs on RISC-V (little-endian) and x86 (little-endian); we - * unconditionally byte-swap. - * - * Open-coded shifts rather than __builtin_bswapN — on RISC-V without - * the Zbb extension, gcc lowers __builtin_bswap32 to a libgcc call - * (__bswapsi2 / __bswapdi2) which isn't present in a freestanding - * kernel link. Mirrors Linux's scripts/dtc/libfdt/libfdt_env.h - * which uses ___constant_swab32-style explicit shifts. */ -static inline uint16_t __lumefdt_bswap16(uint16_t x) -{ - return (uint16_t)((x << 8) | (x >> 8)); -} -static inline uint32_t __lumefdt_bswap32(uint32_t x) -{ - return ((x & 0x000000FFu) << 24) | - ((x & 0x0000FF00u) << 8) | - ((x & 0x00FF0000u) >> 8) | - ((x & 0xFF000000u) >> 24); -} -static inline uint64_t __lumefdt_bswap64(uint64_t x) -{ - return ((x & 0x00000000000000FFull) << 56) | - ((x & 0x000000000000FF00ull) << 40) | - ((x & 0x0000000000FF0000ull) << 24) | - ((x & 0x00000000FF000000ull) << 8) | - ((x & 0x000000FF00000000ull) >> 8) | - ((x & 0x0000FF0000000000ull) >> 24) | - ((x & 0x00FF000000000000ull) >> 40) | - ((x & 0xFF00000000000000ull) >> 56); -} - -#define fdt16_to_cpu(x) __lumefdt_bswap16((uint16_t)(x)) -#define cpu_to_fdt16(x) ((fdt16_t)__lumefdt_bswap16((uint16_t)(x))) -#define fdt32_to_cpu(x) __lumefdt_bswap32((uint32_t)(x)) -#define cpu_to_fdt32(x) ((fdt32_t)__lumefdt_bswap32((uint32_t)(x))) -#define fdt64_to_cpu(x) __lumefdt_bswap64((uint64_t)(x)) -#define cpu_to_fdt64(x) ((fdt64_t)__lumefdt_bswap64((uint64_t)(x))) - -#endif /* LIBFDT_ENV_H */ diff --git a/include/lume/limits.h b/include/lume/limits.h deleted file mode 100644 index a275a71..0000000 --- a/include/lume/limits.h +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_LIMITS_H -#define _LUME_LIMITS_H - -/* - * Numeric limit constants — minimal subset needed by LumeOS kernel code. - * - * Values match the standard on all 64-bit LP64 targets, which - * is the only ABI LumeOS supports. Defined as plain integer literals so - * this header is usable from C, C++, and assembly without dragging in - * the toolchain's (which on hosted builds references libc - * internals we don't link against). - */ - -/* Signed/unsigned char */ -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 -#define UCHAR_MAX 255 -#define CHAR_MIN SCHAR_MIN -#define CHAR_MAX SCHAR_MAX - -/* Short */ -#define SHRT_MIN (-32768) -#define SHRT_MAX 32767 -#define USHRT_MAX 65535 - -/* Int */ -#define INT_MIN (-INT_MAX - 1) -#define INT_MAX 2147483647 -#define UINT_MAX 4294967295U - -/* Long (LP64: 64-bit) */ -#define LONG_MIN (-LONG_MAX - 1L) -#define LONG_MAX 9223372036854775807L -#define ULONG_MAX 18446744073709551615UL - -/* Long long */ -#define LLONG_MIN (-LLONG_MAX - 1LL) -#define LLONG_MAX 9223372036854775807LL -#define ULLONG_MAX 18446744073709551615ULL - -/* size_t (LP64) */ -#define SIZE_MAX ULONG_MAX -#define SSIZE_MAX LONG_MAX - -#endif /* _LUME_LIMITS_H */ diff --git a/include/lume/list.h b/include/lume/list.h deleted file mode 100644 index ed1202a..0000000 --- a/include/lume/list.h +++ /dev/null @@ -1,346 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#include -#include - -/** - * @brief The node to be embedded in a struct to make it linkable. - * - * An object can be on multiple lists simultaneously by embedding multiple - * list_node members with different names. - */ -struct list_node { - list_node* prev; - list_node* next; - - /** - * @brief Initializes the node to point to itself, forming an empty list head. - */ - void init() { - prev = this; - next = this; - } - - /** - * @brief Checks if the list this node is the head of is empty. - * @return True if the list is empty, false otherwise. - */ - bool is_empty() const { - return next == this; - } -}; - -/* - * Type-safe container_of: given a pointer to a list_node member, - * recover a pointer to the enclosing object. - * Uses pointer-to-member arithmetic — no __builtin_offsetof needed. - */ -template -static inline T *list_entry(list_node *node) -{ - const size_t off = (size_t)(uintptr) & (((T *)nullptr)->*Member); - return reinterpret_cast(reinterpret_cast(node) - off); -} - -/** - * @brief A type-safe, intrusive, doubly-linked list. - * - * This class manages objects of type T that have a `list_node` member. - * It has zero runtime overhead compared to a manual C implementation and - * provides compile-time type safety. - * - * @tparam T The type of the object in the list. - * @tparam NodeMember A pointer-to-member specifying which `list_node` in T to use. - */ -template -class List { -private: - static list_node* get_node(T* obj) { - return &(obj->*NodeMember); - } - - // NOTE: `((T*)nullptr)->*NodeMember` is technically undefined behavior in - // standard C++. However, it's a common idiom in low-level programming - // (similar to `offsetof`) that compilers typically handle correctly, - // especially with flags like `-fno-delete-null-pointer-checks`. - // The alternative (using `offsetof`) would sacrifice the compile-time - // type safety of the pointer-to-member template parameter. - static T* get_obj(list_node* node) { - constexpr size_t offset = (size_t)(uintptr) & (((T*)nullptr)->*NodeMember); - return reinterpret_cast(reinterpret_cast(node) - offset); - } - - static const T* get_obj(const list_node* node) { - constexpr size_t offset = (size_t)(uintptr) & (((T*)nullptr)->*NodeMember); - return reinterpret_cast(reinterpret_cast(node) - offset); - } - -public: - class iterator; - class const_iterator; - - class iterator { - friend class List; - friend class const_iterator; - - public: - iterator(list_node* node) : node_(node) {} - - T& operator*() const { return *get_obj(node_); } - T* operator->() const { return get_obj(node_); } - - iterator& operator++() { - node_ = node_->next; - return *this; - } - iterator operator++(int) { - iterator tmp = *this; - ++(*this); - return tmp; - } - - iterator& operator--() { - node_ = node_->prev; - return *this; - } - iterator operator--(int) { - iterator tmp = *this; - --(*this); - return tmp; - } - - bool operator==(const iterator& other) const { return node_ == other.node_; } - bool operator!=(const iterator& other) const { return !(*this == other); } - - private: - list_node* node_; - }; - - class const_iterator { - public: - const_iterator(const list_node* node) : node_(node) {} - const_iterator(const iterator& other) : node_(other.node_) {} - - const T& operator*() const { return *get_obj(node_); } - const T* operator->() const { return get_obj(node_); } - - const_iterator& operator++() { - node_ = node_->next; - return *this; - } - const_iterator operator++(int) { - const_iterator tmp = *this; - ++(*this); - return tmp; - } - - const_iterator& operator--() { - node_ = node_->prev; - return *this; - } - const_iterator operator--(int) { - const_iterator tmp = *this; - --(*this); - return tmp; - } - - bool operator==(const const_iterator& other) const { return node_ == other.node_; } - bool operator!=(const const_iterator& other) const { return !(*this == other); } - - private: - const list_node* node_; - }; - - List() { head_.init(); } - ~List() = default; - - // This container is intrusive and does not own the objects. - // Copying or moving it is a logical error. - List(const List&) = delete; - List& operator=(const List&) = delete; - - bool empty() const { return head_.is_empty(); } - - void push_front(T* obj) { - list_node* node = get_node(obj); - node->next = head_.next; - node->prev = &head_; - head_.next->prev = node; - head_.next = node; - } - - void push_back(T* obj) { - list_node* node = get_node(obj); - node->prev = head_.prev; - node->next = &head_; - head_.prev->next = node; - head_.prev = node; - } - - /** - * @brief Splices all elements from another list to the front of this list. - * - * Moves all elements from `other` to the beginning of `this` list in O(1) - * time. The `other` list becomes empty after the operation. - * - * @param other The list to splice from. - */ - void splice_front(List& other) { - if (other.empty()) { - return; - } - list_node* this_first = head_.next; - list_node* other_first = other.head_.next; - list_node* other_last = other.head_.prev; - - // Link other's last to this's original first - other_last->next = this_first; - this_first->prev = other_last; - - // Link this's head to other's first - head_.next = other_first; - other_first->prev = &head_; - - // Reset the other list - other.head_.init(); - } - - /** - * @brief Splices all elements from another list to the back of this list. - * - * Moves all elements from `other` to the end of `this` list in O(1) - * time. The `other` list becomes empty after the operation. - * - * @param other The list to splice from. - */ - void splice_tail(List& other) { - if (other.empty()) { - return; - } - list_node* this_last = head_.prev; - list_node* other_first = other.head_.next; - list_node* other_last = other.head_.prev; - - // Link this's last to other's first - this_last->next = other_first; - other_first->prev = this_last; - - // Link other's last to this's head - other_last->next = &head_; - head_.prev = other_last; - - // Reset the other list - other.head_.init(); - } - - T* pop_front() { - if (empty()) { - return nullptr; - } - list_node* node = head_.next; - node->prev->next = node->next; - node->next->prev = node->prev; - node->init(); - return get_obj(node); - } - - T* pop_back() { - if (empty()) { - return nullptr; - } - list_node* node = head_.prev; - node->prev->next = node->next; - node->next->prev = node->prev; - node->init(); - return get_obj(node); - } - - void remove(T* obj) { - list_node* node = get_node(obj); - node->prev->next = node->next; - node->next->prev = node->prev; - node->init(); - } - - T* front() { - return empty() ? nullptr : get_obj(head_.next); - } - - const T* front() const { - return empty() ? nullptr : get_obj(head_.next); - } - - T* back() { - return empty() ? nullptr : get_obj(head_.prev); - } - - const T* back() const { - return empty() ? nullptr : get_obj(head_.prev); - } - - iterator begin() { return iterator(head_.next); } - iterator end() { return iterator(&head_); } - const_iterator begin() const { return const_iterator(head_.next); } - const_iterator end() const { return const_iterator(&head_); } - const_iterator cbegin() const { return const_iterator(head_.next); } - const_iterator cend() const { return const_iterator(&head_); } - -private: - list_node head_; -}; - -/* ======================================================================== - * Linux-compatible C-style list macros (for VFS subsystem) - * ======================================================================== */ - -using list_head = list_node; - -inline void list_init(list_node* head) { - head->prev = head; - head->next = head; -} - -inline bool list_empty(const list_node* head) { - return head->next == head; -} - -inline void __list_add(list_node* node, list_node* p, list_node* n) { - n->prev = node; - node->next = n; - node->prev = p; - p->next = node; -} - -inline void list_add(list_node* node, list_node* head) { - __list_add(node, head, head->next); -} - -inline void list_add_tail(list_node* node, list_node* head) { - __list_add(node, head->prev, head); -} - -inline void list_del(list_node* node) { - node->prev->next = node->next; - node->next->prev = node->prev; - node->next = nullptr; - node->prev = nullptr; -} - -inline void list_del_init(list_node* node) { - node->prev->next = node->next; - node->next->prev = node->prev; - list_init(node); -} - -#define list_entry(ptr, type, member) container_of(ptr, type, member) - -#define list_for_each(pos, head) \ - for ((pos) = (head)->next; (pos) != (head); (pos) = (pos)->next) - -#define list_for_each_safe(pos, tmp, head) \ - for ((pos) = (head)->next, (tmp) = (pos)->next; \ - (pos) != (head); \ - (pos) = (tmp), (tmp) = (pos)->next) diff --git a/include/lume/lumeos.lds.h b/include/lume/lumeos.lds.h deleted file mode 100644 index 58d2f72..0000000 --- a/include/lume/lumeos.lds.h +++ /dev/null @@ -1,193 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Common Linker Script Macros (Machine-Independent) - * - * Shared section definitions that every architecture must emit. - * Architecture-specific lumeos.lds.S files #include this header - * and use these macros to avoid duplicating common boilerplate. - * - * Modeled after Linux include/asm-generic/vmlinux.lds.h - * Reference: docs/specs/linker_and_entry.md - */ - -#ifndef _LUME_LUMEOS_LDS_H -#define _LUME_LUMEOS_LDS_H - -/* ===== Text Section: executable code ===== - * - * .init.text is merged into the main .text segment so PC-relative `la` - * from regular code can call __init helpers without a thunk. Linux - * keeps a separate .init.text only to reclaim the pages after boot — - * LumeOS doesn't yet reclaim, so the merge is harmless and avoids an - * extra PT_LOAD entry. */ -#define TEXT_SECTION \ - .text : AT(ADDR(.text) - PAGE_OFFSET) { \ - _stext = .; \ - *(.text .text.*) \ - *(.init.text .init.text.*) \ - *(.fixup) \ - _etext = .; \ - } = 0 - -/* ===== Read-Only Data + C++ init_array + initramfs ===== - * - * Layout invariants: - * - extable / init_array / driver_array / initramfs all live INSIDE - * .rodata between _srodata and _erodata so the VMM has one R-only - * mapping to manage. - * - The relocation table (.lume.reloc) is NOT in here — it lives in - * its own padded output section (see RELOC_SECTION) so that its - * two-pass-build size variance can't shift downstream offsets. - * (Putting it in .rodata caused a heisenbug where pre-link offsets - * used by gen_reloc.py didn't match post-link offsets after the - * reloc.o blob was inserted.) - */ -#define RODATA_SECTION \ - .rodata : AT(ADDR(.rodata) - PAGE_OFFSET) { \ - _srodata = .; \ - *(.rodata .rodata.*) \ - *(.srodata .srodata.* .srodata.cst*) \ - . = ALIGN(8); \ - __extable_start = .; \ - KEEP(*(.extable)) \ - __extable_end = .; \ - INIT_ARRAY \ - DRIVER_ARRAY \ - /* Embedded initramfs CPIO archive */ \ - . = ALIGN(8); \ - __initramfs_start = .; \ - KEEP(*(.init.ramfs)) \ - __initramfs_end = .; \ - . = ALIGN(4096); \ - _erodata = .; \ - } - -/* ===== .rel.dyn / .rela.dyn — Linker-emitted RELA relocations ===== - * - * Mirrors arch/riscv/kernel/vmlinux.lds.S §101-109: the .rela.dyn - * section sits BETWEEN init data and .rodata so it lands in a - * read-only PT_LOAD segment alongside .text/.rodata. The companion - * dynamic-linker bookkeeping (.dynamic, .dynsym, .dynstr, .hash, - * .gnu.hash) lives in the RW segment AFTER .data — Linux does the - * same under #ifdef CONFIG_RELOCATABLE (§139-147). */ -#define RELA_DYN_SECTION \ - .rel.dyn : AT(ADDR(.rel.dyn) - PAGE_OFFSET) { \ - *(.rel.dyn*) \ - } \ - .rela.dyn : AT(ADDR(.rela.dyn) - PAGE_OFFSET) ALIGN(8) {\ - __rela_dyn_start = .; \ - *(.rela .rela*) \ - __rela_dyn_end = .; \ - } - -/* ===== GOT — kept; everything else dynamic-linker is discarded ===== - * - * Strict mirror of arch/riscv/kernel/vmlinux.lds.S in Linux: the only - * dynamic-linker artefact the kernel keeps is `.got` (it's referenced - * by every -fPIE compiled global access). `.plt .dynamic .dynsym - * .dynstr .hash .gnu.hash .interp .dynbss` are all sent to /DISCARD/ - * via the DISCARDS macro below — the kernel never invokes a dynamic - * linker (head.S walks .rela.dyn directly). - * - * Keeping .plt was the cause of two distinct bugs: - * 1. PLT trampoline target for an undefined symbol (selftest_reloc - * after we removed test_reloc.cc) was unresolved → jumps to a - * slot that re-jumps to itself → instruction page fault. - * 2. .plt carries X permission; living in the same PT_LOAD as .data - * forces the load segment to RWX, which `ld` warns about. - * - * Sit in the same PT_LOAD as .data because .got is RW. */ -#define GOT_SECTION \ - .got : AT(ADDR(.got) - PAGE_OFFSET) { *(.got*) } - -/* ===== Embedded initramfs (CPIO archive) ===== */ -#define INITRAMFS_SECTION \ - .init.ramfs : AT(ADDR(.init.ramfs) - PAGE_OFFSET) { \ - . = ALIGN(8); \ - __initramfs_start = .; \ - KEEP(*(.init.ramfs)) \ - __initramfs_end = .; \ - } - -/* ===== C++ Global Constructor Table ===== */ -#define INIT_ARRAY \ - . = ALIGN(8); \ - __init_array_start = .; \ - KEEP(*(.init_array .init_array.*)) \ - __init_array_end = .; - -/* ===== Driver Registration Table ===== */ -#define DRIVER_ARRAY \ - . = ALIGN(8); \ - PROVIDE(__drivers_start = .); \ - KEEP(*(.drivers)) \ - PROVIDE(__drivers_end = .); - -/* ===== Initialized Read-Write Data ===== - * - * .init.data is merged into .data for the same reason TEXT_SECTION - * absorbs .init.text — LumeOS doesn't yet reclaim __init pages, so - * splitting them gains nothing while costing a PT_LOAD entry. */ -#define DATA_SECTION \ - .data : AT(ADDR(.data) - PAGE_OFFSET) { \ - _sdata = .; \ - *(.data .data.*) \ - *(.init.data .init.data.*) \ - ARCH_DATA_EXTRA \ - _edata = .; \ - } - -/* ===== BSS: Uninitialized Data ===== */ -#define BSS_SECTION \ - .bss : AT(ADDR(.bss) - PAGE_OFFSET) { \ - _sbss = .; \ - *(.bss .bss.*) \ - *(.sbss .sbss.*) \ - ARCH_BSS_EXTRA \ - _ebss = .; \ - } - -/* ===== Discard Unwanted Sections ===== - * - * Mirrors arch/riscv/kernel/vmlinux.lds.S in Linux: - * /DISCARD/ : { - * *(.dynbss) - * *(.dynstr*) - * *(.dynamic*) - * *(.plt*) - * *(.interp*) - * *(.eh_frame) - * *(.note.GNU-stack) - * } - * - * Why each is safe to discard: - * .plt — -Bsymbolic resolves all internal refs at link time; - * any remaining PLT entry is an undefined symbol that - * the kernel would have crashed on anyway. - * .dynamic etc. — kernel doesn't invoke a dynamic linker; head.S - * walks __rela_dyn_start..__rela_dyn_end manually. - * .interp — no PT_INTERP at runtime. - * .eh_frame* — no C++ exceptions in kernel (-fno-exceptions). - * .note.* — boot-time identification metadata, unused. */ -#define DISCARDS \ - /DISCARD/ : { \ - *(.dynbss) \ - *(.dynstr*) \ - *(.dynamic*) \ - *(.dynsym*) \ - *(.hash*) *(.gnu.hash*) \ - *(.plt*) \ - *(.interp*) \ - *(.eh_frame .eh_frame_hdr) \ - *(.note .note.*) \ - *(.comment) \ - } - -/* ===== Kernel Image Boundary ===== */ -#define KERNEL_END \ - . = ALIGN(4096); \ - _kernel_end = .; - -#endif /* _LUME_LUMEOS_LDS_H */ diff --git a/include/lume/memblock.h b/include/lume/memblock.h deleted file mode 100644 index cb9a76b..0000000 --- a/include/lume/memblock.h +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * memblock — Boot-time physical memory allocator - * - * A simple region-based allocator active from early boot until - * the buddy system (PMM) takes over. Inspired by Linux's memblock. - * - * Lifetime: - * 1. memblock_init() — discovers RAM via FDT, reserves kernel image - * 2. vmm_init() — uses memblock_alloc for page table pages & page_map - * 3. pmm_init() — absorbs remaining free regions into buddy - * 4. memblock_retire() — marks memblock inactive; all alloc via PMM - * - * This eliminates the need for post-init pointer relocation when - * rebinding page_map to a VMEMMAP virtual address. - */ - -#include - -inline constexpr int kMemblockMaxRegions = 128; - -/* Initialize memblock: scan FDT for RAM, reserve kernel image + firmware. */ -void memblock_init(uint64 fdt_paddr); - -/* Mark a physical range as reserved (will not be handed to buddy). */ -void memblock_reserve(uint64 base, uint64 size); - -/* Allocate `size` bytes aligned to `align` from top of free memory. - * Returns PA, or 0 on failure. Used for page_map. */ -uint64 memblock_alloc_top(uint64 size, uint64 align); - -/* Allocate `size` bytes aligned to `align` from bottom of free memory. - * Returns PA, or 0 on failure. Used for page table pages. */ -uint64 memblock_alloc(uint64 size, uint64 align); - -/* Query memory layout (same info as FDT). */ -uint64 memblock_get_mem_base(); -uint64 memblock_get_mem_size(); - -/* Is memblock still the active allocator? */ -bool memblock_is_active(); - -/* Mark memblock as retired (PMM takes over). */ -void memblock_retire(); - -/* Iterate all free (unreserved) regions in ascending order. - * Used by pmm_init() to feed free pages into the buddy system. */ -void memblock_for_each_free(void (*cb)(uint64 base, uint64 size, void* ctx), - void* ctx); diff --git a/include/lume/mm_layout.h b/include/lume/mm_layout.h deleted file mode 100644 index 7744de0..0000000 --- a/include/lume/mm_layout.h +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * mm_layout.h — User/Kernel address space boundary definitions - * - * Single source of truth for the user/kernel VA split. - * All modules (VMM, uaccess, page fault, tests) MUST include this - * header instead of defining their own constants. - * - * Layout (SV39, RISC-V): - * [0x0000_0000_0000, kUserVaLimit) — User space - * [kUserVaLimit, 0xFFFF_FFFF_FFFF) — Kernel space (direct map, vmemmap, etc.) - * - * Reference: docs/specs/linux_abi_mm_plan.md §5 - */ - -#include -#include - -/* User VA range: [kUserVaBase, kUserVaLimit) - * kUserVaBase avoids mapping the null page (catch NULL derefs). - * - * SV39: user space is the lower half [0, 2^38). The upper half - * [0xFFFFFFC000000000, 0xFFFFFFFFFFFFFFFF] is kernel space. - * Addresses between 2^38 and 0xFFFFFFC000000000 are non-canonical - * and will always fault — they must never be used. - * - * This value MUST match the page table mode selected by the MD layer. - * If we ever support SV48/SV57, update this accordingly. */ -inline constexpr uint64 kUserVaBase = kPageSize; -inline constexpr uint64 kUserVaLimit = 0x4000000000ULL; /* 2^38 = 256 GB */ - -/* Kernel VA starts at the sign-extended upper half */ -inline constexpr uint64 kKernelVaBase = 0xFFFFFFC000000000ULL; - -/* User stack: sits at the top of the user VA range. - * Matches Linux STACK_TOP = TASK_SIZE = kUserVaLimit. - * One guard page below the top, 8 MB stack. */ -inline constexpr uint64 kUserStackSize = 8ULL * 1024 * 1024; -inline constexpr uint64 kUserStackTop = kUserVaLimit - kPageSize; /* guard page */ -inline constexpr uint64 kUserStackBase = kUserStackTop - kUserStackSize; - -/* - * Check whether an address range [addr, addr+len) is entirely - * within user space. Returns true if valid. - */ -inline bool is_user_range(uint64 addr, uint64 len) -{ - if (addr < kUserVaBase) { - return false; - } - if (addr >= kUserVaLimit) { - return false; - } - if (addr + len < addr) { - return false; // Overflow - } - if (addr + len > kUserVaLimit) { - return false; - } - return true; -} - -/* - * Check whether a single address is in user space. - */ -inline bool is_user_address(uint64 addr) -{ - return addr >= kUserVaBase && addr < kUserVaLimit; -} diff --git a/include/lume/mman.h b/include/lume/mman.h deleted file mode 100644 index d952419..0000000 --- a/include/lume/mman.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * POSIX Memory Management Constants - * Reference: docs/specs/syscall.md §9 - */ - -/* mmap / mprotect protection flags */ -inline constexpr int PROT_NONE = 0x0; -inline constexpr int PROT_READ = 0x1; -inline constexpr int PROT_WRITE = 0x2; -inline constexpr int PROT_EXEC = 0x4; - -/* mmap flags */ -inline constexpr int MAP_SHARED = 0x01; -inline constexpr int MAP_PRIVATE = 0x02; -inline constexpr int MAP_FIXED = 0x10; -inline constexpr int MAP_ANONYMOUS = 0x20; diff --git a/include/lume/mount.h b/include/lume/mount.h deleted file mode 100644 index 13f8e62..0000000 --- a/include/lume/mount.h +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * mount.h — Internal mount structure - */ - -#include -#include -#include -#include - -struct dentry; -struct super_block; -struct file_system_type; - -/* ================================================================== */ -/* mount (VFS-internal) */ -/* ================================================================== */ - -struct mount { - vfsmount mnt; - mount* mnt_parent; - dentry* mnt_mountpoint; - list_node mnt_child; - list_head mnt_mounts; - list_node mnt_list; - lume::atomic mnt_count; -}; - -inline mount* real_mount(vfsmount* m) { - return reinterpret_cast(m); -} - -/* ================================================================== */ -/* Mount API */ -/* ================================================================== */ - -int do_mount(const char* dev, const char* dir, - const char* fstype, uint64 flags, void* data); -int do_umount(vfsmount* mnt, int flags); - -vfsmount* vfs_kern_mount(file_system_type* type, int flags, - const char* name, void* data); - -/* Global root */ -extern vfsmount* g_root_mnt; -extern dentry* g_root_dentry; - -void mount_init(); diff --git a/include/lume/mutex.h b/include/lume/mutex.h deleted file mode 100644 index 9719aa6..0000000 --- a/include/lume/mutex.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Mutex — Linux-style sleeping mutex (no priority inheritance). - * - * Semantics mirror Linux kernel/locking/mutex.c: - * - Single owner (nullptr when free). - * - FIFO wait list — first waiter is the next owner. - * - Recursive acquire by the same task is FORBIDDEN (panic). - * - Owner MUST be the one to unlock. - * - lock() may sleep; MUST NOT be called from IRQ context, with - * preemption disabled, or while holding a spinlock. - * - try_lock() never sleeps; may be called from any context. - * - * Priority inheritance lives in a separate primitive (RtMutex, future) - * just like Linux splits struct mutex / struct rt_mutex. - * - * Reference: docs/specs/mutex.md - */ - -#include -#include -#include - -struct TaskControlBlock; - -class Mutex { -public: - void init(const char* name); - - /* Blocking acquire (uninterruptible). */ - void lock(); - - /* Non-blocking attempt. Returns true if acquired. */ - bool try_lock(); - - /* Release; only the owner may call (else panic). */ - void unlock(); - - bool is_locked() const { return owner_ != nullptr; } - bool is_owned_by_current() const; - TaskControlBlock* owner() const { return owner_; } - -private: - TaskControlBlock* owner_ = nullptr; - Spinlock wait_lock_; - list_node wait_list_{}; - const char* name_ = nullptr; -}; - -/* RAII guard. */ -class MutexGuard { -public: - explicit MutexGuard(Mutex& m) : m_(m) { m_.lock(); } - ~MutexGuard() { m_.unlock(); } - MutexGuard(const MutexGuard&) = delete; - MutexGuard& operator=(const MutexGuard&) = delete; -private: - Mutex& m_; -}; diff --git a/include/lume/namei.h b/include/lume/namei.h deleted file mode 100644 index 1764693..0000000 --- a/include/lume/namei.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * namei.h — Pathname lookup (path resolution) - */ - -#include -#include /* struct path */ -#include /* struct qstr */ - -/* ================================================================== */ -/* LOOKUP_* flags */ -/* ================================================================== */ - -inline constexpr uint32 LOOKUP_FOLLOW = 0x0001; -inline constexpr uint32 LOOKUP_DIRECTORY = 0x0002; -inline constexpr uint32 LOOKUP_CREATE = 0x0200; -inline constexpr uint32 LOOKUP_EXCL = 0x0400; -inline constexpr uint32 LOOKUP_PARENT = 0x0010; - -/* ================================================================== */ -/* Path lookup API */ -/* ================================================================== */ - -int kern_path(const char* name, unsigned int flags, path* result); -int filename_lookup(int dfd, const char* name, unsigned int flags, path* result); -dentry* lookup_one_len(const char* name, dentry* parent, int len); - -void namei_init(); diff --git a/include/lume/new.h b/include/lume/new.h deleted file mode 100644 index cdcacb8..0000000 --- a/include/lume/new.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Placement New for Freestanding Environments - * - * In -ffreestanding -nostdlib mode, may not be available. - * LumeOS provides its own placement new/delete operators. - * - * Usage: g_obj = new (g_obj_buf) MyClass(args...); - * - * Reference: docs/specs/global_init.md §3.1 - */ - -inline void* operator new(decltype(sizeof(0)), void* ptr) noexcept { return ptr; } -inline void operator delete(void*, void*) noexcept {} diff --git a/include/lume/page.h b/include/lume/page.h deleted file mode 100644 index 61bff95..0000000 --- a/include/lume/page.h +++ /dev/null @@ -1,151 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Page — Physical page descriptor - * - * Each Page describes one 4KB physical page. A flat array of Page - * structs (page_map) covers all physical memory discovered via FDT. - * - * Memory layout is compressed using a union: only one of free/slab - * metadata is valid at a time, determined by `type`. - * - * Fields: - * refcount — lifecycle reference count (atomic). Page cannot be - * freed while refcount > 0. - * mapcount — PTE mapping count (atomic). Number of page table - * entries pointing to this page. Used by COW and - * future reclaim. - * flags — page state bits (PG_*). Also serves as a bit-lock - * via PG_LOCKED for short critical sections. - * type — discriminant for the union (Free/Slab/Anon/File). - * mapping — pointer to reverse-mapping context. For anonymous - * pages, points to AnonVma (low bit set). For file - * pages, points to FileMapping (low bit clear). - * index — page offset within the mapping object. - * - * Reference: docs/specs/pmm.md §3.1 - */ - -#include -#include -#include - -/* Forward declarations */ -class KmemCache; - -/* ================================================================== */ -/* Page type discriminant */ -/* ================================================================== */ - -enum class PageType : uint8 { - Free, // In Buddy free list - PcpCached, // In Per-CPU cache (invisible to buddy coalescing) - Allocated, // Handed out but not yet typed (PMM default) - Slab, // Backing a Slab cache - Anon, // Anonymous user page - File, // File-backed page (page cache) -}; - -/* ================================================================== */ -/* Page flags (stored as atomic uint32) */ -/* ================================================================== */ - -inline constexpr uint32 kPgLocked = (1U << 0); // Bit-lock for short critical sections -inline constexpr uint32 kPgReferenced = (1U << 1); // Accessed since last check -inline constexpr uint32 kPgDirty = (1U << 2); // Modified, needs writeback -inline constexpr uint32 kPgWriteback = (1U << 3); // IO writeback in progress -inline constexpr uint32 kPgLru = (1U << 4); // On an LRU list -inline constexpr uint32 kPgMapped = (1U << 5); // Has at least one PTE mapping -inline constexpr uint32 kPgSwapcache = (1U << 6); // In swap cache (future) -inline constexpr uint32 kPgCow = (1U << 7); // Involved in COW sharing - -/* ================================================================== */ -/* Page descriptor */ -/* ================================================================== */ - -struct Page { - /* --- Counts (atomic, lock-free) --- */ - lume::atomic refcount; // Lifecycle ref: 0 = reclaimable - lume::atomic mapcount; // PTE mapping count: 0 = no user mapping - - /* --- State --- */ - lume::atomic flags; // PG_* bits (also serves as bit-lock) - PageType type; // Discriminant for union - uint8 order; // Buddy order (0–10, i.e. 4KB–4MB) - - /* --- Reverse mapping --- */ - void* mapping; // AnonVma* (low bit set) or FileMapping* - uint64 index; // Page offset within mapping object - - /* --- LRU (future) --- */ - list_node lru; // LRU list linkage (for reclaim) - - /* --- Subsystem-specific metadata --- */ - union { - /* Valid when type == Free */ - struct { - list_node free_link; // Link into Buddy or PCP free list - } free; - - /* Valid when type == Slab */ - struct { - KmemCache* cache; // Owning slab cache - uint32 obj_count; // Number of allocated objects on this page - void* freelist; // Head of in-page free object linked list - } slab; - - /* type == Anon / File: no extra union metadata (rmap via mapping) */ - }; -}; - -/* ================================================================== */ -/* Page bit-lock (lightweight, no sleep, used for rmap critical */ -/* sections and short metadata updates) */ -/* ================================================================== */ - -inline bool page_trylock(Page* page) -{ - uint32 old = page->flags.fetch_or(kPgLocked); - return (old & kPgLocked) == 0; -} - -inline void page_lock(Page* page) -{ - while (!page_trylock(page)) { - /* spin — acceptable for short critical sections only */ - } -} - -inline void page_unlock(Page* page) -{ - page->flags.fetch_and(~kPgLocked); -} - -/* ================================================================== */ -/* Mapping pointer helpers (Linux convention: low bit = anon) */ -/* ================================================================== */ - -inline bool page_is_anon(const Page* page) -{ - return (reinterpret_cast(page->mapping) & 1ULL) != 0; -} - -inline void* page_mapping_raw(const Page* page) -{ - return reinterpret_cast( - reinterpret_cast(page->mapping) & ~1ULL); -} - -inline void page_set_anon_mapping(Page* page, void* anon_vma) -{ - page->mapping = reinterpret_cast( - reinterpret_cast(anon_vma) | 1ULL); -} - -inline void page_set_file_mapping(Page* page, void* file_mapping) -{ - page->mapping = file_mapping; -} diff --git a/include/lume/page_cache.h b/include/lume/page_cache.h deleted file mode 100644 index abdc535..0000000 --- a/include/lume/page_cache.h +++ /dev/null @@ -1,82 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * page_cache.h — Page Cache interface - * - * Provides a stable abstraction for caching physical pages indexed by - * (mapping, index) pairs. All file-backed fault paths should go - * through this interface so that upgrading the backing implementation - * (e.g. LRU eviction, writeback, radix tree) does not require - * changing any caller. - * - * Current implementation: simple open-addressing hash table. - * Future: radix tree + LRU lists + writeback integration. - * - * Terminology: - * mapping — opaque pointer identifying the backing object - * (FileMapping*, or any future cache-able object). - * index — page-granularity offset within the mapping. - * - * Reference: docs/specs/linux_abi_mm_plan.md §2.9, §3 - */ - -#include - -struct Page; - -/* - * Look up a cached page by (mapping, index). - * Returns the Page* if found (with refcount incremented), or nullptr. - * Caller must call page_cache_put() when done. - */ -Page* page_cache_get(void* mapping, uint64 index); - -/* - * Insert a page into the cache, associated with (mapping, index). - * The page's refcount is incremented by the cache. - * If a page already exists at (mapping, index), returns -EEXIST. - * Returns 0 on success, negative errno on failure. - */ -int page_cache_insert(void* mapping, uint64 index, Page* page); - -/* - * Release a reference obtained via page_cache_get(). - * This decrements the page's refcount. If the page was removed - * from the cache and refcount drops to 0, the page is freed. - */ -void page_cache_put(Page* page); - -/* - * Remove a page from the cache by (mapping, index). - * Decrements the cache's reference on the page. - * Returns the removed Page* (caller does NOT own a new ref), - * or nullptr if not found. - */ -Page* page_cache_remove(void* mapping, uint64 index); - -/* - * Remove all pages associated with a given mapping. - * Used during file close / inode eviction / truncate. - * Each removed page has its cache reference decremented. - */ -void page_cache_invalidate(void* mapping); - -/* - * Look up a page; if not found, allocate one, insert it, and return it. - * The returned page has its refcount incremented (caller must put). - * Returns nullptr on OOM. - * - * This is the primary interface for file-backed fault paths: - * the caller gets a page and then fills it with file data if kPgUptodate - * is not set. - */ -Page* page_cache_get_or_alloc(void* mapping, uint64 index); - -/* - * Initialize the page cache subsystem. - * Called once during boot after slab_init(). - */ -void page_cache_init(); diff --git a/include/lume/pgrp.h b/include/lume/pgrp.h deleted file mode 100644 index 127f3f8..0000000 --- a/include/lume/pgrp.h +++ /dev/null @@ -1,125 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Process Group / Session infrastructure. - * - * Linux models pgrp/session via struct pid + PIDTYPE_PGID/PIDTYPE_SID hlists. - * We use a simpler design that supports the same operations cheaply: - * - * - Each thread group owns one signal_struct (refcount-shared with - * CLONE_THREAD siblings). - * - signal_struct carries pgid/sid and is the linked-list node on a - * fixed-size pgrp hash table. - * - kill(pid<=0), tty_signal_pgrp, orphan checks all walk one bucket. - * - * Concurrency: g_pgrp_lock protects every bucket and the pgrp_link of - * every signal_struct on a bucket. signal_struct::lock is a finer-grain - * lock for fields that change without re-hashing (e.g. tty pointer). - * - * Reference: Linux include/linux/pid.h, kernel/pid.c - */ - -#include -#include -#include - -struct signal_struct; -struct TaskControlBlock; - -/* ================================================================== */ -/* Subsystem init */ -/* ================================================================== */ - -void pgrp_init(); - -/* ================================================================== */ -/* signal_struct lifecycle */ -/* ================================================================== */ - -/* - * Allocate a new signal_struct for `leader`, with sid=pgid=leader_pid, - * refcount=1, attached to pgrp `leader_pid`. Returns nullptr on OOM. - */ -signal_struct* alloc_signal_struct(int32 leader_pid, - TaskControlBlock* leader); - -/* - * Allocate a child signal_struct inheriting pgid/sid/tty from `parent`. - * The new struct is attached to the parent's pgrp and starts with - * refcount=1. Used by fork (non-CLONE_THREAD). - */ -signal_struct* fork_signal_struct(signal_struct* parent, - TaskControlBlock* child_leader); - -/* Increment refcount (CLONE_THREAD share). */ -void get_signal_struct(signal_struct* sig); - -/* - * Decrement refcount; on last drop, detach from pgrp hash and free. - * Pass the task that's dropping the reference so we can manage - * leader pointers if the leader exits while sub-threads remain. - */ -void put_signal_struct(signal_struct* sig); - -/* ================================================================== */ -/* Pgrp operations (assume signal_struct is allocated) */ -/* ================================================================== */ - -/* - * Move a signal_struct from its current pgrp to `new_pgid`. - * Used by setpgid / setsid. Takes g_pgrp_lock internally. - */ -void change_pgid(signal_struct* sig, int32 new_pgid); - -/* - * Invoke `fn(sig)` for every signal_struct whose pgid == target. - * Holds g_pgrp_lock for the entire walk — fn must not block, sleep, - * or take locks that order before g_pgrp_lock. - * - * Template-y but kept in header to avoid a function-ptr indirection; - * keep callsites lean. - */ -template -void for_each_pgrp_member(int32 target_pgid, F&& fn); - -/* - * Count the number of signal_structs in `pgid`. Used by setsid - * preflight (can't create a session if you're already a pgrp leader - * with members) and orphan checks. - */ -int pgrp_member_count(int32 pgid); - -/* ================================================================== */ -/* Implementation details exposed for the template above */ -/* ================================================================== */ - -constexpr int kPgrpHashShift = 6; -constexpr int kPgrpHashSize = 1 << kPgrpHashShift; /* 64 buckets */ -constexpr int kPgrpHashMask = kPgrpHashSize - 1; - -extern list_node g_pgrp_hash[kPgrpHashSize]; -extern Spinlock g_pgrp_lock; - -inline int pgrp_hash_idx(int32 pgid) { - return static_cast(static_cast(pgid)) & kPgrpHashMask; -} - -#include - -template -void for_each_pgrp_member(int32 target_pgid, F&& fn) -{ - LockGuard guard(g_pgrp_lock); - list_node* bucket = &g_pgrp_hash[pgrp_hash_idx(target_pgid)]; - list_node* node = bucket->next; - while (node != bucket) { - list_node* nxt = node->next; /* fn may not unlink, but be safe */ - auto* sig = list_entry(node); - if (sig->pgid == target_pgid) - fn(sig); - node = nxt; - } -} diff --git a/include/lume/pgtable_types.h b/include/lume/pgtable_types.h deleted file mode 100644 index e309a82..0000000 --- a/include/lume/pgtable_types.h +++ /dev/null @@ -1,69 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Page Table Entry Types — strongly typed wrappers. - * - * Layout and macro names mirror Linux's arch/riscv/include/asm/page.h - * and pgtable-64.h so that arch/riscv/mm/init.c can be copied from - * Linux without source edits. The wrapped struct prevents accidental - * mixing of a pte_t with a pgd_t or a raw physical address, which the - * previous bare-uint64 design in pmap.cc could not catch. - * - * Underlying width on RV64 LP64 is `unsigned long` = 64 bits, matching - * Linux exactly — assembly references (e.g. REG_S/REG_L on a pte_t*) - * see the same byte layout. - * - * SV39 uses 3 levels (pgd -> pmd -> pte); SV48 uses 4 (pgd -> pud -> - * pmd -> pte). p4d_t/pud_t are emitted unconditionally so that the - * higher-level abstractions in asm-generic/pgtable-nopud.h and friends - * (which Linux uses to collapse unused levels) work without #ifdef. - */ - -#include - -typedef struct { - unsigned long pte; -} pte_t; - -typedef struct { - unsigned long pmd; -} pmd_t; - -typedef struct { - unsigned long pud; -} pud_t; - -typedef struct { - unsigned long p4d; -} p4d_t; - -typedef struct { - unsigned long pgd; -} pgd_t; - -typedef struct { - unsigned long pgprot; -} pgprot_t; - -typedef struct page *pgtable_t; - -/* Field accessors */ -#define pte_val(x) ((x).pte) -#define pmd_val(x) ((x).pmd) -#define pud_val(x) ((x).pud) -#define p4d_val(x) ((x).p4d) -#define pgd_val(x) ((x).pgd) -#define pgprot_val(x) ((x).pgprot) - -/* Constructors (cast raw uint64 to wrapped type) */ -#define __pte(x) ((pte_t) { (x) }) -#define __pmd(x) ((pmd_t) { (x) }) -#define __pud(x) ((pud_t) { (x) }) -#define __p4d(x) ((p4d_t) { (x) }) -#define __pgd(x) ((pgd_t) { (x) }) -#define __pgprot(x) ((pgprot_t) { (x) }) - -#define PTE_FMT "%016lx" diff --git a/include/lume/pid.h b/include/lume/pid.h deleted file mode 100644 index 8503750..0000000 --- a/include/lume/pid.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * PID Allocator — Bitmap-based O(1) block search - * Reference: docs/specs/task.md §3.2 - */ - -#include -#include - -inline constexpr int32 kMaxPid = 32768; - -class PidAllocator { -public: - void init(); - int32 alloc(); - void free(int32 pid); - -private: - static constexpr int32 kBitmapWords = kMaxPid / 64; - Spinlock lock_; - uint64 bitmap_[kBitmapWords]; - int32 next_hint_ = 2; -}; - -extern PidAllocator g_pid_alloc; diff --git a/include/lume/pipe.h b/include/lume/pipe.h deleted file mode 100644 index c905c9a..0000000 --- a/include/lume/pipe.h +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * pipe.h — Pipe data structure and API - * - * A pipe is a unidirectional byte stream backed by a fixed-size - * circular buffer. Two file structs (reader + writer) share a - * single pipe_inode_info. - */ - -#include -#include -#include -#include - -struct file; -struct files_struct; - -/* ================================================================== */ -/* pipe_inode_info */ -/* ================================================================== */ - -inline constexpr int PIPE_BUF_SIZE = 4096; - -struct pipe_inode_info { - char buf[PIPE_BUF_SIZE]; - int rd_pos; /* Read position in circular buffer */ - int wr_pos; /* Write position in circular buffer */ - int len; /* Bytes currently in buffer */ - Spinlock lock; - WaitQueue rd_wait; /* Readers sleep here when empty */ - WaitQueue wr_wait; /* Writers sleep here when full */ - - lume::atomic readers; /* Number of open read ends */ - lume::atomic writers; /* Number of open write ends */ - lume::atomic refcount; /* Total references */ -}; - -/* ================================================================== */ -/* API */ -/* ================================================================== */ - -/* Create a pipe, install read/write fds into the given files_struct. - * Returns 0 on success, negative errno on failure. */ -int do_pipe2(files_struct* files, int fds[2], int flags); - -/* Allocate a fresh pipe_inode_info */ -pipe_inode_info* alloc_pipe_info(); -void free_pipe_info(pipe_inode_info* pipe); diff --git a/include/lume/platform_device.h b/include/lume/platform_device.h deleted file mode 100644 index ac3e527..0000000 --- a/include/lume/platform_device.h +++ /dev/null @@ -1,64 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * platform_device / platform_driver — FDT-described memory-mapped devices. - * - * Mirrors Linux include/linux/platform_device.h. The platform bus is - * the catch-all bus for devices that don't live on a real bus like PCI - * or USB — every device discovered via the FDT lands here. - * - * Reference: docs/specs/storage_stack.md §4.3 - */ - -#include -#include - -class DeviceNode; - -/* Compatible-string -> driver-private data table (Linux's of_device_id). */ -struct of_device_id { - const char* compatible; - const void* data; -}; - -struct platform_device { - device dev; - DeviceNode* of_node; // FDT node this device came from - uint64 mmio_base; // first `reg` cell from FDT (0 if none) - uint64 mmio_size; // second `reg` cell (0 if none) - int irq; // first interrupt (-1 if none / not parsed) -}; - -struct platform_driver { - device_driver driver; - int (*probe)(platform_device*); - void (*remove)(platform_device*); - const of_device_id* of_match_table; // NULL-terminated array -}; - -extern bus_type platform_bus; - -void platform_bus_init(); -int platform_driver_register(platform_driver* drv); -int platform_device_register(platform_device* pdev); - -/* Helper: pull current driver out of a probed device. */ -inline platform_driver* to_platform_driver(device_driver* drv) -{ - return container_of(drv, platform_driver, driver); -} -inline platform_device* to_platform_device(device* dev) -{ - return container_of(dev, platform_device, dev); -} - -/* Linker-set registration macro — drop a pointer to your platform_driver - * into the .drivers section. driver_probe_all() iterates this set at - * boot. Use a unique token in CONCAT to avoid name collisions. */ -#define PLATFORM_DRIVER(_drv) \ - extern platform_driver _drv; \ - static platform_driver* const __pdrv_ptr_##_drv \ - __attribute__((used, section(".drivers"))) = &_drv diff --git a/include/lume/pmm.h b/include/lume/pmm.h deleted file mode 100644 index 3e4b819..0000000 --- a/include/lume/pmm.h +++ /dev/null @@ -1,108 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Physical Memory Manager (PMM) — Buddy System + Per-CPU Cache - * - * Manages all physical pages discovered via FDT. Built on a - * power-of-two buddy allocator for multi-page requests, with a - * Per-CPU single-page cache (PCP) to reduce lock contention on the - * hot single-page alloc/free path. - * - * Concurrency model: - * - PCP operations run with interrupts disabled (same-CPU safety). - * - Global buddy operations are protected by a single Spinlock. - * - Reference counts use __atomic builtins (lock-free). - * - * Reference: docs/specs/pmm.md - */ - -#include -#include -#include -#include - -/* Buddy system constants */ -inline constexpr int kMaxOrder = CONFIG_MAX_ORDER; // Orders 0..(N-1) - -/* Per-CPU cache dynamic parameters (calculated in pmm_init) */ -extern uint32 g_pcp_high_watermark; -extern uint32 g_pcp_batch_size; - -/* ================================================================== */ -/* Public free-function API */ -/* ================================================================== */ - -/* - * Initialize the PMM. Called by BSP after vmm_init() + memblock. - * page_map is already mapped at VMEMMAP VA by vmm_init. - * Populates buddy lists from memblock's free regions, then retires memblock. - * Panics on failure. - */ -void pmm_init(); - -/* --- Single-page fast path (uses PCP) --- */ - -// Allocate one 4KB page. Returns nullptr on OOM. -Page* pmm_alloc_page(); - -// Free one 4KB page. -void pmm_free_page(Page* page); - -/* --- Multi-page slow path (direct buddy) --- */ - -// Allocate 2^order contiguous pages. Returns nullptr on OOM. -Page* pmm_alloc_pages(uint8 order); - -// Free 2^order contiguous pages. -void pmm_free_pages(Page* page, uint8 order); - -/* --- Reference counting (atomic, lock-free) --- */ - -void page_incref(Page* page); -void page_decref(Page* page); - -/* --- Map counting (atomic, lock-free) --- */ - -inline void page_inc_mapcount(Page* page) { - page->mapcount.fetch_add(1); -} - -inline uint32 page_dec_mapcount(Page* page) { - return page->mapcount.fetch_sub(1) - 1; // Returns new value -} - -inline uint32 page_mapcount(const Page* page) { - return page->mapcount.load(__ATOMIC_RELAXED); -} - -/* --- Address conversion --- */ - -// Convert a Page* to its physical address. -PhysAddr page_to_pa(const Page* page); - -// Convert a physical address to its Page*. -Page* pa_to_page(PhysAddr pa); - -// Convert a Page* to a kernel virtual address. -VirtAddr page_to_va(const Page* page); - -/* --- PFN (Page Frame Number) abstraction --- */ -/* - * PFN is the fundamental unit for PA↔Page conversion. - * PA↔PFN converters already exist in addr.h (pa_to_pfn / pfn_to_pa). - * When sparse vmemmap lands, only pfn_to_page/page_to_pfn - * need to change — no callers are affected. - */ - -// Convert PFN to Page*. PFN = pa / PAGE_SIZE. -Page* pfn_to_page(uint64 pfn); - -// Convert Page* to PFN. -uint64 page_to_pfn(const Page* page); - -// Query PMM memory range (for VMM kernel mapping) -PhysAddr pmm_get_mem_base(); -uint64 pmm_get_mem_size(); diff --git a/include/lume/poll.h b/include/lume/poll.h deleted file mode 100644 index 7d5bca2..0000000 --- a/include/lume/poll.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * poll.h — POSIX poll() / ppoll() infrastructure. - * - * Linux pattern (include/linux/poll.h): - * - file_operations->poll(file, poll_table) returns a bitmask of - * POLL* events that are currently true on this file. - * - As a side effect, the poll callback calls poll_wait(file, wq, pt) - * to register the caller on every wait queue that might fire when - * state changes. sys_ppoll() then sleeps on those queues until - * one of them fires or a signal/timeout arrives. - * - * Our minimal implementation supports a SINGLE wait queue per poll call - * (sufficient for nfds==1, which is the BusyBox interactive shell case). - * Multi-fd polls work but fall back to busy re-checking; a proper - * per-fd waiter-list upgrade can come later. - */ - -#include - -struct file; -class WaitQueue; - -/* ================================================================== */ -/* UAPI: pollfd struct + POLL* event bits (Linux asm-generic) */ -/* ================================================================== */ - -struct pollfd { - int32 fd; - int16 events; - int16 revents; -}; - -inline constexpr int16 POLLIN = 0x0001; -inline constexpr int16 POLLPRI = 0x0002; -inline constexpr int16 POLLOUT = 0x0004; -inline constexpr int16 POLLERR = 0x0008; -inline constexpr int16 POLLHUP = 0x0010; -inline constexpr int16 POLLNVAL = 0x0020; -inline constexpr int16 POLLRDNORM = 0x0040; -inline constexpr int16 POLLRDBAND = 0x0080; -inline constexpr int16 POLLWRNORM = 0x0100; -inline constexpr int16 POLLWRBAND = 0x0200; - -/* ================================================================== */ -/* Kernel-side poll_table */ -/* ================================================================== */ - -/* - * Carried into file_operations->poll(). Drivers call poll_wait() with - * the wait queue they'd like the poller to sleep on; we record the - * first one. When `wq == nullptr` on entry, no real registration is - * needed (the caller is just probing readiness). - */ -struct poll_table { - WaitQueue* wq; /* first wait queue registered (single-wq design) */ -}; - -/* - * Called from f_op->poll() implementations to register a wait queue. - * If `pt` is null we're in a probe-only pass — caller doesn't want to - * sleep, just to read current revents. - */ -void poll_wait(file* fp, WaitQueue* wq, poll_table* pt); diff --git a/include/lume/ptrace.h b/include/lume/ptrace.h deleted file mode 100644 index 687d103..0000000 --- a/include/lume/ptrace.h +++ /dev/null @@ -1,76 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * PtRegs — Linux-compatible user register context - * - * This structure MUST match the Linux RISC-V pt_regs layout exactly. - * It is the canonical representation for: - * - Signal frame construction (ucontext / sigcontext) - * - ptrace(GETREGS/SETREGS) - * - /proc//regs - * - * The internal TrapFrame (arch/trapframe.h) has a DIFFERENT layout - * optimized for fast trap entry/exit. Conversion between the two - * is done via trapframe_to_pt_regs() / pt_regs_to_trapframe(). - * - * Reference: Linux arch/riscv/include/asm/ptrace.h - */ - -#include - -struct PtRegs { - uint64 epc; // Program counter at trap - uint64 ra; // x1 - uint64 sp; // x2 - uint64 gp; // x3 - uint64 tp; // x4 - uint64 t0; // x5 - uint64 t1; // x6 - uint64 t2; // x7 - uint64 s0; // x8 - uint64 s1; // x9 - uint64 a0; // x10 - uint64 a1; // x11 - uint64 a2; // x12 - uint64 a3; // x13 - uint64 a4; // x14 - uint64 a5; // x15 - uint64 a6; // x16 - uint64 a7; // x17 - uint64 s2; // x18 - uint64 s3; // x19 - uint64 s4; // x20 - uint64 s5; // x21 - uint64 s6; // x22 - uint64 s7; // x23 - uint64 s8; // x24 - uint64 s9; // x25 - uint64 s10; // x26 - uint64 s11; // x27 - uint64 t3; // x28 - uint64 t4; // x29 - uint64 t5; // x30 - uint64 t6; // x31 - /* CSRs */ - uint64 status; // sstatus - uint64 badaddr; // stval - uint64 cause; // scause - /* Syscall bookkeeping */ - uint64 orig_a0; // a0 value before syscall (for restart) -}; - -static_assert(sizeof(PtRegs) == 36 * 8, "PtRegs must be 288 bytes (Linux ABI)"); - -/* - * Convert between internal TrapFrame and Linux-ABI PtRegs. - * These are the ONLY places that know both layouts. - * Future TrapFrame restructuring only needs to update these two functions. - */ -namespace arch { struct TrapFrame; } - -void trapframe_to_pt_regs(PtRegs* dst, const arch::TrapFrame* src, - uint64 scause, uint64 stval); -void pt_regs_to_trapframe(arch::TrapFrame* dst, const PtRegs* src); diff --git a/include/lume/random.h b/include/lume/random.h deleted file mode 100644 index 740b060..0000000 --- a/include/lume/random.h +++ /dev/null @@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#include - -enum class RandomSeedSource : uint8 { - Unknown = 0, - FdtProvided, - HwRandom, - CycleFallback, -}; - -/* - * MI: Machine-Independent Random Number Generator API - * - * Provides early PRNG and eventually a full CSPRNG. - */ - -/* - * Initialize early PRNG with a seed (e.g., from FDT). - * If seed is 0, attempts to use hardware TRNG or falls back to timer jitter. - */ -void random_early_init(uint64 seed); - -/* Consume random bits */ -uint64 get_random_u64(); -uint32 get_random_u32(); -void get_random_bytes(void* buf, size_t len); - -/* Inject entropy (for future interrupt/device mixing) */ -void add_device_randomness(const void* buf, size_t len); - -/* Early-seed metadata (for boot diagnostics/KASLR logs). */ -RandomSeedSource random_early_seed_source(); -uint64 random_early_seed_value(); -const char* random_seed_source_name(RandomSeedSource source); diff --git a/include/lume/rbtree.h b/include/lume/rbtree.h deleted file mode 100644 index 80b0c6c..0000000 --- a/include/lume/rbtree.h +++ /dev/null @@ -1,207 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Red-Black Trees — public API - * Adapted from Linux kernel include/linux/rbtree.h - * - * (C) 1999 Andrea Arcangeli - */ - -#pragma once - -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Core macros */ -/* ------------------------------------------------------------------ */ - -#define rb_parent(r) ((struct rb_node *)((r)->__rb_parent_color & ~3UL)) - -#define rb_entry(ptr, type, member) container_of(ptr, type, member) - -#define RB_EMPTY_ROOT(root) (READ_ONCE((root)->rb_node) == nullptr) - -#define RB_EMPTY_NODE(node) \ - ((node)->__rb_parent_color == (unsigned long)(node)) -#define RB_CLEAR_NODE(node) \ - ((node)->__rb_parent_color = (unsigned long)(node)) - -/* ------------------------------------------------------------------ */ -/* Core API (implemented in lib/rbtree.cc) */ -/* ------------------------------------------------------------------ */ - -#ifdef __cplusplus -extern "C" { -#endif - -void rb_insert_color(struct rb_node *, struct rb_root *); -void rb_erase(struct rb_node *, struct rb_root *); - -struct rb_node *rb_next(const struct rb_node *); -struct rb_node *rb_prev(const struct rb_node *); -struct rb_node *rb_first(const struct rb_root *); -struct rb_node *rb_last(const struct rb_root *); - -struct rb_node *rb_first_postorder(const struct rb_root *); -struct rb_node *rb_next_postorder(const struct rb_node *); - -void rb_replace_node(struct rb_node *victim, struct rb_node *_new, - struct rb_root *root); - -#ifdef __cplusplus -} -#endif - -/* ------------------------------------------------------------------ */ -/* Inline helpers */ -/* ------------------------------------------------------------------ */ - -static inline void rb_link_node(struct rb_node *node, struct rb_node *parent, - struct rb_node **rb_link) -{ - node->__rb_parent_color = (unsigned long)parent; - node->rb_left = node->rb_right = nullptr; - *rb_link = node; -} - -#define rb_entry_safe(ptr, type, member) \ - ({ __typeof__(ptr) ____ptr = (ptr); \ - ____ptr ? rb_entry(____ptr, type, member) : nullptr; \ - }) - -/* ------------------------------------------------------------------ */ -/* Cached (leftmost) tree helpers */ -/* ------------------------------------------------------------------ */ - -#define rb_first_cached(root) (root)->rb_leftmost - -static inline void rb_insert_color_cached(struct rb_node *node, - struct rb_root_cached *root, - bool leftmost) -{ - if (leftmost) - root->rb_leftmost = node; - rb_insert_color(node, &root->rb_root); -} - -static inline void rb_erase_cached(struct rb_node *node, - struct rb_root_cached *root) -{ - if (root->rb_leftmost == node) - root->rb_leftmost = rb_next(node); - rb_erase(node, &root->rb_root); -} - -static inline void rb_replace_node_cached(struct rb_node *victim, - struct rb_node *_new, - struct rb_root_cached *root) -{ - if (root->rb_leftmost == victim) - root->rb_leftmost = _new; - rb_replace_node(victim, _new, &root->rb_root); -} - -static inline void rb_erase_init(struct rb_node *n, struct rb_root *root) -{ - rb_erase(n, root); - RB_CLEAR_NODE(n); -} - -/* ------------------------------------------------------------------ */ -/* Generic insert / find helpers (inline, using function pointers) */ -/* ------------------------------------------------------------------ */ - -static inline void -rb_add(struct rb_node *node, struct rb_root *tree, - bool (*less)(struct rb_node *, const struct rb_node *)) -{ - struct rb_node **link = &tree->rb_node; - struct rb_node *parent = nullptr; - - while (*link) { - parent = *link; - if (less(node, parent)) - link = &parent->rb_left; - else - link = &parent->rb_right; - } - - rb_link_node(node, parent, link); - rb_insert_color(node, tree); -} - -static inline void -rb_add_cached(struct rb_node *node, struct rb_root_cached *tree, - bool (*less)(struct rb_node *, const struct rb_node *)) -{ - struct rb_node **link = &tree->rb_root.rb_node; - struct rb_node *parent = nullptr; - bool leftmost = true; - - while (*link) { - parent = *link; - if (less(node, parent)) { - link = &parent->rb_left; - } else { - link = &parent->rb_right; - leftmost = false; - } - } - - rb_link_node(node, parent, link); - rb_insert_color_cached(node, tree, leftmost); -} - -static inline struct rb_node * -rb_find(const void *key, const struct rb_root *tree, - int (*cmp)(const void *key, const struct rb_node *)) -{ - struct rb_node *node = tree->rb_node; - - while (node) { - int c = cmp(key, node); - if (c < 0) - node = node->rb_left; - else if (c > 0) - node = node->rb_right; - else - return node; - } - return nullptr; -} - -static inline struct rb_node * -rb_find_add(struct rb_node *node, struct rb_root *tree, - int (*cmp)(struct rb_node *, const struct rb_node *)) -{ - struct rb_node **link = &tree->rb_node; - struct rb_node *parent = nullptr; - int c; - - while (*link) { - parent = *link; - c = cmp(node, parent); - if (c < 0) - link = &parent->rb_left; - else if (c > 0) - link = &parent->rb_right; - else - return parent; - } - - rb_link_node(node, parent, link); - rb_insert_color(node, tree); - return nullptr; -} - -/* ------------------------------------------------------------------ */ -/* Iteration macros */ -/* ------------------------------------------------------------------ */ - -#define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \ - for (pos = rb_entry_safe(rb_first_postorder(root), __typeof__(*pos), field); \ - pos && ({ n = rb_entry_safe(rb_next_postorder(&pos->field), \ - __typeof__(*pos), field); 1; }); \ - pos = n) - diff --git a/include/lume/rbtree_augmented.h b/include/lume/rbtree_augmented.h deleted file mode 100644 index d4559c4..0000000 --- a/include/lume/rbtree_augmented.h +++ /dev/null @@ -1,252 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Red-Black Trees — augmented operations & internal helpers - * Adapted from Linux kernel include/linux/rbtree_augmented.h - * - * (C) 1999 Andrea Arcangeli - * (C) 2002 David Woodhouse - * (C) 2012 Michel Lespinasse - */ - -#pragma once - -#include - -/* ------------------------------------------------------------------ */ -/* Augmented callback structure */ -/* ------------------------------------------------------------------ */ - -struct rb_augment_callbacks { - void (*propagate)(struct rb_node *node, struct rb_node *stop); - void (*copy)(struct rb_node *old, struct rb_node *_new); - void (*rotate)(struct rb_node *old, struct rb_node *_new); -}; - -extern "C" void __rb_insert_augmented(struct rb_node *node, struct rb_root *root, - void (*augment_rotate)(struct rb_node *old, struct rb_node *_new)); - -extern "C" void __rb_erase_color(struct rb_node *parent, struct rb_root *root, - void (*augment_rotate)(struct rb_node *old, struct rb_node *_new)); - -static inline void -rb_insert_augmented(struct rb_node *node, struct rb_root *root, - const struct rb_augment_callbacks *augment) -{ - __rb_insert_augmented(node, root, augment->rotate); -} - -static inline void -rb_insert_augmented_cached(struct rb_node *node, - struct rb_root_cached *root, bool newleft, - const struct rb_augment_callbacks *augment) -{ - if (newleft) - root->rb_leftmost = node; - rb_insert_augmented(node, &root->rb_root, augment); -} - -/* ------------------------------------------------------------------ */ -/* Color / parent encoding helpers */ -/* ------------------------------------------------------------------ */ - -#define RB_RED 0 -#define RB_BLACK 1 - -#define __rb_parent(pc) ((struct rb_node *)(pc & ~3UL)) - -#define __rb_color(pc) ((pc) & 1) -#define __rb_is_black(pc) __rb_color(pc) -#define __rb_is_red(pc) (!__rb_color(pc)) -#define rb_color(rb) __rb_color((rb)->__rb_parent_color) -#define rb_is_red(rb) __rb_is_red((rb)->__rb_parent_color) -#define rb_is_black(rb) __rb_is_black((rb)->__rb_parent_color) - -static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p) -{ - rb->__rb_parent_color = rb_color(rb) + (unsigned long)p; -} - -static inline void rb_set_parent_color(struct rb_node *rb, - struct rb_node *p, int color) -{ - rb->__rb_parent_color = (unsigned long)p + color; -} - -static inline void -__rb_change_child(struct rb_node *old, struct rb_node *_new, - struct rb_node *parent, struct rb_root *root) -{ - if (parent) { - if (parent->rb_left == old) - WRITE_ONCE(parent->rb_left, _new); - else - WRITE_ONCE(parent->rb_right, _new); - } else - WRITE_ONCE(root->rb_node, _new); -} - -/* ------------------------------------------------------------------ */ -/* Augmented erase (inline) */ -/* ------------------------------------------------------------------ */ - -static __always_inline struct rb_node * -__rb_erase_augmented(struct rb_node *node, struct rb_root *root, - const struct rb_augment_callbacks *augment) -{ - struct rb_node *child = node->rb_right; - struct rb_node *tmp = node->rb_left; - struct rb_node *parent, *rebalance; - unsigned long pc; - - if (!tmp) { - /* - * Case 1: node to erase has no more than 1 child (easy!) - */ - pc = node->__rb_parent_color; - parent = __rb_parent(pc); - __rb_change_child(node, child, parent, root); - if (child) { - child->__rb_parent_color = pc; - rebalance = nullptr; - } else - rebalance = __rb_is_black(pc) ? parent : nullptr; - tmp = parent; - } else if (!child) { - /* Still case 1, but this time the child is node->rb_left */ - tmp->__rb_parent_color = pc = node->__rb_parent_color; - parent = __rb_parent(pc); - __rb_change_child(node, tmp, parent, root); - rebalance = nullptr; - tmp = parent; - } else { - struct rb_node *successor = child, *child2; - - tmp = child->rb_left; - if (!tmp) { - /* - * Case 2: node's successor is its right child - */ - parent = successor; - child2 = successor->rb_right; - - augment->copy(node, successor); - } else { - /* - * Case 3: node's successor is leftmost under - * node's right child subtree - */ - do { - parent = successor; - successor = tmp; - tmp = tmp->rb_left; - } while (tmp); - child2 = successor->rb_right; - WRITE_ONCE(parent->rb_left, child2); - WRITE_ONCE(successor->rb_right, child); - rb_set_parent(child, successor); - - augment->copy(node, successor); - augment->propagate(parent, successor); - } - - tmp = node->rb_left; - WRITE_ONCE(successor->rb_left, tmp); - rb_set_parent(tmp, successor); - - pc = node->__rb_parent_color; - tmp = __rb_parent(pc); - __rb_change_child(node, successor, tmp, root); - - if (child2) { - rb_set_parent_color(child2, parent, RB_BLACK); - rebalance = nullptr; - } else { - rebalance = rb_is_black(successor) ? parent : nullptr; - } - successor->__rb_parent_color = pc; - tmp = successor; - } - - augment->propagate(tmp, nullptr); - return rebalance; -} - -static __always_inline void -rb_erase_augmented(struct rb_node *node, struct rb_root *root, - const struct rb_augment_callbacks *augment) -{ - struct rb_node *rebalance = __rb_erase_augmented(node, root, augment); - if (rebalance) - __rb_erase_color(rebalance, root, augment->rotate); -} - -static __always_inline void -rb_erase_augmented_cached(struct rb_node *node, struct rb_root_cached *root, - const struct rb_augment_callbacks *augment) -{ - if (root->rb_leftmost == node) - root->rb_leftmost = rb_next(node); - rb_erase_augmented(node, &root->rb_root, augment); -} - -/* ------------------------------------------------------------------ */ -/* Augmented callback declaration macros */ -/* ------------------------------------------------------------------ */ - -#define RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \ - RBSTRUCT, RBFIELD, RBAUGMENTED, RBCOMPUTE) \ -static inline void \ -RBNAME ## _propagate(struct rb_node *rb, struct rb_node *stop) \ -{ \ - while (rb != stop) { \ - RBSTRUCT *node = rb_entry(rb, RBSTRUCT, RBFIELD); \ - if (RBCOMPUTE(node, true)) \ - break; \ - rb = rb_parent(&node->RBFIELD); \ - } \ -} \ -static inline void \ -RBNAME ## _copy(struct rb_node *rb_old, struct rb_node *rb_new) \ -{ \ - RBSTRUCT *old_ = rb_entry(rb_old, RBSTRUCT, RBFIELD); \ - RBSTRUCT *new_ = rb_entry(rb_new, RBSTRUCT, RBFIELD); \ - new_->RBAUGMENTED = old_->RBAUGMENTED; \ -} \ -static void \ -RBNAME ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \ -{ \ - RBSTRUCT *old_ = rb_entry(rb_old, RBSTRUCT, RBFIELD); \ - RBSTRUCT *new_ = rb_entry(rb_new, RBSTRUCT, RBFIELD); \ - new_->RBAUGMENTED = old_->RBAUGMENTED; \ - RBCOMPUTE(old_, false); \ -} \ -RBSTATIC const struct rb_augment_callbacks RBNAME = { \ - RBNAME ## _propagate, \ - RBNAME ## _copy, \ - RBNAME ## _rotate \ -}; - -#define RB_DECLARE_CALLBACKS_MAX(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD, \ - RBTYPE, RBAUGMENTED, RBCOMPUTE) \ -static inline bool RBNAME ## _compute_max(RBSTRUCT *node, bool exit_early) \ -{ \ - RBSTRUCT *child; \ - RBTYPE max = RBCOMPUTE(node); \ - if (node->RBFIELD.rb_left) { \ - child = rb_entry(node->RBFIELD.rb_left, RBSTRUCT, RBFIELD); \ - if (child->RBAUGMENTED > max) \ - max = child->RBAUGMENTED; \ - } \ - if (node->RBFIELD.rb_right) { \ - child = rb_entry(node->RBFIELD.rb_right, RBSTRUCT, RBFIELD); \ - if (child->RBAUGMENTED > max) \ - max = child->RBAUGMENTED; \ - } \ - if (exit_early && node->RBAUGMENTED == max) \ - return true; \ - node->RBAUGMENTED = max; \ - return false; \ -} \ -RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \ - RBSTRUCT, RBFIELD, RBAUGMENTED, RBNAME ## _compute_max) - diff --git a/include/lume/rbtree_types.h b/include/lume/rbtree_types.h deleted file mode 100644 index 688ade4..0000000 --- a/include/lume/rbtree_types.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Red-Black Tree type definitions - * Adapted from Linux kernel include/linux/rbtree_types.h - */ - -#pragma once - -#include - -struct rb_node { - unsigned long __rb_parent_color; - struct rb_node *rb_right; - struct rb_node *rb_left; -} __attribute__((aligned(sizeof(long)))); - -struct rb_root { - struct rb_node *rb_node; -}; - -struct rb_root_cached { - struct rb_root rb_root; - struct rb_node *rb_leftmost; -}; - -#define RB_ROOT (struct rb_root) { nullptr, } -#define RB_ROOT_CACHED (struct rb_root_cached) { {nullptr, }, nullptr } - diff --git a/include/lume/sched.h b/include/lume/sched.h deleted file mode 100644 index ab26bac..0000000 --- a/include/lume/sched.h +++ /dev/null @@ -1,102 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Scheduler Public Interface - * - * Linux-style sched_class core with per-CPU runqueues. - * Phase 2: O(1) bitmap class is the default scheduling class. - * - * Reference: docs/specs/scheduler.md - */ - -#include -#include - -struct TaskControlBlock; - -/* ======================================================================== - * Scheduler Constants — driven by CONFIG_xxx (see scripts/Kconfig.mk) - * ======================================================================== */ - -inline constexpr int kNumPriorities = CONFIG_NR_PRIORITIES; -inline constexpr int kDefaultPriority = CONFIG_DEFAULT_PRIORITY; -inline constexpr int kDefaultTimeSlice = CONFIG_DEFAULT_TIMESLICE; -inline constexpr int kIdlePriority = CONFIG_IDLE_PRIORITY; - -/* ======================================================================== - * Initialization - * ======================================================================== */ - -/* BSP: initialize all RunQueues, create BSP idle thread and boot TCB. */ -void sched_init(); - -/* AP: create per-CPU idle thread and boot TCB. */ -void sched_init_ap(); - -/* ======================================================================== - * Core Scheduling - * ======================================================================== */ - -/* Main scheduling entry point. Picks the next task and context-switches. - * Called voluntarily (yield, sleep, exit) or from trap return path. */ -void schedule(); - -/* Timer tick handler. Delegates to current task's sched_class. - * Called from MI trap layer in interrupt context. */ -void sched_tick(); - -/* Check if rescheduling is needed (called before returning to user mode). */ -void sched_check_preempt(); - -/* Voluntarily yield the current time slice. */ -void sched_yield(); - -/* ======================================================================== - * Task Queue Management (used by task.cc, waitqueue.cc) - * ======================================================================== */ - -/* Make a task runnable: add it to its CPU's RunQueue. */ -void sched_enqueue(TaskControlBlock* task); - -/* Mark a task as sleeping: remove it from the RunQueue. */ -void sched_dequeue(TaskControlBlock* task); - -/* ======================================================================== - * Time Slice Policy - * ======================================================================== */ - -/* Convert priority level to time slice length. - * Higher priority (lower number) → longer time slice. */ -int32 priority_to_timeslice(uint8 priority); - -/* ======================================================================== - * Task Migration & Load Balancing - * ======================================================================== */ - -/* - * sched_migrate_task — Move a task from its current CPU to target_cpu. - * - * The task must NOT be the currently running task. It is dequeued from - * its old runqueue and enqueued onto the target. Both runqueue locks - * are acquired in cpu_id order to prevent deadlock. - * - * Returns 0 on success, -EINVAL if task is current or target is invalid. - */ -int sched_migrate_task(TaskControlBlock* task, uint8 target_cpu); - -/* - * sched_balance — Periodic load balancer. - * - * Called from sched_tick(). Checks if any CPU has significantly more - * runnable tasks and pulls work to the local runqueue. This is a - * simplified version of Linux's load_balance(). - */ -void sched_balance(); - -/* - * sched_nr_running — Get the number of runnable tasks on a CPU. - */ -uint32 sched_nr_running(uint32 cpu_id); diff --git a/include/lume/sched_class.h b/include/lume/sched_class.h deleted file mode 100644 index 08686c1..0000000 --- a/include/lume/sched_class.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Scheduler Class Interface (Linux-style) - * - * Each scheduling algorithm implements a sched_class and is chained - * in priority order. The scheduler core walks the chain to select - * the next runnable task. - */ - -#include - -struct RunQueue; -struct TaskControlBlock; - -struct SchedClass { - const char* name; - const SchedClass* next; // Linked list order: higher priority first - - void (*init_rq)(RunQueue* rq); - - void (*enqueue_task)(RunQueue* rq, TaskControlBlock* task); - void (*dequeue_task)(RunQueue* rq, TaskControlBlock* task); - TaskControlBlock* (*pick_next_task)(RunQueue* rq); - void (*put_prev_task)(RunQueue* rq, TaskControlBlock* task); - - void (*task_tick)(RunQueue* rq, TaskControlBlock* curr); - void (*yield_task)(RunQueue* rq, TaskControlBlock* curr); -}; - -extern const SchedClass g_sched_class_o1; -extern const SchedClass g_sched_class_idle; diff --git a/include/lume/selftest.h b/include/lume/selftest.h deleted file mode 100644 index 7040986..0000000 --- a/include/lume/selftest.h +++ /dev/null @@ -1,65 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Boot Self-Test Framework - * - * Minimal assertion-based test harness that runs during kernel_main() - * after all subsystems are initialized. Each test is a void function - * that calls ST_ASSERT / ST_ASSERT_EQ macros. On failure, prints - * the failing expression and panics. - * - * Usage: - * void selftest_pmm(); // defined in test/test_pmm.cc - * void selftest_slab(); // defined in test/test_slab.cc - * - * All self-tests run only on BSP in single-core mode. - */ - -#include -#include -#include - -#define ST_ASSERT(cond) \ - do { \ - if (!(cond)) { \ - kprintf("[FAIL] %s:%d: assertion failed: %s\n", \ - __FILE__, __LINE__, #cond); \ - kernel_panic("selftest failed", #cond); \ - } \ - } while (0) - -#define ST_ASSERT_EQ(a, b) \ - do { \ - auto _a = (a); auto _b = (b); \ - if (_a != _b) { \ - kprintf("[FAIL] %s:%d: %s != %s (0x%llx != 0x%llx)\n", \ - __FILE__, __LINE__, #a, #b, \ - (uint64)(uintptr)(_a), (uint64)(uintptr)(_b)); \ - kernel_panic("selftest failed", #a " != " #b); \ - } \ - } while (0) - -#define ST_ASSERT_NE(a, b) \ - do { \ - auto _a = (a); auto _b = (b); \ - if (_a == _b) { \ - kprintf("[FAIL] %s:%d: %s == %s (both 0x%llx)\n", \ - __FILE__, __LINE__, #a, #b, \ - (uint64)(uintptr)(_a)); \ - kernel_panic("selftest failed", #a " == " #b); \ - } \ - } while (0) - -/* Announce a test suite beginning/end */ -inline void st_begin(const char* name) -{ - kprintf("[test] %s ... ", name); -} - -inline void st_pass() -{ - kprintf("PASS\n"); -} diff --git a/include/lume/setup.h b/include/lume/setup.h deleted file mode 100644 index f8e6cb6..0000000 --- a/include/lume/setup.h +++ /dev/null @@ -1,42 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_SETUP_H -#define _LUME_SETUP_H - -/* - * Boot-time interfaces called between assembly and C. - * - * Mirrors the subset of Linux include/linux/setup.h relevant to LumeOS's - * Linux-aligned RISC-V boot flow: - * - * setup_vm Build early_pg_dir / trampoline_pg_dir before - * the MMU is enabled. Filled kernel_map for - * all subsequent code to consult. - * relocate_enable_mmu Switch SATP, jump to higher-half, apply - * .rela.dyn via relocate_kernel. - * relocate_kernel Walk .rela.dyn, patch R_RISCV_RELATIVE - * slots with addend + kaslr_offset. - * - * kernel_main (LumeOS's equivalent of Linux's start_kernel) is declared - * in kernel/main.cc and re-declared in arch-side glue — kept local to - * that file to avoid creating an artificial public API for the lone - * call site in head.S. - */ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void setup_vm(uintptr_t load_pa, uintptr_t dtb_pa); -void relocate_enable_mmu(pgd_t *pgdir); -void relocate_kernel(void); - -#ifdef __cplusplus -} -#endif - -#endif /* _LUME_SETUP_H */ diff --git a/include/lume/signal.h b/include/lume/signal.h deleted file mode 100644 index 05b7542..0000000 --- a/include/lume/signal.h +++ /dev/null @@ -1,60 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Signal Infrastructure — Core signal delivery API - * - * Provides the interface between trap handling, signal delivery, - * and user-space signal handler execution. - * - * Reference: Linux include/linux/sched/signal.h - */ - -#include - -struct TaskControlBlock; -struct sighand_struct; -namespace arch { struct TrapFrame; } - -/* ------------------------------------------------------------------ - * sighand_struct lifecycle (Linux kernel/fork.c:copy_sighand pattern) - * ------------------------------------------------------------------ */ - -sighand_struct* alloc_sighand(); -sighand_struct* copy_sighand(sighand_struct* parent); -void get_sighand(sighand_struct* sh); -void put_sighand(sighand_struct* sh); - -/* - * force_sig_fault — Deliver a fault-induced signal to the current task. - * - * Called from trap handler when a user-mode exception cannot be resolved. - * Bypasses the blocked mask and enqueues the signal. - * - * @signo: Signal number (SIGSEGV, SIGBUS, SIGILL, SIGFPE, etc.) - * @code: si_code for siginfo_t (e.g., SEGV_MAPERR, SEGV_ACCERR) - * @addr: Fault address (stval / badaddr) - */ -void force_sig_fault(int signo, int code, uint64 addr); - -/* - * do_signal — Process pending signals before returning to user mode. - * - * Called at the end of trap_handle() when origin == FromUser. - * If a signal is pending and a handler is registered, constructs - * a signal frame on the user stack and redirects epc. - * - * @tf: TrapFrame to modify if signal delivery is needed. - */ -void do_signal(arch::TrapFrame* tf); - -/* - * signal_pending — Check if the task has unblocked pending signals. - * - * Used by blocking syscalls (e.g., n_tty_read) to detect whether - * they should return -EINTR. - */ -bool signal_pending(TaskControlBlock* task); - diff --git a/include/lume/signal_nr.h b/include/lume/signal_nr.h deleted file mode 100644 index 8e595d7..0000000 --- a/include/lume/signal_nr.h +++ /dev/null @@ -1,54 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Linux-compatible signal numbers and related ABI constants. - * - * This mirrors the common Linux UAPI numbering used by asm-generic/signal.h. - * Keep the values stable so user-space binaries see the same numbers. - */ - -inline constexpr int _NSIG = 64; -inline constexpr int _NSIG_BPW = sizeof(unsigned long) * 8; -inline constexpr int _NSIG_WORDS = _NSIG / _NSIG_BPW; - -inline constexpr int SIGHUP = 1; -inline constexpr int SIGINT = 2; -inline constexpr int SIGQUIT = 3; -inline constexpr int SIGILL = 4; -inline constexpr int SIGTRAP = 5; -inline constexpr int SIGABRT = 6; -inline constexpr int SIGIOT = SIGABRT; -inline constexpr int SIGBUS = 7; -inline constexpr int SIGFPE = 8; -inline constexpr int SIGKILL = 9; -inline constexpr int SIGUSR1 = 10; -inline constexpr int SIGSEGV = 11; -inline constexpr int SIGUSR2 = 12; -inline constexpr int SIGPIPE = 13; -inline constexpr int SIGALRM = 14; -inline constexpr int SIGTERM = 15; -inline constexpr int SIGSTKFLT = 16; -inline constexpr int SIGCHLD = 17; -inline constexpr int SIGCONT = 18; -inline constexpr int SIGSTOP = 19; -inline constexpr int SIGTSTP = 20; -inline constexpr int SIGTTIN = 21; -inline constexpr int SIGTTOU = 22; -inline constexpr int SIGURG = 23; -inline constexpr int SIGXCPU = 24; -inline constexpr int SIGXFSZ = 25; -inline constexpr int SIGVTALRM = 26; -inline constexpr int SIGPROF = 27; -inline constexpr int SIGWINCH = 28; -inline constexpr int SIGIO = 29; -inline constexpr int SIGPOLL = SIGIO; -inline constexpr int SIGPWR = 30; -inline constexpr int SIGSYS = 31; -inline constexpr int SIGUNUSED = 31; - -/* Real-time signals start here in Linux UAPI. */ -inline constexpr int SIGRTMIN = 32; -inline constexpr int SIGRTMAX = _NSIG; diff --git a/include/lume/signal_types.h b/include/lume/signal_types.h deleted file mode 100644 index f66231b..0000000 --- a/include/lume/signal_types.h +++ /dev/null @@ -1,263 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Signal Types — Linux-compatible structures for signal delivery - * - * Follows the RISC-V LP64 ABI layout so that user-space programs - * compiled with musl / glibc see the correct struct sizes. - * - * Reference: Linux include/uapi/asm-generic/signal.h - * Linux include/uapi/asm-generic/siginfo.h - */ - -#include -#include -#include -#include - -/* ================================================================== */ -/* Signal set (64-bit bitmap) */ -/* ================================================================== */ - -struct sigset_t { - uint64 sig[_NSIG_WORDS]; /* _NSIG_WORDS = 1 on LP64 */ - - void clear() { for (auto& s : sig) s = 0; } - void fill() { for (auto& s : sig) s = ~0ULL; } - void add(int signo) { sig[(signo-1)/64] |= (1ULL << ((signo-1)%64)); } - void del(int signo) { sig[(signo-1)/64] &= ~(1ULL << ((signo-1)%64)); } - bool has(int signo) const { return (sig[(signo-1)/64] >> ((signo-1)%64)) & 1; } - bool is_empty() const { for (auto s : sig) if (s) return false; return true; } - - sigset_t operator&(const sigset_t& o) const { - sigset_t r; - for (int i = 0; i < _NSIG_WORDS; i++) r.sig[i] = sig[i] & o.sig[i]; - return r; - } - sigset_t operator|(const sigset_t& o) const { - sigset_t r; - for (int i = 0; i < _NSIG_WORDS; i++) r.sig[i] = sig[i] | o.sig[i]; - return r; - } - sigset_t operator~() const { - sigset_t r; - for (int i = 0; i < _NSIG_WORDS; i++) r.sig[i] = ~sig[i]; - return r; - } -}; - -/* ================================================================== */ -/* siginfo_t (simplified, Linux UAPI compatible layout) */ -/* ================================================================== */ - -struct kernel_siginfo { - int si_signo; - int si_errno; - int si_code; - int _pad0; /* alignment */ - - union { - /* kill() */ - struct { - int32 _pid; - int32 _uid; - } _kill; - - /* SIGCHLD */ - struct { - int32 _pid; - int32 _uid; - int _status; - long _utime; - long _stime; - } _sigchld; - - /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP */ - struct { - uint64 _addr; - } _sigfault; - - /* Pad to 128 bytes total (Linux SI_MAX_SIZE) */ - char _pad[128 - 4*sizeof(int)]; - } _sifields; -}; - -/* ================================================================== */ -/* Signal action (kernel representation) */ -/* ================================================================== */ - -/* sa_flags bits (Linux UAPI) */ -inline constexpr uint64 SA_NOCLDSTOP = 0x00000001; -inline constexpr uint64 SA_NOCLDWAIT = 0x00000002; -inline constexpr uint64 SA_SIGINFO = 0x00000004; -inline constexpr uint64 SA_RESTORER = 0x04000000; -inline constexpr uint64 SA_ONSTACK = 0x08000000; -inline constexpr uint64 SA_RESTART = 0x10000000; -inline constexpr uint64 SA_NODEFER = 0x40000000; -inline constexpr uint64 SA_RESETHAND = 0x80000000; - -/* Special handler values */ -inline constexpr uint64 SIG_DFL = 0; -inline constexpr uint64 SIG_IGN = 1; -inline constexpr uint64 SIG_ERR = static_cast(-1); - -struct kernel_sigaction { - uint64 sa_handler; /* handler address or SIG_DFL/SIG_IGN */ - uint64 sa_flags; - uint64 sa_restorer; /* sigreturn trampoline (SA_RESTORER) */ - sigset_t sa_mask; /* signals blocked during handler */ -}; - -/* ================================================================== */ -/* Per-task signal state */ -/* ================================================================== */ - -/* Queued signal entry */ -struct sigqueue { - list_node list; - kernel_siginfo info; -}; - -/* Pending signal set + queue */ -struct sigpending { - list_node list; /* list of sigqueue entries */ - sigset_t signal; /* bitmap of pending signals */ - - void init() { - list.init(); - signal.clear(); - } -}; - -/* Signal handler table (shared between threads via CLONE_SIGHAND). - * - * Linux pattern (kernel/fork.c:copy_sighand): one sighand_struct per - * thread group by default, shared across CLONE_SIGHAND siblings, - * refcounted, freed when the last referencing task exits. Its - * `siglock` guards BOTH the action table and every per-task `pending` - * list of every task that references this sighand. That single-lock - * model is what lets send/dequeue/discard race-free without per-list - * locks. */ -struct sighand_struct { - Spinlock siglock; - uint32 refcount; /* # tasks sharing this sighand (≥1) */ - kernel_sigaction action[_NSIG]; - - void init() { - siglock.init("sighand"); - refcount = 1; - for (auto& a : action) { - a.sa_handler = SIG_DFL; - a.sa_flags = 0; - a.sa_restorer = 0; - a.sa_mask.clear(); - } - } -}; - -/* ================================================================== */ -/* signal_struct — per-thread-group shared state */ -/* ================================================================== */ - -struct TaskControlBlock; -struct tty_struct; - -/* - * Linux's signal_struct is the per-thread-group container holding: - * - Process group / session identity (pgid, sid) - * - Controlling terminal (tty) - * - Misc state shared across CLONE_THREAD siblings - * - * Refcount tracks the number of tasks in the thread group; when the last - * task in the group exits, the signal_struct is freed. Detachment from - * the pgrp hash also happens at that point. - * - * `pgrp_link` makes this signal_struct a member of one pgrp bucket; the - * pgrp subsystem walks the bucket to enumerate all thread groups whose - * pgid hashes there. - */ -struct signal_struct { - Spinlock lock; - uint32 refcount; /* # tasks sharing this (≥1) */ - int32 pgid; /* process group id */ - int32 sid; /* session id */ - tty_struct* tty; /* controlling tty (or nullptr) */ - int32 tty_old_pgrp; /* SIGHUP target on TIOCNOTTY */ - TaskControlBlock* leader; /* thread-group leader (pid==tgid) */ - list_node pgrp_link; /* on pgrp hash bucket */ - - void init(int32 leader_pid, TaskControlBlock* tg_leader) { - lock.init("signal"); - refcount = 1; - pgid = leader_pid; - sid = leader_pid; - tty = nullptr; - tty_old_pgrp = 0; - leader = tg_leader; - pgrp_link.init(); - } -}; - -/* ================================================================== */ -/* Default signal dispositions */ -/* ================================================================== */ - -enum SigDefaultAction { - SIG_ACT_TERM, /* Terminate */ - SIG_ACT_IGN, /* Ignore */ - SIG_ACT_CORE, /* Terminate + core dump */ - SIG_ACT_STOP, /* Stop process */ - SIG_ACT_CONT, /* Continue if stopped */ -}; - -/* Returns the default action for a standard signal */ -inline SigDefaultAction sig_default_action(int sig) -{ - switch (sig) { - case SIGCHLD: - case SIGURG: - case SIGWINCH: - return SIG_ACT_IGN; - - case SIGCONT: - return SIG_ACT_CONT; - - case SIGSTOP: - case SIGTSTP: - case SIGTTIN: - case SIGTTOU: - return SIG_ACT_STOP; - - case SIGQUIT: - case SIGILL: - case SIGTRAP: - case SIGABRT: - case SIGBUS: - case SIGFPE: - case SIGSEGV: - case SIGXCPU: - case SIGXFSZ: - case SIGSYS: - return SIG_ACT_CORE; - - default: - return SIG_ACT_TERM; - } -} - -/* SIG_KERNEL_ONLY: cannot be caught or ignored */ -inline bool sig_kernel_only(int sig) -{ - return sig == SIGKILL || sig == SIGSTOP; -} - -/* ================================================================== */ -/* SigprocMask how values (Linux UAPI) */ -/* ================================================================== */ - -inline constexpr int SIG_BLOCK = 0; -inline constexpr int SIG_UNBLOCK = 1; -inline constexpr int SIG_SETMASK = 2; diff --git a/include/lume/slab.h b/include/lume/slab.h deleted file mode 100644 index 4ebade1..0000000 --- a/include/lume/slab.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * SLUB public API - * - * This header exposes the allocator entry points to the rest of the kernel. - * Implementation details stay in mm/slab.h and mm/slab.cc. - */ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Initialize global slab caches. */ -void slab_init(); - -/* Allocate/free kernel memory. */ -void* kmalloc(uint32 size); -void kfree(void* ptr); - -#ifdef __cplusplus -} -#endif diff --git a/include/lume/smp.h b/include/lume/smp.h deleted file mode 100644 index a5292b6..0000000 --- a/include/lume/smp.h +++ /dev/null @@ -1,74 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * smp.h — Machine-Independent SMP primitives - * - * Provides cross-CPU communication (IPI) and TLB coordination. - * The MI interface calls through to arch-specific backends - * (e.g. SBI on RISC-V, APIC on x86). - * - * Reference: docs/specs/linux_abi_mm_plan.md §SMP - */ - -#include -#include -#include - -/* - * IPI reasons — each bit in the per-CPU pending mask - * corresponds to one reason. Multiple reasons can be - * pending simultaneously. - */ -enum IpiReason : uint32 { - IPI_RESCHEDULE = (1U << 0), /* Target should call schedule() */ - IPI_TLB_SHOOTDOWN = (1U << 1), /* Target should flush TLB */ - IPI_CALL_FUNCTION = (1U << 2), /* Target should run a function */ - IPI_HALT = (1U << 3), /* Target should halt */ -}; - -/* - * Per-CPU IPI pending state. - * Written by sender (atomically), consumed by receiver in IRQ context. - */ -struct IpiData { - lume::atomic pending; /* Bitmask of IpiReason */ - - /* TLB shootdown payload */ - uint64 tlb_start; - uint64 tlb_end; -}; - -/* Per-CPU IPI data array (BSS zero-initialized) */ -extern IpiData g_ipi_data[kMaxCpus]; - -/* - * smp_send_ipi — Send an IPI to a set of CPUs - * - * @cpu_mask: bitmask of target CPU IDs (bit N = CPU N) - * @reason: reason bits to set in the target's pending mask - * - * Safe to call from any context (interrupt or process). - */ -void smp_send_ipi(uint64 cpu_mask, uint32 reason); - -/* - * smp_send_reschedule — Convenience: send reschedule IPI to one CPU - */ -inline void smp_send_reschedule(uint8 cpu_id) -{ - smp_send_ipi(1ULL << cpu_id, IPI_RESCHEDULE); -} - -/* - * smp_init — Initialize SMP subsystem (called from BSP after trap_init) - */ -void smp_init(); - -/* - * smp_handle_ipi — Called from trap handler on receiving S-mode - * software interrupt. Processes all pending IPI reasons. - */ -void smp_handle_ipi(); diff --git a/include/lume/stdarg.h b/include/lume/stdarg.h deleted file mode 100644 index c8dc7f4..0000000 --- a/include/lume/stdarg.h +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef _LINUX_STDARG_H -#define _LINUX_STDARG_H - -typedef __builtin_va_list va_list; -#define va_start(v, l) __builtin_va_start(v, l) -#define va_end(v) __builtin_va_end(v) -#define va_arg(v, T) __builtin_va_arg(v, T) -#define va_copy(d, s) __builtin_va_copy(d, s) - -#endif diff --git a/include/lume/stringify.h b/include/lume/stringify.h deleted file mode 100644 index 0e84cbe..0000000 --- a/include/lume/stringify.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __LINUX_STRINGIFY_H -#define __LINUX_STRINGIFY_H - -/* Indirect stringification. Doing two levels allows the parameter to be a - * macro itself. For example, compile with -DFOO=bar, __stringify(FOO) - * converts to "bar". - */ - -#define __stringify_1(x...) #x -#define __stringify(x...) __stringify_1(x) - -#define FILE_LINE __FILE__ ":" __stringify(__LINE__) - -#endif /* !__LINUX_STRINGIFY_H */ diff --git a/include/lume/syscall.h b/include/lume/syscall.h deleted file mode 100644 index 8185096..0000000 --- a/include/lume/syscall.h +++ /dev/null @@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * System Call Interface — Machine-Independent Layer - * - * Defines the unified syscall handler signature and the MI dispatch function. - * MD layer (arch/riscv/syscall/syscall_md.cc) extracts registers into args[6] - * and calls syscall_dispatch(). - * - * Reference: docs/specs/syscall.md §4 - */ - -#include - -/* Unified syscall handler signature. - * All arguments and return value are register-width (uint64). - * Individual sys_* functions cast internally. */ -using SyscallHandler = int64 (*)(uint64, uint64, uint64, - uint64, uint64, uint64); - -/* MI-layer syscall dispatcher. - * Called by MD layer after extracting syscall number and arguments. - * Returns the syscall result (negative errno on error). */ -int64 syscall_dispatch(uint64 nr, uint64 args[6]); - -/* Register all implemented syscall handlers into the jump table. - * Called from kernel_main() after sched_init(). */ -void syscall_init(); - -/* MD-layer entry point — called from trap handler on TrapCause::Syscall. - * Extracts registers from TrapFrame, calls syscall_dispatch, writes result. */ -namespace arch { -struct TrapFrame; -} -void syscall_dispatch_md(arch::TrapFrame* tf); diff --git a/include/lume/syscall_nr.h b/include/lume/syscall_nr.h deleted file mode 100644 index 29e3904..0000000 --- a/include/lume/syscall_nr.h +++ /dev/null @@ -1,82 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * System Call Numbers — RISC-V LP64 (asm-generic/unistd.h compatible) - * - * Numbering strictly follows Linux asm-generic so that musl libc / Busybox - * binaries can be run without modification. - * - * Reference: docs/specs/syscall.md §4.3 - */ - -inline constexpr int SYS_exit = 93; -inline constexpr int SYS_exit_group = 94; -inline constexpr int SYS_set_tid_address = 96; -inline constexpr int SYS_sched_yield = 124; -inline constexpr int SYS_uname = 160; -inline constexpr int SYS_getpid = 172; -inline constexpr int SYS_getppid = 173; -inline constexpr int SYS_getuid = 174; -inline constexpr int SYS_getgid = 176; -inline constexpr int SYS_gettid = 178; -inline constexpr int SYS_brk = 214; -inline constexpr int SYS_munmap = 215; -inline constexpr int SYS_clone = 220; -inline constexpr int SYS_execve = 221; -inline constexpr int SYS_mmap = 222; -inline constexpr int SYS_mprotect = 226; -inline constexpr int SYS_wait4 = 260; - -inline constexpr int SYS_getcwd = 17; -inline constexpr int SYS_dup = 23; -inline constexpr int SYS_dup3 = 24; -inline constexpr int SYS_ioctl = 29; -inline constexpr int SYS_mkdirat = 34; -inline constexpr int SYS_unlinkat = 35; -inline constexpr int SYS_chdir = 49; -inline constexpr int SYS_openat = 56; -inline constexpr int SYS_close = 57; -inline constexpr int SYS_pipe2 = 59; -inline constexpr int SYS_lseek = 62; -inline constexpr int SYS_read = 63; -inline constexpr int SYS_write = 64; -inline constexpr int SYS_writev = 66; -inline constexpr int SYS_ppoll = 73; -inline constexpr int SYS_fstatat = 79; -inline constexpr int SYS_fstat = 80; -inline constexpr int SYS_getdents64 = 61; - -inline constexpr int SYS_fcntl = 25; -inline constexpr int SYS_linkat = 37; -inline constexpr int SYS_mount = 40; -inline constexpr int SYS_umount2 = 39; - -inline constexpr int SYS_kill = 129; -inline constexpr int SYS_tkill = 130; -inline constexpr int SYS_tgkill = 131; -inline constexpr int SYS_sigaltstack = 132; -inline constexpr int SYS_rt_sigaction = 134; -inline constexpr int SYS_rt_sigprocmask = 135; -inline constexpr int SYS_rt_sigreturn = 139; -inline constexpr int SYS_reboot = 142; -inline constexpr int SYS_setpgid = 154; -inline constexpr int SYS_getpgid = 155; -inline constexpr int SYS_getsid = 156; -inline constexpr int SYS_setsid = 157; -inline constexpr int SYS_prctl = 167; -inline constexpr int SYS_geteuid = 175; -inline constexpr int SYS_getegid = 177; - -inline constexpr int SYS_futex = 98; -inline constexpr int SYS_nanosleep = 101; -inline constexpr int SYS_clock_gettime = 113; -inline constexpr int SYS_epoll_create1 = 20; -inline constexpr int SYS_epoll_ctl = 21; -inline constexpr int SYS_epoll_pwait = 22; - -inline constexpr int SYS_rt_sigtimedwait = 137; -inline constexpr int SYS_socket = 198; -inline constexpr int SYS_sendto = 206; diff --git a/include/lume/task.h b/include/lume/task.h deleted file mode 100644 index e959147..0000000 --- a/include/lume/task.h +++ /dev/null @@ -1,144 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Task Control Block & Task State - * - * Central representation of every execution context in LumeOS, - * whether kernel thread or (future) user process. - * - * Reference: docs/specs/task.md §3.1, docs/specs/scheduler.md §3.1 - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* Forward declarations */ -struct VmSpace; -struct SchedClass; - -/* ======================================================================== - * Task State Machine - * ======================================================================== */ - -enum class TaskState : uint8 { - Runnable = 0, // In a Per-CPU ready queue - Running = 1, // Currently executing on a CPU - Sleeping = 2, // Blocked on a WaitQueue - Zombie = 3, // Exited, waiting for parent wait() - Dead = 4, // Fully reclaimed, TCB can be freed - Stopped = 5, // Job control: SIGSTOP/SIGTSTP/SIGTTIN/SIGTTOU -}; - -/* ======================================================================== - * Task Flags - * ======================================================================== */ - -inline constexpr uint8 TF_KTHREAD = 0x01; // Kernel thread (never enters user mode) -inline constexpr uint8 TF_IDLE = 0x02; // Idle thread -inline constexpr uint8 TF_INIT = 0x04; // init process (PID 1) - -/* ======================================================================== - * Kernel Stack - * ======================================================================== */ - -inline constexpr uint64 kKernelStackSize = CONFIG_KERNEL_STACK_SIZE; -inline constexpr int kKernelStackOrder = (kKernelStackSize <= 4096) ? 0 - : (kKernelStackSize <= 8192) ? 1 - : (kKernelStackSize <= 16384) ? 2 - : (kKernelStackSize <= 32768) ? 3 : 4; -inline constexpr uint64 kStackCanary = 0xDEAD'BEEF'CAFE'BABEULL; - -/* ======================================================================== - * Task Control Block - * ======================================================================== */ - -struct TaskControlBlock { - /* ===== Scheduler hot fields (cache-line optimized) ===== */ - TaskState state; // Current state - uint8 priority; // Static priority [0, 31] - uint8 cpu_id; // Pinned CPU (Phase 2: no migration) - uint8 flags; // TF_KTHREAD | TF_IDLE | TF_INIT - - int32 time_slice; // Remaining time slice (ticks) - int32 pid; // Unique task ID (Linux: tid) - int32 tgid; // Thread group ID (Linux: pid) - int32 preempt_count; // >0: preemption disabled (holding locks etc.) - - list_node run_link; // RunQueue list node - list_node all_link; // Global task list node - - /* ===== Context ===== */ - arch::Context context; // Callee-saved registers (scheduler switch) - arch::TrapFrame* trapframe; // Trap frame (user-mode entry/exit) - arch::FpState fpstate; // FPU register state (f0-f31 + fcsr) - - /* ===== Kernel Stack ===== */ - uint64 kstack_pa; // Physical address - uint64 kstack_va; // Virtual address (stack bottom) - - /* ===== Address Space ===== */ - VmSpace* mm; // nullptr = kernel thread - - /* ===== Per-task lock ===== - * Protects: parent, children, sibling, exit_code, state transitions. - * Lock ordering: task->lock -> g_task_list_lock (never reverse). */ - Spinlock lock; - - /* ===== Task Hierarchy ===== */ - TaskControlBlock* parent; - list_node children; // Children list head - list_node sibling; // Sibling list node - WaitQueue wait_chld; // Parent waits on this for children to exit - - /* ===== Exit ===== */ - int32 exit_code; - int32 exit_signal; // Linux: signal sent to parent on exit. - // SIGCHLD = notify parent, become zombie - // -1 = auto-reap (kthreads) - uint64 clear_child_tid; // CLONE_CHILD_CLEARTID: write 0 here on exit - - /* ===== Job control reporting ===== - * stopped_code: 0 means "no pending stop notification"; non-zero is the - * Linux wstatus value to hand back from wait4(WUNTRACED). Cleared - * after the parent consumes it via wait4 (or task termination). - * notify_continued: set when SIGCONT resumes us; consumed by - * wait4(WCONTINUED). */ - int32 stopped_code; - bool notify_continued; - - /* ===== Scheduler class metadata ===== */ - const SchedClass* sched_class; - void* sched_entity; - - /* ===== VFS ===== */ - struct files_struct* files; // Per-task fd table (shared via CLONE_FILES) - struct fs_struct* fs; // cwd/root (shared via CLONE_FS) - - /* ===== Signals ===== */ - struct sigpending pending; // Per-task pending signal queue - sigset_t blocked; // Blocked signal mask - struct sighand_struct* sighand; // Signal handler table (shared via CLONE_SIGHAND) - struct signal_struct* signal; // Thread-group identity: pgid/sid/ctty (shared via CLONE_THREAD) - - /* ===== Debug ===== */ - const char* name; -}; - -/* ======================================================================== - * current_task() — fast access to the running task on this CPU - * - * Must be called with interrupts disabled or while holding a spinlock. - * ======================================================================== */ -TaskControlBlock* current_task(); - -/* Terminate the current task with a signal. */ -void task_kill_current(int sig); diff --git a/include/lume/timer.h b/include/lume/timer.h deleted file mode 100644 index 9bdddd5..0000000 --- a/include/lume/timer.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#include - -/* - * MI Timer Subsystem - */ - -#include - -struct TimerList { - list_node entry; - uint64 expires; - void (*function)(TimerList*); - void* data; - - void init(void (*cb)(TimerList*)) { - entry.init(); - function = cb; - data = nullptr; - expires = 0; - } -}; - -extern uint64 g_jiffies; - -void timer_init(); - -// AP per-CPU initialization -void timer_init_ap(); - -// Handle timer interrupt tick (called from TrapHandler) -void timer_tick(); - -// Get configured timebase frequency -uint64 timer_get_freq(); - -void add_timer(TimerList* timer); -int del_timer(TimerList* timer); -int mod_timer(TimerList* timer, uint64 expires); diff --git a/include/lume/tlb.h b/include/lume/tlb.h deleted file mode 100644 index b4d51ea..0000000 --- a/include/lume/tlb.h +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * tlb.h — Machine-Independent TLB management interface - * - * All TLB invalidation in the kernel MUST go through these functions. - * Direct use of arch::mmu::flush_tlb_*() is prohibited outside of - * this file's implementation. - * - * Current implementation: local CPU sfence.vma only (single-core). - * When SMP IPI infrastructure is available, tlb_shootdown_range() - * and tlb_shootdown_all() will broadcast invalidation to remote - * CPUs via IPI — no caller changes required. - * - * Reference: docs/specs/linux_abi_mm_plan.md §4 - */ - -#include - -struct VmSpace; - -/* - * Invalidate TLB entries for a VA range [start, end) on ALL CPUs - * that may have cached translations for the given address space. - * - * @mm: address space (used to determine which CPUs to IPI; - * nullptr means kernel address space = all CPUs). - * @start: first VA to invalidate (page-aligned). - * @end: one-past-last VA to invalidate (page-aligned). - * - * If (end - start) exceeds a threshold, falls back to full flush. - */ -void tlb_shootdown_range(VmSpace* mm, uint64 start, uint64 end); - -/* - * Invalidate a single page's TLB entry on ALL CPUs. - * Convenience wrapper around tlb_shootdown_range(). - */ -void tlb_shootdown_page(VmSpace* mm, uint64 va); - -/* - * Full TLB flush on ALL CPUs. - * Used after page table switch, large-scale munmap, etc. - */ -void tlb_shootdown_all(); diff --git a/include/lume/trap.h b/include/lume/trap.h deleted file mode 100644 index 61a5054..0000000 --- a/include/lume/trap.h +++ /dev/null @@ -1,109 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Trap Subsystem — Machine-Independent Interface - * - * Defines TrapCause enum and MI-layer declarations. - * MD layer (arch/riscv/trap/trap_md.cc) translates scause → TrapCause. - * MI layer (kernel/trap.cc) dispatches based on TrapCause alone. - * - * Reference: docs/specs/trap.md §3.2 - */ - -#include - -/* MI-layer trap cause classification. - * MD layer is responsible for translating architecture-specific cause codes - * (e.g., RISC-V scause) into these semantic values. MI layer never reads CSRs. */ -enum class TrapCause : uint32 { - /* --- Exceptions (Synchronous) --- */ - PageFaultLoad = 0, // Load page fault - PageFaultStore = 1, // Store/AMO page fault - PageFaultExec = 2, // Instruction page fault - Syscall = 3, // User-mode ecall - IllegalInst = 4, // Illegal instruction - Breakpoint = 5, // Breakpoint (ebreak) - AccessFault = 6, // Bus access fault (not page fault) - AlignFault = 7, // Address misalignment - - /* --- Interrupts (Asynchronous) --- */ - IrqTimer = 16, // S-mode timer interrupt - IrqSoftware = 17, // S-mode software interrupt (IPI) - IrqExternal = 18, // S-mode external interrupt (PLIC) - - /* --- Unknown --- */ - Unknown = 255, -}; - -/* High-level trap class for routing and stats. */ -enum class TrapClass : uint8 { - Exception = 0, - Interrupt = 1, - Syscall = 2, - Unknown = 3, -}; - -/* Origin privilege of the trap. */ -enum class TrapOrigin : uint8 { - FromUser = 0, - FromKernel = 1, -}; - -/* Unified trap context passed from MD to MI. */ -struct TrapInfo { - TrapClass cls; - TrapCause cause; - TrapOrigin origin; - uint64 val; // stval (faulting address or instruction) - uint64 epc; // sepc at trap entry (may be adjusted by MD) - uint64 scause; // raw scause for diagnostics -}; - -/* Trap statistics for debugging/testing. */ -inline constexpr uint32 kTrapCauseCount = 12; - -struct TrapStats { - uint64 total; - uint64 by_cause[kTrapCauseCount]; - TrapCause last_cause; - TrapClass last_class; - TrapOrigin last_origin; - uint64 last_val; - uint64 last_epc; - uint64 last_scause; -}; - -namespace arch { -struct TrapFrame; // Forward declaration (defined in arch/trapframe.h) -} - -/* - * trap_init() — BSP initialization - * Sets stvec to kernel_trap_entry (handles traps while in S-mode). - * Initializes the global IrqManager. - * Called from kernel_main() after VMM and before PLIC. - */ -void trap_init(); - -/* - * trap_init_ap() — AP per-CPU initialization - * Sets this CPU's stvec. - */ -void trap_init_ap(); - -/* - * trap_handle() — MI-layer semantic dispatcher - * Called by MD layer after scause → TrapCause translation. - * Routes to page fault handler, syscall dispatcher, IRQ manager, etc. - * - * tf: pointer to the current TrapFrame - * info: translated trap context from MD layer - */ -void trap_handle(arch::TrapFrame* tf, const TrapInfo& info); - -/* Trap statistics helpers (MI layer). */ -void trap_stats_get(TrapStats* out); -void trap_stats_reset(); diff --git a/include/lume/tty.h b/include/lume/tty.h deleted file mode 100644 index 34cf7bb..0000000 --- a/include/lume/tty.h +++ /dev/null @@ -1,165 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * tty.h — TTY subsystem core structures - * - * tty_struct is the central object representing an open terminal. - * It connects a hardware driver (tty_driver) with a line discipline - * (tty_ldisc) to implement the full terminal abstraction. - * - * Architecture: - * user read/write → tty_core → tty_ldisc (n_tty) → tty_driver (uart/pty) - * - * Reference: Linux include/linux/tty.h, include/linux/tty_ldisc.h - */ - -#include -#include -#include -#include - -struct tty_struct; -struct file; -struct file_operations; -struct inode; - -/* ================================================================== */ -/* tty_driver — hardware/pseudo-terminal driver interface */ -/* ================================================================== */ - -struct tty_driver_ops { - int (*open)(tty_struct* tty); - void (*close)(tty_struct* tty); - int (*write)(tty_struct* tty, const char* buf, int count); - int (*write_room)(tty_struct* tty); - void (*put_char)(tty_struct* tty, char ch); - void (*flush_chars)(tty_struct* tty); - int (*chars_in_buffer)(tty_struct* tty); - void (*flush_buffer)(tty_struct* tty); - int (*ioctl)(tty_struct* tty, unsigned int cmd, uint64 arg); - void (*throttle)(tty_struct* tty); - void (*unthrottle)(tty_struct* tty); - void (*hangup)(tty_struct* tty); -}; - -struct tty_driver { - const char* name; /* "ttyS", "ttySIF", "pts" */ - int major; - int minor_start; - int num; /* number of devices */ - const tty_driver_ops* ops; -}; - -/* ================================================================== */ -/* tty_ldisc — line discipline interface */ -/* ================================================================== */ - -struct tty_ldisc_ops { - const char* name; - int num; /* N_TTY = 0 */ - - int (*open)(tty_struct* tty); - void (*close)(tty_struct* tty); - int (*read)(tty_struct* tty, file* fp, char* buf, uint64 count); - int (*write)(tty_struct* tty, file* fp, const char* buf, uint64 count); - void (*receive_buf)(tty_struct* tty, const char* buf, int count); - int (*ioctl)(tty_struct* tty, unsigned int cmd, uint64 arg); - void (*flush_buffer)(tty_struct* tty); - int (*chars_in_buffer)(tty_struct* tty); - void (*set_termios)(tty_struct* tty, const termios* old); - void (*hangup)(tty_struct* tty); -}; - -struct tty_ldisc { - const tty_ldisc_ops* ops; - void* data; /* ldisc private data (n_tty_data*) */ -}; - -/* ================================================================== */ -/* tty_struct — central TTY object */ -/* ================================================================== */ - -inline constexpr int TTY_BUF_SIZE = 4096; - -/* TTY flags */ -inline constexpr uint32 TTY_THROTTLED = (1 << 0); -inline constexpr uint32 TTY_IO_ERROR = (1 << 1); -inline constexpr uint32 TTY_CLOSING = (1 << 2); -inline constexpr uint32 TTY_HUPPING = (1 << 3); - -struct tty_struct { - int index; /* device index */ - const tty_driver* driver; /* hardware driver */ - tty_ldisc ldisc; /* current line discipline */ - tty_struct* link; /* PTY peer (master ↔ slave) */ - - termios termios_data; /* terminal settings */ - winsize ws; /* window size */ - - int32 pgrp; /* foreground process group */ - int32 session; /* controlling session */ - - /* Output buffer (tty_core → driver) */ - char write_buf[TTY_BUF_SIZE]; - int write_cnt; - - /* Synchronization */ - WaitQueue read_wait; - WaitQueue write_wait; - Spinlock lock; - - uint32 flags; - int open_count; - - /* Private driver data */ - void* driver_data; -}; - -/* ================================================================== */ -/* TTY core API */ -/* ================================================================== */ - -/* Initialize the TTY subsystem (creates /dev/console TTY) */ -void tty_init(); - -/* Allocate and initialize a new tty_struct */ -tty_struct* tty_alloc(const tty_driver* driver, int index); - -/* Open/close a TTY (called from chardev open/close) */ -int tty_open(tty_struct* tty); -void tty_close(tty_struct* tty); - -/* Core I/O (called from file_operations) */ -int64 tty_read(tty_struct* tty, file* fp, char* buf, uint64 count); -int64 tty_write(tty_struct* tty, file* fp, const char* buf, uint64 count); -long tty_ioctl(tty_struct* tty, file* fp, unsigned int cmd, uint64 arg); - -/* Called by hardware driver when bytes arrive */ -void tty_receive_buf(tty_struct* tty, const char* buf, int count); - -/* Signal helpers */ -void tty_signal_pgrp(tty_struct* tty, int sig); - -/* file_operations for TTY devices */ -extern file_operations tty_fops; - -/* Global console TTY */ -extern tty_struct* g_console_tty; - -/* ================================================================== */ -/* N_TTY line discipline */ -/* ================================================================== */ - -extern const tty_ldisc_ops n_tty_ops; - -/* ================================================================== */ -/* UART TTY driver */ -/* ================================================================== */ - -extern const tty_driver uart_tty_driver; - -/* Initialize UART as a TTY driver (registers RX IRQ) */ -void uart_tty_init(tty_struct* tty); diff --git a/include/lume/tty_ioctl.h b/include/lume/tty_ioctl.h deleted file mode 100644 index 87ba59b..0000000 --- a/include/lume/tty_ioctl.h +++ /dev/null @@ -1,202 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * tty_ioctl.h — Terminal I/O control constants and structures - * - * Linux-compatible termios, winsize, and TIOC* ioctl definitions. - * Values match the RISC-V/generic Linux ABI. - * - * Reference: include/uapi/asm-generic/termbits.h, - * include/uapi/asm-generic/ioctls.h - */ - -#include - -/* ================================================================== */ -/* termios c_cc indices */ -/* ================================================================== */ - -inline constexpr int VINTR = 0; -inline constexpr int VQUIT = 1; -inline constexpr int VERASE = 2; -inline constexpr int VKILL = 3; -inline constexpr int VEOF = 4; -inline constexpr int VTIME = 5; -inline constexpr int VMIN = 6; -inline constexpr int VSWTC = 7; -inline constexpr int VSTART = 8; -inline constexpr int VSTOP = 9; -inline constexpr int VSUSP = 10; -inline constexpr int VEOL = 11; -inline constexpr int VREPRINT = 12; -inline constexpr int VDISCARD = 13; -inline constexpr int VWERASE = 14; -inline constexpr int VLNEXT = 15; -inline constexpr int VEOL2 = 16; -inline constexpr int NCCS = 19; - -/* ================================================================== */ -/* c_iflag — input mode flags */ -/* ================================================================== */ - -inline constexpr uint32 IGNBRK = 0000001; -inline constexpr uint32 BRKINT = 0000002; -inline constexpr uint32 IGNPAR = 0000004; -inline constexpr uint32 PARMRK = 0000010; -inline constexpr uint32 INPCK = 0000020; -inline constexpr uint32 ISTRIP = 0000040; -inline constexpr uint32 INLCR = 0000100; -inline constexpr uint32 IGNCR = 0000200; -inline constexpr uint32 ICRNL = 0000400; -inline constexpr uint32 IUCLC = 0001000; -inline constexpr uint32 IXON = 0002000; -inline constexpr uint32 IXANY = 0004000; -inline constexpr uint32 IXOFF = 0010000; -inline constexpr uint32 IMAXBEL = 0020000; -inline constexpr uint32 IUTF8 = 0040000; - -/* ================================================================== */ -/* c_oflag — output mode flags */ -/* ================================================================== */ - -inline constexpr uint32 OPOST = 0000001; -inline constexpr uint32 OLCUC = 0000002; -inline constexpr uint32 ONLCR = 0000004; -inline constexpr uint32 OCRNL = 0000010; -inline constexpr uint32 ONOCR = 0000020; -inline constexpr uint32 ONLRET = 0000040; -inline constexpr uint32 OFILL = 0000100; -inline constexpr uint32 OFDEL = 0000200; - -/* ================================================================== */ -/* c_cflag — control mode flags */ -/* ================================================================== */ - -inline constexpr uint32 CSIZE = 0000060; -inline constexpr uint32 CS5 = 0000000; -inline constexpr uint32 CS6 = 0000020; -inline constexpr uint32 CS7 = 0000040; -inline constexpr uint32 CS8 = 0000060; -inline constexpr uint32 CSTOPB = 0000100; -inline constexpr uint32 CREAD = 0000200; -inline constexpr uint32 PARENB = 0000400; -inline constexpr uint32 PARODD = 0001000; -inline constexpr uint32 HUPCL = 0002000; -inline constexpr uint32 CLOCAL = 0004000; - -/* Baud rates (stored in c_cflag masked with CBAUD) */ -inline constexpr uint32 CBAUD = 0010017; -inline constexpr uint32 B0 = 0000000; -inline constexpr uint32 B9600 = 0000015; -inline constexpr uint32 B19200 = 0000016; -inline constexpr uint32 B38400 = 0000017; -inline constexpr uint32 B115200 = 0010002; - -/* ================================================================== */ -/* c_lflag — local mode flags */ -/* ================================================================== */ - -inline constexpr uint32 ISIG = 0000001; -inline constexpr uint32 ICANON = 0000002; -inline constexpr uint32 XCASE = 0000004; -inline constexpr uint32 LECHO = 0000010; /* Named LECHO to avoid macro conflict */ -inline constexpr uint32 ECHOE = 0000020; -inline constexpr uint32 ECHOK = 0000040; -inline constexpr uint32 ECHONL = 0000100; -inline constexpr uint32 NOFLSH = 0000200; -inline constexpr uint32 TOSTOP = 0000400; -inline constexpr uint32 ECHOCTL = 0001000; -inline constexpr uint32 ECHOPRT = 0002000; -inline constexpr uint32 ECHOKE = 0004000; -inline constexpr uint32 IEXTEN = 0100000; - -/* Linux uses ECHO = 0x0008, we use LECHO to avoid reserved-name issues. - * Provide the standard name as well for ioctl compatibility. */ -inline constexpr uint32 ECHO = LECHO; - -/* ================================================================== */ -/* termios structure */ -/* ================================================================== */ - -struct termios { - uint32 c_iflag; /* input mode flags */ - uint32 c_oflag; /* output mode flags */ - uint32 c_cflag; /* control mode flags */ - uint32 c_lflag; /* local mode flags */ - uint8 c_line; /* line discipline */ - uint8 c_cc[NCCS]; /* control characters */ -}; - -/* ================================================================== */ -/* winsize structure */ -/* ================================================================== */ - -struct winsize { - uint16 ws_row; - uint16 ws_col; - uint16 ws_xpixel; - uint16 ws_ypixel; -}; - -/* ================================================================== */ -/* ioctl command numbers (Linux asm-generic/ioctls.h) */ -/* ================================================================== */ - -inline constexpr uint32 TCGETS = 0x5401; -inline constexpr uint32 TCSETS = 0x5402; -inline constexpr uint32 TCSETSW = 0x5403; -inline constexpr uint32 TCSETSF = 0x5404; -inline constexpr uint32 TCGETA = 0x5405; -inline constexpr uint32 TCSETA = 0x5406; -inline constexpr uint32 TCSETAW = 0x5407; -inline constexpr uint32 TCSETAF = 0x5408; -inline constexpr uint32 TCSBRK = 0x5409; -inline constexpr uint32 TCXONC = 0x540A; -inline constexpr uint32 TCFLSH = 0x540B; -inline constexpr uint32 TIOCEXCL = 0x540C; -inline constexpr uint32 TIOCNXCL = 0x540D; -inline constexpr uint32 TIOCSCTTY = 0x540E; -inline constexpr uint32 TIOCGPGRP = 0x540F; -inline constexpr uint32 TIOCSPGRP = 0x5410; -inline constexpr uint32 TIOCOUTQ = 0x5411; -inline constexpr uint32 TIOCSTI = 0x5412; -inline constexpr uint32 TIOCGWINSZ = 0x5413; -inline constexpr uint32 TIOCSWINSZ = 0x5414; -inline constexpr uint32 TIOCMGET = 0x5415; -inline constexpr uint32 TIOCMSET = 0x5418; -inline constexpr uint32 FIONREAD = 0x541B; -inline constexpr uint32 TIOCNOTTY = 0x5422; -inline constexpr uint32 TIOCGPTLCK = 0x80045430; -inline constexpr uint32 TIOCSPTLCK = 0x40045431; - -/* Default termios for a new TTY */ -inline void tty_default_termios(termios* t) -{ - t->c_iflag = ICRNL | IXON | IUTF8; - t->c_oflag = OPOST | ONLCR; - t->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL; - t->c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN; - t->c_line = 0; /* N_TTY */ - - for (int i = 0; i < NCCS; i++) - t->c_cc[i] = 0; - - t->c_cc[VINTR] = 003; /* Ctrl+C */ - t->c_cc[VQUIT] = 034; /* Ctrl+\ */ - t->c_cc[VERASE] = 0177; /* DEL */ - t->c_cc[VKILL] = 025; /* Ctrl+U */ - t->c_cc[VEOF] = 004; /* Ctrl+D */ - t->c_cc[VSTART] = 021; /* Ctrl+Q */ - t->c_cc[VSTOP] = 023; /* Ctrl+S */ - t->c_cc[VSUSP] = 032; /* Ctrl+Z */ - t->c_cc[VREPRINT] = 022; /* Ctrl+R */ - t->c_cc[VWERASE] = 027; /* Ctrl+W */ - t->c_cc[VLNEXT] = 026; /* Ctrl+V */ - t->c_cc[VEOL] = 0; - t->c_cc[VEOL2] = 0; - t->c_cc[VMIN] = 1; - t->c_cc[VTIME] = 0; -} diff --git a/include/lume/types.h b/include/lume/types.h deleted file mode 100644 index 2342359..0000000 --- a/include/lume/types.h +++ /dev/null @@ -1,78 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#ifndef _LUME_TYPES_H -#define _LUME_TYPES_H - -/* - * LumeOS Base Type Definitions - * - * Three naming layers coexist so that source files imported from - * upstream projects (Linux kernel, libfdt) compile unchanged: - * - * LumeOS native uint8 / int8 / ... / uint64 / int64 - * Linux kernel short names u8 / s8 / ... / u64 / s64 - * POSIX / C99 (with _t) uint8_t / ... / uint64_t / intptr_t - * - * All three resolve to the same underlying compiler builtin, so they - * are binary-compatible. - * - * Declared with C `typedef` (not C++ `using`) so this header may be - * included from .c sources — required for libfdt shims and the - * arch/riscv/kernel/pi/ subsystem, which are pure C imports from - * Linux. C++ accepts `typedef` syntax identically. - */ - -/* ===== LumeOS native names ===== */ -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; -typedef unsigned long long uint64; - -typedef signed char int8; -typedef signed short int16; -typedef signed int int32; -typedef signed long long int64; - -typedef __SIZE_TYPE__ size_t; -typedef __PTRDIFF_TYPE__ ptrdiff_t; -typedef int64 ssize_t; -typedef uint64 uintptr; - -/* ===== Linux kernel short names ===== */ -typedef uint8 u8; typedef int8 s8; -typedef uint16 u16; typedef int16 s16; -typedef uint32 u32; typedef int32 s32; -typedef uint64 u64; typedef int64 s64; - -/* ===== POSIX / C99 aliases ===== - * Guarded so a later #include from libc-shim during musl - * userspace builds is a no-op rather than a redefinition error. */ -#ifndef _STDINT_H -# define _STDINT_H -typedef uint8 uint8_t; -typedef uint16 uint16_t; -typedef uint32 uint32_t; -typedef uint64 uint64_t; -typedef int8 int8_t; -typedef int16 int16_t; -typedef int32 int32_t; -typedef int64 int64_t; -typedef uintptr uintptr_t; -typedef int64 intptr_t; -#endif - -/* ===== Linux domain typedefs needed by RISC-V boot path ===== */ -typedef uint64 phys_addr_t; - -/* ===== libfdt on-wire types (big-endian). Real byte-swap helpers - * live in . ===== */ -typedef uint16 fdt16_t; -typedef uint32 fdt32_t; -typedef uint64 fdt64_t; - -#ifndef offsetof -# define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) -#endif - -#endif /* _LUME_TYPES_H */ diff --git a/include/lume/uaccess.h b/include/lume/uaccess.h deleted file mode 100644 index 5a9ed71..0000000 --- a/include/lume/uaccess.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * User-space memory access — safe copy routines. - * - * Phase 2: Software page-table validation. - * Phase 3+: Exception Table (zero-cost happy path). - * - * Reference: docs/specs/syscall.md §8 - */ - -#include - -/* Copy len bytes from user address to kernel buffer. - * Returns 0 on success, -EFAULT if user address is invalid. */ -int copy_from_user(void* kernel_dst, uint64 user_src, uint64 len); - -/* Copy len bytes from kernel buffer to user address. - * Returns 0 on success, -EFAULT if user address is invalid. */ -int copy_to_user(uint64 user_dst, const void* kernel_src, uint64 len); - -/* Copy NUL-terminated string from user space. - * Returns string length (excluding NUL) or -EFAULT. */ -int64 strncpy_from_user(char* kernel_dst, uint64 user_src, uint64 max_len); diff --git a/include/lume/uuid.h b/include/lume/uuid.h deleted file mode 100644 index fcbd4a3..0000000 --- a/include/lume/uuid.h +++ /dev/null @@ -1,207 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * UUID/GUID definition - * - * Copyright (C) 2010, 2016 Intel Corp. - * Huang Ying - */ - -#pragma once - -#include -#include - -constexpr uint32 UUID_SIZE = 16; -constexpr uint32 UUID_STRING_LEN = 36; - -static inline int uuid_hex_value(char c) -{ - if (c >= '0' && c <= '9') { - return c - '0'; - } - if (c >= 'a' && c <= 'f') { - return c - 'a' + 10; - } - if (c >= 'A' && c <= 'F') { - return c - 'A' + 10; - } - return -1; -} - -static inline bool uuid_parse_raw(const char* uuid, uint8 out[UUID_SIZE]) -{ - if (!uuid) { - return false; - } - if (strlen(uuid) != UUID_STRING_LEN) { - return false; - } - if (uuid[8] != '-' || uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-') { - return false; - } - - int out_index = 0; - for (int i = 0; i < static_cast(UUID_STRING_LEN); ) { - if (uuid[i] == '-') { - ++i; - continue; - } - - int hi = uuid_hex_value(uuid[i]); - int lo = uuid_hex_value(uuid[i + 1]); - if (hi < 0 || lo < 0) { - return false; - } - - out[out_index++] = static_cast((hi << 4) | lo); - i += 2; - } - - return out_index == static_cast(UUID_SIZE); -} - -struct uuid_base { - uint8 b[UUID_SIZE]; - - bool is_null() const - { - for (uint32 i = 0; i < UUID_SIZE; ++i) { - if (b[i] != 0) { - return false; - } - } - return true; - } - - bool operator==(const uuid_base& other) const - { - return memcmp(b, other.b, UUID_SIZE) == 0; - } - - bool operator!=(const uuid_base& other) const - { - return !(*this == other); - } -}; - -struct uuid_t : public uuid_base { - explicit uuid_t(const uint8 in_b[UUID_SIZE]) - { - memcpy(b, in_b, UUID_SIZE); - } - - explicit constexpr uuid_t(uint32 a, uint16 b, uint16 c, uint8 d0, uint8 d1, - uint8 d2, uint8 d3, uint8 d4, uint8 d5, - uint8 d6, uint8 d7) - : uuid_base{{ - static_cast((a >> 24) & 0xff), - static_cast((a >> 16) & 0xff), - static_cast((a >> 8) & 0xff), - static_cast(a & 0xff), - static_cast((b >> 8) & 0xff), - static_cast(b & 0xff), - static_cast((c >> 8) & 0xff), - static_cast(c & 0xff), - d0, d1, d2, d3, d4, d5, d6, d7 - }} - { - } - - constexpr uuid_t() : uuid_base{{0}} {} - - static bool parse(const char* uuid, uuid_t& out) - { - uint8 tmp[UUID_SIZE]; - if (!uuid_parse_raw(uuid, tmp)) { - return false; - } - - memcpy(out.b, tmp, UUID_SIZE); - return true; - } - - static bool is_valid(const char* uuid) - { - uint8 tmp[UUID_SIZE]; - return uuid_parse_raw(uuid, tmp); - } - - static constexpr uuid_t null() - { - return uuid_t(); - } - - void import_bytes(const uint8* src) - { - memcpy(b, src, UUID_SIZE); - } - - void export_bytes(uint8* dst) const - { - memcpy(dst, b, UUID_SIZE); - } -}; - -struct guid_t : public uuid_base { - explicit guid_t(const uint8 in_b[UUID_SIZE]) - { - memcpy(b, in_b, UUID_SIZE); - } - - explicit constexpr guid_t(uint32 a, uint16 b, uint16 c, uint8 d0, uint8 d1, - uint8 d2, uint8 d3, uint8 d4, uint8 d5, - uint8 d6, uint8 d7) - : uuid_base{{ - static_cast(a & 0xff), - static_cast((a >> 8) & 0xff), - static_cast((a >> 16) & 0xff), - static_cast((a >> 24) & 0xff), - static_cast(b & 0xff), - static_cast((b >> 8) & 0xff), - static_cast(c & 0xff), - static_cast((c >> 8) & 0xff), - d0, d1, d2, d3, d4, d5, d6, d7 - }} - { - } - - constexpr guid_t() : uuid_base{{0}} {} - static bool parse(const char* uuid, guid_t& out) - { - uint8 tmp[UUID_SIZE]; - if (!uuid_parse_raw(uuid, tmp)) { - return false; - } - - static constexpr uint8 guid_index[UUID_SIZE] = { - 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15, - }; - - for (int i = 0; i < static_cast(UUID_SIZE); ++i) { - out.b[guid_index[i]] = tmp[i]; - } - return true; - } - - static bool is_valid(const char* uuid) - { - uint8 tmp[UUID_SIZE]; - return uuid_parse_raw(uuid, tmp); - } - - static constexpr guid_t null() - { - return guid_t(); - } - - void import_bytes(const uint8* src) - { - memcpy(b, src, UUID_SIZE); - } - - void export_bytes(uint8* dst) const - { - memcpy(dst, b, UUID_SIZE); - } -}; - diff --git a/include/lume/vmm.h b/include/lume/vmm.h deleted file mode 100644 index 9cbebf1..0000000 --- a/include/lume/vmm.h +++ /dev/null @@ -1,115 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * vmm.h — Virtual Memory Manager - * - * Managing kernel and user virtual address spaces. - * - * Reference: docs/specs/vmm.md - */ - -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* MI-layer permission flags (architecture-independent) */ -/* */ -/* These are used by VMA and vmm_map_user / vmm_handle_page_fault. */ -/* The pmap MD layer translates them to hardware PTE bits. */ -/* ------------------------------------------------------------------ */ -inline constexpr uint64 VM_READ = (1ULL << 0); -inline constexpr uint64 VM_WRITE = (1ULL << 1); -inline constexpr uint64 VM_EXEC = (1ULL << 2); -inline constexpr uint64 VM_USER = (1ULL << 3); - -enum class VmFaultCause : uint8 { - Read = 0, - Write = 1, - Exec = 2, -}; - -/* Forward declarations */ -struct VmSpace; -struct VmAreaStruct; - -/* - * Virtual Memory Area (VMA) - * Represents a contiguous range [start, end) of uniform permissions. - */ -struct VmAreaStruct { - uint64 start; // Start VA (page aligned) - uint64 end; // End VA (exclusive, page aligned) - uint64 perm; // VM_READ | VM_WRITE | VM_EXEC | VM_USER - struct rb_node rb; // Linkage in VmSpace::vma_tree - VmSpace* mm; // Back pointer to the parent address space -}; - -/* - * Address Space (VmSpace) - * Represents a user process's complete virtual memory mapping. - * - * Lock contract: - * Holds: lock (internal spinlock) - * May acquire: PMM global lock (via pmm_alloc_page inside page fault) - * Callers must NOT hold: PMM lock (lock ordering: VmSpace -> PMM) - */ -struct VmSpace { - uint64 root_pa; // SV39 root page table physical address - struct rb_root vma_tree; // Red-black tree of VmAreaStructs - Spinlock lock; // Protects vma_tree mutations - lume::atomic refcount; // Reference count (for CLONE_VM sharing) - lume::atomic cpu_mask; // Bitmask of CPUs with this mm in satp - - uint64 brk_start; // Start of heap (page-aligned) - uint64 brk_end; // Current heap end (page-aligned) - uint64 mmap_base; // Base for mmap (Linux: TASK_UNMAPPED_BASE = TASK_SIZE/3) - - // Create a brand new VmSpace (allocates root pagetable, refcount=1) - static VmSpace* create(); - - // Increment reference count (for CLONE_VM) - void incref(); - - // Decrement reference count; destroys VmSpace when it reaches 0. - // Call this instead of destroy() directly. - void put(); - - // Destroy VmSpace, unmapping all VMAs and freeing pagetables. - // Internal — called by put() when refcount drops to 0. - void destroy(); -}; - -/* Initialize kernel page table (Phase 1) */ -void vmm_init(); - -/* Switch AP to the kernel page table built by BSP (Phase 1) */ -void vmm_init_ap(); - -/* Map MMIO device region to the active kernel page table */ -void vmm_map_kernel_mmio(uint64 pa, uint64 size); - -/* Query page_map allocation (set by vmm_init, read by pmm_init). - * Returns the PA, byte size, and page count of the vmemmap region. */ -uint64 vmm_get_page_map_pa(); -uint64 vmm_get_page_map_size(); -uint64 vmm_get_num_pages(); - -/* User space memory management (VMA & Demand Paging) */ -int vmm_map_user(VmSpace* space, uint64 va, uint64 len, uint64 perm); -int vmm_unmap_user(VmSpace* space, uint64 va, uint64 len); -int vmm_protect_user(VmSpace* space, uint64 va, uint64 len, uint64 perm); - -/* VMA helpers for mmap/mprotect implementations */ -uint64 mm_find_free_va(VmSpace* space, uint64 length, uint64 align); -bool vma_range_covered(VmSpace* space, uint64 start, uint64 end); - -/* Handle user page fault (lookup VMA -> allocate page -> map) */ -int vmm_handle_page_fault(VmSpace* space, uint64 fault_addr, VmFaultCause cause); - -/* Clone an address space for fork() */ -VmSpace* vmm_clone(VmSpace* parent_space); diff --git a/include/lume/wait.h b/include/lume/wait.h deleted file mode 100644 index 865c1f2..0000000 --- a/include/lume/wait.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * POSIX waitpid / wait4 Constants - * Reference: docs/specs/syscall.md §9 - */ - -/* waitpid options */ -inline constexpr int WNOHANG = 1; -inline constexpr int WUNTRACED = 2; -inline constexpr int WCONTINUED = 8; -inline constexpr int WSTOPPED = WUNTRACED; /* POSIX alias */ -inline constexpr int WEXITED = 4; /* POSIX */ -inline constexpr int WNOWAIT = 0x01000000; /* POSIX: peek, don't reap */ - -/* Exit status encoding (Linux-compatible) */ -static inline int WEXITSTATUS(int s) { return (s >> 8) & 0xFF; } -static inline bool WIFEXITED(int s) { return (s & 0x7F) == 0; } -static inline bool WIFSIGNALED(int s) { return (s & 0x7F) != 0 && (s & 0x7F) != 0x7F; } -static inline int WTERMSIG(int s) { return s & 0x7F; } -static inline bool WIFSTOPPED(int s) { return (s & 0xFF) == 0x7F; } -static inline int WSTOPSIG(int s) { return (s >> 8) & 0xFF; } -static inline bool WIFCONTINUED(int s){ return s == 0xFFFF; } - -/* Encode exit code into wstatus (normal exit) */ -static inline int W_EXITCODE(int code) { return (code & 0xFF) << 8; } -static inline int W_STOPCODE(int sig) { return ((sig & 0xFF) << 8) | 0x7F; } -static inline int W_CONTINUED() { return 0xFFFF; } diff --git a/include/lume/waitqueue.h b/include/lume/waitqueue.h deleted file mode 100644 index 3720cb7..0000000 --- a/include/lume/waitqueue.h +++ /dev/null @@ -1,79 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * WaitQueue — blocking synchronization primitive - * - * Supports two usage patterns: - * - * 1. Simple (legacy): wq.sleep() — combines prepare/schedule/finish. - * Suitable for simple cases where no external condition is checked. - * - * 2. Linux-style two-phase (recommended for correctness): - * - * wq.prepare_to_wait(curr, TaskState::Sleeping); - * if (!condition) { - * schedule(); - * } - * wq.finish_wait(curr); - * - * This pattern prevents the "lost wakeup" race: the task is already - * on the wait list (and marked Sleeping) BEFORE checking the condition. - * If a wake_one/wake_all fires between the check and schedule(), the - * task's state will already be set back to Runnable, and schedule() - * will see state == Runnable and simply re-run the task. - * - * Reference: docs/specs/scheduler.md, docs/specs/task.md §5 - */ - -#include -#include -#include - -struct TaskControlBlock; -enum class TaskState : uint8; - -class WaitQueue { -public: - void init(const char* name = "wq") { - head_.init(); - lock_.init(name); - } - - /* - * Phase 1: Add the task to the wait queue and set its state. - * The task is NOT yet descheduled — the caller must check the - * condition and call schedule() if the condition is still false. - * - * Must be called with interrupts disabled or preemption disabled. - */ - void prepare_to_wait(TaskControlBlock* task, TaskState new_state); - - /* - * Phase 3: Remove the task from the wait queue (if still on it) - * and ensure its state is Runnable. Called after schedule() returns - * (i.e. after the task has been woken up, or if the condition was - * true and schedule() was skipped). - */ - void finish_wait(TaskControlBlock* task); - - /* Legacy convenience: combines prepare_to_wait + schedule + finish_wait. - * If external_lock is provided, it is released AFTER the task is - * added to the wait queue but BEFORE schedule() is called. */ - void sleep(Spinlock* external_lock = nullptr); - - /* Wake the first (oldest) sleeping task. Returns true if a task was woken. */ - bool wake_one(); - - /* Wake all sleeping tasks. Returns the number of tasks woken. */ - int wake_all(); - - /* Check if any tasks are waiting. */ - bool is_empty() const { return head_.is_empty(); } - -private: - list_node head_; - Spinlock lock_; -}; diff --git a/include/zircon/LICENSE b/include/zircon/LICENSE deleted file mode 100644 index 7ed244f..0000000 --- a/include/zircon/LICENSE +++ /dev/null @@ -1,24 +0,0 @@ -Copyright 2019 The Fuchsia Authors. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/include/zircon/README.lume b/include/zircon/README.lume deleted file mode 100644 index 41e610f..0000000 --- a/include/zircon/README.lume +++ /dev/null @@ -1,11 +0,0 @@ -Zircon public support headers required by the first kernel library batch - -Fuchsia revision: f8d670ab4bbb71bfb4d569893ba12fbb8a83bacd - -Imported files: - zircon/system/public/zircon/compiler.h - sdk/lib/zircon-assert/zircon/assert.h - -The assert header is a regular-file copy of the SDK target. The corresponding -path under zircon/system/public is a Fuchsia-tree-relative symbolic link and -is deliberately not reproduced as a broken link. diff --git a/include/zircon/assert.h b/include/zircon/assert.h deleted file mode 100644 index 47f8c4d..0000000 --- a/include/zircon/assert.h +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2016 The Fuchsia Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef LIB_ZIRCON_ASSERT_ZIRCON_ASSERT_H_ -#define LIB_ZIRCON_ASSERT_ZIRCON_ASSERT_H_ - -// For a description of which asserts are enabled at which debug levels, see the documentation for -// GN build argument |assert_level|. - -#ifdef _KERNEL -#include -#define ZX_PANIC(args...) PANIC(args) -#define ZX_ASSERT(args...) ASSERT(args) -#define ZX_ASSERT_MSG(args...) ASSERT_MSG(args) -#define ZX_DEBUG_ASSERT(args...) DEBUG_ASSERT(args) -#define ZX_DEBUG_ASSERT_MSG(args...) DEBUG_ASSERT_MSG(args) -#define ZX_DEBUG_ASSERT_COND(args...) DEBUG_ASSERT_COND(args) -#define ZX_DEBUG_ASSERT_MSG_COND(args...) DEBUG_ASSERT_MSG_COND(args) -#define ZX_DEBUG_ASSERT_IMPLEMENTED DEBUG_ASSERT_IMPLEMENTED - -#else // #ifdef _KERNEL - -#include - -__BEGIN_CDECLS -// NOLINTNEXTLINE(bugprone-reserved-identifier) -void __zx_panic(const char* format, ...) __NO_RETURN __PRINTFLIKE(1, 2); -__END_CDECLS - -#define ZX_PANIC(fmt, ...) __zx_panic((fmt), ##__VA_ARGS__) - -// Conditionally implement ZX_DEBUG_ASSERT based on ZX_ASSERT_LEVEL. -// -// ZX_DEBUG_ASSERT_IMPLEMENTED is intended to be used to conditionalize code -// that is logically part of a debug assert. It's useful for performing complex -// consistency checks that are difficult to work into a ZX_DEBUG_ASSERT -// statement. -#ifdef ZX_ASSERT_LEVEL -#define ZX_DEBUG_ASSERT_IMPLEMENTED (ZX_ASSERT_LEVEL > 1) -#else -#define ZX_DEBUG_ASSERT_IMPLEMENTED 0 -#endif - -// Notes about the C++ and C versions of the assert macros. -// -// The C++ versions of these macros follow a very specific form for testing the -// assert predicate `x`. Specifically, the test of the predicate is _always_ -// written simply as `if (x)`. Not: -// -// 1) `if (!x)` // or -// 2) `if ((x))` // or -// 3) `if (unlikely(!(x))) // or -// 4) `if (ZX_DEBUG_ASSERT_ENABLED && unlikely(!(x))) // or, anything else. -// -// It is *always* just `if (x)`. There is a method to this madness. The -// primary reason for this is to catch mistakes of the following form: -// -// ZX_DEBUG_ASSERT(my_bool_variable = false); -// ZX_ASSERT(my_int_variable = 5); -// -// Both of these are examples of a pattern where a code author meant to use -// comparison (`==`), but accidentally used assignment (`=`), meaning that the -// first of these examples is always going to fire, while the second will never -// fire. Both of them will have a side effect of mutating their variable, but a -// ZX_DEBUG_ASSERT's mutation will drop out of a release build. -// -// :: Accidental Assignment Protection :: -// -// This is all very bad, and _should_ be caught by the -Wparentheses warning, -// when enabled (which it usually is). Unfortunately, surrounding an assignment -// operation in a set of `()` will suppress the warning. Pretty much any other -// form of the predicate test ends up requiring that we add in an extra pair of -// `()`. This also includes wrapping the predicate in things like `unlikely(x)` -// and `likely(x)`. So, we have to restrict ourselves strictly to testing with -// `if (x)` in order to get the accidental assignment protection we desire. -// -// :: Temporary Variable Latching :: -// -// A surprise advantage to taking this approach is that it allows us (in C++) to -// more easily write predicates which involve latching to a temporary variable. -// Consider a case where we want to debug assert something about a value -// returned by a function which is expensive to call. We could write: -// -// DEBUG_ASSERT_MSG(Expensive() == 5, -// "Expensive() returned a non-five value (%u)", -// Expensive()); -// -// But now we are calling the expensive function twice. We could also say: -// -// [[maybe_unused]] const uint32_t e = Expensive(); -// ZX_DEBUG_ASSERT_MSG(e, "Expensive() returned a non-five value (%u)", e); -// -// but it takes a couple of lines, we have to add in a [[maybe_unused]] -// annotation, and we may still be forced to evaluate Expensive if the compiler -// cannot tell that it is guaranteed to have no side effects. -// -// With the new only-`if (x)` form of testing the predicate, however, we can do -// better. Now, we can write: -// -// ZX_DEBUG_ASSERT_MSG(const uint32_t e = Expensive(); e == 5, -// "Expensive() returned a non-five value (%u)", e); -// -// We still get our protection against accidental assignment, we are guaranteed -// to evaluate Expensive exactly once in a debug build, and zero times in a -// release build. -// -// :: WARNING - C code does not get these benefits :: -// -// To write in this style, but also preserve the likely/unlikely hinting -// benefits, we are forced to use C++'s standardized attributes `[[likely]]` and -// `[[unlikely]]``. These are not available in C, which has to use the old -// compiler attribute macros, which always end up introducing `()`, and -// suppressing the accidental assignment protection. Right now, there is no -// good way around this, and as long as we are building C code using this -// header, we will need to maintain a version of these macros which do not offer -// the same level of protection. -// -#ifdef __cplusplus - -// Only use the [[likely]] attribute if we are sure the compiler is going to -// understand it. -#if defined(__has_cpp_attribute) && (__has_cpp_attribute(likely) >= 201803L) -// NOLINTNEXTLINE(bugprone-reserved-identifier) -#define _ZIRCON_ASSERT_ATTRIBUTE_LIKELY [[likely]] -#else -// NOLINTNEXTLINE(bugprone-reserved-identifier) -#define _ZIRCON_ASSERT_ATTRIBUTE_LIKELY -#endif - -// Assert that |x| is true, else panic. -// -// ZX_ASSERT is always enabled and |x| will be evaluated regardless of any build arguments. -#define ZX_ASSERT(x) \ - do { \ - if (x) \ - _ZIRCON_ASSERT_ATTRIBUTE_LIKELY { break; } \ - else { /* NOLINT(readability-else-after-return) */ \ - ZX_PANIC("ASSERT FAILED at (%s:%d): %s", __FILE__, __LINE__, #x); \ - } \ - } while (0) - -// Assert that |x| is true, else panic with the given message. -// -// ZX_ASSERT_MSG is always enabled and |x| will be evaluated regardless of any build arguments. -#define ZX_ASSERT_MSG(x, msg, msgargs...) \ - do { \ - if (x) \ - _ZIRCON_ASSERT_ATTRIBUTE_LIKELY { break; } \ - else { \ - ZX_PANIC("ASSERT FAILED at (%s:%d): %s" msg, __FILE__, __LINE__, #x, ##msgargs); \ - } \ - } while (0) - -// Assert that |x| is true, else panic. -// -// Depending on build arguments, ZX_DEBUG_ASSERT may or may not be enabled. When disabled, |x| will -// not be evaluated. -#define ZX_DEBUG_ASSERT(x) \ - do { \ - if (ZX_DEBUG_ASSERT_IMPLEMENTED) { \ - if (x) \ - _ZIRCON_ASSERT_ATTRIBUTE_LIKELY { break; } \ - else { \ - ZX_PANIC("DEBUG ASSERT FAILED at (%s:%d): %s", __FILE__, __LINE__, #x); \ - } \ - } \ - } while (0) - -// Assert that |x| is true, else panic with the given message. -// -// Depending on build arguments, ZX_DEBUG_ASSERT_MSG may or may not be enabled. When disabled, |x| -// will not be evaluated. -#define ZX_DEBUG_ASSERT_MSG(x, msg, msgargs...) \ - do { \ - if (ZX_DEBUG_ASSERT_IMPLEMENTED) { \ - if (x) \ - _ZIRCON_ASSERT_ATTRIBUTE_LIKELY { break; } \ - else { \ - ZX_PANIC("DEBUG ASSERT FAILED at (%s:%d): %s" msg, __FILE__, __LINE__, #x, ##msgargs); \ - } \ - } \ - } while (0) - -#else // #ifdef __cplusplus - -// Assert that |x| is true, else panic. -// -// ZX_ASSERT is always enabled and |x| will be evaluated regardless of any build arguments. -#define ZX_ASSERT(x) \ - do { \ - if (unlikely(!(x))) { \ - ZX_PANIC("ASSERT FAILED at (%s:%d): %s", __FILE__, __LINE__, #x); \ - } \ - } while (0) - -// Assert that |x| is true, else panic with the given message. -// -// ZX_ASSERT_MSG is always enabled and |x| will be evaluated regardless of any build arguments. -#define ZX_ASSERT_MSG(x, msg, msgargs...) \ - do { \ - if (unlikely(!(x))) { \ - ZX_PANIC("ASSERT FAILED at (%s:%d): %s" msg, __FILE__, __LINE__, #x, ##msgargs); \ - } \ - } while (0) - -// Assert that |x| is true, else panic. -// -// Depending on build arguments, ZX_DEBUG_ASSERT may or may not be enabled. When disabled, |x| will -// not be evaluated. -#define ZX_DEBUG_ASSERT(x) \ - do { \ - if (ZX_DEBUG_ASSERT_IMPLEMENTED && unlikely(!(x))) { \ - ZX_PANIC("DEBUG ASSERT FAILED at (%s:%d): %s", __FILE__, __LINE__, #x); \ - } \ - } while (0) - -// Assert that |x| is true, else panic with the given message. -// -// Depending on build arguments, ZX_DEBUG_ASSERT_MSG may or may not be enabled. When disabled, |x| -// will not be evaluated. -#define ZX_DEBUG_ASSERT_MSG(x, msg, msgargs...) \ - do { \ - if (ZX_DEBUG_ASSERT_IMPLEMENTED && unlikely(!(x))) { \ - ZX_PANIC("DEBUG ASSERT FAILED at (%s:%d): %s" msg, __FILE__, __LINE__, #x, ##msgargs); \ - } \ - } while (0) - -#endif // #ifdef __cplusplus - // -// implement _COND versions of ZX_DEBUG_ASSERT which only emit the body if -// ZX_DEBUG_ASSERT_IMPLEMENTED is set -#if ZX_DEBUG_ASSERT_IMPLEMENTED -#define ZX_DEBUG_ASSERT_COND(x) ZX_DEBUG_ASSERT(x) -#define ZX_DEBUG_ASSERT_MSG_COND(x, msg, msgargs...) ZX_DEBUG_ASSERT_MSG(x, msg, msgargs) -#else -#define ZX_DEBUG_ASSERT_COND(x) \ - do { \ - } while (0) -#define ZX_DEBUG_ASSERT_MSG_COND(x, msg, msgargs...) \ - do { \ - } while (0) -#endif - -#endif // #ifdef _KERNEL -#endif // LIB_ZIRCON_ASSERT_ZIRCON_ASSERT_H_ diff --git a/include/zircon/compiler.h b/include/zircon/compiler.h deleted file mode 100644 index 45ea8d6..0000000 --- a/include/zircon/compiler.h +++ /dev/null @@ -1,380 +0,0 @@ -// Copyright 2016 The Fuchsia Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file provides macros for unifying differences in C/C++ compiler -// extensions, and providing backwards-compatibility for older C++ standards. -// -// May be included by C, C++, and assembly files. - -#ifndef ZIRCON_COMPILER_H_ -#define ZIRCON_COMPILER_H_ - -// Ensure we are using a known compiler. -#if !defined(__GNUC__) && !defined(__clang__) -#error "Unrecognized compiler!" -#endif - -// Feature checking macros. -// -// If feature checking macros are not provided by the compiler, we assume that the -// checked features are unavailable. - -// C++11 attribute checking. -#ifndef __has_cpp_attribute -#define __has_cpp_attribute(x) 0 -#endif - -// clang feature checking. -#ifndef __has_feature -#define __has_feature(x) 0 -#endif - -#if !defined(__ASSEMBLER__) - -// C++ header guards. -#ifdef __cplusplus -#define __BEGIN_CDECLS extern "C" { -#define __END_CDECLS } -#else -#define __BEGIN_CDECLS -#define __END_CDECLS -#endif - -// -// Function and data attributes. -// - -// Function inlining directives. -#define __NO_INLINE __attribute__((__noinline__)) -#define __ALWAYS_INLINE __attribute__((__always_inline__)) - -// Avoid issuing a warning if the given variable/function is unused. -#ifndef __cplusplus -#define __UNUSED __attribute__((__unused__)) -#endif - -// Pack the given structure or class, omitting padding between fields. -#define __PACKED __attribute__((packed)) - -// Place the variable in thread-local storage. -#define __THREAD __thread - -// Align the variable or type to at least `x` bytes. `x` must be a power of two. -#define __ALIGNED(x) __attribute__((aligned(x))) - -// Declare the given function will never return. (such as `exit`, `abort`, etc). -#define __NO_RETURN __attribute__((__noreturn__)) - -// Warn if the result of this function is ignored by the caller. -#define __WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) - -// Declare that the given stack variable may be left uninitialized if it does -// not have a specified initial value. -#if defined(__clang__) -#define __UNINITIALIZED __attribute__((uninitialized)) -#else -#define __UNINITIALIZED -#endif - -// Warn if a constructed objected is not used by the caller. -// -// Generates a warning on code like this: -// -// { -// AutoLock(&mutex); // error: the AutoLock goes out of scope immediately. -// locked_variable = 42; -// } -// -// C++17 defines [[nodiscard]] to do this, but some older but supported -// versions of GCC support [[nodiscard]] on functions but not constructors. -// Having a separate __WARN_UNUSED_CONSTRUCTOR allows us to hide the attribute -// only on constructors on old versions of GCC. -#if defined(__cplusplus) -#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 10)) -#define __WARN_UNUSED_CONSTRUCTOR [[nodiscard]] -#else -#define __WARN_UNUSED_CONSTRUCTOR -#endif -#endif - -// Mark a function or variable as deprecated, warning about any callers. -#if !defined(__DEPRECATE) -#define __DEPRECATE __attribute__((__deprecated__)) -#endif - -// Mark a function as having no visible side-effects: It may read memory, but -// will not modify it. -// -// Multiple calls to the function may be optimized away by the compiler. -#define __PURE __attribute__((__pure__)) - -// Mark a function has having an output determined solely on its input -// parameters (but not memory). -// -// Multiple calls to the function may be optimized away by the compiler, even -// if memory is modified between calls. -#define __CONST __attribute__((__const__)) - -// The given function is malloc-like, returning a pointer to new, unused -// memory. -// -// The compiler can assume that the returned pointer does not alias any other -// pointer, which may help the compiler optimize the program. -#define __MALLOC __attribute__((__malloc__)) - -// The given function allocates memory of size argument |x| or |x| * |y| and returns -// a pointer to that memory. Argument indexes are one-based. The compiler can use this -// information to support compile-time __builtin_object_size checks. -#if defined(__clang__) -#define __ALLOC_SIZE(x, ...) __attribute__((__alloc_size__(x, ##__VA_ARGS__))) -#else -// TODO(fxrev.dev/571541): GCC warns incorrectly on constructs that could result in -// large allocations for type reasons but cannot for other (checked) reasons. Disable -// the attribute there. -#define __ALLOC_SIZE(x, ...) -#endif - -// Indicate that the given function takes a printf/scanf-style format string. -// -// "__fmt" is the argument number of the format string, indexed from 1. -// "__varargs" is the argument number of the variable args "..." argument -// counting from 1. -// -// If applied to a class method, the implicit "this" parameter counts as the -// first argument. -#define __PRINTFLIKE(__fmt, __varargs) __attribute__((__format__(__printf__, __fmt, __varargs))) -#define __SCANFLIKE(__fmt, __varargs) __attribute__((__format__(__scanf__, __fmt, __varargs))) - -// Indicate that the `n`th argument to a function is non-null. -// -// The compiler will emit warnings if it can prove an argument is null, and -// may optimise assuming that the values are non-null. -#define __NONNULL(n) __attribute__((__nonnull__ n)) - -// The given function is a "leaf", and won't call further functions. -// -// Leaf functions must only return directly, and not call back into the -// current compilation unit (either via direct calls, or function pointers). -// -// May help the compiler optimize calls to the function in some cases. -#define __LEAF_FN __attribute__((__leaf__)) - -// Mark the given function or variable as `constexpr`. -// -// Used in code included by both C and C++. Code that is pure C++ should use -// `constexpr` directly. -#ifdef __cplusplus -#define __CONSTEXPR constexpr -#else -#define __CONSTEXPR -#endif - -// Optimize the given function using custom flags. -// -// For example, -// -// __OPTIMIZE("O3") int myfunction() { ... } -// -// will cause GCC to optimize the function at the O3 level, independent -// of what the compiler optimization flags are. -#if !defined(__clang__) -#define __OPTIMIZE(x) __attribute__((__optimize__(x))) -#else -#define __OPTIMIZE(x) -#endif - -// Indicate the given function should not use LLVM's stack hardening features, -// but instead put all local variables on the standard stack. -// -// c.f. https://clang.llvm.org/docs/SafeStack.html -#if defined(__clang__) -#define __NO_SAFESTACK __attribute__((__no_sanitize__("safe-stack", "shadow-call-stack"))) -#else -#define __NO_SAFESTACK -#endif - -// The given C++ class or struct need not have a unique address when part of -// a larger struct or class, but can be safely collapsed into a zero-byte -// object by the compiler. -#if __has_cpp_attribute(no_unique_address) -#define __NO_UNIQUE_ADDRESS [[no_unique_address]] -#elif __has_cpp_attribute(msvc::no_unique_address) -// msvc targets, as used by efi, have a different attribute name, even when -// targeting C++20. -#define __NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -#else -#define __NO_UNIQUE_ADDRESS -#endif - -// Indicate that the given function should be treated by the Clang static -// analyzer as if it doesn't return. -// -// A workaround to help static analyzer identify assertion failures -#if defined(__clang__) -#define __ANALYZER_CREATE_SINK __attribute__((analyzer_noreturn)) -#else -#define __ANALYZER_CREATE_SINK -#endif - -// Mark the given function as externally visible, and shouldn't be optimized -// away by link-time optimizations or whole-program optimizations. -#if !defined(__clang__) -#define __EXTERNALLY_VISIBLE __attribute__((__externally_visible__)) -#else -#define __EXTERNALLY_VISIBLE -#endif - -// Declare that this function declaration should be emitted as an alias for -// another function. -#define __ALIAS(x) __attribute__((__alias__(x))) - -// Place the given global into a particular linker section. -#define __SECTION(x) __attribute__((__section__(x))) - -// The given function or global should be given a weak symbol, or a weak -// alias to another symbol. -#define __WEAK __attribute__((__weak__)) -#define __WEAK_ALIAS(x) __attribute__((__weak__, __alias__(x))) - -// The given static variable should still be emitted by the compiler, even if it -// appears unused to the compiler. -// -// Rarely needed. Not to be confused with "__UNUSED", which avoids the -// compiler warning if a variable appears unused. -#define __ALWAYS_EMIT __attribute__((__used__)) - -// Declare this object's ELF symbol visibility. -#define __EXPORT __attribute__((__visibility__("default"))) -#define __LOCAL __attribute__((__visibility__("hidden"))) - -// -// Builtin functions. -// - -// Provide a hint to the compiler that the given expression is likely/unlikely -// to be true. -// -// if (unlikely(status != ZX_OK)) { -// error(...); -// } -// -#ifndef likely -#define likely(x) __builtin_expect(!!(x), 1) -#endif - -#ifndef unlikely -#define unlikely(x) __builtin_expect(!!(x), 0) -#endif - -// Return the program counter of the calling function. -#define __GET_CALLER(x) __builtin_return_address(0) - -// Return the address of the current stack frame. -#define __GET_FRAME(x) __builtin_frame_address(0) - -// Return true if the given expression is a known compile-time constant. -#define __ISCONSTANT(x) __builtin_constant_p(x) - -// Assume this branch of code cannot be reached. -#define __UNREACHABLE __builtin_unreachable() - -// Get the offset of `field` from the beginning of the struct or class `type`. -#define __offsetof(type, field) __builtin_offsetof(type, field) - -// Perform an arithmetic operation, returning "true" if the operation overflowed. -// -// Equivalent to: { *result = a + b; return _overflow_occurred; } -#define add_overflow(a, b, result) __builtin_add_overflow(a, b, result) -#define sub_overflow(a, b, result) __builtin_sub_overflow(a, b, result) -#define mul_overflow(a, b, result) __builtin_mul_overflow(a, b, result) - -// Indicate the given case of a switch statement is intended to fall through -// to the next case, and avoid generating a compiler warning. -// -// switch (n) { -// case 0: -// case 1: -// handle_zero_and_one_case(); -// __FALLTHROUGH; -// default: -// handle_all_cases(); -// break; -// } -// -#if defined(__cplusplus) -#define __FALLTHROUGH [[fallthrough]] -#elif defined(__cplusplus) && defined(__clang__) -#define __FALLTHROUGH [[clang::fallthrough]] -// The GNU style attribute is supported by Clang for C code, but __GNUC__ for -// clang right now is 4. -#elif __GNUC__ >= 7 || (!defined(__cplusplus) && defined(__clang__)) -#define __FALLTHROUGH __attribute__((__fallthrough__)) -#else -#define __FALLTHROUGH \ - do { \ - } while (0) -#endif - -// Locking annotations. -// -// The following annotations allow compile-time checking that annotated data -// is only accessed while holding the correct locks. -// -// The annotations are only supported by Clang, and frequently used with C++ -// standard library types in userspace, so only enable in Clang when we know -// that the C++ standard library types are annotated or if we're in kernel -// code. -#if defined(__clang__) && (defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) || defined(_KERNEL)) -#define __THREAD_ANNOTATION(x) __attribute__((x)) -#else -#define __THREAD_ANNOTATION(x) -#endif -#define __TA_CAPABILITY(x) __THREAD_ANNOTATION(__capability__(x)) -#define __TA_GUARDED(x) __THREAD_ANNOTATION(__guarded_by__(x)) -#define __TA_ACQUIRE(...) __THREAD_ANNOTATION(__acquire_capability__(__VA_ARGS__)) -#define __TA_ACQUIRE_SHARED(...) __THREAD_ANNOTATION(__acquire_shared_capability__(__VA_ARGS__)) -#define __TA_TRY_ACQUIRE(...) __THREAD_ANNOTATION(__try_acquire_capability__(__VA_ARGS__)) -#define __TA_TRY_ACQUIRE_SHARED(...) \ - __THREAD_ANNOTATION(__try_acquire_shared_capability__(__VA_ARGS__)) -// Neither ACQUIRED_BEFORE nor ACQUIRED_AFTER are implemented in clang. Users of these macros must -// not rely upon them to catch lock ordering bugs, and must treat them as documentation only. -// See: -// https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#acquired-before-and-acquired-after-are-currently-unimplemented -#define __TA_ACQUIRED_BEFORE(...) __THREAD_ANNOTATION(__acquired_before__(__VA_ARGS__)) -#define __TA_ACQUIRED_AFTER(...) __THREAD_ANNOTATION(__acquired_after__(__VA_ARGS__)) -#define __TA_RELEASE(...) __THREAD_ANNOTATION(__release_capability__(__VA_ARGS__)) -#define __TA_RELEASE_SHARED(...) __THREAD_ANNOTATION(__release_shared_capability__(__VA_ARGS__)) -#define __TA_REQUIRES(...) __THREAD_ANNOTATION(__requires_capability__(__VA_ARGS__)) -#define __TA_REQUIRES_SHARED(...) __THREAD_ANNOTATION(__requires_shared_capability__(__VA_ARGS__)) -#define __TA_EXCLUDES(...) __THREAD_ANNOTATION(__locks_excluded__(__VA_ARGS__)) -#define __TA_ASSERT(...) __THREAD_ANNOTATION(__assert_capability__(__VA_ARGS__)) -#define __TA_ASSERT_SHARED(...) __THREAD_ANNOTATION(__assert_shared_capability__(__VA_ARGS__)) -#define __TA_RETURN_CAPABILITY(x) __THREAD_ANNOTATION(__lock_returned__(x)) -#define __TA_SCOPED_CAPABILITY __THREAD_ANNOTATION(__scoped_lockable__) -#define __TA_NO_THREAD_SAFETY_ANALYSIS __THREAD_ANNOTATION(__no_thread_safety_analysis__) - -// Experimental lifetime analysis annotations. -#ifndef __OWNER -#ifdef __clang__ -#define __OWNER(x) [[gsl::Owner(x)]] -#define __POINTER(x) [[gsl::Pointer(x)]] -#else -#define __OWNER(x) -#define __POINTER(x) -#endif -#endif - -#if defined(__cpp_constinit) && __cpp_constinit >= 201907L -#define __CONSTINIT constinit -#elif defined(__clang__) -#define __CONSTINIT [[clang::require_constant_initialization]] -#elif defined(__GNUC__) && __GNUC__ >= 13 -#define __CONSTINIT __constinit -#else -#define __CONSTINIT -#endif - -#endif // !defined(__ASSEMBLER__) - -#endif // ZIRCON_COMPILER_H_ diff --git a/kernel/Build.mk b/kernel/Build.mk deleted file mode 100644 index 8f8ffa0..0000000 --- a/kernel/Build.mk +++ /dev/null @@ -1,11 +0,0 @@ -targets += kernel/core -target.kernel/core.kind := source-set -target.kernel/core.sources := \ - kernel/main.cc kernel/sync/spinlock.cc kernel/sync/mutex.cc \ - kernel/trap.cc kernel/irq.cc kernel/sched_core.cc \ - kernel/sched_class_o1.cc kernel/timer.cc kernel/pid.cc kernel/pgrp.cc \ - kernel/task.cc kernel/syscall.cc kernel/sys_process.cc kernel/sys_mm.cc \ - kernel/sys_info.cc kernel/sys_fs.cc kernel/uaccess.cc kernel/waitqueue.cc \ - kernel/signal.cc kernel/sys_signal.cc kernel/sys_misc.cc kernel/exec.cc \ - kernel/poll.cc kernel/ptrace.cc kernel/smp.cc - diff --git a/kernel/exec.cc b/kernel/exec.cc deleted file mode 100644 index 616c0da..0000000 --- a/kernel/exec.cc +++ /dev/null @@ -1,659 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * exec.cc — ELF64 binary loader and execve implementation - * - * Loads a static ELF64 executable into a fresh address space, - * constructs the user stack (argc/argv/envp/auxv), and redirects - * the current task's trapframe to begin executing at the ELF entry. - * - * Reference: Linux fs/binfmt_elf.c, fs/exec.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Assembly entry points (trap_vector.S) */ -extern "C" void trap_vector(); -extern "C" [[noreturn]] void trap_dispatch(arch::TrapFrame*); -extern "C" void userret(arch::TrapFrame* tf); - -/* ================================================================== */ -/* Constants */ -/* ================================================================== */ - -/* User stack layout comes from mm_layout.h (MI layer). - * kUserStackTop, kUserStackBase, kUserStackSize are defined there, - * derived from kUserVaLimit so they automatically adapt to the - * page table mode (SV39/SV48). */ - -/* ================================================================== */ -/* Helper: kernel_read — read from a file into a kernel buffer */ -/* ================================================================== */ - -static int64 kernel_read(file* fp, void* buf, uint64 count, int64 offset) -{ - int64 pos = offset; - if (!fp->f_op || !fp->f_op->read) return -EINVAL; - return fp->f_op->read(fp, static_cast(buf), count, &pos); -} - -/* ================================================================== */ -/* Helper: copy data to a user page via kernel direct map */ -/* ================================================================== */ - -static void memcpy_kernel(void* dst, const void* src, uint64 n) -{ - auto* d = static_cast(dst); - auto* s = static_cast(src); - for (uint64 i = 0; i < n; i++) - d[i] = s[i]; -} - -static void memset_kernel(void* dst, uint8 val, uint64 n) -{ - auto* d = static_cast(dst); - for (uint64 i = 0; i < n; i++) - d[i] = val; -} - -static uint64 strlen_kernel(const char* s) -{ - uint64 n = 0; - while (s[n]) n++; - return n; -} - -/* ================================================================== */ -/* Helper: allocate and map a page at a specific user VA */ -/* ================================================================== */ - -static int map_page_at(VmSpace* mm, uint64 va, uint64 pte_perm) -{ - Page* pg = pmm_alloc_page(); - if (!pg) return -ENOMEM; - - uint64 pa = page_to_pa(pg).raw; - - /* Zero the page */ - void* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - memset_kernel(kva, 0, kPageSize); - - int ret = pmap::map(mm->root_pa, va, pa, pte_perm); - if (ret != 0) { - pmm_free_page(pg); - return -ENOMEM; - } - page_inc_mapcount(pg); - return 0; -} - -/* ================================================================== */ -/* load_elf_binary — parse ELF and map segments */ -/* ================================================================== */ - -struct elf_load_info { - uint64 entry; /* ELF entry point (after base offset) */ - uint64 phdr_addr; /* User VA where phdr was loaded */ - uint16 phnum; /* Number of program headers */ - uint16 phentsize; /* Size of each phdr */ - uint64 brk_start; /* End of highest PT_LOAD segment (for brk) */ - uint64 load_bias; /* PIE load bias (0 for ET_EXEC) */ -}; - -static int load_elf_binary(file* fp, VmSpace* mm, elf_load_info* info) -{ - /* Read ELF header */ - Elf64_Ehdr ehdr{}; - int64 n = kernel_read(fp, &ehdr, sizeof(ehdr), 0); - if (n < static_cast(sizeof(ehdr))) { - printk(KERN_ERR "exec: failed to read ELF header (got %lld)\n", n); - return -ENOEXEC; - } - - /* Validate magic */ - if (ehdr.e_ident[EI_MAG0] != ELFMAG0 || - ehdr.e_ident[EI_MAG1] != ELFMAG1 || - ehdr.e_ident[EI_MAG2] != ELFMAG2 || - ehdr.e_ident[EI_MAG3] != ELFMAG3) { - printk(KERN_ERR "exec: bad ELF magic\n"); - return -ENOEXEC; - } - - /* Validate class (64-bit) and endianness (little-endian) */ - if (ehdr.e_ident[EI_CLASS] != ELFCLASS64) return -ENOEXEC; - if (ehdr.e_ident[EI_DATA] != ELFDATA2LSB) return -ENOEXEC; - - /* Validate type and machine */ - if (ehdr.e_type != ET_EXEC && ehdr.e_type != ET_DYN) return -ENOEXEC; - if (ehdr.e_machine != EM_RISCV) return -ENOEXEC; - - if (ehdr.e_phnum == 0 || ehdr.e_phentsize < sizeof(Elf64_Phdr)) - return -ENOEXEC; - - /* Read program headers */ - uint64 phdr_total = static_cast(ehdr.e_phnum) * ehdr.e_phentsize; - if (phdr_total > kPageSize) return -ENOEXEC; /* Sanity limit */ - - /* Allocate kernel buffer for program headers */ - uint8 phdr_buf[512]; /* Max ~8 phdrs * 56 bytes each */ - if (phdr_total > sizeof(phdr_buf)) return -ENOEXEC; - - n = kernel_read(fp, phdr_buf, phdr_total, static_cast(ehdr.e_phoff)); - if (n < static_cast(phdr_total)) return -ENOEXEC; - - info->phnum = ehdr.e_phnum; - info->phentsize = ehdr.e_phentsize; - info->phdr_addr = 0; - info->brk_start = 0; - info->load_bias = 0; - - /* - * PIE (ET_DYN): segments have p_vaddr starting near 0. - * We must choose a load base and add it to all addresses. - * Linux uses ELF_ET_DYN_BASE (~2/3 of TASK_SIZE); we use 0x400000. - */ - constexpr uint64 kPieLoadBase = 0x400000; - uint64 load_bias = (ehdr.e_type == ET_DYN) ? kPieLoadBase : 0; - info->load_bias = load_bias; - info->entry = ehdr.e_entry + load_bias; - - /* Process each PT_LOAD segment */ - for (uint16 i = 0; i < ehdr.e_phnum; i++) { - auto* phdr = reinterpret_cast( - phdr_buf + i * ehdr.e_phentsize); - - if (phdr->p_type == PT_PHDR) { - /* Remember where program headers are mapped */ - info->phdr_addr = phdr->p_vaddr + load_bias; - continue; - } - - if (phdr->p_type != PT_LOAD) continue; - if (phdr->p_memsz == 0) continue; - - /* Compute permissions */ - uint64 perm = pmap::PTE_V | pmap::PTE_U; - if (phdr->p_flags & PF_R) perm |= pmap::PTE_R; - if (phdr->p_flags & PF_W) perm |= pmap::PTE_W; - if (phdr->p_flags & PF_X) perm |= pmap::PTE_X; - - /* Page-align the segment boundaries (apply load bias for PIE) */ - uint64 seg_start = page_align_down(phdr->p_vaddr + load_bias); - uint64 seg_end = page_align_up(phdr->p_vaddr + phdr->p_memsz + load_bias); - - /* Create VMA for this segment */ - uint64 vm_perm = VM_USER; - if (phdr->p_flags & PF_R) vm_perm |= VM_READ; - if (phdr->p_flags & PF_W) vm_perm |= VM_WRITE; - if (phdr->p_flags & PF_X) vm_perm |= VM_EXEC; - - int err = vmm_map_user(mm, seg_start, seg_end - seg_start, vm_perm); - if (err) { - printk(KERN_ERR "exec: vmm_map_user failed for segment %d: %d\n", - i, err); - return err; - } - - /* Map and fill pages */ - for (uint64 va = seg_start; va < seg_end; va += kPageSize) { - err = map_page_at(mm, va, perm); - if (err) return err; - - /* Determine how much file data goes into this page */ - uint64 file_seg_start = phdr->p_vaddr + load_bias; - uint64 file_seg_end = phdr->p_vaddr + phdr->p_filesz + load_bias; - - uint64 page_start = va; - uint64 page_end = va + kPageSize; - - /* Overlap between [page_start, page_end) and [file_seg_start, file_seg_end) */ - if (page_start < file_seg_end && page_end > file_seg_start) { - uint64 copy_start = (page_start > file_seg_start) ? page_start : file_seg_start; - uint64 copy_end = (page_end < file_seg_end) ? page_end : file_seg_end; - uint64 copy_len = copy_end - copy_start; - - /* File offset for this data */ - uint64 file_off = phdr->p_offset + (copy_start - phdr->p_vaddr - load_bias); - - /* Get kernel VA of the mapped page */ - uint64 pa; - if (!pmap::lookup(mm->root_pa, va, &pa)) return -EFAULT; - uint8* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - - /* Read file data into the page */ - uint64 page_offset = copy_start - va; - n = kernel_read(fp, kva + page_offset, copy_len, - static_cast(file_off)); - if (n < static_cast(copy_len)) { - printk(KERN_ERR "exec: short read at offset %llu\n", file_off); - return -EIO; - } - } - /* BSS region (memsz > filesz) is already zeroed by map_page_at */ - } - - /* Track highest loaded address for brk */ - if (seg_end > info->brk_start) - info->brk_start = seg_end; - - /* Detect which PT_LOAD contains the program header table. - * Linux: fs/binfmt_elf.c line ~1209 */ - if (info->phdr_addr == 0 && - phdr->p_offset <= ehdr.e_phoff && - ehdr.e_phoff < phdr->p_offset + phdr->p_filesz) { - info->phdr_addr = ehdr.e_phoff - phdr->p_offset - + phdr->p_vaddr + load_bias; - } - } - - /* phdr_addr should have been set by the PT_LOAD loop above - * or by a PT_PHDR entry. If still zero, something is wrong. */ - if (info->phdr_addr == 0) { - printk(KERN_ERR "exec: unable to determine AT_PHDR address\n"); - return -ENOEXEC; - } - - return 0; -} - -/* ================================================================== */ -/* setup_user_stack — build argc/argv/envp/auxv on the user stack */ -/* ================================================================== */ - -static int setup_user_stack(VmSpace* mm, const char* const* argv, - const char* const* envp, - const elf_load_info* info, - uint64* out_sp) -{ - /* Create stack VMA */ - uint64 vm_perm = VM_USER | VM_READ | VM_WRITE; - int err = vmm_map_user(mm, kUserStackBase, kUserStackSize, vm_perm); - if (err) return err; - - /* We only need the top few pages for initial stack content. - * Map 2 pages at the top for argc/argv/envp/auxv. */ - uint64 perm = pmap::PTE_V | pmap::PTE_U | pmap::PTE_R | pmap::PTE_W; - for (uint64 va = kUserStackTop - 2 * kPageSize; va < kUserStackTop; va += kPageSize) { - err = map_page_at(mm, va, perm); - if (err) return err; - } - - /* Count arguments and environment */ - int argc = 0; - int envc = 0; - if (argv) { while (argv[argc]) argc++; } - if (envp) { while (envp[envc]) envc++; } - - /* - * Build the stack from top down using kernel VA access. - * Layout (top to bottom): - * 1. String data (argv strings, envp strings) - * 2. Padding (16-byte align) - * 3. auxv[] - * 4. NULL (end of envp) - * 5. envp[] pointers - * 6. NULL (end of argv) - * 7. argv[] pointers - * 8. argc - */ - - /* First pass: calculate total string space */ - uint64 str_total = 0; - for (int i = 0; i < argc; i++) - str_total += strlen_kernel(argv[i]) + 1; - for (int i = 0; i < envc; i++) - str_total += strlen_kernel(envp[i]) + 1; - - /* String area starts at top of stack */ - uint64 str_pos = kUserStackTop - str_total; - str_pos &= ~15ULL; /* 16-byte align */ - - /* Copy strings and record user addresses */ - uint64 argv_addrs[32]; /* Max 32 args */ - uint64 envp_addrs[32]; - if (argc > 32) argc = 32; - if (envc > 32) envc = 32; - - uint64 cur = str_pos; - for (int i = 0; i < argc; i++) { - uint64 len = strlen_kernel(argv[i]) + 1; - argv_addrs[i] = cur; - - /* Copy string bytes to user stack via kernel VA */ - uint64 pa; - if (!pmap::lookup(mm->root_pa, page_align_down(cur), &pa)) - return -EFAULT; - uint8* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - uint64 off = cur - page_align_down(cur); - memcpy_kernel(kva + off, argv[i], len); - cur += len; - } - for (int i = 0; i < envc; i++) { - uint64 len = strlen_kernel(envp[i]) + 1; - envp_addrs[i] = cur; - - uint64 pa; - if (!pmap::lookup(mm->root_pa, page_align_down(cur), &pa)) - return -EFAULT; - uint8* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - uint64 off = cur - page_align_down(cur); - memcpy_kernel(kva + off, envp[i], len); - cur += len; - } - - /* Build auxv, envp[], argv[], argc below the strings */ - /* Count entries: argc + argv_ptrs + NULL + envp_ptrs + NULL + auxv (6 pairs + terminator) */ - int auxv_count = 8; /* AT_PHDR, AT_PHENT, AT_PHNUM, AT_PAGESZ, AT_BASE, AT_ENTRY, AT_RANDOM, AT_NULL */ - uint64 table_size = sizeof(uint64) * (1 + argc + 1 + envc + 1 + auxv_count * 2); - uint64 table_start = str_pos - table_size; - table_start &= ~15ULL; - - /* Write the table entries. - * We need to handle page boundaries, but for simplicity we assume - * the table fits in the already-mapped pages. */ - uint64 sp = table_start; - - /* Helper: write a uint64 to user stack */ - auto write_u64 = [&](uint64 addr, uint64 val) -> int { - uint64 pa; - if (!pmap::lookup(mm->root_pa, page_align_down(addr), &pa)) - return -EFAULT; - uint8* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - uint64 off = addr - page_align_down(addr); - *reinterpret_cast(kva + off) = val; - return 0; - }; - - /* argc */ - err = write_u64(sp, static_cast(argc)); - if (err) return err; - sp += 8; - - /* argv[] */ - for (int i = 0; i < argc; i++) { - err = write_u64(sp, argv_addrs[i]); - if (err) return err; - sp += 8; - } - err = write_u64(sp, 0); /* NULL terminator */ - if (err) return err; - sp += 8; - - /* envp[] */ - for (int i = 0; i < envc; i++) { - err = write_u64(sp, envp_addrs[i]); - if (err) return err; - sp += 8; - } - err = write_u64(sp, 0); /* NULL terminator */ - if (err) return err; - sp += 8; - - /* auxv[] */ - auto write_auxv = [&](uint64 type, uint64 val) -> int { - int r = write_u64(sp, type); - if (r) return r; - sp += 8; - r = write_u64(sp, val); - if (r) return r; - sp += 8; - return 0; - }; - - write_auxv(AT_PHDR, info->phdr_addr); - write_auxv(AT_PHENT, info->phentsize); - write_auxv(AT_PHNUM, info->phnum); - write_auxv(AT_PAGESZ, kPageSize); - write_auxv(AT_BASE, info->load_bias); - write_auxv(AT_ENTRY, info->entry); - write_auxv(AT_RANDOM, str_pos - 16); /* Point to 16 bytes of zeros for now */ - write_auxv(AT_NULL, 0); - - *out_sp = table_start; - return 0; -} - -/* ================================================================== */ -/* do_execve — main entry point */ -/* ================================================================== */ - -int do_execve(const char* pathname, const char* const* argv, - const char* const* envp) -{ - TaskControlBlock* curr = current_task(); - if (!curr) return -EINVAL; - - /* 1. Look up the file */ - path p{}; - int err = filename_lookup(AT_FDCWD, pathname, 0, &p); - if (err) { - printk(KERN_ERR "exec: file not found: %s (err=%d)\n", pathname, err); - return err; - } - - inode* ip = p.de->d_inode; - if (!ip || !S_ISREG(ip->i_mode)) { - printk(KERN_ERR "exec: not a regular file: %s\n", pathname); - return -EACCES; - } - - /* Open a kernel file handle */ - file* fp = alloc_empty_file(O_RDONLY); - if (!fp) { - return -ENOMEM; - } - fp->f_inode = ip; - fp->f_path = p; - fp->f_op = ip->i_fop; - fp->f_pos = 0; - - if (fp->f_op && fp->f_op->open) { - err = fp->f_op->open(ip, fp); - if (err) { - fput(fp); - return err; - } - } - - /* 2. Create new address space */ - VmSpace* new_mm = VmSpace::create(); - if (!new_mm) { - fput(fp); - return -ENOMEM; - } - - /* 3. Load ELF segments */ - elf_load_info info{}; - err = load_elf_binary(fp, new_mm, &info); - if (err) { - printk(KERN_ERR "exec: load_elf_binary failed: %d\n", err); - new_mm->put(); - fput(fp); - dput(p.de); - return err; - } - - /* 4. Set up user stack */ - uint64 user_sp = 0; - err = setup_user_stack(new_mm, argv, envp, &info, &user_sp); - if (err) { - printk(KERN_ERR "exec: setup_user_stack failed: %d\n", err); - new_mm->put(); - fput(fp); - return err; - } - - /* Set brk */ - new_mm->brk_start = page_align_up(info.brk_start); - new_mm->brk_end = new_mm->brk_start; - - /* Set mmap base — Linux: arch_pick_mmap_layout() sets mm->mmap_base - * to TASK_UNMAPPED_BASE = PAGE_ALIGN(TASK_SIZE / 3). - * This ensures mmap(NULL) returns addresses well above the ELF - * text/data segments. */ - new_mm->mmap_base = page_align_up(kUserVaLimit / 3); - - fput(fp); - - /* =============================================================== */ - /* Point of no return — replace the current process */ - /* =============================================================== */ - - /* 5a. Replace address space */ - VmSpace* old_mm = curr->mm; - curr->mm = new_mm; - pmap::activate(new_mm->root_pa); - if (old_mm) old_mm->put(); - - /* 5a'. Transition from kernel thread to user process. - * Linux: begin_new_exec() in fs/exec.c: - * current->flags &= ~PF_KTHREAD; (line 1173) - * tsk->exit_signal = SIGCHLD; (line 1021) - * Without this, a kernel_execve'd task stays marked as a kthread - * and would be auto-reaped (exit_signal=-1) instead of becoming - * a proper zombie for parent wait(). */ - curr->flags &= ~TF_KTHREAD; - curr->exit_signal = SIGCHLD; - - /* 5b. Reset signal handlers to SIG_DFL (POSIX requirement). - * - * Linux fs/exec.c:flush_signal_handlers() runs under sighand->siglock. - * Even though after fork our sighand is no longer shared with the - * parent (we copy in task_clone), Linux still locks here — and so - * must we, because the same sighand may be shared with CLONE_SIGHAND - * sibling threads of the execing task. Holding siglock here also - * keeps the per-task blocked mask reset atomic w.r.t. concurrent - * sigprocmask / signal delivery on this very task. */ - if (curr->sighand) { - LockGuard guard(curr->sighand->siglock); - for (int i = 0; i < _NSIG; i++) { - if (curr->sighand->action[i].sa_handler != SIG_IGN) - curr->sighand->action[i].sa_handler = SIG_DFL; - curr->sighand->action[i].sa_flags = 0; - curr->sighand->action[i].sa_mask.clear(); - } - curr->blocked.clear(); - } else { - curr->blocked.clear(); - } - - /* 5c. Close O_CLOEXEC file descriptors */ - /* TODO: implement close-on-exec */ - - /* 6. Set up trapframe to enter user space */ - arch::TrapFrame* tf = curr->trapframe; - if (!tf) { - printk(KERN_ERR "exec: no trapframe!\n"); - task_kill_current(SIGKILL); - return -EINVAL; /* not reached */ - } - - /* Initialize trapframe for user-mode return. - * This is the MI equivalent of Linux's start_thread() + kernel - * metadata setup. All arch-specific details (sstatus, FP state, - * kernel_satp, kernel_sp, trap handler address, etc.) are handled - * by the MD layer. MI exec never touches arch registers. */ - arch::trapframe_init_user(tf, info.entry, user_sp); - - pr_debug_s(KLOG_SUBSYS_EXEC, - "exec: pid %d entry=%llx sp=%llx phdr=%llx\n", - curr->pid, info.entry, user_sp, info.phdr_addr); - - /* Verify loaded data at entry point — debug-level, ring buffer only. */ - { - uint64 pa; - if (pmap::lookup(curr->mm->root_pa, page_align_down(info.entry), &pa)) { - uint8* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - uint64 off = info.entry - page_align_down(info.entry); - pr_debug_s(KLOG_SUBSYS_EXEC, - "exec: entry bytes @%llx: %02x %02x %02x %02x %02x %02x %02x %02x\n", - info.entry, - kva[off+0], kva[off+1], kva[off+2], kva[off+3], - kva[off+4], kva[off+5], kva[off+6], kva[off+7]); - } - for (uint64 va = 0x10000; va < 0x14000; va += kPageSize) { - if (pmap::lookup(curr->mm->root_pa, va, &pa)) { - uint8* kva2 = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - pr_debug_s(KLOG_SUBSYS_EXEC, - "exec: page %llx: %02x%02x%02x%02x %02x%02x%02x%02x\n", - va, kva2[0], kva2[1], kva2[2], kva2[3], - kva2[4], kva2[5], kva2[6], kva2[7]); - } else { - pr_debug_s(KLOG_SUBSYS_EXEC, - "exec: page %llx: NOT MAPPED\n", va); - } - } - } - - /* Flush instruction cache after loading executable code into memory. - * Without this, the I-cache may contain stale data for the pages - * we just loaded, causing the CPU to execute garbage. */ - arch::mmu::flush_icache(); - - return 0; /* Will return to user mode via trap return */ -} - -/* ================================================================== */ -/* sys_execve_wrapper — syscall entry point */ -/* ================================================================== */ - -int64 sys_execve_wrapper(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - const char* pathname = reinterpret_cast(a0); - const char* const* argv = reinterpret_cast(a1); - const char* const* envp = reinterpret_cast(a2); - - return do_execve(pathname, argv, envp); -} - -/* ================================================================== */ -/* kernel_execve — call execve from kernel context (e.g. init) */ -/* ================================================================== */ - -int kernel_execve(const char* pathname, const char* const* argv, - const char* const* envp) -{ - TaskControlBlock* curr = current_task(); - - int ret = do_execve(pathname, argv, envp); - if (ret != 0) - return ret; - - /* - * do_execve succeeded: the trapframe is set up with entry point, - * user stack, and sstatus (SPP=0 for U-mode). We must NOT return - * normally — that would go back through the kthread return path - * and jump to address 0. Instead, jump directly to user mode via - * the same userret() path that fork_child_entry uses. - * - * Switch stvec from kernelvec to trap_vector so that traps from - * U-mode are handled by the user trap entry path (which loads - * kernel context from the trapframe via sscratch). - */ - arch::trap::set_vector(reinterpret_cast(trap_vector)); - userret(curr->trapframe); - __builtin_unreachable(); -} diff --git a/kernel/irq.cc b/kernel/irq.cc deleted file mode 100644 index 4de468a..0000000 --- a/kernel/irq.cc +++ /dev/null @@ -1,106 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * IRQ Manager Implementation - * - * Lock-free dispatch path for interrupt context safety. - * Registration/unregistration is protected by atomic publish. - * - * Reference: docs/specs/trap.md §3.3 - */ - -#include -#include -#include - -/* Global singleton */ -IrqManager g_irq_manager; - -void IrqManager::init() { - for (uint32 i = 0; i < kMaxIrqs; i++) { - entries_[i].handler_ptr.store(0, __ATOMIC_RELAXED); - entries_[i].arg = nullptr; - } -} - -int IrqManager::register_handler(uint32 irq, IrqHandler handler, void *arg) { - if (irq >= kMaxIrqs) - return -EINVAL; - - if (!handler) - return -EINVAL; - - /* Check if already registered (CAS from 0 to handler) */ - uint64 expected = 0; - uint64 desired = reinterpret_cast(handler); - - /* Set arg first (before publishing handler) so dispatch sees valid arg */ - entries_[irq].arg = arg; - - if (!entries_[irq].handler_ptr.compare_exchange(expected, desired, - __ATOMIC_ACQ_REL)) { - /* Already registered by someone else */ - return -EBUSY; - } - - return 0; -} - -void IrqManager::unregister_handler(uint32 irq) { - if (irq >= kMaxIrqs) - return; - - /* Clear handler with release semantics */ - entries_[irq].handler_ptr.store(0, __ATOMIC_RELEASE); - entries_[irq].arg = nullptr; -} - -void IrqManager::dispatch(uint32 irq) { - if (irq >= kMaxIrqs) - return; - - /* Load handler with acquire semantics — pairs with register's release */ - uint64 h = entries_[irq].handler_ptr.load(__ATOMIC_ACQUIRE); - if (h == 0) { - /* Spurious or unregistered IRQ — silently ignore */ - return; - } - - auto handler = reinterpret_cast(h); - handler(irq, entries_[irq].arg); -} - -bool IrqManager::has_handler(uint32 irq) const { - if (irq >= kMaxIrqs) - return false; - return entries_[irq].handler_ptr.load(__ATOMIC_ACQUIRE) != 0; -} - -void IrqManager::set_chip(const IrqChip* chip) { - chip_ = chip; -} - -uint32 IrqManager::claim() const { - return chip_ ? chip_->claim() : 0; -} - -void IrqManager::complete(uint32 irq) const { - if (chip_) chip_->complete(irq); -} - -void IrqManager::init_ap() const { - if (chip_ && chip_->init_ap) chip_->init_ap(); -} - -void IrqManager::enable(uint32 irq) const { - if (chip_ && chip_->enable) chip_->enable(irq); -} - -void IrqManager::disable(uint32 irq) const { - if (chip_ && chip_->disable) chip_->disable(irq); -} - -void IrqManager::set_priority(uint32 irq, uint32 priority) const { - if (chip_ && chip_->set_priority) chip_->set_priority(irq, priority); -} diff --git a/kernel/main.cc b/kernel/main.cc deleted file mode 100644 index c84f3ad..0000000 --- a/kernel/main.cc +++ /dev/null @@ -1,474 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * LumeOS Kernel Main Entry — Global Initialization Sequence - * - * All CPUs enter kernel_main() after the assembly bootstrap (entry.S) - * has enabled MMU, cleared BSS, and called early_cpp_init(). - * - * BSP (cpu_id == 0) executes the full subsystem initialization DAG. - * APs spin on ap_boot_sync, then perform per-CPU init only. - * - * Boot DAG invariants (docs/specs/linux_abi_mm_plan.md §Boot Sequence): - * - trap_init() MUST precede any allocator (exception safety net) - * - sched_init() MUST precede timer_init() (software before hardware) - * - PID 1 (init) is spawned before entering idle loop - * - * Reference: docs/specs/global_init.md - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Declared by entry.S: the hart ID that won BSP election -extern "C" uint32 bsp_hart_id; - -// Linker symbol: kernel entry point (physical start address) -extern "C" char _start[]; - -// ============================================================ -// Forward declarations for subsystem init functions. -// Each is implemented by its owning module. On failure they -// call kernel_panic() directly — no error return. -// ============================================================ - -// BSP global init (strict order) -void console_init(); // 1. UART ready; kprintf/panic can output -void fdt_init(uint64 fdt_paddr); // 2. Parse FDT, build device node table -void pmm_init(); // 3. Buddy allocator ready -void slab_init(); // 4. kmem_cache ready; operator new usable -void vmm_init(); // 5. Fine-grained kernel page table; retire early_pgdir -void task_init(); // 6. PID allocator + global task list -void pgrp_init(); // 6.5. Process group hash table -void sched_init(); // 7. Create BSP Idle Task, init ready queues -void timer_init(); // 8. Configure timer interrupt (scheduler tick) -void syscall_init(); // 9. Register syscall jump table -void super_init(); // 10. VFS superblock registry -void ramfs_init(); // 11. RamFS filesystem registration -void vfs_init(); // 12. Mount root filesystem -void cdev_init(); // 13. Character device registry -void console_cdev_init(); // 14. Register console/null/zero cdevs -void devfs_init(); // 15. Create /dev and populate nodes -void tty_init(); // 15.5. TTY subsystem (console TTY + UART RX IRQ) -void populate_rootfs(); // 15.6. Unpack embedded initramfs CPIO into ramfs - -// Boot self-test runner -#ifdef CONFIG_SELFTEST -void selftest_run_all(); -#endif - -// AP per-CPU init -void vmm_init_ap(); // Switch to BSP-built kernel page table -void timer_init_ap(); // Start this CPU's timer interrupt -void sched_init_ap(); // Init per-CPU ready queue, create Idle Task - -// kthread_create from task.cc -extern TaskControlBlock *kthread_create(const char *name, void (*entry)(void *), - void *arg, uint8 priority); - -// ============================================================ -// PID 1 — init thread -// ============================================================ -static void init_thread_func(void *) { - printk(KERN_INFO "[init] PID 1 started\n"); - - /* Run post-SMP tests — APs are online by now */ -#ifdef CONFIG_SELFTEST - extern void selftest_smp(); - kprintf("\n========================================\n"); - kprintf(" Post-SMP Test Suite\n"); - kprintf("========================================\n"); - selftest_smp(); - kprintf("========================================\n"); - kprintf(" Post-SMP tests PASSED\n"); - kprintf("========================================\n\n"); -#endif - - /* - * Set up init's own VFS context (like Linux kernel_init). - * kthread_create does NOT inherit files/fs, so init creates its own. - */ - TaskControlBlock *self = current_task(); - - if (!self->files) { - self->files = alloc_files_struct(); - if (!self->files) { - printk(KERN_ERR "[init] failed to allocate files_struct\n"); - goto out; - } - } - if (!self->fs) { - self->fs = alloc_fs_struct(); - if (!self->fs) { - printk(KERN_ERR "[init] failed to allocate fs_struct\n"); - goto out; - } - /* Point to the global root filesystem */ - self->fs->root.de = g_root_dentry; - self->fs->root.mnt = g_root_mnt; - self->fs->pwd = self->fs->root; - } - - /* Open /dev/console → fd 0 (stdin), dup to fd 1, 2 */ - { - extern int64 sys_openat(uint64, uint64, uint64, uint64, uint64, uint64); - extern int64 sys_dup(uint64, uint64, uint64, uint64, uint64, uint64); - - int64 fd0 = - sys_openat(static_cast(-100), /* AT_FDCWD */ - reinterpret_cast("/dev/console"), O_RDWR, 0, 0, 0); - if (fd0 < 0) { - printk(KERN_ERR "[init] open /dev/console failed: %d\n", - static_cast(fd0)); - } else { - sys_dup(static_cast(fd0), 0, 0, 0, 0, 0); /* fd 1 */ - sys_dup(static_cast(fd0), 0, 0, 0, 0, 0); /* fd 2 */ - printk(KERN_INFO "[init] fd 0/1/2 -> /dev/console\n"); - } - } - - /* - * Try to exec /sbin/init (like Linux kernel_init). - * If not found, fall through to idle. - */ - { - extern int kernel_execve(const char *, const char *const *, - const char *const *); - - const char *init_paths[] = {"/sbin/init", "/etc/init", "/bin/init", - "/bin/sh", nullptr}; - const char *argv[] = {"/sbin/init", nullptr}; - const char *envp[] = {"HOME=/", "PATH=/sbin:/bin", nullptr}; - - for (int i = 0; init_paths[i]; i++) { - argv[0] = init_paths[i]; - int ret = kernel_execve(init_paths[i], argv, envp); - if (ret == 0) { - /* Success — do_execve modified our trapframe. - * When this kthread returns through the trap return path, - * it will jump to user space. */ - return; - } - printk(KERN_INFO "[init] exec %s failed: %d\n", init_paths[i], ret); - } - - printk(KERN_ERR "[init] No init found! Kernel panic.\n"); - } - -out: - extern void task_exit(int code); - task_exit(0); -} - -// ============================================================ -// Second-stage synchronization barrier (C++ layer) -// AP cores spin here until BSP finishes all global init. -// ============================================================ -static lume::atomic ap_boot_sync; - -// ============================================================ -// kernel_main — C++ entry point for all CPUs -// ============================================================ -extern "C" [[noreturn]] void kernel_main(uint64 cpu_id, uint64 fdt_paddr) { - - if (cpu_id == bsp_hart_id) { - // ======================================================== - // BSP: Absolute single-core period — no locks needed. - // APs are spinning on ap_boot_sync. - // ======================================================== - - uint64 fdt_pa = fdt_paddr; - - // ---- Phase 1: Console + Exception Safety Net ---- - - // 1. Early console setup: discover UART via FDT before ANY output. - console_early_init(fdt_pa); - klog_init(); - - printk("\n"); - printk(KERN_INFO "LumeOS Kernel v0.1\n"); - printk(KERN_INFO "boot: BSP online, cpu_id=%llu\n", cpu_id); - printk(KERN_INFO "boot: higher-half kernel active\n"); - - /* kernel_map filled by arch/riscv/mm/init.cc::setup_vm before MMU - * enable; relocate_kernel has already applied .rela.dyn. */ - printk(KERN_INFO "boot: kimage phys=0x%llx virt=0x%llx size=%llu\n", - static_cast(kernel_map.phys_addr), - static_cast(kernel_map.virt_addr), - static_cast(kernel_map.size)); - - // --- Subsystem init DAG (strict top-down order) --- - - // 2. Trap handler — install exception vector FIRST. - // Any fault from here on gets a proper panic backtrace - // instead of a silent hang. (Linux: trap_init is in start_kernel - // right after setup_arch.) - trap_init(); - printk(KERN_INFO "init: trap_init done\n"); - - // 3. FDT parsing — make device tree available - fdt_init(fdt_pa); - printk(KERN_INFO "init: fdt_init done\n"); - - // 4. KASLR — seed PRNG and randomise VA layout. - // MUST happen before vmm_init() builds the kernel page table. - { - uint64 kaslr_seed = 0; - fdt_early_get_kaslr_seed(&kaslr_seed); - random_early_init(kaslr_seed); - arch::kaslr_init(); - } - - // Sort exception table before setting RO permissions in vmm_init() - extable_init(); - - // ---- Phase 2: Memory Subsystem (strict cascade) ---- - - // 5. Memblock allocator (Early boot PA allocator) - memblock_init(fdt_pa); - printk(KERN_INFO "init: memblock_init done\n"); - - // 6. Virtual memory manager — builds page table with KASLR'd bases - vmm_init(); - printk(KERN_INFO "init: vmm_init done\n"); - - // 7. Physical memory manager (Buddy) - pmm_init(); - printk(KERN_INFO "init: pmm_init done\n"); - - // 8. Slab allocator — operator new usable after this - slab_init(); - printk(KERN_INFO "init: slab_init done\n"); - - // 9. Page cache (minimal hash table, stable interface for file-backed mmap) - page_cache_init(); - - // 10. FDT Phase 2 — build DeviceNode object tree (needs Slab) - fdt_unflatten(); - printk(KERN_INFO "init: fdt_unflatten done\n"); - - // ---- Phase 3: Task & Scheduler (software state before hardware) ---- - - // 11. Task management (PID allocator + global task list) - task_init(); - printk(KERN_INFO "init: task_init done\n"); - - pgrp_init(); - - sched_init(); - printk(KERN_INFO "init: sched_init done\n"); - - // ---- Phase 3.5: VFS (needs slab + sched) ---- - super_init(); - ramfs_init(); - vfs_init(); - printk(KERN_INFO "init: vfs_init done (ramfs root mounted)\n"); - - // ---- Phase 3.55: Unpack initramfs into root ---- - populate_rootfs(); - - // ---- Phase 3.6: Device nodes ---- - cdev_init(); - console_cdev_init(); - devfs_init(); - printk(KERN_INFO "init: devfs done\n"); - - // ---- Phase 4: Hardware Drivers & Interrupts ---- - - // 13. Hardware Drivers Discovery (Interrupt Controllers, etc) - driver_probe_all(); - printk(KERN_INFO "init: driver_probe_all done\n"); - - // 13.5. TTY subsystem — needs PLIC (driver_probe_all) for UART RX IRQ - tty_init(); - printk(KERN_INFO "init: tty_init done\n"); - - // 14. Timer interrupt (scheduler tick source) - // Safe now: scheduler is fully initialized. - timer_init(); - printk(KERN_INFO "init: timer_init done\n"); - - // 15. Syscall jump table - syscall_init(); - printk(KERN_INFO "init: syscall_init done\n"); - - // 16. SMP / IPI infrastructure - smp_init(); - arch::cpu::software_intr_on(); // Enable S-mode software interrupts for IPI - arch::cpu::external_intr_on(); // Enable S-mode external interrupts for PLIC (UART) - - // ---- Phase 5: Self-test & Launch ---- - - // 17. Boot self-tests — verify subsystem correctness. - // Tests that create kthreads must wait() for them (freeing PIDs). -#ifdef CONFIG_SELFTEST - selftest_run_all(); -#endif - - // 18. Spawn PID 1 (init) — the first persistent task. - // Like Linux's rest_init() → user_mode_thread(kernel_init). - // All test PIDs have been freed, so PID 1 is available. - TaskControlBlock *init_task = - kthread_create("init", init_thread_func, nullptr, 0); - if (init_task) { - init_task->flags |= TF_INIT; - - /* Init is session and process-group leader: sid = pgid = pid. - * Allocate signal_struct AND sighand_struct eagerly so every - * descendant (created via task_clone) inherits a real identity - * and a real lock object — signal sending must take siglock and - * cannot tolerate a null sighand. */ - init_task->signal = alloc_signal_struct(init_task->pid, init_task); - if (!init_task->signal) { - printk(KERN_ERR "boot: FAILED to allocate init signal_struct\n"); - } - init_task->sighand = alloc_sighand(); - if (!init_task->sighand) { - printk(KERN_ERR "boot: FAILED to allocate init sighand\n"); - } - - /* Publish g_init_task so reparenting paths can find the foster - * parent when other tasks exit before init takes over user space. */ - extern TaskControlBlock* g_init_task; - g_init_task = init_task; - - printk(KERN_INFO "boot: init thread created (pid=%d sid=%d pgid=%d)\n", - init_task->pid, - init_task->signal ? init_task->signal->sid : -1, - init_task->signal ? init_task->signal->pgid : -1); - } else { - printk(KERN_ERR "boot: FAILED to create init thread!\n"); - } - - - BOOT_STAGE(5, "core kernel init"); - printk(KERN_INFO "boot: BSP init complete, releasing APs\n"); - - // Release APs with RELEASE semantics: - // guarantees all global data is visible to APs. - ap_boot_sync.store(1, __ATOMIC_RELEASE); - - // Start AP harts via SBI HSM extension. - // OpenSBI v1.0+ parks non-boot harts in STOPPED state. - // They must be explicitly started with sbi_hart_start(). - // - // kernel_map.phys_addr was filled by setup_vm in arch/riscv/mm/init.cc - // before MMU enable — it's the runtime PA at which the kernel was - // loaded. APs start at the same PA as the BSP. - { - uint64 start_pa = kernel_map.phys_addr; - if (start_pa == 0) { - /* Defensive fallback if setup_vm hasn't filled the field. */ - start_pa = - boot_va_to_pa(virt_addr(reinterpret_cast(_start))).raw; - } - uint32 num_harts = 4; // TODO: read from FDT /cpus - for (uint32 h = 0; h < num_harts; h++) { - if (h == static_cast(cpu_id)) - continue; // skip BSP - auto ret = arch::sbi::sbi_hart_start(h, start_pa, fdt_paddr); - if (ret.error == arch::sbi::SBI_SUCCESS) { - printk(KERN_INFO "smp: started hart %u at PA 0x%llx\n", h, start_pa); - } else { - printk(KERN_ERR "smp: failed to start hart %u (err=%ld)\n", h, - ret.error); - } - } - } - - // BSP enables interrupts — first timer tick will preempt - // into the scheduler loop, which will pick up PID 1. - arch::cpu::intr_on(); - - printk(KERN_INFO "boot: BSP entering idle loop\n"); - - } else { - // ======================================================== - // AP: spin until BSP finishes global init - // ======================================================== - // DEBUG (commented out — uncomment for SMP debugging): - // arch::sbi::sbi_ecall(1, 0, '1'); // AP entered kernel_main - - while (ap_boot_sync.load(__ATOMIC_ACQUIRE) == 0) - ; - - // arch::sbi::sbi_ecall(1, 0, '2'); // AP passed ap_boot_sync - - // --- Per-CPU init (must happen before any printk!) --- - // early_pgdir doesn't map UART MMIO, so we MUST switch to - // BSP's kernel page table before any console output. - vmm_init_ap(); // Switch to BSP-built kernel page table - - // arch::sbi::sbi_ecall(1, 0, '3'); // vmm_init_ap done - - trap_init_ap(); // Install stvec on this CPU - - // arch::sbi::sbi_ecall(1, 0, '4'); // trap_init_ap done - - printk(KERN_INFO "boot: AP online, cpu_id=%llu\n", cpu_id); - - sched_init_ap(); // Init per-CPU RunQueue, create Idle Task - - // arch::sbi::sbi_ecall(1, 0, '5'); // sched_init_ap done - - timer_init_ap(); // Start this CPU's timer interrupt - arch::cpu::software_intr_on(); // Enable S-mode software interrupts for IPI - arch::cpu::external_intr_on(); // Enable S-mode external interrupts for PLIC (UART) - - // AP is now a fully functional scheduler CPU. - // Enable interrupts — first timer tick preempts into idle loop. - arch::cpu::intr_on(); - - printk(KERN_INFO "boot: AP cpu_id=%llu fully initialized\n", cpu_id); - } - - // All CPUs reach here. - // The "current task" is the boot stub (bsp_task or ap_task, pid=-1). - // We must hand off to the scheduler's idle task by calling schedule(). - // Without this, the BSP runs as bsp_task (O1 class, timeslice=20 ticks) - // instead of the idle task (which yields immediately when any task is - // runnable). That delays PID 1 by up to 200ms and can stall entirely - // if no timer tick fires before the first WFI. - { - TaskControlBlock *self = current_task(); - if (self) { - self->state = TaskState::Dead; // Boot stub is done; don't re-enqueue - } - schedule(); // Switch to idle task (or init if it's already runnable) - } - - // Should not reach here — schedule() switches away permanently. - // But just in case, spin with WFI as a safety net. - while (true) { - arch::cpu::halt_until_interrupt(); - } -} diff --git a/kernel/pgrp.cc b/kernel/pgrp.cc deleted file mode 100644 index e5b382c..0000000 --- a/kernel/pgrp.cc +++ /dev/null @@ -1,148 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Process Group / Session Implementation - * - * Hash table of signal_struct objects keyed by pgid. Lifecycle of - * signal_struct mirrors Linux: one per thread group, refcounted across - * CLONE_THREAD siblings, freed when the last task in the group exits. - * - * Reference: Linux kernel/pid.c, kernel/exit.c - */ - -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* Hash table state */ -/* ================================================================== */ - -list_node g_pgrp_hash[kPgrpHashSize]; -Spinlock g_pgrp_lock; - -void pgrp_init() -{ - for (auto& bucket : g_pgrp_hash) bucket.init(); - g_pgrp_lock.init("pgrp"); -} - -/* ================================================================== */ -/* Internal helpers (must be called with g_pgrp_lock held) */ -/* ================================================================== */ - -static void pgrp_attach_locked(signal_struct* sig, int32 pgid) -{ - sig->pgid = pgid; - list_node* bucket = &g_pgrp_hash[pgrp_hash_idx(pgid)]; - sig->pgrp_link.prev = bucket->prev; - sig->pgrp_link.next = bucket; - bucket->prev->next = &sig->pgrp_link; - bucket->prev = &sig->pgrp_link; -} - -static void pgrp_detach_locked(signal_struct* sig) -{ - /* Unlink only if currently on a list — init() makes prev/next point - * to self, which we treat as "not linked". */ - if (sig->pgrp_link.next == &sig->pgrp_link) return; - sig->pgrp_link.prev->next = sig->pgrp_link.next; - sig->pgrp_link.next->prev = sig->pgrp_link.prev; - sig->pgrp_link.init(); -} - -/* ================================================================== */ -/* signal_struct allocation / refcount */ -/* ================================================================== */ - -signal_struct* alloc_signal_struct(int32 leader_pid, TaskControlBlock* leader) -{ - auto* sig = new signal_struct; - if (!sig) return nullptr; - sig->init(leader_pid, leader); - - LockGuard guard(g_pgrp_lock); - pgrp_attach_locked(sig, leader_pid); - return sig; -} - -signal_struct* fork_signal_struct(signal_struct* parent, - TaskControlBlock* child_leader) -{ - if (!parent) return nullptr; - - auto* sig = new signal_struct; - if (!sig) return nullptr; - - /* Copy identity from parent, then override leader and attach. */ - sig->lock.init("signal"); - sig->refcount = 1; - sig->leader = child_leader; - sig->tty_old_pgrp = 0; - sig->pgrp_link.init(); - - { - LockGuard pg(parent->lock); - sig->pgid = parent->pgid; - sig->sid = parent->sid; - sig->tty = parent->tty; - } - - LockGuard guard(g_pgrp_lock); - pgrp_attach_locked(sig, sig->pgid); - return sig; -} - -void get_signal_struct(signal_struct* sig) -{ - if (!sig) return; - LockGuard guard(sig->lock); - sig->refcount++; -} - -void put_signal_struct(signal_struct* sig) -{ - if (!sig) return; - - uint32 remaining; - { - LockGuard guard(sig->lock); - remaining = --sig->refcount; - } - if (remaining != 0) return; - - /* Last reference — detach from pgrp hash and free. */ - { - LockGuard guard(g_pgrp_lock); - pgrp_detach_locked(sig); - } - delete sig; -} - -/* ================================================================== */ -/* Pgrp membership change */ -/* ================================================================== */ - -void change_pgid(signal_struct* sig, int32 new_pgid) -{ - if (!sig) return; - LockGuard guard(g_pgrp_lock); - if (sig->pgid == new_pgid) return; - pgrp_detach_locked(sig); - pgrp_attach_locked(sig, new_pgid); -} - -int pgrp_member_count(int32 pgid) -{ - LockGuard guard(g_pgrp_lock); - int n = 0; - list_node* bucket = &g_pgrp_hash[pgrp_hash_idx(pgid)]; - for (list_node* node = bucket->next; node != bucket; node = node->next) { - auto* sig = list_entry(node); - if (sig->pgid == pgid) n++; - } - return n; -} diff --git a/kernel/pid.cc b/kernel/pid.cc deleted file mode 100644 index 04b846b..0000000 --- a/kernel/pid.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * PID Allocator — Bitmap-based O(1) block search - * Reference: docs/specs/task.md §3.2 - */ - -#include - -void PidAllocator::init() -{ - for (int i = 0; i < kBitmapWords; i++) - bitmap_[i] = 0; - next_hint_ = 1; - bitmap_[0] |= 0x1ULL; /* Reserve PID 0 (idle/swapper) only. - * PID 1 (init) is allocated normally — the first - * kthread_create() call gets it, matching Linux. */ -} - -int32 PidAllocator::alloc() -{ - LockGuard guard(lock_); - - int32 word_start = next_hint_ / 64; - - for (int32 passes = 0; passes < kBitmapWords; passes++) { - int32 w = (word_start + passes) % kBitmapWords; - uint64 free_bits = ~bitmap_[w]; - if (free_bits == 0) - continue; - - int bit = 0; - uint64 v = free_bits; - while ((v & 1ULL) == 0) { v >>= 1; bit++; } - int32 pid = w * 64 + bit; - - if (pid >= kMaxPid) - continue; - - bitmap_[w] |= (1ULL << bit); - next_hint_ = pid + 1; - if (next_hint_ >= kMaxPid) - next_hint_ = 2; - - return pid; - } - - return -1; -} - -void PidAllocator::free(int32 pid) -{ - if (pid < 0 || pid >= kMaxPid) - return; - - LockGuard guard(lock_); - int32 w = pid / 64; - int32 bit = pid % 64; - bitmap_[w] &= ~(1ULL << bit); -} - -PidAllocator g_pid_alloc; diff --git a/kernel/poll.cc b/kernel/poll.cc deleted file mode 100644 index 3674491..0000000 --- a/kernel/poll.cc +++ /dev/null @@ -1,250 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * sys_ppoll — POSIX ppoll() implementation. - * - * Linux fs/select.c:do_sys_poll() pattern, simplified for our needs: - * - Two-phase loop: "register-then-check". First pass calls every - * f_op->poll() with a real poll_table so drivers can register their - * wait queues; if any fd is already ready we return immediately. - * Otherwise schedule() until a wq fires (or timeout/signal), then - * re-check with poll_table=nullptr (probe-only). - * - * Limitations vs. Linux: - * - Only a single wait queue per ppoll call is tracked (the first one - * a driver hands to poll_wait). Multi-fd polls work, but only the - * first wq's wake actually re-runs the loop; other fds becoming - * ready won't be noticed until the timer fires or another wake. - * BusyBox interactive shell polls one fd (stdin), so this matches. - * - * Reference: Linux fs/select.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* poll_wait — called by file_operations->poll() implementations */ -/* ================================================================== */ - -void poll_wait(file* /*fp*/, WaitQueue* wq, poll_table* pt) -{ - /* Probe-only pass: pt is null, drivers skip registration. */ - if (!pt || !wq) return; - /* Single-wq design: keep the first one we see. A more complete - * implementation would chain entries onto a list. */ - if (!pt->wq) pt->wq = wq; -} - -/* ================================================================== */ -/* Linux-compatible timespec */ -/* ================================================================== */ - -struct linux_timespec_pp { - int64 tv_sec; - int64 tv_nsec; -}; - -/* - * Convert a timespec into a deadline in jiffies (g_jiffies clock). - * Returns 0 if the input is null (= infinite wait), or a deadline - * jiffy value otherwise. Caller treats 0 deadline as "no timeout". - */ -static uint64 timespec_to_deadline(const linux_timespec_pp* ts) -{ - if (!ts) return 0; - /* g_jiffies advances at 100 Hz (HZ=100) — 1 jiffy = 10 ms */ - uint64 ticks = static_cast(ts->tv_sec) * 100ULL; - ticks += ts->tv_nsec / 10'000'000; /* 10 ms granularity */ - /* Round up sub-jiffy nsec so a tiny timeout doesn't truncate to 0. */ - if (ts->tv_nsec % 10'000'000 != 0) ticks++; - return g_jiffies + ticks; -} - -/* ================================================================== */ -/* do_poll — one scan over all fds */ -/* ================================================================== */ - -/* - * For each fd: look up the file, call its poll() callback. If `pt` is - * non-null, drivers register their wait queues onto it. Returns the - * number of fds that have any non-zero revents. - */ -static int do_poll_scan(pollfd* fds, uint32 nfds, poll_table* pt) -{ - TaskControlBlock* c = current_task(); - files_struct* files = c ? c->files : nullptr; - if (!files) return 0; - int ready = 0; - - for (uint32 i = 0; i < nfds; i++) { - if (fds[i].fd < 0) { - fds[i].revents = 0; - continue; - } - file* fp = fcheck(files, fds[i].fd); - if (!fp) { - fds[i].revents = POLLNVAL; - ready++; - continue; - } - uint32 mask = 0; - if (fp->f_op && fp->f_op->poll) { - mask = fp->f_op->poll(fp, pt); - } else { - /* No poll handler — treat as always readable/writable so - * a missing implementation doesn't permanently block sh. */ - mask = POLLIN | POLLOUT; - } - /* Filter: revents always include error/hup; userland event bits - * only set if requested in events. */ - uint32 always = POLLERR | POLLHUP | POLLNVAL; - uint32 want = static_cast(fds[i].events) | always; - fds[i].revents = static_cast(mask & want); - if (fds[i].revents) ready++; - } - return ready; -} - -/* ================================================================== */ -/* sys_ppoll */ -/* ================================================================== */ - -/* - * a0 = struct pollfd __user *ufds - * a1 = nfds_t nfds - * a2 = const struct __kernel_timespec __user *tsp (nullable = infinite) - * a3 = const sigset_t __user *sigmask (nullable = no override) - * a4 = size_t sigsetsize - */ -int64 sys_ppoll(uint64 a0, uint64 a1, uint64 a2, uint64 a3, - uint64 a4, uint64 /*a5*/) -{ - uint64 ufds = a0; - uint32 nfds = static_cast(a1); - uint64 utsp = a2; - uint64 usigmask = a3; - uint64 sigsetsize = a4; - - if (nfds > 1024) return -EINVAL; /* Linux RLIMIT_NOFILE-ish cap */ - if (usigmask && sigsetsize != sizeof(sigset_t)) return -EINVAL; - - /* Copy timespec from user. Null pointer means "wait forever". */ - bool have_timeout = (utsp != 0); - linux_timespec_pp ts{}; - if (have_timeout) { - if (copy_from_user(&ts, utsp, sizeof(ts)) < 0) return -EFAULT; - if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= 1'000'000'000) - return -EINVAL; - } - uint64 deadline = have_timeout ? timespec_to_deadline(&ts) : 0; - - /* Apply temporary sigmask if requested. Linux semantics: the new - * mask is in effect for the duration of the call; on return we - * restore the old mask. If a signal interrupts us mid-wait, the - * original mask is restored before returning -EINTR. */ - TaskControlBlock* curr = current_task(); - sigset_t saved_mask{}; - bool mask_swapped = false; - if (usigmask && curr && curr->sighand) { - sigset_t newmask{}; - if (copy_from_user(&newmask, usigmask, sizeof(newmask)) < 0) - return -EFAULT; - newmask.del(SIGKILL); - newmask.del(SIGSTOP); - LockGuard guard(curr->sighand->siglock); - saved_mask = curr->blocked; - curr->blocked = newmask; - mask_swapped = true; - } - - /* Copy pollfd array from user. Allocate a kernel buffer; for the - * common nfds<=8 case this is one slab object. */ - pollfd* kfds = nullptr; - uint64 fds_bytes = static_cast(nfds) * sizeof(pollfd); - int64 ret = 0; - - if (nfds > 0) { - kfds = static_cast(operator new[](fds_bytes)); - if (!kfds) { ret = -ENOMEM; goto out_restore_mask; } - if (copy_from_user(kfds, ufds, fds_bytes) < 0) { - ret = -EFAULT; goto out_free; - } - } - - /* The main poll loop. */ - { - poll_table pt{}; - pt.wq = nullptr; - int n_ready = do_poll_scan(kfds, nfds, &pt); - - while (n_ready == 0) { - /* Timeout==0 means non-blocking probe. */ - if (have_timeout && deadline <= g_jiffies) break; - - /* No registered wait queue? Nothing to sleep on. This - * happens when no fd has a poll handler that calls - * poll_wait — fall back to a short reschedule loop so we - * don't burn the CPU. */ - if (!pt.wq) { - schedule(); - if (signal_pending(curr)) { ret = -EINTR; goto out_free; } - pt.wq = nullptr; - n_ready = do_poll_scan(kfds, nfds, &pt); - continue; - } - - /* Standard prepare-check-schedule pattern. */ - pt.wq->prepare_to_wait(curr, TaskState::Sleeping); - - /* Re-probe with pt=nullptr (no extra registration) so we - * see any state change that arrived between the previous - * scan and prepare_to_wait. */ - n_ready = do_poll_scan(kfds, nfds, nullptr); - if (n_ready > 0) { - pt.wq->finish_wait(curr); - break; - } - if (signal_pending(curr)) { - pt.wq->finish_wait(curr); - ret = -EINTR; goto out_free; - } - - schedule(); - pt.wq->finish_wait(curr); - - /* Reset the registration and rescan — drivers may register - * fresh wait queues this pass. */ - pt.wq = nullptr; - n_ready = do_poll_scan(kfds, nfds, &pt); - } - ret = n_ready; - } - - /* Copy revents back to user (events bits stay as user wrote them). */ - if (nfds > 0) { - if (copy_to_user(ufds, kfds, fds_bytes) < 0) ret = -EFAULT; - } - -out_free: - if (kfds) operator delete[](kfds); - -out_restore_mask: - if (mask_swapped && curr && curr->sighand) { - LockGuard guard(curr->sighand->siglock); - curr->blocked = saved_mask; - } - return ret; -} diff --git a/kernel/ptrace.cc b/kernel/ptrace.cc deleted file mode 100644 index 3280c07..0000000 --- a/kernel/ptrace.cc +++ /dev/null @@ -1,92 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * PtRegs ↔ TrapFrame conversion - * - * This is the ONLY file that knows both the internal TrapFrame layout - * and the Linux-ABI PtRegs layout. When TrapFrame is restructured - * (e.g., to embed pt_regs directly), only this file needs to change. - */ - -#include -#include - -void trapframe_to_pt_regs(PtRegs* dst, const arch::TrapFrame* src, - uint64 scause, uint64 stval) -{ - dst->epc = src->epc; - dst->ra = src->ra; - dst->sp = src->sp; - dst->gp = src->gp; - dst->tp = src->tp; - dst->t0 = src->t[0]; - dst->t1 = src->t[1]; - dst->t2 = src->t[2]; - dst->s0 = src->s[0]; - dst->s1 = src->s[1]; - dst->a0 = src->a[0]; - dst->a1 = src->a[1]; - dst->a2 = src->a[2]; - dst->a3 = src->a[3]; - dst->a4 = src->a[4]; - dst->a5 = src->a[5]; - dst->a6 = src->a[6]; - dst->a7 = src->a[7]; - dst->s2 = src->s[2]; - dst->s3 = src->s[3]; - dst->s4 = src->s[4]; - dst->s5 = src->s[5]; - dst->s6 = src->s[6]; - dst->s7 = src->s[7]; - dst->s8 = src->s[8]; - dst->s9 = src->s[9]; - dst->s10 = src->s[10]; - dst->s11 = src->s[11]; - dst->t3 = src->t[3]; - dst->t4 = src->t[4]; - dst->t5 = src->t[5]; - dst->t6 = src->t[6]; - dst->status = src->sstatus; - dst->badaddr = stval; - dst->cause = scause; - dst->orig_a0 = src->a[0]; /* Caller should set this before syscall dispatch */ -} - -void pt_regs_to_trapframe(arch::TrapFrame* dst, const PtRegs* src) -{ - dst->epc = src->epc; - dst->ra = src->ra; - dst->sp = src->sp; - dst->gp = src->gp; - dst->tp = src->tp; - dst->t[0] = src->t0; - dst->t[1] = src->t1; - dst->t[2] = src->t2; - dst->s[0] = src->s0; - dst->s[1] = src->s1; - dst->a[0] = src->a0; - dst->a[1] = src->a1; - dst->a[2] = src->a2; - dst->a[3] = src->a3; - dst->a[4] = src->a4; - dst->a[5] = src->a5; - dst->a[6] = src->a6; - dst->a[7] = src->a7; - dst->s[2] = src->s2; - dst->s[3] = src->s3; - dst->s[4] = src->s4; - dst->s[5] = src->s5; - dst->s[6] = src->s6; - dst->s[7] = src->s7; - dst->s[8] = src->s8; - dst->s[9] = src->s9; - dst->s[10] = src->s10; - dst->s[11] = src->s11; - dst->t[3] = src->t3; - dst->t[4] = src->t4; - dst->t[5] = src->t5; - dst->t[6] = src->t6; - dst->sstatus = src->status; - /* badaddr and cause are CSR values, not written back to TrapFrame */ -} diff --git a/kernel/sched_class_o1.cc b/kernel/sched_class_o1.cc deleted file mode 100644 index 28c693c..0000000 --- a/kernel/sched_class_o1.cc +++ /dev/null @@ -1,81 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * O(1) Priority Bitmap Scheduling Class - */ - -#include -#include -#include -#include -#include - -static void o1_init_rq(RunQueue* rq) -{ - rq->o1().init(); -} - -static void o1_enqueue_task(RunQueue* rq, TaskControlBlock* task) -{ - rq->o1().enqueue(task); - rq->inc_running(); -} - -static void o1_dequeue_task(RunQueue* rq, TaskControlBlock* task) -{ - rq->o1().dequeue(task); - rq->dec_running(); -} - -static TaskControlBlock* o1_pick_next_task(RunQueue* rq) -{ - return rq->o1().pick_next(); -} - -static void o1_put_prev_task(RunQueue* /*rq*/, TaskControlBlock* /*task*/) {} - -int32 priority_to_timeslice(uint8 priority) -{ - int32 ts = 20 - static_cast(priority) * 19 / 31; - if (ts < 1) ts = 1; - return ts; -} - -static void o1_task_tick(RunQueue* rq, TaskControlBlock* curr) -{ - if (curr == rq->idle()) { - /* Idle task: if anything is runnable, yield immediately */ - if (rq->nr_running() > 0) { - rq->set_need_resched(true); - } - return; - } - - curr->time_slice--; - if (curr->time_slice <= 0) { - curr->time_slice = priority_to_timeslice(curr->priority); - rq->set_need_resched(true); - } -} - -static void o1_yield_task(RunQueue* rq, TaskControlBlock* curr) -{ - if (curr == rq->idle()) - return; - - curr->time_slice = 0; - rq->set_need_resched(true); -} - -const SchedClass g_sched_class_o1 = { - .name = "o1", - .next = &g_sched_class_idle, - .init_rq = o1_init_rq, - .enqueue_task = o1_enqueue_task, - .dequeue_task = o1_dequeue_task, - .pick_next_task = o1_pick_next_task, - .put_prev_task = o1_put_prev_task, - .task_tick = o1_task_tick, - .yield_task = o1_yield_task, -}; diff --git a/kernel/sched_core.cc b/kernel/sched_core.cc deleted file mode 100644 index c0e068e..0000000 --- a/kernel/sched_core.cc +++ /dev/null @@ -1,571 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Scheduler Core - * - * The core walks sched_class chain to pick the next task. Each class - * owns its own runqueue data and policy. This file owns the per-CPU - * runqueue array and the scheduling state machine. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Assembly trampoline symbol (MD layer) */ -extern "C" void kthread_entry_trampoline(); - -/* Per-CPU runqueue array */ -static RunQueue g_rq[kMaxCpus]; - -/* sched_class chain head (highest priority first) */ -static const SchedClass* g_sched_class_head = &g_sched_class_o1; - -/* ======================================================================== - * Idle thread - * ======================================================================== */ - -static void idle_thread_func(void* /*arg*/) -{ - while (true) { - if (g_rq[arch::cpu::id()].need_resched()) { - schedule(); - } - arch::cpu::intr_on(); - arch::cpu::halt_until_interrupt(); - } -} - - -/* ======================================================================== - * Idle class (always returns idle task) - * ======================================================================== */ - -static void idle_init_rq(RunQueue* /*rq*/) {} -static void idle_enqueue(RunQueue* /*rq*/, TaskControlBlock* /*task*/) {} -static void idle_dequeue(RunQueue* /*rq*/, TaskControlBlock* /*task*/) {} -static TaskControlBlock* idle_pick_next(RunQueue* rq) { return rq->idle(); } -static void idle_put_prev(RunQueue* /*rq*/, TaskControlBlock* /*task*/) {} -static void idle_task_tick(RunQueue* /*rq*/, TaskControlBlock* /*curr*/) {} -static void idle_yield(RunQueue* /*rq*/, TaskControlBlock* /*curr*/) {} - -const SchedClass g_sched_class_idle = { - .name = "idle", - .next = nullptr, - .init_rq = idle_init_rq, - .enqueue_task = idle_enqueue, - .dequeue_task = idle_dequeue, - .pick_next_task = idle_pick_next, - .put_prev_task = idle_put_prev, - .task_tick = idle_task_tick, - .yield_task = idle_yield, -}; - -/* ======================================================================== - * Internal helpers - * ======================================================================== */ - -static RunQueue* rq_for_cpu(uint32 cpu_id) -{ - return &g_rq[cpu_id]; -} - -static RunQueue* this_rq() -{ - return rq_for_cpu(arch::cpu::id()); -} - -static TaskControlBlock* pick_next_task(RunQueue* rq) -{ - for (const SchedClass* c = g_sched_class_head; c; c = c->next) { - TaskControlBlock* t = c->pick_next_task(rq); - if (t) { - return t; - } - } - return rq->idle(); -} - -static const char* idle_name_for_cpu(uint32 cpu) -{ - static char names[kMaxCpus][16]; - if (cpu >= kMaxCpus) { - kernel_panic("sched: cpu_id out of range"); - } - - if (names[cpu][0] == '\0') { - ksnprintf(names[cpu], sizeof(names[cpu]), "idle/%u", cpu); - } - return names[cpu]; -} - -/* ======================================================================== - * Kernel thread entry — MI-layer function called by MD trampoline - * ======================================================================== */ - -/* Forward declaration — C++ linkage (task.cc) */ -void task_exit(int code); - -extern "C" void kthread_entry(void (*entry)(void*), void* arg) -{ - RunQueue* rq = this_rq(); - rq->lock().release(); - - arch::cpu::intr_on(); - - entry(arg); - - /* Entry function returned — clean exit (release PID, stack, TCB) */ - task_exit(0); - __builtin_unreachable(); -} - -/* ======================================================================== - * fork_child_entry — called from ret_from_fork assembly - * ======================================================================== */ -extern "C" void userret(arch::TrapFrame* tf); -extern "C" void trap_vector(); - -extern "C" void fork_child_entry(arch::TrapFrame* tf) -{ - RunQueue* rq = this_rq(); - rq->lock().release(); - - /* Set stvec to trap_vector for user-mode traps, then return to user */ - arch::trap::set_vector(reinterpret_cast(trap_vector)); - userret(tf); - - __builtin_unreachable(); -} - -/* ======================================================================== - * alloc_task — canonical TCB allocator (defined in task.cc) - * - * Single point of initialization for TaskControlBlock. Ensures all - * fields are properly zeroed when the struct gains new members. - * ======================================================================== */ - -extern TaskControlBlock* alloc_task(const char* name, uint8 priority, - uint8 flags, uint8 cpu); - -/* ======================================================================== - * Public API: current_task() - * ======================================================================== */ - -TaskControlBlock* current_task() -{ - return this_rq()->current(); -} - -/* ======================================================================== - * Public API: sched_enqueue / sched_dequeue - * ======================================================================== */ - -void sched_enqueue(TaskControlBlock* task) -{ - RunQueue* rq = rq_for_cpu(task->cpu_id); - LockGuard guard(rq->lock()); - - if (!task->sched_class) { - task->sched_class = &g_sched_class_o1; - } - if (!task->sched_entity) { - task->sched_entity = &task->run_link; - } - - task->sched_class->enqueue_task(rq, task); - - if (rq->current() == rq->idle() || task->priority < rq->current()->priority) { - rq->set_need_resched(true); - } -} - -void sched_dequeue(TaskControlBlock* task) -{ - RunQueue* rq = rq_for_cpu(task->cpu_id); - LockGuard guard(rq->lock()); - - if (!task->sched_class) { - task->sched_class = &g_sched_class_o1; - } - task->sched_class->dequeue_task(rq, task); -} - -/* ======================================================================== - * schedule() — main scheduling entry point - * ======================================================================== */ - -void schedule() -{ - RunQueue* rq = this_rq(); - rq->lock().acquire(); - - TaskControlBlock* prev = rq->current(); - - if (prev && prev->state == TaskState::Running) { - prev->state = TaskState::Runnable; - prev->sched_class->enqueue_task(rq, prev); - } else if (prev) { - prev->sched_class->put_prev_task(rq, prev); - } - - TaskControlBlock* next = pick_next_task(rq); - - if (prev == next) { - /* We picked the same task. It must be Running again. */ - next->state = TaskState::Running; - next->sched_class->dequeue_task(rq, next); - rq->clear_need_resched(); - rq->lock().release(); - return; - } - - if (next != rq->idle()) { - next->sched_class->dequeue_task(rq, next); - } - - next->state = TaskState::Running; - rq->set_current(next); - rq->clear_need_resched(); - - /* Switch address space (satp) if the new task has a different mm. - * Kernel threads (mm == nullptr) borrow the previous task's mm, - * so no satp switch is needed — this matches Linux's lazy TLB behavior. */ - { - VmSpace* prev_mm = prev ? prev->mm : nullptr; - VmSpace* next_mm = next->mm; - uint32 cpu = static_cast(arch::cpu::id()); - - if (next_mm && next_mm != prev_mm) { - /* Switching TO a user process with a different address space. - * Linux: switch_mm_irqs_off() in arch/riscv/mm/context.c - * sets satp and flushes TLB. */ - arch::mmu::set_page_table(next_mm->root_pa); - arch::mmu::flush_tlb_all(); - next_mm->cpu_mask.fetch_or(1ULL << cpu, __ATOMIC_RELAXED); - - /* Critical: update TrapFrame's kernel_satp so that trap_vector.S - * restores the correct page table on next trap entry. - * Without this, a process migrated to a new CPU would have its - * trap entry use a stale satp from when trapframe_init_user() - * was called, pointing to whatever page table was active then - * on the ORIGINAL CPU. */ - if (next->trapframe) { - next->trapframe->kernel_satp = arch::mmu::read_satp(); - } - } - - if (prev_mm && prev_mm != next_mm) { - /* Leaving prev's address space — clear our bit */ - prev_mm->cpu_mask.fetch_and(~(1ULL << cpu), __ATOMIC_RELAXED); - } - } - - /* FPU lazy save/restore. - * Save prev's FP registers only if they were modified (FS=Dirty). - * Restore next's FP state for user tasks; disable FPU for kthreads. */ - if (arch::fpu_state_dirty(arch::fpu_get_fs())) { - fpu_save(&prev->fpstate); - } - if (next->mm != nullptr) { - arch::fpu_set_fs(arch::kSstatusFS_Clean); - fpu_restore(&next->fpstate); - } else { - arch::fpu_set_fs(arch::kSstatusFS_Off); - } - - arch::context_switch(&prev->context, &next->context); - - rq->lock().release(); -} - -/* ======================================================================== - * sched_tick() — called from timer interrupt (MI trap layer) - * ======================================================================== */ - -void sched_tick() -{ - RunQueue* rq = this_rq(); - { - LockGuard guard(rq->lock()); - TaskControlBlock* curr = rq->current(); - if (!curr) return; - curr->sched_class->task_tick(rq, curr); - } - - /* Periodic load balancing — runs without holding rq lock */ - sched_balance(); -} - -/* ======================================================================== - * sched_check_preempt() — called from trap return path - * - * Only preempts if: - * 1. need_resched flag is set (a higher-priority task is ready) - * 2. preempt_count == 0 (no spinlocks held, safe to context switch) - * ======================================================================== */ - -void sched_check_preempt() -{ - RunQueue* rq = this_rq(); - if (!rq->need_resched()) return; - - TaskControlBlock* curr = current_task(); - if (curr && curr->preempt_count > 0) { - /* Cannot preempt — caller is in a critical section. - * The preemption will fire when the last lock is released. */ - return; - } - schedule(); -} - -/* ======================================================================== - * sched_yield() — voluntary yield - * ======================================================================== */ - -void sched_yield() -{ - RunQueue* rq = this_rq(); - { - LockGuard guard(rq->lock()); - TaskControlBlock* curr = rq->current(); - if (curr && curr != rq->idle()) { - curr->sched_class->yield_task(rq, curr); - rq->set_need_resched(true); - } - } - schedule(); -} - -/* ======================================================================== - * sched_init() — BSP initialization - * ======================================================================== */ - -void sched_init() -{ - for (int i = 0; i < kMaxCpus; i++) { - RunQueue* rq = &g_rq[i]; - rq->init(static_cast(i)); - - g_sched_class_o1.init_rq(rq); - g_sched_class_idle.init_rq(rq); - } - - g_sched_class_head = &g_sched_class_o1; - - uint64 bsp_cpu = arch::cpu::id(); - uint8 bsp_cpu8 = static_cast(bsp_cpu); - - TaskControlBlock* idle0 = alloc_task(idle_name_for_cpu(static_cast(bsp_cpu)), - kIdlePriority, - TF_KTHREAD | TF_IDLE, bsp_cpu8); - if (!idle0) kernel_panic("sched_init: failed to create idle/bsp"); - - idle0->pid = 0; - idle0->tgid = 0; - idle0->sched_class = &g_sched_class_idle; - idle0->sched_entity = nullptr; - - uint64 stack_top = idle0->kstack_va + kKernelStackSize - - sizeof(arch::TrapFrame); - idle0->context = {}; - idle0->context.ra = reinterpret_cast(kthread_entry_trampoline); - idle0->context.sp = stack_top; - idle0->context.s[0] = reinterpret_cast(idle_thread_func); - idle0->context.s[1] = 0; - - g_rq[bsp_cpu].set_idle(idle0); - - TaskControlBlock* bsp_task = alloc_task("kernel_main", 0, TF_KTHREAD, bsp_cpu8); - if (!bsp_task) kernel_panic("sched_init: failed to create bsp_task"); - - bsp_task->pid = -1; - bsp_task->tgid = -1; - bsp_task->state = TaskState::Running; - - g_rq[bsp_cpu].set_current(bsp_task); -} - -/* ======================================================================== - * sched_init_ap() — AP per-CPU initialization - * ======================================================================== */ - -void sched_init_ap() -{ - uint64 cpu = arch::cpu::id(); - - const char* name = idle_name_for_cpu(static_cast(cpu)); - - TaskControlBlock* idle = alloc_task(name, kIdlePriority, - TF_KTHREAD | TF_IDLE, - static_cast(cpu)); - if (!idle) kernel_panic("sched_init_ap: failed to create idle"); - - idle->pid = 0; - idle->tgid = 0; - idle->sched_class = &g_sched_class_idle; - idle->sched_entity = nullptr; - - uint64 stack_top = idle->kstack_va + kKernelStackSize - - sizeof(arch::TrapFrame); - idle->context = {}; - idle->context.ra = reinterpret_cast(kthread_entry_trampoline); - idle->context.sp = stack_top; - idle->context.s[0] = reinterpret_cast(idle_thread_func); - idle->context.s[1] = 0; - - g_rq[cpu].set_idle(idle); - - TaskControlBlock* ap_task = alloc_task("ap_boot", 0, TF_KTHREAD, - static_cast(cpu)); - if (!ap_task) kernel_panic("sched_init_ap: failed to create ap_task"); - - ap_task->pid = -1; - ap_task->tgid = -1; - ap_task->state = TaskState::Running; - - g_rq[cpu].set_current(ap_task); -} - -/* ======================================================================== - * sched_nr_running() — runnable task count for a CPU - * ======================================================================== */ - -uint32 sched_nr_running(uint32 cpu_id) -{ - if (cpu_id >= kMaxCpus) return 0; - return g_rq[cpu_id].o1().nr_running(); -} - -/* ======================================================================== - * sched_migrate_task() — move a task between CPUs - * - * Locks are acquired in cpu_id order to prevent ABBA deadlock. - * The task must be Runnable (in a runqueue) and not currently running. - * ======================================================================== */ - -int sched_migrate_task(TaskControlBlock* task, uint8 target_cpu) -{ - if (!task || target_cpu >= kMaxCpus) return -22; /* -EINVAL */ - - uint8 src_cpu = task->cpu_id; - if (src_cpu == target_cpu) return 0; /* already there */ - - /* Cannot migrate idle or currently-running tasks */ - if (task->flags & TF_IDLE) return -22; - - RunQueue* src_rq = rq_for_cpu(src_cpu); - RunQueue* dst_rq = rq_for_cpu(target_cpu); - - /* Ordered lock acquisition: always lock lower cpu_id first */ - if (src_cpu < target_cpu) { - src_rq->lock().acquire(); - dst_rq->lock().acquire(); - } else { - dst_rq->lock().acquire(); - src_rq->lock().acquire(); - } - - int ret = -22; - - /* Double-check: task must not be current on either CPU */ - if (task != src_rq->current() && task->state == TaskState::Runnable) { - /* Dequeue from source */ - task->sched_class->dequeue_task(src_rq, task); - - /* Update cpu_id and enqueue on destination */ - task->cpu_id = target_cpu; - task->sched_class->enqueue_task(dst_rq, task); - - /* Signal target CPU to reschedule */ - dst_rq->set_need_resched(true); - ret = 0; - } - - /* Release in reverse order */ - if (src_cpu < target_cpu) { - dst_rq->lock().release(); - src_rq->lock().release(); - } else { - src_rq->lock().release(); - dst_rq->lock().release(); - } - - /* If migration succeeded, send reschedule IPI to target */ - if (ret == 0) { - smp_send_reschedule(target_cpu); - } - - return ret; -} - -/* ======================================================================== - * sched_balance() — periodic load balancer (pull model) - * - * Called from sched_tick() context. Looks at all other CPUs and if any - * has 2+ more runnable tasks than the local CPU, pulls one task. - * This is a simplified Linux-style load_balance(). - * ======================================================================== */ - -void sched_balance() -{ - uint32 this_cpu = static_cast(arch::cpu::id()); - uint32 local_load = g_rq[this_cpu].o1().nr_running(); - - /* Only balance if we're idle or lightly loaded */ - if (local_load > 1) return; - - uint32 busiest_cpu = this_cpu; - uint32 busiest_load = local_load; - - /* Find the busiest CPU */ - for (uint32 cpu = 0; cpu < kMaxCpus; cpu++) { - if (cpu == this_cpu) continue; - uint32 load = g_rq[cpu].o1().nr_running(); - if (load > busiest_load) { - busiest_load = load; - busiest_cpu = cpu; - } - } - - /* Only pull if imbalance is >= 2 */ - if (busiest_cpu == this_cpu || busiest_load < local_load + 2) return; - - /* Try to pull one task from the busiest CPU */ - RunQueue* busy_rq = rq_for_cpu(busiest_cpu); - - /* Lock ordering: lower cpu_id first */ - RunQueue* first = (this_cpu < busiest_cpu) - ? &g_rq[this_cpu] : busy_rq; - RunQueue* second = (this_cpu < busiest_cpu) - ? busy_rq : &g_rq[this_cpu]; - - first->lock().acquire(); - second->lock().acquire(); - - /* Re-check after acquiring locks */ - TaskControlBlock* victim = busy_rq->o1().pick_next(); - if (victim && victim != busy_rq->current() - && !(victim->flags & TF_IDLE)) { - victim->sched_class->dequeue_task(busy_rq, victim); - victim->cpu_id = static_cast(this_cpu); - victim->sched_class->enqueue_task(&g_rq[this_cpu], victim); - g_rq[this_cpu].set_need_resched(true); - } - - second->lock().release(); - first->lock().release(); -} diff --git a/kernel/sched_internal.h b/kernel/sched_internal.h deleted file mode 100644 index 514b613..0000000 --- a/kernel/sched_internal.h +++ /dev/null @@ -1,115 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -class O1RunQueue { -public: - void init() { - bitmap_ = 0; - nr_running_ = 0; - for (int p = 0; p < kNumPriorities; p++) { - queues_[p].init(); - } - } - - void enqueue(TaskControlBlock* task) { - int prio = task->priority; - - list_node* head = &queues_[prio]; - task->run_link.prev = head->prev; - task->run_link.next = head; - head->prev->next = &task->run_link; - head->prev = &task->run_link; - - bitmap_ |= (1U << prio); - nr_running_++; - - task->state = TaskState::Runnable; - } - - void dequeue(TaskControlBlock* task) { - int prio = task->priority; - - task->run_link.prev->next = task->run_link.next; - task->run_link.next->prev = task->run_link.prev; - task->run_link.init(); - - if (queues_[prio].is_empty()) { - bitmap_ &= ~(1U << prio); - } - - if (nr_running_ > 0) { - nr_running_--; - } - } - - TaskControlBlock* pick_next() const { - if (bitmap_ == 0) { - return nullptr; - } - - int prio = lume::ctz32(bitmap_); - list_node* node = queues_[prio].next; - return list_entry(node); - } - - uint32 nr_running() const { return nr_running_; } - -private: - uint32 bitmap_ = 0; - list_node queues_[kNumPriorities]; - uint32 nr_running_ = 0; -}; - -class RunQueue { -public: - void init(uint32 cpu_id) { - lock_.init("RunQueue"); - cpu_id_ = cpu_id; - nr_running_ = 0; - need_resched_ = false; - current_ = nullptr; - idle_ = nullptr; - } - - Spinlock& lock() { return lock_; } - - uint32 cpu_id() const { return cpu_id_; } - - uint32 nr_running() const { return nr_running_; } - void inc_running() { nr_running_++; } - void dec_running() { if (nr_running_ > 0) nr_running_--; } - - bool need_resched() const { return need_resched_; } - void set_need_resched(bool v) { need_resched_ = v; } - void clear_need_resched() { need_resched_ = false; } - - TaskControlBlock* current() const { return current_; } - void set_current(TaskControlBlock* task) { current_ = task; } - - TaskControlBlock* idle() const { return idle_; } - void set_idle(TaskControlBlock* task) { idle_ = task; } - - O1RunQueue& o1() { return o1_; } - const O1RunQueue& o1() const { return o1_; } - -private: - Spinlock lock_; - uint32 cpu_id_ = 0; - uint32 nr_running_ = 0; - bool need_resched_ = false; - - TaskControlBlock* current_ = nullptr; - TaskControlBlock* idle_ = nullptr; - - O1RunQueue o1_; -}; diff --git a/kernel/signal.cc b/kernel/signal.cc deleted file mode 100644 index 53d26da..0000000 --- a/kernel/signal.cc +++ /dev/null @@ -1,442 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Signal Delivery — Queue, Dequeue, Default Actions, and do_signal - * - * Implements the core signal infrastructure: - * - send_signal(): enqueue a signal to a task's pending set - * - force_sig_fault(): fault-induced signal (trap handler API) - * - do_signal(): called on return-to-user, delivers pending signals - * - next_signal(): dequeue the highest-priority deliverable signal - * - * Signal frame construction (arch-specific) is in arch/riscv/signal.cc. - * - * Reference: Linux kernel/signal.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Forward declaration: arch-specific signal frame setup */ -int setup_signal_frame(arch::TrapFrame* tf, int signo, - kernel_sigaction* ka, kernel_siginfo* info); - -/* ================================================================== */ -/* sighand_struct lifecycle (refcount-shared, Linux copy_sighand) */ -/* ================================================================== */ - -sighand_struct* alloc_sighand() -{ - auto* sh = new sighand_struct; - if (sh) sh->init(); - return sh; -} - -sighand_struct* copy_sighand(sighand_struct* parent) -{ - /* Linux: kernel/fork.c:copy_sighand() when !CLONE_SIGHAND copies - * the action table verbatim so the child inherits dispositions - * without sharing future modifications. */ - if (!parent) return alloc_sighand(); - auto* sh = new sighand_struct; - if (!sh) return nullptr; - sh->init(); - LockGuard guard(parent->siglock); - for (int i = 0; i < _NSIG; i++) sh->action[i] = parent->action[i]; - return sh; -} - -void get_sighand(sighand_struct* sh) -{ - if (!sh) return; - LockGuard guard(sh->siglock); - sh->refcount++; -} - -void put_sighand(sighand_struct* sh) -{ - if (!sh) return; - uint32 remaining; - { - LockGuard guard(sh->siglock); - remaining = --sh->refcount; - } - if (remaining == 0) delete sh; -} - -/* ================================================================== */ -/* next_signal — find lowest-numbered deliverable signal */ -/* ================================================================== */ - -/* Manual count-trailing-zeros (no libgcc __ctzdi2 dependency) */ -static inline int sig_ctz64(uint64 x) -{ - if (x == 0) return 64; - int n = 0; - if ((x & 0xFFFFFFFF) == 0) { n += 32; x >>= 32; } - if ((x & 0x0000FFFF) == 0) { n += 16; x >>= 16; } - if ((x & 0x000000FF) == 0) { n += 8; x >>= 8; } - if ((x & 0x0000000F) == 0) { n += 4; x >>= 4; } - if ((x & 0x00000003) == 0) { n += 2; x >>= 2; } - if ((x & 0x00000001) == 0) { n += 1; } - return n; -} - -static int next_signal(sigpending* pending, const sigset_t* mask) -{ - /* Standard signals: check bitmap & ~blocked */ - for (int i = 0; i < _NSIG_WORDS; i++) { - uint64 bits = pending->signal.sig[i] & ~mask->sig[i]; - if (bits != 0) { - int sig = i * 64 + sig_ctz64(bits) + 1; - return sig; - } - } - return 0; -} - -/* ================================================================== */ -/* dequeue_signal — remove a signal from the pending set */ -/* ================================================================== */ - -/* - * Dequeue the next deliverable signal. MUST be called with - * task->sighand->siglock held. Mirrors Linux's __dequeue_signal() - * (kernel/signal.c) which requires the same lock. - */ -static int dequeue_signal_locked(TaskControlBlock* task, kernel_siginfo* info) -{ - int sig = next_signal(&task->pending, &task->blocked); - if (sig == 0) return 0; - - /* Clear the bitmap bit */ - task->pending.signal.del(sig); - - /* Search the queue for a matching sigqueue entry */ - list_node* node = task->pending.list.next; - while (node != &task->pending.list) { - auto* q = list_entry(node); - if (q->info.si_signo == sig) { - /* Remove from queue */ - node->prev->next = node->next; - node->next->prev = node->prev; - if (info) *info = q->info; - delete q; - return sig; - } - node = node->next; - } - - /* No queued entry — fill in minimal info */ - if (info) { - info->si_signo = sig; - info->si_errno = 0; - info->si_code = 0; /* SI_USER */ - } - return sig; -} - -/* ================================================================== */ -/* send_signal — enqueue a signal to a task */ -/* ================================================================== */ - -/* - * Drop a queued sigqueue entry with the given signo from `task`. - * - * MUST be called with task->sighand->siglock held — Linux's - * flush_sigqueue_mask() has the same precondition (kernel/signal.c). - */ -static bool discard_pending_locked(TaskControlBlock* task, int signo) -{ - bool any = false; - list_node* node = task->pending.list.next; - while (node != &task->pending.list) { - list_node* nxt = node->next; - auto* q = list_entry(node); - if (q->info.si_signo == signo) { - node->prev->next = node->next; - node->next->prev = node->prev; - delete q; - any = true; - } - node = nxt; - } - task->pending.signal.del(signo); - return any; -} - -static inline bool is_stop_sig(int sig) -{ - return sig == SIGSTOP || sig == SIGTSTP || - sig == SIGTTIN || sig == SIGTTOU; -} - -/* - * send_signal — queue a signal to a task. - * - * Acquires task->sighand->siglock for the full update (bitmap, queue, - * stop/cont side-effects, scheduler wake). Mirrors Linux's - * __send_signal_locked() which also requires this lock (see - * kernel/signal.c:1048 lockdep_assert_held). - * - * Returns 0 on success or a negative errno. - */ -int send_signal(int sig, kernel_siginfo* info, TaskControlBlock* task) -{ - if (sig < 1 || sig > _NSIG) return -EINVAL; - if (!task) return -ESRCH; - if (!task->sighand) return -ESRCH; /* eager-alloc invariant; tasks - * without sighand can't receive - * signals (idle / early kthreads) */ - - LockGuard guard(task->sighand->siglock); - - /* - * Linux's prepare_signal(): a stop signal cancels any pending - * SIGCONT and vice versa, so the most recent decision wins. - */ - if (is_stop_sig(sig)) { - discard_pending_locked(task, SIGCONT); - } else if (sig == SIGCONT) { - discard_pending_locked(task, SIGSTOP); - discard_pending_locked(task, SIGTSTP); - discard_pending_locked(task, SIGTTIN); - discard_pending_locked(task, SIGTTOU); - - /* SIGCONT's resume effect happens atomically with delivery. */ - if (task->state == TaskState::Stopped) { - task->state = TaskState::Runnable; - task->notify_continued = true; - task->stopped_code = 0; - sched_enqueue(task); - if (task->parent) task->parent->wait_chld.wake_all(); - } - } - - /* Already pending? For standard signals, just mark the bitmap */ - if (sig < SIGRTMIN && task->pending.signal.has(sig)) - return 0; - - /* Enqueue a sigqueue entry */ - auto* q = new sigqueue; - if (!q) { - /* Can't allocate — just set the bitmap (signal still delivered) */ - task->pending.signal.add(sig); - return 0; - } - - q->list.init(); - if (info) { - q->info = *info; - } else { - q->info.si_signo = sig; - q->info.si_errno = 0; - q->info.si_code = 0; /* SI_USER */ - } - q->info.si_signo = sig; /* ensure consistent */ - - /* Add to tail of queue */ - list_node* head = &task->pending.list; - q->list.prev = head->prev; - q->list.next = head; - head->prev->next = &q->list; - head->prev = &q->list; - - /* Set bitmap */ - task->pending.signal.add(sig); - - /* Wake the task if it's sleeping in an interruptible wait. */ - if (task->state == TaskState::Sleeping) { - task->state = TaskState::Runnable; - sched_enqueue(task); - } - - /* SIGKILL must run even if the target is Stopped. */ - if (sig == SIGKILL && task->state == TaskState::Stopped) { - task->state = TaskState::Runnable; - task->stopped_code = 0; - sched_enqueue(task); - } - - return 0; -} - -/* ================================================================== */ -/* force_sig_fault — trap handler API */ -/* ================================================================== */ - -void force_sig_fault(int signo, int code, uint64 addr) -{ - TaskControlBlock* curr = current_task(); - if (!curr) return; - - /* Kernel threads cannot handle signals — kill immediately */ - if (curr->flags & TF_KTHREAD) { - pr_err("signal: kernel thread %s received signal %d\n", - curr->name ? curr->name : "(noname)", signo); - task_kill_current(signo); - return; - } - - /* Sighand must already exist for user-mode tasks (allocated at - * fork / kernel_execve time). If it's somehow missing, the only - * safe action is to terminate. */ - if (!curr->sighand) { - pr_err("signal: pid %d has no sighand, killing\n", curr->pid); - task_kill_current(signo); - return; - } - - kernel_siginfo info{}; - info.si_signo = signo; - info.si_code = code; - info._sifields._sigfault._addr = addr; - - /* Force: bypass blocked mask for fatal signals (lock to keep - * blocked-mask updates consistent with sigprocmask). */ - { - LockGuard guard(curr->sighand->siglock); - curr->blocked.del(signo); - } - - send_signal(signo, &info, curr); -} - -/* ================================================================== */ -/* signal_pending — check if unblocked signals are pending */ -/* ================================================================== */ - -bool signal_pending(TaskControlBlock* task) -{ - /* Advisory check (matches Linux's recalc_sigpending() usage): - * callers re-validate under siglock before acting. The bitmap is - * a uint64 word; a torn read can only produce false-positives or - * false-negatives transiently, never a corrupt pointer. */ - if (!task) return false; - sigset_t unblocked = task->pending.signal & ~task->blocked; - return !unblocked.is_empty(); -} - -/* ================================================================== */ -/* do_signal — called before returning to user mode */ -/* ================================================================== */ - -void do_signal(arch::TrapFrame* tf) -{ - TaskControlBlock* curr = current_task(); - if (!curr) return; - - /* Kernel threads never deliver signals via frames */ - if (curr->flags & TF_KTHREAD) return; - - /* No sighand means no signal infrastructure for this task */ - if (!curr->sighand) return; - - while (true) { - kernel_siginfo info{}; - kernel_sigaction ka_copy; - int sig; - - /* - * Take siglock for dequeue + action snapshot. Action processing - * (default actions like SIG_ACT_TERM, or constructing a signal - * frame for a user handler) is done OUTSIDE the lock — it can - * touch user memory and even call schedule(). This matches - * Linux's get_signal() loop in kernel/signal.c: it takes - * siglock around dequeue_signal+ka_copy, drops it before - * dispatching, and re-acquires next iteration. - */ - { - LockGuard guard(curr->sighand->siglock); - sig = dequeue_signal_locked(curr, &info); - if (sig == 0) break; - ka_copy = curr->sighand->action[sig - 1]; - } - kernel_sigaction* ka = &ka_copy; - - /* SIG_IGN: discard */ - if (ka->sa_handler == SIG_IGN && !sig_kernel_only(sig)) - continue; - - /* SIG_DFL: apply default action */ - if (ka->sa_handler == SIG_DFL) { - SigDefaultAction act = sig_default_action(sig); - switch (act) { - case SIG_ACT_IGN: - continue; - case SIG_ACT_TERM: - case SIG_ACT_CORE: - pr_debug_s(KLOG_SUBSYS_SIGNAL, - "signal: pid %d killed by signal %d\n", - curr->pid, sig); - task_kill_current(sig); - return; /* never reached */ - case SIG_ACT_STOP: { - /* - * Enter Stopped state. Record the encoded wstatus so - * the parent's wait4(WUNTRACED) can observe and report. - * The schedule() below does NOT re-enqueue Stopped - * tasks — when SIGCONT eventually arrives, send_signal - * flips us back to Runnable and re-enqueues. - */ - curr->stopped_code = W_STOPCODE(sig); - curr->state = TaskState::Stopped; - if (curr->parent) - curr->parent->wait_chld.wake_all(); - pr_debug_s(KLOG_SUBSYS_SIGNAL, - "signal: pid %d stopped by sig %d\n", - curr->pid, sig); - schedule(); - /* - * Resumed (either by SIGCONT or SIGKILL). Loop back to - * deliver any remaining pending signals before returning - * to user mode. - */ - continue; - } - case SIG_ACT_CONT: - /* SIGCONT's resume side-effect already happened in - * send_signal(). The only thing left at handler time - * is to consume the signal (no-op for SIG_DFL). */ - continue; - } - } - - /* User handler: construct signal frame */ - pr_debug_s(KLOG_SUBSYS_SIGNAL, - "signal: pid %d delivering sig %d handler=%llx\n", - curr->pid, sig, reinterpret_cast(ka->sa_handler)); - int ret = setup_signal_frame(tf, sig, ka, &info); - if (ret < 0) { - pr_err("signal: failed to set up frame for sig %d\n", sig); - task_kill_current(sig); - return; - } - - /* Post-delivery bookkeeping under siglock — both the per-task - * blocked mask and the shared action table (SA_RESETHAND) are - * touched, so we must hold the same lock the senders use. */ - { - LockGuard guard(curr->sighand->siglock); - if (!(ka->sa_flags & SA_NODEFER)) curr->blocked.add(sig); - curr->blocked = curr->blocked | ka->sa_mask; - if (ka->sa_flags & SA_RESETHAND) { - curr->sighand->action[sig - 1].sa_handler = SIG_DFL; - } - } - - /* Only deliver one signal per return-to-user */ - break; - } -} diff --git a/kernel/smp.cc b/kernel/smp.cc deleted file mode 100644 index 1a79ac3..0000000 --- a/kernel/smp.cc +++ /dev/null @@ -1,112 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * smp.cc — SMP IPI implementation - * - * Sending side: atomically set reason bits in target CPU's IpiData, - * then invoke arch-specific IPI delivery (SBI ecall on RISC-V). - * - * Receiving side: smp_handle_ipi() is called from the trap handler - * when an S-mode software interrupt arrives. It atomically consumes - * all pending reason bits and dispatches to the appropriate handler. - * - * Reference: docs/specs/linux_abi_mm_plan.md §SMP §2.2 - */ - -#include -#include -#include -#include -#include -#include - -/* Per-CPU IPI data — BSS zero-initialized */ -IpiData g_ipi_data[kMaxCpus]; - -/* ------------------------------------------------------------------ */ -/* smp_init */ -/* ------------------------------------------------------------------ */ - -void smp_init() -{ - for (uint32 i = 0; i < kMaxCpus; i++) { - g_ipi_data[i].pending.store(0, __ATOMIC_RELAXED); - g_ipi_data[i].tlb_start = 0; - g_ipi_data[i].tlb_end = 0; - } - - printk(KERN_INFO "smp: IPI framework initialized (%u CPUs max)\n", - static_cast(kMaxCpus)); -} - -/* ------------------------------------------------------------------ */ -/* smp_send_ipi — send IPI to target CPUs */ -/* ------------------------------------------------------------------ */ - -void smp_send_ipi(uint64 cpu_mask, uint32 reason) -{ - if (cpu_mask == 0) return; - - /* Set pending bits on each target CPU's IpiData */ - for (uint32 cpu = 0; cpu < kMaxCpus; cpu++) { - if (cpu_mask & (1ULL << cpu)) { - g_ipi_data[cpu].pending.fetch_or(reason, __ATOMIC_RELEASE); - } - } - - /* Deliver hardware interrupt via SBI. - * RISC-V SBI IPI extension sends S-mode software interrupt - * to the specified harts. hart_mask maps 1:1 to cpu_mask - * (assuming hartid == cpu_id, which holds for QEMU virt). */ - arch::sbi::sbi_send_ipi(cpu_mask, 0); -} - -/* ------------------------------------------------------------------ */ -/* smp_handle_ipi — called from trap handler on software interrupt */ -/* ------------------------------------------------------------------ */ - -void smp_handle_ipi() -{ - uint32 cpu = static_cast(arch::cpu::id()); - - /* Clear the S-mode software interrupt pending bit (sip.SSIP). - * On RISC-V, we must clear this in software, otherwise the - * interrupt will keep firing. */ - arch::cpu::clear_sip_ssip(); - - /* Atomically consume all pending reasons */ - uint32 reasons = g_ipi_data[cpu].pending.exchange(0, __ATOMIC_ACQUIRE); - - if (reasons == 0) return; /* Spurious */ - - /* Dispatch each reason */ - - if (reasons & IPI_RESCHEDULE) { - /* Just need to return from interrupt — schedule() will be - * called on the return-from-trap path if need_resched is set. - * For now, set the flag by yielding on next opportunity. */ - /* TODO: set need_resched flag when preemption tracking is added */ - } - - if (reasons & IPI_TLB_SHOOTDOWN) { - /* Execute local TLB flush with the parameters the sender stored */ - uint64 start = g_ipi_data[cpu].tlb_start; - uint64 end = g_ipi_data[cpu].tlb_end; - if (start == 0 && end == 0) { - arch::mmu::flush_tlb_all(); - } else { - for (uint64 va = start; va < end; va += kPageSize) { - arch::mmu::flush_tlb_page(va); - } - } - } - - if (reasons & IPI_HALT) { - printk(KERN_INFO "smp: CPU %u halting by IPI\n", cpu); - arch::cpu::intr_off(); - while (true) { - arch::cpu::halt_until_interrupt(); - } - } -} diff --git a/kernel/sync/cpu_state.h b/kernel/sync/cpu_state.h deleted file mode 100644 index 1f7dde0..0000000 --- a/kernel/sync/cpu_state.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Per-CPU Interrupt Nesting Tracker - * - * Tracks spinlock nesting depth on each CPU to ensure interrupts - * are only restored when the last spinlock is released. - * - * BSS-segment global array; zero-initialized by entry.S BSS clear. - * Reference: docs/specs/spinlock.md §3.1 - */ - -#include -#include - -namespace sync { - -struct CpuSyncState { - int lock_depth; // Number of spinlocks held by this CPU - bool intr_was_on; // Were interrupts enabled before the first lock? -}; - -inline constexpr uint64 kInvalidCpuId = ~0ULL; - -// BSS-segment global array, zero-initialized by entry.S -extern CpuSyncState g_cpu_sync_states[kMaxCpus]; - -// Internal API — called only by Spinlock::acquire/release -void push_intr(); -void pop_intr(); - -} // namespace sync diff --git a/kernel/sync/mutex.cc b/kernel/sync/mutex.cc deleted file mode 100644 index c4d3e9d..0000000 --- a/kernel/sync/mutex.cc +++ /dev/null @@ -1,156 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Mutex — Linux-style sleeping mutex (no PI). - * - * Implementation notes (mirroring kernel/locking/mutex.c, simplified): - * - * - Fast path (uncontended): wait_lock_ -> see owner_==null -> claim -> unlock. - * - Slow path (contended): enqueue MutexWaiter on stack, sleep, race for - * ownership after each wake. unlock() wakes only the head waiter. - * - No optimistic spin, no handoff anti-starvation, no interruptible wait. - * These belong to follow-up work (see mutex.md §5). - * - * Reference: docs/specs/mutex.md - */ - -#include -#include -#include -#include -#include - -namespace { - -struct MutexWaiter { - list_node link; - TaskControlBlock* task; -}; - -} // namespace - -/* ------------------------------------------------------------------ */ -/* init */ -/* ------------------------------------------------------------------ */ - -void Mutex::init(const char* name) -{ - owner_ = nullptr; - name_ = name; - wait_lock_.init(name != nullptr ? name : "mutex"); - wait_list_.init(); -} - -/* ------------------------------------------------------------------ */ -/* try_lock — non-blocking, safe from any context */ -/* ------------------------------------------------------------------ */ - -bool Mutex::try_lock() -{ - LockGuard g(wait_lock_); - if (owner_ != nullptr) { - return false; - } - owner_ = current_task(); - return true; -} - -/* ------------------------------------------------------------------ */ -/* lock — blocking, must be called in schedulable context */ -/* ------------------------------------------------------------------ */ - -void Mutex::lock() -{ - TaskControlBlock* curr = current_task(); - - if (curr == nullptr) { - kernel_panic("Mutex::lock: no current task"); - } - if (curr->preempt_count > 0) { - kernel_panic("Mutex::lock: preemption disabled (holding spinlock?)"); - } - - wait_lock_.acquire(); - - if (owner_ == nullptr) { - owner_ = curr; - wait_lock_.release(); - return; - } - - if (owner_ == curr) { - wait_lock_.release(); - kernel_panic("Mutex::lock: recursive acquire by same task"); - } - - /* Slow path: enqueue ourselves and sleep until we are head + lock free. */ - MutexWaiter waiter; - waiter.link.init(); - waiter.task = curr; - list_add_tail(&waiter.link, &wait_list_); - - for (;;) { - /* Set state inside wait_lock_ so unlock-side sees a coherent view: - * either we are on the list AND Sleeping (will be woken), or we - * already took ownership above (not in this loop). */ - curr->state = TaskState::Sleeping; - wait_lock_.release(); - - schedule(); - - wait_lock_.acquire(); - - if (owner_ == nullptr && wait_list_.next == &waiter.link) { - owner_ = curr; - list_del_init(&waiter.link); - wait_lock_.release(); - return; - } - /* Spurious wake / lost race — keep waiting. */ - } -} - -/* ------------------------------------------------------------------ */ -/* unlock */ -/* ------------------------------------------------------------------ */ - -void Mutex::unlock() -{ - TaskControlBlock* curr = current_task(); - - wait_lock_.acquire(); - - if (owner_ != curr) { - wait_lock_.release(); - kernel_panic("Mutex::unlock: not the owner"); - } - - owner_ = nullptr; - - if (!wait_list_.is_empty()) { - list_node* first = wait_list_.next; - MutexWaiter* w = list_entry(first); - TaskControlBlock* victim = w->task; - - /* Race-tolerant wake: only enqueue if still sleeping. If the - * waiter is already Runnable (e.g. it was already woken by a - * timer-driven schedule reentry and didn't yet retry the lock), - * sched_enqueue would double-link it. */ - if (victim->state == TaskState::Sleeping) { - victim->state = TaskState::Runnable; - sched_enqueue(victim); - } - } - - wait_lock_.release(); -} - -/* ------------------------------------------------------------------ */ -/* Debug accessors */ -/* ------------------------------------------------------------------ */ - -bool Mutex::is_owned_by_current() const -{ - return owner_ == current_task(); -} diff --git a/kernel/sync/spinlock.cc b/kernel/sync/spinlock.cc deleted file mode 100644 index f649fe7..0000000 --- a/kernel/sync/spinlock.cc +++ /dev/null @@ -1,120 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Spinlock Implementation - * - * TTAS (Test-and-Test-and-Set) spinlock with: - * - Acquire: __ATOMIC_ACQUIRE memory ordering - * - Release: __ATOMIC_RELEASE memory ordering - * - Automatic interrupt disable/enable via push_intr/pop_intr - * - Dead-lock and invalid-release detection via kernel_panic - * - * Reference: docs/specs/spinlock.md - */ - -#include "spinlock.h" -#include "cpu_state.h" -#include -#include -#include - -// ============================================================ -// Per-CPU sync state (BSS zero-initialized) -// ============================================================ -namespace sync { - -CpuSyncState g_cpu_sync_states[kMaxCpus]; - -void push_intr() { - bool was_on = arch::cpu::intr_enabled(); - arch::cpu::intr_off(); - - auto& state = g_cpu_sync_states[arch::cpu::id()]; - if (state.lock_depth == 0) { - state.intr_was_on = was_on; - } - state.lock_depth++; -} - -void pop_intr() { - auto& state = g_cpu_sync_states[arch::cpu::id()]; - state.lock_depth--; - - if (state.lock_depth == 0 && state.intr_was_on) { - arch::cpu::intr_on(); - } -} - -} // namespace sync - -// ============================================================ -// Spinlock methods -// ============================================================ - -void Spinlock::init(const char* name) { - name_ = name; - locked_.store(0, __ATOMIC_RELAXED); - cpu_id_ = sync::kInvalidCpuId; -} - -void Spinlock::acquire() { -#ifdef DEBUG - // Optional: detect interrupt-state leakage - if (arch::cpu::intr_enabled()) { - auto& state = sync::g_cpu_sync_states[arch::cpu::id()]; - if (state.lock_depth > 0) { - kernel_panic("spinlock: interrupts enabled while holding lock"); - } - } -#endif - - // Step 1: disable interrupts, track nesting depth - sync::push_intr(); - - // Step 2: dead-lock detection (same CPU re-acquiring) - if (is_held_by_current_cpu()) { - kernel_panic("spinlock: double lock", name_); - } - - // Step 3: TTAS spin loop - while (true) { - // Outer: spin on local cache copy (no bus traffic) - while (locked_.load(__ATOMIC_RELAXED)) - ; - // Inner: attempt atomic exchange with acquire semantics - if (locked_.exchange(1, __ATOMIC_ACQUIRE) == 0) - break; - } - - // Step 4: record owner - cpu_id_ = arch::cpu::id(); - - // Step 5: bump preempt_count — prevents schedule() from preempting - TaskControlBlock* curr = current_task(); - if (curr) curr->preempt_count++; -} - -void Spinlock::release() { - // Step 1: verify caller is the holder - if (!is_held_by_current_cpu()) { - kernel_panic("spinlock: invalid release", name_); - } - - // Step 2: clear owner - cpu_id_ = sync::kInvalidCpuId; - - // Step 3: release the lock with release semantics - locked_.store(0, __ATOMIC_RELEASE); - - // Step 4: drop preempt_count - TaskControlBlock* curr = current_task(); - if (curr) curr->preempt_count--; - - // Step 5: restore interrupt state if this was the last lock - sync::pop_intr(); -} - -bool Spinlock::is_held_by_current_cpu() const { - return cpu_id_ == arch::cpu::id(); -} diff --git a/kernel/sync/spinlock.h b/kernel/sync/spinlock.h deleted file mode 100644 index a1369d1..0000000 --- a/kernel/sync/spinlock.h +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * Spinlock & LockGuard - * - * Provides mutual exclusion for SMP kernels using TTAS - * (Test-and-Test-and-Set) with acquire/release memory ordering. - * Interrupt disable/enable is managed automatically via push_intr/pop_intr. - * - * Reference: docs/specs/spinlock.md - */ - -#include -#include -#include "cpu_state.h" - -class Spinlock { -public: - // Default: BSS zero is safe. Call init() to give the lock a name. - Spinlock() = default; - - // Explicit initialization (for global objects or Placement New) - void init(const char* name); - - // Non-copyable, non-movable (lock identity is its address) - Spinlock(const Spinlock&) = delete; - Spinlock& operator=(const Spinlock&) = delete; - Spinlock(Spinlock&&) = delete; - Spinlock& operator=(Spinlock&&) = delete; - - void acquire(); - void release(); - bool is_held_by_current_cpu() const; - -private: - lume::atomic locked_; // 0 = free, 1 = held - const char* name_ = "uninit"; // Lock name (for panic messages) - uint64 cpu_id_ = sync::kInvalidCpuId; // Holder CPU ID -}; - -class LockGuard { -public: - explicit LockGuard(Spinlock& lock) : lock_(lock) { - lock_.acquire(); - } - - ~LockGuard() { - lock_.release(); - } - - LockGuard(const LockGuard&) = delete; - LockGuard& operator=(const LockGuard&) = delete; - LockGuard(LockGuard&&) = delete; - LockGuard& operator=(LockGuard&&) = delete; - -private: - Spinlock& lock_; -}; diff --git a/kernel/sys_fs.cc b/kernel/sys_fs.cc deleted file mode 100644 index 1d26fdd..0000000 --- a/kernel/sys_fs.cc +++ /dev/null @@ -1,679 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * sys_fs.cc — Filesystem-related syscall handlers - * - * Implements: openat, close, read, write, lseek, fstat, getdents64, - * dup, dup3, getcwd, chdir, mkdirat, unlinkat - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ================================================================== */ -/* Helpers */ -/* ================================================================== */ - -static files_struct* current_files() -{ - TaskControlBlock* t = current_task(); - return t ? t->files : nullptr; -} - -static fs_struct* current_fs() -{ - TaskControlBlock* t = current_task(); - return t ? t->fs : nullptr; -} - -/* ================================================================== */ -/* sys_openat(dirfd, pathname, flags, mode) */ -/* ================================================================== */ - -int64 sys_openat(uint64 a0, uint64 a1, uint64 a2, - uint64 a3, uint64 /*a4*/, uint64 /*a5*/) -{ - int dirfd = static_cast(a0); - const char* pathname = reinterpret_cast(a1); - int flags = static_cast(a2); - uint32 mode = static_cast(a3); - - files_struct* files = current_files(); - if (!files) return -EMFILE; - - - /* Pathname lookup */ - path p{}; - int err = filename_lookup(dirfd, pathname, 0, &p); - - if (err == -ENOENT && (flags & O_CREAT)) { - /* Create: look up the parent directory */ - /* Find last '/' to split parent path / filename */ - const char* last_slash = nullptr; - for (const char* s = pathname; *s; s++) { - if (*s == '/') last_slash = s; - } - - if (!last_slash || last_slash == pathname) { - /* File in root or current directory */ - path parent{}; - if (last_slash == pathname) { - /* Absolute: parent is root */ - parent.de = g_root_dentry; - parent.mnt = g_root_mnt; - } else { - /* Relative: parent is cwd */ - fs_struct* fs = current_fs(); - if (!fs) return -ENOENT; - parent = fs->pwd; - } - - const char* name = last_slash ? last_slash + 1 : pathname; - inode* dir_ip = parent.de->d_inode; - if (!dir_ip || !dir_ip->i_op || !dir_ip->i_op->create) { - return -EACCES; - } - - /* Create the inode via the directory's i_op->create */ - qstr q{}; - q.name = name; - q.len = 0; - for (const char* s = name; *s; s++) q.len++; - dentry* new_de = d_alloc(parent.de, &q); - if (!new_de) return -ENOMEM; - - - err = dir_ip->i_op->create(dir_ip, new_de, mode & ~S_IFMT, false); - if (err) { - /* TODO: free new_de */ - return err; - } - - p.de = new_de; - p.mnt = parent.mnt; - } else { - /* TODO: multi-component parent lookup */ - return -ENOENT; - } - } else if (err) { - return err; - } - - /* Allocate fd */ - int fd = alloc_fd(files, 0); - if (fd < 0) { - return fd; - } - - /* Allocate file object */ - file* fp = alloc_empty_file(flags); - if (!fp) { - /* TODO: release fd */ - return -ENFILE; - } - - fp->f_inode = p.de->d_inode; - fp->f_path = p; - fp->f_op = p.de->d_inode->i_fop; - fp->f_pos = 0; - - /* Chardev: look up cdev by i_rdev and replace f_op */ - if (S_ISCHR(fp->f_inode->i_mode)) { - extern int devfs_chrdev_open(inode* ip, file* fp); - err = devfs_chrdev_open(fp->f_inode, fp); - if (err) { - fput(fp); - return err; - } - } else if (fp->f_op && fp->f_op->open) { - err = fp->f_op->open(fp->f_inode, fp); - if (err) { - fput(fp); - return err; - } - } - - /* O_TRUNC for regular files */ - if ((flags & O_TRUNC) && S_ISREG(fp->f_inode->i_mode)) { - fp->f_inode->i_size = 0; - } - - fd_install(files, fd, fp); - return fd; -} - -/* ================================================================== */ -/* sys_close(fd) */ -/* ================================================================== */ - -int64 sys_close(uint64 a0, uint64 /*a1*/, uint64 /*a2*/, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - files_struct* files = current_files(); - if (!files) return -EBADF; - return close_fd(files, fd); -} - -/* ================================================================== */ -/* sys_read(fd, buf, count) */ -/* ================================================================== */ - -int64 sys_read(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - char* buf = reinterpret_cast(a1); - uint64 count = a2; - - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, fd); - if (!fp) return -EBADF; - - if (!(fp->f_mode & FMODE_READ)) return -EBADF; - - return vfs_read(fp, buf, count, &fp->f_pos); -} - -/* ================================================================== */ -/* sys_write(fd, buf, count) */ -/* ================================================================== */ - -int64 sys_write(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - const char* buf = reinterpret_cast(a1); - uint64 count = a2; - - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, fd); - if (!fp) return -EBADF; - - if (!(fp->f_mode & FMODE_WRITE)) return -EBADF; - - return vfs_write(fp, buf, count, &fp->f_pos); -} - -/* ================================================================== */ -/* sys_lseek(fd, offset, whence) */ -/* ================================================================== */ - -int64 sys_lseek(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - int64 offset = static_cast(a1); - int whence = static_cast(a2); - - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, fd); - if (!fp) return -EBADF; - - return vfs_llseek(fp, offset, whence); -} - -/* ================================================================== */ -/* sys_fstat(fd, statbuf) */ -/* ================================================================== */ - -int64 sys_fstat_wrapper(uint64 a0, uint64 a1, uint64 /*a2*/, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - auto* statbuf = reinterpret_cast(a1); - - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, fd); - if (!fp) return -EBADF; - - return vfs_fstat(fp, statbuf); -} - -/* ================================================================== */ -/* sys_getdents64(fd, dirp, count) */ -/* ================================================================== */ - -struct linux_dirent64 { - uint64 d_ino; - int64 d_off; - uint16 d_reclen; - uint8 d_type; - char d_name[]; -}; - -struct getdents_ctx { - dir_context ctx; - char* buf; - int count; - int written; - int error; -}; - -static bool filldir64(dir_context* ctx, const char* name, int namelen, - int64 offset, uint64 ino, unsigned int d_type) -{ - auto* gctx = container_of(ctx, getdents_ctx, ctx); - - /* Calculate record length (rounded up to 8 bytes) */ - int reclen = static_cast( - (sizeof(linux_dirent64) + namelen + 1 + 7) & ~7ULL); - - if (gctx->written + reclen > gctx->count) { - return false; /* Buffer full */ - } - - auto* dirent = reinterpret_cast( - gctx->buf + gctx->written); - - dirent->d_ino = ino; - dirent->d_off = offset + 1; - dirent->d_reclen = static_cast(reclen); - dirent->d_type = static_cast(d_type); - - /* Copy name */ - for (int i = 0; i < namelen; i++) { - dirent->d_name[i] = name[i]; - } - dirent->d_name[namelen] = '\0'; - - gctx->written += reclen; - return true; -} - -int64 sys_getdents64(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - char* buf = reinterpret_cast(a1); - int count = static_cast(a2); - - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, fd); - if (!fp) return -EBADF; - - if (!fp->f_op || !fp->f_op->iterate_shared) { - return -ENOTDIR; - } - - getdents_ctx gctx{}; - gctx.ctx.actor = filldir64; - gctx.ctx.pos = fp->f_pos; - gctx.buf = buf; - gctx.count = count; - gctx.written = 0; - gctx.error = 0; - - fp->f_op->iterate_shared(fp, &gctx.ctx); - fp->f_pos = gctx.ctx.pos; - - return gctx.written; -} - -/* ================================================================== */ -/* sys_dup(oldfd) */ -/* ================================================================== */ - -int64 sys_dup(uint64 a0, uint64 /*a1*/, uint64 /*a2*/, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int oldfd = static_cast(a0); - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, oldfd); - if (!fp) return -EBADF; - - int newfd = alloc_fd(files, 0); - if (newfd < 0) return newfd; - - get_file(fp); - fd_install(files, newfd, fp); - return newfd; -} - -/* ================================================================== */ -/* sys_dup3(oldfd, newfd, flags) */ -/* ================================================================== */ - -int64 sys_dup3(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int oldfd = static_cast(a0); - int newfd = static_cast(a1); - int flags = static_cast(a2); - - files_struct* files = current_files(); - if (!files) return -EBADF; - - return do_dup2(files, oldfd, newfd, flags); -} - -/* ================================================================== */ -/* sys_getcwd(buf, size) */ -/* ================================================================== */ - -int64 sys_getcwd(uint64 a0, uint64 a1, uint64 /*a2*/, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - char* buf = reinterpret_cast(a0); - uint64 size = a1; - - if (!buf || size == 0) return -EINVAL; - - fs_struct* fs = current_fs(); - if (!fs) return -ENOENT; - - char tmp[256]; - char* result = d_path(&fs->pwd, tmp, sizeof(tmp)); - if (!result) return -ERANGE; - - /* Calculate length */ - int len = 0; - for (const char* s = result; *s; s++) len++; - len++; /* Include NUL */ - - if (static_cast(len) > size) return -ERANGE; - - for (int i = 0; i < len; i++) { - buf[i] = result[i]; - } - - return len; -} - -/* ================================================================== */ -/* sys_chdir(pathname) */ -/* ================================================================== */ - -int64 sys_chdir(uint64 a0, uint64 /*a1*/, uint64 /*a2*/, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - const char* pathname = reinterpret_cast(a0); - - path p{}; - int err = filename_lookup(AT_FDCWD, pathname, LOOKUP_DIRECTORY, &p); - if (err) return err; - - if (!S_ISDIR(p.de->d_inode->i_mode)) { - path_put(&p); - return -ENOTDIR; - } - - fs_struct* fs = current_fs(); - if (!fs) { - path_put(&p); - return -ENOENT; - } - - set_fs_pwd(fs, &p); - path_put(&p); - return 0; -} - -/* ================================================================== */ -/* sys_mkdirat(dirfd, pathname, mode) */ -/* ================================================================== */ - -int64 sys_mkdirat(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int dirfd = static_cast(a0); - const char* pathname = reinterpret_cast(a1); - uint32 mode = static_cast(a2); - - /* Walk to the parent directory */ - /* For simplicity, support only "single component" paths for now */ - path parent{}; - int err; - - if (pathname[0] == '/') { - parent.de = g_root_dentry; - parent.mnt = g_root_mnt; - pathname++; /* skip leading / */ - } else { - fs_struct* fs = current_fs(); - if (!fs) return -ENOENT; - parent = fs->pwd; - (void)dirfd; /* TODO: respect dirfd for AT_FDCWD check */ - } - - inode* dir_ip = parent.de->d_inode; - if (!dir_ip || !dir_ip->i_op || !dir_ip->i_op->mkdir) { - return -EPERM; - } - - qstr q{}; - q.name = pathname; - q.len = 0; - for (const char* s = pathname; *s; s++) q.len++; - dentry* new_de = d_alloc(parent.de, &q); - if (!new_de) return -ENOMEM; - - err = dir_ip->i_op->mkdir(dir_ip, new_de, mode | S_IFDIR); - if (err) { - return err; - } - - return 0; -} - -/* ================================================================== */ -/* sys_unlinkat(dirfd, pathname, flags) */ -/* ================================================================== */ - -int64 sys_unlinkat(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - (void)a0; (void)a1; (void)a2; - /* TODO: implement unlink/rmdir */ - return -ENOSYS; -} - -/* ================================================================== */ -/* sys_writev(fd, iov, iovcnt) */ -/* ================================================================== */ - -struct iovec { - void* iov_base; - uint64 iov_len; -}; - -int64 sys_writev(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - const iovec* iov = reinterpret_cast(a1); - int iovcnt = static_cast(a2); - - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, fd); - if (!fp) return -EBADF; - if (!(fp->f_mode & FMODE_WRITE)) return -EBADF; - - int64 total = 0; - for (int i = 0; i < iovcnt; i++) { - if (iov[i].iov_len == 0) continue; - int64 ret = vfs_write(fp, static_cast(iov[i].iov_base), - iov[i].iov_len, &fp->f_pos); - if (ret < 0) { - return total > 0 ? total : ret; - } - total += ret; - if (static_cast(ret) < iov[i].iov_len) break; - } - return total; -} - -/* ================================================================== */ -/* sys_ioctl — dispatch to file_operations */ -/* ================================================================== */ - -int64 sys_ioctl(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - unsigned int cmd = static_cast(a1); - uint64 arg = a2; - - TaskControlBlock* curr = current_task(); - if (!curr || !curr->files) return -EBADF; - - file* fp = fcheck(curr->files, fd); - if (!fp) return -EBADF; - - if (fp->f_op && fp->f_op->unlocked_ioctl) - return fp->f_op->unlocked_ioctl(fp, cmd, arg); - - return -ENOTTY; -} - -/* ================================================================== */ -/* sys_pipe2(fds, flags) */ -/* ================================================================== */ - -#include - -int64 sys_pipe2(uint64 a0, uint64 a1, uint64 /*a2*/, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int* user_fds = reinterpret_cast(a0); - int flags = static_cast(a1); - - files_struct* files = current_files(); - if (!files) return -EMFILE; - - int fds[2]; - int err = do_pipe2(files, fds, flags); - if (err) return err; - - user_fds[0] = fds[0]; - user_fds[1] = fds[1]; - return 0; -} - -/* ================================================================== */ -/* sys_fcntl(fd, cmd, arg) */ -/* ================================================================== */ - -/* fcntl commands — Linux ABI values */ -inline constexpr int F_DUPFD = 0; -inline constexpr int F_GETFD = 1; -inline constexpr int F_SETFD = 2; -inline constexpr int F_GETFL = 3; -inline constexpr int F_SETFL = 4; -inline constexpr int F_DUPFD_CLOEXEC = 1030; - -inline constexpr int FD_CLOEXEC = 1; - -/* Bitmap helpers (duplicated from fd.cc — TODO: move to shared header) */ -static inline bool fcntl_bit_test(const uint64* bmap, int bit) { - return (bmap[bit / 64] >> (bit % 64)) & 1; -} -static inline void fcntl_bit_set(uint64* bmap, int bit) { - bmap[bit / 64] |= (1ULL << (bit % 64)); -} -static inline void fcntl_bit_clear(uint64* bmap, int bit) { - bmap[bit / 64] &= ~(1ULL << (bit % 64)); -} - -int64 sys_fcntl(uint64 a0, uint64 a1, uint64 a2, - uint64 /*a3*/, uint64 /*a4*/, uint64 /*a5*/) -{ - int fd = static_cast(a0); - int cmd = static_cast(a1); - uint64 arg = a2; - - files_struct* files = current_files(); - if (!files) return -EBADF; - - file* fp = fcheck(files, fd); - if (!fp) return -EBADF; - - switch (cmd) { - case F_DUPFD: - case F_DUPFD_CLOEXEC: { - int new_fd = alloc_fd(files, static_cast(arg)); - if (new_fd < 0) return new_fd; - get_file(fp); - fd_install(files, new_fd, fp); - if (cmd == F_DUPFD_CLOEXEC) { - LockGuard guard(files->file_lock); - fcntl_bit_set(files->close_on_exec_init, new_fd); - } - return new_fd; - } - - case F_GETFD: { - LockGuard guard(files->file_lock); - return fcntl_bit_test(files->close_on_exec_init, fd) ? FD_CLOEXEC : 0; - } - - case F_SETFD: { - LockGuard guard(files->file_lock); - if (arg & FD_CLOEXEC) - fcntl_bit_set(files->close_on_exec_init, fd); - else - fcntl_bit_clear(files->close_on_exec_init, fd); - return 0; - } - - case F_GETFL: - return fp->f_flags; - - case F_SETFL: - /* Only allow changing O_APPEND, O_NONBLOCK, O_ASYNC */ - fp->f_flags = (fp->f_flags & ~(O_APPEND | O_NONBLOCK)) | - (static_cast(arg) & (O_APPEND | O_NONBLOCK)); - return 0; - - default: - return -EINVAL; - } -} - -/* ================================================================== */ -/* sys_socket (SYS_socket = 198) & sys_sendto (SYS_sendto = 206) */ -/* ================================================================== */ - -int64 sys_socket(uint64, uint64, uint64, uint64, uint64, uint64) -{ - /* - * COMPATIBILITY STUB: - * LumeOS currently lacks a networking stack and Unix Domain Sockets (AF_UNIX). - * We return -EAFNOSUPPORT (Address family not supported by protocol) as expected - * by Linux applications (like BusyBox syslogd connecting to /dev/log). - */ - return -EAFNOSUPPORT; -} - -int64 sys_sendto(uint64, uint64, uint64, uint64, uint64, uint64) -{ - /* COMPATIBILITY STUB */ - return -EAFNOSUPPORT; -} diff --git a/kernel/sys_info.cc b/kernel/sys_info.cc deleted file mode 100644 index 79baab0..0000000 --- a/kernel/sys_info.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * System Information Calls - * - * Implements: uname - * - * Reference: docs/specs/syscall.md §7.3 - */ - -#include -#include -#include - -/* Linux-compatible utsname structure (65-byte fields) */ -struct utsname { - char sysname[65]; - char nodename[65]; - char release[65]; - char version[65]; - char machine[65]; - char domainname[65]; -}; - -/* Simple safe string copy */ -static void safe_strncpy(char* dst, const char* src, uint64 n) -{ - uint64 i = 0; - for (; i < n - 1 && src[i] != '\0'; i++) - dst[i] = src[i]; - dst[i] = '\0'; -} - -int64 sys_uname(uint64 buf_ptr, uint64, uint64, uint64, uint64, uint64) -{ - utsname info = {}; - safe_strncpy(info.sysname, "LumeOS", sizeof(info.sysname)); - safe_strncpy(info.nodename, "lume", sizeof(info.nodename)); - safe_strncpy(info.release, "0.1.0", sizeof(info.release)); - safe_strncpy(info.version, "Phase 2", sizeof(info.version)); - safe_strncpy(info.machine, "riscv64", sizeof(info.machine)); - safe_strncpy(info.domainname, "(none)", sizeof(info.domainname)); - - if (copy_to_user(buf_ptr, &info, sizeof(info)) < 0) - return -EFAULT; - - return 0; -} diff --git a/kernel/sys_misc.cc b/kernel/sys_misc.cc deleted file mode 100644 index 48eb47b..0000000 --- a/kernel/sys_misc.cc +++ /dev/null @@ -1,360 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Miscellaneous System Calls — busybox bootstrap set - * - * Each syscall follows the Linux kernel semantics exactly. - * Reference: Linux kernel/sys.c, kernel/signal.c, kernel/time/posix-timers.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ====================================================================== - * sys_reboot — Linux kernel/reboot.c - * - * Validates magic numbers and performs the requested action. - * For now, we only support LINUX_REBOOT_CMD_CAD_ON/OFF (ignore) - * and reject everything else with -EPERM (no CAP_SYS_BOOT). - * ====================================================================== */ - -static constexpr uint32 LINUX_REBOOT_MAGIC1 = 0xfee1dead; -static constexpr uint32 LINUX_REBOOT_MAGIC2 = 672274793; /* 0x28121969 */ -static constexpr uint32 LINUX_REBOOT_MAGIC2A = 85072278; -static constexpr uint32 LINUX_REBOOT_MAGIC2B = 369367448; -static constexpr uint32 LINUX_REBOOT_MAGIC2C = 537993216; - -int64 sys_reboot(uint64 magic1, uint64 magic2, uint64 cmd, - uint64, uint64, uint64) -{ - /* Linux: kernel/reboot.c — validate magic numbers first */ - if (static_cast(magic1) != LINUX_REBOOT_MAGIC1) - return -EINVAL; - if (static_cast(magic2) != LINUX_REBOOT_MAGIC2 && - static_cast(magic2) != LINUX_REBOOT_MAGIC2A && - static_cast(magic2) != LINUX_REBOOT_MAGIC2B && - static_cast(magic2) != LINUX_REBOOT_MAGIC2C) - return -EINVAL; - - /* We don't have CAP_SYS_BOOT yet — reject with -EPERM. - * This matches Linux behavior for unprivileged callers. - * Busybox handles this gracefully and continues. */ - (void)cmd; - printk(KERN_INFO "reboot: cmd=%llu (not implemented, returning -EPERM)\n", cmd); - return -EPERM; -} - -/* ====================================================================== - * sys_prctl — Linux kernel/sys.c - * - * Process control. Most options are optional for early boot. - * We implement the minimum set busybox needs. - * ====================================================================== */ - -/* prctl option constants (from ) */ -static constexpr int PR_SET_NAME = 15; -static constexpr int PR_GET_NAME = 16; -static constexpr int PR_SET_PDEATHSIG = 1; -static constexpr int PR_GET_PDEATHSIG = 2; - -int64 sys_prctl(uint64 option, uint64 arg2, uint64 arg3, - uint64 arg4, uint64 arg5, uint64) -{ - switch (static_cast(option)) { - case PR_SET_PDEATHSIG: - /* Linux: set signal delivered when parent dies. - * Silently accept — we don't track pdeath_signal yet. */ - return 0; - case PR_GET_PDEATHSIG: { - /* Linux: return current pdeath_signal (0 = none) */ - int32 zero = 0; - if (copy_to_user(arg2, &zero, sizeof(zero)) != 0) - return -EFAULT; - return 0; - } - case PR_SET_NAME: { - /* Linux: set comm (task name), max 16 chars */ - /* TODO: copy_from_user the string */ - return 0; - } - case PR_GET_NAME: { - /* Linux: get comm (task name) */ - TaskControlBlock* curr = current_task(); - if (!curr) return -ESRCH; - const char* name = curr->name ? curr->name : ""; - uint64 len = 0; - while (name[len] && len < 15) len++; - char buf[16] = {}; - for (uint64 i = 0; i < len; i++) buf[i] = name[i]; - if (copy_to_user(arg2, buf, 16) != 0) - return -EFAULT; - return 0; - } - default: - /* Unknown prctl — Linux returns -EINVAL for unrecognized options */ - return -EINVAL; - } -} - -/* ====================================================================== - * Session / Process-Group syscalls - * - * All four operate on the caller's signal_struct (or a target task's). - * Identity lives in signal_struct, so these become straightforward reads - * and pgrp-hash updates. We mirror Linux kernel/sys.c semantics closely. - * ====================================================================== */ - -static TaskControlBlock* find_task_by_pid(int32 pid) -{ - extern list_node g_all_tasks; - extern Spinlock g_task_list_lock; - LockGuard guard(g_task_list_lock); - list_node* node = g_all_tasks.next; - while (node != &g_all_tasks) { - auto* task = list_entry(node); - if (task->pid == pid) return task; - node = node->next; - } - return nullptr; -} - -/* - * sys_setsid — Linux kernel/sys.c:ksys_setsid() - * - * Caller becomes leader of a new session+pgrp. Refused if a pgrp with - * id == caller pid already exists with members other than the caller — - * that's Linux's "process group id already exists" check, which prevents - * collisions when a non-leader tries to setsid. - */ -int64 sys_setsid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -ESRCH; - - /* Detect collision: another pgrp already uses our pid as pgid. */ - bool conflict = false; - for_each_pgrp_member(curr->pid, [&](signal_struct* sig) { - if (sig != curr->signal) conflict = true; - }); - if (conflict) return -EPERM; - - /* Move to new pgrp (creates one if missing), update sid, drop ctty. */ - change_pgid(curr->signal, curr->pid); - - /* Detach the controlling terminal. If this task is the session - * leader that owns the tty (tty->session == caller's old sid), - * also clear the tty's session/pgrp so the next session-leader - * that opens the device can claim it. Without this, tty->session - * permanently sticks to the abandoned sid and every subsequent - * tty_acquire_ctty() bails with "owned by another session" — - * which is exactly what kept BusyBox's child sh from picking the - * console back up after init's setsid(). - * - * Linux's behavior is similar in spirit (disassociate_ctty when - * the leader exits), but it triggers from exit, not setsid. Our - * simpler "clear-on-give-up" matches the way our acquisition path - * is written. */ - tty_struct* old_tty = nullptr; - int32 old_sid = 0; - { - LockGuard guard(curr->signal->lock); - old_tty = curr->signal->tty; - old_sid = curr->signal->sid; - curr->signal->sid = curr->pid; - curr->signal->tty = nullptr; - curr->signal->tty_old_pgrp = 0; - } - if (old_tty) { - LockGuard guard(old_tty->lock); - if (old_tty->session == old_sid) { - old_tty->session = 0; - old_tty->pgrp = 0; - } - } - return curr->pid; -} - -/* - * sys_setpgid — Linux kernel/sys.c:ksys_setpgid() - * - * Move a process between groups within the same session. Allowed: - * - caller targeting self or a child - * - target is not a session leader - * - target stays in caller's session - * - target hasn't exec()'d (we don't track did_exec yet, so skip) - * - new pgid is either == target's pid (new group) or names a pgrp - * that already exists in the same session - */ -int64 sys_setpgid(uint64 pid, uint64 pgid, uint64, uint64, uint64, uint64) -{ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -ESRCH; - - int32 target_pid = static_cast(pid); - int32 target_pgid = static_cast(pgid); - - if (target_pid == 0) target_pid = curr->pid; - if (target_pgid == 0) target_pgid = target_pid; - if (target_pgid < 0) return -EINVAL; - - TaskControlBlock* target = (target_pid == curr->pid) - ? curr - : find_task_by_pid(target_pid); - if (!target || !target->signal) return -ESRCH; - - /* Target must be caller or a child of caller. */ - if (target != curr && target->parent != curr) return -ESRCH; - - /* Same session as caller. */ - if (target->signal->sid != curr->signal->sid) return -EPERM; - - /* Cannot move a session leader into a different pgrp. */ - if (target->signal->sid == target->pid) return -EPERM; - - /* If target_pgid != target_pid, the pgrp must already exist in - * the same session. pgrp existence == any signal_struct with - * pgid == target_pgid AND sid == caller's sid. */ - if (target_pgid != target->pid) { - bool found = false; - for_each_pgrp_member(target_pgid, [&](signal_struct* sig) { - if (sig->sid == curr->signal->sid) found = true; - }); - if (!found) return -EPERM; - } - - change_pgid(target->signal, target_pgid); - return 0; -} - -/* - * sys_getpgid — return process group ID of `pid` (0 = self). - */ -int64 sys_getpgid(uint64 pid, uint64, uint64, uint64, uint64, uint64) -{ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -ESRCH; - - if (pid == 0) return curr->signal->pgid; - - TaskControlBlock* target = find_task_by_pid(static_cast(pid)); - if (!target || !target->signal) return -ESRCH; - return target->signal->pgid; -} - -/* - * sys_getsid — return session ID of `pid` (0 = self). - */ -int64 sys_getsid(uint64 pid, uint64, uint64, uint64, uint64, uint64) -{ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->signal) return -ESRCH; - - if (pid == 0) return curr->signal->sid; - - TaskControlBlock* target = find_task_by_pid(static_cast(pid)); - if (!target || !target->signal) return -ESRCH; - - /* Linux: -EPERM if target's session differs from caller's and we're - * in a different namespace. We have one namespace, so always allow. */ - return target->signal->sid; -} - -/* ====================================================================== - * sys_geteuid / sys_getegid — Linux kernel/sys.c - * - * Return effective UID/GID. We run everything as root (0). - * ====================================================================== */ - -int64 sys_geteuid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - /* Linux: return current_euid(). We are always root. */ - return 0; -} - -int64 sys_getegid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - /* Linux: return current_egid(). We are always root. */ - return 0; -} - -/* ====================================================================== - * sys_sigaltstack — Linux kernel/signal.c - * - * Set/get alternate signal stack. For now, accept and ignore - * (busybox doesn't critically need it for shell operation). - * ====================================================================== */ - -int64 sys_sigaltstack(uint64 uss_ptr, uint64 uoss_ptr, - uint64, uint64, uint64, uint64) -{ - /* Linux: if uoss != NULL, return current alt stack info. - * We don't have alt stacks yet — report SS_DISABLE. */ - if (uoss_ptr != 0) { - /* stack_t { void* ss_sp; int ss_flags; size_t ss_size; } - * On RISC-V LP64: 8 + 4 + padding + 8 = 24 bytes typically, - * but the ABI packs it as {uint64, int32, pad, uint64}. */ - struct { - uint64 ss_sp; - int32 ss_flags; - int32 _pad; - uint64 ss_size; - } oss = { 0, 2 /* SS_DISABLE */, 0, 0 }; - if (copy_to_user(uoss_ptr, &oss, sizeof(oss)) != 0) - return -EFAULT; - } - - /* uss: silently accept (we'll need it for proper signal handling later) */ - (void)uss_ptr; - return 0; -} - -/* ====================================================================== - * sys_clock_gettime — Linux kernel/time/posix-timers.c - * - * Get the current time for a given clock. - * We use the RISC-V cycle counter as a monotonic source. - * ====================================================================== */ - -static constexpr int CLOCK_REALTIME = 0; -static constexpr int CLOCK_MONOTONIC = 1; - -int64 sys_clock_gettime(uint64 clk_id, uint64 tp_ptr, - uint64, uint64, uint64, uint64) -{ - if (tp_ptr == 0) return -EFAULT; - - /* Read RISC-V time CSR (mtime mapped to SBI) */ - uint64 ticks = arch::cpu::read_time(); - - /* Convert to seconds + nanoseconds. - * QEMU virt timebase-frequency is 10MHz. */ - constexpr uint64 kTimebaseHz = 10'000'000ULL; - uint64 sec = ticks / kTimebaseHz; - uint64 nsec = (ticks % kTimebaseHz) * (1'000'000'000ULL / kTimebaseHz); - - struct timespec64 { - int64 tv_sec; - int64 tv_nsec; - }; - - timespec64 ts; - ts.tv_sec = static_cast(sec); - ts.tv_nsec = static_cast(nsec); - - (void)clk_id; /* We treat all clocks as monotonic for now */ - - if (copy_to_user(tp_ptr, &ts, sizeof(ts)) != 0) - return -EFAULT; - - return 0; -} diff --git a/kernel/sys_mm.cc b/kernel/sys_mm.cc deleted file mode 100644 index bfa067c..0000000 --- a/kernel/sys_mm.cc +++ /dev/null @@ -1,178 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Memory Management System Calls - * - * Implements: brk, mmap (anonymous only), munmap, mprotect. - * - * Reference: docs/specs/syscall.md §7.2 - */ - -#include -#include -#include -#include -#include -#include -#include - - -/* Page alignment helpers */ -static inline uint64 page_align_up(uint64 x) -{ - return (x + kPageSize - 1) & ~(kPageSize - 1); -} - -static inline uint64 page_align_down(uint64 x) -{ - return x & ~(kPageSize - 1); -} - -/* ====================================================================== - * sys_brk - * ====================================================================== */ - -int64 sys_brk(uint64 new_brk, uint64, uint64, uint64, uint64, uint64) -{ - VmSpace* mm = current_task()->mm; - if (!mm) - return -ENOMEM; /* kernel threads have no user address space */ - - if (new_brk == 0) { - return static_cast(mm->brk_end); - } - - if (mm->brk_start == 0) { - uint64 init_brk = page_align_up(new_brk); - mm->brk_start = init_brk; - mm->brk_end = init_brk; - } - - if (new_brk < mm->brk_start) { - return -EINVAL; - } - - uint64 new_end = page_align_up(new_brk); - if (new_end > mm->brk_end) { - uint64 grow = new_end - mm->brk_end; - int ret = vmm_map_user(mm, mm->brk_end, grow, VM_READ | VM_WRITE); - if (ret < 0) { - return ret; - } - } else if (new_end < mm->brk_end) { - uint64 shrink = mm->brk_end - new_end; - int ret = vmm_unmap_user(mm, new_end, shrink); - if (ret < 0) { - return ret; - } - } - - mm->brk_end = new_end; - return static_cast(new_brk); -} - -/* ====================================================================== - * sys_mmap - * ====================================================================== */ - -int64 sys_mmap(uint64 addr, uint64 length, uint64 prot, - uint64 flags, uint64 fd, uint64 offset) -{ - printk("[mmap] addr=%llx len=%llx prot=%llx flags=%llx fd=%lld off=%llx\n", - addr, length, prot, flags, static_cast(fd), offset); - - if (length == 0) return -EINVAL; - length = page_align_up(length); - if (offset % kPageSize != 0) return -EINVAL; - - if ((flags & MAP_PRIVATE) && (flags & MAP_SHARED)) return -EINVAL; - if (!(flags & MAP_PRIVATE) && !(flags & MAP_SHARED)) return -EINVAL; - - VmSpace* mm = current_task()->mm; - if (!mm) return -ENOMEM; - - /* Phase 2: only anonymous private mappings */ - if (!(flags & MAP_ANONYMOUS)) { - printk("[mmap] REJECTED: file-backed mmap not implemented\n"); - return -ENOSYS; /* File-backed mmap is Phase 3 */ - } - if (flags & MAP_SHARED) - return -ENOSYS; /* Shared mappings are Phase 3 */ - - (void)fd; - - /* Convert POSIX prot → MI permission flags */ - uint64 vm_perm = 0; - if (prot & PROT_READ) vm_perm |= VM_READ; - if (prot & PROT_WRITE) vm_perm |= VM_WRITE; - if (prot & PROT_EXEC) vm_perm |= VM_EXEC; - vm_perm |= VM_USER; - - uint64 va = addr; - if (flags & MAP_FIXED) { - if (va % kPageSize != 0) return -EINVAL; - } else if (va != 0) { - va = page_align_down(va); - } - - if (va == 0) { - va = mm_find_free_va(mm, length, kPageSize); - if (!va) return -ENOMEM; - } - - if (flags & MAP_FIXED) { - int ret = vmm_unmap_user(mm, va, length); - if (ret < 0) return ret; - } - - int ret = vmm_map_user(mm, va, length, vm_perm); - if (ret < 0 && !(flags & MAP_FIXED) && addr != 0) { - uint64 fallback = mm_find_free_va(mm, length, kPageSize); - if (!fallback) return ret; - ret = vmm_map_user(mm, fallback, length, vm_perm); - if (ret < 0) return ret; - va = fallback; - } else if (ret < 0) { - return ret; - } - - return static_cast(va); -} - -/* ====================================================================== - * sys_munmap - * ====================================================================== */ - -int64 sys_munmap(uint64 addr, uint64 length, uint64, uint64, uint64, uint64) -{ - if (length == 0) return -EINVAL; - if (addr % kPageSize != 0) return -EINVAL; - length = page_align_up(length); - - VmSpace* mm = current_task()->mm; - if (!mm) return -EINVAL; - - return vmm_unmap_user(mm, addr, length); -} - -/* ====================================================================== - * sys_mprotect — Phase 2 stub - * ====================================================================== */ - -int64 sys_mprotect(uint64 addr, uint64 len, uint64 prot, - uint64, uint64, uint64) -{ - if (len == 0) return -EINVAL; - if (addr % kPageSize != 0) return -EINVAL; - - VmSpace* mm = current_task()->mm; - if (!mm) return -ENOMEM; - - uint64 vm_perm = 0; - if (prot & PROT_READ) vm_perm |= VM_READ; - if (prot & PROT_WRITE) vm_perm |= VM_WRITE; - if (prot & PROT_EXEC) vm_perm |= VM_EXEC; - - return vmm_protect_user(mm, addr, len, vm_perm); -} diff --git a/kernel/sys_process.cc b/kernel/sys_process.cc deleted file mode 100644 index 438ad1b..0000000 --- a/kernel/sys_process.cc +++ /dev/null @@ -1,185 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Process Control System Calls - * - * Implements: exit, exit_group, getpid, gettid, getppid, - * sched_yield, clone (stub), wait4 (stub), - * set_tid_address, getuid, getgid. - * - * Reference: docs/specs/syscall.md §7.1 - */ - -#include "lume/klog.h" -#include -#include -#include -#include -#include -#include - -/* External: task lifecycle (kernel/task.cc) */ -extern void task_exit(int code); -extern int32 do_wait4(int32 wait_pid, int options, int32* exit_code); -extern int32 task_clone(arch::TrapFrame* tf, uint64 clone_flags, - uint64 child_stack, uint64 parent_tidptr, - uint64 child_tidptr, uint64 tls); -extern int32 task_fork(arch::TrapFrame* tf); - -/* ====================================================================== - * sys_exit / sys_exit_group - * ====================================================================== */ - -int64 sys_exit(uint64 code, uint64, uint64, uint64, uint64, uint64) -{ - task_exit(static_cast(code & 0xFF)); - __builtin_unreachable(); -} - -int64 sys_exit_group(uint64 code, uint64, uint64, uint64, uint64, uint64) -{ - /* Phase 2: single-threaded, equivalent to sys_exit. - * Phase 3: kill all threads in tgid then exit. */ - task_exit(static_cast(code & 0xFF)); - __builtin_unreachable(); -} - -/* ====================================================================== - * sys_getpid / sys_gettid / sys_getppid - * ====================================================================== */ - -int64 sys_getpid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - return current_task()->tgid; /* Linux: getpid() returns tgid */ -} - -int64 sys_gettid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - return current_task()->pid; /* Linux: gettid() returns real tid */ -} - -int64 sys_getppid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - TaskControlBlock* parent = current_task()->parent; - return parent ? parent->tgid : 0; -} - -/* ====================================================================== - * sys_sched_yield - * ====================================================================== */ - -int64 sys_sched_yield_wrapper(uint64, uint64, uint64, uint64, uint64, uint64) -{ - sched_yield(); - return 0; -} - -int64 sys_clone_wrapper(uint64 flags, uint64 child_stack, - uint64 ptid, uint64 ctid, uint64 tls, uint64) -{ - arch::TrapFrame* tf = current_task()->trapframe; - if (!tf) return -EINVAL; - - return task_clone(tf, flags, child_stack, ptid, ctid, tls); -} - -/* ======================================================================== - * sys_wait4 — Wait for child to exit - * ======================================================================== */ - -int64 sys_wait4_wrapper(uint64 pid, uint64 wstatus_ptr, - uint64 options, uint64, uint64, uint64) -{ - int32 exit_code = 0; - int32 child_pid = do_wait4(static_cast(pid), - static_cast(options), - &exit_code); - - if (child_pid < 0) return child_pid; - - /* exit_code is already in Linux wstatus format */ - if (wstatus_ptr != 0) { - if (copy_to_user(wstatus_ptr, &exit_code, sizeof(int)) < 0) - return -EFAULT; - } - - return child_pid; -} - -/* ====================================================================== - * sys_set_tid_address — musl libc calls this very early - * ====================================================================== */ - -int64 sys_set_tid_address(uint64 tidptr, uint64, uint64, - uint64, uint64, uint64) -{ - /* Store clear_child_tid pointer — on exit, kernel writes 0 here - * and does futex_wake (enables pthread_join). */ - current_task()->clear_child_tid = tidptr; - return current_task()->pid; -} - -/* ====================================================================== - * sys_getuid / sys_getgid — Phase 2: always root - * ====================================================================== */ - -int64 sys_getuid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - return 0; /* root */ -} - -int64 sys_getgid(uint64, uint64, uint64, uint64, uint64, uint64) -{ - return 0; /* root */ -} - -/* ====================================================================== - * sys_nanosleep (SYS_nanosleep = 101) - * ====================================================================== */ -#include -#include -#include - -struct linux_timespec { - int64 tv_sec; - int64 tv_nsec; -}; - -static void nanosleep_wakeup(TimerList* t) { - TaskControlBlock* task = static_cast(t->data); - task->state = TaskState::Runnable; - sched_enqueue(task); -} - -int64 sys_nanosleep(uint64 req_ptr, uint64 rem_ptr, uint64, uint64, uint64, uint64) { - if (req_ptr == 0) return -EINVAL; - - linux_timespec req; - if (copy_from_user(&req, req_ptr, sizeof(req)) != 0) { - return -EFAULT; - } - - uint64 target = *(volatile uint64*)&g_jiffies + (req.tv_sec * 100) + (req.tv_nsec / 10000000); - - TaskControlBlock* curr = current_task(); - curr->state = TaskState::Sleeping; - - TimerList t; - t.init(nanosleep_wakeup); - t.expires = target; - t.data = curr; - - add_timer(&t); - - if (*(volatile uint64*)&g_jiffies < target) { - schedule(); - } else { - curr->state = TaskState::Running; - } - - - del_timer(&t); - - return 0; -} diff --git a/kernel/sys_signal.cc b/kernel/sys_signal.cc deleted file mode 100644 index 8b459d5..0000000 --- a/kernel/sys_signal.cc +++ /dev/null @@ -1,351 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * sys_signal.cc — Signal-related system calls - * - * Implements: - * sys_kill (SYS_kill = 129) - * sys_rt_sigaction (SYS_rt_sigaction = 134) - * sys_rt_sigprocmask (SYS_rt_sigprocmask = 135) - * sys_rt_sigreturn (SYS_rt_sigreturn = 139) - * - * Reference: Linux kernel/signal.c, arch/riscv/kernel/signal.c - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* From signal.cc */ -extern int send_signal(int sig, kernel_siginfo* info, TaskControlBlock* task); - -/* From task.cc */ -extern list_node g_all_tasks; -extern Spinlock g_task_list_lock; - -/* ================================================================== */ -/* Helper: find task by PID */ -/* ================================================================== */ - -static TaskControlBlock* find_task_by_pid(int32 pid) -{ - LockGuard guard(g_task_list_lock); - list_node* node = g_all_tasks.next; - while (node != &g_all_tasks) { - auto* task = list_entry(node); - if (task->pid == pid) return task; - node = node->next; - } - return nullptr; -} - -/* ================================================================== */ -/* sys_kill — send a signal to a process */ -/* ================================================================== */ - -/* - * Deliver `sig` to the thread-group leader represented by `sig_st`. - * sighand is allocated eagerly at fork/exec time, so we just trust - * that the leader has one; send_signal returns -ESRCH if not. - */ -static int deliver_to_group(signal_struct* sig_st, int sig, - kernel_siginfo* info) -{ - if (!sig_st || !sig_st->leader) return 0; - if (send_signal(sig, info, sig_st->leader) == 0) return 1; - return 0; -} - -int64 sys_kill(uint64 a0, uint64 a1, uint64, uint64, uint64, uint64) -{ - int32 pid = static_cast(a0); - int sig = static_cast(a1); - - if (sig < 0 || sig > _NSIG) return -EINVAL; - - TaskControlBlock* curr = current_task(); - if (!curr) return -ESRCH; - - kernel_siginfo info{}; - info.si_signo = sig; - info.si_code = 0; /* SI_USER */ - info._sifields._kill._pid = curr->pid; - info._sifields._kill._uid = 0; - - /* pid > 0: deliver to that thread group's leader. */ - if (pid > 0) { - TaskControlBlock* target = find_task_by_pid(pid); - if (!target) return -ESRCH; - /* Group signal: prefer the thread-group leader if available. */ - if (target->signal && target->signal->leader) - target = target->signal->leader; - if (sig == 0) return 0; - return send_signal(sig, &info, target); - } - - /* pid == 0: every member of caller's process group. */ - if (pid == 0) { - if (!curr->signal) return -ESRCH; - if (sig == 0) return 0; - int delivered = 0; - int32 target_pgid = curr->signal->pgid; - for_each_pgrp_member(target_pgid, [&](signal_struct* s) { - delivered += deliver_to_group(s, sig, &info); - }); - return delivered > 0 ? 0 : -ESRCH; - } - - /* pid == -1: every process the caller may signal, except init. - * We approximate "every" with "every thread-group leader on every - * pgrp bucket". This is rare in practice (BusyBox doesn't use it - * during normal shell operation). */ - if (pid == -1) { - if (sig == 0) return 0; - int delivered = 0; - LockGuard guard(g_pgrp_lock); - for (auto& bucket : g_pgrp_hash) { - list_node* node = bucket.next; - while (node != &bucket) { - list_node* next = node->next; - auto* s = list_entry(node); - if (s->leader && s->leader->pid != 1) - delivered += deliver_to_group(s, sig, &info); - node = next; - } - } - return delivered > 0 ? 0 : -ESRCH; - } - - /* pid < -1: every member of pgrp |pid|. */ - int32 target_pgid = -pid; - if (sig == 0) { - bool any = false; - for_each_pgrp_member(target_pgid, [&](signal_struct*) { any = true; }); - return any ? 0 : -ESRCH; - } - int delivered = 0; - for_each_pgrp_member(target_pgid, [&](signal_struct* s) { - delivered += deliver_to_group(s, sig, &info); - }); - return delivered > 0 ? 0 : -ESRCH; -} - -/* ================================================================== */ -/* sys_tkill / sys_tgkill — send a signal to a specific thread */ -/* ================================================================== */ - -static int64 do_tkill(int32 tgid, int32 tid, int sig) -{ - if (sig < 0 || sig > _NSIG) return -EINVAL; - if (tid <= 0) return -EINVAL; - TaskControlBlock* target = find_task_by_pid(tid); - if (!target) return -ESRCH; - /* tgid == -1 from tkill means "any tgid"; otherwise enforce match. */ - if (tgid != -1 && target->tgid != tgid) return -ESRCH; - - if (sig == 0) return 0; - - kernel_siginfo info{}; - info.si_signo = sig; - info.si_code = 0; /* SI_TKILL would be -6; userland rarely checks */ - info._sifields._kill._pid = current_task() ? current_task()->pid : 0; - info._sifields._kill._uid = 0; - return send_signal(sig, &info, target); -} - -int64 sys_tkill(uint64 a0, uint64 a1, uint64, uint64, uint64, uint64) -{ - return do_tkill(-1, - static_cast(a0), - static_cast(a1)); -} - -int64 sys_tgkill(uint64 a0, uint64 a1, uint64 a2, uint64, uint64, uint64) -{ - return do_tkill(static_cast(a0), - static_cast(a1), - static_cast(a2)); -} - -/* ================================================================== */ -/* sys_rt_sigaction — get/set signal disposition */ -/* ================================================================== */ - -/* - * User-space sigaction struct layout (RISC-V LP64): - * uint64 sa_handler; - * uint64 sa_flags; - * uint64 sa_restorer; (SA_RESTORER) - * sigset_t sa_mask; (8 bytes on LP64) - */ -struct user_sigaction { - uint64 sa_handler; - uint64 sa_flags; - uint64 sa_restorer; - sigset_t sa_mask; -}; - -int64 sys_rt_sigaction(uint64 a0, uint64 a1, uint64 a2, uint64 a3, - uint64, uint64) -{ - int sig = static_cast(a0); - uint64 act_uaddr = a1; /* const struct sigaction __user * */ - uint64 oact_uaddr = a2; /* struct sigaction __user * */ - uint64 sigsetsize = a3; - - if (sig < 1 || sig > _NSIG) return -EINVAL; - if (sig_kernel_only(sig)) return -EINVAL; - if (sigsetsize != sizeof(sigset_t)) return -EINVAL; - - TaskControlBlock* curr = current_task(); - if (!curr || !curr->sighand) return -EINVAL; - - /* All reads/writes of the action table happen under siglock — - * Linux's do_sigaction() also takes the same lock (kernel/signal.c). */ - user_sigaction old{}; - user_sigaction act{}; - bool have_new = (act_uaddr != 0); - - if (have_new) { - int err = copy_from_user(&act, act_uaddr, sizeof(act)); - if (err < 0) return -EFAULT; - } - - { - LockGuard guard(curr->sighand->siglock); - kernel_sigaction* ksa = &curr->sighand->action[sig - 1]; - old.sa_handler = ksa->sa_handler; - old.sa_flags = ksa->sa_flags; - old.sa_restorer = ksa->sa_restorer; - old.sa_mask = ksa->sa_mask; - - if (have_new) { - ksa->sa_handler = act.sa_handler; - ksa->sa_flags = act.sa_flags; - ksa->sa_restorer = act.sa_restorer; - ksa->sa_mask = act.sa_mask; - ksa->sa_mask.del(SIGKILL); - ksa->sa_mask.del(SIGSTOP); - } - } - - if (oact_uaddr != 0) { - int err = copy_to_user(oact_uaddr, &old, sizeof(old)); - if (err < 0) return -EFAULT; - } - return 0; -} - -/* ================================================================== */ -/* sys_rt_sigprocmask — change signal blocked mask */ -/* ================================================================== */ - -int64 sys_rt_sigprocmask(uint64 a0, uint64 a1, uint64 a2, uint64 a3, - uint64, uint64) -{ - int how = static_cast(a0); - uint64 set_uaddr = a1; - uint64 oset_uaddr = a2; - uint64 sigsetsize = a3; - - if (sigsetsize != sizeof(sigset_t)) return -EINVAL; - - TaskControlBlock* curr = current_task(); - if (!curr || !curr->sighand) return -EINVAL; - - sigset_t newset{}; - bool have_new = (set_uaddr != 0); - if (have_new) { - int err = copy_from_user(&newset, set_uaddr, sizeof(sigset_t)); - if (err < 0) return -EFAULT; - newset.del(SIGKILL); - newset.del(SIGSTOP); - } - - sigset_t old{}; - { - /* Linux: kernel/signal.c:do_sigprocmask() also holds siglock - * across read+update so the snapshot is atomic vs. concurrent - * signal delivery. */ - LockGuard guard(curr->sighand->siglock); - old = curr->blocked; - if (have_new) { - switch (how) { - case SIG_BLOCK: - curr->blocked = curr->blocked | newset; - break; - case SIG_UNBLOCK: - curr->blocked = curr->blocked & ~newset; - break; - case SIG_SETMASK: - curr->blocked = newset; - break; - default: - return -EINVAL; - } - } - } - - if (oset_uaddr != 0) { - int err = copy_to_user(oset_uaddr, &old, sizeof(sigset_t)); - if (err < 0) return -EFAULT; - } - return 0; -} - -/* ================================================================== */ -/* sys_rt_sigreturn — restore context after signal handler */ -/* ================================================================== */ - -/* Arch-specific: implemented in arch/riscv/signal.cc */ -extern int64 arch_sigreturn(arch::TrapFrame* tf); - -int64 sys_rt_sigreturn(uint64, uint64, uint64, uint64, uint64, uint64) -{ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->trapframe) return -EINVAL; - - return arch_sigreturn(curr->trapframe); -} - -/* ================================================================== */ -/* sys_rt_sigtimedwait (SYS_rt_sigtimedwait = 137) */ -/* ================================================================== */ -#include -#include - -struct linux_timespec { - int64 tv_sec; - int64 tv_nsec; -}; - -int64 sys_rt_sigtimedwait(uint64 /* set_ptr */, uint64 /* info_ptr */, uint64 timeout_ptr, uint64 /* sigsetsize */, uint64, uint64) -{ - /* - * COMPATIBILITY STUB: - * LumeOS lacks full real-time signal queues and timed waiting mechanism. - * When BusyBox init runs out of children to reap, it calls this to wait - * for incoming signals (like SIGCHLD) with a timeout. - * We simulate the timeout by yielding the CPU, then return -EAGAIN (Try again) - * which tells user space that the timeout expired without receiving a signal. - */ - if (timeout_ptr != 0) { - linux_timespec req; - if (copy_from_user(&req, timeout_ptr, sizeof(req)) == 0) { - uint64 target = g_jiffies + (req.tv_sec * 100) + (req.tv_nsec / 10000000); - while (g_jiffies < target) { - schedule(); - } - } - } - return -EAGAIN; -} diff --git a/kernel/syscall.cc b/kernel/syscall.cc deleted file mode 100644 index a5b80ec..0000000 --- a/kernel/syscall.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * System Call MI Layer — Jump Table & Dispatcher - * - * O(1) function pointer array dispatch. No switch-case. - * syscall_init() registers all implemented handlers. - * - * Reference: docs/specs/syscall.md §6 - */ - -#include -#include -#include -#include -#include -#include -#include - -/* ====================================================================== - * Jump table - * ====================================================================== */ - -inline constexpr int kNrSyscalls = 512; - -static SyscallHandler sys_call_table[kNrSyscalls]; - -/* ====================================================================== - * MI Dispatcher - * ====================================================================== */ - -int64 syscall_dispatch(uint64 nr, uint64 args[6]) -{ - if (nr >= static_cast(kNrSyscalls)) { - kprintf("[syscall] nr=%llu out of range\n", nr); - return -ENOSYS; - } - - /* Per-syscall entry trace. KLOG_DEBUG keeps it out of the console - * by default; enable via klog_set_level(KLOG_DEBUG) or read the - * ring buffer to investigate. Subsys mask gates this further. */ - pr_debug_s(KLOG_SUBSYS_SYSCALL, - "syscall: nr=%llu a0=%llx a1=%llx a2=%llx a3=%llx\n", - nr, args[0], args[1], args[2], args[3]); - - SyscallHandler handler = sys_call_table[nr]; - if (!handler) { - kprintf("[syscall] unimplemented nr=%llu\n", nr); - return -ENOSYS; - } - - return handler(args[0], args[1], args[2], - args[3], args[4], args[5]); -} - -/* ====================================================================== - * Forward declarations of sys_* handlers - * ====================================================================== */ - -/* sys_process.cc */ -int64 sys_exit(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_exit_group(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getpid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_gettid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getppid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_sched_yield_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_clone_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_wait4_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_set_tid_address(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getuid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getgid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_nanosleep(uint64, uint64, uint64, uint64, uint64, uint64); - -/* sys_mm.cc */ -int64 sys_brk(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_mmap(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_munmap(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_mprotect(uint64, uint64, uint64, uint64, uint64, uint64); - -/* sys_info.cc */ -int64 sys_uname(uint64, uint64, uint64, uint64, uint64, uint64); - -/* sys_fs.cc */ -int64 sys_openat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_close(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_read(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_write(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_lseek(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_fstat_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getdents64(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_dup(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_dup3(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getcwd(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_chdir(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_mkdirat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_unlinkat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_writev(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_ioctl(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_ppoll(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_pipe2(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_fcntl(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_socket(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_sendto(uint64, uint64, uint64, uint64, uint64, uint64); - -/* sys_signal.cc */ -int64 sys_kill(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_tkill(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_tgkill(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_rt_sigaction(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_rt_sigprocmask(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_rt_sigreturn(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_rt_sigtimedwait(uint64, uint64, uint64, uint64, uint64, uint64); - -/* exec.cc */ -int64 sys_execve_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); - -/* sys_misc.cc */ -int64 sys_reboot(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_prctl(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_setsid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getsid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_setpgid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getpgid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_geteuid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getegid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_sigaltstack(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_clock_gettime(uint64, uint64, uint64, uint64, uint64, uint64); - -/* ====================================================================== - * syscall_init — register all handlers - * ====================================================================== */ - -void syscall_init() -{ - /* Zero the table (redundant for BSS, but explicit) */ - for (int i = 0; i < kNrSyscalls; i++) - sys_call_table[i] = nullptr; - - /* Phase 2: minimal runnable set */ - sys_call_table[SYS_exit] = sys_exit; - sys_call_table[SYS_exit_group] = sys_exit_group; - sys_call_table[SYS_getpid] = sys_getpid; - sys_call_table[SYS_gettid] = sys_gettid; - sys_call_table[SYS_getppid] = sys_getppid; - sys_call_table[SYS_sched_yield] = sys_sched_yield_wrapper; - sys_call_table[SYS_clone] = sys_clone_wrapper; - sys_call_table[SYS_wait4] = sys_wait4_wrapper; - sys_call_table[SYS_set_tid_address] = sys_set_tid_address; - sys_call_table[SYS_getuid] = sys_getuid; - sys_call_table[SYS_getgid] = sys_getgid; - sys_call_table[SYS_brk] = sys_brk; - sys_call_table[SYS_mmap] = sys_mmap; - sys_call_table[SYS_munmap] = sys_munmap; - sys_call_table[SYS_mprotect] = sys_mprotect; - sys_call_table[SYS_uname] = sys_uname; - - /* Phase 3: filesystem */ - sys_call_table[SYS_openat] = sys_openat; - sys_call_table[SYS_close] = sys_close; - sys_call_table[SYS_read] = sys_read; - sys_call_table[SYS_write] = sys_write; - sys_call_table[SYS_lseek] = sys_lseek; - sys_call_table[SYS_fstat] = sys_fstat_wrapper; - sys_call_table[SYS_getdents64] = sys_getdents64; - sys_call_table[SYS_dup] = sys_dup; - sys_call_table[SYS_dup3] = sys_dup3; - sys_call_table[SYS_getcwd] = sys_getcwd; - sys_call_table[SYS_chdir] = sys_chdir; - sys_call_table[SYS_mkdirat] = sys_mkdirat; - sys_call_table[SYS_unlinkat] = sys_unlinkat; - sys_call_table[SYS_writev] = sys_writev; - sys_call_table[SYS_ioctl] = sys_ioctl; - sys_call_table[SYS_ppoll] = sys_ppoll; - - /* Phase 4: signals */ - sys_call_table[SYS_kill] = sys_kill; - sys_call_table[SYS_tkill] = sys_tkill; - sys_call_table[SYS_tgkill] = sys_tgkill; - sys_call_table[SYS_rt_sigaction] = sys_rt_sigaction; - sys_call_table[SYS_rt_sigprocmask] = sys_rt_sigprocmask; - sys_call_table[SYS_rt_sigreturn] = sys_rt_sigreturn; - sys_call_table[SYS_rt_sigtimedwait] = sys_rt_sigtimedwait; - - /* Phase 5: exec */ - sys_call_table[SYS_execve] = sys_execve_wrapper; - - /* Phase 6: pipe + fcntl */ - sys_call_table[SYS_pipe2] = sys_pipe2; - sys_call_table[SYS_fcntl] = sys_fcntl; - - /* Phase 7: busybox bootstrap */ - sys_call_table[SYS_reboot] = sys_reboot; - sys_call_table[SYS_prctl] = sys_prctl; - sys_call_table[SYS_setsid] = sys_setsid; - sys_call_table[SYS_getsid] = sys_getsid; - sys_call_table[SYS_setpgid] = sys_setpgid; - sys_call_table[SYS_getpgid] = sys_getpgid; - sys_call_table[SYS_geteuid] = sys_geteuid; - sys_call_table[SYS_getegid] = sys_getegid; - sys_call_table[SYS_sigaltstack] = sys_sigaltstack; - sys_call_table[SYS_clock_gettime] = sys_clock_gettime; - sys_call_table[SYS_nanosleep] = sys_nanosleep; - sys_call_table[SYS_socket] = sys_socket; - sys_call_table[SYS_sendto] = sys_sendto; - - printk(KERN_INFO "init: syscall_init done (%d handlers registered)\n", 46); -} diff --git a/kernel/task.cc b/kernel/task.cc deleted file mode 100644 index 9f9b043..0000000 --- a/kernel/task.cc +++ /dev/null @@ -1,780 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Task Management — create, exit, destroy, kthread - * - * Implements task lifecycle management: kernel thread creation, - * task exit (zombie transition), and resource reclamation. - * - * Reference: docs/specs/task.md §4-§6 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ====================================================================== - * Forward declarations - * ====================================================================== */ - -extern "C" void kthread_entry_trampoline(); -extern "C" void ret_from_fork(); - -/* ====================================================================== - * Global task list - * ====================================================================== */ - -list_node g_all_tasks; -Spinlock g_task_list_lock; -int32 g_nr_tasks = 0; - -/* Special tasks */ -TaskControlBlock* g_kernel_task = nullptr; /* PID 0 container */ -TaskControlBlock* g_init_task = nullptr; /* PID 1 (future) */ - -/* ====================================================================== - * task_init() — called once from kernel_main before sched_init - * ====================================================================== */ - -void task_init() -{ - g_all_tasks.init(); - g_task_list_lock.init("task_list"); - g_pid_alloc.init(); - - printk(KERN_INFO "init: task_init done (pid_alloc ready)\n"); -} - -/* ====================================================================== - * alloc_task — allocate TCB + kernel stack - * - * This is the SINGLE canonical TCB initializer. Both kthread_create - * (task.cc) and sched_init (sched_core.cc) must use this function. - * NEVER duplicate this logic — adding fields to TaskControlBlock - * requires updating only this function. - * ====================================================================== */ - -TaskControlBlock* alloc_task(const char* name, uint8 priority, - uint8 flags, uint8 cpu) -{ - auto* task = new TaskControlBlock; - if (!task) return nullptr; - - task->context = {}; - - /* Allocate 8KB kernel stack (order-1 = 2 pages) */ - Page* stack_page = pmm_alloc_pages(1); - if (!stack_page) { - delete task; - return nullptr; - } - task->kstack_pa = page_to_pa(stack_page).raw; - task->kstack_va = pa_to_va(phys_addr(task->kstack_pa)).raw; - - /* Write stack canary at bottom */ - *reinterpret_cast(task->kstack_va) = kStackCanary; - - /* Place TrapFrame at the top of the kernel stack (like Linux pt_regs). - * ALL tasks — kernel threads and user processes — have a TrapFrame - * here. kthread_create sets the initial SP below the TrapFrame so - * the kthread function never touches this reserved area. - * kernel_execve / do_execve can later fill it in for user-mode return. */ - uint64 tf_addr = task->kstack_va + kKernelStackSize - - sizeof(arch::TrapFrame); - task->trapframe = reinterpret_cast(tf_addr); - __builtin_memset(task->trapframe, 0, sizeof(arch::TrapFrame)); - - /* Basic fields */ - task->name = name; - task->priority = priority; - task->time_slice = priority_to_timeslice(priority); - task->state = TaskState::Runnable; - task->cpu_id = cpu; - task->flags = flags; - task->exit_code = 0; - task->exit_signal = 0; - task->preempt_count = 0; - task->clear_child_tid = 0; - task->stopped_code = 0; - task->notify_continued = false; - task->parent = nullptr; - task->mm = nullptr; - task->fpstate = {}; - task->files = nullptr; - task->fs = nullptr; - task->pending.init(); - task->blocked.clear(); - task->sighand = nullptr; - task->signal = nullptr; - - /* Init all list nodes */ - task->run_link.init(); - task->all_link.init(); - task->children.init(); - task->sibling.init(); - task->lock.init("task"); - task->wait_chld.init("wait_chld"); - - /* Default sched class */ - extern const SchedClass g_sched_class_o1; - task->sched_class = &g_sched_class_o1; - task->sched_entity = &task->run_link; - - return task; -} - -/* Add task to global task list */ -static void task_list_add(TaskControlBlock* task) -{ - LockGuard guard(g_task_list_lock); - - list_node* head = &g_all_tasks; - task->all_link.prev = head->prev; - task->all_link.next = head; - head->prev->next = &task->all_link; - head->prev = &task->all_link; - - g_nr_tasks++; -} - -/* Remove task from global task list */ -static void task_list_remove(TaskControlBlock* task) -{ - LockGuard guard(g_task_list_lock); - - task->all_link.prev->next = task->all_link.next; - task->all_link.next->prev = task->all_link.prev; - task->all_link.init(); - - if (g_nr_tasks > 0) - g_nr_tasks--; -} - -/* ====================================================================== - * kthread_create — create a kernel thread - * ====================================================================== */ - -TaskControlBlock* kthread_create(const char* name, - void (*entry)(void*), - void* arg, - uint8 priority) -{ - TaskControlBlock* task = alloc_task(name, priority, TF_KTHREAD, - static_cast(arch::cpu::id())); - if (!task) return nullptr; - - /* Allocate PID */ - task->pid = g_pid_alloc.alloc(); - if (task->pid < 0) { - /* PID exhausted — clean up */ - pmm_free_pages(pa_to_page(phys_addr(task->kstack_pa)), 1); - delete task; - return nullptr; - } - task->tgid = task->pid; - - /* Kernel threads: exit_signal = -1 → auto-reap on exit. - * Linux: kernel_thread() passes (flags & ~CSIGNAL) → exit_signal = 0, - * but kthreads' parent (kthreadd) reaps them. We have no kthreadd, - * so we use -1 which makes exit_notify() call release_task() directly, - * identical to Linux's CLONE_THREAD autoreap path. */ - task->exit_signal = -1; - - /* Set up context for kthread_entry_trampoline. - * SP starts BELOW the TrapFrame reserved at the stack top. - * This ensures the kthread function never clobbers the TrapFrame area. */ - uint64 stack_top = task->kstack_va + kKernelStackSize - - sizeof(arch::TrapFrame); - task->context = {}; - task->context.ra = reinterpret_cast(kthread_entry_trampoline); - task->context.sp = stack_top; - task->context.s[0] = reinterpret_cast(entry); - task->context.s[1] = reinterpret_cast(arg); - - /* Parent is kernel_task (PID 0) or current caller */ - TaskControlBlock* parent = g_kernel_task ? g_kernel_task : current_task(); - task->parent = parent; - if (parent) { - LockGuard guard(parent->lock); - list_node* head = &parent->children; - task->sibling.prev = head->prev; - task->sibling.next = head; - head->prev->next = &task->sibling; - head->prev = &task->sibling; - } - - /* Add to global list and enqueue */ - task_list_add(task); - sched_enqueue(task); - - return task; -} - -/* ====================================================================== - * task_exit — transition current task to Zombie - * ====================================================================== */ - -void task_exit(int code) -{ - TaskControlBlock* curr = current_task(); - if (!curr) kernel_panic("task_exit: no current task"); - - /* Linux ABI: normal exit encodes status as (code & 0xFF) << 8 */ - curr->exit_code = (code & 0xFF) << 8; - - /* CLONE_CHILD_CLEARTID / set_tid_address: write 0 to user tidptr. - * This is how pthread_join detects thread termination. - * TODO: futex_wake(clear_child_tid, 1) after writing 0. */ - if (curr->clear_child_tid != 0 && curr->mm != nullptr) { - int32 zero = 0; - copy_to_user(curr->clear_child_tid, &zero, sizeof(zero)); - curr->clear_child_tid = 0; - } - - /* Release user address space (refcount-safe). - * MUST switch to kernel page table FIRST — otherwise we're running - * on a freed page table after put() deallocates it. */ - if (curr->mm != nullptr) { - extern uint64 g_kernel_pgtbl; - pmap::activate(g_kernel_pgtbl); - curr->mm->put(); - curr->mm = nullptr; - } - - /* Reparent children to init (or kernel_task if no init yet) */ - TaskControlBlock* foster = g_init_task ? g_init_task : g_kernel_task; - if (foster && !curr->children.is_empty()) { - LockGuard guard(curr->lock); - - list_node* child_node = curr->children.next; - while (child_node != &curr->children) { - list_node* next_sib = child_node->next; - auto* child = list_entry(child_node); - child->parent = foster; - - /* Move sibling link to foster's children */ - child_node->prev->next = child_node->next; - child_node->next->prev = child_node->prev; - - list_node* fhead = &foster->children; - child_node->prev = fhead->prev; - child_node->next = fhead; - fhead->prev->next = child_node; - fhead->prev = child_node; - - child_node = next_sib; - } - curr->children.init(); - } - - - /* ---- exit_notify: Linux kernel/exit.c:exit_notify() ---- - * Determine whether this task should be auto-reaped or become zombie. - * - * Linux logic (simplified): - * - exit_signal == -1 (kthreads, sub-threads): autoreap = true - * - exit_signal >= 1 (user processes): notify parent, become zombie - * - * If autoreap, we call release_task() equivalent inline: - * free PID, remove from task list, then deschedule to Dead. */ - bool autoreap = (curr->exit_signal <= 0); - - if (autoreap) { - /* Auto-reap: release resources immediately (no zombie state). - * Linux: exit_notify() → tsk->exit_state = EXIT_DEAD → release_task() */ - task_list_remove(curr); - g_pid_alloc.free(curr->pid); - - /* Remove from parent's children list */ - curr->sibling.prev->next = curr->sibling.next; - curr->sibling.next->prev = curr->sibling.prev; - curr->sibling.init(); - - /* Drop signal_struct ref: last task in the thread group also - * detaches us from the pgrp hash. */ - if (curr->signal) { - put_signal_struct(curr->signal); - curr->signal = nullptr; - } - if (curr->sighand) { - put_sighand(curr->sighand); - curr->sighand = nullptr; - } - - curr->state = TaskState::Dead; - schedule(); - __builtin_unreachable(); - } - - /* User process path: become Zombie for parent wait() */ - curr->state = TaskState::Zombie; - - /* Wake parent->wait_chld queue */ - if (curr->parent) { - curr->parent->wait_chld.wake_all(); - } - - /* Yield CPU — never returns */ - schedule(); - - __builtin_unreachable(); -} - -void task_kill_current(int sig) -{ - TaskControlBlock* curr = current_task(); - if (!curr) kernel_panic("task_kill_current: no current task"); - - /* Linux ABI: signal-killed encodes status as (signo & 0x7F) */ - curr->exit_code = sig & 0x7F; - - /* Release user address space (refcount-safe). - * Switch to kernel page table first (same as task_exit). */ - if (curr->mm) { - extern uint64 g_kernel_pgtbl; - pmap::activate(g_kernel_pgtbl); - curr->mm->put(); - curr->mm = nullptr; - } - - /* Reparent children (same as task_exit) */ - TaskControlBlock* foster = g_init_task ? g_init_task : g_kernel_task; - if (foster && !curr->children.is_empty()) { - LockGuard guard(curr->lock); - - list_node* child_node = curr->children.next; - while (child_node != &curr->children) { - list_node* next_sib = child_node->next; - auto* child = list_entry(child_node); - child->parent = foster; - - child_node->prev->next = child_node->next; - child_node->next->prev = child_node->prev; - - list_node* fhead = &foster->children; - child_node->prev = fhead->prev; - child_node->next = fhead; - fhead->prev->next = child_node; - fhead->prev = child_node; - - child_node = next_sib; - } - curr->children.init(); - } - - curr->state = TaskState::Zombie; - - if (curr->parent) { - curr->parent->wait_chld.wake_all(); - } - - schedule(); - __builtin_unreachable(); -} - -/* ====================================================================== - * task_destroy — fully reclaim a Zombie task (called by waitpid) - * ====================================================================== */ - -void task_destroy(TaskControlBlock* task) -{ - /* Remove from global list */ - task_list_remove(task); - - /* Remove from parent's children */ - task->sibling.prev->next = task->sibling.next; - task->sibling.next->prev = task->sibling.prev; - task->sibling.init(); - - /* Free PID */ - g_pid_alloc.free(task->pid); - - /* Drop signal_struct + sighand refs. For zombies these are delayed - * until reap (here) so a waitpid() walker can still inspect - * pgid/sid; Linux defers __exit_signal/__cleanup_sighand to - * release_task() for the same reason. */ - if (task->signal) { - put_signal_struct(task->signal); - task->signal = nullptr; - } - if (task->sighand) { - put_sighand(task->sighand); - task->sighand = nullptr; - } - - /* Free kernel stack */ - if (task->kstack_pa != 0) { - pmm_free_pages(pa_to_page(phys_addr(task->kstack_pa)), 1); - } - - /* Free TCB */ - delete task; -} - -/* ====================================================================== - * do_wait4 — wait for a child to exit (Linux-compatible) - * - * @wait_pid: >0 = specific child PID - * -1 = any child - * 0 = any child in same process group (TODO) - * <-1 = any child in specific process group (TODO) - * @options: WNOHANG = return immediately if no zombie - * @exit_code: output parameter (already in Linux wstatus format) - * - * Returns: PID of exited child, -ECHILD, or -EAGAIN (WNOHANG). - * ====================================================================== */ - -int32 do_wait4(int32 wait_pid, int options, int32* exit_code) -{ - TaskControlBlock* curr = current_task(); - if (!curr) return -EINVAL; - - while (true) { - TaskControlBlock* zombie = nullptr; - TaskControlBlock* report = nullptr; /* Stopped/Continued report */ - int32 report_status = 0; - bool has_children = false; - - /* - * Two-phase wait: put ourselves on the wait queue BEFORE - * checking the condition. This closes the race window where - * a child exits between our check and schedule(). - * - * If a child exits and calls wake_all() while we're checking, - * our state will be flipped back to Runnable, and schedule() - * will simply return immediately. - */ - curr->wait_chld.prepare_to_wait(curr, TaskState::Sleeping); - - /* Scan children */ - curr->lock.acquire(); - - if (curr->children.is_empty()) { - curr->lock.release(); - curr->wait_chld.finish_wait(curr); - return -ECHILD; - } - has_children = true; - - list_node* node = curr->children.next; - while (node != &curr->children) { - auto* child = list_entry(node); - bool matches = (wait_pid == -1) || (wait_pid == child->pid); - if (!matches) { - node = node->next; - continue; - } - - /* Zombie reaping has priority — it frees resources. */ - if (child->state == TaskState::Zombie) { - zombie = child; - break; - } - - /* WUNTRACED: report Stopped child once per stop event. */ - if ((options & WUNTRACED) && child->stopped_code != 0) { - report = child; - report_status = child->stopped_code; - break; - } - - /* WCONTINUED: report a one-shot SIGCONT resume. */ - if ((options & WCONTINUED) && child->notify_continued) { - report = child; - report_status = W_CONTINUED(); - break; - } - - node = node->next; - } - curr->lock.release(); - - if (zombie) { - curr->wait_chld.finish_wait(curr); - int32 pid = zombie->pid; - if (exit_code) *exit_code = zombie->exit_code; - task_destroy(zombie); - return pid; - } - - if (report) { - /* Status-only report: clear the one-shot flag, leave the - * child alive. WNOWAIT (peek) would skip the clear, but - * we don't yet honour it. */ - curr->wait_chld.finish_wait(curr); - int32 pid = report->pid; - if (exit_code) *exit_code = report_status; - if (W_CONTINUED() == report_status) { - report->notify_continued = false; - } else { - report->stopped_code = 0; - } - return pid; - } - - /* No event to report */ - if (!has_children) { - curr->wait_chld.finish_wait(curr); - return -ECHILD; - } - if (options & WNOHANG) { - curr->wait_chld.finish_wait(curr); - return 0; - } - - /* Condition still false — deschedule. - * We are already on the wait queue and marked Sleeping. */ - schedule(); - - /* Woken up — finish_wait removes us from queue, restores Runnable */ - curr->wait_chld.finish_wait(curr); - - /* Loop back to re-check the condition */ - } -} - -/* Legacy wrapper for internal callers */ -int32 task_wait(int32* exit_code) -{ - return do_wait4(-1, 0, exit_code); -} - -/* ====================================================================== - * task_clone — clone current task with Linux-compatible flags - * - * @tf: trap frame to copy to child - * @clone_flags: CLONE_VM | CLONE_THREAD | CSIGNAL etc. - * @child_stack: if non-zero, set as child's user SP (for pthread) - * @parent_tidptr: write child tid here in parent (CLONE_PARENT_SETTID) - * @child_tidptr: write child tid here in child (CLONE_CHILD_SETTID) - * @tls: TLS pointer (CLONE_SETTLS → tp register) - * - * Returns: child PID in parent, 0 in child, or negative errno. - * ====================================================================== */ - -int32 task_clone(arch::TrapFrame* tf, uint64 clone_flags, - uint64 child_stack, uint64 parent_tidptr, - uint64 child_tidptr, uint64 tls) -{ - TaskControlBlock* curr = current_task(); - if (!curr) return -EINVAL; - - TaskControlBlock* child = alloc_task("cloned", curr->priority, 0, - static_cast(arch::cpu::id())); - if (!child) return -ENOMEM; - - /* Allocate PID */ - child->pid = g_pid_alloc.alloc(); - if (child->pid < 0) { - pmm_free_pages(pa_to_page(phys_addr(child->kstack_pa)), 1); - delete child; - return -ENOMEM; - } - - /* exit_signal + tgid: from clone_flags. - * Linux: fork.c line 2418/2424 */ - if (clone_flags & CLONE_THREAD) { - child->tgid = curr->tgid; - child->exit_signal = -1; /* Linux: sub-threads auto-reap */ - } else { - child->tgid = child->pid; - child->exit_signal = static_cast(clone_flags & 0xFF); /* CSIGNAL */ - if (child->exit_signal == 0) { - child->exit_signal = SIGCHLD; /* default for fork() */ - } - } - - /* Address space: CLONE_VM shares, otherwise deep copy */ - if (clone_flags & CLONE_VM) { - if (curr->mm) { - curr->mm->incref(); - child->mm = curr->mm; - } - } else { - if (curr->mm) { - child->mm = vmm_clone(curr->mm); - if (!child->mm) { - g_pid_alloc.free(child->pid); - pmm_free_pages(pa_to_page(phys_addr(child->kstack_pa)), 1); - delete child; - return -ENOMEM; - } - } - } - - /* Copy TrapFrame to the child's kernel stack */ - uint64 tf_addr = child->kstack_va + kKernelStackSize - sizeof(arch::TrapFrame); - child->trapframe = reinterpret_cast(tf_addr); - *child->trapframe = *tf; - - /* Set Kernel SP */ - child->trapframe->kernel_sp = reinterpret_cast(child->trapframe); - child->trapframe->kernel_cpu_id = child->cpu_id; - - /* Child returns 0 from fork/clone */ - child->trapframe->a[0] = 0; - - /* If caller specified a child stack, use it (pthread_create) */ - if (child_stack != 0) { - child->trapframe->sp = child_stack; - } - - /* CLONE_SETTLS: set thread pointer register */ - if (clone_flags & CLONE_SETTLS) { - child->trapframe->tp = tls; - } - - /* Set up context for ret_from_fork */ - uint64 stack_top = tf_addr; - child->context = {}; - child->context.ra = reinterpret_cast(ret_from_fork); - child->context.sp = stack_top; - child->context.s[0] = tf_addr; - - /* ---- Copy fs_struct (Linux: copy_fs in fork.c) ---- - * CLONE_FS: share the same fs_struct (increment refcount). - * Otherwise: allocate a new fs_struct copying root/pwd. */ - if (curr->fs != nullptr) { - if (clone_flags & CLONE_FS) { - curr->fs->count.fetch_add(1, __ATOMIC_RELAXED); - child->fs = curr->fs; - } else { - child->fs = copy_fs_struct(curr->fs); - } - } - - /* ---- Copy files_struct (Linux: copy_files in fork.c) ---- - * CLONE_FILES: share the same fd table. - * Otherwise: duplicate the fd table. */ - if (curr->files != nullptr) { - if (clone_flags & CLONE_FILES) { - curr->files->count.fetch_add(1, __ATOMIC_RELAXED); - child->files = curr->files; - } else { - child->files = dup_fd(curr->files); - } - } - - /* ---- Copy sighand (Linux kernel/fork.c:copy_sighand) ---- - * CLONE_SIGHAND: share signal handlers (incref parent's). - * Otherwise: deep copy of the action table; child gets its own - * sighand_struct (and its own siglock). Both branches MUST yield - * a non-null sighand — every user task needs one so signal paths - * can take the siglock without lazy-allocation races. */ - if (clone_flags & CLONE_SIGHAND) { - if (!curr->sighand) { - /* CLONE_SIGHAND requires the parent to have a sighand. */ - return -EINVAL; - } - get_sighand(curr->sighand); - child->sighand = curr->sighand; - } else { - child->sighand = copy_sighand(curr->sighand); - if (!child->sighand) { - /* OOM — same best-effort policy as fs/files/signal above. - * A separate cleanup-on-OOM pass is on the to-do list. */ - } - } - - /* ---- Copy signal_struct (Linux: copy_signal in fork.c) ---- - * CLONE_THREAD shares the parent's signal_struct (incref). - * Otherwise allocate a new one that inherits pgid/sid/tty from the - * parent so the child stays in the same process group and session — - * this is what makes fork() participate in the existing job-control - * identity without explicit setpgid() calls. */ - if (curr->signal != nullptr) { - if (clone_flags & CLONE_THREAD) { - get_signal_struct(curr->signal); - child->signal = curr->signal; - } else { - child->signal = fork_signal_struct(curr->signal, child); - } - } - - /* Add to task tree */ - child->parent = curr; - { - LockGuard guard(curr->lock); - list_node* head = &curr->children; - child->sibling.prev = head->prev; - child->sibling.next = head; - head->prev->next = &child->sibling; - head->prev = &child->sibling; - } - - /* Add to global list and enqueue */ - task_list_add(child); - sched_enqueue(child); - - /* CLONE_PARENT_SETTID: write child tid to parent's user address */ - if ((clone_flags & CLONE_PARENT_SETTID) && parent_tidptr != 0) { - copy_to_user(parent_tidptr, &child->pid, sizeof(child->pid)); - } - - /* CLONE_CHILD_SETTID: write child tid into child's user address. - * Note: this runs in parent context, but the address is in the - * child's mm. For CLONE_VM (threads), parent and child share mm - * so this works directly. For fork, the page was just CoW-copied. */ - if ((clone_flags & CLONE_CHILD_SETTID) && child_tidptr != 0) { - if (clone_flags & CLONE_VM) { - /* Same address space — write directly */ - copy_to_user(child_tidptr, &child->pid, sizeof(child->pid)); - } - /* For non-CLONE_VM fork, the child's mm is separate. - * The write would need to go into the child's pagetable. - * Linux handles this in the child's first schedule via - * a special flag. For now, threads (CLONE_VM) are the - * primary consumer. */ - } - - /* CLONE_CHILD_CLEARTID: kernel writes 0 to child_tidptr on exit */ - if (clone_flags & CLONE_CHILD_CLEARTID) { - child->clear_child_tid = child_tidptr; - } - - return child->pid; -} - -/* Legacy wrapper — plain fork() semantics */ -int32 task_fork(arch::TrapFrame* tf) -{ - return task_clone(tf, SIGCHLD, 0, 0, 0, 0); -} - - -/* ====================================================================== - * task_check_stack_canary - * ====================================================================== */ - -void task_check_stack_canary(TaskControlBlock* task) -{ - if (!task || task->kstack_va == 0) return; - - auto* canary = reinterpret_cast(task->kstack_va); - if (*canary != kStackCanary) { - kernel_panic("kernel stack overflow detected"); - } -} diff --git a/kernel/timer.cc b/kernel/timer.cc deleted file mode 100644 index 3cf03cf..0000000 --- a/kernel/timer.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include -#include -#include -#include - -#include - -uint64 g_jiffies = 0; -static uint64 g_timer_freq = 10000000; -static uint64 g_tick_interval = 0; - -static list_node g_timer_list; -static Spinlock g_timer_lock; - - -void add_timer(TimerList* timer) { - LockGuard guard(g_timer_lock); - - list_node* pos; - list_for_each(pos, &g_timer_list) { - TimerList* t = list_entry(pos); - if (t->expires > timer->expires) { - break; - } - } - - timer->entry.prev = pos->prev; - timer->entry.next = pos; - pos->prev->next = &timer->entry; - pos->prev = &timer->entry; -} - -int del_timer(TimerList* timer) { - LockGuard guard(g_timer_lock); - if (timer->entry.next != nullptr && timer->entry.next != &timer->entry) { - timer->entry.prev->next = timer->entry.next; - timer->entry.next->prev = timer->entry.prev; - timer->entry.init(); - return 1; - } - return 0; -} - -int mod_timer(TimerList* timer, uint64 expires) { - int ret = del_timer(timer); - timer->expires = expires; - add_timer(timer); - return ret; -} - -static void run_timers() { - g_timer_lock.acquire(); - - while (!g_timer_list.is_empty()) { - TimerList* t = list_entry(g_timer_list.next); - if (t->expires > g_jiffies) { - break; - } - - t->entry.prev->next = t->entry.next; - t->entry.next->prev = t->entry.prev; - t->entry.init(); - - g_timer_lock.release(); - t->function(t); - g_timer_lock.acquire(); - } - - g_timer_lock.release(); -} - -static void timer_set_next() { - arch::sbi::set_timer(arch::cpu::read_time() + g_tick_interval); -} - -void timer_init() { - DeviceNode* cpus = fdt_get_node_by_path("/cpus"); - if (cpus) { - g_timer_freq = cpus->get_prop_u32("timebase-frequency", g_timer_freq); - } - - // Default 100 Hz (10ms per tick) - g_tick_interval = g_timer_freq / 100; - - g_timer_lock.init("timer_list"); - g_timer_list.init(); - - timer_set_next(); - - arch::cpu::timer_intr_on(); -} - - -void timer_init_ap() { - timer_set_next(); - arch::cpu::timer_intr_on(); -} - -extern "C" uint32 bsp_hart_id; - -void timer_tick() { - if (arch::cpu::id() == bsp_hart_id) { - g_jiffies++; - run_timers(); - } - - timer_set_next(); - sched_tick(); -} - - -uint64 timer_get_freq() { - return g_timer_freq; -} diff --git a/kernel/trap.cc b/kernel/trap.cc deleted file mode 100644 index 2116d91..0000000 --- a/kernel/trap.cc +++ /dev/null @@ -1,258 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Trap MI Layer — Machine-Independent Semantic Dispatcher - * - * Receives a translated TrapCause from the MD layer and routes to - * the appropriate handler. - * - * *** MI INVARIANT: This file contains ZERO inline assembly, - * ZERO arch-specific constants (no CSR reads, no scause codes). *** - * arch/trapframe.h is included because TrapFrame is the cross-layer - * data contract defined in docs/specs/arch_abstraction.md §3.2. - * - * Reference: docs/specs/trap.md §4 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* TrapFrame: cross-layer data contract */ -#include /* search_extable: kernel fault recovery */ - -/* ======================================================================== - * trap_handle() — MI-layer dispatcher for traps - * - * Called by MD layer after scause → TrapInfo translation. - * ======================================================================== */ - -static TrapStats g_trap_stats = {}; - -static uint32 trap_cause_index(TrapCause cause) -{ - uint32 raw = static_cast(cause); - - /* Exceptions 0-7 map directly to indices 0-7 */ - if (raw <= 7) { - return raw; - } - /* IRQs 16-18 map to indices 8-10 */ - if (raw >= 16 && raw <= 18) { - return raw - 16 + 8; - } - /* Unknown / out-of-range */ - return 11; -} - -static void trap_record(const TrapInfo& info) -{ - uint32 idx = trap_cause_index(info.cause); - __atomic_fetch_add(&g_trap_stats.total, 1, __ATOMIC_RELAXED); - __atomic_fetch_add(&g_trap_stats.by_cause[idx], 1, __ATOMIC_RELAXED); - g_trap_stats.last_cause = info.cause; - g_trap_stats.last_class = info.cls; - g_trap_stats.last_origin = info.origin; - g_trap_stats.last_val = info.val; - g_trap_stats.last_epc = info.epc; - g_trap_stats.last_scause = info.scause; -} - -static VmFaultCause vm_fault_cause_from_trap(TrapCause cause) -{ - switch (cause) { - case TrapCause::PageFaultStore: - return VmFaultCause::Write; - case TrapCause::PageFaultExec: - return VmFaultCause::Exec; - case TrapCause::PageFaultLoad: - default: - return VmFaultCause::Read; - } -} - -void trap_stats_get(TrapStats* out) -{ - if (!out) { - return; - } - *out = g_trap_stats; -} - -void trap_stats_reset() -{ - g_trap_stats = {}; -} - -void trap_handle(arch::TrapFrame* tf, const TrapInfo& info) -{ - trap_record(info); - - /* ---- Kernel exception handling ---- - * Interrupts are always allowed through. For exceptions: - * - Page faults: handled in the switch below (extable fixup path) - * - Other exceptions: try extable, then panic. - * - * This replaces the old blanket kernel_panic, enabling - * copy_from_user/copy_to_user to safely fault on user pages. */ - if (info.origin == TrapOrigin::FromKernel && - info.cls != TrapClass::Interrupt) { - - /* Page faults are dispatched in the switch — let them through */ - bool is_page_fault = - (info.cause == TrapCause::PageFaultLoad || - info.cause == TrapCause::PageFaultStore || - info.cause == TrapCause::PageFaultExec); - - if (!is_page_fault) { - /* Non-page-fault kernel exception: try extable fixup */ - uint64 fixup = search_extable(info.epc); - if (fixup != 0) { - tf->epc = fixup; - return; - } - kprintf("[trap] fatal kernel exception: cause=%u epc=0x%llx val=0x%llx\n", - static_cast(info.cause), info.epc, info.val); - kernel_panic("unrecoverable kernel exception"); - } - } - - switch (info.cause) { - /* ---- Page Faults ---- */ - case TrapCause::PageFaultLoad: - case TrapCause::PageFaultStore: - case TrapCause::PageFaultExec: - if (info.origin == TrapOrigin::FromUser) { - TaskControlBlock* curr = current_task(); - if (!curr || !curr->mm) { - kernel_panic("user page fault with no current mm"); - } - - int ret = vmm_handle_page_fault(curr->mm, info.val, - vm_fault_cause_from_trap(info.cause)); - if (ret == -EFAULT) { - kprintf("[trap] user SIGSEGV (MAPERR) epc=0x%llx addr=0x%llx\n", - info.epc, info.val); - force_sig_fault(SIGSEGV, 1 /* SEGV_MAPERR */, info.val); - } else if (ret == -ENOMEM) { - kprintf("[trap] user SIGKILL (OOM) epc=0x%llx addr=0x%llx\n", - info.epc, info.val); - force_sig_fault(SIGKILL, 0, info.val); - } else if (ret < 0) { - kprintf("[trap] user SIGSEGV (ACCERR) epc=0x%llx addr=0x%llx\n", - info.epc, info.val); - force_sig_fault(SIGSEGV, 2 /* SEGV_ACCERR */, info.val); - } - break; - } - - /* Kernel page fault — try exception table fixup. - * This is the path used by copy_from_user/copy_to_user when - * accessing unmapped or faulting user addresses from S-mode. */ - { - uint64 fixup = search_extable(info.epc); - if (fixup != 0) { - tf->epc = fixup; - break; - } - } - kprintf("[trap] kernel page fault: epc=0x%llx addr=0x%llx\n", - info.epc, info.val); - { - TaskControlBlock* curr = current_task(); - if (curr) { - kprintf("[trap] pid=%d state=%d\n", - curr->pid, static_cast(curr->state)); - kprintf("[trap] tf->epc=%llx tf->ra=%llx tf->sp=%llx\n", - tf->epc, tf->ra, tf->sp); - } - } - kernel_panic("unhandled kernel page fault (no extable entry)"); - break; - - /* ---- System Call ---- */ - case TrapCause::Syscall: - syscall_dispatch_md(tf); - break; - - /* ---- Interrupts ---- */ - case TrapCause::IrqTimer: - /* Timer tick */ - timer_tick(); - break; - - case TrapCause::IrqExternal: { - /* External interrupt: generic claim → dispatch → complete */ - uint32 irq = g_irq_manager.claim(); - if (irq != 0) { - g_irq_manager.dispatch(irq); - g_irq_manager.complete(irq); - } - break; - } - - case TrapCause::IrqSoftware: - /* S-mode software interrupt = IPI from another hart */ - smp_handle_ipi(); - break; - - /* ---- Fatal exceptions ---- */ - case TrapCause::IllegalInst: - if (info.origin == TrapOrigin::FromUser) { - kprintf("[trap] user illegal instruction at epc=0x%llx stval=0x%llx\n", - info.epc, info.val); - force_sig_fault(SIGILL, 1 /* ILL_ILLOPC */, info.epc); - } else { - kprintf("[trap] illegal instruction at epc=0x%llx\n", info.epc); - kernel_panic("illegal instruction in kernel mode"); - } - break; - - case TrapCause::AccessFault: - kprintf("[trap] access fault\n"); - kernel_panic("access fault"); - break; - - case TrapCause::AlignFault: - kprintf("[trap] alignment fault\n"); - kernel_panic("alignment fault"); - break; - - case TrapCause::Breakpoint: - kprintf("[trap] breakpoint\n"); - /* ebreak advance is handled by MD layer (arch-specific instruction size) */ - break; - - case TrapCause::Unknown: - default: - kprintf("[trap] unknown trap\n"); - kernel_panic("unknown trap"); - break; - } - - /* Process pending signals before returning to user mode */ - if (info.origin == TrapOrigin::FromUser) { - do_signal(tf); - } - - /* Preemption check on return from any interrupt. - * This is the kernel's equivalent of Linux's retint_kernel path: - * if a timer tick (or IPI) set need_resched, we must call schedule() - * before returning — otherwise the idle loop never yields to - * runnable tasks like PID 1. */ - if (info.cls == TrapClass::Interrupt) { - sched_check_preempt(); - } -} diff --git a/kernel/uaccess.cc b/kernel/uaccess.cc deleted file mode 100644 index 14c5fb7..0000000 --- a/kernel/uaccess.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * User-Kernel Memory Copy — Phase 3 (Exception Tables) - * - * Validates user pointers by checking they fall within user address space - * (below KERNEL_VA_BASE). Uses assembly-level safe copy functions that - * integrate with the kernel's Exception Table mechanism. - * - * Reference: docs/specs/syscall.md §8 - */ - -#include -#include -#include -#include -#include - -extern "C" int __uaccess_memcpy(void* dst, const void* src, uint64 len); -extern "C" int64 __uaccess_strncpy(char* dst, const char* src, uint64 max_len); - -int copy_from_user(void* kernel_dst, uint64 user_src, uint64 len) -{ - if (len == 0) return 0; - if (!is_user_range(user_src, len)) return -EFAULT; - - return __uaccess_memcpy(kernel_dst, reinterpret_cast(user_src), len); -} - -int copy_to_user(uint64 user_dst, const void* kernel_src, uint64 len) -{ - if (len == 0) return 0; - if (!is_user_range(user_dst, len)) return -EFAULT; - - return __uaccess_memcpy(reinterpret_cast(user_dst), kernel_src, len); -} - -int64 strncpy_from_user(char* kernel_dst, uint64 user_src, uint64 max_len) -{ - if (!is_user_range(user_src, 1)) return -EFAULT; - - /* We must also check that the string does not cross into kernel space. - This is safely handled by the assembly routine which will fault if it hits - an unmapped page. However, to strictly respect kKernelVaBase, we should - restrict max_len to the distance to kKernelVaBase. */ - uint64 max_allowed = kKernelVaBase - user_src; - if (max_len > max_allowed) { - max_len = max_allowed; - } - - return __uaccess_strncpy(kernel_dst, reinterpret_cast(user_src), max_len); -} diff --git a/kernel/waitqueue.cc b/kernel/waitqueue.cc deleted file mode 100644 index 9689417..0000000 --- a/kernel/waitqueue.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * WaitQueue — blocking synchronization implementation - * - * Two-phase wait protocol: - * - * prepare_to_wait(): task → Sleeping, link into queue - * [caller checks condition — if still false, calls schedule()] - * finish_wait(): remove from queue, restore Runnable - * - * Legacy sleep() wraps the two-phase pattern for simple callers. - * - * wake_one()/wake_all(): dequeue waiters → Runnable, sched_enqueue() - * - * The internal spinlock protects the wait list only. - * schedule() is called AFTER releasing all spinlocks to avoid - * holding a lock across a context switch. - */ - -#include -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Two-phase wait API */ -/* ------------------------------------------------------------------ */ - -void WaitQueue::prepare_to_wait(TaskControlBlock* task, TaskState new_state) -{ - LockGuard guard(lock_); - - /* Set state BEFORE linking — this is the key to preventing lost wakeups. - * If wake_one fires between now and schedule(), it will set state back - * to Runnable, and schedule() will see Runnable and not block. */ - task->state = new_state; - - /* Only add to queue if not already linked (idempotent) */ - if (task->run_link.next == &task->run_link) { - /* Link into wait queue tail */ - list_node* node = &task->run_link; - node->prev = head_.prev; - node->next = &head_; - head_.prev->next = node; - head_.prev = node; - } -} - -void WaitQueue::finish_wait(TaskControlBlock* task) -{ - LockGuard guard(lock_); - - /* Remove from wait queue if still linked */ - if (task->run_link.next != &task->run_link) { - list_node* node = &task->run_link; - node->prev->next = node->next; - node->next->prev = node->prev; - node->init(); - } - - /* Ensure task is Runnable (it may have been woken by wake_one/wake_all - * already, or it may never have slept if the condition was true). */ - if (task->state == TaskState::Sleeping) { - task->state = TaskState::Runnable; - } -} - -/* ------------------------------------------------------------------ */ -/* Legacy convenience API */ -/* ------------------------------------------------------------------ */ - -void WaitQueue::sleep(Spinlock* external_lock) -{ - TaskControlBlock* curr = current_task(); - if (!curr) { - if (external_lock) external_lock->release(); - return; - } - - /* Phase 1: add to queue, mark Sleeping */ - prepare_to_wait(curr, TaskState::Sleeping); - - /* Release external lock AFTER we are on the queue (critical ordering) */ - if (external_lock) { - external_lock->release(); - } - - /* Phase 2: context switch away — will return here when woken */ - schedule(); - - /* Phase 3: clean up */ - finish_wait(curr); -} - -/* ------------------------------------------------------------------ */ -/* Wakeup */ -/* ------------------------------------------------------------------ */ - -bool WaitQueue::wake_one() -{ - LockGuard guard(lock_); - - if (head_.is_empty()) - return false; - - /* Dequeue the first (oldest) waiter */ - list_node* node = head_.next; - node->prev->next = node->next; - node->next->prev = node->prev; - node->init(); - - TaskControlBlock* task = - list_entry(node); - - task->state = TaskState::Runnable; - sched_enqueue(task); - - return true; -} - -int WaitQueue::wake_all() -{ - LockGuard guard(lock_); - - int count = 0; - while (!head_.is_empty()) { - list_node* node = head_.next; - node->prev->next = node->next; - node->next->prev = node->prev; - node->init(); - - TaskControlBlock* task = - list_entry(node); - - task->state = TaskState::Runnable; - sched_enqueue(task); - count++; - } - - return count; -} diff --git a/lib/Build.mk b/lib/Build.mk deleted file mode 100644 index 2d5a095..0000000 --- a/lib/Build.mk +++ /dev/null @@ -1,49 +0,0 @@ -targets += lib/ktl/headers lib/libc/headers lib/ktl lib/runtime lib/string \ - lib/libfdt lib/core - -target.lib/ktl/headers.kind := header-library -target.lib/ktl/headers.public-includes := lib/ktl/include -target.lib/ktl/headers.public-after-includes := lib/ktl/include-after - -target.lib/libc/headers.kind := header-library -target.lib/libc/headers.public-includes := lib/libc/include -target.lib/libc/headers.public-after-includes := lib/libc/include-after -target.lib/libc/headers.deps := lib/ktl/headers - -target.lib/ktl.kind := source-set -target.lib/ktl.sources := lib/ktl/popcount.cc lib/ktl/stub-new.cc -target.lib/ktl.deps := lib/ktl/headers lib/libc/headers - -target.lib/runtime.kind := source-set -target.lib/runtime.sources := \ - lib/cxx_abi.cc lib/rbtree.cc lib/kobject.cc lib/kprintf.cc lib/klog.cc \ - lib/random.cc lib/printf.c - -target.lib/string.kind := static-library -target.lib/string.sources := $(sort $(wildcard lib/string/*.c)) - -# Architecture assembly replaces the matching generic C implementation. -string-arch.riscv := -string-arch.x86_64 := x86_64 -string-arch.aarch64 := aarch64 -string-arch.i386 := i386 -string-arch.arm := arm -string-arch := $(string-arch.$(ARCH)) -ifneq ($(string-arch),) -string-asm := $(sort $(wildcard lib/string/$(string-arch)/*.S) \ - $(wildcard lib/string/$(string-arch)/*.s)) -string-asm-names := $(sort $(basename $(notdir $(string-asm)))) -target.lib/string.sources := $(filter-out \ - $(foreach name,$(string-asm-names),lib/string/$(name).c), \ - $(target.lib/string.sources)) $(string-asm) -endif - -target.lib/libfdt.kind := static-library -target.lib/libfdt.sources := \ - lib/fdt.c lib/fdt_ro.c lib/fdt_wip.c lib/fdt_rw.c lib/fdt_sw.c \ - lib/fdt_strerror.c lib/fdt_empty_tree.c lib/fdt_addresses.c -target.lib/libfdt.private-includes := scripts/dtc/libfdt -target.lib/libfdt.cflags := -Wno-parentheses -Wno-sign-compare - -target.lib/core.kind := header-library -target.lib/core.deps := lib/ktl lib/libc/headers lib/runtime lib/string lib/libfdt diff --git a/lib/cxx_abi.cc b/lib/cxx_abi.cc deleted file mode 100644 index 872b4a2..0000000 --- a/lib/cxx_abi.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * cxx_abi.cc — Minimal C++ ABI stubs for freestanding kernel - * - * Provides symbols that the compiler/linker expects from the C++ - * runtime library. All error paths are fatal (kernel_panic). - * - * Reference: docs/specs/cpp_runtime.md - */ - -#include - -/* Pure virtual function call trap. - * Generated by the compiler in vtable entries for pure virtual methods. - * Reaching this means a derived class failed to implement a pure virtual. */ -extern "C" void __cxa_pure_virtual() -{ - kernel_panic("pure virtual function call"); -} - -/* Global destructor registration. - * The kernel does not support global object destruction — all global - * objects use Placement New with explicit lifetime management. - * If the compiler emits a call to this, it indicates a code violation. */ -extern "C" int __cxa_atexit(void (*)(void*), void*, void*) -{ - kernel_panic("__cxa_atexit called in kernel"); - return 0; // unreachable -} - -/* DSO handle — required by __cxa_atexit ABI. - * The kernel is statically linked; this symbol just needs to exist. */ -extern "C" { -void* __dso_handle __attribute__((visibility("hidden"))) = nullptr; -} diff --git a/lib/fdt.c b/lib/fdt.c deleted file mode 100644 index 1b20383..0000000 --- a/lib/fdt.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt.c" diff --git a/lib/fdt_addresses.c b/lib/fdt_addresses.c deleted file mode 100644 index d58f896..0000000 --- a/lib/fdt_addresses.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt_addresses.c" diff --git a/lib/fdt_empty_tree.c b/lib/fdt_empty_tree.c deleted file mode 100644 index 37f8ef8..0000000 --- a/lib/fdt_empty_tree.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt_empty_tree.c" diff --git a/lib/fdt_ro.c b/lib/fdt_ro.c deleted file mode 100644 index 3599d49..0000000 --- a/lib/fdt_ro.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt_ro.c" diff --git a/lib/fdt_rw.c b/lib/fdt_rw.c deleted file mode 100644 index 65d7a71..0000000 --- a/lib/fdt_rw.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt_rw.c" diff --git a/lib/fdt_strerror.c b/lib/fdt_strerror.c deleted file mode 100644 index dae35ea..0000000 --- a/lib/fdt_strerror.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt_strerror.c" diff --git a/lib/fdt_sw.c b/lib/fdt_sw.c deleted file mode 100644 index d04f220..0000000 --- a/lib/fdt_sw.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt_sw.c" diff --git a/lib/fdt_wip.c b/lib/fdt_wip.c deleted file mode 100644 index ebfb3c1..0000000 --- a/lib/fdt_wip.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../scripts/dtc/libfdt/fdt_wip.c" diff --git a/lib/klog.cc b/lib/klog.cc deleted file mode 100644 index 86c67f8..0000000 --- a/lib/klog.cc +++ /dev/null @@ -1,574 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * klog.cc — Kernel logging subsystem implementation - * - * Implements the ring buffer, spinlock-protected writes, log level - * filtering, and synchronous console output. - * - * Phase 2 TODO: async flush via kernel thread (see docs/specs/klog.md) - */ - -#include -#include -#include -#include -#include -#include - -/* Forward declaration — mpaland/printf */ -extern "C" int vsnprintf_(char* buffer, size_t count, - const char* format, __builtin_va_list va); - -/* ======================================================================== - * Ring Buffer State - * ======================================================================== */ - -struct KlogEntryHdr { - uint32 seq; - uint32 len; - uint64 ts; - uint16 cpu; - uint8 level; - uint8 subsys; - uint16 reserved; -}; - -static struct { - char data[KLOG_BUF_SIZE]; - uint32 head; /* Next write position */ - uint32 tail; /* Next read position (for /proc/kmsg) */ - uint32 console_tail; /* Next position to flush to console */ - uint32 dropped; - lume::atomic seq; - uint64 subsys_mask; - Spinlock lock; - KlogLevel console_level; /* Messages <= this level go to UART */ - bool initialized; - bool panic_mode; -} g_klog; - -/* ======================================================================== - * Level name table - * ======================================================================== */ - -static const char* klog_level_name(KlogLevel level) -{ - static const char* names[] = { - "EMERG", "ALERT", "CRIT", "ERR", - "WARN", "NOTICE", "INFO", "DEBUG" - }; - if (level <= KLOG_DEBUG) { - return names[level]; - } - return "?"; -} - -static const char* klog_subsys_name(KlogSubsys subsys) -{ - static const char* names[] = { - "GEN", - "SCHED", - "TRAP", - "IRQ", - "TIMER", - "VMM", - "PMM", - "SLAB", - "FS", - "DRV", - "TEST", - }; - if (subsys < KLOG_SUBSYS_MAX) { - return names[subsys]; - } - return "?"; -} - -static const char* parse_kern_level(const char* fmt, KlogLevel* level) -{ - if (!fmt || !level) { - return fmt; - } - - /* Linux-style "\001n" prefix (KERN_SOH) */ - if (fmt[0] == '\001' && fmt[1] >= '0' && fmt[1] <= '7') { - *level = static_cast(fmt[1] - '0'); - return fmt + 2; - } - - /* Alternate "" prefix */ - if (fmt[0] == '<' && fmt[1] >= '0' && fmt[1] <= '7' && fmt[2] == '>') { - *level = static_cast(fmt[1] - '0'); - return fmt + 3; - } - - return fmt; -} - -/* ======================================================================== - * Ring Buffer Operations - * ======================================================================== */ - -/* Write a byte to the ring buffer. Overwrites oldest data on overflow. */ -static inline uint32 min_u32(uint32 a, uint32 b) -{ - return (a < b) ? a : b; -} - -static void ring_write_bytes(const void* src, uint32 len) -{ - const char* p = reinterpret_cast(src); - for (uint32 i = 0; i < len; ++i) { - g_klog.data[(g_klog.head + i) & (KLOG_BUF_SIZE - 1)] = p[i]; - } - g_klog.head += len; -} - -static void ring_read_bytes(uint32 pos, void* dst, uint32 len) -{ - char* out = reinterpret_cast(dst); - for (uint32 i = 0; i < len; ++i) { - out[i] = g_klog.data[(pos + i) & (KLOG_BUF_SIZE - 1)]; - } -} - -static void ring_drop_oldest(uint32 needed) -{ - uint32 min_tail = min_u32(g_klog.tail, g_klog.console_tail); - - while (KLOG_BUF_SIZE - (g_klog.head - min_tail) < needed) { - KlogEntryHdr hdr; - ring_read_bytes(min_tail, &hdr, sizeof(hdr)); - - uint32 entry = sizeof(hdr) + hdr.len; - if (entry == 0 || entry > KLOG_BUF_SIZE) { - min_tail++; - g_klog.dropped++; - continue; - } - min_tail += entry; - g_klog.dropped++; - } - - if (g_klog.tail < min_tail) { - g_klog.tail = min_tail; - } - if (g_klog.console_tail < min_tail) { - g_klog.console_tail = min_tail; - } -} - -/* ======================================================================== - * Console Output (synchronous) - * ======================================================================== */ - -static void console_emit(const char* s, int len) -{ - console_write_all(s, len); -} - -static int klog_format_line(char* out, int out_size, - const KlogEntryHdr& hdr, - const char* msg, int msg_len) -{ - const char* lvl = klog_level_name(static_cast(hdr.level)); - const char* subsys = klog_subsys_name(static_cast(hdr.subsys)); - - int prefix = ksnprintf(out, out_size, - "[%s][cpu%u][%llu][%s] ", - lvl, (uint32)hdr.cpu, - (unsigned long long)hdr.ts, subsys); - if (prefix < 0) { - return 0; - } - - int total = prefix; - int avail = out_size - 1 - total; - if (avail > 0) { - int to_copy = (msg_len < avail) ? msg_len : avail; - for (int i = 0; i < to_copy; ++i) { - out[total + i] = msg[i]; - } - total += to_copy; - } - - if (total > 0 && out[total - 1] != '\n' && total < out_size - 1) { - out[total++] = '\n'; - } - - out[total] = '\0'; - return total; -} - -static int klog_read_internal(char* buf, int size, uint32* tail_ptr, bool consume) -{ - if (size <= 0) { - return 0; - } - - int written = 0; - uint32 pos = *tail_ptr; - - while (pos != g_klog.head) { - KlogEntryHdr hdr; - ring_read_bytes(pos, &hdr, sizeof(hdr)); - uint32 raw_len = hdr.len; - if (raw_len > KLOG_BUF_SIZE) { - break; - } - uint32 copy_len = raw_len; - if (copy_len > KLOG_LINE_MAX) { - copy_len = KLOG_LINE_MAX; - } - - char msg[KLOG_LINE_MAX + 1]; - ring_read_bytes(pos + sizeof(hdr), msg, copy_len); - msg[copy_len] = '\0'; - - char line[KLOG_LINE_MAX + 64]; - int line_len = klog_format_line(line, sizeof(line), hdr, msg, - static_cast(copy_len)); - - if (line_len <= 0 || written + line_len > size) { - break; - } - - for (int i = 0; i < line_len; ++i) { - buf[written + i] = line[i]; - } - written += line_len; - - pos += sizeof(hdr) + raw_len; - } - - if (consume) { - *tail_ptr = pos; - } - - return written; -} - -static void klog_vex(KlogLevel level, KlogSubsys subsys, - const char* fmt, __builtin_va_list va); - -/* ======================================================================== - * Public API - * ======================================================================== */ - -void klog_init(void) -{ - g_klog.head = 0; - g_klog.tail = 0; - g_klog.console_tail = 0; - g_klog.dropped = 0; - g_klog.seq.store(0, __ATOMIC_RELAXED); - g_klog.subsys_mask = (1ULL << KLOG_SUBSYS_MAX) - 1; - g_klog.console_level = static_cast(KLOG_DEFAULT_LEVEL); - g_klog.initialized = true; - g_klog.panic_mode = false; - g_klog.lock.init("klog"); -} - -void klog(KlogLevel level, const char* fmt, ...) -{ - __builtin_va_list va; - __builtin_va_start(va, fmt); - klog_vex(level, KLOG_SUBSYS_GENERIC, fmt, va); - __builtin_va_end(va); -} - -void klog_ex(KlogLevel level, KlogSubsys subsys, const char* fmt, ...) -{ - __builtin_va_list va; - __builtin_va_start(va, fmt); - klog_vex(level, subsys, fmt, va); - __builtin_va_end(va); -} - -static void klog_vex(KlogLevel level, KlogSubsys subsys, - const char* fmt, __builtin_va_list va) -{ - if (subsys >= KLOG_SUBSYS_MAX) { - subsys = KLOG_SUBSYS_GENERIC; - } - - if (g_klog.initialized && ((g_klog.subsys_mask & (1ULL << subsys)) == 0)) { - return; - } - - char msg[KLOG_LINE_MAX + 1]; - int msg_len = vsnprintf_(msg, KLOG_LINE_MAX, fmt, va); - - if (msg_len < 0) { - return; - } - if (msg_len > KLOG_LINE_MAX) { - msg_len = KLOG_LINE_MAX; - } - msg[msg_len] = '\0'; - - KlogEntryHdr hdr; - hdr.seq = g_klog.seq.fetch_add(1, __ATOMIC_RELAXED); - hdr.len = static_cast(msg_len); - hdr.ts = arch::cpu::read_time(); - hdr.cpu = static_cast(arch::cpu::id()); - hdr.level = static_cast(level); - hdr.subsys = static_cast(subsys); - hdr.reserved = 0; - - bool do_console = (!g_klog.initialized || level <= g_klog.console_level); - - if (g_klog.initialized && !g_klog.panic_mode) { - LockGuard guard(g_klog.lock); - ring_drop_oldest(sizeof(hdr) + hdr.len); - ring_write_bytes(&hdr, sizeof(hdr)); - ring_write_bytes(msg, hdr.len); - if (do_console) { - g_klog.console_tail = g_klog.head; - /* Emit to UART while holding the lock to prevent - * interleaved output from concurrent CPUs. */ - char line[KLOG_LINE_MAX + 64]; - int line_len = klog_format_line(line, sizeof(line), - hdr, msg, hdr.len); - if (line_len > 0) { - console_emit(line, line_len); - } - } - } else if (do_console) { - /* Pre-init or panic mode: emit without lock */ - char line[KLOG_LINE_MAX + 64]; - int line_len = klog_format_line(line, sizeof(line), - hdr, msg, hdr.len); - if (line_len > 0) { - console_emit(line, line_len); - } - } -} - -int vprintk(const char* fmt, __builtin_va_list va) -{ - KlogLevel level = KLOG_INFO; - const char* real_fmt = parse_kern_level(fmt, &level); - - __builtin_va_list va_copy; - __builtin_va_copy(va_copy, va); - - char tmp[KLOG_LINE_MAX + 1]; - int len = vsnprintf_(tmp, KLOG_LINE_MAX, real_fmt, va_copy); - __builtin_va_end(va_copy); - - klog_vex(level, KLOG_SUBSYS_GENERIC, real_fmt, va); - - if (len < 0) { - return 0; - } - return len; -} - -int printk(const char* fmt, ...) -{ - __builtin_va_list va; - __builtin_va_start(va, fmt); - int ret = vprintk(fmt, va); - __builtin_va_end(va); - return ret; -} - -void klog_set_level(KlogLevel level) -{ - g_klog.console_level = level; -} - -void klog_set_subsys_mask(uint64 mask) -{ - g_klog.subsys_mask = mask; -} - -void klog_enable_subsys(KlogSubsys subsys) -{ - if (subsys < KLOG_SUBSYS_MAX) { - g_klog.subsys_mask |= (1ULL << subsys); - } -} - -void klog_disable_subsys(KlogSubsys subsys) -{ - if (subsys < KLOG_SUBSYS_MAX) { - g_klog.subsys_mask &= ~(1ULL << subsys); - } -} - -int klog_read(char* buf, int size) -{ - if (!g_klog.initialized || size <= 0) { - return 0; - } - - LockGuard guard(g_klog.lock); - return klog_read_internal(buf, size, &g_klog.tail, false); -} - -int klog_read_consume(char* buf, int size) -{ - if (!g_klog.initialized || size <= 0) { - return 0; - } - - LockGuard guard(g_klog.lock); - return klog_read_internal(buf, size, &g_klog.tail, true); -} - -void klog_flush(void) -{ - if (!g_klog.initialized) { - return; - } - - LockGuard guard(g_klog.lock); - - uint32 pos = g_klog.console_tail; - while (pos != g_klog.head) { - KlogEntryHdr hdr; - ring_read_bytes(pos, &hdr, sizeof(hdr)); - uint32 raw_len = hdr.len; - if (raw_len > KLOG_BUF_SIZE) { - break; - } - uint32 copy_len = raw_len; - if (copy_len > KLOG_LINE_MAX) { - copy_len = KLOG_LINE_MAX; - } - - char msg[KLOG_LINE_MAX + 1]; - ring_read_bytes(pos + sizeof(hdr), msg, copy_len); - msg[copy_len] = '\0'; - - char line[KLOG_LINE_MAX + 64]; - int line_len = klog_format_line(line, sizeof(line), hdr, msg, - static_cast(copy_len)); - if (line_len > 0) { - console_emit(line, line_len); - } - - pos += sizeof(hdr) + raw_len; - } - - g_klog.console_tail = pos; -} - -bool klog_ratelimit(KlogRateLimit* rl, uint64 now) -{ - if (!rl) { - return true; - } - - if (rl->interval == 0 || rl->burst == 0) { - return true; - } - - if (now - rl->last_ts >= rl->interval) { - rl->last_ts = now; - rl->printed = 0; - rl->suppressed = 0; - } - - if (rl->printed < rl->burst) { - rl->printed++; - return true; - } - - rl->suppressed++; - return false; -} - -void klog_stats(KlogStats* out) -{ - if (!out) { - return; - } - - out->head = g_klog.head; - out->tail = g_klog.tail; - out->console_tail = g_klog.console_tail; - out->dropped = g_klog.dropped; - out->seq = g_klog.seq.load(__ATOMIC_RELAXED); -} - -/* ======================================================================== - * Kernel Panic — Fatal Error Handler - * - * Dumps all critical S-mode CSRs and the stack pointer to the console, - * then halts the CPU. Uses kprintf (NOT klog) to avoid deadlocking - * if the panic was triggered while holding the klog spinlock. - * ======================================================================== */ - -extern "C" [[noreturn]] void kernel_panic(const char* msg, const char* detail) { - /* Disable interrupts immediately */ - arch::cpu::intr_off(); - - g_klog.panic_mode = true; - - /* ---- Banner ---- */ - kprintf("\n\n"); - kprintf("========================================\n"); - kprintf(" *** KERNEL PANIC ***\n"); - kprintf("========================================\n"); - - if (msg != nullptr) { - kprintf(" Reason : %s", msg); - if (detail != nullptr) { - kprintf(": %s", detail); - } - kprintf("\n"); - } - - /* ---- Read S-mode CSRs ---- */ - uint64 sepc, scause, stval, sstatus, satp, stvec, sscratch, sp_val; - - __asm__ volatile("csrr %0, sepc" : "=r"(sepc)); - __asm__ volatile("csrr %0, scause" : "=r"(scause)); - __asm__ volatile("csrr %0, stval" : "=r"(stval)); - __asm__ volatile("csrr %0, sstatus" : "=r"(sstatus)); - __asm__ volatile("csrr %0, satp" : "=r"(satp)); - __asm__ volatile("csrr %0, stvec" : "=r"(stvec)); - __asm__ volatile("csrr %0, sscratch" : "=r"(sscratch)); - __asm__ volatile("mv %0, sp" : "=r"(sp_val)); - - kprintf("\n--- S-mode CSR Dump ---\n"); - kprintf(" sepc = 0x%016llx\n", sepc); - kprintf(" scause = 0x%016llx", scause); - - /* Decode scause for convenience */ - bool is_interrupt = (scause >> 63) != 0; - uint64 cause_code = scause & 0x7FFFFFFFFFFFFFFFULL; - if (is_interrupt) { - kprintf(" (interrupt, code=%llu)\n", cause_code); - } else { - kprintf(" (exception, code=%llu)\n", cause_code); - } - - kprintf(" stval = 0x%016llx\n", stval); - kprintf(" sstatus = 0x%016llx", sstatus); - kprintf(" [SIE=%llu SPP=%llu SPIE=%llu]\n", - (sstatus >> 1) & 1, /* SIE */ - (sstatus >> 8) & 1, /* SPP */ - (sstatus >> 5) & 1); /* SPIE */ - kprintf(" satp = 0x%016llx", satp); - uint64 satp_mode = satp >> 60; - kprintf(" [mode=%llu]\n", satp_mode); - kprintf(" stvec = 0x%016llx\n", stvec); - kprintf(" sscratch = 0x%016llx\n", sscratch); - kprintf(" sp = 0x%016llx\n", sp_val); - - kprintf(" cpu_id = %llu\n", arch::cpu::id()); - kprintf(" time = %llu\n", arch::cpu::read_time()); - - kprintf("========================================\n\n"); - - /* Halt — spin forever with WFI to save power */ - while (true) { - arch::cpu::halt_until_interrupt(); - } -} diff --git a/lib/kobject.cc b/lib/kobject.cc deleted file mode 100644 index 8e8329e..0000000 --- a/lib/kobject.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * kobject — implementation. - * - * Lives in lib/ (mirroring Linux's lib/kobject.c) because kobject is a - * generic primitive, not tied to the driver model. - * - * Reference: docs/specs/storage_stack.md §4.2 - */ - -#include -#include -#include - -void kobject_init(kobject* k, const kobj_type* type) -{ - if (k == nullptr) { - return; - } - k->name = nullptr; - k->parent = nullptr; - k->ktype = type; - k->state_in_sysfs = false; - k->entry.init(); - k->children.init(); - k->lock.init("kobject"); - kref_init(&k->refcount); -} - -int kobject_add(kobject* k, kobject* parent, const char* name) -{ - if (k == nullptr) { - return -1; - } - k->name = name; - if (parent != nullptr) { - kobject_get(parent); - k->parent = parent; - LockGuard g(parent->lock); - list_add_tail(&k->entry, &parent->children); - } - return 0; -} - -void kobject_del(kobject* k) -{ - if (k == nullptr || k->parent == nullptr) { - return; - } - kobject* parent = k->parent; - { - LockGuard g(parent->lock); - list_del_init(&k->entry); - } - k->parent = nullptr; - kobject_put(parent); -} - -void kobject_get(kobject* k) -{ - if (k != nullptr) { - kref_get(&k->refcount); - } -} - -static void kobject_release(kref* r) -{ - kobject* k = container_of(r, kobject, refcount); - if (k->ktype != nullptr && k->ktype->release != nullptr) { - k->ktype->release(k); - } -} - -void kobject_put(kobject* k) -{ - if (k == nullptr) { - return; - } - kref_put(&k->refcount, kobject_release); -} diff --git a/lib/kprintf.cc b/lib/kprintf.cc deleted file mode 100644 index a98de71..0000000 --- a/lib/kprintf.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * kprintf.cc — Kernel formatted output - * - * Uses mpaland/printf's vsnprintf_ as the core formatting engine. - * - * Architecture: - * vsnprintf_() ← pure formatting, writes to buffer - * ↓ - * kprintf() ← format + emit via console_write_all() - * kvprintf() ← va_list variant - * ksnprintf() ← format into caller's buffer - * - * Output path: - * Pre-registration: console_write_all() → early_putc() fallback - * Post-registration: console_write_all() → struct console chain - */ - -#include -#include -#include -#include -#include "printf.h" - -/* ------------------------------------------------------------------ */ -/* Console spinlock (raw, no scheduler dependency — safe in panic) */ -/* ------------------------------------------------------------------ */ - -static lume::atomic g_console_lock{0}; - -static inline void console_lock_acquire() -{ - while (g_console_lock.exchange(1, __ATOMIC_ACQUIRE) != 0) { - /* spin */ - } -} - -static inline void console_lock_release() -{ - g_console_lock.store(0, __ATOMIC_RELEASE); -} - -/* ------------------------------------------------------------------ */ -/* _putchar: required by mpaland/printf for printf_() / vprintf_() */ -/* ------------------------------------------------------------------ */ - -void _putchar(char character) -{ - early_putc(character); -} - -/* ------------------------------------------------------------------ */ -/* Public API */ -/* ------------------------------------------------------------------ */ - -extern "C" int kprintf(const char* fmt, ...) -{ - char buf[256]; - va_list va; - va_start(va, fmt); - int len = vsnprintf_(buf, sizeof(buf), fmt, va); - va_end(va); - - /* Emit to console under lock */ - console_lock_acquire(); - console_write_all(buf, len); - console_lock_release(); - return len; -} - -extern "C" int kvprintf(const char* fmt, va_list va) -{ - char buf[256]; - int len = vsnprintf_(buf, sizeof(buf), fmt, va); - - console_lock_acquire(); - console_write_all(buf, len); - console_lock_release(); - return len; -} - -extern "C" int ksnprintf(char* buf, int count, const char* fmt, ...) -{ - va_list va; - va_start(va, fmt); - int ret = vsnprintf_(buf, (size_t)count, fmt, va); - va_end(va); - return ret; -} diff --git a/lib/ktl/LICENSE b/lib/ktl/LICENSE deleted file mode 100644 index 8580f02..0000000 --- a/lib/ktl/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -Copyright 2016 The Fuchsia Authors -Copyright (c) 2008-2015 Travis Geiselbrecht - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files -(the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of the Software, -and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/ktl/README.lume b/lib/ktl/README.lume deleted file mode 100644 index 7e7c8a4..0000000 --- a/lib/ktl/README.lume +++ /dev/null @@ -1,8 +0,0 @@ -KTL configuration overlay imported from Zircon - -Source: zircon/kernel/lib/ktl -Fuchsia revision: f8d670ab4bbb71bfb4d569893ba12fbb8a83bacd - -The complete KTL header overlay and its two implementation files, popcount.cc -and stub-new.cc, are imported. The KTL target is built together with the -Zircon kernel libc header layer and the version-matched libc++ snapshot. diff --git a/lib/ktl/README.md b/lib/ktl/README.md deleted file mode 100644 index 667c678..0000000 --- a/lib/ktl/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Kernel Template Library - -The Kernel Template Library is a curated subset of the C++ standard library API -using the `ktl` namespace rather than the `std` namespace. When a specific -interface is deemed useful, safe, and appropriate for use in the kernel, it can -be added here. No `std` APIs are ever used directly in the kernel, only `ktl`. - -The API is a strict subset of the standard C++ library API aside from the -namespace. The header file names are mostly directly mapped as well: - - -> - -There can be exceptions. For example, is a very broad collection of -APIs and the ktl subset is more focused. So instead of there -are specific headers for the standard APIs from that are included, such -as for `ktl::unique_ptr` (`std::unique_ptr` in ). - -The implementation here simply leverages the libc++ implementation and defines -`using` aliases in the `ktl` namespace. It's expected that ktl will only ever -provide "header only" APIs. - -## ktl enforcement - -The [``](include/ktl/enforce.h) header file should be used in -most `.cc` files (but not `.h`) files meant only for the kernel environment. -That is, in `.cc` files that use the `` headers or use kernel-only -headers that use them. - -This file must appear last in the `#include` list and `clang-format` will -arrange that automatically. - -After this `#include` any use of the `std` identifier in C++ code will cause a -compile-time error. When such errors are encountered, the kernel code should -be checked for use of C++ standard library headers (with no `.h` in the name, -like `, etc.) that should be replaced with `` headers and for -`std::` names that should be replaced with `ktl::` names. diff --git a/lib/ktl/include-after/errno.h b/lib/ktl/include-after/errno.h deleted file mode 100644 index 52edc9c..0000000 --- a/lib/ktl/include-after/errno.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_ERRNO_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_ERRNO_H_ - -// The kernel doesn't want this file but some libc++ headers we need -// wind up including it. - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_ERRNO_H_ diff --git a/lib/ktl/include-after/wchar.h b/lib/ktl/include-after/wchar.h deleted file mode 100644 index 41d11ae..0000000 --- a/lib/ktl/include-after/wchar.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2018 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_AFTER_WCHAR_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_AFTER_WCHAR_H_ - -#include - -// The kernel doesn't want this file but some libc++ headers we need wind up -// including it and they need these declarations. -// -// **NOTE** This file is include-after because libc++ headers get it via -// #include_next so as to get the "system" rather than libc++'s -// own wrapper. - -typedef struct { -} mbstate_t; - -typedef unsigned int wint_t; -#define WEOF (~wint_t{0}) - -// refers to these in code that's never actually used in ktl. -wchar_t* wmemcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t); -wchar_t* wmemmove(wchar_t*, const wchar_t*, size_t); -wchar_t* wmemset(wchar_t*, wchar_t, size_t); - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_AFTER_WCHAR_H_ diff --git a/lib/ktl/include/__chrono/system_clock.h b/lib/ktl/include/__chrono/system_clock.h deleted file mode 100644 index 5d39243..0000000 --- a/lib/ktl/include/__chrono/system_clock.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2023 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE___CHRONO_SYSTEM_CLOCK_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE___CHRONO_SYSTEM_CLOCK_H_ - -// libc++'s includes this file via various internal headers. -// The declarations it provides aren't needed for the kernel and rely -// on other things stubbed out by the kernel. So this placeholder file -// just prevents compiling the libc++ code that doesn't work. - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE___CHRONO_SYSTEM_CLOCK_H_ diff --git a/lib/ktl/include/__config b/lib/ktl/include/__config deleted file mode 100644 index e04573e..0000000 --- a/lib/ktl/include/__config +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2022 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIG_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIG_ - -// The libc++ internal header <__config> unconditionally responds to some -// predefines set in the EFI environment. So this header wraps it and then -// undoes the damage that our __config_site header can't prevent. - -#include_next <__config> - -#undef _LIBCPP_WIN32API -#undef _LIBCPP_MSVCRT_LIKE -#undef _LIBCPP_MSVCRT -#undef _LIBCPP_HAS_OPEN_WITH_WCHAR - -// This prevents libc++ from doing fallback to spin locks and the like for -// cases where is_always_lock_free is not true. In the kernel, we don't want -// any behind-the-scenes help like that, we want to get link errors from -// libcalls if atomics can't be lowered to real hardware instructions. -#undef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS - -// These are used by <__configuration/availability.h> to decide when headers -// should expect things to be defined in the library. For the kernel, there is -// no library and so everything must be defined in headers. -#undef _LIBCPP_INTRODUCED_IN_LLVM_21 -#define _LIBCPP_INTRODUCED_IN_LLVM_21 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_20 -#define _LIBCPP_INTRODUCED_IN_LLVM_20 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_19 -#define _LIBCPP_INTRODUCED_IN_LLVM_19 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_18 -#define _LIBCPP_INTRODUCED_IN_LLVM_18 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_16 -#define _LIBCPP_INTRODUCED_IN_LLVM_16 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_15 -#define _LIBCPP_INTRODUCED_IN_LLVM_15 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_14 -#define _LIBCPP_INTRODUCED_IN_LLVM_14 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_12 -#define _LIBCPP_INTRODUCED_IN_LLVM_12 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_11 -#define _LIBCPP_INTRODUCED_IN_LLVM_11 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_9 -#define _LIBCPP_INTRODUCED_IN_LLVM_9 0 -#undef _LIBCPP_INTRODUCED_IN_LLVM_4 -#define _LIBCPP_INTRODUCED_IN_LLVM_4 0 - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIG_ diff --git a/lib/ktl/include/__config_site b/lib/ktl/include/__config_site deleted file mode 100644 index 4d2236b..0000000 --- a/lib/ktl/include/__config_site +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2021 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIG_SITE_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIG_SITE_ - -// The libc++ internal header <__config> does #include <__config_site> to get -// definitions that vary by operating system, machine, or configuration. The -// toolchain's libc++ installation provides include/$triple/.../__config_site -// files for each $cpu-fuchsia appropriate for normal userland. But the ktl -// abuse of libc++ is different from public userland libc++, so provide special -// kernel-appropriate definitions here. This file will be in the include path -// ahead of any toolchain-supplied header. Also, some special bare-metal build -// environments such as phys32 or efi that reuse ktl and kernel libc code may -// use settings that cause the compiler to change the $triple it injects into -// the include path to one for which no runtimes are built and so there is no -// __config_site file to be found at all. - -// These two are what <__config_site> for Fuchsia userland defines. -#define _LIBCPP_ABI_VERSION 2 -#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS 1 - -// This has to be defined to some `__*` string but what doesn't really matter. -#define _LIBCPP_ABI_NAMESPACE __ktl - -// When compiling in the UEFI environment, the predefines look like Windows -// but there is no Windows runtime environment to use. -#define _LIBCPP_NO_VCRUNTIME 1 - -// This tells the headers not to use `extern template` declarations that -// expect specific instantiations/specializations to come from the libc++ -// library rather than the headers. In the kernel, only the headers are -// ever going to be available. -#define _LIBCPP_DISABLE_EXTERN_TEMPLATE 1 - -// This tells not to use threading APIs. -#define _LIBCPP_HAS_NO_PLATFORM_WAIT 1 - -// This tells et al to use <__external_threading> instead -// of expecting either POSIX or C11 threading APIs. -#define _LIBCPP_HAS_THREAD_API_EXTERNAL 1 -#define _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL 1 - -// <__config> requires that these be set if _LIBCPP_HAS_THREAD_API_EXTERNAL is. -#define _LIBCPP_HAS_THREADS 1 -#define _LIBCPP_HAS_MONOTONIC_CLOCK 1 - -// This tells not to use `aligned_alloc` from . -#define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 1 - -// This tells various headers to be strict about what includes what. -#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 1 - -// This tells libc++ not to expect full locale APIs in some places. -#define _LIBCPP_HAS_NO_LOCALIZATION 1 - -// This is unfortunately required even though the kernel does not use wide -// characters. -#define _LIBCPP_HAS_WIDE_CHARACTERS 1 - -// This tells pstl headers to use serial algorithms and not try to -// do any multithreading. -#define _LIBCPP_PSTL_CPU_BACKEND_SERIAL 1 - -// This will probably never be used in code that ktl actually uses. -// But define it for completeness. -#define _LIBCPP_INSTRUMENTED_WITH_ASAN __has_feature(address_sanitizer) - -// TODO(https://fxbug.dev/42082322): make the hardening mode selectable through build -// configurations. -// This sets the default to tell libc++ to not enable assertions to prevent -// undefined behavior, but may be overridden if _LIBCPP_HARDENING_MODE is -// defined elsewhere. -#define _LIBCPP_HARDENING_MODE_DEFAULT _LIBCPP_HARDENING_MODE_NONE - -#define _LIBCPP_ASSERTION_SEMANTIC_DEFAULT _LIBCPP_ASSERTION_SEMANTIC_HARDENING_DEPENDENT - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIG_SITE_ diff --git a/lib/ktl/include/__configuration/platform.h b/lib/ktl/include/__configuration/platform.h deleted file mode 100644 index b15e1e0..0000000 --- a/lib/ktl/include/__configuration/platform.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2025 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIGURATION_PLATFORM_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIGURATION_PLATFORM_H_ - -// Other libc++ headers use <__configuration/platform.h> but libc++'s -// <__configuration/platform.h> does not yet recognize the `__PE_COFF__` -// predefine. Until we support this new predefine upstream, -// we must define _LIBCPP_OBJECT_FORMAT_COFF for UEFI targets here. -// TODO(https://fxbug.dev/435771251) -- Support `__PE_COFF__` predefine -// upstream. - -#if defined(__PE_COFF__) -#define _LIBCPP_OBJECT_FORMAT_COFF 2 // Tell libc++ this is PE-COFF. -#endif // __PE_COFF__ - -#include_next <__configuration/platform.h> - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE___CONFIGURATION_PLATFORM_H_ diff --git a/lib/ktl/include/__external_threading b/lib/ktl/include/__external_threading deleted file mode 100644 index 9cec903..0000000 --- a/lib/ktl/include/__external_threading +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE___EXTERNAL_THREADING -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE___EXTERNAL_THREADING - -// libc++'s includes this file via <__threading_support>. It needs -// these types and functions declared, but only for use in interfaces that -// aren't supported in the kernel, so stub declarations are all they need. - -_LIBCPP_BEGIN_NAMESPACE_STD - -struct __libcpp_timespec_t { - long int tv_sec, tv_nsec; -}; - -using __libcpp_thread_id = int; - -bool __libcpp_thread_id_equal(__libcpp_thread_id, __libcpp_thread_id); -bool __libcpp_thread_id_less(__libcpp_thread_id, __libcpp_thread_id); -__libcpp_thread_id __libcpp_thread_get_current_id(); - -void __libcpp_thread_sleep_for(chrono::nanoseconds); -void __libcpp_thread_yield(); - -// This macro is used unconditionally in <__threading_support> but defined -// there only conditionally on when <__external_threading> is not used. -#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY - -_LIBCPP_END_NAMESPACE_STD - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE___EXTERNAL_THREADING diff --git a/lib/ktl/include/climits b/lib/ktl/include/climits deleted file mode 100644 index 86e537d..0000000 --- a/lib/ktl/include/climits +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2022 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#pragma once - -// Other libc++ headers use but libc++'s complains if it -// thinks is not its own wrapper, which we do not need. We always -// get the kernel's before the libc++ with the way the include paths -// are set up, which is necessary because of other headers where preempting -// libc++'s header is unavoidable for the kernel environment. - -#include diff --git a/lib/ktl/include/cmath b/lib/ktl/include/cmath deleted file mode 100644 index 13b8e6b..0000000 --- a/lib/ktl/include/cmath +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2021 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_CMATH_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_CMATH_ - -// The kernel doesn't want this file but some libc++ headers we need -// wind up including it. They don't actually most of the math -// declarations except under #if conditions that aren't true. - -#include <__config> -#include - -_LIBCPP_BEGIN_NAMESPACE_STD - -// These are used in templates that won't ever be instantiated in kernel code. - -template -constexpr bool isinf(T&& x) { - static_assert(!is_same_v, "must not be instantiated in kernel code"); - return false; -} - -template -constexpr bool isnan(T&& x) { - static_assert(!is_same_v, "must not be instantiated in kernel code"); - return false; -} - -template -constexpr bool signbit(T&& x) { - static_assert(!is_same_v, "must not be instantiated in kernel code"); - return false; -} - -template -constexpr T frexp(T&& x, int* exponent) { - static_assert(!is_same_v, "must not be instantiated in kernel code"); - return x; -} - -template -constexpr auto ceil(T&& x) { - static_assert(!is_same_v, "must not be instantiated in kernel code"); - return x; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_CMATH_ diff --git a/lib/ktl/include/cstdint b/lib/ktl/include/cstdint deleted file mode 100644 index 0ab922c..0000000 --- a/lib/ktl/include/cstdint +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2022 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#pragma once - -// Other libc++ headers use but libc++'s complains if it -// thinks is not its own wrapper, so we define _LIBCPP_STDINT_H. We -// always get the real before the libc++ with the way the include -// paths are set up, which is necessary because of other headers where -// preempting libc++'s header is unavoidable for the kernel environment. - -#include - -#define _LIBCPP_STDINT_H -#include_next diff --git a/lib/ktl/include/cstdio b/lib/ktl/include/cstdio deleted file mode 100644 index 349e736..0000000 --- a/lib/ktl/include/cstdio +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_CSTDIO_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_CSTDIO_ - -// The kernel doesn't want this file but some libc++ headers we need -// wind up including it and they need these declarations. -// -// Note this specifically avoids because libc++ doesn't need that -// but indirectly reaches and the kernel's -// uses so there would be a circularity. - -#include - -#define EOF (-1) - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_CSTDIO_ diff --git a/lib/ktl/include/cstdlib b/lib/ktl/include/cstdlib deleted file mode 100644 index 25ad762..0000000 --- a/lib/ktl/include/cstdlib +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2018 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#pragma once - -// This is used by libc++'s just for std::abort, ::posix_memalign, and -// ::free. - -#include - -#include <__config> - -#define _LIBCPP_UNREACHABLE() __builtin_unreachable() - -// This is used by the __libcpp_aligned_alloc inline. Since it always fails -// that inline will trivially always return nullptr. -inline int posix_memalign(void** ptr, size_t align, size_t size) { return 1; } - -// This is used by the __libcpp_aligned_free inline, which won't really ever be -// called. The kernel does have a real free declared elsewhere. -void free(void* ptr); - -_LIBCPP_BEGIN_NAMESPACE_STD - -using ::abort; - -_LIBCPP_END_NAMESPACE_STD diff --git a/lib/ktl/include/cwchar b/lib/ktl/include/cwchar deleted file mode 100644 index 4f24c73..0000000 --- a/lib/ktl/include/cwchar +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_CWCHAR -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_CWCHAR - -// The kernel doesn't want this file but some libc++ headers we need -// wind up including it and they need these declarations. - -#include - -#include <__config> - -_LIBCPP_BEGIN_NAMESPACE_STD - -using ::wmemcpy; -using ::wmemmove; -using ::wmemset; - -// These are called by libc++ header code. The first two should never actually -// be called by anything that really gets instantiated in kernel code since -// wchar_t is never used. However, __constexpr_wmemchr is used by places like -// std::find not just for wchar_t per se but for any trivial type of the same -// size, e.g. uint32_t. So its code must be correct. The other two are filled -// out just in case of an unexpected use. - -constexpr size_t __constexpr_wcslen(const wchar_t* str) { - size_t len = 0; - while (*str++ != L'\0') { - ++len; - } - return len; -} - -constexpr int __constexpr_wmemcmp(const wchar_t* lhs, const wchar_t* rhs, size_t count) { - while (count-- > 0) { - if (*lhs != *rhs) { - return static_cast(*lhs - *rhs); - } - ++lhs; - ++rhs; - } - return 0; -} - -template -constexpr Tp* __constexpr_wmemchr(Tp* str, Up wc, size_t count) { - while (count-- > 0) { - if (*str == wc) { - return str; - } - ++str; - } - return nullptr; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_CWCHAR diff --git a/lib/ktl/include/ktl/algorithm.h b/lib/ktl/include/ktl/algorithm.h deleted file mode 100644 index 7b7baed..0000000 --- a/lib/ktl/include/ktl/algorithm.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ALGORITHM_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ALGORITHM_H_ - -#include - -namespace ktl { - -// "Non-modifying sequence operations" -using std::adjacent_find; -using std::all_of; -using std::any_of; -using std::count; -using std::count_if; -using std::find; -using std::find_end; -using std::find_first_of; -using std::find_if; -using std::find_if_not; -using std::for_each; -using std::for_each_n; -using std::none_of; -using std::search; -using std::search_n; - -namespace ranges { -using std::ranges::adjacent_find; -using std::ranges::all_of; -using std::ranges::any_of; -using std::ranges::count; -using std::ranges::count_if; -using std::ranges::find; -using std::ranges::find_end; -using std::ranges::find_first_of; -using std::ranges::find_if; -using std::ranges::find_if_not; -using std::ranges::for_each; -using std::ranges::for_each_n; -using std::ranges::none_of; -using std::ranges::search; -using std::ranges::search_n; -} // namespace ranges - -// "Modifying sequence operations" (subset) -using std::copy; -using std::copy_if; -using std::fill; -using std::fill_n; -using std::reverse; -using std::shuffle; -using std::transform; - -namespace ranges { -using std::ranges::copy; -using std::ranges::copy_if; -using std::ranges::fill; -using std::ranges::fill_n; -using std::ranges::reverse; -using std::ranges::shuffle; -using std::ranges::transform; -} // namespace ranges - -// "Sorting operations" (subset) -using std::is_sorted; -using std::is_sorted_until; -using std::sort; -using std::stable_sort; - -namespace ranges { -using std::ranges::is_sorted; -using std::ranges::is_sorted_until; -using std::ranges::sort; -using std::ranges::stable_sort; -} // namespace ranges - -// "Binary search operations (on sorted ranges)" -using std::binary_search; -using std::equal_range; -using std::lower_bound; -using std::upper_bound; - -namespace ranges { -using std::ranges::binary_search; -using std::ranges::equal_range; -using std::ranges::lower_bound; -using std::ranges::upper_bound; -} // namespace ranges - -// "Minimum/maximum operations" -using std::clamp; -using std::equal; -using std::max; -using std::max_element; -using std::min; -using std::min_element; -using std::minmax; -using std::minmax_element; - -namespace ranges { -using std::ranges::clamp; -using std::ranges::max; -using std::ranges::max_element; -using std::ranges::min; -using std::ranges::min_element; -using std::ranges::minmax; -using std::ranges::minmax_element; -} // namespace ranges - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ALGORITHM_H_ diff --git a/lib/ktl/include/ktl/array.h b/lib/ktl/include/ktl/array.h deleted file mode 100644 index 90d445a..0000000 --- a/lib/ktl/include/ktl/array.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2019 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ARRAY_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ARRAY_H_ - -#include - -namespace ktl { - -using std::array; -using std::to_array; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ARRAY_H_ diff --git a/lib/ktl/include/ktl/atomic.h b/lib/ktl/include/ktl/atomic.h deleted file mode 100644 index 017db6b..0000000 --- a/lib/ktl/include/ktl/atomic.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2019 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ATOMIC_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ATOMIC_H_ - -#include - -// On arm64 and x86-64, lock-free 128-bit (16-byte) atomics are available. -// But riscv64 does not support them. -#ifdef __riscv -#define HAVE_ATOMIC_128 0 -#else -#define HAVE_ATOMIC_128 1 -#endif - -namespace ktl { - -using std::atomic; -using std::atomic_init; -using std::atomic_ref; - -using std::memory_order; - -using std::memory_order_acq_rel; -using std::memory_order_acquire; -using std::memory_order_consume; -using std::memory_order_relaxed; -using std::memory_order_release; -using std::memory_order_seq_cst; - -using std::atomic_signal_fence; -using std::atomic_thread_fence; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ATOMIC_H_ diff --git a/lib/ktl/include/ktl/bit.h b/lib/ktl/include/ktl/bit.h deleted file mode 100644 index c3ccb7e..0000000 --- a/lib/ktl/include/ktl/bit.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2021 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_BIT_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_BIT_H_ - -#include - -namespace ktl { - -using std::bit_cast; -using std::bit_ceil; -using std::bit_floor; -using std::bit_width; -using std::countl_one; -using std::countl_zero; -using std::countr_one; -using std::countr_zero; -using std::endian; -using std::has_single_bit; -using std::popcount; -using std::rotl; -using std::rotr; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_BIT_H_ diff --git a/lib/ktl/include/ktl/byte.h b/lib/ktl/include/ktl/byte.h deleted file mode 100644 index 26b1294..0000000 --- a/lib/ktl/include/ktl/byte.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_BYTE_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_BYTE_H_ - -#include - -namespace ktl { - -using std::byte; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_BYTE_H_ diff --git a/lib/ktl/include/ktl/concepts.h b/lib/ktl/include/ktl/concepts.h deleted file mode 100644 index 93b3f62..0000000 --- a/lib/ktl/include/ktl/concepts.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2025 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_CONCEPTS_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_CONCEPTS_H_ - -#include - -namespace ktl { - -using std::assignable_from; -using std::common_reference_with; -using std::common_with; -using std::constructible_from; -using std::copy_constructible; -using std::copyable; -using std::default_initializable; -using std::derived_from; -using std::destructible; -using std::equality_comparable; -using std::equality_comparable_with; -using std::equivalence_relation; -using std::integral; -using std::invocable; -using std::movable; -using std::move_constructible; -using std::predicate; -using std::regular; -using std::regular_invocable; -using std::relation; -using std::same_as; -using std::semiregular; -using std::signed_integral; -using std::strict_weak_order; -using std::swappable; -using std::swappable_with; -using std::totally_ordered; -using std::totally_ordered_with; -using std::unsigned_integral; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_CONCEPTS_H_ diff --git a/lib/ktl/include/ktl/declval.h b/lib/ktl/include/ktl/declval.h deleted file mode 100644 index 925fe9c..0000000 --- a/lib/ktl/include/ktl/declval.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2021 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_DECLVAL_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_DECLVAL_H_ - -#include - -namespace ktl { - -using std::declval; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_DECLVAL_H_ diff --git a/lib/ktl/include/ktl/enforce.h b/lib/ktl/include/ktl/enforce.h deleted file mode 100644 index 9c948d2..0000000 --- a/lib/ktl/include/ktl/enforce.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2021 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ENFORCE_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ENFORCE_H_ - -// `#include ` should appear last in the include list of any -// kernel .cc file that uses `ktl` headers. Since many other kernel headers -// use ktl headers and this must appear after *all* uses of any ktl headers, -// whether direct or indirect, it's a good idea to just make sure that -// `#include ` in each .cc file of kernel-only code (i.e. code -// that might ever use ktl directly). -// -// The //.clang-format file has a rule to ensure this file is placed last and -// separate from the other #include lines, so just adding the `#include` line -// to each source file should make sure its placement stays correct. - -// This directive tells the preprocessor that the identifier `std` cannot -// appear in any context (except the expansion of a macro already defined -// before now). This ensures that any stray use of std::name in kernel code -// can get caught at compile time so people remember to use ktl::name instead -// and ensure that what they're using is in the approved ktl subset of std. -// -// It also affects harmless use of `std` as a local variable name or whatever, -// but we can live without kernel code being able to use that one name. -#pragma GCC poison std - -// Also poison the stdcompat namespaces, as the same rules for ktl wrappers -// apply to those as std proper. -#pragma GCC poison cpp17 -#pragma GCC poison cpp20 -#pragma GCC poison cpp23 - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ENFORCE_H_ diff --git a/lib/ktl/include/ktl/forward.h b/lib/ktl/include/ktl/forward.h deleted file mode 100644 index 62874e6..0000000 --- a/lib/ktl/include/ktl/forward.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_INCLUDE_KTL_FORWARD_H_ -#define ZIRCON_KERNEL_INCLUDE_KTL_FORWARD_H_ - -#include - -namespace ktl { - -using std::forward; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_INCLUDE_KTL_FORWARD_H_ diff --git a/lib/ktl/include/ktl/functional.h b/lib/ktl/include/ktl/functional.h deleted file mode 100644 index 026f4cf..0000000 --- a/lib/ktl/include/ktl/functional.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_FUNCTIONAL_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_FUNCTIONAL_H_ - -#include - -namespace ktl { - -using std::bind_front; -using std::invoke; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_FUNCTIONAL_H_ diff --git a/lib/ktl/include/ktl/initializer_list.h b/lib/ktl/include/ktl/initializer_list.h deleted file mode 100644 index 3a69abb..0000000 --- a/lib/ktl/include/ktl/initializer_list.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2021 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_INITIALIZER_LIST_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_INITIALIZER_LIST_H_ - -#include - -namespace ktl { - -using std::initializer_list; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_INITIALIZER_LIST_H_ diff --git a/lib/ktl/include/ktl/inplace_vector.h b/lib/ktl/include/ktl/inplace_vector.h deleted file mode 100644 index 4eaf92b..0000000 --- a/lib/ktl/include/ktl/inplace_vector.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2025 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_INPLACE_VECTOR_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_INPLACE_VECTOR_H_ - -#include - -namespace ktl { - -using cpp26::inplace_vector; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_INPLACE_VECTOR_H_ diff --git a/lib/ktl/include/ktl/iterator.h b/lib/ktl/include/ktl/iterator.h deleted file mode 100644 index 58d92be..0000000 --- a/lib/ktl/include/ktl/iterator.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ITERATOR_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ITERATOR_H_ - -#include - -namespace ktl { - -// This includes only the "iterator operations" and "range access" subsets -// of the API. These are useful for treating all sorts of -// container types, raw arrays, pointers, and {...} literal lists uniformly. -// It leaves out iterator_traits and the "iterator adaptors" subset, which -// have not yet seemed desirable to employ in kernel code. - -using std::advance; -using std::begin; -using std::cbegin; -using std::cend; -using std::crbegin; -using std::crend; -using std::data; -using std::distance; -using std::empty; -using std::end; -using std::next; -using std::prev; -using std::rbegin; -using std::rend; -using std::size; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_ITERATOR_H_ diff --git a/lib/ktl/include/ktl/limits.h b/lib/ktl/include/ktl/limits.h deleted file mode 100644 index 8f6adf4..0000000 --- a/lib/ktl/include/ktl/limits.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2019 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_INCLUDE_KTL_LIMITS_H_ -#define ZIRCON_KERNEL_INCLUDE_KTL_LIMITS_H_ - -#include - -namespace ktl { - -using std::numeric_limits; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_INCLUDE_KTL_LIMITS_H_ diff --git a/lib/ktl/include/ktl/memory.h b/lib/ktl/include/ktl/memory.h deleted file mode 100644 index caf8d47..0000000 --- a/lib/ktl/include/ktl/memory.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2024 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_MEMORY_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_MEMORY_H_ - -#include - -namespace ktl { - -using std::addressof; -using std::to_address; - -using std::align; -using std::assume_aligned; - -using std::default_delete; - -using std::pointer_traits; - -using std::construct_at; -using std::destroy; -using std::destroy_at; -using std::destroy_n; -using std::uninitialized_copy; -using std::uninitialized_copy_n; -using std::uninitialized_default_construct; -using std::uninitialized_default_construct_n; -using std::uninitialized_fill; -using std::uninitialized_fill_n; -using std::uninitialized_move; -using std::uninitialized_move_n; -using std::uninitialized_value_construct; -using std::uninitialized_value_construct_n; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_MEMORY_H_ diff --git a/lib/ktl/include/ktl/new.h b/lib/ktl/include/ktl/new.h deleted file mode 100644 index 12def96..0000000 --- a/lib/ktl/include/ktl/new.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2026 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_NEW_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_NEW_H_ - -#include - -namespace ktl { - -using std::align_val_t; - -using std::destroying_delete; -using std::destroying_delete_t; -using std::nothrow; -using std::nothrow_t; - -using std::launder; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_NEW_H_ diff --git a/lib/ktl/include/ktl/numeric.h b/lib/ktl/include/ktl/numeric.h deleted file mode 100644 index 18cad1f..0000000 --- a/lib/ktl/include/ktl/numeric.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2023 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_NUMERIC_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_NUMERIC_H_ - -#include - -namespace ktl { - -// "Numeric operations" -using std::accumulate; -using std::reduce; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_NUMERIC_H_ diff --git a/lib/ktl/include/ktl/optional.h b/lib/ktl/include/ktl/optional.h deleted file mode 100644 index e08451d..0000000 --- a/lib/ktl/include/ktl/optional.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_OPTIONAL_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_OPTIONAL_H_ - -#include - -namespace ktl { - -using std::in_place; -using std::in_place_t; -using std::make_optional; -using std::nullopt; -using std::nullopt_t; -using std::optional; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_OPTIONAL_H_ diff --git a/lib/ktl/include/ktl/ranges.h b/lib/ktl/include/ktl/ranges.h deleted file mode 100644 index 8e3ee09..0000000 --- a/lib/ktl/include/ktl/ranges.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2025 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_RANGES_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_RANGES_H_ - -#include - -namespace ktl { - -// This can't be a namespace alias like `views` because also -// adds things to ktl::ranges and redundant namespace aliases aren't allowed. -namespace ranges { -using namespace std::ranges; -} // namespace ranges - -// Only this header defines this namespace, so a simple namespace alias works. -namespace views = std::views; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_RANGES_H_ diff --git a/lib/ktl/include/ktl/ref.h b/lib/ktl/include/ktl/ref.h deleted file mode 100644 index fdaddc4..0000000 --- a/lib/ktl/include/ktl/ref.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_REF_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_REF_H_ - -#include - -namespace ktl { - -using std::cref; -using std::ref; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_REF_H_ diff --git a/lib/ktl/include/ktl/source_location.h b/lib/ktl/include/ktl/source_location.h deleted file mode 100644 index 121668d..0000000 --- a/lib/ktl/include/ktl/source_location.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2025 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_SOURCE_LOCATION_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_SOURCE_LOCATION_H_ - -#include - -namespace ktl { - -using std::source_location; - -} - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_SOURCE_LOCATION_H_ diff --git a/lib/ktl/include/ktl/span.h b/lib/ktl/include/ktl/span.h deleted file mode 100644 index deb1df3..0000000 --- a/lib/ktl/include/ktl/span.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_SPAN_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_SPAN_H_ - -#include - -namespace ktl { - -using std::span; - -using std::as_bytes; -using std::as_writable_bytes; - -using std::dynamic_extent; - -using std::data; -using std::size; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_SPAN_H_ diff --git a/lib/ktl/include/ktl/string_view.h b/lib/ktl/include/ktl/string_view.h deleted file mode 100644 index 9ba949f..0000000 --- a/lib/ktl/include/ktl/string_view.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_STRING_VIEW_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_STRING_VIEW_H_ - -#include - -namespace ktl { - -using std::basic_string_view; -using std::string_view; - -} // namespace ktl - -// Just including enables "foo"sv literals. -using namespace std::literals::string_view_literals; - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_STRING_VIEW_H_ diff --git a/lib/ktl/include/ktl/tuple.h b/lib/ktl/include/ktl/tuple.h deleted file mode 100644 index b00c7e0..0000000 --- a/lib/ktl/include/ktl/tuple.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2024 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_TUPLE_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_TUPLE_H_ - -#include - -namespace ktl { - -using std::apply; -using std::forward_as_tuple; -using std::get; -using std::ignore; -using std::make_from_tuple; -using std::make_tuple; -using std::tie; -using std::tuple; -using std::tuple_cat; -using std::tuple_element; -using std::tuple_element_t; -using std::tuple_size; -using std::tuple_size_v; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_TUPLE_H_ diff --git a/lib/ktl/include/ktl/type_traits.h b/lib/ktl/include/ktl/type_traits.h deleted file mode 100644 index fc0a2f0..0000000 --- a/lib/ktl/include/ktl/type_traits.h +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2019 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_TYPE_TRAITS_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_TYPE_TRAITS_H_ - -#include - -namespace ktl { - -using std::add_const; -using std::add_const_t; - -using std::is_array; -using std::is_array_v; -using std::is_bounded_array; -using std::is_bounded_array_v; -using std::is_unbounded_array; -using std::is_unbounded_array_v; - -using std::false_type; -using std::true_type; - -using std::conjunction; -using std::conjunction_v; - -using std::disjunction; -using std::disjunction_v; - -using std::conditional; -using std::conditional_t; - -using std::decay; -using std::decay_t; - -using std::void_t; - -using std::enable_if; -using std::enable_if_t; - -using std::has_unique_object_representations; -using std::has_unique_object_representations_v; - -using std::is_base_of; -using std::is_base_of_v; - -using std::is_const; -using std::is_const_v; - -using std::is_constructible; -using std::is_constructible_v; - -using std::is_copy_constructible; -using std::is_copy_constructible_v; - -using std::is_copy_assignable; -using std::is_copy_assignable_v; - -using std::is_default_constructible; -using std::is_default_constructible_v; - -using std::is_class; -using std::is_class_v; - -using std::is_enum; -using std::is_enum_v; - -using std::is_floating_point; -using std::is_floating_point_v; - -using std::is_function; -using std::is_function_v; - -using std::is_integral; -using std::is_integral_v; - -using std::invoke_result_t; -using std::is_invocable; -using std::is_invocable_r; -using std::is_invocable_r_v; -using std::is_invocable_v; - -using std::is_lvalue_reference; -using std::is_lvalue_reference_v; - -using std::is_move_constructible; -using std::is_move_constructible_v; - -using std::is_move_assignable; -using std::is_move_assignable_v; - -using std::is_pod; -using std::is_pod_v; - -using std::is_same; -using std::is_same_v; - -using std::is_signed; -using std::is_signed_v; - -using std::is_standard_layout; -using std::is_standard_layout_v; - -using std::is_empty; -using std::is_empty_v; - -using std::is_trivial; -using std::is_trivial_v; - -using std::is_trivially_copy_assignable; -using std::is_trivially_copy_assignable_v; - -using std::is_trivially_copy_constructible; -using std::is_trivially_copy_constructible_v; - -using std::is_trivially_constructible; -using std::is_trivially_constructible_v; - -using std::is_trivially_destructible; -using std::is_trivially_destructible_v; - -using std::is_trivially_move_assignable; -using std::is_trivially_move_assignable_v; - -using std::is_trivially_move_constructible; -using std::is_trivially_move_constructible_v; - -using std::is_member_object_pointer; -using std::is_member_object_pointer_v; - -using std::is_unsigned; -using std::is_unsigned_v; - -using std::is_void; -using std::is_void_v; - -using std::make_signed; -using std::make_signed_t; -using std::make_unsigned; -using std::make_unsigned_t; - -using std::remove_all_extents; -using std::remove_all_extents_t; - -using std::remove_const; -using std::remove_const_t; - -using std::remove_extent; -using std::remove_extent_t; - -using std::remove_pointer; -using std::remove_pointer_t; - -using std::remove_reference; -using std::remove_reference_t; - -using std::underlying_type; -using std::underlying_type_t; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_TYPE_TRAITS_H_ diff --git a/lib/ktl/include/ktl/unique_ptr.h b/lib/ktl/include/ktl/unique_ptr.h deleted file mode 100644 index e2d2f39..0000000 --- a/lib/ktl/include/ktl/unique_ptr.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2018 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_INCLUDE_KTL_UNIQUE_PTR_H_ -#define ZIRCON_KERNEL_INCLUDE_KTL_UNIQUE_PTR_H_ - -#include -#include - -#include -#include - -namespace ktl { - -using std::align_val_t; -using std::unique_ptr; - -template -ktl::enable_if_t, unique_ptr> make_unique(fbl::AllocChecker* ac, - Args&&... args) { - return unique_ptr(new (ac) T(std::forward(args)...)); -} - -// For an unbounded array of given size, each element is value-initialized. -// This is different from plain `new (ac) T[n]`, which performs default-initialization. -template -ktl::enable_if_t, unique_ptr> make_unique(fbl::AllocChecker* ac, - size_t n) { - return unique_ptr(new (ac) ktl::remove_extent_t[n]()); -} - -} // namespace ktl - -#endif // ZIRCON_KERNEL_INCLUDE_KTL_UNIQUE_PTR_H_ diff --git a/lib/ktl/include/ktl/utility.h b/lib/ktl/include/ktl/utility.h deleted file mode 100644 index 1e699e2..0000000 --- a/lib/ktl/include/ktl/utility.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2018 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_UTILITY_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_UTILITY_H_ - -#include - -namespace ktl { - -using std::declval; -using std::exchange; -using std::forward; -using std::move; -using std::swap; - -using std::in_place; -using std::in_place_index; -using std::in_place_index_t; -using std::in_place_t; - -using std::index_sequence; -using std::index_sequence_for; -using std::integer_sequence; -using std::make_index_sequence; -using std::make_integer_sequence; - -using std::get; -using std::make_pair; -using std::pair; -using std::piecewise_construct; -using std::piecewise_construct_t; - -using std::ignore; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_UTILITY_H_ diff --git a/lib/ktl/include/ktl/variant.h b/lib/ktl/include/ktl/variant.h deleted file mode 100644 index 68ef362..0000000 --- a/lib/ktl/include/ktl/variant.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_VARIANT_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_VARIANT_H_ - -#include -#include - -namespace ktl { - -using std::get; -using std::get_if; -using std::holds_alternative; -using std::in_place_type; -using std::in_place_type_t; -using std::monostate; -using std::variant; -using std::variant_alternative; -using std::variant_alternative_t; -using std::variant_npos; -using std::variant_size; -using std::variant_size_v; -using std::visit; - -} // namespace ktl - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_KTL_VARIANT_H_ diff --git a/lib/ktl/include/limits b/lib/ktl/include/limits deleted file mode 100644 index d8ea37d..0000000 --- a/lib/ktl/include/limits +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2018 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#pragma once - -// TODO(https://fxbug.dev/42106615): The libc++ defines specializations for -// floating-point types, which in GCC is incompatible with the command-line -// switches used for the kernel. So this header fakes out the other libc++ -// headers with a std::numeric_limits that is close enough. - -#include - -namespace std { - -template -class numeric_limits {}; - -#define SPECIALIZE_INT(type, sign, modulo, digits_, min_, max_) \ - template <> \ - class numeric_limits { \ - public: \ - static constexpr bool is_specialized = true; \ - static constexpr bool is_signed = (sign); \ - static constexpr bool is_integer = true; \ - static constexpr bool is_exact = true; \ - static constexpr bool has_infinity = false; \ - static constexpr bool has_quiet_NaN = false; \ - static constexpr bool has_signaling_NaN = false; \ - static constexpr bool has_denorm = false; \ - static constexpr bool has_denorm_loss = false; \ - static constexpr bool round_style = false; \ - static constexpr bool is_iec559 = false; \ - static constexpr bool is_bounded = true; \ - static constexpr bool is_modulo = (modulo); \ - static constexpr int digits = (digits_); \ - static constexpr int digits10 = (digits_) * 3 / 10; \ - static constexpr int max_digits10 = 0; \ - static constexpr int radix = 2; \ - static constexpr int min_exponent = 0; \ - static constexpr int min_exponent10 = 0; \ - static constexpr int max_exponent = 0; \ - static constexpr int max_exponent10 = 0; \ - static constexpr bool traps = false; \ - static constexpr bool tinyness_before = false; \ - static constexpr type min() { \ - return (min_); \ - } \ - static constexpr type lowest() { \ - return (min_); \ - } \ - static constexpr type max() { \ - return (max_); \ - } \ - static constexpr type epsilon() { \ - return 0; \ - } \ - static constexpr type round_error() { \ - return 0; \ - } \ - static constexpr type infinity() { \ - return 0; \ - } \ - static constexpr type quiet_NaN() { \ - return 0; \ - } \ - static constexpr type signaling_NaN() { \ - return 0; \ - } \ - static constexpr type denorm_min() { \ - return 0; \ - } \ - } - -#define SPECIALIZE_SIGNED(type, min, max) \ - SPECIALIZE_INT(type, true, false, CHAR_BIT * sizeof(type) - 1, min, max) - -#define SPECIALIZE_UNSIGNED(type, min, max) \ - SPECIALIZE_INT(type, false, true, CHAR_BIT * sizeof(type), min, max) - -SPECIALIZE_INT(bool, false, true, 1, false, true); -#if CHAR_MIN == 0 -SPECIALIZE_UNSIGNED(char, CHAR_MIN, CHAR_MAX); -#else -SPECIALIZE_SIGNED(char, CHAR_MIN, CHAR_MAX); -#endif -SPECIALIZE_SIGNED(signed char, SCHAR_MIN, SCHAR_MAX); -SPECIALIZE_UNSIGNED(unsigned char, 0, UCHAR_MAX); - -SPECIALIZE_SIGNED(short, SHRT_MIN, SHRT_MAX); -SPECIALIZE_UNSIGNED(unsigned short, 0, USHRT_MAX); -SPECIALIZE_SIGNED(int, INT_MIN, INT_MAX); -SPECIALIZE_UNSIGNED(unsigned int, 0, UINT_MAX); -SPECIALIZE_SIGNED(long, LONG_MIN, LONG_MAX); -SPECIALIZE_UNSIGNED(unsigned long, 0, ULONG_MAX); -SPECIALIZE_SIGNED(long long, (-__LONG_LONG_MAX__ - 1LL), __LONG_LONG_MAX__); -SPECIALIZE_UNSIGNED(unsigned long long, 0, (__LONG_LONG_MAX__ * 2ULL + 1ULL)); - -#ifdef __SIZEOF_INT128__ -SPECIALIZE_SIGNED(__int128_t, (__int128_t{1} << 127), (~__uint128_t{0} ^ (__int128_t{1} << 127))); -SPECIALIZE_UNSIGNED(__uint128_t, 0, (~__uint128_t{0})); -#endif - -#undef SPECIALIZE_SIGNED -#undef SPECIALIZE_UNSIGNED -#undef SPECIALIZE_INT - -} // namespace std diff --git a/lib/ktl/include/time.h b/lib/ktl/include/time.h deleted file mode 100644 index 138801f..0000000 --- a/lib/ktl/include/time.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_TIME_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_TIME_H_ - -#include - -// uses these when __has_include(). -typedef long int time_t; -struct timespec { - time_t tv_sec; - long int tv_nsec; -}; - -// The kernel doesn't want this file but some libc++ headers we need -// wind up including it and they need these declarations. - -#ifdef __cplusplus - -using clock_t = long int; -struct tm {}; -char* asctime(tm*) noexcept; -clock_t clock() noexcept; -char* ctime(const time_t*) noexcept; -double difftime(time_t, time_t) noexcept; -tm* gmtime(const time_t*) noexcept; -tm* localtime(const time_t*) noexcept; -time_t mktime(tm*) noexcept; -size_t strftime(char*, size_t, const char*, const tm*) noexcept; -time_t time(time_t*) noexcept; -int timespec_get(timespec* ts, int) noexcept; - -#endif // __cplusplus - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_TIME_H_ diff --git a/lib/ktl/include/version b/lib/ktl/include/version deleted file mode 100644 index ba04749..0000000 --- a/lib/ktl/include/version +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2024 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#pragma once - -#include_next - -// We want to be able to implement specialization for std::formatter in common libraries for kernel -// and userspace. By undefing it here, we allow those libraries to avoid exposing that code to the -// kernel where it's not supported. -#undef __cpp_lib_format diff --git a/lib/ktl/include/wchar.h b/lib/ktl/include/wchar.h deleted file mode 100644 index b3f2ccb..0000000 --- a/lib/ktl/include/wchar.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2023 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_WCHAR_H_ -#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_WCHAR_H_ - -// This file is included by and the like that are used from other -// libc++ headers that are wrapped by ktl. This file exists to preempt those -// inclusions so that libc++'s wrapper header won't be used, since -// it's not compatible with the kernel environment. However, other libc++ -// headers also use `#include_next ` to get to "the system libc" -// version of the header. To satisfy those, include-after/wchar.h provides the -// actual declarations needed from the standard C API. So this -// header just defers to that one, but must exist separately in this directory -// so that it preempt's libc++'s wrapper. This can't itself use #include_next -// because that would reach libc++'s wrapper before the include-after file. - -#include "../include-after/wchar.h" - -#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_WCHAR_H_ diff --git a/lib/ktl/popcount.cc b/lib/ktl/popcount.cc deleted file mode 100644 index 07b7888..0000000 --- a/lib/ktl/popcount.cc +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2019 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#include - -// When the compiler doesn't inline __builtin_popcount{,l}, it calls these. -extern "C" int __popcountsi2(uint32_t val); -extern "C" int __popcountdi2(uint64_t val); -// If the compiler doesn't inline __builtin_popcount % 2 it calls this. -extern "C" int __paritydi2(uint64_t val); - -extern "C" int __popcountsi2(uint32_t val) { - // Implement a log2(bits) popcount, with a few tricks to save some - // instructions. - // - // The general idea here is to simply add up the bits in the word in - // parallel, storing intermediate results in different bit positions in - // the word as we go, and eventually arriving at a sum which is the - // popcount of the word. - // - // For example, consider an 8 bit integer written as - // - // b7 b6 b5 b4 b3 b2 b1 b0 - // - // Each of the bits in the word represent a partial sum that, when added - // together, produce our result. We can compute... - // - // ( - // b7 b6 b5 b4 b3 b2 b1 b0 & - // 0 1 0 1 0 1 0 1 = - // 0 b6 0 b4 0 b2 0 b0 - // ) + ( - // b7 b6 b5 b4 b3 b2 b1 b0 >> 1 = - // 0 b7 b6 b5 b4 b3 b2 b1 & - // 0 1 0 1 0 1 0 1 = - // 0 b7 0 b5 0 b3 0 b1 - // ) = - // b7+b6 b5+b4 b3+b2 b1+b0 - // - // And now we have 4 partial sums, each of which takes two bits of - // storage instead of one. Repeating this process with appropriate - // masks and shifts will eventually give us the answer we are looking - // for. After the next step, we will have partial sums which require 3 - // bits of storage, but aligned to 4 bit boundaries; so... - // - // 0 (b7+b6+b5+b4) 0 (b3+b2+b1+b0) - // - // After the last step, we will get the final sum stored in 4 bits, with - // guaranteed 0s for the upper bits. - // aligned to ... - // - // 0 0 0 0 (b7+b6+b5+b4+b3+b2+b1+b0) - // - // While this is the general idea, it turns out that we only need to - // follow this exact process during step #2. For each of the other - // steps (there will be 5 for a 32 bit integer) we can shave a few - // cycles by taking advantage of some of the particular properties of - // each step. See the comments below. - constexpr uint32_t mask1 = 0x55555555; - constexpr uint32_t mask2 = 0x33333333; - constexpr uint32_t mask3 = 0x0F0F0F0F; - constexpr uint32_t mult1 = 0x01010101; - - // Step 1: - // While we could compute (val & mask) + ((val >> 1) & mask), we can - // actually save one of the mask operations by subtracting instead of - // adding. Consider the following truth table... - // - // In | >>1 | & | - | - // X00 | XX0 | X00 | X00 | - // X01 | XX0 | X00 | X01 | - // X10 | XX1 | X01 | X01 | - // X11 | XX1 | X01 | X10 | - // - val = val - ((val >> 1) & mask1); - - // Step 2: - // This is simply the operation described in the overview, adding a - // bunch of 2 bit partials to produce a 3 bit result, but which is - // aligned on 4 bit boundaries (where the MSB of each 4 bit nibble is - // guaranteed to be 0) - val = (val & mask2) + ((val >> 2) & mask2); - - // Step 3: - // Again, we can save a mask operation here. This time, it is because - // the we know that all bit positions ((i * 4) + 3) are guaranteed to be - // zero. We can simply shift by 4 and add the partial sums. Any - // overflow will go into the ((i * 4) + 3) position and not interfere - // with any of the other partial sums. - val = (val + (val >> 4)) & mask3; - - // Step 4 + 5: - // Finally, we can combine steps 4 and 5 using a multiply. We have 4 - // remaining partial sums, each of which is contained in 4 bits and - // aligned to 8 bit boundaries (with 4 bits of zero in-between each - // sum). Now, we have enough space that if we could perform all 4 sums - // at once, we know that the result would fit in (at most) 6 bits, which - // easily fits in our 8 bits of space. - // - // At its heart, multiplying is the equivalent of repeated shifting, and - // conditional adding. IOW - if I multiply by 0101b, it is basically - // the same as saying "shift X left by 0, then add that to shift X left - // by 2" (because bits 0 and bits 2 are the only bits set). - // - // So, we have, 0x0A0B0C0D, and want to compute (A+B+C+D). Multiplying - // our register by 0x01010101 basically does this for us. We are - // summing our register shifted left by 0 (A), 8 (B), 16 (C) and 24 (D), - // which puts A+B+C+D into the upper 8 bits of the register. The lower - // 24 bits are junk, but we know (because of the 0s which separate A-D) - // that this junk is not going to overflow into our result. All we need - // to do is right shift by 24, and we are done. - return (val * mult1) >> 24; -} - -extern "C" int __popcountdi2(uint64_t val) { - // See notes above for how this works. The 64 bit version of this is - // identical to the 32 bit version, the only difference is that during - // the final stage, we use the multiply trick to combine steps 4, 5, and - // 6 to sum all 8 4-bit partial sums at once, fitting the result into a - // 7 bit value. - constexpr uint64_t mask1 = 0x5555555555555555; - constexpr uint64_t mask2 = 0x3333333333333333; - constexpr uint64_t mask3 = 0x0F0F0F0F0F0F0F0F; - constexpr uint64_t mult1 = 0x0101010101010101; - - val = val - ((val >> 1) & mask1); - val = (val & mask2) + ((val >> 2) & mask2); - val = (val + (val >> 4)) & mask3; - return static_cast((val * mult1) >> 56); -} - -extern "C" int __paritydi2(uint64_t val) { return __popcountdi2(val) % 2; } diff --git a/lib/ktl/stub-new.cc b/lib/ktl/stub-new.cc deleted file mode 100644 index 919d941..0000000 --- a/lib/ktl/stub-new.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#include - -// std::stable_sort (used as ktl::stable_sort) uses std::get_temporary_buffer, -// which uses operator new to request a temporary buffer but then works fine -// if it can't get one. There is no "default" memory allocation in the -// kernel, so just provide a stub operator new that always fails so -// std::stable_sort falls back to its no-allocation algorithm. - -namespace std { - -const nothrow_t nothrow; - -} // namespace std - -void* operator new(std::size_t, const std::nothrow_t&) noexcept { return nullptr; } - -void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) noexcept { - return nullptr; -} diff --git a/lib/libc/LICENSE b/lib/libc/LICENSE deleted file mode 100644 index 8580f02..0000000 --- a/lib/libc/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -Copyright 2016 The Fuchsia Authors -Copyright (c) 2008-2015 Travis Geiselbrecht - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files -(the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of the Software, -and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/libc/README.lume b/lib/libc/README.lume deleted file mode 100644 index 8d50752..0000000 --- a/lib/libc/README.lume +++ /dev/null @@ -1,10 +0,0 @@ -Zircon kernel libc header layer - -Source: zircon/kernel/lib/libc/include and include-after -Fuchsia revision: f8d670ab4bbb71bfb4d569893ba12fbb8a83bacd - -This first import contains the complete public header layer. The libc -implementation sources are intentionally not imported yet because abort, -panic, heap, console output, and C++ ABI providers belong to later foundation -batches. Existing LumeOS C implementations continue to provide the symbols -used by the current kernel. diff --git a/lib/libc/include-after/ctype.h b/lib/libc/include-after/ctype.h deleted file mode 100644 index ff2fcfe..0000000 --- a/lib/libc/include-after/ctype.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2016 The Fuchsia Authors -// Copyright (c) 2008 Travis Geiselbrecht -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_CTYPE_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_CTYPE_H_ - -#include - -__BEGIN_CDECLS - -int isalnum(int c); -int isalpha(int c); -int isblank(int c); -int iscntrl(int c); -int isdigit(int c); -int isgraph(int c); -int islower(int c); -int isprint(int c); -int ispunct(int c); -int isspace(int c); -int isupper(int c); -int isxdigit(int c); - -int tolower(int c); -int toupper(int c); - -__END_CDECLS - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_CTYPE_H_ diff --git a/lib/libc/include-after/limits.h b/lib/libc/include-after/limits.h deleted file mode 100644 index f946def..0000000 --- a/lib/libc/include-after/limits.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -// Empty file for toolchain's #include_next to find. diff --git a/lib/libc/include/assert.h b/lib/libc/include/assert.h deleted file mode 100644 index 8b6252e..0000000 --- a/lib/libc/include/assert.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#pragma once - -#include - -#ifdef NDEBUG -#define assert(expr) ((void)0) -#else -#define assert(expr) ZX_ASSERT(expr) -#endif - -// make sure static_assert() is defined, even in C -#if !defined(__cplusplus) && !defined(static_assert) -#define static_assert(e, msg) _Static_assert(e, msg) -#endif diff --git a/lib/libc/include/inttypes.h b/lib/libc/include/inttypes.h deleted file mode 100644 index b19e0f5..0000000 --- a/lib/libc/include/inttypes.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2016 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_INTTYPES_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_INTTYPES_H_ - -// This (or the compiler) defines all the ___FMT__ macros. -#include - -#define PRId8 __INT8_FMTd__ -#define PRId16 __INT16_FMTd__ -#define PRId32 __INT32_FMTd__ -#define PRId64 __INT64_FMTd__ - -#define PRIdLEAST8 __INT_LEAST8_FMTd__ -#define PRIdLEAST16 __INT_LEAST16_FMTd__ -#define PRIdLEAST32 __INT_LEAST32_FMTd__ -#define PRIdLEAST64 __INT_LEAST64_FMTd__ - -#define PRIdFAST8 __INT_FAST8_FMTd__ -#define PRIdFAST16 __INT_FAST16_FMTd__ -#define PRIdFAST32 __INT_FAST32_FMTd__ -#define PRIdFAST64 __INT_FAST64_FMTd__ - -#define PRIi8 __INT8_FMTi__ -#define PRIi16 __INT16_FMTi__ -#define PRIi32 __INT32_FMTi__ -#define PRIi64 __INT64_FMTi__ - -#define PRIiLEAST8 __INT_LEAST8_FMTi__ -#define PRIiLEAST16 __INT_LEAST16_FMTi__ -#define PRIiLEAST32 __INT_LEAST32_FMTi__ -#define PRIiLEAST64 __INT_LEAST64_FMTi__ - -#define PRIiFAST8 __INT_FAST8_FMTi__ -#define PRIiFAST16 __INT_FAST16_FMTi__ -#define PRIiFAST32 __INT_FAST32_FMTi__ -#define PRIiFAST64 __INT_FAST64_FMTi__ - -#define PRIo8 __UINT8_FMTo__ -#define PRIo16 __UINT16_FMTo__ -#define PRIo32 __UINT32_FMTo__ -#define PRIo64 __UINT64_FMTo__ - -#define PRIoLEAST8 __UINT_LEAST8_FMTo__ -#define PRIoLEAST16 __UINT_LEAST16_FMTo__ -#define PRIoLEAST32 __UINT_LEAST32_FMTo__ -#define PRIoLEAST64 __UINT_LEAST64_FMTo__ - -#define PRIoFAST8 __UINT_FAST8_FMTo__ -#define PRIoFAST16 __UINT_FAST16_FMTo__ -#define PRIoFAST32 __UINT_FAST32_FMTo__ -#define PRIoFAST64 __UINT_FAST64_FMTo__ - -#define PRIu8 __UINT8_FMTu__ -#define PRIu16 __UINT16_FMTu__ -#define PRIu32 __UINT32_FMTu__ -#define PRIu64 __UINT64_FMTu__ - -#define PRIuLEAST8 __UINT_LEAST8_FMTu__ -#define PRIuLEAST16 __UINT_LEAST16_FMTu__ -#define PRIuLEAST32 __UINT_LEAST32_FMTu__ -#define PRIuLEAST64 __UINT_LEAST64_FMTu__ - -#define PRIuFAST8 __UINT_FAST8_FMTu__ -#define PRIuFAST16 __UINT_FAST16_FMTu__ -#define PRIuFAST32 __UINT_FAST32_FMTu__ -#define PRIuFAST64 __UINT_FAST64_FMTu__ - -#define PRIx8 __UINT8_FMTx__ -#define PRIx16 __UINT16_FMTx__ -#define PRIx32 __UINT32_FMTx__ -#define PRIx64 __UINT64_FMTx__ - -#define PRIxLEAST8 __UINT_LEAST8_FMTx__ -#define PRIxLEAST16 __UINT_LEAST16_FMTx__ -#define PRIxLEAST32 __UINT_LEAST32_FMTx__ -#define PRIxLEAST64 __UINT_LEAST64_FMTx__ - -#define PRIxFAST8 __UINT_FAST8_FMTx__ -#define PRIxFAST16 __UINT_FAST16_FMTx__ -#define PRIxFAST32 __UINT_FAST32_FMTx__ -#define PRIxFAST64 __UINT_FAST64_FMTx__ - -#define PRIX8 __UINT8_FMTX__ -#define PRIX16 __UINT16_FMTX__ -#define PRIX32 __UINT32_FMTX__ -#define PRIX64 __UINT64_FMTX__ - -#define PRIXLEAST8 __UINT_LEAST8_FMTX__ -#define PRIXLEAST16 __UINT_LEAST16_FMTX__ -#define PRIXLEAST32 __UINT_LEAST32_FMTX__ -#define PRIXLEAST64 __UINT_LEAST64_FMTX__ - -#define PRIXFAST8 __UINT_FAST8_FMTX__ -#define PRIXFAST16 __UINT_FAST16_FMTX__ -#define PRIXFAST32 __UINT_FAST32_FMTX__ -#define PRIXFAST64 __UINT_FAST64_FMTX__ - -#define PRIdMAX __INTMAX_FMTd__ -#define PRIiMAX __INTMAX_FMTi__ -#define PRIoMAX __UINTMAX_FMTo__ -#define PRIuMAX __UINTMAX_FMTu__ -#define PRIxMAX __UINTMAX_FMTx__ -#define PRIXMAX __UINTMAX_FMTX__ - -#define PRIdPTR __INTPTR_FMTd__ -#define PRIiPTR __INTPTR_FMTi__ -#define PRIoPTR __UINTPTR_FMTo__ -#define PRIuPTR __UINTPTR_FMTu__ -#define PRIxPTR __UINTPTR_FMTx__ -#define PRIXPTR __UINTPTR_FMTX__ - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_INTTYPES_H_ diff --git a/lib/libc/include/multi-file.h b/lib/libc/include/multi-file.h deleted file mode 100644 index a04a031..0000000 --- a/lib/libc/include/multi-file.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2022 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_MULTI_FILE_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_MULTI_FILE_H_ - -#include - -#include -#include -#include -#include - -// MultiFile broadcasts Write calls across multiple FILE* pointers. Each -// pointer is ignored if it's null. MultiFile::Write always returns success, -// ignoring any failures or short writes from the underlying FILE objects. -template -class MultiFile : public FILE { - public: - using FileArray = ktl::array; - - constexpr MultiFile() : FILE{this} {} - - constexpr explicit MultiFile(const FileArray& files) : FILE{this}, files_(files) {} - - constexpr MultiFile(const MultiFile& other) : MultiFile(other.files_) {} - - FileArray& files() { return files_; } - const FileArray& files() const { return files_; } - - int Write(ktl::string_view str) { - for (FILE* file : files_) { - if (file) { - file->Write(str); - } - } - return static_cast(str.size()); - } - - private: - FileArray files_ = {}; -}; - -template -MultiFile(const ktl::array&) -> MultiFile; - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_MULTI_FILE_H_ diff --git a/lib/libc/include/stdint.h b/lib/libc/include/stdint.h deleted file mode 100644 index 3cbdfeb..0000000 --- a/lib/libc/include/stdint.h +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright 2016 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDINT_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDINT_H_ - -// The compiler predefines macros ___TYPE__, ___MAX__, -// and ___C for the various types. All we have to do here is -// define the public names based on those macros. - -// Clang predefines macros ___FMT__ for each type, -// with being i and for signed types, and o, u, x, and X -// for unsigned types. That lets do its work without -// any special knowledge of what the underlying types are. -// Unfortunately, GCC does not define these macros. To keep all -// knowledge of the compiler's choices isolated to this file, define -// them here for GCC so that can use them unconditionally. -#ifndef __INTMAX_FMTd__ - -#define __INT8_FMT_MODIFIER__ "hh" -#define __INT16_FMT_MODIFIER__ "h" -#ifdef _LP64 -#define __INT32_FMT_MODIFIER__ "" -#else -#define __INT32_FMT_MODIFIER__ "l" -#endif - -#define __INT_LEAST8_FMT_MODIFIER__ __INT8_FMT_MODIFIER__ -#define __INT_LEAST16_FMT_MODIFIER__ __INT16_FMT_MODIFIER__ -#define __INT_LEAST32_FMT_MODIFIER__ __INT32_FMT_MODIFIER__ -#define __INT_LEAST64_FMT_MODIFIER__ __INT64_FMT_MODIFIER__ - -// The *-elf and arm-eabi GCC targets use 'int' for the fast{8,16,32} -// types. On LP64 systems, 'long' is used for the fast64 type, and -// 'long long' on non-LP64 systems. -#define __INT_FAST8_FMT_MODIFIER__ "" -#define __INT_FAST16_FMT_MODIFIER__ "" -#define __INT_FAST32_FMT_MODIFIER__ "" -#if _LP64 -#define __INT_FAST64_FMT_MODIFIER__ "l" -#else -#define __INT_FAST64_FMT_MODIFIER__ "ll" -#endif - -// On machines where 'long' types are 64 bits, the compiler defines -// __INT64_TYPE__ et al using 'long', not 'long long', though both are -// 64-bit types. -#ifdef _LP64 -#define __INT64_FMT_MODIFIER__ "l" -#define __INTPTR_FMT_MODIFIER__ "l" -#else -#define __INT64_FMT_MODIFIER__ "ll" -#define __INTPTR_FMT_MODIFIER__ "" -#endif - -#define __INTMAX_FMT_MODIFIER__ __INT64_FMT_MODIFIER__ - -#define __INTMAX_FMTd__ __INTMAX_FMT_MODIFIER__ "d" -#define __INTMAX_FMTi__ __INTMAX_FMT_MODIFIER__ "i" -#define __UINTMAX_FMTo__ __INTMAX_FMT_MODIFIER__ "o" -#define __UINTMAX_FMTu__ __INTMAX_FMT_MODIFIER__ "u" -#define __UINTMAX_FMTx__ __INTMAX_FMT_MODIFIER__ "x" -#define __UINTMAX_FMTX__ __INTMAX_FMT_MODIFIER__ "X" -#define __INTPTR_FMTd__ __INTPTR_FMT_MODIFIER__ "d" -#define __INTPTR_FMTi__ __INTPTR_FMT_MODIFIER__ "i" -#define __UINTPTR_FMTo__ __INTPTR_FMT_MODIFIER__ "o" -#define __UINTPTR_FMTu__ __INTPTR_FMT_MODIFIER__ "u" -#define __UINTPTR_FMTx__ __INTPTR_FMT_MODIFIER__ "x" -#define __UINTPTR_FMTX__ __INTPTR_FMT_MODIFIER__ "X" -#define __INT8_FMTd__ __INT8_FMT_MODIFIER__ "d" -#define __INT8_FMTi__ __INT8_FMT_MODIFIER__ "i" -#define __INT16_FMTd__ __INT16_FMT_MODIFIER__ "d" -#define __INT16_FMTi__ __INT16_FMT_MODIFIER__ "i" -#define __INT32_FMTd__ __INT32_FMT_MODIFIER__ "d" -#define __INT32_FMTi__ __INT32_FMT_MODIFIER__ "i" -#define __INT64_FMTd__ __INT64_FMT_MODIFIER__ "d" -#define __INT64_FMTi__ __INT64_FMT_MODIFIER__ "i" -#define __UINT8_FMTo__ __INT8_FMT_MODIFIER__ "o" -#define __UINT8_FMTu__ __INT8_FMT_MODIFIER__ "u" -#define __UINT8_FMTx__ __INT8_FMT_MODIFIER__ "x" -#define __UINT8_FMTX__ __INT8_FMT_MODIFIER__ "X" -#define __UINT16_FMTo__ __INT16_FMT_MODIFIER__ "o" -#define __UINT16_FMTu__ __INT16_FMT_MODIFIER__ "u" -#define __UINT16_FMTx__ __INT16_FMT_MODIFIER__ "x" -#define __UINT16_FMTX__ __INT16_FMT_MODIFIER__ "X" -#define __UINT32_FMTo__ __INT32_FMT_MODIFIER__ "o" -#define __UINT32_FMTu__ __INT32_FMT_MODIFIER__ "u" -#define __UINT32_FMTx__ __INT32_FMT_MODIFIER__ "x" -#define __UINT32_FMTX__ __INT32_FMT_MODIFIER__ "X" -#define __UINT64_FMTo__ __INT64_FMT_MODIFIER__ "o" -#define __UINT64_FMTu__ __INT64_FMT_MODIFIER__ "u" -#define __UINT64_FMTx__ __INT64_FMT_MODIFIER__ "x" -#define __UINT64_FMTX__ __INT64_FMT_MODIFIER__ "X" -#define __INT_LEAST8_FMTd__ __INT_LEAST8_FMT_MODIFIER__ "d" -#define __INT_LEAST8_FMTi__ __INT_LEAST8_FMT_MODIFIER__ "i" -#define __UINT_LEAST8_FMTo__ __INT_LEAST8_FMT_MODIFIER__ "o" -#define __UINT_LEAST8_FMTu__ __INT_LEAST8_FMT_MODIFIER__ "u" -#define __UINT_LEAST8_FMTx__ __INT_LEAST8_FMT_MODIFIER__ "x" -#define __UINT_LEAST8_FMTX__ __INT_LEAST8_FMT_MODIFIER__ "X" -#define __INT_LEAST16_FMTd__ __INT_LEAST16_FMT_MODIFIER__ "d" -#define __INT_LEAST16_FMTi__ __INT_LEAST16_FMT_MODIFIER__ "i" -#define __UINT_LEAST16_FMTo__ __INT_LEAST16_FMT_MODIFIER__ "o" -#define __UINT_LEAST16_FMTu__ __INT_LEAST16_FMT_MODIFIER__ "u" -#define __UINT_LEAST16_FMTx__ __INT_LEAST16_FMT_MODIFIER__ "x" -#define __UINT_LEAST16_FMTX__ __INT_LEAST16_FMT_MODIFIER__ "X" -#define __INT_LEAST32_FMTd__ __INT_LEAST32_FMT_MODIFIER__ "d" -#define __INT_LEAST32_FMTi__ __INT_LEAST32_FMT_MODIFIER__ "i" -#define __UINT_LEAST32_FMTo__ __INT_LEAST32_FMT_MODIFIER__ "o" -#define __UINT_LEAST32_FMTu__ __INT_LEAST32_FMT_MODIFIER__ "u" -#define __UINT_LEAST32_FMTx__ __INT_LEAST32_FMT_MODIFIER__ "x" -#define __UINT_LEAST32_FMTX__ __INT_LEAST32_FMT_MODIFIER__ "X" -#define __INT_LEAST64_FMTd__ __INT_LEAST64_FMT_MODIFIER__ "d" -#define __INT_LEAST64_FMTi__ __INT_LEAST64_FMT_MODIFIER__ "i" -#define __UINT_LEAST64_FMTo__ __INT_LEAST64_FMT_MODIFIER__ "o" -#define __UINT_LEAST64_FMTu__ __INT_LEAST64_FMT_MODIFIER__ "u" -#define __UINT_LEAST64_FMTx__ __INT_LEAST64_FMT_MODIFIER__ "x" -#define __UINT_LEAST64_FMTX__ __INT_LEAST64_FMT_MODIFIER__ "X" -#define __INT_FAST8_FMTd__ __INT_FAST8_FMT_MODIFIER__ "d" -#define __INT_FAST8_FMTi__ __INT_FAST8_FMT_MODIFIER__ "i" -#define __UINT_FAST8_FMTo__ __INT_FAST8_FMT_MODIFIER__ "o" -#define __UINT_FAST8_FMTu__ __INT_FAST8_FMT_MODIFIER__ "u" -#define __UINT_FAST8_FMTx__ __INT_FAST8_FMT_MODIFIER__ "x" -#define __UINT_FAST8_FMTX__ __INT_FAST8_FMT_MODIFIER__ "X" -#define __INT_FAST16_FMTd__ __INT_FAST16_FMT_MODIFIER__ "d" -#define __INT_FAST16_FMTi__ __INT_FAST16_FMT_MODIFIER__ "i" -#define __UINT_FAST16_FMTo__ __INT_FAST16_FMT_MODIFIER__ "o" -#define __UINT_FAST16_FMTu__ __INT_FAST16_FMT_MODIFIER__ "u" -#define __UINT_FAST16_FMTx__ __INT_FAST16_FMT_MODIFIER__ "x" -#define __UINT_FAST16_FMTX__ __INT_FAST16_FMT_MODIFIER__ "X" -#define __INT_FAST32_FMTd__ __INT_FAST32_FMT_MODIFIER__ "d" -#define __INT_FAST32_FMTi__ __INT_FAST32_FMT_MODIFIER__ "i" -#define __UINT_FAST32_FMTo__ __INT_FAST32_FMT_MODIFIER__ "o" -#define __UINT_FAST32_FMTu__ __INT_FAST32_FMT_MODIFIER__ "u" -#define __UINT_FAST32_FMTx__ __INT_FAST32_FMT_MODIFIER__ "x" -#define __UINT_FAST32_FMTX__ __INT_FAST32_FMT_MODIFIER__ "X" -#define __INT_FAST64_FMTd__ __INT_FAST64_FMT_MODIFIER__ "d" -#define __INT_FAST64_FMTi__ __INT_FAST64_FMT_MODIFIER__ "i" -#define __UINT_FAST64_FMTo__ __INT_FAST64_FMT_MODIFIER__ "o" -#define __UINT_FAST64_FMTu__ __INT_FAST64_FMT_MODIFIER__ "u" -#define __UINT_FAST64_FMTx__ __INT_FAST64_FMT_MODIFIER__ "x" -#define __UINT_FAST64_FMTX__ __INT_FAST64_FMT_MODIFIER__ "X" - -#endif - -typedef __UINT8_TYPE__ uint8_t; -typedef __UINT16_TYPE__ uint16_t; -typedef __UINT32_TYPE__ uint32_t; -typedef __UINT64_TYPE__ uint64_t; -typedef __INT8_TYPE__ int8_t; -typedef __INT16_TYPE__ int16_t; -typedef __INT32_TYPE__ int32_t; -typedef __INT64_TYPE__ int64_t; - -#define UINT8_MAX __UINT8_MAX__ -#define UINT16_MAX __UINT16_MAX__ -#define UINT32_MAX __UINT32_MAX__ -#define UINT64_MAX __UINT64_MAX__ - -#define INT8_MAX __INT8_MAX__ -#define INT16_MAX __INT16_MAX__ -#define INT32_MAX __INT32_MAX__ -#define INT64_MAX __INT64_MAX__ - -#define INT8_MIN (-INT8_MAX - 1) -#define INT16_MIN (-INT16_MAX - 1) -#define INT32_MIN (-INT32_MAX - 1) -#define INT64_MIN (-INT64_MAX - 1) - -typedef __UINT_LEAST8_TYPE__ uint_least8_t; -typedef __UINT_LEAST16_TYPE__ uint_least16_t; -typedef __UINT_LEAST32_TYPE__ uint_least32_t; -typedef __UINT_LEAST64_TYPE__ uint_least64_t; -typedef __INT_LEAST8_TYPE__ int_least8_t; -typedef __INT_LEAST16_TYPE__ int_least16_t; -typedef __INT_LEAST32_TYPE__ int_least32_t; -typedef __INT_LEAST64_TYPE__ int_least64_t; - -#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__ -#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__ -#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__ -#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__ - -#define INT_LEAST8_MAX __INT_LEAST8_MAX__ -#define INT_LEAST16_MAX __INT_LEAST16_MAX__ -#define INT_LEAST32_MAX __INT_LEAST32_MAX__ -#define INT_LEAST64_MAX __INT_LEAST64_MAX__ - -#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1) -#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1) -#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1) -#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1) - -typedef __UINT_FAST8_TYPE__ uint_fast8_t; -typedef __UINT_FAST16_TYPE__ uint_fast16_t; -typedef __UINT_FAST32_TYPE__ uint_fast32_t; -typedef __UINT_FAST64_TYPE__ uint_fast64_t; -typedef __INT_FAST8_TYPE__ int_fast8_t; -typedef __INT_FAST16_TYPE__ int_fast16_t; -typedef __INT_FAST32_TYPE__ int_fast32_t; -typedef __INT_FAST64_TYPE__ int_fast64_t; - -#define UINT_FAST8_MAX __UINT_FAST8_MAX__ -#define UINT_FAST16_MAX __UINT_FAST16_MAX__ -#define UINT_FAST32_MAX __UINT_FAST32_MAX__ -#define UINT_FAST64_MAX __UINT_FAST64_MAX__ - -#define INT_FAST8_MAX __INT_FAST8_MAX__ -#define INT_FAST16_MAX __INT_FAST16_MAX__ -#define INT_FAST32_MAX __INT_FAST32_MAX__ -#define INT_FAST64_MAX __INT_FAST64_MAX__ - -#define INT_FAST8_MIN (-INT_FAST8_MAX - 1) -#define INT_FAST16_MIN (-INT_FAST16_MAX - 1) -#define INT_FAST32_MIN (-INT_FAST32_MAX - 1) -#define INT_FAST64_MIN (-INT_FAST64_MAX - 1) - -typedef __INTPTR_TYPE__ intptr_t; -typedef __UINTPTR_TYPE__ uintptr_t; - -#define INTPTR_MAX __INTPTR_MAX__ -#define INTPTR_MIN (-INTPTR_MAX - 1) -#define UINTPTR_MAX __UINTPTR_MAX__ - -typedef __INTMAX_TYPE__ intmax_t; -typedef __UINTMAX_TYPE__ uintmax_t; - -#define INTMAX_MAX __INTMAX_MAX__ -#define INTMAX_MIN (-INTMAX_MAX - 1) -#define UINTMAX_MAX __UINTMAX_MAX__ - -#define SIZE_MAX __SIZE_MAX__ - -// GCC defines __INT_C macros which append the correct suffix -// to an (un)signed integer literal, with being one of 8, 16, 32, 64 -// and MAX, and type being U for unsigned types. The standard stdint.h macros -// with the same names without the leading __ could be implemented in terms of -// these macros. -// -// Clang predefines macros __INT_C_SUFFIX__ which expand to the -// suffix itself. We define the standard stdint.h macros in terms of the GCC -// variants and for Clang we define their equivalents. -#ifndef __INTMAX_C - -#define __int_c_join(a, b) a##b -#define __int_c(v, suffix) __int_c_join(v, suffix) - -#define __INT8_C(c) __int_c(c, __INT8_C_SUFFIX__) -#define __INT16_C(c) __int_c(c, __INT16_C_SUFFIX__) -#define __INT32_C(c) __int_c(c, __INT32_C_SUFFIX__) -#define __INT64_C(c) __int_c(c, __INT64_C_SUFFIX__) - -#define __UINT8_C(c) __int_c(c, __UINT8_C_SUFFIX__) -#define __UINT16_C(c) __int_c(c, __UINT16_C_SUFFIX__) -#define __UINT32_C(c) __int_c(c, __UINT32_C_SUFFIX__) -#define __UINT64_C(c) __int_c(c, __UINT64_C_SUFFIX__) - -#define __INTMAX_C(c) __int_c(c, __INTMAX_C_SUFFIX__) -#define __UINTMAX_C(c) __int_c(c, __UINTMAX_C_SUFFIX__) - -#endif - -#define INT8_C(c) __INT8_C(c) -#define INT16_C(c) __INT16_C(c) -#define INT32_C(c) __INT32_C(c) -#define INT64_C(c) __INT64_C(c) - -#define UINT8_C(c) __UINT8_C(c) -#define UINT16_C(c) __UINT16_C(c) -#define UINT32_C(c) __UINT32_C(c) -#define UINT64_C(c) __UINT64_C(c) - -#define INTMAX_C(c) __INTMAX_C(c) -#define UINTMAX_C(c) __UINTMAX_C(c) - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDINT_H_ diff --git a/lib/libc/include/stdio.h b/lib/libc/include/stdio.h deleted file mode 100644 index ae5a84b..0000000 --- a/lib/libc/include/stdio.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2020 The Fuchsia Authors -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDIO_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDIO_H_ - -#include -#include -#include - -// All anybody really wants from stdio is printf. - -#ifdef __cplusplus -#include - -class FILE { - public: - // This is basically equivalent to having a virtual Write function with - // subclasses providing their own data members in lieu of ptr. But it's - // simpler and avoids a vtable that might need address fixup at load time - // (and the double indirection for a single-entry vtable--at the cost of - // double indirection for the ptr data in a callback that uses it). - - using Callback = int(void*, ktl::string_view); - - FILE() = default; - - constexpr FILE(Callback* write, void* ptr) : write_(write), ptr_(ptr) {} - - template - explicit FILE(T* writer) - : write_([](void* ptr, ktl::string_view s) { return static_cast(ptr)->Write(s); }), - ptr_(writer) {} - - // This is what fprintf calls to do output. - int Write(ktl::string_view s) { return write_(ptr_, s); } - - constexpr explicit operator bool() const { return write_; } - - constexpr bool operator==(const FILE& other) const { - return write_ == other.write_ && ptr_ == other.ptr_; - } - - constexpr bool operator!=(const FILE& other) const { return !(*this == other); } - - // This is not defined by libc itself. The kernel defines it to point at - // the default console output mechanism. - static FILE stdout_; - - private: - Callback* write_ = nullptr; - void* ptr_ = nullptr; -}; - -#define stdout (&FILE::stdout_) - -inline int fputc(int c, FILE* f) { - const unsigned char uc = static_cast(c); - return f->Write({reinterpret_cast(&uc), 1}) == 1 ? uc : -1; -} - -inline int putc(int c, FILE* f) { return fputc(c, f); } - -inline int putchar(int c) { return fputc(c, stdout); } - -inline int fputs(const char* s, FILE* f) { - ktl::string_view str(s); - return f->Write(str) == static_cast(str.size()) ? 0 : -1; -} - -inline int puts(const char* s) { return fputs(s, stdout) == 0 ? putchar('\n') : -1; } - -#else // !__cplusplus - -// C users just need the function declarations. -typedef struct _FILE_is_opaque FILE; - -#endif // __cplusplus - -__BEGIN_CDECLS - -int printf(const char*, ...) __PRINTFLIKE(1, 2); -int fprintf(FILE*, const char*, ...) __PRINTFLIKE(2, 3); -int snprintf(char* buf, size_t len, const char*, ...) __PRINTFLIKE(3, 4); - -int vprintf(const char*, va_list); -int vfprintf(FILE*, const char*, va_list); -int vsnprintf(char* buf, size_t len, const char*, va_list); - -__END_CDECLS - -#if DISABLE_DEBUG_OUTPUT -// The declarations stand so these can be used without parens to get -// the real functions (e.g. &printf or (printf)(...)). -#define printf(...) -#define vprintf(fmt, args) -#endif - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDIO_H_ diff --git a/lib/libc/include/stdlib.h b/lib/libc/include/stdlib.h deleted file mode 100644 index 45c5a21..0000000 --- a/lib/libc/include/stdlib.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2016 The Fuchsia Authors -// Copyright (c) 2008-2014 Travis Geiselbrecht -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDLIB_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDLIB_H_ - -#include -#include -#include - -#ifdef _KERNEL -#include // lib/heap provides malloc/free definitions. -#endif - -__BEGIN_CDECLS - -long strtol(const char *nptr, char **endptr, int base); -unsigned long int strtoul(const char *nptr, char **endptr, int base); - -void abort(void) __attribute__((noreturn)); - -#define RAND_MAX (0x7fffffff) - -int rand(void); -void srand(unsigned int seed); - -// Note: POSIX.1 specifies unsigned int, but we use uintptr_t instead. -int rand_r(uintptr_t *seed); - -__END_CDECLS - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STDLIB_H_ diff --git a/lib/libc/include/string-file.h b/lib/libc/include/string-file.h deleted file mode 100644 index 1632933..0000000 --- a/lib/libc/include/string-file.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2021 The Fuchsia Authors -// Copyright (c) 2008 Travis Geiselbrecht -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STRING_FILE_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STRING_FILE_H_ - -#ifdef __cplusplus -#include - -#include -#include -#include - -// FILE* wrapper over a string. -class StringFile : public FILE { - public: - StringFile() = delete; - StringFile(const StringFile &) = delete; - StringFile operator=(const StringFile &) = delete; - - explicit StringFile(ktl::span s) : FILE(this), buffer_(s) {} - - ~StringFile() = default; - - // Adds a null character at the end of the current buffer and returns a view - // into the written section. - ktl::span take() &&; - - // Returns |str.size()| and writes as much of |str| as it would fit in the - // buffer [offest_, size - 1) while reserving the last byte for null - // character. - int Write(ktl::string_view str); - - // Returns a region representing the currently used portion of the buffer. - ktl::span used_region() const { - return (offset_ > 0) ? ktl::span{buffer_.data(), offset_} : ktl::span{}; - } - - // Returns a region representing the remaining unused space in the buffer, - // _not_ including the space reserved for the final null character. - ktl::span available_region() const { - const size_t available = ktl::max(buffer_.size() - offset_, 1) - 1; - return (available > 0) ? ktl::span{buffer_.data() + offset_, available} - : ktl::span{}; - } - - // Skip up to |amt| bytes in the buffer, advancing the write pointer as if we - // had written data, but without actually changing the buffer. - void Skip(size_t amt) { - amt = ktl::min(amt, available_region().size()); - offset_ += amt; - } - - // Provide two ways for users to convert the currently used buffer into a - // string_view. Given a string file |S|, users may say either: - // - // 1) S.as_string_view(); // or - // 2) static_cast(S); - // - // to perform the conversion. - // - ktl::string_view as_string_view() const { - return (offset_ > 0) ? ktl::string_view{buffer_.data(), offset_} : ktl::string_view{}; - } - - explicit operator ktl::string_view() const { return this->as_string_view(); } - - private: - ktl::span buffer_; - size_t offset_ = 0; -}; - -#endif // __cplusplus - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STRING_FILE_H_ diff --git a/lib/libc/include/string.h b/lib/libc/include/string.h deleted file mode 100644 index 3b55ccb..0000000 --- a/lib/libc/include/string.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 The Fuchsia Authors -// Copyright (c) 2008 Travis Geiselbrecht -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT - -#ifndef ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STRING_H_ -#define ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STRING_H_ - -// Other libc++ headers use but libc++'s complains if it -// thinks is not its own wrapper, which we do not need. We always -// get the kernel's before the libc++ with the way the include paths -// are set up, which is necessary because of other headers where preempting -// libc++'s header is unavoidable for the kernel environment. So just we -// define the macro that checks for to keep it happy. -#define _LIBCPP_STRING_H - -#include -#include - -__BEGIN_CDECLS - -int memcmp(const void*, const void*, size_t) __PURE; -void* memcpy(void*, const void*, size_t); -void* memmove(void*, const void*, size_t); -void* memset(void*, int, size_t); - -char* strcat(char*, const char*); -int strcmp(const char*, const char*) __PURE; -char* strcpy(char*, const char*); -size_t strlen(const char*) __PURE; -char* strncat(char*, const char*, size_t); -int strncmp(const char*, const char*, size_t) __PURE; -char* strncpy(char*, const char*, size_t); -size_t strspn(const char*, const char*) __PURE; -size_t strcspn(const char* s, const char*) __PURE; -char* strtok(char*, const char*); -int strcoll(const char* s1, const char* s2) __PURE; -size_t strxfrm(char* dest, const char* src, size_t n) __PURE; - -// Not actually defined in the kernel, but expects the declaration. -char* strerror(int); - -// Nonstandard. -size_t strlcat(char*, const char*, size_t); -size_t strlcpy(char*, const char*, size_t); -int strncasecmp(const char*, const char*, size_t) __PURE; -int strnicmp(const char*, const char*, size_t) __PURE; -size_t strnlen(const char* s, size_t count) __PURE; - -// Used by address sanitizer. -__typeof(memcpy) __unsanitized_memcpy; -__typeof(memmove) __unsanitized_memmove; -__typeof(memset) __unsanitized_memset; - -__END_CDECLS - -// C++ wants overloads for const and non-const versions of some functions. -#ifdef __cplusplus - -const char* strchr(const char*, int) __asm__("strchr") __PURE; -inline char* strchr(char* s, int c) { - return const_cast(strchr(const_cast(s), c)); -} - -const char* strpbrk(const char*, const char*) __asm__("strpbrk") __PURE; -inline char* strpbrk(char* s1, const char* s2) { - return const_cast(strpbrk(const_cast(s1), s2)); -} - -const char* strrchr(const char*, int) __asm__("strrchr") __PURE; -inline char* strrchr(char* s, int c) { - return const_cast(strrchr(const_cast(s), c)); -} - -const void* memchr(const void*, int, size_t) __asm__("memchr") __PURE; -inline void* memchr(void* s, int c, size_t n) { - return const_cast(memchr(const_cast(s), c, n)); -} - -const char* strstr(const char*, const char*) __asm__("strstr") __PURE; -inline char* strstr(char* s1, const char* s2) { - return const_cast(strstr(const_cast(s1), s2)); -} - -#else - -void* memchr(const void*, int, size_t); -char* strchr(const char*, int) __PURE; -char* strpbrk(const char*, const char*) __PURE; -char* strrchr(const char*, int) __PURE; -char* strstr(const char*, const char*) __PURE; - -#endif // __cplusplus - -#endif // ZIRCON_KERNEL_LIB_LIBC_INCLUDE_STRING_H_ diff --git a/lib/printf.c b/lib/printf.c deleted file mode 100644 index 8a700ad..0000000 --- a/lib/printf.c +++ /dev/null @@ -1,914 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// \author (c) Marco Paland (info@paland.com) -// 2014-2019, PALANDesign Hannover, Germany -// -// \license The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// \brief Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on -// embedded systems with a very limited resources. These routines are thread -// safe and reentrant! -// Use this instead of the bloated standard/newlib printf cause these use -// malloc for printf (and may not be thread safe). -// -/////////////////////////////////////////////////////////////////////////////// - -#include -#include - -#include "printf.h" - - -// define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the -// printf_config.h header file -// default: undefined -#ifdef PRINTF_INCLUDE_CONFIG_H -#include "printf_config.h" -#endif - - -// 'ntoa' conversion buffer size, this must be big enough to hold one converted -// numeric number including padded zeros (dynamically created on stack) -// default: 32 byte -#ifndef PRINTF_NTOA_BUFFER_SIZE -#define PRINTF_NTOA_BUFFER_SIZE 32U -#endif - -// 'ftoa' conversion buffer size, this must be big enough to hold one converted -// float number including padded zeros (dynamically created on stack) -// default: 32 byte -#ifndef PRINTF_FTOA_BUFFER_SIZE -#define PRINTF_FTOA_BUFFER_SIZE 32U -#endif - -// support for the floating point type (%f) -// default: activated -#ifndef PRINTF_DISABLE_SUPPORT_FLOAT -#define PRINTF_SUPPORT_FLOAT -#endif - -// support for exponential floating point notation (%e/%g) -// default: activated -#ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL -#define PRINTF_SUPPORT_EXPONENTIAL -#endif - -// define the default floating point precision -// default: 6 digits -#ifndef PRINTF_DEFAULT_FLOAT_PRECISION -#define PRINTF_DEFAULT_FLOAT_PRECISION 6U -#endif - -// define the largest float suitable to print with %f -// default: 1e9 -#ifndef PRINTF_MAX_FLOAT -#define PRINTF_MAX_FLOAT 1e9 -#endif - -// support for the long long types (%llu or %p) -// default: activated -#ifndef PRINTF_DISABLE_SUPPORT_LONG_LONG -#define PRINTF_SUPPORT_LONG_LONG -#endif - -// support for the ptrdiff_t type (%t) -// ptrdiff_t is normally defined in as long or long long type -// default: activated -#ifndef PRINTF_DISABLE_SUPPORT_PTRDIFF_T -#define PRINTF_SUPPORT_PTRDIFF_T -#endif - -/////////////////////////////////////////////////////////////////////////////// - -// internal flag definitions -#define FLAGS_ZEROPAD (1U << 0U) -#define FLAGS_LEFT (1U << 1U) -#define FLAGS_PLUS (1U << 2U) -#define FLAGS_SPACE (1U << 3U) -#define FLAGS_HASH (1U << 4U) -#define FLAGS_UPPERCASE (1U << 5U) -#define FLAGS_CHAR (1U << 6U) -#define FLAGS_SHORT (1U << 7U) -#define FLAGS_LONG (1U << 8U) -#define FLAGS_LONG_LONG (1U << 9U) -#define FLAGS_PRECISION (1U << 10U) -#define FLAGS_ADAPT_EXP (1U << 11U) - - -// import float.h for DBL_MAX -#if defined(PRINTF_SUPPORT_FLOAT) -#include -#endif - - -// output function type -typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen); - - -// wrapper (used as buffer) for output function type -typedef struct { - void (*fct)(char character, void* arg); - void* arg; -} out_fct_wrap_type; - - -// internal buffer output -static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen) -{ - if (idx < maxlen) { - ((char*)buffer)[idx] = character; - } -} - - -// internal null output -static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen) -{ - (void)character; (void)buffer; (void)idx; (void)maxlen; -} - - -// internal _putchar wrapper -static inline void _out_char(char character, void* buffer, size_t idx, size_t maxlen) -{ - (void)buffer; (void)idx; (void)maxlen; - if (character) { - _putchar(character); - } -} - - -// internal output function wrapper -static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen) -{ - (void)idx; (void)maxlen; - if (character) { - // buffer is the output fct pointer - ((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg); - } -} - - -// internal secure strlen -// \return The length of the string (excluding the terminating 0) limited by 'maxsize' -static inline unsigned int _strnlen_s(const char* str, size_t maxsize) -{ - const char* s; - for (s = str; *s && maxsize--; ++s); - return (unsigned int)(s - str); -} - - -// internal test if char is a digit (0-9) -// \return true if char is a digit -static inline bool _is_digit(char ch) -{ - return (ch >= '0') && (ch <= '9'); -} - - -// internal ASCII string to unsigned int conversion -static unsigned int _atoi(const char** str) -{ - unsigned int i = 0U; - while (_is_digit(**str)) { - i = i * 10U + (unsigned int)(*((*str)++) - '0'); - } - return i; -} - - -// output the specified string in reverse, taking care of any zero-padding -static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen, const char* buf, size_t len, unsigned int width, unsigned int flags) -{ - const size_t start_idx = idx; - - // pad spaces up to given width - if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { - for (size_t i = len; i < width; i++) { - out(' ', buffer, idx++, maxlen); - } - } - - // reverse string - while (len) { - out(buf[--len], buffer, idx++, maxlen); - } - - // append pad spaces up to given width - if (flags & FLAGS_LEFT) { - while (idx - start_idx < width) { - out(' ', buffer, idx++, maxlen); - } - } - - return idx; -} - - -// internal itoa format -static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char* buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) -{ - // pad leading zeros - if (!(flags & FLAGS_LEFT)) { - if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { - width--; - } - while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } - while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } - } - - // handle hash - if (flags & FLAGS_HASH) { - if (!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) { - len--; - if (len && (base == 16U)) { - len--; - } - } - if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = 'x'; - } - else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = 'X'; - } - else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = 'b'; - } - if (len < PRINTF_NTOA_BUFFER_SIZE) { - buf[len++] = '0'; - } - } - - if (len < PRINTF_NTOA_BUFFER_SIZE) { - if (negative) { - buf[len++] = '-'; - } - else if (flags & FLAGS_PLUS) { - buf[len++] = '+'; // ignore the space if the '+' exists - } - else if (flags & FLAGS_SPACE) { - buf[len++] = ' '; - } - } - - return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags); -} - - -// internal itoa for 'long' type -static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) -{ - char buf[PRINTF_NTOA_BUFFER_SIZE]; - size_t len = 0U; - - // no hash for 0 values - if (!value) { - flags &= ~FLAGS_HASH; - } - - // write if precision != 0 and value is != 0 - if (!(flags & FLAGS_PRECISION) || value) { - do { - const char digit = (char)(value % base); - buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; - value /= base; - } while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); - } - - return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); -} - - -// internal itoa for 'long long' type -#if defined(PRINTF_SUPPORT_LONG_LONG) -static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) -{ - char buf[PRINTF_NTOA_BUFFER_SIZE]; - size_t len = 0U; - - // no hash for 0 values - if (!value) { - flags &= ~FLAGS_HASH; - } - - // write if precision != 0 and value is != 0 - if (!(flags & FLAGS_PRECISION) || value) { - do { - const char digit = (char)(value % base); - buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; - value /= base; - } while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); - } - - return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); -} -#endif // PRINTF_SUPPORT_LONG_LONG - - -#if defined(PRINTF_SUPPORT_FLOAT) - -#if defined(PRINTF_SUPPORT_EXPONENTIAL) -// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT -static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags); -#endif - - -// internal ftoa for fixed decimal floating point -static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) -{ - char buf[PRINTF_FTOA_BUFFER_SIZE]; - size_t len = 0U; - double diff = 0.0; - - // powers of 10 - static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; - - // test for special values - if (value != value) - return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags); - if (value < -DBL_MAX) - return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags); - if (value > DBL_MAX) - return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width, flags); - - // test for very large values - // standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad - if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) { -#if defined(PRINTF_SUPPORT_EXPONENTIAL) - return _etoa(out, buffer, idx, maxlen, value, prec, width, flags); -#else - return 0U; -#endif - } - - // test for negative - bool negative = false; - if (value < 0) { - negative = true; - value = 0 - value; - } - - // set default precision, if not set explicitly - if (!(flags & FLAGS_PRECISION)) { - prec = PRINTF_DEFAULT_FLOAT_PRECISION; - } - // limit precision to 9, cause a prec >= 10 can lead to overflow errors - while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) { - buf[len++] = '0'; - prec--; - } - - int whole = (int)value; - double tmp = (value - whole) * pow10[prec]; - unsigned long frac = (unsigned long)tmp; - diff = tmp - frac; - - if (diff > 0.5) { - ++frac; - // handle rollover, e.g. case 0.99 with prec 1 is 1.0 - if (frac >= pow10[prec]) { - frac = 0; - ++whole; - } - } - else if (diff < 0.5) { - } - else if ((frac == 0U) || (frac & 1U)) { - // if halfway, round up if odd OR if last digit is 0 - ++frac; - } - - if (prec == 0U) { - diff = value - (double)whole; - if ((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) { - // exactly 0.5 and ODD, then round up - // 1.5 -> 2, but 2.5 -> 2 - ++whole; - } - } - else { - unsigned int count = prec; - // now do fractional part, as an unsigned number - while (len < PRINTF_FTOA_BUFFER_SIZE) { - --count; - buf[len++] = (char)(48U + (frac % 10U)); - if (!(frac /= 10U)) { - break; - } - } - // add extra 0s - while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) { - buf[len++] = '0'; - } - if (len < PRINTF_FTOA_BUFFER_SIZE) { - // add decimal - buf[len++] = '.'; - } - } - - // do whole part, number is reversed - while (len < PRINTF_FTOA_BUFFER_SIZE) { - buf[len++] = (char)(48 + (whole % 10)); - if (!(whole /= 10)) { - break; - } - } - - // pad leading zeros - if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) { - if (width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { - width--; - } - while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } - } - - if (len < PRINTF_FTOA_BUFFER_SIZE) { - if (negative) { - buf[len++] = '-'; - } - else if (flags & FLAGS_PLUS) { - buf[len++] = '+'; // ignore the space if the '+' exists - } - else if (flags & FLAGS_SPACE) { - buf[len++] = ' '; - } - } - - return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags); -} - - -#if defined(PRINTF_SUPPORT_EXPONENTIAL) -// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse -static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) -{ - // check for NaN and special values - if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) { - return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags); - } - - // determine the sign - const bool negative = value < 0; - if (negative) { - value = -value; - } - - // default precision - if (!(flags & FLAGS_PRECISION)) { - prec = PRINTF_DEFAULT_FLOAT_PRECISION; - } - - // determine the decimal exponent - // based on the algorithm by David Gay (https://www.ampl.com/netlib/fp/dtoa.c) - union { - uint64_t U; - double F; - } conv; - - conv.F = value; - int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023; // effectively log2 - conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U); // drop the exponent so conv.F is now in [1,2) - // now approximate log10 from the log2 integer part and an expansion of ln around 1.5 - int expval = (int)(0.1760912590558 + exp2 * 0.301029995663981 + (conv.F - 1.5) * 0.289529654602168); - // now we want to compute 10^expval but we want to be sure it won't overflow - exp2 = (int)(expval * 3.321928094887362 + 0.5); - const double z = expval * 2.302585092994046 - exp2 * 0.6931471805599453; - const double z2 = z * z; - conv.U = (uint64_t)(exp2 + 1023) << 52U; - // compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex - conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14))))); - // correct for rounding errors - if (value < conv.F) { - expval--; - conv.F /= 10; - } - - // the exponent format is "%+03d" and largest value is "307", so set aside 4-5 characters - unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U; - - // in "%g" mode, "prec" is the number of *significant figures* not decimals - if (flags & FLAGS_ADAPT_EXP) { - // do we want to fall-back to "%f" mode? - if ((value >= 1e-4) && (value < 1e6)) { - if ((int)prec > expval) { - prec = (unsigned)((int)prec - expval - 1); - } - else { - prec = 0; - } - flags |= FLAGS_PRECISION; // make sure _ftoa respects precision - // no characters in exponent - minwidth = 0U; - expval = 0; - } - else { - // we use one sigfig for the whole part - if ((prec > 0) && (flags & FLAGS_PRECISION)) { - --prec; - } - } - } - - // will everything fit? - unsigned int fwidth = width; - if (width > minwidth) { - // we didn't fall-back so subtract the characters required for the exponent - fwidth -= minwidth; - } else { - // not enough characters, so go back to default sizing - fwidth = 0U; - } - if ((flags & FLAGS_LEFT) && minwidth) { - // if we're padding on the right, DON'T pad the floating part - fwidth = 0U; - } - - // rescale the float value - if (expval) { - value /= conv.F; - } - - // output the floating part - const size_t start_idx = idx; - idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FLAGS_ADAPT_EXP); - - // output the exponent part - if (minwidth) { - // output the exponential symbol - out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); - // output the exponent value - idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS); - // might need to right-pad spaces - if (flags & FLAGS_LEFT) { - while (idx - start_idx < width) out(' ', buffer, idx++, maxlen); - } - } - return idx; -} -#endif // PRINTF_SUPPORT_EXPONENTIAL -#endif // PRINTF_SUPPORT_FLOAT - - -// internal vsnprintf -static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va) -{ - unsigned int flags, width, precision, n; - size_t idx = 0U; - - if (!buffer) { - // use null output function - out = _out_null; - } - - while (*format) - { - // format specifier? %[flags][width][.precision][length] - if (*format != '%') { - // no - out(*format, buffer, idx++, maxlen); - format++; - continue; - } - else { - // yes, evaluate it - format++; - } - - // evaluate flags - flags = 0U; - do { - switch (*format) { - case '0': flags |= FLAGS_ZEROPAD; format++; n = 1U; break; - case '-': flags |= FLAGS_LEFT; format++; n = 1U; break; - case '+': flags |= FLAGS_PLUS; format++; n = 1U; break; - case ' ': flags |= FLAGS_SPACE; format++; n = 1U; break; - case '#': flags |= FLAGS_HASH; format++; n = 1U; break; - default : n = 0U; break; - } - } while (n); - - // evaluate width field - width = 0U; - if (_is_digit(*format)) { - width = _atoi(&format); - } - else if (*format == '*') { - const int w = va_arg(va, int); - if (w < 0) { - flags |= FLAGS_LEFT; // reverse padding - width = (unsigned int)-w; - } - else { - width = (unsigned int)w; - } - format++; - } - - // evaluate precision field - precision = 0U; - if (*format == '.') { - flags |= FLAGS_PRECISION; - format++; - if (_is_digit(*format)) { - precision = _atoi(&format); - } - else if (*format == '*') { - const int prec = (int)va_arg(va, int); - precision = prec > 0 ? (unsigned int)prec : 0U; - format++; - } - } - - // evaluate length field - switch (*format) { - case 'l' : - flags |= FLAGS_LONG; - format++; - if (*format == 'l') { - flags |= FLAGS_LONG_LONG; - format++; - } - break; - case 'h' : - flags |= FLAGS_SHORT; - format++; - if (*format == 'h') { - flags |= FLAGS_CHAR; - format++; - } - break; -#if defined(PRINTF_SUPPORT_PTRDIFF_T) - case 't' : - flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; - break; -#endif - case 'j' : - flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; - break; - case 'z' : - flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; - break; - default : - break; - } - - // evaluate specifier - switch (*format) { - case 'd' : - case 'i' : - case 'u' : - case 'x' : - case 'X' : - case 'o' : - case 'b' : { - // set the base - unsigned int base; - if (*format == 'x' || *format == 'X') { - base = 16U; - } - else if (*format == 'o') { - base = 8U; - } - else if (*format == 'b') { - base = 2U; - } - else { - base = 10U; - flags &= ~FLAGS_HASH; // no hash for dec format - } - // uppercase - if (*format == 'X') { - flags |= FLAGS_UPPERCASE; - } - - // no plus or space flag for u, x, X, o, b - if ((*format != 'i') && (*format != 'd')) { - flags &= ~(FLAGS_PLUS | FLAGS_SPACE); - } - - // ignore '0' flag when precision is given - if (flags & FLAGS_PRECISION) { - flags &= ~FLAGS_ZEROPAD; - } - - // convert the integer - if ((*format == 'i') || (*format == 'd')) { - // signed - if (flags & FLAGS_LONG_LONG) { -#if defined(PRINTF_SUPPORT_LONG_LONG) - const long long value = va_arg(va, long long); - idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); -#endif - } - else if (flags & FLAGS_LONG) { - const long value = va_arg(va, long); - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); - } - else { - const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int); - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); - } - } - else { - // unsigned - if (flags & FLAGS_LONG_LONG) { -#if defined(PRINTF_SUPPORT_LONG_LONG) - idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); -#endif - } - else if (flags & FLAGS_LONG) { - idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); - } - else { - const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int); - idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags); - } - } - format++; - break; - } -#if defined(PRINTF_SUPPORT_FLOAT) - case 'f' : - case 'F' : - if (*format == 'F') flags |= FLAGS_UPPERCASE; - idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); - format++; - break; -#if defined(PRINTF_SUPPORT_EXPONENTIAL) - case 'e': - case 'E': - case 'g': - case 'G': - if ((*format == 'g')||(*format == 'G')) flags |= FLAGS_ADAPT_EXP; - if ((*format == 'E')||(*format == 'G')) flags |= FLAGS_UPPERCASE; - idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); - format++; - break; -#endif // PRINTF_SUPPORT_EXPONENTIAL -#endif // PRINTF_SUPPORT_FLOAT - case 'c' : { - unsigned int l = 1U; - // pre padding - if (!(flags & FLAGS_LEFT)) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - // char output - out((char)va_arg(va, int), buffer, idx++, maxlen); - // post padding - if (flags & FLAGS_LEFT) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - format++; - break; - } - - case 's' : { - const char* p = va_arg(va, char*); - unsigned int l = _strnlen_s(p, precision ? precision : (size_t)-1); - // pre padding - if (flags & FLAGS_PRECISION) { - l = (l < precision ? l : precision); - } - if (!(flags & FLAGS_LEFT)) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - // string output - while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { - out(*(p++), buffer, idx++, maxlen); - } - // post padding - if (flags & FLAGS_LEFT) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - format++; - break; - } - - case 'p' : { - width = sizeof(void*) * 2U; - flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE; -#if defined(PRINTF_SUPPORT_LONG_LONG) - const bool is_ll = sizeof(uintptr_t) == sizeof(long long); - if (is_ll) { - idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags); - } - else { -#endif - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags); -#if defined(PRINTF_SUPPORT_LONG_LONG) - } -#endif - format++; - break; - } - - case '%' : - out('%', buffer, idx++, maxlen); - format++; - break; - - default : - out(*format, buffer, idx++, maxlen); - format++; - break; - } - } - - // termination - out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen); - - // return written chars without terminating \0 - return (int)idx; -} - - -/////////////////////////////////////////////////////////////////////////////// - -int printf_(const char* format, ...) -{ - va_list va; - va_start(va, format); - char buffer[1]; - const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va); - va_end(va); - return ret; -} - - -int sprintf_(char* buffer, const char* format, ...) -{ - va_list va; - va_start(va, format); - const int ret = _vsnprintf(_out_buffer, buffer, (size_t)-1, format, va); - va_end(va); - return ret; -} - - -int snprintf_(char* buffer, size_t count, const char* format, ...) -{ - va_list va; - va_start(va, format); - const int ret = _vsnprintf(_out_buffer, buffer, count, format, va); - va_end(va); - return ret; -} - - -int vprintf_(const char* format, va_list va) -{ - char buffer[1]; - return _vsnprintf(_out_char, buffer, (size_t)-1, format, va); -} - - -int vsnprintf_(char* buffer, size_t count, const char* format, va_list va) -{ - return _vsnprintf(_out_buffer, buffer, count, format, va); -} - - -int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...) -{ - va_list va; - va_start(va, format); - const out_fct_wrap_type out_fct_wrap = { out, arg }; - const int ret = _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va); - va_end(va); - return ret; -} diff --git a/lib/printf.h b/lib/printf.h deleted file mode 100644 index 8aa23cf..0000000 --- a/lib/printf.h +++ /dev/null @@ -1,129 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// \author (c) Marco Paland (info@paland.com) -// 2014-2019, PALANDesign Hannover, Germany -// -// \license The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on -// embedded systems with a very limited resources. -// Use this instead of bloated standard/newlib printf. -// These routines are thread safe and reentrant. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _PRINTF_H_ -#define _PRINTF_H_ - -#include - -/* LumeOS: avoid stddef.h — define types from compiler builtins directly. - * This works in both C and C++ and matches our types.h definition. */ -#ifndef _SIZE_T_DEFINED -#define _SIZE_T_DEFINED -typedef __SIZE_TYPE__ size_t; -typedef __PTRDIFF_TYPE__ ptrdiff_t; -typedef __INTMAX_TYPE__ intmax_t; -#endif - -/* LumeOS: kernel does not need floating-point formatted output */ -#define PRINTF_DISABLE_SUPPORT_FLOAT -#define PRINTF_DISABLE_SUPPORT_EXPONENTIAL - - -#ifdef __cplusplus -extern "C" { -#endif - - -/** - * Output a character to a custom device like UART, used by the printf() function - * This function is declared here only. You have to write your custom implementation somewhere - * \param character Character to output - */ -void _putchar(char character); - - -/** - * Tiny printf implementation - * You have to implement _putchar if you use printf() - * To avoid conflicts with the regular printf() API it is overridden by macro defines - * and internal underscore-appended functions like printf_() are used - * \param format A string that specifies the format of the output - * \return The number of characters that are written into the array, not counting the terminating null character - */ -#define printf printf_ -int printf_(const char* format, ...); - - -/** - * Tiny sprintf implementation - * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! - * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! - * \param format A string that specifies the format of the output - * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character - */ -#define sprintf sprintf_ -int sprintf_(char* buffer, const char* format, ...); - - -/** - * Tiny snprintf/vsnprintf implementation - * \param buffer A pointer to the buffer where to store the formatted string - * \param count The maximum number of characters to store in the buffer, including a terminating null character - * \param format A string that specifies the format of the output - * \param va A value identifying a variable arguments list - * \return The number of characters that COULD have been written into the buffer, not counting the terminating - * null character. A value equal or larger than count indicates truncation. Only when the returned value - * is non-negative and less than count, the string has been completely written. - */ -#define snprintf snprintf_ -#define vsnprintf vsnprintf_ -int snprintf_(char* buffer, size_t count, const char* format, ...); -int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); - - -/** - * Tiny vprintf implementation - * \param format A string that specifies the format of the output - * \param va A value identifying a variable arguments list - * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character - */ -#define vprintf vprintf_ -int vprintf_(const char* format, va_list va); - - -/** - * printf with output function - * You may use this as dynamic alternative to printf() with its fixed _putchar() output - * \param out An output function which takes one character and an argument pointer - * \param arg An argument pointer for user data passed to output function - * \param format A string that specifies the format of the output - * \return The number of characters that are sent to the output function, not counting the terminating null character - */ -int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); - - -#ifdef __cplusplus -} -#endif - - -#endif // _PRINTF_H_ diff --git a/lib/random.cc b/lib/random.cc deleted file mode 100644 index 428c75c..0000000 --- a/lib/random.cc +++ /dev/null @@ -1,152 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include -#include - -#include - -/* - * Early Boot PRNG (xoshiro256**) - * State size: 256 bits (4 * 64-bit words) - * Extremely fast, excellent statistical properties. - */ - -static uint64 g_state[4]; -static bool g_initialized = false; -static uint64 g_init_seed = 0; -static RandomSeedSource g_seed_source = RandomSeedSource::Unknown; - -static inline uint64 rotl(const uint64 x, int k) { - return (x << k) | (x >> (64 - k)); -} - -/* SplitMix64 used to initialize xoshiro state from a single 64-bit seed */ -static uint64 splitmix64(uint64& state) { - uint64 z = (state += 0x9e3779b97f4a7c15ULL); - z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL; - z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL; - return z ^ (z >> 31); -} - -void random_early_init(uint64 seed) -{ - if (g_initialized) return; - - RandomSeedSource source = RandomSeedSource::Unknown; - - /* If seed is 0 (not provided by bootloader), try hardware */ - if (seed == 0) { - uint64 hw_val; - if (arch::get_hw_random(hw_val)) { - seed = hw_val; - source = RandomSeedSource::HwRandom; - } else { - /* Fallback: use boot cycles mixed with a constant */ - seed = arch::get_cycles() ^ 0xdeadbeefbadc0ffeULL; - source = RandomSeedSource::CycleFallback; - } - } else { - source = RandomSeedSource::FdtProvided; - } - - uint64 sm_state = seed; - g_state[0] = splitmix64(sm_state); - g_state[1] = splitmix64(sm_state); - g_state[2] = splitmix64(sm_state); - g_state[3] = splitmix64(sm_state); - - g_init_seed = seed; - g_seed_source = source; - g_initialized = true; - kprintf("[random] early PRNG initialized, seed=0x%llx, source=%s\n", - seed, random_seed_source_name(source)); -} - -uint64 get_random_u64() -{ - if (!g_initialized) { - random_early_init(0); - } - - const uint64 result = rotl(g_state[1] * 5, 7) * 9; - - const uint64 t = g_state[1] << 17; - - g_state[2] ^= g_state[0]; - g_state[3] ^= g_state[1]; - g_state[1] ^= g_state[2]; - g_state[0] ^= g_state[3]; - - g_state[2] ^= t; - g_state[3] = rotl(g_state[3], 45); - - /* Mix with current cycles for slight additional unpredictability */ - return result ^ arch::get_cycles(); -} - -uint32 get_random_u32() -{ - return static_cast(get_random_u64() >> 32); -} - -void get_random_bytes(void* buf, size_t len) -{ - uint8* p = static_cast(buf); - while (len >= 8) { - uint64 val = get_random_u64(); - for (int i = 0; i < 8; i++) { - p[i] = (val >> (i * 8)) & 0xFF; - } - p += 8; - len -= 8; - } - if (len > 0) { - uint64 val = get_random_u64(); - for (size_t i = 0; i < len; i++) { - p[i] = (val >> (i * 8)) & 0xFF; - } - } -} - -void add_device_randomness(const void* buf, size_t len) -{ - /* - * For now, just mix into the xoshiro state using a simple XOR. - * In the future, this will feed the CSPRNG entropy pool. - */ - const uint8* p = static_cast(buf); - uint64 mix = arch::get_cycles(); - for (size_t i = 0; i < len; i++) { - mix = (mix << 5) ^ (mix >> 59) ^ p[i]; - } - - g_state[0] ^= mix; - g_state[1] ^= arch::get_cycles(); -} - -RandomSeedSource random_early_seed_source() -{ - return g_seed_source; -} - -uint64 random_early_seed_value() -{ - return g_init_seed; -} - -const char* random_seed_source_name(RandomSeedSource source) -{ - switch (source) { - case RandomSeedSource::FdtProvided: - return "fdt"; - case RandomSeedSource::HwRandom: - return "hw"; - case RandomSeedSource::CycleFallback: - return "cycle"; - case RandomSeedSource::Unknown: - default: - return "unknown"; - } -} diff --git a/lib/rbtree.cc b/lib/rbtree.cc deleted file mode 100644 index 6718a1a..0000000 --- a/lib/rbtree.cc +++ /dev/null @@ -1,596 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - Red Black Trees - (C) 1999 Andrea Arcangeli - (C) 2002 David Woodhouse - (C) 2012 Michel Lespinasse - - - linux/lib/rbtree.c -*/ - -#include - - -/* - * red-black trees properties: https://en.wikipedia.org/wiki/Rbtree - * - * 1) A node is either red or black - * 2) The root is black - * 3) All leaves (nullptr) are black - * 4) Both children of every red node are black - * 5) Every simple path from root to leaves contains the same number - * of black nodes. - * - * 4 and 5 give the O(log n) guarantee, since 4 implies you cannot have two - * consecutive red nodes in a path and every red node is therefore followed by - * a black. So if B is the number of black nodes on every simple path (as per - * 5), then the longest possible path due to 4 is 2B. - * - * We shall indicate color with case, where black nodes are uppercase and red - * nodes will be lowercase. Unknown color nodes shall be drawn as red within - * parentheses and have some accompanying text comment. - */ - -/* - * Notes on lockless lookups: - * - * All stores to the tree structure (rb_left and rb_right) must be done using - * WRITE_ONCE(). And we must not inadvertently cause (temporary) loops in the - * tree structure as seen in program order. - * - * These two requirements will allow lockless iteration of the tree -- not - * correct iteration mind you, tree rotations are not atomic so a lookup might - * miss entire subtrees. - * - * But they do guarantee that any such traversal will only see valid elements - * and that it will indeed complete -- does not get stuck in a loop. - * - * It also guarantees that if the lookup returns an element it is the 'correct' - * one. But not returning an element does _NOT_ mean it's not present. - * - * NOTE: - * - * Stores to __rb_parent_color are not important for simple lookups so those - * are left undone as of now. Nor did I check for loops involving parent - * pointers. - */ - -static inline void rb_set_black(struct rb_node *rb) -{ - rb->__rb_parent_color += RB_BLACK; -} - -static inline struct rb_node *rb_red_parent(struct rb_node *red) -{ - return (struct rb_node *)red->__rb_parent_color; -} - -/* - * Helper function for rotations: - * - old's parent and color get assigned to _new - * - old gets assigned _new as a parent and 'color' as a color. - */ -static inline void -__rb_rotate_set_parents(struct rb_node *old, struct rb_node *_new, - struct rb_root *root, int color) -{ - struct rb_node *parent = rb_parent(old); - _new->__rb_parent_color = old->__rb_parent_color; - rb_set_parent_color(old, _new, color); - __rb_change_child(old, _new, parent, root); -} - -static __always_inline void -__rb_insert(struct rb_node *node, struct rb_root *root, - void (*augment_rotate)(struct rb_node *old, struct rb_node *_new)) -{ - struct rb_node *parent = rb_red_parent(node), *gparent, *tmp; - - while (true) { - /* - * Loop invariant: node is red. - */ - if (unlikely(!parent)) { - /* - * The inserted node is root. Either this is the - * first node, or we recursed at Case 1 below and - * are no longer violating 4). - */ - rb_set_parent_color(node, nullptr, RB_BLACK); - break; - } - - /* - * If there is a black parent, we are done. - * Otherwise, take some corrective action as, - * per 4), we don't want a red root or two - * consecutive red nodes. - */ - if(rb_is_black(parent)) - break; - - gparent = rb_red_parent(parent); - - tmp = gparent->rb_right; - if (parent != tmp) { /* parent == gparent->rb_left */ - if (tmp && rb_is_red(tmp)) { - /* - * Case 1 - node's uncle is red (color flips). - * - * G g - * / \ / \ - * p u --> P U - * / / - * n n - * - * However, since g's parent might be red, and - * 4) does not allow this, we need to recurse - * at g. - */ - rb_set_parent_color(tmp, gparent, RB_BLACK); - rb_set_parent_color(parent, gparent, RB_BLACK); - node = gparent; - parent = rb_parent(node); - rb_set_parent_color(node, parent, RB_RED); - continue; - } - - tmp = parent->rb_right; - if (node == tmp) { - /* - * Case 2 - node's uncle is black and node is - * the parent's right child (left rotate at parent). - * - * G G - * / \ / \ - * p U --> n U - * \ / - * n p - * - * This still leaves us in violation of 4), the - * continuation into Case 3 will fix that. - */ - tmp = node->rb_left; - WRITE_ONCE(parent->rb_right, tmp); - WRITE_ONCE(node->rb_left, parent); - if (tmp) - rb_set_parent_color(tmp, parent, - RB_BLACK); - rb_set_parent_color(parent, node, RB_RED); - augment_rotate(parent, node); - parent = node; - tmp = node->rb_right; - } - - /* - * Case 3 - node's uncle is black and node is - * the parent's left child (right rotate at gparent). - * - * G P - * / \ / \ - * p U --> n g - * / \ - * n U - */ - WRITE_ONCE(gparent->rb_left, tmp); /* == parent->rb_right */ - WRITE_ONCE(parent->rb_right, gparent); - if (tmp) - rb_set_parent_color(tmp, gparent, RB_BLACK); - __rb_rotate_set_parents(gparent, parent, root, RB_RED); - augment_rotate(gparent, parent); - break; - } else { - tmp = gparent->rb_left; - if (tmp && rb_is_red(tmp)) { - /* Case 1 - color flips */ - rb_set_parent_color(tmp, gparent, RB_BLACK); - rb_set_parent_color(parent, gparent, RB_BLACK); - node = gparent; - parent = rb_parent(node); - rb_set_parent_color(node, parent, RB_RED); - continue; - } - - tmp = parent->rb_left; - if (node == tmp) { - /* Case 2 - right rotate at parent */ - tmp = node->rb_right; - WRITE_ONCE(parent->rb_left, tmp); - WRITE_ONCE(node->rb_right, parent); - if (tmp) - rb_set_parent_color(tmp, parent, - RB_BLACK); - rb_set_parent_color(parent, node, RB_RED); - augment_rotate(parent, node); - parent = node; - tmp = node->rb_left; - } - - /* Case 3 - left rotate at gparent */ - WRITE_ONCE(gparent->rb_right, tmp); /* == parent->rb_left */ - WRITE_ONCE(parent->rb_left, gparent); - if (tmp) - rb_set_parent_color(tmp, gparent, RB_BLACK); - __rb_rotate_set_parents(gparent, parent, root, RB_RED); - augment_rotate(gparent, parent); - break; - } - } -} - -/* - * Inline version for rb_erase() use - we want to be able to inline - * and eliminate the dummy_rotate callback there - */ -static __always_inline void -____rb_erase_color(struct rb_node *parent, struct rb_root *root, - void (*augment_rotate)(struct rb_node *old, struct rb_node *_new)) -{ - struct rb_node *node = nullptr, *sibling, *tmp1, *tmp2; - - while (true) { - /* - * Loop invariants: - * - node is black (or nullptr on first iteration) - * - node is not the root (parent is not nullptr) - * - All leaf paths going through parent and node have a - * black node count that is 1 lower than other leaf paths. - */ - sibling = parent->rb_right; - if (node != sibling) { /* node == parent->rb_left */ - if (rb_is_red(sibling)) { - /* - * Case 1 - left rotate at parent - * - * P S - * / \ / \ - * N s --> p Sr - * / \ / \ - * Sl Sr N Sl - */ - tmp1 = sibling->rb_left; - WRITE_ONCE(parent->rb_right, tmp1); - WRITE_ONCE(sibling->rb_left, parent); - rb_set_parent_color(tmp1, parent, RB_BLACK); - __rb_rotate_set_parents(parent, sibling, root, - RB_RED); - augment_rotate(parent, sibling); - sibling = tmp1; - } - tmp1 = sibling->rb_right; - if (!tmp1 || rb_is_black(tmp1)) { - tmp2 = sibling->rb_left; - if (!tmp2 || rb_is_black(tmp2)) { - /* - * Case 2 - sibling color flip - * (p could be either color here) - * - * (p) (p) - * / \ / \ - * N S --> N s - * / \ / \ - * Sl Sr Sl Sr - * - * This leaves us violating 5) which - * can be fixed by flipping p to black - * if it was red, or by recursing at p. - * p is red when coming from Case 1. - */ - rb_set_parent_color(sibling, parent, - RB_RED); - if (rb_is_red(parent)) - rb_set_black(parent); - else { - node = parent; - parent = rb_parent(node); - if (parent) - continue; - } - break; - } - /* - * Case 3 - right rotate at sibling - * (p could be either color here) - * - * (p) (p) - * / \ / \ - * N S --> N sl - * / \ \ - * sl Sr S - * \ - * Sr - * - * Note: p might be red, and then both - * p and sl are red after rotation(which - * breaks property 4). This is fixed in - * Case 4 (in __rb_rotate_set_parents() - * which set sl the color of p - * and set p RB_BLACK) - * - * (p) (sl) - * / \ / \ - * N sl --> P S - * \ / \ - * S N Sr - * \ - * Sr - */ - tmp1 = tmp2->rb_right; - WRITE_ONCE(sibling->rb_left, tmp1); - WRITE_ONCE(tmp2->rb_right, sibling); - WRITE_ONCE(parent->rb_right, tmp2); - if (tmp1) - rb_set_parent_color(tmp1, sibling, - RB_BLACK); - augment_rotate(sibling, tmp2); - tmp1 = sibling; - sibling = tmp2; - } - /* - * Case 4 - left rotate at parent + color flips - * (p and sl could be either color here. - * After rotation, p becomes black, s acquires - * p's color, and sl keeps its color) - * - * (p) (s) - * / \ / \ - * N S --> P Sr - * / \ / \ - * (sl) sr N (sl) - */ - tmp2 = sibling->rb_left; - WRITE_ONCE(parent->rb_right, tmp2); - WRITE_ONCE(sibling->rb_left, parent); - rb_set_parent_color(tmp1, sibling, RB_BLACK); - if (tmp2) - rb_set_parent(tmp2, parent); - __rb_rotate_set_parents(parent, sibling, root, - RB_BLACK); - augment_rotate(parent, sibling); - break; - } else { - sibling = parent->rb_left; - if (rb_is_red(sibling)) { - /* Case 1 - right rotate at parent */ - tmp1 = sibling->rb_right; - WRITE_ONCE(parent->rb_left, tmp1); - WRITE_ONCE(sibling->rb_right, parent); - rb_set_parent_color(tmp1, parent, RB_BLACK); - __rb_rotate_set_parents(parent, sibling, root, - RB_RED); - augment_rotate(parent, sibling); - sibling = tmp1; - } - tmp1 = sibling->rb_left; - if (!tmp1 || rb_is_black(tmp1)) { - tmp2 = sibling->rb_right; - if (!tmp2 || rb_is_black(tmp2)) { - /* Case 2 - sibling color flip */ - rb_set_parent_color(sibling, parent, - RB_RED); - if (rb_is_red(parent)) - rb_set_black(parent); - else { - node = parent; - parent = rb_parent(node); - if (parent) - continue; - } - break; - } - /* Case 3 - left rotate at sibling */ - tmp1 = tmp2->rb_left; - WRITE_ONCE(sibling->rb_right, tmp1); - WRITE_ONCE(tmp2->rb_left, sibling); - WRITE_ONCE(parent->rb_left, tmp2); - if (tmp1) - rb_set_parent_color(tmp1, sibling, - RB_BLACK); - augment_rotate(sibling, tmp2); - tmp1 = sibling; - sibling = tmp2; - } - /* Case 4 - right rotate at parent + color flips */ - tmp2 = sibling->rb_right; - WRITE_ONCE(parent->rb_left, tmp2); - WRITE_ONCE(sibling->rb_right, parent); - rb_set_parent_color(tmp1, sibling, RB_BLACK); - if (tmp2) - rb_set_parent(tmp2, parent); - __rb_rotate_set_parents(parent, sibling, root, - RB_BLACK); - augment_rotate(parent, sibling); - break; - } - } -} - -/* Non-inline version for rb_erase_augmented() use */ -void __rb_erase_color(struct rb_node *parent, struct rb_root *root, - void (*augment_rotate)(struct rb_node *old, struct rb_node *_new)) -{ - ____rb_erase_color(parent, root, augment_rotate); -} - -/* - * Non-augmented rbtree manipulation functions. - * - * We use dummy augmented callbacks here, and have the compiler optimize them - * out of the rb_insert_color() and rb_erase() function definitions. - */ - -static inline void dummy_propagate(struct rb_node *node, struct rb_node *stop) {} -static inline void dummy_copy(struct rb_node *old, struct rb_node *_new) {} -static inline void dummy_rotate(struct rb_node *old, struct rb_node *_new) {} - -static const struct rb_augment_callbacks dummy_callbacks = { - .propagate = dummy_propagate, - .copy = dummy_copy, - .rotate = dummy_rotate -}; - -void rb_insert_color(struct rb_node *node, struct rb_root *root) -{ - __rb_insert(node, root, dummy_rotate); -} - -void rb_erase(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *rebalance; - rebalance = __rb_erase_augmented(node, root, &dummy_callbacks); - if (rebalance) - ____rb_erase_color(rebalance, root, dummy_rotate); -} - - -/* - * Augmented rbtree manipulation functions. - * - * This instantiates the same __always_inline functions as in the non-augmented - * case, but this time with user-defined callbacks. - */ - -void __rb_insert_augmented(struct rb_node *node, struct rb_root *root, - void (*augment_rotate)(struct rb_node *old, struct rb_node *_new)) -{ - __rb_insert(node, root, augment_rotate); -} - -struct rb_node *rb_next(const struct rb_node *node) -{ - struct rb_node *parent; - - if (RB_EMPTY_NODE(node)) - return nullptr; - - /* - * If we have a right-hand child, go down and then left as far - * as we can. - */ - if (node->rb_right) { - node = node->rb_right; - while (node->rb_left) - node = node->rb_left; - return (struct rb_node *)node; - } - - /* - * No right-hand children. Everything down and left is smaller than us, - * so any 'next' node must be in the general direction of our parent. - * Go up the tree; any time the ancestor is a right-hand child of its - * parent, keep going up. First time it's a left-hand child of its - * parent, said parent is our 'next' node. - */ - while ((parent = rb_parent(node)) && node == parent->rb_right) - node = parent; - - return parent; -} - -struct rb_node *rb_prev(const struct rb_node *node) -{ - struct rb_node *parent; - - if (RB_EMPTY_NODE(node)) - return nullptr; - - /* - * If we have a left-hand child, go down and then right as far - * as we can. - */ - if (node->rb_left) { - node = node->rb_left; - while (node->rb_right) - node = node->rb_right; - return (struct rb_node *)node; - } - - /* - * No left-hand children. Go up till we find an ancestor which - * is a right-hand child of its parent. - */ - while ((parent = rb_parent(node)) && node == parent->rb_left) - node = parent; - - return parent; -} - -void rb_replace_node(struct rb_node *victim, struct rb_node *_new, - struct rb_root *root) -{ - struct rb_node *parent = rb_parent(victim); - - /* Copy the pointers/colour from the victim to the replacement */ - *_new = *victim; - - /* Set the surrounding nodes to point to the replacement */ - if (victim->rb_left) - rb_set_parent(victim->rb_left, _new); - if (victim->rb_right) - rb_set_parent(victim->rb_right, _new); - __rb_change_child(victim, _new, parent, root); -} - - -static struct rb_node *rb_left_deepest_node(const struct rb_node *node) -{ - for (;;) { - if (node->rb_left) - node = node->rb_left; - else if (node->rb_right) - node = node->rb_right; - else - return (struct rb_node *)node; - } -} - -struct rb_node *rb_next_postorder(const struct rb_node *node) -{ - const struct rb_node *parent; - if (!node) - return nullptr; - parent = rb_parent(node); - - /* If we're sitting on node, we've already seen our children */ - if (parent && node == parent->rb_left && parent->rb_right) { - /* If we are the parent's left node, go to the parent's right - * node then all the way down to the left */ - return rb_left_deepest_node(parent->rb_right); - } else - /* Otherwise we are the parent's right node, and the parent - * should be next */ - return (struct rb_node *)parent; -} - -struct rb_node *rb_first_postorder(const struct rb_root *root) -{ - if (!root->rb_node) - return nullptr; - - return rb_left_deepest_node(root->rb_node); -} - -struct rb_node *rb_first(const struct rb_root *root) -{ - struct rb_node *n; - - n = root->rb_node; - if (!n) - return nullptr; - while (n->rb_left) - n = n->rb_left; - return n; -} - -struct rb_node *rb_last(const struct rb_root *root) -{ - struct rb_node *n; - - n = root->rb_node; - if (!n) - return nullptr; - while (n->rb_right) - n = n->rb_right; - return n; -} diff --git a/lib/string/COPYRIGHT b/lib/string/COPYRIGHT deleted file mode 100644 index 2f15edc..0000000 --- a/lib/string/COPYRIGHT +++ /dev/null @@ -1,193 +0,0 @@ -musl as a whole is licensed under the following standard MIT license: - ----------------------------------------------------------------------- -Copyright © 2005-2020 Rich Felker, et al. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ----------------------------------------------------------------------- - -Authors/contributors include: - -A. Wilcox -Ada Worcester -Alex Dowad -Alex Suykov -Alexander Monakov -Andre McCurdy -Andrew Kelley -Anthony G. Basile -Aric Belsito -Arvid Picciani -Bartosz Brachaczek -Benjamin Peterson -Bobby Bingham -Boris Brezillon -Brent Cook -Chris Spiegel -Clément Vasseur -Daniel Micay -Daniel Sabogal -Daurnimator -David Carlier -David Edelsohn -Denys Vlasenko -Dmitry Ivanov -Dmitry V. Levin -Drew DeVault -Emil Renner Berthing -Fangrui Song -Felix Fietkau -Felix Janda -Gianluca Anzolin -Hauke Mehrtens -He X -Hiltjo Posthuma -Isaac Dunham -Jaydeep Patil -Jens Gustedt -Jeremy Huntwork -Jo-Philipp Wich -Joakim Sindholt -John Spencer -Julien Ramseier -Justin Cormack -Kaarle Ritvanen -Khem Raj -Kylie McClain -Leah Neukirchen -Luca Barbato -Luka Perkov -Lynn Ochs -M Farkas-Dyck (Strake) -Mahesh Bodapati -Markus Wichmann -Masanori Ogino -Michael Clark -Michael Forney -Mikhail Kremnyov -Natanael Copa -Nicholas J. Kain -orc -Pascal Cuoq -Patrick Oppenlander -Petr Hosek -Petr Skocik -Pierre Carrier -Reini Urban -Rich Felker -Richard Pennington -Ryan Fairfax -Samuel Holland -Segev Finer -Shiz -sin -Solar Designer -Stefan Kristiansson -Stefan O'Rear -Szabolcs Nagy -Timo Teräs -Trutz Behn -Will Dietz -William Haddon -William Pitcock - -Portions of this software are derived from third-party works licensed -under terms compatible with the above MIT license: - -The TRE regular expression implementation (src/regex/reg* and -src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed -under a 2-clause BSD license (license text in the source files). The -included version has been heavily modified by Rich Felker in 2012, in -the interests of size, simplicity, and namespace cleanliness. - -Much of the math library code (src/math/* and src/complex/*) is -Copyright © 1993,2004 Sun Microsystems or -Copyright © 2003-2011 David Schultz or -Copyright © 2003-2009 Steven G. Kargl or -Copyright © 2003-2009 Bruce D. Evans or -Copyright © 2008 Stephen L. Moshier or -Copyright © 2017-2018 Arm Limited -and labelled as such in comments in the individual source files. All -have been licensed under extremely permissive terms. - -The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008 -The Android Open Source Project and is licensed under a two-clause BSD -license. It was taken from Bionic libc, used on Android. - -The AArch64 memcpy and memset code (src/string/aarch64/*) are -Copyright © 1999-2019, Arm Limited. - -The implementation of DES for crypt (src/crypt/crypt_des.c) is -Copyright © 1994 David Burren. It is licensed under a BSD license. - -The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was -originally written by Solar Designer and placed into the public -domain. The code also comes with a fallback permissive license for use -in jurisdictions that may not recognize the public domain. - -The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011 -Lynn Ochs and is licensed under an MIT-style license. - -The x86_64 port was written by Nicholas J. Kain and is licensed under -the standard MIT terms. - -The mips and microblaze ports were originally written by Richard -Pennington for use in the ellcc project. The original code was adapted -by Rich Felker for build system and code conventions during upstream -integration. It is licensed under the standard MIT terms. - -The mips64 port was contributed by Imagination Technologies and is -licensed under the standard MIT terms. - -The powerpc port was also originally written by Richard Pennington, -and later supplemented and integrated by John Spencer. It is licensed -under the standard MIT terms. - -All other files which have no copyright comments are original works -produced specifically for use as part of this library, written either -by Rich Felker, the main author of the library, or by one or more -contibutors listed above. Details on authorship of individual files -can be found in the git version control history of the project. The -omission of copyright and license comments in each file is in the -interest of source tree size. - -In addition, permission is hereby granted for all public header files -(include/* and arch/*/bits/*) and crt files intended to be linked into -applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit -the copyright notice and permission notice otherwise required by the -license, and to use these files without any requirement of -attribution. These files include substantial contributions from: - -Bobby Bingham -John Spencer -Nicholas J. Kain -Rich Felker -Richard Pennington -Stefan Kristiansson -Szabolcs Nagy - -all of whom have explicitly granted such permission. - -This file previously contained text expressing a belief that most of -the files covered by the above exception were sufficiently trivial not -to be subject to copyright, resulting in confusion over whether it -negated the permissions granted in the license. In the spirit of -permissive licensing, and of not having licensing issues being an -obstacle to adoption, that text has been removed. diff --git a/lib/string/aarch64/memcpy.S b/lib/string/aarch64/memcpy.S deleted file mode 100644 index 48bb8a8..0000000 --- a/lib/string/aarch64/memcpy.S +++ /dev/null @@ -1,186 +0,0 @@ -/* - * memcpy - copy memory area - * - * Copyright (c) 2012-2020, Arm Limited. - * SPDX-License-Identifier: MIT - */ - -/* Assumptions: - * - * ARMv8-a, AArch64, unaligned accesses. - * - */ - -#define dstin x0 -#define src x1 -#define count x2 -#define dst x3 -#define srcend x4 -#define dstend x5 -#define A_l x6 -#define A_lw w6 -#define A_h x7 -#define B_l x8 -#define B_lw w8 -#define B_h x9 -#define C_l x10 -#define C_lw w10 -#define C_h x11 -#define D_l x12 -#define D_h x13 -#define E_l x14 -#define E_h x15 -#define F_l x16 -#define F_h x17 -#define G_l count -#define G_h dst -#define H_l src -#define H_h srcend -#define tmp1 x14 - -/* This implementation of memcpy uses unaligned accesses and branchless - sequences to keep the code small, simple and improve performance. - - Copies are split into 3 main cases: small copies of up to 32 bytes, medium - copies of up to 128 bytes, and large copies. The overhead of the overlap - check is negligible since it is only required for large copies. - - Large copies use a software pipelined loop processing 64 bytes per iteration. - The destination pointer is 16-byte aligned to minimize unaligned accesses. - The loop tail is handled by always copying 64 bytes from the end. -*/ - -.global memcpy -.type memcpy,%function -memcpy: - add srcend, src, count - add dstend, dstin, count - cmp count, 128 - b.hi .Lcopy_long - cmp count, 32 - b.hi .Lcopy32_128 - - /* Small copies: 0..32 bytes. */ - cmp count, 16 - b.lo .Lcopy16 - ldp A_l, A_h, [src] - ldp D_l, D_h, [srcend, -16] - stp A_l, A_h, [dstin] - stp D_l, D_h, [dstend, -16] - ret - - /* Copy 8-15 bytes. */ -.Lcopy16: - tbz count, 3, .Lcopy8 - ldr A_l, [src] - ldr A_h, [srcend, -8] - str A_l, [dstin] - str A_h, [dstend, -8] - ret - - .p2align 3 - /* Copy 4-7 bytes. */ -.Lcopy8: - tbz count, 2, .Lcopy4 - ldr A_lw, [src] - ldr B_lw, [srcend, -4] - str A_lw, [dstin] - str B_lw, [dstend, -4] - ret - - /* Copy 0..3 bytes using a branchless sequence. */ -.Lcopy4: - cbz count, .Lcopy0 - lsr tmp1, count, 1 - ldrb A_lw, [src] - ldrb C_lw, [srcend, -1] - ldrb B_lw, [src, tmp1] - strb A_lw, [dstin] - strb B_lw, [dstin, tmp1] - strb C_lw, [dstend, -1] -.Lcopy0: - ret - - .p2align 4 - /* Medium copies: 33..128 bytes. */ -.Lcopy32_128: - ldp A_l, A_h, [src] - ldp B_l, B_h, [src, 16] - ldp C_l, C_h, [srcend, -32] - ldp D_l, D_h, [srcend, -16] - cmp count, 64 - b.hi .Lcopy128 - stp A_l, A_h, [dstin] - stp B_l, B_h, [dstin, 16] - stp C_l, C_h, [dstend, -32] - stp D_l, D_h, [dstend, -16] - ret - - .p2align 4 - /* Copy 65..128 bytes. */ -.Lcopy128: - ldp E_l, E_h, [src, 32] - ldp F_l, F_h, [src, 48] - cmp count, 96 - b.ls .Lcopy96 - ldp G_l, G_h, [srcend, -64] - ldp H_l, H_h, [srcend, -48] - stp G_l, G_h, [dstend, -64] - stp H_l, H_h, [dstend, -48] -.Lcopy96: - stp A_l, A_h, [dstin] - stp B_l, B_h, [dstin, 16] - stp E_l, E_h, [dstin, 32] - stp F_l, F_h, [dstin, 48] - stp C_l, C_h, [dstend, -32] - stp D_l, D_h, [dstend, -16] - ret - - .p2align 4 - /* Copy more than 128 bytes. */ -.Lcopy_long: - - /* Copy 16 bytes and then align dst to 16-byte alignment. */ - - ldp D_l, D_h, [src] - and tmp1, dstin, 15 - bic dst, dstin, 15 - sub src, src, tmp1 - add count, count, tmp1 /* Count is now 16 too large. */ - ldp A_l, A_h, [src, 16] - stp D_l, D_h, [dstin] - ldp B_l, B_h, [src, 32] - ldp C_l, C_h, [src, 48] - ldp D_l, D_h, [src, 64]! - subs count, count, 128 + 16 /* Test and readjust count. */ - b.ls .Lcopy64_from_end - -.Lloop64: - stp A_l, A_h, [dst, 16] - ldp A_l, A_h, [src, 16] - stp B_l, B_h, [dst, 32] - ldp B_l, B_h, [src, 32] - stp C_l, C_h, [dst, 48] - ldp C_l, C_h, [src, 48] - stp D_l, D_h, [dst, 64]! - ldp D_l, D_h, [src, 64]! - subs count, count, 64 - b.hi .Lloop64 - - /* Write the last iteration and copy 64 bytes from the end. */ -.Lcopy64_from_end: - ldp E_l, E_h, [srcend, -64] - stp A_l, A_h, [dst, 16] - ldp A_l, A_h, [srcend, -48] - stp B_l, B_h, [dst, 32] - ldp B_l, B_h, [srcend, -32] - stp C_l, C_h, [dst, 48] - ldp C_l, C_h, [srcend, -16] - stp D_l, D_h, [dst, 64] - stp E_l, E_h, [dstend, -64] - stp A_l, A_h, [dstend, -48] - stp B_l, B_h, [dstend, -32] - stp C_l, C_h, [dstend, -16] - ret - -.size memcpy,.-memcpy diff --git a/lib/string/aarch64/memset.S b/lib/string/aarch64/memset.S deleted file mode 100644 index f0d29b7..0000000 --- a/lib/string/aarch64/memset.S +++ /dev/null @@ -1,115 +0,0 @@ -/* - * memset - fill memory with a constant byte - * - * Copyright (c) 2012-2020, Arm Limited. - * SPDX-License-Identifier: MIT - */ - -/* Assumptions: - * - * ARMv8-a, AArch64, Advanced SIMD, unaligned accesses. - * - */ - -#define dstin x0 -#define val x1 -#define valw w1 -#define count x2 -#define dst x3 -#define dstend x4 -#define zva_val x5 - -.global memset -.type memset,%function -memset: - - dup v0.16B, valw - add dstend, dstin, count - - cmp count, 96 - b.hi .Lset_long - cmp count, 16 - b.hs .Lset_medium - mov val, v0.D[0] - - /* Set 0..15 bytes. */ - tbz count, 3, 1f - str val, [dstin] - str val, [dstend, -8] - ret - nop -1: tbz count, 2, 2f - str valw, [dstin] - str valw, [dstend, -4] - ret -2: cbz count, 3f - strb valw, [dstin] - tbz count, 1, 3f - strh valw, [dstend, -2] -3: ret - - /* Set 17..96 bytes. */ -.Lset_medium: - str q0, [dstin] - tbnz count, 6, .Lset96 - str q0, [dstend, -16] - tbz count, 5, 1f - str q0, [dstin, 16] - str q0, [dstend, -32] -1: ret - - .p2align 4 - /* Set 64..96 bytes. Write 64 bytes from the start and - 32 bytes from the end. */ -.Lset96: - str q0, [dstin, 16] - stp q0, q0, [dstin, 32] - stp q0, q0, [dstend, -32] - ret - - .p2align 4 -.Lset_long: - and valw, valw, 255 - bic dst, dstin, 15 - str q0, [dstin] - cmp count, 160 - ccmp valw, 0, 0, hs - b.ne .Lno_zva - -#ifndef SKIP_ZVA_CHECK - mrs zva_val, dczid_el0 - and zva_val, zva_val, 31 - cmp zva_val, 4 /* ZVA size is 64 bytes. */ - b.ne .Lno_zva -#endif - str q0, [dst, 16] - stp q0, q0, [dst, 32] - bic dst, dst, 63 - sub count, dstend, dst /* Count is now 64 too large. */ - sub count, count, 128 /* Adjust count and bias for loop. */ - - .p2align 4 -.Lzva_loop: - add dst, dst, 64 - dc zva, dst - subs count, count, 64 - b.hi .Lzva_loop - stp q0, q0, [dstend, -64] - stp q0, q0, [dstend, -32] - ret - -.Lno_zva: - sub count, dstend, dst /* Count is 16 too large. */ - sub dst, dst, 16 /* Dst is biased by -32. */ - sub count, count, 64 + 16 /* Adjust count and bias for loop. */ -.Lno_zva_loop: - stp q0, q0, [dst, 32] - stp q0, q0, [dst, 64]! - subs count, count, 64 - b.hi .Lno_zva_loop - stp q0, q0, [dstend, -64] - stp q0, q0, [dstend, -32] - ret - -.size memset,.-memset - diff --git a/lib/string/arm/__aeabi_memcpy.s b/lib/string/arm/__aeabi_memcpy.s deleted file mode 100644 index 3a527e4..0000000 --- a/lib/string/arm/__aeabi_memcpy.s +++ /dev/null @@ -1,45 +0,0 @@ -.syntax unified - -.global __aeabi_memcpy8 -.global __aeabi_memcpy4 -.global __aeabi_memcpy -.global __aeabi_memmove8 -.global __aeabi_memmove4 -.global __aeabi_memmove - -.type __aeabi_memcpy8,%function -.type __aeabi_memcpy4,%function -.type __aeabi_memcpy,%function -.type __aeabi_memmove8,%function -.type __aeabi_memmove4,%function -.type __aeabi_memmove,%function - -__aeabi_memmove8: -__aeabi_memmove4: -__aeabi_memmove: - cmp r0, r1 - bls 3f - cmp r2, #0 - beq 2f - adds r0, r0, r2 - adds r2, r1, r2 -1: subs r2, r2, #1 - ldrb r3, [r2] - subs r0, r0, #1 - strb r3, [r0] - cmp r1, r2 - bne 1b -2: bx lr -__aeabi_memcpy8: -__aeabi_memcpy4: -__aeabi_memcpy: -3: cmp r2, #0 - beq 2f - adds r2, r1, r2 -1: ldrb r3, [r1] - adds r1, r1, #1 - strb r3, [r0] - adds r0, r0, #1 - cmp r1, r2 - bne 1b -2: bx lr diff --git a/lib/string/arm/__aeabi_memset.s b/lib/string/arm/__aeabi_memset.s deleted file mode 100644 index f9f6058..0000000 --- a/lib/string/arm/__aeabi_memset.s +++ /dev/null @@ -1,31 +0,0 @@ -.syntax unified - -.global __aeabi_memclr8 -.global __aeabi_memclr4 -.global __aeabi_memclr -.global __aeabi_memset8 -.global __aeabi_memset4 -.global __aeabi_memset - -.type __aeabi_memclr8,%function -.type __aeabi_memclr4,%function -.type __aeabi_memclr,%function -.type __aeabi_memset8,%function -.type __aeabi_memset4,%function -.type __aeabi_memset,%function - -__aeabi_memclr8: -__aeabi_memclr4: -__aeabi_memclr: - movs r2, #0 -__aeabi_memset8: -__aeabi_memset4: -__aeabi_memset: - cmp r1, #0 - beq 2f - adds r1, r0, r1 -1: strb r2, [r0] - adds r0, r0, #1 - cmp r1, r0 - bne 1b -2: bx lr diff --git a/lib/string/arm/memcpy.S b/lib/string/arm/memcpy.S deleted file mode 100644 index 869e344..0000000 --- a/lib/string/arm/memcpy.S +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -/* - * Optimized memcpy() for ARM. - * - * note that memcpy() always returns the destination pointer, - * so we have to preserve R0. - */ - -/* - * This file has been modified from the original for use in musl libc. - * The main changes are: addition of .type memcpy,%function to make the - * code safely callable from thumb mode, adjusting the return - * instructions to be compatible with pre-thumb ARM cpus, removal of - * prefetch code that is not compatible with older cpus and support for - * building as thumb 2 and big-endian. - */ - -.syntax unified - -.global memcpy -.type memcpy,%function -memcpy: - /* The stack must always be 64-bits aligned to be compliant with the - * ARM ABI. Since we have to save R0, we might as well save R4 - * which we can use for better pipelining of the reads below - */ - .fnstart - .save {r0, r4, lr} - stmfd sp!, {r0, r4, lr} - /* Making room for r5-r11 which will be spilled later */ - .pad #28 - sub sp, sp, #28 - - /* it simplifies things to take care of len<4 early */ - cmp r2, #4 - blo copy_last_3_and_return - - /* compute the offset to align the source - * offset = (4-(src&3))&3 = -src & 3 - */ - rsb r3, r1, #0 - ands r3, r3, #3 - beq src_aligned - - /* align source to 32 bits. We need to insert 2 instructions between - * a ldr[b|h] and str[b|h] because byte and half-word instructions - * stall 2 cycles. - */ - movs r12, r3, lsl #31 - sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */ - ldrbmi r3, [r1], #1 - ldrbcs r4, [r1], #1 - ldrbcs r12,[r1], #1 - strbmi r3, [r0], #1 - strbcs r4, [r0], #1 - strbcs r12,[r0], #1 - -src_aligned: - - /* see if src and dst are aligned together (congruent) */ - eor r12, r0, r1 - tst r12, #3 - bne non_congruent - - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack - * frame. Don't update sp. - */ - stmea sp, {r5-r11} - - /* align the destination to a cache-line */ - rsb r3, r0, #0 - ands r3, r3, #0x1C - beq congruent_aligned32 - cmp r3, r2 - andhi r3, r2, #0x1C - - /* conditionnaly copies 0 to 7 words (length in r3) */ - movs r12, r3, lsl #28 - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */ - ldmmi r1!, {r8, r9} /* 8 bytes */ - stmcs r0!, {r4, r5, r6, r7} - stmmi r0!, {r8, r9} - tst r3, #0x4 - ldrne r10,[r1], #4 /* 4 bytes */ - strne r10,[r0], #4 - sub r2, r2, r3 - -congruent_aligned32: - /* - * here source is aligned to 32 bytes. - */ - -cached_aligned32: - subs r2, r2, #32 - blo less_than_32_left - - /* - * We preload a cache-line up to 64 bytes ahead. On the 926, this will - * stall only until the requested world is fetched, but the linefill - * continues in the the background. - * While the linefill is going, we write our previous cache-line - * into the write-buffer (which should have some free space). - * When the linefill is done, the writebuffer will - * start dumping its content into memory - * - * While all this is going, we then load a full cache line into - * 8 registers, this cache line should be in the cache by now - * (or partly in the cache). - * - * This code should work well regardless of the source/dest alignment. - * - */ - - /* Align the preload register to a cache-line because the cpu does - * "critical word first" (the first word requested is loaded first). - */ - @ bic r12, r1, #0x1F - @ add r12, r12, #64 - -1: ldmia r1!, { r4-r11 } - subs r2, r2, #32 - - /* - * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi - * for ARM9 preload will not be safely guarded by the preceding subs. - * When it is safely guarded the only possibility to have SIGSEGV here - * is because the caller overstates the length. - */ - @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */ - stmia r0!, { r4-r11 } - bhs 1b - - add r2, r2, #32 - -less_than_32_left: - /* - * less than 32 bytes left at this point (length in r2) - */ - - /* skip all this if there is nothing to do, which should - * be a common case (if not executed the code below takes - * about 16 cycles) - */ - tst r2, #0x1F - beq 1f - - /* conditionnaly copies 0 to 31 bytes */ - movs r12, r2, lsl #28 - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */ - ldmmi r1!, {r8, r9} /* 8 bytes */ - stmcs r0!, {r4, r5, r6, r7} - stmmi r0!, {r8, r9} - movs r12, r2, lsl #30 - ldrcs r3, [r1], #4 /* 4 bytes */ - ldrhmi r4, [r1], #2 /* 2 bytes */ - strcs r3, [r0], #4 - strhmi r4, [r0], #2 - tst r2, #0x1 - ldrbne r3, [r1] /* last byte */ - strbne r3, [r0] - - /* we're done! restore everything and return */ -1: ldmfd sp!, {r5-r11} - ldmfd sp!, {r0, r4, lr} - bx lr - - /********************************************************************/ - -non_congruent: - /* - * here source is aligned to 4 bytes - * but destination is not. - * - * in the code below r2 is the number of bytes read - * (the number of bytes written is always smaller, because we have - * partial words in the shift queue) - */ - cmp r2, #4 - blo copy_last_3_and_return - - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack - * frame. Don't update sp. - */ - stmea sp, {r5-r11} - - /* compute shifts needed to align src to dest */ - rsb r5, r0, #0 - and r5, r5, #3 /* r5 = # bytes in partial words */ - mov r12, r5, lsl #3 /* r12 = right */ - rsb lr, r12, #32 /* lr = left */ - - /* read the first word */ - ldr r3, [r1], #4 - sub r2, r2, #4 - - /* write a partial word (0 to 3 bytes), such that destination - * becomes aligned to 32 bits (r5 = nb of words to copy for alignment) - */ - movs r5, r5, lsl #31 - -#if __ARMEB__ - movmi r3, r3, ror #24 - strbmi r3, [r0], #1 - movcs r3, r3, ror #24 - strbcs r3, [r0], #1 - movcs r3, r3, ror #24 - strbcs r3, [r0], #1 -#else - strbmi r3, [r0], #1 - movmi r3, r3, lsr #8 - strbcs r3, [r0], #1 - movcs r3, r3, lsr #8 - strbcs r3, [r0], #1 - movcs r3, r3, lsr #8 -#endif - - cmp r2, #4 - blo partial_word_tail - -#if __ARMEB__ - mov r3, r3, lsr r12 - mov r3, r3, lsl r12 -#endif - - /* Align destination to 32 bytes (cache line boundary) */ -1: tst r0, #0x1c - beq 2f - ldr r5, [r1], #4 - sub r2, r2, #4 -#if __ARMEB__ - mov r4, r5, lsr lr - orr r4, r4, r3 - mov r3, r5, lsl r12 -#else - mov r4, r5, lsl lr - orr r4, r4, r3 - mov r3, r5, lsr r12 -#endif - str r4, [r0], #4 - cmp r2, #4 - bhs 1b - blo partial_word_tail - - /* copy 32 bytes at a time */ -2: subs r2, r2, #32 - blo less_than_thirtytwo - - /* Use immediate mode for the shifts, because there is an extra cycle - * for register shifts, which could account for up to 50% of - * performance hit. - */ - - cmp r12, #24 - beq loop24 - cmp r12, #8 - beq loop8 - -loop16: - ldr r12, [r1], #4 -1: mov r4, r12 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} - subs r2, r2, #32 - ldrhs r12, [r1], #4 -#if __ARMEB__ - orr r3, r3, r4, lsr #16 - mov r4, r4, lsl #16 - orr r4, r4, r5, lsr #16 - mov r5, r5, lsl #16 - orr r5, r5, r6, lsr #16 - mov r6, r6, lsl #16 - orr r6, r6, r7, lsr #16 - mov r7, r7, lsl #16 - orr r7, r7, r8, lsr #16 - mov r8, r8, lsl #16 - orr r8, r8, r9, lsr #16 - mov r9, r9, lsl #16 - orr r9, r9, r10, lsr #16 - mov r10, r10, lsl #16 - orr r10, r10, r11, lsr #16 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsl #16 -#else - orr r3, r3, r4, lsl #16 - mov r4, r4, lsr #16 - orr r4, r4, r5, lsl #16 - mov r5, r5, lsr #16 - orr r5, r5, r6, lsl #16 - mov r6, r6, lsr #16 - orr r6, r6, r7, lsl #16 - mov r7, r7, lsr #16 - orr r7, r7, r8, lsl #16 - mov r8, r8, lsr #16 - orr r8, r8, r9, lsl #16 - mov r9, r9, lsr #16 - orr r9, r9, r10, lsl #16 - mov r10, r10, lsr #16 - orr r10, r10, r11, lsl #16 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsr #16 -#endif - bhs 1b - b less_than_thirtytwo - -loop8: - ldr r12, [r1], #4 -1: mov r4, r12 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} - subs r2, r2, #32 - ldrhs r12, [r1], #4 -#if __ARMEB__ - orr r3, r3, r4, lsr #24 - mov r4, r4, lsl #8 - orr r4, r4, r5, lsr #24 - mov r5, r5, lsl #8 - orr r5, r5, r6, lsr #24 - mov r6, r6, lsl #8 - orr r6, r6, r7, lsr #24 - mov r7, r7, lsl #8 - orr r7, r7, r8, lsr #24 - mov r8, r8, lsl #8 - orr r8, r8, r9, lsr #24 - mov r9, r9, lsl #8 - orr r9, r9, r10, lsr #24 - mov r10, r10, lsl #8 - orr r10, r10, r11, lsr #24 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsl #8 -#else - orr r3, r3, r4, lsl #24 - mov r4, r4, lsr #8 - orr r4, r4, r5, lsl #24 - mov r5, r5, lsr #8 - orr r5, r5, r6, lsl #24 - mov r6, r6, lsr #8 - orr r6, r6, r7, lsl #24 - mov r7, r7, lsr #8 - orr r7, r7, r8, lsl #24 - mov r8, r8, lsr #8 - orr r8, r8, r9, lsl #24 - mov r9, r9, lsr #8 - orr r9, r9, r10, lsl #24 - mov r10, r10, lsr #8 - orr r10, r10, r11, lsl #24 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsr #8 -#endif - bhs 1b - b less_than_thirtytwo - -loop24: - ldr r12, [r1], #4 -1: mov r4, r12 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} - subs r2, r2, #32 - ldrhs r12, [r1], #4 -#if __ARMEB__ - orr r3, r3, r4, lsr #8 - mov r4, r4, lsl #24 - orr r4, r4, r5, lsr #8 - mov r5, r5, lsl #24 - orr r5, r5, r6, lsr #8 - mov r6, r6, lsl #24 - orr r6, r6, r7, lsr #8 - mov r7, r7, lsl #24 - orr r7, r7, r8, lsr #8 - mov r8, r8, lsl #24 - orr r8, r8, r9, lsr #8 - mov r9, r9, lsl #24 - orr r9, r9, r10, lsr #8 - mov r10, r10, lsl #24 - orr r10, r10, r11, lsr #8 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsl #24 -#else - orr r3, r3, r4, lsl #8 - mov r4, r4, lsr #24 - orr r4, r4, r5, lsl #8 - mov r5, r5, lsr #24 - orr r5, r5, r6, lsl #8 - mov r6, r6, lsr #24 - orr r6, r6, r7, lsl #8 - mov r7, r7, lsr #24 - orr r7, r7, r8, lsl #8 - mov r8, r8, lsr #24 - orr r8, r8, r9, lsl #8 - mov r9, r9, lsr #24 - orr r9, r9, r10, lsl #8 - mov r10, r10, lsr #24 - orr r10, r10, r11, lsl #8 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsr #24 -#endif - bhs 1b - -less_than_thirtytwo: - /* copy the last 0 to 31 bytes of the source */ - rsb r12, lr, #32 /* we corrupted r12, recompute it */ - add r2, r2, #32 - cmp r2, #4 - blo partial_word_tail - -1: ldr r5, [r1], #4 - sub r2, r2, #4 -#if __ARMEB__ - mov r4, r5, lsr lr - orr r4, r4, r3 - mov r3, r5, lsl r12 -#else - mov r4, r5, lsl lr - orr r4, r4, r3 - mov r3, r5, lsr r12 -#endif - str r4, [r0], #4 - cmp r2, #4 - bhs 1b - -partial_word_tail: - /* we have a partial word in the input buffer */ - movs r5, lr, lsl #(31-3) -#if __ARMEB__ - movmi r3, r3, ror #24 - strbmi r3, [r0], #1 - movcs r3, r3, ror #24 - strbcs r3, [r0], #1 - movcs r3, r3, ror #24 - strbcs r3, [r0], #1 -#else - strbmi r3, [r0], #1 - movmi r3, r3, lsr #8 - strbcs r3, [r0], #1 - movcs r3, r3, lsr #8 - strbcs r3, [r0], #1 -#endif - - /* Refill spilled registers from the stack. Don't update sp. */ - ldmfd sp, {r5-r11} - -copy_last_3_and_return: - movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */ - ldrbmi r2, [r1], #1 - ldrbcs r3, [r1], #1 - ldrbcs r12,[r1] - strbmi r2, [r0], #1 - strbcs r3, [r0], #1 - strbcs r12,[r0] - - /* we're done! restore sp and spilled registers and return */ - add sp, sp, #28 - ldmfd sp!, {r0, r4, lr} - bx lr - diff --git a/lib/string/bcmp.c b/lib/string/bcmp.c deleted file mode 100644 index d4c093f..0000000 --- a/lib/string/bcmp.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include -#include - -int bcmp(const void *s1, const void *s2, size_t n) -{ - return memcmp(s1, s2, n); -} diff --git a/lib/string/bcopy.c b/lib/string/bcopy.c deleted file mode 100644 index 25e98a2..0000000 --- a/lib/string/bcopy.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include -#include - -void bcopy(const void *s1, void *s2, size_t n) -{ - memmove(s2, s1, n); -} diff --git a/lib/string/bzero.c b/lib/string/bzero.c deleted file mode 100644 index 08f1398..0000000 --- a/lib/string/bzero.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include -#include - -void bzero(void *s, size_t n) -{ - memset(s, 0, n); -} diff --git a/lib/string/explicit_bzero.c b/lib/string/explicit_bzero.c deleted file mode 100644 index c94f25f..0000000 --- a/lib/string/explicit_bzero.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include - -void explicit_bzero(void *d, size_t n) -{ - d = memset(d, 0, n); - __asm__ __volatile__ ("" : : "r"(d) : "memory"); -} diff --git a/lib/string/i386/memcpy.s b/lib/string/i386/memcpy.s deleted file mode 100644 index 0608dd8..0000000 --- a/lib/string/i386/memcpy.s +++ /dev/null @@ -1,32 +0,0 @@ -.global memcpy -.global __memcpy_fwd -.hidden __memcpy_fwd -.type memcpy,@function -memcpy: -__memcpy_fwd: - push %esi - push %edi - mov 12(%esp),%edi - mov 16(%esp),%esi - mov 20(%esp),%ecx - mov %edi,%eax - cmp $4,%ecx - jc 1f - test $3,%edi - jz 1f -2: movsb - dec %ecx - test $3,%edi - jnz 2b -1: mov %ecx,%edx - shr $2,%ecx - rep - movsl - and $3,%edx - jz 1f -2: movsb - dec %edx - jnz 2b -1: pop %edi - pop %esi - ret diff --git a/lib/string/i386/memmove.s b/lib/string/i386/memmove.s deleted file mode 100644 index 2a6a504..0000000 --- a/lib/string/i386/memmove.s +++ /dev/null @@ -1,22 +0,0 @@ -.global memmove -.type memmove,@function -memmove: - mov 4(%esp),%eax - sub 8(%esp),%eax - cmp 12(%esp),%eax -.hidden __memcpy_fwd - jae __memcpy_fwd - push %esi - push %edi - mov 12(%esp),%edi - mov 16(%esp),%esi - mov 20(%esp),%ecx - lea -1(%edi,%ecx),%edi - lea -1(%esi,%ecx),%esi - std - rep movsb - cld - lea 1(%edi),%eax - pop %edi - pop %esi - ret diff --git a/lib/string/i386/memset.s b/lib/string/i386/memset.s deleted file mode 100644 index d00422c..0000000 --- a/lib/string/i386/memset.s +++ /dev/null @@ -1,76 +0,0 @@ -.global memset -.type memset,@function -memset: - mov 12(%esp),%ecx - cmp $62,%ecx - ja 2f - - mov 8(%esp),%dl - mov 4(%esp),%eax - test %ecx,%ecx - jz 1f - - mov %dl,%dh - - mov %dl,(%eax) - mov %dl,-1(%eax,%ecx) - cmp $2,%ecx - jbe 1f - - mov %dx,1(%eax) - mov %dx,(-1-2)(%eax,%ecx) - cmp $6,%ecx - jbe 1f - - shl $16,%edx - mov 8(%esp),%dl - mov 8(%esp),%dh - - mov %edx,(1+2)(%eax) - mov %edx,(-1-2-4)(%eax,%ecx) - cmp $14,%ecx - jbe 1f - - mov %edx,(1+2+4)(%eax) - mov %edx,(1+2+4+4)(%eax) - mov %edx,(-1-2-4-8)(%eax,%ecx) - mov %edx,(-1-2-4-4)(%eax,%ecx) - cmp $30,%ecx - jbe 1f - - mov %edx,(1+2+4+8)(%eax) - mov %edx,(1+2+4+8+4)(%eax) - mov %edx,(1+2+4+8+8)(%eax) - mov %edx,(1+2+4+8+12)(%eax) - mov %edx,(-1-2-4-8-16)(%eax,%ecx) - mov %edx,(-1-2-4-8-12)(%eax,%ecx) - mov %edx,(-1-2-4-8-8)(%eax,%ecx) - mov %edx,(-1-2-4-8-4)(%eax,%ecx) - -1: ret - -2: movzbl 8(%esp),%eax - mov %edi,12(%esp) - imul $0x1010101,%eax - mov 4(%esp),%edi - test $15,%edi - mov %eax,-4(%edi,%ecx) - jnz 2f - -1: shr $2, %ecx - rep - stosl - mov 4(%esp),%eax - mov 12(%esp),%edi - ret - -2: xor %edx,%edx - sub %edi,%edx - and $15,%edx - mov %eax,(%edi) - mov %eax,4(%edi) - mov %eax,8(%edi) - mov %eax,12(%edi) - sub %edx,%ecx - add %edx,%edi - jmp 1b diff --git a/lib/string/index.c b/lib/string/index.c deleted file mode 100644 index 8f6894c..0000000 --- a/lib/string/index.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include -#include - -char *index(const char *s, int c) -{ - return strchr(s, c); -} diff --git a/lib/string/memccpy.c b/lib/string/memccpy.c deleted file mode 100644 index 99f146f..0000000 --- a/lib/string/memccpy.c +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n) -{ - unsigned char *d = dest; - const unsigned char *s = src; - - c = (unsigned char)c; -#ifdef __GNUC__ - typedef size_t __attribute__((__may_alias__)) word; - word *wd; - const word *ws; - if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s)!=c; n--, s++, d++); - if ((uintptr_t)s & ALIGN) goto tail; - size_t k = ONES * c; - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws^k); - n-=sizeof(size_t), ws++, wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } -#endif - for (; n && (*d=*s)!=c; n--, s++, d++); -tail: - if (n) return d+1; - return 0; -} diff --git a/lib/string/memchr.c b/lib/string/memchr.c deleted file mode 100644 index d0f670f..0000000 --- a/lib/string/memchr.c +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include -#include - -#define SS (sizeof(size_t)) -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -void *memchr(const void *src, int c, size_t n) -{ - const unsigned char *s = src; - c = (unsigned char)c; -#ifdef __GNUC__ - for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--); - if (n && *s != c) { - typedef size_t __attribute__((__may_alias__)) word; - const word *w; - size_t k = ONES * c; - for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS); - s = (const void *)w; - } -#endif - for (; n && *s != c; s++, n--); - return n ? (void *)s : 0; -} diff --git a/lib/string/memcmp.c b/lib/string/memcmp.c deleted file mode 100644 index 15606f4..0000000 --- a/lib/string/memcmp.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -int memcmp(const void *vl, const void *vr, size_t n) -{ - const unsigned char *l=vl, *r=vr; - for (; n && *l == *r; n--, l++, r++); - return n ? *l-*r : 0; -} diff --git a/lib/string/memcpy.c b/lib/string/memcpy.c deleted file mode 100644 index de26a00..0000000 --- a/lib/string/memcpy.c +++ /dev/null @@ -1,127 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include -#include - -void *memcpy(void *restrict dest, const void *restrict src, size_t n) -{ - unsigned char *d = dest; - const unsigned char *s = src; - -#ifdef __GNUC__ - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define LS >> -#define RS << -#else -#define LS << -#define RS >> -#endif - - typedef uint32_t __attribute__((__may_alias__)) u32; - uint32_t w, x; - - for (; (uintptr_t)s % 4 && n; n--) *d++ = *s++; - - if ((uintptr_t)d % 4 == 0) { - for (; n>=16; s+=16, d+=16, n-=16) { - *(u32 *)(d+0) = *(u32 *)(s+0); - *(u32 *)(d+4) = *(u32 *)(s+4); - *(u32 *)(d+8) = *(u32 *)(s+8); - *(u32 *)(d+12) = *(u32 *)(s+12); - } - if (n&8) { - *(u32 *)(d+0) = *(u32 *)(s+0); - *(u32 *)(d+4) = *(u32 *)(s+4); - d += 8; s += 8; - } - if (n&4) { - *(u32 *)(d+0) = *(u32 *)(s+0); - d += 4; s += 4; - } - if (n&2) { - *d++ = *s++; *d++ = *s++; - } - if (n&1) { - *d = *s; - } - return dest; - } - - if (n >= 32) switch ((uintptr_t)d % 4) { - case 1: - w = *(u32 *)s; - *d++ = *s++; - *d++ = *s++; - *d++ = *s++; - n -= 3; - for (; n>=17; s+=16, d+=16, n-=16) { - x = *(u32 *)(s+1); - *(u32 *)(d+0) = (w LS 24) | (x RS 8); - w = *(u32 *)(s+5); - *(u32 *)(d+4) = (x LS 24) | (w RS 8); - x = *(u32 *)(s+9); - *(u32 *)(d+8) = (w LS 24) | (x RS 8); - w = *(u32 *)(s+13); - *(u32 *)(d+12) = (x LS 24) | (w RS 8); - } - break; - case 2: - w = *(u32 *)s; - *d++ = *s++; - *d++ = *s++; - n -= 2; - for (; n>=18; s+=16, d+=16, n-=16) { - x = *(u32 *)(s+2); - *(u32 *)(d+0) = (w LS 16) | (x RS 16); - w = *(u32 *)(s+6); - *(u32 *)(d+4) = (x LS 16) | (w RS 16); - x = *(u32 *)(s+10); - *(u32 *)(d+8) = (w LS 16) | (x RS 16); - w = *(u32 *)(s+14); - *(u32 *)(d+12) = (x LS 16) | (w RS 16); - } - break; - case 3: - w = *(u32 *)s; - *d++ = *s++; - n -= 1; - for (; n>=19; s+=16, d+=16, n-=16) { - x = *(u32 *)(s+3); - *(u32 *)(d+0) = (w LS 8) | (x RS 24); - w = *(u32 *)(s+7); - *(u32 *)(d+4) = (x LS 8) | (w RS 24); - x = *(u32 *)(s+11); - *(u32 *)(d+8) = (w LS 8) | (x RS 24); - w = *(u32 *)(s+15); - *(u32 *)(d+12) = (x LS 8) | (w RS 24); - } - break; - } - if (n&16) { - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - } - if (n&8) { - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - } - if (n&4) { - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - } - if (n&2) { - *d++ = *s++; *d++ = *s++; - } - if (n&1) { - *d = *s; - } - return dest; -#endif - - for (; n; n--) *d++ = *s++; - return dest; -} diff --git a/lib/string/memmem.c b/lib/string/memmem.c deleted file mode 100644 index cfd23bb..0000000 --- a/lib/string/memmem.c +++ /dev/null @@ -1,152 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _GNU_SOURCE -#include -#include - -static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) -{ - uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; - for (h+=2, k-=2; k; k--, hw = hw<<8 | *h++) - if (hw == nw) return (char *)h-2; - return hw == nw ? (char *)h-2 : 0; -} - -static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) -{ - uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8; - uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8; - for (h+=3, k-=3; k; k--, hw = (hw|*h++)<<8) - if (hw == nw) return (char *)h-3; - return hw == nw ? (char *)h-3 : 0; -} - -static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) -{ - uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; - uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; - for (h+=4, k-=4; k; k--, hw = hw<<8 | *h++) - if (hw == nw) return (char *)h-4; - return hw == nw ? (char *)h-4 : 0; -} - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const unsigned char *n, size_t l) -{ - size_t i, ip, jp, k, p, ms, p0, mem, mem0; - size_t byteset[32 / sizeof(size_t)] = { 0 }; - size_t shift[256]; - - /* Computing length of needle and fill shift table */ - for (i=0; i n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (memcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Search loop */ - for (;;) { - /* If remainder of haystack is shorter than needle, done */ - if (z-h < l) return 0; - - /* Check last byte first; advance by shift on mismatch */ - if (BITOP(byteset, h[l-1], &)) { - k = l-shift[h[l-1]]; - if (k) { - if (k < mem) k = mem; - h += k; - mem = 0; - continue; - } - } else { - h += l; - mem = 0; - continue; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); kmem && n[k-1] == h[k-1]; k--); - if (k <= mem) return (char *)h; - h += p; - mem = mem0; - } -} - -void *memmem(const void *h0, size_t k, const void *n0, size_t l) -{ - const unsigned char *h = h0, *n = n0; - - /* Return immediately on empty needle */ - if (!l) return (void *)h; - - /* Return immediately when needle is longer than haystack */ - if (k -#include - -#ifdef __GNUC__ -typedef __attribute__((__may_alias__)) size_t WT; -#define WS (sizeof(WT)) -#endif - -void *memmove(void *dest, const void *src, size_t n) -{ - char *d = dest; - const char *s = src; - - if (d==s) return d; - if ((uintptr_t)s-(uintptr_t)d-n <= -2*n) return memcpy(d, s, n); - - if (d=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s; - } -#endif - for (; n; n--) *d++ = *s++; - } else { -#ifdef __GNUC__ - if ((uintptr_t)s % WS == (uintptr_t)d % WS) { - while ((uintptr_t)(d+n) % WS) { - if (!n--) return dest; - d[n] = s[n]; - } - while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n); - } -#endif - while (n) n--, d[n] = s[n]; - } - - return dest; -} diff --git a/lib/string/mempcpy.c b/lib/string/mempcpy.c deleted file mode 100644 index 1f33e45..0000000 --- a/lib/string/mempcpy.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _GNU_SOURCE -#include - -void *mempcpy(void *dest, const void *src, size_t n) -{ - return (char *)memcpy(dest, src, n) + n; -} diff --git a/lib/string/memrchr.c b/lib/string/memrchr.c deleted file mode 100644 index 8d5c742..0000000 --- a/lib/string/memrchr.c +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -void *__memrchr(const void *m, int c, size_t n) -{ - const unsigned char *s = m; - c = (unsigned char)c; - while (n--) if (s[n]==c) return (void *)(s+n); - return 0; -} - -weak_alias(__memrchr, memrchr); diff --git a/lib/string/memset.c b/lib/string/memset.c deleted file mode 100644 index e780c71..0000000 --- a/lib/string/memset.c +++ /dev/null @@ -1,93 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include - -void *memset(void *dest, int c, size_t n) -{ - unsigned char *s = dest; - size_t k; - - /* Fill head and tail with minimal branching. Each - * conditional ensures that all the subsequently used - * offsets are well-defined and in the dest region. */ - - if (!n) return dest; - s[0] = c; - s[n-1] = c; - if (n <= 2) return dest; - s[1] = c; - s[2] = c; - s[n-2] = c; - s[n-3] = c; - if (n <= 6) return dest; - s[3] = c; - s[n-4] = c; - if (n <= 8) return dest; - - /* Advance pointer to align it at a 4-byte boundary, - * and truncate n to a multiple of 4. The previous code - * already took care of any head/tail that get cut off - * by the alignment. */ - - k = -(uintptr_t)s & 3; - s += k; - n -= k; - n &= -4; - -#ifdef __GNUC__ - typedef uint32_t __attribute__((__may_alias__)) u32; - typedef uint64_t __attribute__((__may_alias__)) u64; - - u32 c32 = ((u32)-1)/255 * (unsigned char)c; - - /* In preparation to copy 32 bytes at a time, aligned on - * an 8-byte bounary, fill head/tail up to 28 bytes each. - * As in the initial byte-based head/tail fill, each - * conditional below ensures that the subsequent offsets - * are valid (e.g. !(n<=24) implies n>=28). */ - - *(u32 *)(s+0) = c32; - *(u32 *)(s+n-4) = c32; - if (n <= 8) return dest; - *(u32 *)(s+4) = c32; - *(u32 *)(s+8) = c32; - *(u32 *)(s+n-12) = c32; - *(u32 *)(s+n-8) = c32; - if (n <= 24) return dest; - *(u32 *)(s+12) = c32; - *(u32 *)(s+16) = c32; - *(u32 *)(s+20) = c32; - *(u32 *)(s+24) = c32; - *(u32 *)(s+n-28) = c32; - *(u32 *)(s+n-24) = c32; - *(u32 *)(s+n-20) = c32; - *(u32 *)(s+n-16) = c32; - - /* Align to a multiple of 8 so we can fill 64 bits at a time, - * and avoid writing the same bytes twice as much as is - * practical without introducing additional branching. */ - - k = 24 + ((uintptr_t)s & 4); - s += k; - n -= k; - - /* If this loop is reached, 28 tail bytes have already been - * filled, so any remainder when n drops below 32 can be - * safely ignored. */ - - u64 c64 = c32 | ((u64)c32 << 32); - for (; n >= 32; n-=32, s+=32) { - *(u64 *)(s+0) = c64; - *(u64 *)(s+8) = c64; - *(u64 *)(s+16) = c64; - *(u64 *)(s+24) = c64; - } -#else - /* Pure C fallback with no aliasing violations. */ - for (; n; n--, s++) *s = c; -#endif - - return dest; -} diff --git a/lib/string/rindex.c b/lib/string/rindex.c deleted file mode 100644 index 897e19e..0000000 --- a/lib/string/rindex.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include -#include - -char *rindex(const char *s, int c) -{ - return strrchr(s, c); -} diff --git a/lib/string/stpcpy.c b/lib/string/stpcpy.c deleted file mode 100644 index 0c1f1b4..0000000 --- a/lib/string/stpcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include -#include - -#define ALIGN (sizeof(size_t)) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -char *__stpcpy(char *restrict d, const char *restrict s) -{ -#ifdef __GNUC__ - typedef size_t __attribute__((__may_alias__)) word; - word *wd; - const word *ws; - if ((uintptr_t)s % ALIGN == (uintptr_t)d % ALIGN) { - for (; (uintptr_t)s % ALIGN; s++, d++) - if (!(*d=*s)) return d; - wd=(void *)d; ws=(const void *)s; - for (; !HASZERO(*ws); *wd++ = *ws++); - d=(void *)wd; s=(const void *)ws; - } -#endif - for (; (*d=*s); s++, d++); - - return d; -} - -weak_alias(__stpcpy, stpcpy); diff --git a/lib/string/stpncpy.c b/lib/string/stpncpy.c deleted file mode 100644 index ca2ef78..0000000 --- a/lib/string/stpncpy.c +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -char *__stpncpy(char *restrict d, const char *restrict s, size_t n) -{ -#ifdef __GNUC__ - typedef size_t __attribute__((__may_alias__)) word; - word *wd; - const word *ws; - if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); - if (!n || !*s) goto tail; - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws); - n-=sizeof(size_t), ws++, wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } -#endif - for (; n && (*d=*s); n--, s++, d++); -tail: - memset(d, 0, n); - return d; -} - -weak_alias(__stpncpy, stpncpy); - diff --git a/lib/string/strcat.c b/lib/string/strcat.c deleted file mode 100644 index 723c2ff..0000000 --- a/lib/string/strcat.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strcat(char *restrict dest, const char *restrict src) -{ - strcpy(dest + strlen(dest), src); - return dest; -} diff --git a/lib/string/strchr.c b/lib/string/strchr.c deleted file mode 100644 index ddeca01..0000000 --- a/lib/string/strchr.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strchr(const char *s, int c) -{ - char *r = __strchrnul(s, c); - return *(unsigned char *)r == (unsigned char)c ? r : 0; -} diff --git a/lib/string/strchrnul.c b/lib/string/strchrnul.c deleted file mode 100644 index 6fc86d1..0000000 --- a/lib/string/strchrnul.c +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include -#include - -#define ALIGN (sizeof(size_t)) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -char *__strchrnul(const char *s, int c) -{ - c = (unsigned char)c; - if (!c) return (char *)s + strlen(s); - -#ifdef __GNUC__ - typedef size_t __attribute__((__may_alias__)) word; - const word *w; - for (; (uintptr_t)s % ALIGN; s++) - if (!*s || *(unsigned char *)s == c) return (char *)s; - size_t k = ONES * c; - for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++); - s = (void *)w; -#endif - for (; *s && *(unsigned char *)s != c; s++); - return (char *)s; -} - -weak_alias(__strchrnul, strchrnul); diff --git a/lib/string/strcmp.c b/lib/string/strcmp.c deleted file mode 100644 index afcb1b7..0000000 --- a/lib/string/strcmp.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -int strcmp(const char *l, const char *r) -{ - for (; *l==*r && *l; l++, r++); - return *(unsigned char *)l - *(unsigned char *)r; -} diff --git a/lib/string/strcpy.c b/lib/string/strcpy.c deleted file mode 100644 index a761577..0000000 --- a/lib/string/strcpy.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strcpy(char *restrict dest, const char *restrict src) -{ - __stpcpy(dest, src); - return dest; -} diff --git a/lib/string/strcspn.c b/lib/string/strcspn.c deleted file mode 100644 index ba55fe6..0000000 --- a/lib/string/strcspn.c +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -size_t strcspn(const char *s, const char *c) -{ - const char *a = s; - size_t byteset[32/sizeof(size_t)]; - - if (!c[0] || !c[1]) return __strchrnul(s, *c)-a; - - memset(byteset, 0, sizeof byteset); - for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); - for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++); - return s-a; -} diff --git a/lib/string/strlcat.c b/lib/string/strlcat.c deleted file mode 100644 index a61821d..0000000 --- a/lib/string/strlcat.c +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include - -size_t strlcat(char *d, const char *s, size_t n) -{ - size_t l = strnlen(d, n); - if (l == n) return l + strlen(s); - return l + strlcpy(d+l, s, n-l); -} diff --git a/lib/string/strlcpy.c b/lib/string/strlcpy.c deleted file mode 100644 index c2a5142..0000000 --- a/lib/string/strlcpy.c +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _BSD_SOURCE -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -size_t strlcpy(char *d, const char *s, size_t n) -{ - char *d0 = d; - size_t *wd; - - if (!n--) goto finish; -#ifdef __GNUC__ - typedef size_t __attribute__((__may_alias__)) word; - const word *ws; - if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); - if (n && *s) { - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws); - n-=sizeof(size_t), ws++, wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } - } -#endif - for (; n && (*d=*s); n--, s++, d++); - *d = 0; -finish: - return d-d0 + strlen(s); -} diff --git a/lib/string/strlen.c b/lib/string/strlen.c deleted file mode 100644 index 76e14f2..0000000 --- a/lib/string/strlen.c +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include -#include - -#define ALIGN (sizeof(size_t)) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -size_t strlen(const char *s) -{ - const char *a = s; -#ifdef __GNUC__ - typedef size_t __attribute__((__may_alias__)) word; - const word *w; - for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a; - for (w = (const void *)s; !HASZERO(*w); w++); - s = (const void *)w; -#endif - for (; *s; s++); - return s-a; -} diff --git a/lib/string/strncat.c b/lib/string/strncat.c deleted file mode 100644 index a144e37..0000000 --- a/lib/string/strncat.c +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strncat(char *restrict d, const char *restrict s, size_t n) -{ - char *a = d; - d += strlen(d); - while (n && *s) n--, *d++ = *s++; - *d++ = 0; - return a; -} diff --git a/lib/string/strncmp.c b/lib/string/strncmp.c deleted file mode 100644 index b98473b..0000000 --- a/lib/string/strncmp.c +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -int strncmp(const char *_l, const char *_r, size_t n) -{ - const unsigned char *l=(void *)_l, *r=(void *)_r; - if (!n--) return 0; - for (; *l && *r && n && *l == *r ; l++, r++, n--); - return *l - *r; -} diff --git a/lib/string/strncpy.c b/lib/string/strncpy.c deleted file mode 100644 index a828465..0000000 --- a/lib/string/strncpy.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strncpy(char *restrict d, const char *restrict s, size_t n) -{ - __stpncpy(d, s, n); - return d; -} diff --git a/lib/string/strnlen.c b/lib/string/strnlen.c deleted file mode 100644 index 8931c52..0000000 --- a/lib/string/strnlen.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -size_t strnlen(const char *s, size_t n) -{ - const char *p = memchr(s, 0, n); - return p ? p-s : n; -} diff --git a/lib/string/strpbrk.c b/lib/string/strpbrk.c deleted file mode 100644 index 82fbc92..0000000 --- a/lib/string/strpbrk.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strpbrk(const char *s, const char *b) -{ - s += strcspn(s, b); - return *s ? (char *)s : 0; -} diff --git a/lib/string/strrchr.c b/lib/string/strrchr.c deleted file mode 100644 index a45b459..0000000 --- a/lib/string/strrchr.c +++ /dev/null @@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strrchr(const char *s, int c) -{ - return __memrchr(s, c, strlen(s) + 1); -} diff --git a/lib/string/strsep.c b/lib/string/strsep.c deleted file mode 100644 index 2d513f4..0000000 --- a/lib/string/strsep.c +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#define _GNU_SOURCE -#include - -char *strsep(char **str, const char *sep) -{ - char *s = *str, *end; - if (!s) return NULL; - end = s + strcspn(s, sep); - if (*end) *end++ = 0; - else end = 0; - *str = end; - return s; -} diff --git a/lib/string/strspn.c b/lib/string/strspn.c deleted file mode 100644 index f27710d..0000000 --- a/lib/string/strspn.c +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -size_t strspn(const char *s, const char *c) -{ - const char *a = s; - size_t byteset[32/sizeof(size_t)] = { 0 }; - - if (!c[0]) return 0; - if (!c[1]) { - for (; *s == *c; s++); - return s-a; - } - - for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); - for (; *s && BITOP(byteset, *(unsigned char *)s, &); s++); - return s-a; -} diff --git a/lib/string/strstr.c b/lib/string/strstr.c deleted file mode 100644 index 07e2982..0000000 --- a/lib/string/strstr.c +++ /dev/null @@ -1,157 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include -#include - -static char *twobyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; - for (h++; *h && hw != nw; hw = hw<<8 | *++h); - return *h ? (char *)h-1 : 0; -} - -static char *threebyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8; - uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8; - for (h+=2; *h && hw != nw; hw = (hw|*++h)<<8); - return *h ? (char *)h-2 : 0; -} - -static char *fourbyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; - uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; - for (h+=3; *h && hw != nw; hw = hw<<8 | *++h); - return *h ? (char *)h-3 : 0; -} - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -static char *twoway_strstr(const unsigned char *h, const unsigned char *n) -{ - const unsigned char *z; - size_t l, ip, jp, k, p, ms, p0, mem, mem0; - size_t byteset[32 / sizeof(size_t)] = { 0 }; - size_t shift[256]; - - /* Computing length of needle and fill shift table */ - for (l=0; n[l] && h[l]; l++) - BITOP(byteset, n[l], |=), shift[n[l]] = l+1; - if (n[l]) return 0; /* hit the end of h */ - - /* Compute maximal suffix */ - ip = -1; jp = 0; k = p = 1; - while (jp+k n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (memcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Initialize incremental end-of-haystack pointer */ - z = h; - - /* Search loop */ - for (;;) { - /* Update incremental end-of-haystack pointer */ - if (z-h < l) { - /* Fast estimate for MAX(l,63) */ - size_t grow = l | 63; - const unsigned char *z2 = memchr(z, 0, grow); - if (z2) { - z = z2; - if (z-h < l) return 0; - } else z += grow; - } - - /* Check last byte first; advance by shift on mismatch */ - if (BITOP(byteset, h[l-1], &)) { - k = l-shift[h[l-1]]; - if (k) { - if (k < mem) k = mem; - h += k; - mem = 0; - continue; - } - } else { - h += l; - mem = 0; - continue; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); - if (n[k]) { - h += k-ms; - mem = 0; - continue; - } - /* Compare left half */ - for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); - if (k <= mem) return (char *)h; - h += p; - mem = mem0; - } -} - -char *strstr(const char *h, const char *n) -{ - /* Return immediately on empty needle */ - if (!n[0]) return (char *)h; - - /* Use faster algorithms for short needles */ - h = strchr(h, *n); - if (!h || !n[1]) return (char *)h; - if (!h[1]) return 0; - if (!n[2]) return twobyte_strstr((void *)h, (void *)n); - if (!h[2]) return 0; - if (!n[3]) return threebyte_strstr((void *)h, (void *)n); - if (!h[3]) return 0; - if (!n[4]) return fourbyte_strstr((void *)h, (void *)n); - - return twoway_strstr((void *)h, (void *)n); -} diff --git a/lib/string/strtok.c b/lib/string/strtok.c deleted file mode 100644 index 86d9c97..0000000 --- a/lib/string/strtok.c +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strtok(char *restrict s, const char *restrict sep) -{ - static char *p; - if (!s && !(s = p)) return NULL; - s += strspn(s, sep); - if (!*s) return p = 0; - p = s + strcspn(s, sep); - if (*p) *p++ = 0; - else p = 0; - return s; -} diff --git a/lib/string/strtok_r.c b/lib/string/strtok_r.c deleted file mode 100644 index a702703..0000000 --- a/lib/string/strtok_r.c +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */ - -#include - -char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p) -{ - if (!s && !(s = *p)) return NULL; - s += strspn(s, sep); - if (!*s) return *p = 0; - *p = s + strcspn(s, sep); - if (**p) *(*p)++ = 0; - else *p = 0; - return s; -} diff --git a/lib/string/x86_64/memcpy.s b/lib/string/x86_64/memcpy.s deleted file mode 100644 index 3d960ef..0000000 --- a/lib/string/x86_64/memcpy.s +++ /dev/null @@ -1,25 +0,0 @@ -.global memcpy -.global __memcpy_fwd -.hidden __memcpy_fwd -.type memcpy,@function -memcpy: -__memcpy_fwd: - mov %rdi,%rax - cmp $8,%rdx - jc 1f - test $7,%edi - jz 1f -2: movsb - dec %rdx - test $7,%edi - jnz 2b -1: mov %rdx,%rcx - shr $3,%rcx - rep - movsq - and $7,%edx - jz 1f -2: movsb - dec %edx - jnz 2b -1: ret diff --git a/lib/string/x86_64/memmove.s b/lib/string/x86_64/memmove.s deleted file mode 100644 index 172c025..0000000 --- a/lib/string/x86_64/memmove.s +++ /dev/null @@ -1,16 +0,0 @@ -.global memmove -.type memmove,@function -memmove: - mov %rdi,%rax - sub %rsi,%rax - cmp %rdx,%rax -.hidden __memcpy_fwd - jae __memcpy_fwd - mov %rdx,%rcx - lea -1(%rdi,%rdx),%rdi - lea -1(%rsi,%rdx),%rsi - std - rep movsb - cld - lea 1(%rdi),%rax - ret diff --git a/lib/string/x86_64/memset.s b/lib/string/x86_64/memset.s deleted file mode 100644 index 2d3f5e5..0000000 --- a/lib/string/x86_64/memset.s +++ /dev/null @@ -1,72 +0,0 @@ -.global memset -.type memset,@function -memset: - movzbq %sil,%rax - mov $0x101010101010101,%r8 - imul %r8,%rax - - cmp $126,%rdx - ja 2f - - test %edx,%edx - jz 1f - - mov %sil,(%rdi) - mov %sil,-1(%rdi,%rdx) - cmp $2,%edx - jbe 1f - - mov %ax,1(%rdi) - mov %ax,(-1-2)(%rdi,%rdx) - cmp $6,%edx - jbe 1f - - mov %eax,(1+2)(%rdi) - mov %eax,(-1-2-4)(%rdi,%rdx) - cmp $14,%edx - jbe 1f - - mov %rax,(1+2+4)(%rdi) - mov %rax,(-1-2-4-8)(%rdi,%rdx) - cmp $30,%edx - jbe 1f - - mov %rax,(1+2+4+8)(%rdi) - mov %rax,(1+2+4+8+8)(%rdi) - mov %rax,(-1-2-4-8-16)(%rdi,%rdx) - mov %rax,(-1-2-4-8-8)(%rdi,%rdx) - cmp $62,%edx - jbe 1f - - mov %rax,(1+2+4+8+16)(%rdi) - mov %rax,(1+2+4+8+16+8)(%rdi) - mov %rax,(1+2+4+8+16+16)(%rdi) - mov %rax,(1+2+4+8+16+24)(%rdi) - mov %rax,(-1-2-4-8-16-32)(%rdi,%rdx) - mov %rax,(-1-2-4-8-16-24)(%rdi,%rdx) - mov %rax,(-1-2-4-8-16-16)(%rdi,%rdx) - mov %rax,(-1-2-4-8-16-8)(%rdi,%rdx) - -1: mov %rdi,%rax - ret - -2: test $15,%edi - mov %rdi,%r8 - mov %rax,-8(%rdi,%rdx) - mov %rdx,%rcx - jnz 2f - -1: shr $3,%rcx - rep - stosq - mov %r8,%rax - ret - -2: xor %edx,%edx - sub %edi,%edx - and $15,%edx - mov %rax,(%rdi) - mov %rax,8(%rdi) - sub %rdx,%rcx - add %rdx,%rdi - jmp 1b diff --git a/mm/Build.mk b/mm/Build.mk deleted file mode 100644 index b6d816d..0000000 --- a/mm/Build.mk +++ /dev/null @@ -1,6 +0,0 @@ -targets += mm/core -target.mm/core.kind := source-set -target.mm/core.sources := \ - mm/memblock.cc mm/pmm.cc mm/slab.cc mm/vmm.cc mm/vma.cc \ - mm/page_cache.cc mm/tlb.cc - diff --git a/mm/memblock.cc b/mm/memblock.cc deleted file mode 100644 index aee0245..0000000 --- a/mm/memblock.cc +++ /dev/null @@ -1,257 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * memblock.cc — Boot-time physical memory allocator - * - * Simple region tracker: one memory region (from FDT) plus an array - * of reserved regions. Allocation searches for gaps between reserved - * regions. All operations are O(n_reserved), which is fine for the - * ~20 allocations that happen during early boot. - * - * Reference: inspired by Linux kernel's mm/memblock.c - */ - -#include -#include -#include -#include -#include -#include - -extern "C" char _stext[], _kernel_end[]; - -/* ------------------------------------------------------------------ */ -/* Module state */ -/* ------------------------------------------------------------------ */ - -namespace { - -constexpr uint64 kMB = 1024ULL * 1024ULL; - -struct { - uint64 mem_base; - uint64 mem_size; - - struct { - uint64 base; - uint64 size; - } reserved[kMemblockMaxRegions]; - int reserved_count; - bool active; -} g_mb; - -/* ------------------------------------------------------------------ */ -/* Internal helpers */ -/* ------------------------------------------------------------------ */ - -/* Insert a reserved region, keeping the array sorted by base. */ -void insert_reserved(uint64 base, uint64 size) -{ - if (g_mb.reserved_count >= kMemblockMaxRegions) { - kernel_panic("memblock: too many reserved regions"); - } - - int i = g_mb.reserved_count; - while (i > 0 && g_mb.reserved[i - 1].base > base) { - g_mb.reserved[i] = g_mb.reserved[i - 1]; - i--; - } - g_mb.reserved[i] = {base, size}; - g_mb.reserved_count++; -} - -/* Check if [base, base+size) overlaps any reserved region. */ -bool overlaps_reserved(uint64 base, uint64 size) -{ - uint64 end = base + size; - for (int i = 0; i < g_mb.reserved_count; i++) { - uint64 rb = g_mb.reserved[i].base; - uint64 re = rb + g_mb.reserved[i].size; - if (base < re && end > rb) { - return true; - } - } - return false; -} - -/* Find the end of the first reserved region that covers `addr`. */ -uint64 reserved_end_covering(uint64 addr) -{ - for (int i = 0; i < g_mb.reserved_count; i++) { - uint64 rb = g_mb.reserved[i].base; - uint64 re = rb + g_mb.reserved[i].size; - if (addr >= rb && addr < re) { - return re; - } - } - return addr; -} - -} // namespace - -/* ------------------------------------------------------------------ */ -/* Public API */ -/* ------------------------------------------------------------------ */ - -void memblock_init(uint64 fdt_paddr) -{ - - /* 1. Get memory layout from FDT */ - uint64 mem_base = 0; - uint64 mem_size = 0; - fdt_early_get_mem_info(&mem_base, &mem_size); - if (mem_size == 0) { - kernel_panic("memblock_init: FDT reports zero memory"); - } - - g_mb.mem_base = mem_base; - g_mb.mem_size = mem_size; - g_mb.reserved_count = 0; - g_mb.active = true; - - /* 2. Reserve firmware region [mem_base, kPhysStart). - * - * Everything below the kernel's linked load address is firmware - * territory (OpenSBI), which is PMP-protected. */ - { - uint64 fw_end = kPhysStart; - if (fw_end > mem_base) { - memblock_reserve(mem_base, fw_end - mem_base); - } - } - - /* 2b. Reserve stale pre-relocation kernel image. - * - * After physical KASLR, the kernel is relocated from its original - * load address (kPhysStart) to a new PA. The old copy at - * [kPhysStart, kPhysStart + kernel_size) must not be allocated — - * it contains stale code/data that would corrupt page tables or - * other structures if reused. */ - { - uint64 ks_pa = boot_va_to_pa(virt_addr( - reinterpret_cast(_stext))).raw; - if (ks_pa != kPhysStart) { - /* Kernel was relocated — reserve the original location */ - uint64 kernel_size = boot_va_to_pa(virt_addr( - reinterpret_cast(_kernel_end))).raw - ks_pa; - memblock_reserve(kPhysStart, kernel_size); - } - } - - /* 3. Reserve kernel image [_stext, _kernel_end) */ - uint64 ks_pa = boot_va_to_pa(virt_addr( - reinterpret_cast(_stext))).raw; - uint64 ke_pa = boot_va_to_pa(virt_addr( - reinterpret_cast(_kernel_end))).raw; - memblock_reserve(ks_pa, ke_pa - ks_pa); - - /* 4. Reserve FDT blob — it lives in RAM and must not be overwritten - * by vmemmap/page_map or buddy before fdt_unflatten() copies it. */ - { - struct fdt_hdr { uint32 magic; uint32 totalsize; }; - const auto* fh = reinterpret_cast(fdt_paddr); - uint32 fdt_size = ((fh->totalsize & 0xFF) << 24) | - (((fh->totalsize >> 8) & 0xFF) << 16) | - (((fh->totalsize >> 16) & 0xFF) << 8) | - ((fh->totalsize >> 24) & 0xFF); - memblock_reserve(fdt_paddr, fdt_size); - kprintf("[memblock] FDT reserved [0x%llx, 0x%llx)\n", - fdt_paddr, fdt_paddr + fdt_size); - } - - kprintf("[memblock] RAM [0x%llx, 0x%llx) = %llu MB\n", - mem_base, mem_base + mem_size, mem_size / kMB); - kprintf("[memblock] kernel reserved [0x%llx, 0x%llx)\n", ks_pa, ke_pa); -} - -void memblock_reserve(uint64 base, uint64 size) -{ - uint64 aligned_base = page_align_down(base); - uint64 aligned_end = page_align_up(base + size); - insert_reserved(aligned_base, aligned_end - aligned_base); -} - -uint64 memblock_alloc_top(uint64 size, uint64 align) -{ - uint64 mem_end = g_mb.mem_base + g_mb.mem_size; - - /* Search from top of RAM downward */ - uint64 end = page_align_down(mem_end); - uint64 start = (end - size) & ~(align - 1); - - while (start >= g_mb.mem_base && start + size <= mem_end) { - if (!overlaps_reserved(start, size)) { - memblock_reserve(start, size); - return start; - } - if (start < align) { - break; - } - start -= align; - } - - kernel_panic("memblock_alloc_top: out of memory"); - return 0; -} - -uint64 memblock_alloc(uint64 size, uint64 align) -{ - uint64 mem_end = g_mb.mem_base + g_mb.mem_size; - uint64 start = page_align_up(g_mb.mem_base); - - while (start + size <= mem_end) { - start = (start + align - 1) & ~(align - 1); - if (start + size > mem_end) { - break; - } - - if (!overlaps_reserved(start, size)) { - memblock_reserve(start, size); - return start; - } - - /* Skip past the overlapping reserved region */ - uint64 skip = reserved_end_covering(start); - if (skip <= start) { - start += align; - } else { - start = skip; - } - } - - kernel_panic("memblock_alloc: out of memory"); - return 0; -} - -uint64 memblock_get_mem_base() { return g_mb.mem_base; } -uint64 memblock_get_mem_size() { return g_mb.mem_size; } - -bool memblock_is_active() { return g_mb.active; } -void memblock_retire() { g_mb.active = false; } - -void memblock_for_each_free(void (*cb)(uint64 base, uint64 size, void* ctx), - void* ctx) -{ - uint64 pos = g_mb.mem_base; - uint64 mem_end = g_mb.mem_base + g_mb.mem_size; - - for (int i = 0; i < g_mb.reserved_count && pos < mem_end; i++) { - uint64 rb = g_mb.reserved[i].base; - if (rb < pos) { - uint64 re = g_mb.reserved[i].base + g_mb.reserved[i].size; - if (re > pos) { - pos = re; - } - continue; - } - if (rb > pos) { - cb(pos, rb - pos, ctx); - } - pos = g_mb.reserved[i].base + g_mb.reserved[i].size; - } - - if (pos < mem_end) { - cb(pos, mem_end - pos, ctx); - } -} diff --git a/mm/page_cache.cc b/mm/page_cache.cc deleted file mode 100644 index 25c6a60..0000000 --- a/mm/page_cache.cc +++ /dev/null @@ -1,252 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * page_cache.cc — Minimal page cache implementation - * - * Open-addressing hash table indexed by (mapping, index) pairs. - * Fixed-size bucket array allocated at init time via slab. - * - * This is intentionally simple: no LRU, no writeback, no eviction. - * The interface in page_cache.h is designed so that upgrading to a - * radix tree + LRU scheme later only changes this file. - * - * Concurrency: protected by a single spinlock. Acceptable for - * initial bring-up; will be replaced by per-bucket or RCU-based - * locking when contention becomes measurable. - */ - -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Hash table internals */ -/* ------------------------------------------------------------------ */ - -struct CacheEntry { - void* mapping; // nullptr = empty slot - uint64 index; - Page* page; -}; - -namespace { - -constexpr uint64 kCacheBuckets = 1024; - -CacheEntry g_buckets[kCacheBuckets]; -Spinlock g_cache_lock; - -uint64 hash_key(void* mapping, uint64 index) -{ - uint64 m = reinterpret_cast(mapping); - /* FNV-1a inspired mixing */ - uint64 h = m ^ (index * 0x517cc1b727220a95ULL); - h ^= h >> 17; - h *= 0xbf58476d1ce4e5b9ULL; - h ^= h >> 31; - return h % kCacheBuckets; -} - -/* Linear probe to find an entry or an empty slot. */ -CacheEntry* find_slot(void* mapping, uint64 index) -{ - uint64 start = hash_key(mapping, index); - for (uint64 i = 0; i < kCacheBuckets; i++) { - uint64 idx = (start + i) % kCacheBuckets; - CacheEntry* e = &g_buckets[idx]; - if (e->mapping == nullptr) { - return e; // Empty slot - } - if (e->mapping == mapping && e->index == index) { - return e; // Found - } - } - return nullptr; // Table full -} - -/* Find an existing entry (not an empty slot). */ -CacheEntry* find_entry(void* mapping, uint64 index) -{ - uint64 start = hash_key(mapping, index); - for (uint64 i = 0; i < kCacheBuckets; i++) { - uint64 idx = (start + i) % kCacheBuckets; - CacheEntry* e = &g_buckets[idx]; - if (e->mapping == nullptr) { - return nullptr; // Empty = not found - } - if (e->mapping == mapping && e->index == index) { - return e; - } - } - return nullptr; -} - -/* - * Remove an entry and fix up the linear-probe chain. - * Standard open-addressing deletion with backward shift. - */ -void remove_entry(CacheEntry* entry) -{ - uint64 removed = static_cast(entry - g_buckets); - entry->mapping = nullptr; - entry->page = nullptr; - - /* Backward-shift deletion to maintain probe chain integrity */ - uint64 cur = (removed + 1) % kCacheBuckets; - while (g_buckets[cur].mapping != nullptr) { - uint64 ideal = hash_key(g_buckets[cur].mapping, g_buckets[cur].index); - /* Check if cur's ideal position is "before" removed in probe order */ - bool needs_shift = false; - if (removed <= cur) { - needs_shift = (ideal <= removed || ideal > cur); - } else { - needs_shift = (ideal <= removed && ideal > cur); - } - - if (needs_shift) { - g_buckets[removed] = g_buckets[cur]; - g_buckets[cur].mapping = nullptr; - g_buckets[cur].page = nullptr; - removed = cur; - } - cur = (cur + 1) % kCacheBuckets; - } -} - -} // namespace - -/* ------------------------------------------------------------------ */ -/* Public API */ -/* ------------------------------------------------------------------ */ - -void page_cache_init() -{ - g_cache_lock.init("page_cache"); - for (uint64 i = 0; i < kCacheBuckets; i++) { - g_buckets[i].mapping = nullptr; - g_buckets[i].index = 0; - g_buckets[i].page = nullptr; - } -} - -Page* page_cache_get(void* mapping, uint64 index) -{ - LockGuard guard(g_cache_lock); - CacheEntry* e = find_entry(mapping, index); - if (!e) { - return nullptr; - } - page_incref(e->page); - return e->page; -} - -int page_cache_insert(void* mapping, uint64 index, Page* page) -{ - if (!mapping || !page) { - return -EINVAL; - } - - LockGuard guard(g_cache_lock); - - /* Check for existing entry */ - CacheEntry* existing = find_entry(mapping, index); - if (existing) { - return -EEXIST; - } - - /* Find an empty slot */ - CacheEntry* slot = find_slot(mapping, index); - if (!slot || slot->mapping != nullptr) { - return -ENOMEM; // Table full - } - - slot->mapping = mapping; - slot->index = index; - slot->page = page; - page_incref(page); // Cache holds a reference - - return 0; -} - -void page_cache_put(Page* page) -{ - if (!page) { - return; - } - page_decref(page); -} - -Page* page_cache_remove(void* mapping, uint64 index) -{ - LockGuard guard(g_cache_lock); - CacheEntry* e = find_entry(mapping, index); - if (!e) { - return nullptr; - } - - Page* page = e->page; - remove_entry(e); - page_decref(page); // Release cache's reference - return page; -} - -void page_cache_invalidate(void* mapping) -{ - if (!mapping) { - return; - } - - LockGuard guard(g_cache_lock); - - /* Scan all buckets — acceptable for current table size */ - for (uint64 i = 0; i < kCacheBuckets; i++) { - if (g_buckets[i].mapping == mapping) { - Page* page = g_buckets[i].page; - remove_entry(&g_buckets[i]); - page_decref(page); - /* After removal, re-check this index since backward shift - * may have moved an entry into this slot. */ - i--; - } - } -} - -Page* page_cache_get_or_alloc(void* mapping, uint64 index) -{ - /* Fast path: already cached */ - Page* page = page_cache_get(mapping, index); - if (page) { - return page; - } - - /* Slow path: allocate and insert */ - page = pmm_alloc_page(); - if (!page) { - return nullptr; - } - - int ret = page_cache_insert(mapping, index, page); - if (ret == -EEXIST) { - /* Race: another thread inserted between our get and insert. - * Free our allocation and return the existing page. */ - pmm_free_page(page); - return page_cache_get(mapping, index); - } - if (ret < 0) { - pmm_free_page(page); - return nullptr; - } - - /* Caller gets a ref (insert already added cache's ref, - * we need one more for the caller). */ - /* Actually, insert did incref for cache. The page already has - * refcount=1 from alloc + 1 from insert = 2. - * We return it to caller who must put() when done. - * So we incref once more for the caller's reference. */ - page_incref(page); - return page; -} diff --git a/mm/pmm.cc b/mm/pmm.cc deleted file mode 100644 index b7cf611..0000000 --- a/mm/pmm.cc +++ /dev/null @@ -1,528 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * pmm.cc — Physical Memory Manager implementation - * - * Buddy allocator with Per-CPU single-page caches (PCP). - * - * Initialization sequence (called by BSP in single-core period): - * 1. memblock + vmm_init allocate and map the page_map at VMEMMAP. - * 2. Zero and mark all Page descriptors reserved by default. - * 3. Carve free regions from memblock into the buddy system. - * - * The page_map is a flat array indexed by physical page frame number (PFN). - * PFN = (pa - mem_base) / PAGE_SIZE. This keeps address conversion O(1). - * - * Reference: docs/specs/pmm.md - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Per-CPU page cache */ -/* ------------------------------------------------------------------ */ - -struct PerCpuCache { - list_node free_list; // Single-page free list - uint32 count; // Number of cached pages -}; - -/* ------------------------------------------------------------------ */ -/* Module-private state */ -/* ------------------------------------------------------------------ */ - -namespace { - -/* PCP Cache tuning parameters */ -constexpr uint32 kPcpBatchDivisor = 1024; -constexpr uint32 kPcpMinBatchSize = 16; -constexpr uint64 kMB = 1024ULL * 1024ULL; - -Spinlock g_pmm_lock; -list_node g_free_areas[kMaxOrder]; // Buddy free lists [0..10] -PerCpuCache g_pcp[kMaxCpus]; - -Page *g_page_map = nullptr; // Flat array of Page descriptors -uint64 g_page_map_pa = 0; // Physical base of page_map storage -uint64 g_page_map_bytes = 0; // Byte size of page_map storage -uint64 g_mem_base = 0; // Physical memory base (from FDT) -uint64 g_mem_size = 0; // Total physical memory size -uint64 g_num_pages = 0; // Total managed pages - -} // namespace - -uint32 g_pcp_high_watermark = 0; -uint32 g_pcp_batch_size = 0; - -/* ------------------------------------------------------------------ */ -/* Address conversion helpers */ -/* ------------------------------------------------------------------ */ - -/* - * PFN (Page Frame Number) — fundamental conversion unit. - * When sparse vmemmap is implemented, only these two functions change. - * All other PA↔Page conversions go through them. - */ -uint64 page_to_pfn(const Page *page) { - uintptr base = reinterpret_cast(g_page_map); - uintptr addr = reinterpret_cast(page); - uintptr end = base + g_num_pages * sizeof(Page); - - if (addr < base || addr >= end) { - kernel_panic("page_to_pfn: page outside page_map bounds"); - } - - uint64 idx = (addr - base) / sizeof(Page); - return (g_mem_base / kPageSize) + idx; -} - -Page *pfn_to_page(uint64 pfn) { - uint64 base_pfn = g_mem_base / kPageSize; - if (pfn < base_pfn || pfn >= base_pfn + g_num_pages) { - kernel_panic("pfn_to_page: PFN outside managed range"); - } - return &g_page_map[pfn - base_pfn]; -} - -PhysAddr page_to_pa(const Page *page) { - return pfn_to_pa(Pfn{page_to_pfn(page)}); -} - -Page *pa_to_page(PhysAddr pa) { - return pfn_to_page(pa_to_pfn(pa).raw); -} - -VirtAddr page_to_va(const Page *page) { - return pa_to_va(page_to_pa(page)); -} - - -/* ------------------------------------------------------------------ */ -/* Buddy system internals (caller must hold g_pmm_lock) */ -/* ------------------------------------------------------------------ */ - -namespace { - -/* - * Find a page's buddy at a given order. - * Buddy PFN = PFN ^ (1 << order). - */ -inline Page *buddy_of(Page *page, uint8 order) { - uint64 pfn = static_cast(page - g_page_map); - uint64 buddy_pfn = pfn ^ (1ULL << order); - if (buddy_pfn >= g_num_pages) { - return nullptr; - } - return &g_page_map[buddy_pfn]; -} - -/* - * Insert a free block into the buddy free list at the given order. - */ -void buddy_list_add(Page *page, uint8 order) { - page->type = PageType::Free; - page->order = order; - list_node *head = &g_free_areas[order]; - list_node *node = &page->free.free_link; - node->next = head->next; - node->prev = head; - head->next->prev = node; - head->next = node; -} - -/* - * Remove a block from whatever buddy free list it is on. - */ -void buddy_list_del(Page *page) { - list_node *node = &page->free.free_link; - node->prev->next = node->next; - node->next->prev = node->prev; - node->next = node; - node->prev = node; -} - -/* - * Allocate a block of 2^order contiguous pages from the buddy system. - * Splits higher-order blocks if no exact match is available. - * Returns nullptr if no memory available. - */ -Page *buddy_alloc(uint8 order) { - for (int cur = order; cur < kMaxOrder; cur++) { - list_node *head = &g_free_areas[cur]; - if (head->next == head) { - continue; // Empty at this order - } - - // Pop the first block from this order's free list - list_node *node = head->next; - // Compute Page* from the free_link member offset - Page *page = - reinterpret_cast(reinterpret_cast(node) - - __builtin_offsetof(Page, free.free_link)); - buddy_list_del(page); - - // Split down to the requested order - while (cur > order) { - cur--; - // The upper half becomes a free buddy - Page *split = &g_page_map[(page - g_page_map) + (1ULL << cur)]; - buddy_list_add(split, static_cast(cur)); - } - - page->type = PageType::Allocated; - page->order = order; - page->refcount.store(1, __ATOMIC_RELAXED); - page->mapcount.store(0, __ATOMIC_RELAXED); - page->flags.store(0, __ATOMIC_RELAXED); - page->mapping = nullptr; - page->index = 0; - return page; - } - return nullptr; -} - -/* - * Return a block of 2^order pages to the buddy system. - * Coalesces with its buddy recursively up to kMaxOrder-1. - */ -void buddy_free(Page *page, uint8 order) { - uint64 pfn = static_cast(page - g_page_map); - - while (order < kMaxOrder - 1) { - Page *buddy = buddy_of(page, order); - if (!buddy) { - break; - } - // Buddy must be free AND at the same order to coalesce - if (buddy->type != PageType::Free || buddy->order != order) { - break; - } - - // Remove buddy from its free list and merge - buddy_list_del(buddy); - - // The merged block starts at the lower PFN - uint64 buddy_pfn = static_cast(buddy - g_page_map); - if (buddy_pfn < pfn) { - page = buddy; - pfn = buddy_pfn; - } - order++; - } - - buddy_list_add(page, order); -} - -/* ------------------------------------------------------------------ */ -/* Per-CPU cache operations (interrupts must be disabled by caller) */ -/* ------------------------------------------------------------------ */ - -/* - * Refill the PCP from the global buddy system. - * Acquires g_pmm_lock internally. - */ -void refill_pcp(PerCpuCache *pcp) { - LockGuard guard(g_pmm_lock); - for (uint32 i = 0; i < g_pcp_batch_size; i++) { - Page *page = buddy_alloc(0); - if (!page) { - break; - } - // Put onto PCP list (reuse the free_link for PCP chain) - page->type = PageType::PcpCached; - list_node *node = &page->free.free_link; - node->next = pcp->free_list.next; - node->prev = &pcp->free_list; - pcp->free_list.next->prev = node; - pcp->free_list.next = node; - pcp->count++; - } -} - -/* - * Drain half the PCP back to the global buddy system. - * Acquires g_pmm_lock internally. - */ -void drain_pcp(PerCpuCache *pcp) { - LockGuard guard(g_pmm_lock); - int to_drain = pcp->count / 2; - for (int i = 0; i < to_drain; i++) { - list_node *head = &pcp->free_list; - if (head->next == head) { - break; - } - list_node *node = head->next; - // Unlink from PCP - node->prev->next = node->next; - node->next->prev = node->prev; - pcp->count--; - - Page *page = - reinterpret_cast(reinterpret_cast(node) - - __builtin_offsetof(Page, free.free_link)); - buddy_free(page, 0); - } -} - -} // namespace - -/* ------------------------------------------------------------------ */ -/* Public API: single-page (fast path via PCP) */ -/* ------------------------------------------------------------------ */ - -Page *pmm_alloc_page() { - /* - * Disable interrupts to prevent reentry on the same CPU - * (e.g. timer IRQ handler calling pmm_alloc_page while we - * are mid-way through manipulating the PCP list). - */ - bool was_on = arch::cpu::intr_enabled(); - arch::cpu::intr_off(); - - uint64 cpu = arch::cpu::id(); - PerCpuCache *pcp = &g_pcp[cpu]; - - if (pcp->count == 0) { - refill_pcp(pcp); - } - - Page *page = nullptr; - if (pcp->count > 0) { - list_node *node = pcp->free_list.next; - // Unlink - node->prev->next = node->next; - node->next->prev = node->prev; - pcp->count--; - - page = - reinterpret_cast(reinterpret_cast(node) - - __builtin_offsetof(Page, free.free_link)); - - // Validate the page is within the page_map bounds - if (page < g_page_map || page >= g_page_map + g_num_pages) { - kernel_panic("pmm_alloc_page: PCP returned out-of-bounds page"); - } - - page->type = PageType::Allocated; - page->order = 0; - page->refcount.store(1, __ATOMIC_RELAXED); - page->mapcount.store(0, __ATOMIC_RELAXED); - page->flags.store(0, __ATOMIC_RELAXED); - page->mapping = nullptr; - page->index = 0; - } - - if (was_on) { - arch::cpu::intr_on(); - } - return page; -} - -void pmm_free_page(Page *page) { - if (!page) { - kernel_panic("pmm_free_page: null page"); - } - - bool was_on = arch::cpu::intr_enabled(); - arch::cpu::intr_off(); - - uint64 cpu = arch::cpu::id(); - PerCpuCache *pcp = &g_pcp[cpu]; - - // Push onto PCP - page->type = PageType::PcpCached; - page->order = 0; - list_node *node = &page->free.free_link; - node->next = pcp->free_list.next; - node->prev = &pcp->free_list; - pcp->free_list.next->prev = node; - pcp->free_list.next = node; - pcp->count++; - - // Drain if over high watermark - if (pcp->count >= g_pcp_high_watermark) { - drain_pcp(pcp); - } - - if (was_on) { - arch::cpu::intr_on(); - } -} - -/* ------------------------------------------------------------------ */ -/* Public API: multi-page (slow path, direct buddy) */ -/* ------------------------------------------------------------------ */ - -Page *pmm_alloc_pages(uint8 order) { - if (order >= kMaxOrder) { - return nullptr; - } - LockGuard guard(g_pmm_lock); - return buddy_alloc(order); -} - -void pmm_free_pages(Page *page, uint8 order) { - if (!page) { - kernel_panic("pmm_free_pages: null page"); - } - if (order >= kMaxOrder) { - kernel_panic("pmm_free_pages: order out of range"); - } - LockGuard guard(g_pmm_lock); - buddy_free(page, order); -} - -/* ------------------------------------------------------------------ */ -/* Public API: reference counting */ -/* ------------------------------------------------------------------ */ - -void page_incref(Page *page) { page->refcount.fetch_add(1); } - -void page_decref(Page *page) { - uint32 old = page->refcount.fetch_sub(1); - if (old == 1) { - // Refcount dropped to 0 — return to pool based on originally allocated - // order - if (page->order == 0) { - pmm_free_page(page); - } else { - pmm_free_pages(page, page->order); - } - } -} - -/* ------------------------------------------------------------------ */ -/* Initialization */ -/* ------------------------------------------------------------------ */ - -/* - * Helper: zero out a range of bytes. We cannot use memset here - * because lib/string may not be linked yet. - */ -namespace { -void zero_range(void *start, uint64 bytes) { - uint8 *p = static_cast(start); - for (uint64 i = 0; i < bytes; i++) { - p[i] = 0; - } -} -} // namespace - -void pmm_init() { - /* 1. Get memory layout from memblock (already scanned FDT) */ - g_mem_base = memblock_get_mem_base(); - g_mem_size = memblock_get_mem_size(); - g_num_pages = vmm_get_num_pages(); - - if (g_mem_size == 0) { - kernel_panic("pmm_init: memblock reports zero memory"); - } - - /* 2. PCP parameters */ - uint32 calc_batch = static_cast(g_num_pages / (kMaxCpus * kPcpBatchDivisor)); - g_pcp_batch_size = (calc_batch > kPcpMinBatchSize) ? calc_batch : kPcpMinBatchSize; - g_pcp_high_watermark = g_pcp_batch_size * 4; - - /* 3. page_map was allocated by vmm_init at vmemmap VA. - * No relocation needed — page_map starts life at the right VA. */ - g_page_map_pa = vmm_get_page_map_pa(); - g_page_map_bytes = vmm_get_page_map_size(); - g_page_map = reinterpret_cast(arch::g_vmemmap_base); - - /* 4. Zero out the entire page_map */ - zero_range(g_page_map, g_page_map_bytes); - - /* 4b. Default every page descriptor to reserved/non-free. */ - for (uint64 i = 0; i < g_num_pages; i++) { - Page *page = &g_page_map[i]; - page->refcount.store(0, __ATOMIC_RELAXED); - page->mapcount.store(0, __ATOMIC_RELAXED); - page->flags.store(0, __ATOMIC_RELAXED); - page->type = PageType::Allocated; - page->order = 0; - page->mapping = nullptr; - page->index = 0; - page->lru.init(); - page->free.free_link.init(); - } - - /* 5. Initialize buddy free list heads */ - g_pmm_lock.init("pmm"); - for (int i = 0; i < kMaxOrder; i++) { - g_free_areas[i].init(); - } - - /* 6. Initialize PCP list heads */ - for (int i = 0; i < kMaxCpus; i++) { - g_pcp[i].free_list.init(); - g_pcp[i].count = 0; - } - - /* 7. Feed free regions from memblock into the buddy system. - * memblock knows about all reserved regions (firmware, kernel, - * page table pages, page_map). Everything else is free. */ - struct FeedCtx { - uint64 total_pages; - }; - FeedCtx ctx{0}; - - memblock_for_each_free( - [](uint64 base, uint64 size, void *arg) { - auto *c = static_cast(arg); - uint64 start_pfn = (base - memblock_get_mem_base()) / kPageSize; - uint64 end_pfn = start_pfn + size / kPageSize; - - /* Access page_map via the globals directly (they are in anon namespace now) */ - - uint64 pfn = start_pfn; - while (pfn < end_pfn) { - uint8 order = 0; - for (int o = kMaxOrder - 1; o >= 0; o--) { - uint64 block_size = 1ULL << o; - if ((pfn & (block_size - 1)) == 0 && pfn + block_size <= end_pfn) { - order = static_cast(o); - break; - } - } - - Page *page = &g_page_map[pfn]; - page->type = PageType::Free; - page->order = order; - page->refcount.store(0, __ATOMIC_RELAXED); - page->free.free_link.init(); - - /* Inline buddy_list_add since we're inside a lambda */ - list_node *head = &g_free_areas[order]; - list_node *node = &page->free.free_link; - node->next = head->next; - node->prev = head; - head->next->prev = node; - head->next = node; - - pfn += (1ULL << order); - c->total_pages += (1ULL << order); - } - }, - &ctx); - - kprintf("[pmm] buddy: %llu free pages (%llu MB)\n", ctx.total_pages, - (ctx.total_pages * kPageSize) / kMB); - - /* 8. Retire memblock — all future allocations go through PMM */ - memblock_retire(); -} - -PhysAddr pmm_get_mem_base() { return phys_addr(g_mem_base); } -uint64 pmm_get_mem_size() { return g_mem_size; } diff --git a/mm/slab.cc b/mm/slab.cc deleted file mode 100644 index 43d8c4a..0000000 --- a/mm/slab.cc +++ /dev/null @@ -1,321 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * slab.cc — SLUB allocator implementation - * - * Key design points: - * - Free object list is embedded in the objects themselves (first 8 bytes). - * - Per-page metadata lives in Page.slab (cache, obj_count, freelist). - * - Per-CPU "active page" avoids lock contention on the fast path. - * - partial_ list protected by per-KmemCache Spinlock. - * - PMM calls happen outside the lock to avoid lock ordering issues. - * - * Address note: the kernel may be running at physical addresses via - * identity mapping (before vmm_init). We handle PA/VA carefully: - * PMM gives us Page*, page_to_pa() gives PA, and we access page - * contents via pa_to_va() (higher-half VA, always mapped). - * - * Reference: docs/specs/slab.md - */ - -#include "slab.h" -#include -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Helpers */ -/* ------------------------------------------------------------------ */ - -/* - * Convert a Page* to the usable virtual address of the page's contents. - * Uses the higher-half mapping which is always active. - */ -static inline void* page_to_data_va(Page* page) -{ - return reinterpret_cast(page_to_va(page).raw); -} - -/* Round up x to the next multiple of align (align must be power of 2) */ -static inline uint32 align_up(uint32 x, uint32 align) -{ - return (x + align - 1) & ~(align - 1); -} - -/* ------------------------------------------------------------------ */ -/* Global size-class caches */ -/* ------------------------------------------------------------------ */ - -KmemCache g_size_caches[kNumSizeClasses]; - -/* ------------------------------------------------------------------ */ -/* KmemCache::init */ -/* ------------------------------------------------------------------ */ - -void KmemCache::init(const char* name, uint32 obj_size, uint32 obj_align) -{ - name_ = name; - obj_align_ = (obj_align < 8) ? 8 : obj_align; // minimum 8 for freelist ptr - obj_size_ = align_up((obj_size < 8) ? 8 : obj_size, obj_align_); - objs_per_slab_ = kPageSize / obj_size_; - - lock_.init(name); - partial_.init(); - - for (int i = 0; i < kMaxCpus; i++) - cpu_slab_[i].active = nullptr; -} - -/* ------------------------------------------------------------------ */ -/* KmemCache::new_slab — allocate and format a fresh slab page */ -/* ------------------------------------------------------------------ */ - -Page* KmemCache::new_slab() -{ - Page* page = pmm_alloc_page(); - if (!page) - return nullptr; - - page->type = PageType::Slab; - page->slab.cache = this; - page->slab.obj_count = 0; - - /* Build the embedded free list across all object slots */ - uint8* base = static_cast(page_to_data_va(page)); - void* head = nullptr; - - /* Chain objects from last to first so freelist order = low addr first */ - for (int i = static_cast(objs_per_slab_) - 1; i >= 0; i--) { - void* obj = base + i * obj_size_; - *reinterpret_cast(obj) = head; - head = obj; - } - page->slab.freelist = head; - - return page; -} - -/* ------------------------------------------------------------------ */ -/* Partial list management (lock must be held) */ -/* ------------------------------------------------------------------ */ - -Page* KmemCache::get_partial() -{ - /* - * Phase 1 simplification: no partial list tracking. - * The slow path always allocates a fresh page from PMM. - * Full pages stay alive (Page.slab.cache is valid for kfree). - * Empty pages are returned to PMM immediately. - * - * TODO: add list_node to Page.slab and implement partial tracking - * to avoid wasting partially-filled pages. - */ - (void)partial_; - return nullptr; -} - -void KmemCache::put_partial(Page* page) -{ - (void)page; -} - -void KmemCache::remove_partial(Page* page) -{ - (void)page; -} - -/* ------------------------------------------------------------------ */ -/* KmemCache::alloc */ -/* ------------------------------------------------------------------ */ - -void* KmemCache::alloc() -{ - bool was_on = arch::cpu::intr_enabled(); - arch::cpu::intr_off(); - - uint64 cpu = arch::cpu::id(); - Page* active = cpu_slab_[cpu].active; - - /* Fast path: pop from active page's freelist */ - if (active && active->slab.freelist) { - void* obj = active->slab.freelist; - active->slab.freelist = *reinterpret_cast(obj); - active->slab.obj_count++; - if (was_on) arch::cpu::intr_on(); - return obj; - } - - /* Slow path: need a new active page */ - - /* If current active is full, detach it (it stays as Slab state, - * cache pointer still valid for kfree to find it) */ - if (active && !active->slab.freelist) { - cpu_slab_[cpu].active = nullptr; - } - - if (was_on) arch::cpu::intr_on(); - - /* Try to get a partial page or allocate a fresh one. - * PMM call happens without any lock held. */ - Page* new_page = new_slab(); - if (!new_page) - return nullptr; - - /* Install as new active page */ - was_on = arch::cpu::intr_enabled(); - arch::cpu::intr_off(); - - /* Another interrupt handler might have set a new active while we - * were allocating. If so, put ours aside (simplified: just use ours). */ - cpu_slab_[cpu].active = new_page; - - void* obj = new_page->slab.freelist; - new_page->slab.freelist = *reinterpret_cast(obj); - new_page->slab.obj_count++; - - if (was_on) arch::cpu::intr_on(); - return obj; -} - -/* ------------------------------------------------------------------ */ -/* KmemCache::free */ -/* ------------------------------------------------------------------ */ - -void KmemCache::free(void* obj) -{ - if (!obj) - return; - - /* Find the Page for this object's page */ - uint64 obj_addr = reinterpret_cast(obj); - - /* Convert VA to PA. Like pmm.cc, handle both PA and VA cases. */ - uint64 obj_pa = va_to_pa(virt_addr(obj_addr)).raw; - uint64 page_pa = obj_pa & ~(kPageSize - 1); - Page* page = pa_to_page(phys_addr(page_pa)); - - if (page->type != PageType::Slab || page->slab.cache != this) - kernel_panic("slab free: object does not belong to this cache"); - - bool was_on = arch::cpu::intr_enabled(); - arch::cpu::intr_off(); - - /* Push object back onto the page's freelist */ - *reinterpret_cast(obj) = page->slab.freelist; - page->slab.freelist = obj; - page->slab.obj_count--; - - /* If page is now completely empty, return it to PMM */ - if (page->slab.obj_count == 0) { - /* If this page is our active, clear it */ - uint64 cpu = arch::cpu::id(); - if (cpu_slab_[cpu].active == page) - cpu_slab_[cpu].active = nullptr; - - if (was_on) arch::cpu::intr_on(); - - /* Return page to PMM */ - page->slab.cache = nullptr; - page->slab.freelist = nullptr; - pmm_free_page(page); - return; - } - - if (was_on) arch::cpu::intr_on(); -} - -/* ------------------------------------------------------------------ */ -/* Public free-function API */ -/* ------------------------------------------------------------------ */ - -/* Find the smallest size class >= size */ -static KmemCache* find_cache(uint32 size) -{ - for (int i = 0; i < kNumSizeClasses; i++) { - if (kSizeClasses[i] >= size) - return &g_size_caches[i]; - } - return nullptr; // Too large for slab -} - -void* kmalloc(uint32 size) -{ - if (size == 0) - return nullptr; - - /* Large allocation: fall back to PMM directly */ - if (size > kSizeClasses[kNumSizeClasses - 1]) { - uint8 order = 0; - uint64 needed = (size + kPageSize - 1) / kPageSize; - while ((1ULL << order) < needed) - order++; - Page* page = pmm_alloc_pages(order); - if (!page) - return nullptr; - return reinterpret_cast(pa_to_va(page_to_pa(page)).raw); - } - - KmemCache* cache = find_cache(size); - if (!cache) - return nullptr; - return cache->alloc(); -} - -void kfree(void* ptr) -{ - if (!ptr) - return; - - uint64 addr = reinterpret_cast(ptr); - uint64 pa = va_to_pa(virt_addr(addr)).raw; - uint64 page_pa = pa & ~(kPageSize - 1); - Page* page = pa_to_page(phys_addr(page_pa)); - - if (page->type == PageType::Slab) { - KmemCache* cache = page->slab.cache; - if (!cache) - kernel_panic("kfree: slab page has null cache"); - cache->free(ptr); - } else if (page->type == PageType::Allocated) { - /* Large allocation — return directly to PMM */ - pmm_free_pages(page, page->order); - } else { - kernel_panic("kfree: invalid page state"); - } -} - -/* ------------------------------------------------------------------ */ -/* C++ operator new / delete */ -/* ------------------------------------------------------------------ */ - -/* Use decltype(sizeof(0)) instead of size_t to match the compiler's - * built-in expectation for operator new (unsigned long vs unsigned long long). */ -using __sz = decltype(sizeof(0)); - -void* operator new(__sz size) { return kmalloc(static_cast(size)); } -void* operator new[](__sz size) { return kmalloc(static_cast(size)); } - -void operator delete(void* ptr) noexcept { kfree(ptr); } -void operator delete[](void* ptr) noexcept { kfree(ptr); } -void operator delete(void* ptr, __sz) noexcept { kfree(ptr); } -void operator delete[](void* ptr, __sz) noexcept { kfree(ptr); } - -/* ------------------------------------------------------------------ */ -/* Initialization */ -/* ------------------------------------------------------------------ */ - -void slab_init() -{ - for (int i = 0; i < kNumSizeClasses; i++) { - /* Build a name string like "kmalloc-32" */ - static const char* names[kNumSizeClasses] = { - "kmalloc-8", "kmalloc-16", "kmalloc-32", - "kmalloc-64", "kmalloc-128", "kmalloc-256", - "kmalloc-512", "kmalloc-1024","kmalloc-2048" - }; - g_size_caches[i].init(names[i], kSizeClasses[i], 8); - } -} diff --git a/mm/slab.h b/mm/slab.h deleted file mode 100644 index 909ee62..0000000 --- a/mm/slab.h +++ /dev/null @@ -1,83 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#pragma once - -/* - * SLUB Allocator — module-private header - * - * SLUB = Simple List of Unfull Blocks. - * Metadata lives in Page descriptors (no per-page Slab header). - * Free object list is embedded inside the objects themselves. - * Per-CPU "active page" eliminates lock contention on the fast path. - * - * Reference: docs/specs/slab.md - */ - -#include -#include -#include -#include -#include - -/* Size classes: 8, 16, 32, 64, 128, 256, 512, 1024, 2048 */ -inline constexpr int kNumSizeClasses = 9; -inline constexpr uint32 kSizeClasses[kNumSizeClasses] = { - 8, 16, 32, 64, 128, 256, 512, 1024, 2048 -}; - -/* Per-CPU active slab page pointer */ -struct PerCpuSlab { - Page* active; // Currently used slab page (nullptr if none) -}; - -/* - * KmemCache — manages a pool of fixed-size objects. - * - * Lock contract: - * lock_ protects partial_ list only. - * Per-CPU cpu_slab_ access requires interrupts disabled. - * PMM calls happen outside lock_ to avoid lock ordering issues. - */ -class KmemCache { -public: - KmemCache() = default; - - // Explicit init (Placement New / BSS pattern) - void init(const char* name, uint32 obj_size, uint32 obj_align); - - // Allocate one object. Returns nullptr on OOM. - void* alloc(); - - // Free one object back to its owning page. - void free(void* obj); - - const char* name() const { return name_; } - uint32 obj_size() const { return obj_size_; } - -private: - // Get a partially-filled page from the partial list (lock must be held) - Page* get_partial(); - - // Put a page onto the partial list (lock must be held) - void put_partial(Page* page); - - // Remove a page from the partial list (lock must be held) - void remove_partial(Page* page); - - // Allocate a new page from PMM and format it as a slab - Page* new_slab(); - - Spinlock lock_; // Protects partial_ only - list_node partial_; // Partially-filled slab pages - - PerCpuSlab cpu_slab_[kMaxCpus]; // Per-CPU active page - - const char* name_ = "uninit"; - uint32 obj_size_ = 0; // Aligned object size (bytes) - uint32 obj_align_ = 0; // Alignment requirement - uint32 objs_per_slab_ = 0; // Objects per 4KB page -}; - -/* Global size-class caches */ -extern KmemCache g_size_caches[kNumSizeClasses]; diff --git a/mm/tlb.cc b/mm/tlb.cc deleted file mode 100644 index b7a8ba7..0000000 --- a/mm/tlb.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * tlb.cc — TLB shootdown implementation - * - * Uses RISC-V SBI Remote Fence extension to perform cross-hart - * TLB invalidation. SBI firmware handles the IPI delivery and - * synchronization — the call blocks until all target harts have - * completed their local sfence.vma. - * - * When a VmSpace is provided, we use its cpu_mask to target only - * the CPUs that have this address space loaded in satp. This avoids - * unnecessary IPI storms on unrelated cores. - * - * Reference: docs/specs/linux_abi_mm_plan.md §SMP §2.1 - */ - -#include -#include -#include -#include -#include -#include - -/* - * If a shootdown range exceeds this many pages, do a full flush - * instead of per-page invalidation. - */ -static constexpr uint64 kShootdownPageThreshold = 32; - -/* - * Build a cpu mask for all online CPUs (fallback when mm is null). - */ -namespace { -uint64 all_cpus_mask() -{ - uint64 mask = 0; - for (uint32 i = 0; i < kMaxCpus; i++) { - mask |= (1ULL << i); - } - return mask; -} - -/* - * Get the target cpu mask: use mm->cpu_mask when available, - * fall back to all_cpus_mask for kernel address space (mm == nullptr). - */ -uint64 target_cpu_mask(VmSpace* mm) -{ - if (mm) { - uint64 mask = mm->cpu_mask.load(__ATOMIC_RELAXED); - /* Always include our own CPU — we may still have stale TLB */ - mask |= (1ULL << arch::cpu::id()); - return mask; - } - return all_cpus_mask(); -} -} // namespace - -void tlb_shootdown_range(VmSpace* mm, uint64 start, uint64 end) -{ - if (start >= end) { - return; - } - - uint64 num_pages = (end - start) / kPageSize; - uint64 cpu_mask = target_cpu_mask(mm); - - if (num_pages > kShootdownPageThreshold) { - /* Full flush on target CPUs via arch backend */ - arch::tlb::flush_remote(cpu_mask, 0, ~0ULL); - return; - } - - /* Range flush on target CPUs via arch backend */ - arch::tlb::flush_remote(cpu_mask, start, end - start); -} - -void tlb_shootdown_page(VmSpace* mm, uint64 va) -{ - uint64 cpu_mask = target_cpu_mask(mm); - arch::tlb::flush_remote(cpu_mask, va, kPageSize); -} - -void tlb_shootdown_all() -{ - uint64 cpu_mask = all_cpus_mask(); - arch::tlb::flush_remote(cpu_mask, 0, ~0ULL); -} diff --git a/mm/vma.cc b/mm/vma.cc deleted file mode 100644 index da89e08..0000000 --- a/mm/vma.cc +++ /dev/null @@ -1,640 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * vma.cc — Virtual Memory Area management (MI layer) - * - * Manages user address spaces using a red-black tree of VMA regions. - * Implements demand paging: vmm_map_user records intent only; - * physical pages are allocated on page fault via vmm_handle_page_fault. - * - * MI/MD separation: this file NEVER references pmap::PTE_* constants. - * Permission translation is delegated to pmap::vm_perm_to_pte(). - * - * Reference: docs/specs/vmm.md - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Rbtree callbacks for VMA interval tree */ -/* ------------------------------------------------------------------ */ - -static bool vma_less(struct rb_node* node, const struct rb_node* parent) { - VmAreaStruct* n = reinterpret_cast( - reinterpret_cast(node) - __builtin_offsetof(VmAreaStruct, rb)); - const VmAreaStruct* p = reinterpret_cast( - reinterpret_cast(parent) - __builtin_offsetof(VmAreaStruct, rb)); - return n->start < p->start; -} - -static int vma_cmp(const void* key, const struct rb_node* node) { - uint64 addr = *static_cast(key); - const VmAreaStruct* n = reinterpret_cast( - reinterpret_cast(node) - __builtin_offsetof(VmAreaStruct, rb)); - if (addr < n->start) return -1; - if (addr >= n->end) return 1; - return 0; -} - -static VmAreaStruct* node_to_vma(struct rb_node* node) -{ - return reinterpret_cast( - reinterpret_cast(node) - __builtin_offsetof(VmAreaStruct, rb)); -} - -static uint64 align_up_any(uint64 value, uint64 align) -{ - if (align == 0) { - return value; - } - return ((value + align - 1) / align) * align; -} - -static bool range_overlaps(uint64 a_start, uint64 a_end, - uint64 b_start, uint64 b_end) -{ - return a_start < b_end && b_start < a_end; -} - - - -static bool vma_overlaps_locked(VmSpace* space, uint64 start, uint64 end) -{ - struct rb_node* node = rb_first(&space->vma_tree); - while (node) { - VmAreaStruct* vma = node_to_vma(node); - if (range_overlaps(start, end, vma->start, vma->end)) { - return true; - } - node = rb_next(node); - } - return false; -} - -static bool vma_range_covered_locked(VmSpace* space, uint64 start, uint64 end) -{ - uint64 cursor = start; - struct rb_node* node = rb_first(&space->vma_tree); - while (node && cursor < end) { - VmAreaStruct* vma = node_to_vma(node); - if (vma->end <= cursor) { - node = rb_next(node); - continue; - } - if (vma->start > cursor) { - return false; - } - if (vma->end > cursor) { - cursor = vma->end; - } - node = rb_next(node); - } - return cursor >= end; -} - -static void vma_try_merge_neighbors_locked(VmSpace* space, VmAreaStruct* vma) -{ - struct rb_node* prev_node = rb_prev(&vma->rb); - if (prev_node) { - VmAreaStruct* prev = node_to_vma(prev_node); - if (prev->end == vma->start && prev->perm == vma->perm) { - prev->end = vma->end; - rb_erase(&vma->rb, &space->vma_tree); - delete vma; - vma = prev; - } - } - - struct rb_node* next_node = rb_next(&vma->rb); - if (next_node) { - VmAreaStruct* next = node_to_vma(next_node); - if (vma->end == next->start && vma->perm == next->perm) { - vma->end = next->end; - rb_erase(&next->rb, &space->vma_tree); - delete next; - } - } -} - -static int vma_split_locked(VmSpace* space, VmAreaStruct* vma, uint64 split) -{ - if (split <= vma->start || split >= vma->end) { - return 0; - } - - VmAreaStruct* right = new VmAreaStruct; - if (!right) { - return -ENOMEM; - } - - right->start = split; - right->end = vma->end; - right->perm = vma->perm; - right->mm = space; - - vma->end = split; - rb_add(&right->rb, &space->vma_tree, vma_less); - return 0; -} - -static int vma_split_range_locked(VmSpace* space, uint64 start, uint64 end) -{ - if (end <= start) { - return 0; - } - - struct rb_node* start_node = rb_find(&start, &space->vma_tree, vma_cmp); - if (!start_node) { - return -ENOMEM; - } - VmAreaStruct* start_vma = node_to_vma(start_node); - int ret = vma_split_locked(space, start_vma, start); - if (ret < 0) { - return ret; - } - - uint64 end_key = end - 1; - struct rb_node* end_node = rb_find(&end_key, &space->vma_tree, vma_cmp); - if (!end_node) { - return -ENOMEM; - } - VmAreaStruct* end_vma = node_to_vma(end_node); - return vma_split_locked(space, end_vma, end); -} - -/* ------------------------------------------------------------------ */ -/* VmSpace lifecycle */ -/* ------------------------------------------------------------------ */ - -VmSpace* VmSpace::create() { - VmSpace* space = new VmSpace; - if (!space) return nullptr; - - space->root_pa = pmap::create(); - if (!space->root_pa) { - delete space; - return nullptr; - } - - space->vma_tree = RB_ROOT; - space->lock.init("VmSpace"); - space->refcount.store(1, __ATOMIC_RELAXED); - space->brk_start = 0; - space->brk_end = 0; - return space; -} - -void VmSpace::incref() { - refcount.fetch_add(1, __ATOMIC_RELAXED); -} - -void VmSpace::put() { - if (refcount.fetch_sub(1, __ATOMIC_ACQ_REL) == 1) { - destroy(); - } -} - -void VmSpace::destroy() { - /* Drain VMA tree under lock, then release BEFORE delete this */ - lock.acquire(); - uint64 root = root_pa; - struct rb_node* node = rb_first(&vma_tree); - while (node) { - VmAreaStruct* vma = reinterpret_cast( - reinterpret_cast(node) - __builtin_offsetof(VmAreaStruct, rb)); - - /* Decref and dec mapcount for all mapped physical pages */ - for (uint64 addr = vma->start; addr < vma->end; addr += kPageSize) { - uint64 pa; - if (pmap::lookup(root, addr, &pa)) { - Page* pg = pa_to_page(phys_addr(pa)); - page_dec_mapcount(pg); - page_decref(pg); - } - } - - node = rb_next(node); - rb_erase(&vma->rb, &vma_tree); - delete vma; - } - lock.release(); - - /* Destroy hardware page tables outside the lock */ - pmap::destroy(root); - - /* Finally free VmSpace itself */ - delete this; -} - -/* ------------------------------------------------------------------ */ -/* Public API: VMA manipulation */ -/* ------------------------------------------------------------------ */ - -int vmm_map_user(VmSpace* space, uint64 va, uint64 len, uint64 perm) { - if (!space) return -EINVAL; - - va = page_align_down(va); - len = page_align_up(len); - if (len == 0) return 0; - if (va < kUserVaBase) return -EINVAL; - if (va >= kUserVaLimit) return -EINVAL; - if (va + len < va || va + len > kUserVaLimit) return -EINVAL; - - VmAreaStruct* vma = new VmAreaStruct; - if (!vma) return -ENOMEM; - vma->start = va; - vma->end = va + len; - vma->perm = perm | VM_USER; // Enforce user-mode access (MI flag) - vma->mm = space; - - LockGuard guard(space->lock); - if (vma_overlaps_locked(space, vma->start, vma->end)) { - delete vma; - return -EINVAL; - } - rb_add(&vma->rb, &space->vma_tree, vma_less); - vma_try_merge_neighbors_locked(space, vma); - return 0; -} - -int vmm_unmap_user(VmSpace* space, uint64 va, uint64 len) { - if (!space) return -EINVAL; - va = page_align_down(va); - len = page_align_up(len); - if (len == 0) return 0; - if (va < kUserVaBase) return -EINVAL; - if (va >= kUserVaLimit) return -EINVAL; - if (va + len < va || va + len > kUserVaLimit) return -EINVAL; - uint64 end = va + len; - - LockGuard guard(space->lock); - struct rb_node* node = rb_first(&space->vma_tree); - while (node) { - VmAreaStruct* vma = node_to_vma(node); - struct rb_node* next = rb_next(node); - - if (vma->end <= va) { - node = next; - continue; - } - if (vma->start >= end) { - break; - } - - uint64 unmap_start = (vma->start > va) ? vma->start : va; - uint64 unmap_end = (vma->end < end) ? vma->end : end; - - if (unmap_start < unmap_end) { - for (uint64 addr = unmap_start; addr < unmap_end; addr += kPageSize) { - uint64 pa; - if (pmap::lookup(space->root_pa, addr, &pa)) { - pmap::unmap(space->root_pa, addr); - Page* pg = pa_to_page(phys_addr(pa)); - page_dec_mapcount(pg); - page_decref(pg); - } - } - } - - if (unmap_start == vma->start && unmap_end == vma->end) { - rb_erase(&vma->rb, &space->vma_tree); - delete vma; - } else if (unmap_start == vma->start) { - rb_erase(&vma->rb, &space->vma_tree); - vma->start = unmap_end; - rb_add(&vma->rb, &space->vma_tree, vma_less); - } else if (unmap_end == vma->end) { - vma->end = unmap_start; - } else { - VmAreaStruct* right = new VmAreaStruct; - if (!right) { - return -ENOMEM; - } - right->start = unmap_end; - right->end = vma->end; - right->perm = vma->perm; - right->mm = space; - - vma->end = unmap_start; - rb_add(&right->rb, &space->vma_tree, vma_less); - break; - } - - node = next; - } - return 0; -} - -int vmm_protect_user(VmSpace* space, uint64 va, uint64 len, uint64 perm) -{ - if (!space) return -EINVAL; - va = page_align_down(va); - len = page_align_up(len); - if (len == 0) return -EINVAL; - if (va < kUserVaBase) return -EINVAL; - if (va >= kUserVaLimit) return -EINVAL; - if (va + len < va || va + len > kUserVaLimit) return -EINVAL; - - uint64 end = va + len; - - LockGuard guard(space->lock); - if (!vma_range_covered_locked(space, va, end)) { - return -ENOMEM; - } - int ret = vma_split_range_locked(space, va, end); - if (ret < 0) { - return ret; - } - - bool tlb_flush_needed = false; - struct rb_node* node = rb_find(&va, &space->vma_tree, vma_cmp); - while (node) { - VmAreaStruct* vma = node_to_vma(node); - if (vma->start >= end) { - break; - } - if (vma->end <= va) { - node = rb_next(node); - continue; - } - - vma->perm = (perm | VM_USER); - - for (uint64 addr = vma->start; addr < vma->end; addr += kPageSize) { - uint64 pa; - if (!pmap::lookup(space->root_pa, addr, &pa)) { - continue; - } - - if (perm == 0) { - Page* pg = pa_to_page(phys_addr(pa)); - page_dec_mapcount(pg); - page_decref(pg); - pmap::unmap(space->root_pa, addr); - tlb_flush_needed = true; - continue; - } - - uint64 pte_perm = pmap::vm_perm_to_pte(vma->perm); - if ((vma->perm & VM_WRITE) && pmap::is_cow(space->root_pa, addr)) { - pte_perm &= ~pmap::PTE_W; - pte_perm |= pmap::PTE_COW; - } - - int ret = pmap::protect(space->root_pa, addr, pte_perm); - if (ret < 0) { - return ret; - } - tlb_flush_needed = true; - } - - node = rb_next(node); - } - - if (tlb_flush_needed) { - tlb_shootdown_range(space, va, end); - } - return 0; -} - -uint64 mm_find_free_va(VmSpace* space, uint64 length, uint64 align) -{ - if (!space) return 0; - length = page_align_up(length); - if (length == 0) return 0; - if (align < kPageSize) align = kPageSize; - - LockGuard guard(space->lock); - - /* Linux: arch_get_unmapped_area() starts from mm->mmap_base. - * RISC-V: TASK_UNMAPPED_BASE = PAGE_ALIGN(TASK_SIZE / 3). - * Fall back to kUserVaBase if mmap_base not set (kernel VmSpaces). */ - uint64 base = space->mmap_base ? space->mmap_base : kUserVaBase; - uint64 cursor = align_up_any(base, align); - struct rb_node* node = rb_first(&space->vma_tree); - while (node) { - VmAreaStruct* vma = node_to_vma(node); - if (cursor <= vma->start) { - if (cursor > kUserVaLimit - length) { - return 0; - } - if (cursor + length <= vma->start) { - return cursor; - } - } - if (cursor < vma->end) { - cursor = vma->end; - } - cursor = align_up_any(cursor, align); - node = rb_next(node); - } - - if (cursor > kUserVaLimit - length) { - return 0; - } - return cursor; -} - -bool vma_range_covered(VmSpace* space, uint64 start, uint64 end) -{ - if (!space) return false; - start = page_align_down(start); - end = page_align_up(end); - if (end <= start) return true; - - LockGuard guard(space->lock); - return vma_range_covered_locked(space, start, end); -} - -/* ------------------------------------------------------------------ */ -/* Page fault handler (demand paging) */ -/* ------------------------------------------------------------------ */ - -static bool vma_allows(const VmAreaStruct* vma, VmFaultCause cause) -{ - switch (cause) { - case VmFaultCause::Read: - return (vma->perm & VM_READ) != 0; - case VmFaultCause::Write: - return (vma->perm & VM_WRITE) != 0; - case VmFaultCause::Exec: - return (vma->perm & VM_EXEC) != 0; - default: - return false; - } -} - -int vmm_handle_page_fault(VmSpace* space, uint64 fault_addr, VmFaultCause cause) { - if (!space) return -EINVAL; - - uint64 aligned_addr = page_align_down(fault_addr); - - LockGuard guard(space->lock); - struct rb_node* node = rb_find(&fault_addr, &space->vma_tree, vma_cmp); - if (!node) { - return -EFAULT; // No VMA covers this address → segfault - } - - VmAreaStruct* vma = reinterpret_cast( - reinterpret_cast(node) - __builtin_offsetof(VmAreaStruct, rb)); - - if (!vma_allows(vma, cause)) { - return -EFAULT; - } - - /* Check if page is already mapped */ - uint64 paddr; - if (pmap::lookup(space->root_pa, aligned_addr, &paddr)) { - if (cause == VmFaultCause::Write && pmap::is_cow(space->root_pa, aligned_addr)) { - /* Store Page Fault on a COW page */ - Page* page = pmm_alloc_page(); - if (!page) return -ENOMEM; - uint64 new_pa = page_to_pa(page).raw; - - /* Copy page contents */ - uint8* dst = reinterpret_cast(pa_to_va(phys_addr(new_pa)).raw); - const uint8* src = reinterpret_cast(pa_to_va(phys_addr(paddr)).raw); - for (uint64 i = 0; i < kPageSize; i++) { - dst[i] = src[i]; - } - - /* Remap with write permission, clearing COW */ - uint64 pte_perm = pmap::vm_perm_to_pte(vma->perm); - if (pmap::map(space->root_pa, aligned_addr, new_pa, pte_perm) != 0) { - pmm_free_page(page); - return -ENOMEM; - } - - /* New page gets mapcount = 1 (we just mapped it) */ - page_inc_mapcount(page); - - /* Decrement mapcount and refcount of old page */ - Page* old_page = pa_to_page(phys_addr(paddr)); - page_dec_mapcount(old_page); - page_decref(old_page); - - /* Flush TLB to remove old read-only cached translation */ - tlb_shootdown_page(space, aligned_addr); - return 0; - } - /* DEBUG: page already mapped but still faulting — dump PTE */ - { - uint64 cur_satp; - asm volatile("csrr %0, satp" : "=r"(cur_satp)); - printk(KERN_ERR "fault: va=%llx pa=%llx cause=%d pte=%llx satp=%llx root=%llx\n", - aligned_addr, paddr, static_cast(cause), - pmap::lookup_pte(space->root_pa, aligned_addr), - cur_satp, space->root_pa); - } - return 0; // Already mapped, maybe read fault on existing page - } - - /* Allocate physical page and zero it. - * Linux: do_anonymous_page() uses alloc_zeroed_user_highpage_movable(). - * Anonymous pages MUST be zeroed — userspace expects MAP_ANONYMOUS - * pages to contain all zeros (POSIX requirement). */ - Page* page = pmm_alloc_page(); - if (!page) return -ENOMEM; - - uint64 pa = page_to_pa(page).raw; - - /* Zero the page before mapping it to userspace */ - /* Zero the page before mapping it to userspace */ - uint8* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - for (uint64 i = 0; i < kPageSize; i++) kva[i] = 0; - - /* Translate MI permission flags to hardware PTE bits (MD layer) */ - uint64 pte_perm = pmap::vm_perm_to_pte(vma->perm); - - if (pmap::map(space->root_pa, aligned_addr, pa, pte_perm) != 0) { - pmm_free_page(page); - return -ENOMEM; - } - - /* Initial mapping: refcount is already 1 from pmm_alloc_page. - * Set mapcount = 1 to track this PTE mapping. */ - page_inc_mapcount(page); - - return 0; -} - -/* ------------------------------------------------------------------ */ -/* Fork / Clone (COW infrastructure) */ -/* ------------------------------------------------------------------ */ - -VmSpace* vmm_clone(VmSpace* parent) { - if (!parent) return nullptr; - - VmSpace* child = VmSpace::create(); - if (!child) return nullptr; - - child->brk_start = parent->brk_start; - child->brk_end = parent->brk_end; - - LockGuard parent_guard(parent->lock); - - struct rb_node* node = rb_first(&parent->vma_tree); - while (node) { - VmAreaStruct* parent_vma = reinterpret_cast( - reinterpret_cast(node) - __builtin_offsetof(VmAreaStruct, rb)); - - VmAreaStruct* child_vma = new VmAreaStruct; - if (!child_vma) { - child->destroy(); - return nullptr; - } - child_vma->start = parent_vma->start; - child_vma->end = parent_vma->end; - child_vma->perm = parent_vma->perm; - child_vma->mm = child; - - /* Copy pages and mark COW if writable */ - for (uint64 va = child_vma->start; va < child_vma->end; va += kPageSize) { - uint64 pa; - if (pmap::lookup(parent->root_pa, va, &pa)) { - /* Make parent COW if it was writable */ - if (child_vma->perm & VM_WRITE) { - pmap::make_cow(parent->root_pa, va); - /* Flush TLB for parent since we reduced permissions */ - tlb_shootdown_page(parent, va); - } - - /* Map in child as COW or read-only */ - uint64 pte_perm = pmap::vm_perm_to_pte(child_vma->perm); - if (child_vma->perm & VM_WRITE) { - pte_perm &= ~pmap::PTE_W; - pte_perm |= pmap::PTE_COW; - } - - if (pmap::map(child->root_pa, va, pa, pte_perm) != 0) { - /* If map fails, we leak what we did in this loop for now, - * but child->destroy() will clean it up safely since - * we increment refcounts as we go. */ - delete child_vma; - child->destroy(); - return nullptr; - } - - /* Increment physical page refcount and mapcount */ - Page* shared_page = pa_to_page(phys_addr(pa)); - page_incref(shared_page); - page_inc_mapcount(shared_page); - } - } - - rb_add(&child_vma->rb, &child->vma_tree, vma_less); - node = rb_next(node); - } - - return child; -} diff --git a/mm/vmm.cc b/mm/vmm.cc deleted file mode 100644 index 51617e3..0000000 --- a/mm/vmm.cc +++ /dev/null @@ -1,235 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * vmm.cc — Virtual Memory Manager (Phase 1: Kernel Page Table) - * - * Builds a fine-grained kernel page table, activates it, and retires - * the early_pgdir identity mapping from entry.S. - * - * With memblock integration, the initialization order is: - * memblock_init → vmm_init (allocates page_map from memblock, - * maps vmemmap, activates page table) → pmm_init (buddy system - * starts with page_map already at vmemmap VA — no relocation). - * - * Reference: docs/specs/vmm.md - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Linker-exported section boundaries (virtual addresses) */ -extern "C" char _stext[], _etext[]; -extern "C" char _srodata[], _erodata[]; -extern "C" char _sdata[], _edata[]; -extern "C" char _sbss[], _ebss[]; -extern "C" char _kernel_end[]; - -/* Global kernel page table root PA — external linkage for task_exit */ -uint64 g_kernel_pgtbl = 0; - -namespace { - -/* VMM exports for PMM: page_map location after vmemmap mapping. */ -uint64 g_vmemmap_page_map_pa = 0; -uint64 g_vmemmap_page_map_size = 0; -uint64 g_vmemmap_num_pages = 0; - -/* Convert a linker symbol to PA (kernel is executing in higher-half VA). */ -inline uint64 sym_to_pa(const void *sym) { - return boot_va_to_pa(virt_addr(reinterpret_cast(sym))).raw; -} - -/* Map a PA range into the kernel page table via the direct map. */ -void map_range(uint64 root, uint64 pa_start, uint64 pa_end, - uint64 perm) { - for (uint64 pa = pa_start; pa < pa_end; pa += kPageSize) { - uint64 va = pa_to_va(phys_addr(pa)).raw; - int ret = pmap::map(root, va, pa, perm | pmap::PTE_G); - if (ret != 0) { - kernel_panic("vmm_init: pmap::map failed"); - } - } -} - -/* Map a PA range into the kernel page table at the fixed linked VA. */ -void map_range_linked(uint64 root, uint64 pa_start, uint64 pa_end, - uint64 perm) { - for (uint64 pa = pa_start; pa < pa_end; pa += kPageSize) { - uint64 va = boot_pa_to_va(phys_addr(pa)).raw; - int ret = pmap::map(root, va, pa, perm | pmap::PTE_G); - if (ret != 0) { - kernel_panic("vmm_init: pmap::map (linked) failed"); - } - } -} - -/* Map a PA range to an explicit VA base, using 2MB pages where possible. */ -void map_range_at_huge(uint64 root, uint64 va_base, uint64 pa_start, - uint64 pa_end, uint64 perm) { - constexpr uint64 k2MB = 2ULL * 1024 * 1024; - uint64 pa = pa_start; - uint64 va = va_base; - - /* Map 2MB-aligned chunks with mega pages */ - while (pa + k2MB <= pa_end) { - if ((va & (k2MB - 1)) == 0 && (pa & (k2MB - 1)) == 0) { - int ret = pmap::map_2mb(root, va, pa, perm | pmap::PTE_G); - if (ret != 0) { - kernel_panic("vmm_init: pmap::map_2mb failed"); - } - pa += k2MB; - va += k2MB; - } else { - break; - } - } - - /* Map remaining 4KB tail */ - while (pa < pa_end) { - int ret = pmap::map(root, va, pa, perm | pmap::PTE_G); - if (ret != 0) { - kernel_panic("vmm_init: vmemmap 4KB pmap::map failed"); - } - pa += kPageSize; - va += kPageSize; - } -} - -} // namespace - -uint64 vmm_get_page_map_pa() { return g_vmemmap_page_map_pa; } -uint64 vmm_get_page_map_size() { return g_vmemmap_page_map_size; } -uint64 vmm_get_num_pages() { return g_vmemmap_num_pages; } - -void vmm_init() { - /* 1. Allocate new root page table (from memblock) */ - uint64 root = pmap::create(); - if (!root) { - kernel_panic("vmm_init: failed to create root page table"); - } - - /* 2. Compute PA boundaries of each kernel section */ - uint64 text_start = page_align_down(sym_to_pa(_stext)); - uint64 text_end = page_align_up(sym_to_pa(_etext)); - uint64 ro_start = page_align_down(sym_to_pa(_srodata)); - uint64 ro_end = page_align_up(sym_to_pa(_erodata)); - uint64 data_start = page_align_down(sym_to_pa(_sdata)); - uint64 bss_end = page_align_up(sym_to_pa(_ebss)); - - /* Memory extent from memblock */ - uint64 mem_base = memblock_get_mem_base(); - uint64 mem_size = memblock_get_mem_size(); - uint64 mem_end = mem_base + mem_size; - - /* 3. Map kernel image at FIXED linked VA. - * - * Kernel text/data are linked at the bootstrap higher-half addresses - * (kDirectMapBaseDefault + PA). They must remain executable/readable at - * those addresses until full kernel-image relocation is implemented. - */ - map_range_linked(root, text_start, text_end, pmap::PTE_R | pmap::PTE_X); - - /* 4. Map .rodata (R) at fixed linked VA. - * We map [_srodata, _sdata) so that the .lume.reloc section (which - * sits in its own padded output section between _erodata and _sdata) - * is also covered. Relocator only reads it during early boot, but - * mapping it keeps post-vmm accesses to __lume_reloc_* symbols sane. */ - map_range_linked(root, ro_start, page_align_down(sym_to_pa(_sdata)), - pmap::PTE_R); - - /* 5. Map .data + .bss (RW) at fixed linked VA */ - map_range_linked(root, data_start, bss_end, pmap::PTE_R | pmap::PTE_W); - - /* 6. Map usable physical RAM into the KASLR-slid direct map. - * - * The direct map provides pa_to_va() / va_to_pa() for the physical - * address space. We map from kPhysStart (the kernel's linked load - * address), skipping [mem_base, kPhysStart) because that region is - * PMP-protected firmware (OpenSBI) — S-mode cannot access it. - * - * Linux does the same on RISC-V: the linear map covers only the - * usable RAM range, not firmware-reserved regions. - * - * Uses 2MB huge pages for efficiency (64 entries for 128MB vs 32K). - */ - uint64 dm_start = kPhysStart; - if (dm_start < mem_base) { - dm_start = mem_base; - } - uint64 dm_va_base = pa_to_va(phys_addr(dm_start)).raw; - map_range_at_huge(root, dm_va_base, dm_start, mem_end, - pmap::PTE_R | pmap::PTE_W); - - /* 7. Allocate page_map from memblock (top of RAM) and map at VMEMMAP. - * - * Since memblock is active (PMM not yet initialized), pmap::map - * allocates page table pages from memblock too. page_map starts - * life at the vmemmap VA — no relocation ever needed. - */ - uint64 num_pages = mem_size / kPageSize; - uint64 page_map_bytes = num_pages * sizeof(Page); - uint64 page_map_span = page_align_up(page_map_bytes); - uint64 page_map_pa = memblock_alloc_top(page_map_span, kPageSize); - - if (!page_map_pa) { - kernel_panic("vmm_init: memblock failed to allocate page_map"); - } - - kprintf("[vmm] vmemmap: %llu pages, %llu KB at PA 0x%llx\n", num_pages, - page_map_span / 1024, page_map_pa); - - /* Map page_map at vmemmap_base from KaslrLayout (randomised by KASLR), using 2MB pages where possible */ - map_range_at_huge(root, arch::kaslr_layout_get().vmemmap_base, page_map_pa, - page_map_pa + page_map_span, pmap::PTE_R | pmap::PTE_W); - - /* Export for pmm_init() */ - g_vmemmap_page_map_pa = page_map_pa; - g_vmemmap_page_map_size = page_map_bytes; - g_vmemmap_num_pages = num_pages; - - /* 8. Pre-map console MMIO before page table switch */ - g_kernel_pgtbl = root; - console_init(); - - /* 9. Activate the new page table */ - pmap::activate(root); - - /* Console MMIO access must now use runtime (KASLR) direct-map base. */ - console_use_runtime_mapping(); - - kprintf("[vmm] vmm_init complete (vmemmap at 0x%llx)\n", arch::kaslr_layout_get().vmemmap_base); -} - -void vmm_init_ap() { - if (!g_kernel_pgtbl) { - kernel_panic("vmm_init_ap: kernel page table not ready"); - } - pmap::activate(g_kernel_pgtbl); -} - -void vmm_map_kernel_mmio(uint64 pa, uint64 size) { - if (!g_kernel_pgtbl) { - kernel_panic("vmm_map_kernel_mmio: kernel page table not ready"); - } - - uint64 aligned_pa = page_align_down(pa); - uint64 aligned_size = page_align_up(pa + size) - aligned_pa; - - map_range(g_kernel_pgtbl, aligned_pa, aligned_pa + aligned_size, - pmap::PTE_R | pmap::PTE_W | pmap::PTE_G); - tlb_shootdown_all(); -} diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include deleted file mode 100644 index 611499d..0000000 --- a/scripts/Kbuild.include +++ /dev/null @@ -1,159 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2026 Richard Qin -# -# scripts/Kbuild.include — shared Make helpers for LumeOS. -# -# Mirrors a small, useful subset of Linux's scripts/Kbuild.include. -# Provides: -# -# - Q / KBUILD_VERBOSE : `make V=1` shows full commands, -# default V=0 prints a one-line summary -# - $(call cmd,) : echo a quiet summary, then run cmd_ -# - $(call if_changed,) : rebuild when inputs or the command change. -# -# Naming convention adopted from Linux: each command has both a -# `quiet_cmd_` (single-line summary) and a `cmd_` (full -# command line). $(quiet) selects which prefix to display: -# V=0 -> quiet := quiet_ -> echoes " CC foo.c" -# V=1 -> quiet := -> echoes the full $(CC) $(CFLAGS) ... -# ---------------------------------------------------------------------- - -# --- Verbosity --------------------------------------------------------- -# Override at the command line: `make V=1`. Default V=0 = quiet. -KBUILD_VERBOSE ?= $(V) -KBUILD_VERBOSE ?= 0 - -ifeq ($(KBUILD_VERBOSE),1) - Q := - quiet := -else - Q := @ - quiet := quiet_ -endif - -# --- echo-cmd / cmd / if_changed --------------------------------------- -# -# echo-cmd prints the recipe's one-line summary (when quiet) or its full -# command line (when verbose). Implementation uses $($(quiet)cmd_) -# so the right form is picked up automatically. -# -# cmd is the workhorse: print summary, then execute the real command. -echo-cmd = $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) - -cmd = @$(echo-cmd) $(cmd_$(1)) - -# Record a checksum of the exact argv next to each output. FORCE makes Make -# reconsider the action; run-if-changed executes it only for a changed input or -# command signature. -if_changed = @scripts/build/run-if-changed.sh \ - $(dir $@).$(notdir $@).cmd $@ '$($(quiet)cmd_$(1))' $^ -- $(cmd_$(1)) - -# --- Standard quiet_cmd_* / cmd_* templates --------------------------- -# -# Subdir Makefiles and the top-level Makefile can reference these by -# name via $(call cmd,). Add new pairs here as new recipe shapes -# show up (e.g., cmd_lz / cmd_gz / cmd_zstd for compressed Image targets). - - quiet_cmd_cc_o_c = CC $(PRIVATE_SOURCE) - cmd_cc_o_c = $(CC) $(CFLAGS_LIBC) $(PRIVATE_INCLUDES) $(PRIVATE_DEFINES) $(PRIVATE_CFLAGS) -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_cxx_o_cc = CXX $(PRIVATE_SOURCE) - cmd_cxx_o_cc = $(CXX) $(CXXFLAGS) $(PRIVATE_INCLUDES) $(PRIVATE_DEFINES) $(PRIVATE_CXXFLAGS) -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_as_o_S = AS $(PRIVATE_SOURCE) - cmd_as_o_S = $(CC) $(ASFLAGS) $(PRIVATE_INCLUDES) $(PRIVATE_DEFINES) $(PRIVATE_ASFLAGS) -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_cc_s_c = CC -S $< - cmd_cc_s_c = $(CC) $(CFLAGS_LIBC) -S $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_gen_asm_offsets = GEN $@ - cmd_gen_asm_offsets = scripts/build/generate-asm-offsets.sh $@ \ - $(ASM_OFFSETS_S) $(ASM_OFFSETS_SED) $(ASM_OFFSETS_C) - - quiet_cmd_autoconf = GEN $@ - cmd_autoconf = scripts/build/generate-autoconf.sh $@ \ - CONFIG_NR_CPUS $(CONFIG_NR_CPUS) value \ - CONFIG_HZ $(CONFIG_HZ) value \ - CONFIG_NR_PRIORITIES $(CONFIG_NR_PRIORITIES) value \ - CONFIG_DEFAULT_PRIORITY $(CONFIG_DEFAULT_PRIORITY) value \ - CONFIG_IDLE_PRIORITY $(CONFIG_IDLE_PRIORITY) value \ - CONFIG_DEFAULT_TIMESLICE $(CONFIG_DEFAULT_TIMESLICE) value \ - CONFIG_PAGE_SIZE $(CONFIG_PAGE_SIZE) value \ - CONFIG_MAX_ORDER $(CONFIG_MAX_ORDER) value \ - CONFIG_KERNEL_STACK_SIZE $(CONFIG_KERNEL_STACK_SIZE) value \ - CONFIG_KASLR $(CONFIG_KASLR) bool \ - CONFIG_KASLR_POLICY_ID $(CONFIG_KASLR_POLICY_ID) value \ - CONFIG_KASLR_LOG_LEVEL $(CONFIG_KASLR_LOG_LEVEL) value \ - CONFIG_STACK_CANARY $(CONFIG_STACK_CANARY) bool \ - CONFIG_DEBUG $(CONFIG_DEBUG) bool \ - CONFIG_DEBUG_LOCKS $(CONFIG_DEBUG_LOCKS) bool \ - CONFIG_SELFTEST $(CONFIG_SELFTEST) bool \ - CONFIG_KLOG $(CONFIG_KLOG) bool \ - CONFIG_KERNEL_COMPRESSED $(CONFIG_KERNEL_COMPRESSED) bool - - quiet_cmd_linker_script = LDS $@ - cmd_linker_script = $(CC) -E -P -x c $(INCLUDES) $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_initramfs = INITRAMFS $(INITRAMFS_SOURCE) - cmd_initramfs = scripts/build/generate-initramfs.sh $(GEN_INIT_CPIO) \ - ./scripts/gen_initramfs.sh $@ \ - $(CONFIG_INITRAMFS_ROOT_UID) $(CONFIG_INITRAMFS_ROOT_GID) \ - $(INITRAMFS_SOURCE) - - quiet_cmd_initramfs_obj = AS $@ (initramfs) - cmd_initramfs_obj = $(CC) $(ASFLAGS) \ - -DINITRAMFS_IMAGE='"$(INITRAMFS_CPIO)"' \ - -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_objcopy_bin = OBJCOPY $@ - cmd_objcopy_bin = $(OBJCOPY) -O binary $< $@ - - quiet_cmd_archive = AR $@ - cmd_archive = scripts/build/archive.sh $@ $(AR) $(PRIVATE_ARCHIVE_OBJECTS) - - quiet_cmd_host_tool = HOSTCC $@ - cmd_host_tool = $(HOSTCC) $(HOSTCFLAGS) $(PRIVATE_HOST_CFLAGS) \ - -o $@ $(PRIVATE_HOST_SOURCE) - - quiet_cmd_host_cc_o_c = HOSTCC $(PRIVATE_SOURCE) - cmd_host_cc_o_c = $(HOSTCC) $(HOSTCFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_host_cxx_o_cc = HOSTCXX $(PRIVATE_SOURCE) - cmd_host_cxx_o_cc = $(HOSTCXX) $(HOSTCXXFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_host_archive = HOSTAR $@ - cmd_host_archive = scripts/build/archive.sh $@ $(HOSTAR) $(PRIVATE_ARCHIVE_OBJECTS) - - quiet_cmd_host_link = HOSTLD $@ - cmd_host_link = $(HOSTCXX) $(HOSTCXXFLAGS) -o $@ \ - $(PRIVATE_HOST_OBJECTS) $(PRIVATE_HOST_LIBS) - - quiet_cmd_toolchain_probe = PROBE toolchain - cmd_toolchain_probe = scripts/build/probe-toolchain.sh $@ \ - $(CC) $(CXX) $(LD) $(COMPILER_FAMILY) $(TARGET_TRIPLE) \ - '$(GCC_TOOLCHAIN)' '$(GCC_SYSROOT)' \ - '$(KTL_INCLUDE)' '$(KTL_AFTER_INCLUDE)' \ - '$(KERNEL_LIBC_INCLUDE)' '$(KERNEL_LIBC_AFTER_INCLUDE)' \ - '$(LIBCXX_INCLUDE)' '$(COMPILER_RESOURCE_INCLUDE)' - - quiet_cmd_phys_cc_o_c = PHYSCC $(PRIVATE_SOURCE) - cmd_phys_cc_o_c = $(CC) $(PHYS_CFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_phys_cxx_o_cc = PHYSCXX $(PRIVATE_SOURCE) - cmd_phys_cxx_o_cc = $(CXX) $(PHYS_CXXFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_phys_as_o_S = PHYSAS $(PRIVATE_SOURCE) - cmd_phys_as_o_S = $(CC) $(PHYS_ASFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@ - - quiet_cmd_link_vmlume = LD $@ - cmd_link_vmlume = scripts/build/link-kernel.sh $@ $(SIZE) \ - $(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ \ - $(KERNEL_LINK_INPUTS) $(INITRAMFS_OBJ) - -# Objcopy with custom flags via per-target OBJCOPYFLAGS variable — -# used by the .pi.o post-processing rule (--prefix-symbols=__pi_ etc.). - quiet_cmd_objcopy = OBJCOPY $@ - cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $< $@ - - quiet_cmd_ld_kernel = LD $@ - cmd_ld_kernel = $(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ $^ diff --git a/scripts/Kconfig.mk b/scripts/Kconfig.mk deleted file mode 100644 index 3db7a2f..0000000 --- a/scripts/Kconfig.mk +++ /dev/null @@ -1,205 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2026 Richard Qin -# -# scripts/Kconfig.mk — Kernel Configuration Infrastructure -# -# This file is the heart of the LumeOS build-time configuration system. -# It mirrors the role of Linux's Kconfig + auto.conf pipeline: -# -# 1. Developer edits `$(O)/.config` (or runs `make O=... defconfig`) -# 2. This file reads that configuration and applies missing defaults, -# validates constraints, and exports two things: -# a) KCPPFLAGS — a set of -DCONFIG_xxx=value flags for the compiler -# b) $(BUILD)/generated/autoconf.h — the same values as C #defines -# -# Design Principles (matching Linux conventions): -# - Every CONFIG_ symbol has a default defined HERE, so an empty output -# directory still builds a sane kernel. -# - Boolean options use 'y' / 'n'. Numeric options are plain integers. -# - The generated autoconf.h uses the exact same names so that -# `#ifdef CONFIG_DEBUG` works identically in Makefile and C. -# ====================================================================== - -# ------------------------------------------------------------------ -# §1 Read user configuration (if it exists) -# ------------------------------------------------------------------ -KCONFIG_CONFIG ?= $(BUILD)/.config --include $(KCONFIG_CONFIG) - -# ------------------------------------------------------------------ -# §2 Provide defaults for every CONFIG_ symbol -# -# ?= means "set only if not already set (by .config or CLI)". -# This is the single source of truth for default values. -# ------------------------------------------------------------------ - -# --- Platform ------------------------------------------------------- -CONFIG_ARCH ?= riscv - -# --- CPU / SMP ------------------------------------------------------ -CONFIG_NR_CPUS ?= 8 - -# --- Scheduler ------------------------------------------------------ -CONFIG_HZ ?= 100 -CONFIG_NR_PRIORITIES ?= 32 - -# --- Memory Management ---------------------------------------------- -CONFIG_PAGE_SIZE ?= 4096 -CONFIG_MAX_ORDER ?= 11 -CONFIG_KERNEL_STACK_SIZE ?= 8192 - -# --- Security / Hardening ------------------------------------------- -CONFIG_KASLR ?= y -CONFIG_KASLR_POLICY_ID ?= 0 -CONFIG_KASLR_LOG_LEVEL ?= 1 -CONFIG_STACK_CANARY ?= y -CONFIG_KERNEL_COMPRESSED ?= y - -# --- Debug ----------------------------------------------------------- -CONFIG_DEBUG ?= y -CONFIG_DEBUG_LOCKS ?= y -CONFIG_SELFTEST ?= y -CONFIG_KLOG ?= y - -# --- Initramfs ------------------------------------------------------ -# Source for the initramfs image. Accepted forms (auto-detected by -# scripts/gen_initramfs.sh): -# - a listing file (gen_init_cpio format) → built into a cpio -# - a directory → packed recursively -# - a *.cpio file → used as-is -# Override on the command line or pin in .config: -# make all CONFIG_INITRAMFS_SOURCE=/path/to/rootfs -CONFIG_INITRAMFS_SOURCE ?= usr/default_cpio_list -CONFIG_INITRAMFS_ROOT_UID ?= 0 -CONFIG_INITRAMFS_ROOT_GID ?= 0 - -# ------------------------------------------------------------------ -# §3 Derived constants (computed from CONFIG_ symbols) -# -# These follow Linux's pattern of expressing dependent values -# so that C code never has to do its own derivation at runtime. -# ------------------------------------------------------------------ - -# Default priority = middle of the range -CONFIG_DEFAULT_PRIORITY = $(shell echo $$(( $(CONFIG_NR_PRIORITIES) / 2 ))) - -# Idle priority = lowest = NR_PRIORITIES - 1 -CONFIG_IDLE_PRIORITY = $(shell echo $$(( $(CONFIG_NR_PRIORITIES) - 1 ))) - -# Default time slice in ticks: 100ms worth of ticks -# (same as Linux CFS's sysctl_sched_min_granularity default) -CONFIG_DEFAULT_TIMESLICE = $(shell echo $$(( $(CONFIG_HZ) / 10 ))) - -# ------------------------------------------------------------------ -# §4 Export to C/C++ via -D flags -# -# KCPPFLAGS is appended to CFLAGS/CXXFLAGS in the main Makefile. -# Every CONFIG_xxx= becomes -DCONFIG_xxx=. -# Boolean 'y' options become -DCONFIG_xxx=1. -# ------------------------------------------------------------------ -KCPPFLAGS := - -# Numeric options — pass through as-is -KCPPFLAGS += -DCONFIG_NR_CPUS=$(CONFIG_NR_CPUS) -KCPPFLAGS += -DCONFIG_HZ=$(CONFIG_HZ) -KCPPFLAGS += -DCONFIG_NR_PRIORITIES=$(CONFIG_NR_PRIORITIES) -KCPPFLAGS += -DCONFIG_DEFAULT_PRIORITY=$(CONFIG_DEFAULT_PRIORITY) -KCPPFLAGS += -DCONFIG_IDLE_PRIORITY=$(CONFIG_IDLE_PRIORITY) -KCPPFLAGS += -DCONFIG_DEFAULT_TIMESLICE=$(CONFIG_DEFAULT_TIMESLICE) -KCPPFLAGS += -DCONFIG_PAGE_SIZE=$(CONFIG_PAGE_SIZE) -KCPPFLAGS += -DCONFIG_MAX_ORDER=$(CONFIG_MAX_ORDER) -KCPPFLAGS += -DCONFIG_KERNEL_STACK_SIZE=$(CONFIG_KERNEL_STACK_SIZE) - -# Boolean options — translate 'y' → 1 -ifeq ($(CONFIG_KASLR),y) -KCPPFLAGS += -DCONFIG_KASLR=1 -endif -KCPPFLAGS += -DCONFIG_KASLR_POLICY_ID=$(CONFIG_KASLR_POLICY_ID) -KCPPFLAGS += -DCONFIG_KASLR_LOG_LEVEL=$(CONFIG_KASLR_LOG_LEVEL) -ifeq ($(CONFIG_STACK_CANARY),y) -KCPPFLAGS += -DCONFIG_STACK_CANARY=1 -endif -ifeq ($(CONFIG_DEBUG),y) -KCPPFLAGS += -DCONFIG_DEBUG=1 -endif -ifeq ($(CONFIG_DEBUG_LOCKS),y) -KCPPFLAGS += -DCONFIG_DEBUG_LOCKS=1 -endif -ifeq ($(CONFIG_SELFTEST),y) -KCPPFLAGS += -DCONFIG_SELFTEST=1 -endif -ifeq ($(CONFIG_KLOG),y) -KCPPFLAGS += -DCONFIG_KLOG=1 -endif -ifeq ($(CONFIG_KERNEL_COMPRESSED),y) -KCPPFLAGS += -DCONFIG_KERNEL_COMPRESSED=1 -endif - -# ------------------------------------------------------------------ -# §5 Generate autoconf.h (analogous to Linux's include/generated/autoconf.h) -# -# This header is auto-generated at build time so that C code can -# #include and see CONFIG_xxx macros without -# relying on -D flags alone. This is important for IDE integration. -# ------------------------------------------------------------------ -AUTOCONF_H := $(BUILD)/generated/autoconf.h - -# ------------------------------------------------------------------ -# §6 Utility targets -# ------------------------------------------------------------------ - -# 'make defconfig' — reset .config to the arch default -.PHONY: defconfig savedefconfig showconfig - -defconfig: - @echo " DEFCFG arch/$(CONFIG_ARCH)/defconfig → $(KCONFIG_CONFIG)" - @mkdir -p $(dir $(KCONFIG_CONFIG)) - @cp arch/$(CONFIG_ARCH)/defconfig $(KCONFIG_CONFIG) - -# 'make savedefconfig' — save current effective config -savedefconfig: - @echo " SAVE $(KCONFIG_CONFIG)" - @mkdir -p $(dir $(KCONFIG_CONFIG)) - @echo "# LumeOS Kernel Configuration (saved $$(date +%Y-%m-%d))" > $(KCONFIG_CONFIG) - @echo "CONFIG_ARCH = $(CONFIG_ARCH)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_NR_CPUS = $(CONFIG_NR_CPUS)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_HZ = $(CONFIG_HZ)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_NR_PRIORITIES = $(CONFIG_NR_PRIORITIES)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_PAGE_SIZE = $(CONFIG_PAGE_SIZE)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_MAX_ORDER = $(CONFIG_MAX_ORDER)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KERNEL_STACK_SIZE = $(CONFIG_KERNEL_STACK_SIZE)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KASLR = $(CONFIG_KASLR)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KASLR_POLICY_ID = $(CONFIG_KASLR_POLICY_ID)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KASLR_LOG_LEVEL = $(CONFIG_KASLR_LOG_LEVEL)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_STACK_CANARY = $(CONFIG_STACK_CANARY)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_DEBUG = $(CONFIG_DEBUG)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_DEBUG_LOCKS = $(CONFIG_DEBUG_LOCKS)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_SELFTEST = $(CONFIG_SELFTEST)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KLOG = $(CONFIG_KLOG)" >> $(KCONFIG_CONFIG) - @echo "CONFIG_KERNEL_COMPRESSED = $(CONFIG_KERNEL_COMPRESSED)" >> $(KCONFIG_CONFIG) - -# 'make showconfig' — print effective configuration -showconfig: - @echo "========================================" - @echo " LumeOS Effective Configuration" - @echo "========================================" - @echo " ARCH = $(CONFIG_ARCH)" - @echo " NR_CPUS = $(CONFIG_NR_CPUS)" - @echo " HZ = $(CONFIG_HZ)" - @echo " NR_PRIORITIES = $(CONFIG_NR_PRIORITIES)" - @echo " DEFAULT_PRIORITY = $(CONFIG_DEFAULT_PRIORITY)" - @echo " IDLE_PRIORITY = $(CONFIG_IDLE_PRIORITY)" - @echo " DEFAULT_TIMESLICE = $(CONFIG_DEFAULT_TIMESLICE)" - @echo " PAGE_SIZE = $(CONFIG_PAGE_SIZE)" - @echo " MAX_ORDER = $(CONFIG_MAX_ORDER)" - @echo " KERNEL_STACK_SIZE = $(CONFIG_KERNEL_STACK_SIZE)" - @echo " KASLR = $(CONFIG_KASLR)" - @echo " KASLR_POLICY_ID = $(CONFIG_KASLR_POLICY_ID)" - @echo " KASLR_LOG_LEVEL = $(CONFIG_KASLR_LOG_LEVEL)" - @echo " STACK_CANARY = $(CONFIG_STACK_CANARY)" - @echo " DEBUG = $(CONFIG_DEBUG)" - @echo " DEBUG_LOCKS = $(CONFIG_DEBUG_LOCKS)" - @echo " SELFTEST = $(CONFIG_SELFTEST)" - @echo " KLOG = $(CONFIG_KLOG)" - @echo " KERNEL_COMPRESSED = $(CONFIG_KERNEL_COMPRESSED)" - @echo "========================================" diff --git a/scripts/build/Build.mk b/scripts/build/Build.mk deleted file mode 100644 index 0a15b38..0000000 --- a/scripts/build/Build.mk +++ /dev/null @@ -1,10 +0,0 @@ -targets += build/host-library-smoke build/host-test-smoke build/phys-library-smoke -target.build/host-library-smoke.kind := host-library -target.build/host-library-smoke.sources := scripts/build/tests/host_library.cc - -target.build/host-test-smoke.kind := host-test -target.build/host-test-smoke.sources := scripts/build/tests/host_test.cc -target.build/host-test-smoke.private-deps := build/host-library-smoke - -target.build/phys-library-smoke.kind := phys-library -target.build/phys-library-smoke.sources := scripts/build/tests/phys_library.cc diff --git a/scripts/build/archive.sh b/scripts/build/archive.sh deleted file mode 100755 index 79f0bb9..0000000 --- a/scripts/build/archive.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu -archive=$1 -ar=$2 -shift 2 -rm -f "$archive" -"$ar" rcs "$archive" "$@" - diff --git a/scripts/build/check-kernel-elf.sh b/scripts/build/check-kernel-elf.sh deleted file mode 100755 index eb92b33..0000000 --- a/scripts/build/check-kernel-elf.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu -elf=$1 -readelf=$2 -nm=$3 -arch=$4 - -case "$arch" in - riscv) expected_machine='RISC-V' ;; - aarch64) expected_machine='AArch64' ;; - x86_64) expected_machine='Advanced Micro Devices X86-64' ;; - *) echo "ELF check: unsupported architecture: $arch" >&2; exit 2 ;; -esac - -machine=$($readelf -h "$elf" | sed -n 's/^[[:space:]]*Machine:[[:space:]]*//p') -[ "$machine" = "$expected_machine" ] || { - echo "ELF check: expected machine '$expected_machine', got '$machine'" >&2 - exit 1 -} - -entry=$($readelf -h "$elf" | sed -n 's/^[[:space:]]*Entry point address:[[:space:]]*//p') -[ -n "$entry" ] && [ "$entry" != 0x0 ] || { - echo "ELF check: kernel has no entry point" >&2 - exit 1 -} - -undefined=$($nm -u "$elf" || true) -[ -z "$undefined" ] || { - echo "ELF check: undefined symbols:" >&2 - printf '%s\n' "$undefined" >&2 - exit 1 -} - -if $readelf -W -l "$elf" | awk '$1 == "LOAD" && $0 ~ /W/ && $0 ~ /E/ { found=1 } END { exit !found }'; then - echo "ELF check: writable and executable LOAD segment" >&2 - exit 1 -fi - -$readelf -S "$elf" | grep -q '[.]rela[.]dyn' || { - echo "ELF check: missing relocation section .rela.dyn" >&2 - exit 1 -} - -echo "Kernel ELF OK: $machine, entry $entry" - diff --git a/scripts/build/environments/host.mk b/scripts/build/environments/host.mk deleted file mode 100644 index 0911ad3..0000000 --- a/scripts/build/environments/host.mk +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -HOSTCC ?= cc -HOSTCXX ?= c++ -HOSTAR ?= ar -HOSTCFLAGS ?= -O2 -g -Wall -Wextra -HOSTCXXFLAGS ?= $(HOSTCFLAGS) -std=c++23 - diff --git a/scripts/build/environments/kernel.mk b/scripts/build/environments/kernel.mk deleted file mode 100644 index 1d6c8cf..0000000 --- a/scripts/build/environments/kernel.mk +++ /dev/null @@ -1,28 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -WARNINGS ?= -Wall -Wextra -Wno-unused-parameter - -ifeq ($(BUILD_VARIANT),release) -KERNEL_OPT_FLAGS := -O2 -g0 -DNDEBUG -else -KERNEL_OPT_FLAGS := -O2 -g -endif - -CFLAGS := $(WARNINGS) $(KERNEL_OPT_FLAGS) \ - -ffreestanding -nostdlib \ - -mcmodel=medany -fPIE -MMD -MP \ - $(TOOLCHAIN_CFLAGS) $(KCPPFLAGS) $(INCLUDES) \ - -I$(BUILD)/generated - -CFLAGS_LIBC := -Iinclude/libc-shim $(CFLAGS) -std=gnu23 \ - -Wno-parentheses -Wno-sign-compare - -CXXFLAGS := $(CFLAGS) $(TOOLCHAIN_CXXFLAGS) -std=c++23 \ - -fno-exceptions -fno-rtti -fno-use-cxa-atexit \ - -fno-threadsafe-statics - -# Pre-MMU assembly must never use GOT-indirect addressing. -ASFLAGS := $(filter-out -fPIE,$(CFLAGS)) -fno-pie - -LDFLAGS := -nostdlib -shared -Bsymbolic -z notext -z norelro \ - --no-dynamic-linker diff --git a/scripts/build/environments/phys.mk b/scripts/build/environments/phys.mk deleted file mode 100644 index 6a11c12..0000000 --- a/scripts/build/environments/phys.mk +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -# Early physical-address execution environment. It deliberately has no heap, -# exceptions, RTTI, thread-safe statics, or PIE/GOT assumptions. -PHYS_CFLAGS := $(WARNINGS) -Os -g -ffreestanding -nostdlib \ - -fno-pie -fno-stack-protector $(TOOLCHAIN_CFLAGS) \ - $(KCPPFLAGS) $(INCLUDES) -I$(BUILD)/generated -PHYS_CXXFLAGS := $(PHYS_CFLAGS) $(TOOLCHAIN_CXXFLAGS) -std=c++23 \ - -fno-exceptions -fno-rtti -fno-use-cxa-atexit \ - -fno-threadsafe-statics -PHYS_ASFLAGS := $(PHYS_CFLAGS) - diff --git a/scripts/build/generate-asm-offsets.sh b/scripts/build/generate-asm-offsets.sh deleted file mode 100755 index 4e90f94..0000000 --- a/scripts/build/generate-asm-offsets.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu -output=$1 -assembly=$2 -sed_script=$3 -source=$4 -tmp="$output.tmp.$$" -{ - echo '/* AUTO-GENERATED — DO NOT EDIT */' - echo "/* Generated from $source */" - echo '#ifndef _LUME_GENERATED_ASM_OFFSETS_H' - echo '#define _LUME_GENERATED_ASM_OFFSETS_H' - echo - sed -n -f "$sed_script" "$assembly" - echo - echo '#endif /* _LUME_GENERATED_ASM_OFFSETS_H */' -} > "$tmp" -if [ -e "$output" ] && cmp -s "$tmp" "$output"; then - rm -f "$tmp" -else - mv -f "$tmp" "$output" -fi - diff --git a/scripts/build/generate-autoconf.sh b/scripts/build/generate-autoconf.sh deleted file mode 100755 index 493d630..0000000 --- a/scripts/build/generate-autoconf.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu -output=$1 -shift -tmp="$output.tmp.$$" -mkdir -p "$(dirname "$output")" -{ - echo '/* AUTO-GENERATED — DO NOT EDIT */' - echo '#pragma once' - while [ "$#" -gt 0 ]; do - name=$1 - value=$2 - kind=$3 - shift 3 - if [ "$kind" = bool ]; then - [ "$value" = y ] && echo "#define $name 1" - else - echo "#define $name $value" - fi - done -} > "$tmp" -if [ -e "$output" ] && cmp -s "$tmp" "$output"; then - rm -f "$tmp" -else - mv -f "$tmp" "$output" -fi - diff --git a/scripts/build/generate-initramfs.sh b/scripts/build/generate-initramfs.sh deleted file mode 100755 index 194e206..0000000 --- a/scripts/build/generate-initramfs.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu -generator=$1 -wrapper=$2 -output=$3 -uid=$4 -gid=$5 -source=$6 -GEN_INIT_CPIO=$generator "$wrapper" -o "$output" -u "$uid" -g "$gid" "$source" - diff --git a/scripts/build/link-kernel.sh b/scripts/build/link-kernel.sh deleted file mode 100755 index 31164e7..0000000 --- a/scripts/build/link-kernel.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu -output=$1 -size_tool=$2 -shift 2 -"$@" -"$size_tool" "$output" - diff --git a/scripts/build/probe-toolchain.sh b/scripts/build/probe-toolchain.sh deleted file mode 100755 index 218a821..0000000 --- a/scripts/build/probe-toolchain.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu -output=$1 -cc=$2 -cxx=$3 -ld=$4 -family=$5 -target=$6 -gcc_toolchain=$7 -sysroot=$8 -ktl_include=$9 -ktl_after_include=${10} -libc_include=${11} -libc_after_include=${12} -libcxx_include=${13} -compiler_resource_include=${14} - -set -- -if [ "$family" = clang ]; then - set -- "$@" "--target=$target" - [ -z "$gcc_toolchain" ] || set -- "$@" "--gcc-toolchain=$gcc_toolchain" - [ -z "$sysroot" ] || set -- "$@" "--sysroot=$sysroot" -fi - -probe() { - language=$1 - standard=$2 - shift 2 - compiler=$cc - [ "$language" = c++ ] && compiler=$cxx - printf '' | "$compiler" "$@" "-std=$standard" -x "$language" \ - -fsyntax-only - >/dev/null 2>&1 -} - -probe_libcxx() { - printf '%s\n' \ - '#include ' \ - '#include ' \ - '#include ' \ - '#include ' \ - '#include ' \ - 'constexpr ktl::array values{1, 2};' \ - 'static_assert(values[1] == 2);' | \ - "$cxx" "$@" -std=c++23 -ffreestanding -fno-exceptions -fno-rtti \ - -nostdinc -I include -I "$ktl_include" -I "$libc_include" \ - -isystem "$compiler_resource_include" \ - -isystem "$libcxx_include" -idirafter "$ktl_after_include" \ - -idirafter "$libc_after_include" -fsyntax-only -x c++ - >/dev/null 2>&1 -} - -tmp="$output.tmp.$$" -mkdir -p "$(dirname "$output")" -{ - echo "cc=$($cc --version | head -n 1)" - echo "cxx=$($cxx --version | head -n 1)" - echo "ld=$($ld --version | head -n 1)" - echo "target=$target" - printf 'c23='; if probe c gnu23 "$@"; then echo yes; else echo no; fi - printf 'cxx23='; if probe c++ c++23 "$@"; then echo yes; else echo no; fi - printf 'libcxx-headers='; if probe_libcxx "$@"; then echo yes; else echo no; fi - printf 'fno-pie='; if probe c++ c++23 "$@" -fno-pie; then echo yes; else echo no; fi - printf 'mcmodel-medany='; if probe c++ c++23 "$@" -mcmodel=medany; then echo yes; else echo no; fi -} > "$tmp" -mv -f "$tmp" "$output" - -grep -q '^c23=yes$' "$output" -grep -q '^cxx23=yes$' "$output" -grep -q '^libcxx-headers=yes$' "$output" -grep -q '^fno-pie=yes$' "$output" -grep -q '^mcmodel-medany=yes$' "$output" diff --git a/scripts/build/probes/libc_headers.c b/scripts/build/probes/libc_headers.c deleted file mode 100644 index e4bdd20..0000000 --- a/scripts/build/probes/libc_headers.c +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ - -#include -#include -#include -#include -#include -#include - -_Static_assert(sizeof(uintptr_t) == sizeof(void*), "uintptr_t must hold a pointer"); diff --git a/scripts/build/probes/libc_headers.cc b/scripts/build/probes/libc_headers.cc deleted file mode 100644 index 1085cd3..0000000 --- a/scripts/build/probes/libc_headers.cc +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -#include -#include -#include -#include -#include -#include -#include -#include - -static_assert(sizeof(uintptr_t) == sizeof(void*)); diff --git a/scripts/build/probes/libcxx.cc b/scripts/build/probes/libcxx.cc deleted file mode 100644 index 8237151..0000000 --- a/scripts/build/probes/libcxx.cc +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -#include -#include -#include -#include -#include -#include - -constexpr std::array kValues{1, 2, 3}; -static_assert(kValues[2] == 3); -static_assert(std::is_same_v::element_type, const int>); -static_assert(std::string_view{"libc++"}.size() == 6); - -using Optional = std::optional; -using Atomic = std::atomic; diff --git a/scripts/build/run-if-changed.sh b/scripts/build/run-if-changed.sh deleted file mode 100755 index 6cdc7c4..0000000 --- a/scripts/build/run-if-changed.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-or-later - -set -eu - -cmdfile=$1 -output=$2 -description=$3 -shift 3 - -rebuild=false -if [ ! -e "$output" ] || [ ! -e "$cmdfile" ]; then - rebuild=true -fi - -while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do - prerequisite=$1 - shift - if [ "$prerequisite" != FORCE ] && [ -e "$prerequisite" ] && \ - [ "$prerequisite" -nt "$output" ]; then - rebuild=true - fi -done - -[ "$#" -gt 0 ] || { echo "run-if-changed: missing --" >&2; exit 2; } -shift - -signature=$(printf '%s\0' "$@" | cksum) -old_signature= -if [ -e "$cmdfile" ]; then - old_signature=$(cat "$cmdfile") -fi -if [ "$signature" != "$old_signature" ]; then - rebuild=true -fi - -if [ "$rebuild" = true ]; then - printf ' %s\n' "$description" - mkdir -p "$(dirname "$output")" "$(dirname "$cmdfile")" - "$@" - tmp="$cmdfile.tmp.$$" - printf '%s\n' "$signature" > "$tmp" - mv -f "$tmp" "$cmdfile" -fi - diff --git a/scripts/build/targets.mk b/scripts/build/targets.mk deleted file mode 100644 index 1a66379..0000000 --- a/scripts/build/targets.mk +++ /dev/null @@ -1,81 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2026 Richard Qin - -# Declarative target registry for the LumeOS build. -# -# Build.mk files populate target..* and append the name to targets. A -# target name is metadata, not a Make rule, so names may contain '/' and ':'. - -target-kinds := \ - interface-library header-library object-library source-set \ - static-library whole-archive host-library phys-library host-tool generated \ - binary-blob kernel-test host-test product -targets := -generated-actions := autoconf asm-offsets linker-script initramfs - -empty := -space := $(empty) $(empty) -comma := , - -# Convert a logical target/source name into a path-safe component. -target-key = $(subst :,_,$(subst /,_,$(1))) - -# Recursively collect a target and all of its dependencies. Dependency cycles -# are rejected separately before this is evaluated for build roots. -target-deps = $(sort $(target.$(1).deps) $(target.$(1).public-deps) \ - $(target.$(1).private-deps) $(target.$(1).interface-deps) \ - $(target.$(1).link-deps) $(target.$(1).tool-deps) \ - $(target.$(1).generated-deps) $(target.$(1).runtime-deps) \ - $(target.$(1).order-only-deps)) -target-closure = $(strip \ - $(if $(filter $(1),$(2)),$(error target dependency cycle: $(2) -> $(1))) \ - $(1) $(foreach dep,$(call target-deps,$(1)),$(call target-closure,$(dep),$(2) $(1)))) -target-link-deps = $(sort $(target.$(1).deps) $(target.$(1).public-deps) \ - $(target.$(1).private-deps) $(target.$(1).interface-deps) \ - $(target.$(1).link-deps)) -target-link-order = $(strip $(1) $(foreach dep,$(call target-link-deps,$(1)),\ - $(call target-link-order,$(dep)))) -unique-words = $(if $(strip $(1)),$(firstword $(1)) \ - $(call unique-words,$(filter-out $(firstword $(1)),$(1)))) - -duplicate-words = $(sort $(foreach word,$(1),\ - $(if $(word 2,$(filter $(word),$(1))),$(word)))) -all-target-sources = $(foreach target,$(targets),$(target.$(target).sources)) -duplicate-target-sources = $(call duplicate-words,$(all-target-sources)) - -define validate-target -$(if $(filter $(target.$(1).kind),$(target-kinds)),,$(error target '$(1)' has invalid kind '$(target.$(1).kind)')) -$(if $(filter header-library interface-library product generated binary-blob,$(target.$(1).kind)),$(if $(strip $(target.$(1).sources)),$(error target '$(1)' of kind $(target.$(1).kind) declares sources),),) -$(if $(filter host-tool,$(target.$(1).kind)),$(if $(word 2,$(target.$(1).sources)),$(error host-tool '$(1)' currently requires exactly one source),),) -$(foreach src,$(target.$(1).sources),$(if $(wildcard $(src)),,$(error target '$(1)' references missing source '$(src)'))) -$(foreach dep,$(call target-deps,$(1)),$(if $(filter $(dep),$(targets)),,$(error target '$(1)' references unknown dependency '$(dep)'))) -$(foreach dep,$(call target-deps,$(1)),$(if $(strip $(target.$(dep).visibility)),\ - $(if $(filter all $(1),$(target.$(dep).visibility)),,\ - $(error target '$(1)' cannot depend on '$(dep)': visibility is '$(target.$(dep).visibility)')),)) -$(if $(filter generated,$(target.$(1).kind)),$(if $(strip $(target.$(1).outputs)),,$(error generated target '$(1)' has no outputs)),) -$(if $(filter generated,$(target.$(1).kind)),$(if $(filter $(target.$(1).action),$(generated-actions)),,$(error generated target '$(1)' has invalid action '$(target.$(1).action)')),) -endef - -define validate-targets -$(if $(strip $(targets)),,$(error no build targets were registered)) -$(if $(filter-out $(words $(sort $(targets))),$(words $(targets))),$(error duplicate build target name),) -$(foreach target,$(targets),$(call validate-target,$(target))) -endef - -# Usage requirements are deliberately separate from link inputs. Public -# include paths and defines propagate through deps; private values apply only -# while compiling the target itself. -target-public-closure = $(sort $(1) $(foreach dep,$(target.$(1).public-deps) \ - $(target.$(1).deps),$(call target-public-closure,$(dep)))) -target-public-includes = $(sort $(foreach target,$(call target-public-closure,$(1)),$(target.$(target).public-includes))) -target-public-after-includes = $(sort $(foreach target,$(call target-public-closure,$(1)),$(target.$(target).public-after-includes))) -target-public-defines = $(sort $(foreach target,$(call target-public-closure,$(1)),$(target.$(target).public-defines))) - -target-usage-roots = $(sort $(1) $(target.$(1).deps) $(target.$(1).public-deps) \ - $(target.$(1).private-deps) $(target.$(1).interface-deps)) -target-compile-includes = $(sort $(target.$(1).private-includes) \ - $(foreach root,$(call target-usage-roots,$(1)),$(call target-public-includes,$(root)))) -target-compile-after-includes = $(sort $(target.$(1).private-after-includes) \ - $(foreach root,$(call target-usage-roots,$(1)),$(call target-public-after-includes,$(root)))) -target-compile-defines = $(sort $(target.$(1).private-defines) \ - $(foreach root,$(call target-usage-roots,$(1)),$(call target-public-defines,$(root)))) diff --git a/scripts/build/tests/host_library.cc b/scripts/build/tests/host_library.cc deleted file mode 100644 index c545815..0000000 --- a/scripts/build/tests/host_library.cc +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -namespace lume::build::test { - -int HostLibrarySmokeTestSymbol() { return 0; } - -} // namespace lume::build::test - diff --git a/scripts/build/tests/host_test.cc b/scripts/build/tests/host_test.cc deleted file mode 100644 index 6b13417..0000000 --- a/scripts/build/tests/host_test.cc +++ /dev/null @@ -1,7 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -namespace lume::build::test { -int HostLibrarySmokeTestSymbol(); -} - -int main() { return lume::build::test::HostLibrarySmokeTestSymbol(); } diff --git a/scripts/build/tests/phys_library.cc b/scripts/build/tests/phys_library.cc deleted file mode 100644 index 2cf1596..0000000 --- a/scripts/build/tests/phys_library.cc +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -extern "C" unsigned long LumePhysBuildSmoke(unsigned long value) { - return value ^ 0x4c554d45UL; -} diff --git a/scripts/build/toolchain.mk b/scripts/build/toolchain.mk deleted file mode 100644 index d244981..0000000 --- a/scripts/build/toolchain.mk +++ /dev/null @@ -1,130 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2026 Richard Qin - -# Toolchain selection: -# make GCC + GNU ld -# make LLVM=1 Clang + GNU ld -# make LLVM=1 LD_TYPE=lld Clang + LLD - -LLVM ?= 0 -LLVM_VERSION ?= 20 -LD_TYPE ?= bfd -LLVM_BINUTILS ?= 0 -CXX_STDLIB ?= libc++ -CXX_ABI ?= lume -COMPILER_RUNTIME ?= compiler-default - -# One pinned libc++ header snapshot is shared by GCC and Clang. Platform C -# declarations and libc++ configuration come from the Zircon libc/KTL layer, -# not from a Linux or Fuchsia userland __config_site. -LIBCXX_ROOT ?= third_party/libcxx -LIBCXX_INCLUDE := $(LIBCXX_ROOT)/include/c++/v1 -KTL_INCLUDE := lib/ktl/include -KTL_AFTER_INCLUDE := lib/ktl/include-after -KERNEL_LIBC_INCLUDE := lib/libc/include -KERNEL_LIBC_AFTER_INCLUDE := lib/libc/include-after - -ifeq ($(wildcard $(LIBCXX_INCLUDE)/__config),) -$(error missing pinned libc++ headers under '$(LIBCXX_INCLUDE)') -endif -ifeq ($(wildcard $(KTL_INCLUDE)/__config_site),) -$(error missing KTL libc++ configuration under '$(KTL_INCLUDE)') -endif -ifneq ($(CXX_STDLIB),libc++) -$(error unsupported CXX_STDLIB '$(CXX_STDLIB)' (LumeOS uses its pinned libc++ headers)) -endif - -GCC_TOOLCHAIN ?= -CROSS_COMPILE ?= - -ifeq ($(ARCH),riscv) -TARGET_TRIPLE := riscv64-unknown-linux-gnu -ifeq ($(strip $(GCC_TOOLCHAIN)),) -ifneq ($(wildcard /opt/riscv64-glibc/bin/riscv64-unknown-linux-gnu-g++),) -GCC_TOOLCHAIN := /opt/riscv64-glibc -endif -endif -ifeq ($(strip $(CROSS_COMPILE)),) -ifneq ($(strip $(GCC_TOOLCHAIN)),) -CROSS_COMPILE := $(GCC_TOOLCHAIN)/bin/$(TARGET_TRIPLE)- -else -CROSS_COMPILE := $(TARGET_TRIPLE)- -endif -endif -else ifeq ($(ARCH),aarch64) -TARGET_TRIPLE := aarch64-linux-gnu -else ifeq ($(ARCH),x86_64) -TARGET_TRIPLE := x86_64-linux-gnu -endif - -ifeq ($(strip $(CROSS_COMPILE)),) -CROSS_COMPILE := $(TARGET_TRIPLE)- -endif -ifeq ($(strip $(GCC_TOOLCHAIN)),) -GCC_TOOLCHAIN := $(patsubst %/bin/,%, $(dir $(CROSS_COMPILE))) -endif - -GCC_SYSROOT := $(strip $(shell $(CROSS_COMPILE)g++ -print-sysroot 2>/dev/null)) - -CLANG_SUFFIX := $(if $(LLVM_VERSION),-$(LLVM_VERSION),) -CLANG ?= clang$(CLANG_SUFFIX) -CLANGXX ?= clang++$(CLANG_SUFFIX) -LLD ?= ld.lld$(CLANG_SUFFIX) - -CLANG_TARGET_FLAGS := --target=$(TARGET_TRIPLE) -ifneq ($(strip $(GCC_TOOLCHAIN)),) -CLANG_TARGET_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) -endif -ifneq ($(strip $(GCC_SYSROOT)),) -CLANG_TARGET_FLAGS += --sysroot=$(GCC_SYSROOT) -endif - -ifeq ($(LLVM),1) -CC := $(CLANG) -CXX := $(CLANGXX) -COMPILER_FAMILY := clang -TOOLCHAIN_CFLAGS := $(CLANG_TARGET_FLAGS) -TOOLCHAIN_CXXFLAGS := -COMPILER_RESOURCE_DIR := $(strip $(shell $(CXX) $(CLANG_TARGET_FLAGS) -print-resource-dir 2>/dev/null)) -COMPILER_RESOURCE_INCLUDE := $(COMPILER_RESOURCE_DIR)/include -ifeq ($(LD_TYPE),lld) -LD := $(LLD) -LINKER_FAMILY := lld -else -LD := $(CROSS_COMPILE)ld -LINKER_FAMILY := bfd -endif - -else -CC := $(CROSS_COMPILE)gcc -CXX := $(CROSS_COMPILE)g++ -LD := $(CROSS_COMPILE)ld -COMPILER_FAMILY := gcc -LINKER_FAMILY := bfd -COMPILER_RESOURCE_INCLUDE := $(strip $(shell $(CXX) -print-file-name=include 2>/dev/null)) -endif - -ifeq ($(wildcard $(COMPILER_RESOURCE_INCLUDE)/stddef.h),) -$(error missing compiler resource headers under '$(COMPILER_RESOURCE_INCLUDE)') -endif - -# Kernel and phys code must not observe the Linux target sysroot. Supply only -# compiler intrinsic headers explicitly; the target graph provides the kernel -# libc and KTL layers, followed by the pinned libc++ headers for C++. -TOOLCHAIN_CFLAGS += -nostdinc -isystem $(COMPILER_RESOURCE_INCLUDE) -TOOLCHAIN_CXXFLAGS += -isystem $(LIBCXX_INCLUDE) - -ifeq ($(LLVM_BINUTILS),1) -AR := llvm-ar$(CLANG_SUFFIX) -NM := llvm-nm$(CLANG_SUFFIX) -OBJCOPY := llvm-objcopy$(CLANG_SUFFIX) -OBJDUMP := llvm-objdump$(CLANG_SUFFIX) -READELF := llvm-readelf$(CLANG_SUFFIX) -else -AR := $(CROSS_COMPILE)ar -NM := $(CROSS_COMPILE)nm -OBJCOPY := $(CROSS_COMPILE)objcopy -OBJDUMP := $(CROSS_COMPILE)objdump -READELF := $(CROSS_COMPILE)readelf -endif -SIZE := $(CROSS_COMPILE)size diff --git a/scripts/build/write-compdb.py b/scripts/build/write-compdb.py deleted file mode 100755 index 9ec5a49..0000000 --- a/scripts/build/write-compdb.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0-or-later - -import json -import pathlib -import sys - -source = pathlib.Path(sys.argv[1]) -output = pathlib.Path(sys.argv[2]) -directory = pathlib.Path.cwd() -entries = [] -for line in source.read_text().splitlines(): - file_name, object_name, command = line.split("\t", 2) - entries.append( - { - "directory": str(directory), - "file": file_name, - "output": object_name, - "command": command, - } - ) -output.parent.mkdir(parents=True, exist_ok=True) -temporary = output.with_suffix(output.suffix + ".tmp") -temporary.write_text(json.dumps(entries, indent=2) + "\n") -temporary.replace(output) - diff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c deleted file mode 100644 index 56d4dcb..0000000 --- a/scripts/dtc/libfdt/fdt.c +++ /dev/null @@ -1,347 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -/* - * Minimal sanity check for a read-only tree. fdt_ro_probe_() checks - * that the given buffer contains what appears to be a flattened - * device tree with sane information in its header. - */ -int32_t fdt_ro_probe_(const void *fdt) -{ - uint32_t totalsize = fdt_totalsize(fdt); - - if (can_assume(VALID_DTB)) - return totalsize; - - /* The device tree must be at an 8-byte aligned address */ - if ((uintptr_t)fdt & 7) - return -FDT_ERR_ALIGNMENT; - - if (fdt_magic(fdt) == FDT_MAGIC) { - /* Complete tree */ - if (!can_assume(LATEST)) { - if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) - return -FDT_ERR_BADVERSION; - if (fdt_last_comp_version(fdt) > - FDT_LAST_SUPPORTED_VERSION) - return -FDT_ERR_BADVERSION; - } - } else if (fdt_magic(fdt) == FDT_SW_MAGIC) { - /* Unfinished sequential-write blob */ - if (!can_assume(VALID_INPUT) && fdt_size_dt_struct(fdt) == 0) - return -FDT_ERR_BADSTATE; - } else { - return -FDT_ERR_BADMAGIC; - } - - if (totalsize < INT32_MAX) - return totalsize; - else - return -FDT_ERR_TRUNCATED; -} - -static int check_off_(uint32_t hdrsize, uint32_t totalsize, uint32_t off) -{ - return (off >= hdrsize) && (off <= totalsize); -} - -static int check_block_(uint32_t hdrsize, uint32_t totalsize, - uint32_t base, uint32_t size) -{ - if (!check_off_(hdrsize, totalsize, base)) - return 0; /* block start out of bounds */ - if ((base + size) < base) - return 0; /* overflow */ - if (!check_off_(hdrsize, totalsize, base + size)) - return 0; /* block end out of bounds */ - return 1; -} - -size_t fdt_header_size_(uint32_t version) -{ - if (version <= 1) - return FDT_V1_SIZE; - else if (version <= 2) - return FDT_V2_SIZE; - else if (version <= 3) - return FDT_V3_SIZE; - else if (version <= 16) - return FDT_V16_SIZE; - else - return FDT_V17_SIZE; -} - -size_t fdt_header_size(const void *fdt) -{ - return can_assume(LATEST) ? FDT_V17_SIZE : - fdt_header_size_(fdt_version(fdt)); -} - -int fdt_check_header(const void *fdt) -{ - size_t hdrsize; - - /* The device tree must be at an 8-byte aligned address */ - if ((uintptr_t)fdt & 7) - return -FDT_ERR_ALIGNMENT; - - if (fdt_magic(fdt) != FDT_MAGIC) - return -FDT_ERR_BADMAGIC; - if (!can_assume(LATEST)) { - if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) - || (fdt_last_comp_version(fdt) > - FDT_LAST_SUPPORTED_VERSION)) - return -FDT_ERR_BADVERSION; - if (fdt_version(fdt) < fdt_last_comp_version(fdt)) - return -FDT_ERR_BADVERSION; - } - hdrsize = fdt_header_size(fdt); - if (!can_assume(VALID_DTB)) { - if ((fdt_totalsize(fdt) < hdrsize) - || (fdt_totalsize(fdt) > INT_MAX)) - return -FDT_ERR_TRUNCATED; - - /* memrsv block must be 8 byte aligned */ - if (fdt_off_mem_rsvmap(fdt) % sizeof(uint64_t)) - return -FDT_ERR_ALIGNMENT; - - /* Structure block must be 4 byte aligned */ - if (fdt_off_dt_struct(fdt) % FDT_TAGSIZE) - return -FDT_ERR_ALIGNMENT; - - /* Bounds check memrsv block */ - if (!check_off_(hdrsize, fdt_totalsize(fdt), - fdt_off_mem_rsvmap(fdt))) - return -FDT_ERR_TRUNCATED; - - /* Bounds check structure block */ - if (!can_assume(LATEST) && fdt_version(fdt) < 17) { - if (!check_off_(hdrsize, fdt_totalsize(fdt), - fdt_off_dt_struct(fdt))) - return -FDT_ERR_TRUNCATED; - } else { - if (!check_block_(hdrsize, fdt_totalsize(fdt), - fdt_off_dt_struct(fdt), - fdt_size_dt_struct(fdt))) - return -FDT_ERR_TRUNCATED; - } - - /* Bounds check strings block */ - if (!check_block_(hdrsize, fdt_totalsize(fdt), - fdt_off_dt_strings(fdt), - fdt_size_dt_strings(fdt))) - return -FDT_ERR_TRUNCATED; - } - - return 0; -} - -const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) -{ - unsigned int uoffset = offset; - unsigned int absoffset = offset + fdt_off_dt_struct(fdt); - - if (offset < 0) - return NULL; - - if (!can_assume(VALID_INPUT)) - if ((absoffset < uoffset) - || ((absoffset + len) < absoffset) - || (absoffset + len) > fdt_totalsize(fdt)) - return NULL; - - if (can_assume(LATEST) || fdt_version(fdt) >= 0x11) - if (((uoffset + len) < uoffset) - || ((offset + len) > fdt_size_dt_struct(fdt))) - return NULL; - - return fdt_offset_ptr_(fdt, offset); -} - -uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) -{ - const fdt32_t *tagp, *lenp; - uint32_t tag, len, sum; - int offset = startoffset; - const char *p; - - *nextoffset = -FDT_ERR_TRUNCATED; - tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE); - if (!can_assume(VALID_DTB) && !tagp) - return FDT_END; /* premature end */ - tag = fdt32_to_cpu(*tagp); - offset += FDT_TAGSIZE; - - *nextoffset = -FDT_ERR_BADSTRUCTURE; - switch (tag) { - case FDT_BEGIN_NODE: - /* skip name */ - do { - p = fdt_offset_ptr(fdt, offset++, 1); - } while (p && (*p != '\0')); - if (!can_assume(VALID_DTB) && !p) - return FDT_END; /* premature end */ - break; - - case FDT_PROP: - lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp)); - if (!can_assume(VALID_DTB) && !lenp) - return FDT_END; /* premature end */ - - len = fdt32_to_cpu(*lenp); - sum = len + offset; - if (!can_assume(VALID_DTB) && - (INT_MAX <= sum || sum < (uint32_t) offset)) - return FDT_END; /* premature end */ - - /* skip-name offset, length and value */ - offset += sizeof(struct fdt_property) - FDT_TAGSIZE + len; - - if (!can_assume(LATEST) && - fdt_version(fdt) < 0x10 && len >= 8 && - ((offset - len) % 8) != 0) - offset += 4; - break; - - case FDT_END: - case FDT_END_NODE: - case FDT_NOP: - break; - - default: - return FDT_END; - } - - if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset)) - return FDT_END; /* premature end */ - - *nextoffset = FDT_TAGALIGN(offset); - return tag; -} - -int fdt_check_node_offset_(const void *fdt, int offset) -{ - if (!can_assume(VALID_INPUT) - && ((offset < 0) || (offset % FDT_TAGSIZE))) - return -FDT_ERR_BADOFFSET; - - if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE) - return -FDT_ERR_BADOFFSET; - - return offset; -} - -int fdt_check_prop_offset_(const void *fdt, int offset) -{ - if (!can_assume(VALID_INPUT) - && ((offset < 0) || (offset % FDT_TAGSIZE))) - return -FDT_ERR_BADOFFSET; - - if (fdt_next_tag(fdt, offset, &offset) != FDT_PROP) - return -FDT_ERR_BADOFFSET; - - return offset; -} - -int fdt_next_node(const void *fdt, int offset, int *depth) -{ - int nextoffset = 0; - uint32_t tag; - - if (offset >= 0) - if ((nextoffset = fdt_check_node_offset_(fdt, offset)) < 0) - return nextoffset; - - do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - - switch (tag) { - case FDT_PROP: - case FDT_NOP: - break; - - case FDT_BEGIN_NODE: - if (depth) - (*depth)++; - break; - - case FDT_END_NODE: - if (depth && ((--(*depth)) < 0)) - return nextoffset; - break; - - case FDT_END: - if ((nextoffset >= 0) - || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth)) - return -FDT_ERR_NOTFOUND; - else - return nextoffset; - } - } while (tag != FDT_BEGIN_NODE); - - return offset; -} - -int fdt_first_subnode(const void *fdt, int offset) -{ - int depth = 0; - - offset = fdt_next_node(fdt, offset, &depth); - if (offset < 0 || depth != 1) - return -FDT_ERR_NOTFOUND; - - return offset; -} - -int fdt_next_subnode(const void *fdt, int offset) -{ - int depth = 1; - - /* - * With respect to the parent, the depth of the next subnode will be - * the same as the last. - */ - do { - offset = fdt_next_node(fdt, offset, &depth); - if (offset < 0 || depth < 1) - return -FDT_ERR_NOTFOUND; - } while (depth > 1); - - return offset; -} - -const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s, - int slen) -{ - const char *last = strtab + tabsize - (slen + 1); - const char *p; - - for (p = strtab; p <= last; p++) - if (memcmp(p, s, slen) == 0 && p[slen] == '\0') - return p; - return NULL; -} - -int fdt_move(const void *fdt, void *buf, int bufsize) -{ - if (!can_assume(VALID_INPUT) && bufsize < 0) - return -FDT_ERR_NOSPACE; - - FDT_RO_PROBE(fdt); - - if (fdt_totalsize(fdt) > (unsigned int)bufsize) - return -FDT_ERR_NOSPACE; - - memmove(buf, fdt, fdt_totalsize(fdt)); - return 0; -} diff --git a/scripts/dtc/libfdt/fdt.h b/scripts/dtc/libfdt/fdt.h deleted file mode 100644 index a07abfc..0000000 --- a/scripts/dtc/libfdt/fdt.h +++ /dev/null @@ -1,66 +0,0 @@ -/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ -#ifndef FDT_H -#define FDT_H -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * Copyright 2012 Kim Phillips, Freescale Semiconductor. - */ - -#ifndef __ASSEMBLER__ - -struct fdt_header { - fdt32_t magic; /* magic word FDT_MAGIC */ - fdt32_t totalsize; /* total size of DT block */ - fdt32_t off_dt_struct; /* offset to structure */ - fdt32_t off_dt_strings; /* offset to strings */ - fdt32_t off_mem_rsvmap; /* offset to memory reserve map */ - fdt32_t version; /* format version */ - fdt32_t last_comp_version; /* last compatible version */ - - /* version 2 fields below */ - fdt32_t boot_cpuid_phys; /* Which physical CPU id we're - booting on */ - /* version 3 fields below */ - fdt32_t size_dt_strings; /* size of the strings block */ - - /* version 17 fields below */ - fdt32_t size_dt_struct; /* size of the structure block */ -}; - -struct fdt_reserve_entry { - fdt64_t address; - fdt64_t size; -}; - -struct fdt_node_header { - fdt32_t tag; - char name[]; -}; - -struct fdt_property { - fdt32_t tag; - fdt32_t len; - fdt32_t nameoff; - char data[]; -}; - -#endif /* !__ASSEMBLER__ */ - -#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ -#define FDT_TAGSIZE sizeof(fdt32_t) - -#define FDT_BEGIN_NODE 0x1 /* Start node: full name */ -#define FDT_END_NODE 0x2 /* End node */ -#define FDT_PROP 0x3 /* Property: name off, - size, content */ -#define FDT_NOP 0x4 /* nop */ -#define FDT_END 0x9 - -#define FDT_V1_SIZE (7*sizeof(fdt32_t)) -#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t)) -#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t)) -#define FDT_V16_SIZE FDT_V3_SIZE -#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) - -#endif /* FDT_H */ diff --git a/scripts/dtc/libfdt/fdt_addresses.c b/scripts/dtc/libfdt/fdt_addresses.c deleted file mode 100644 index c40ba09..0000000 --- a/scripts/dtc/libfdt/fdt_addresses.c +++ /dev/null @@ -1,101 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2014 David Gibson - * Copyright (C) 2018 embedded brains GmbH - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -static int fdt_cells(const void *fdt, int nodeoffset, const char *name) -{ - const fdt32_t *c; - uint32_t val; - int len; - - c = fdt_getprop(fdt, nodeoffset, name, &len); - if (!c) - return len; - - if (len != sizeof(*c)) - return -FDT_ERR_BADNCELLS; - - val = fdt32_to_cpu(*c); - if (val > FDT_MAX_NCELLS) - return -FDT_ERR_BADNCELLS; - - return (int)val; -} - -int fdt_address_cells(const void *fdt, int nodeoffset) -{ - int val; - - val = fdt_cells(fdt, nodeoffset, "#address-cells"); - if (val == 0) - return -FDT_ERR_BADNCELLS; - if (val == -FDT_ERR_NOTFOUND) - return 2; - return val; -} - -int fdt_size_cells(const void *fdt, int nodeoffset) -{ - int val; - - val = fdt_cells(fdt, nodeoffset, "#size-cells"); - if (val == -FDT_ERR_NOTFOUND) - return 1; - return val; -} - -/* This function assumes that [address|size]_cells is 1 or 2 */ -int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset, - const char *name, uint64_t addr, uint64_t size) -{ - int addr_cells, size_cells, ret; - uint8_t data[sizeof(fdt64_t) * 2], *prop; - - ret = fdt_address_cells(fdt, parent); - if (ret < 0) - return ret; - addr_cells = ret; - - ret = fdt_size_cells(fdt, parent); - if (ret < 0) - return ret; - size_cells = ret; - - /* check validity of address */ - prop = data; - if (addr_cells == 1) { - if ((addr > UINT32_MAX) || (((uint64_t) UINT32_MAX + 1 - addr) < size)) - return -FDT_ERR_BADVALUE; - - fdt32_st(prop, (uint32_t)addr); - } else if (addr_cells == 2) { - fdt64_st(prop, addr); - } else { - return -FDT_ERR_BADNCELLS; - } - - /* check validity of size */ - prop += addr_cells * sizeof(fdt32_t); - if (size_cells == 1) { - if (size > UINT32_MAX) - return -FDT_ERR_BADVALUE; - - fdt32_st(prop, (uint32_t)size); - } else if (size_cells == 2) { - fdt64_st(prop, size); - } else { - return -FDT_ERR_BADNCELLS; - } - - return fdt_appendprop(fdt, nodeoffset, name, data, - (addr_cells + size_cells) * sizeof(fdt32_t)); -} diff --git a/scripts/dtc/libfdt/fdt_empty_tree.c b/scripts/dtc/libfdt/fdt_empty_tree.c deleted file mode 100644 index 49d54d4..0000000 --- a/scripts/dtc/libfdt/fdt_empty_tree.c +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2012 David Gibson, IBM Corporation. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -int fdt_create_empty_tree(void *buf, int bufsize) -{ - int err; - - err = fdt_create(buf, bufsize); - if (err) - return err; - - err = fdt_finish_reservemap(buf); - if (err) - return err; - - err = fdt_begin_node(buf, ""); - if (err) - return err; - - err = fdt_end_node(buf); - if (err) - return err; - - err = fdt_finish(buf); - if (err) - return err; - - return fdt_open_into(buf, buf, bufsize); -} diff --git a/scripts/dtc/libfdt/fdt_overlay.c b/scripts/dtc/libfdt/fdt_overlay.c deleted file mode 100644 index 51a3859..0000000 --- a/scripts/dtc/libfdt/fdt_overlay.c +++ /dev/null @@ -1,1101 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2016 Free Electrons - * Copyright (C) 2016 NextThing Co. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -/** - * overlay_get_target_phandle - retrieves the target phandle of a fragment - * @fdto: pointer to the device tree overlay blob - * @fragment: node offset of the fragment in the overlay - * - * overlay_get_target_phandle() retrieves the target phandle of an - * overlay fragment when that fragment uses a phandle (target - * property) instead of a path (target-path property). - * - * returns: - * the phandle pointed by the target property - * 0, if the phandle was not found - * -1, if the phandle was malformed - */ -static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) -{ - const fdt32_t *val; - int len; - - val = fdt_getprop(fdto, fragment, "target", &len); - if (!val) - return 0; - - if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1)) - return (uint32_t)-1; - - return fdt32_to_cpu(*val); -} - -int fdt_overlay_target_offset(const void *fdt, const void *fdto, - int fragment_offset, char const **pathp) -{ - uint32_t phandle; - const char *path = NULL; - int path_len = 0, ret; - - /* Try first to do a phandle based lookup */ - phandle = overlay_get_target_phandle(fdto, fragment_offset); - if (phandle == (uint32_t)-1) - return -FDT_ERR_BADPHANDLE; - - /* no phandle, try path */ - if (!phandle) { - /* And then a path based lookup */ - path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len); - if (path) - ret = fdt_path_offset(fdt, path); - else - ret = path_len; - } else - ret = fdt_node_offset_by_phandle(fdt, phandle); - - /* - * If we haven't found either a target or a - * target-path property in a node that contains a - * __overlay__ subnode (we wouldn't be called - * otherwise), consider it a improperly written - * overlay - */ - if (ret < 0 && path_len == -FDT_ERR_NOTFOUND) - ret = -FDT_ERR_BADOVERLAY; - - /* return on error */ - if (ret < 0) - return ret; - - /* return pointer to path (if available) */ - if (pathp) - *pathp = path ? path : NULL; - - return ret; -} - -/** - * overlay_phandle_add_offset - Increases a phandle by an offset - * @fdt: Base device tree blob - * @node: Device tree overlay blob - * @name: Name of the property to modify (phandle or linux,phandle) - * @delta: offset to apply - * - * overlay_phandle_add_offset() increments a node phandle by a given - * offset. - * - * returns: - * 0 on success. - * Negative error code on error - */ -static int overlay_phandle_add_offset(void *fdt, int node, - const char *name, uint32_t delta) -{ - fdt32_t *valp, val; - int len; - - valp = fdt_getprop_w(fdt, node, name, &len); - if (!valp) - return len; - - if (len != sizeof(val)) - return -FDT_ERR_BADPHANDLE; - - val = fdt32_ld(valp); - if (val + delta < val || val + delta == (uint32_t)-1) - return -FDT_ERR_NOPHANDLES; - - fdt32_st(valp, val + delta); - return 0; -} - -/** - * overlay_adjust_node_phandles - Offsets the phandles of a node - * @fdto: Device tree overlay blob - * @node: Offset of the node we want to adjust - * @delta: Offset to shift the phandles of - * - * overlay_adjust_node_phandles() adds a constant to all the phandles - * of a given node. This is mainly use as part of the overlay - * application process, when we want to update all the overlay - * phandles to not conflict with the overlays of the base device tree. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_adjust_node_phandles(void *fdto, int node, - uint32_t delta) -{ - int child; - int ret; - - ret = overlay_phandle_add_offset(fdto, node, "phandle", delta); - if (ret && ret != -FDT_ERR_NOTFOUND) - return ret; - - ret = overlay_phandle_add_offset(fdto, node, "linux,phandle", delta); - if (ret && ret != -FDT_ERR_NOTFOUND) - return ret; - - fdt_for_each_subnode(child, fdto, node) { - ret = overlay_adjust_node_phandles(fdto, child, delta); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_adjust_local_phandles - Adjust the phandles of a whole overlay - * @fdto: Device tree overlay blob - * @delta: Offset to shift the phandles of - * - * overlay_adjust_local_phandles() adds a constant to all the - * phandles of an overlay. This is mainly use as part of the overlay - * application process, when we want to update all the overlay - * phandles to not conflict with the overlays of the base device tree. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_adjust_local_phandles(void *fdto, uint32_t delta) -{ - /* - * Start adjusting the phandles from the overlay root - */ - return overlay_adjust_node_phandles(fdto, 0, delta); -} - -/** - * overlay_update_local_node_references - Adjust the overlay references - * @fdto: Device tree overlay blob - * @tree_node: Node offset of the node to operate on - * @fixup_node: Node offset of the matching local fixups node - * @delta: Offset to shift the phandles of - * - * overlay_update_local_nodes_references() update the phandles - * pointing to a node within the device tree overlay by adding a - * constant delta. - * - * This is mainly used as part of a device tree application process, - * where you want the device tree overlays phandles to not conflict - * with the ones from the base device tree before merging them. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_update_local_node_references(void *fdto, - int tree_node, - int fixup_node, - uint32_t delta) -{ - int fixup_prop; - int fixup_child; - int ret; - - fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) { - const fdt32_t *fixup_val; - const char *name; - char *tree_val; - int fixup_len; - int tree_len; - int i; - - fixup_val = fdt_getprop_by_offset(fdto, fixup_prop, - &name, &fixup_len); - if (!fixup_val) - return fixup_len; - - if (fixup_len % sizeof(uint32_t)) - return -FDT_ERR_BADOVERLAY; - fixup_len /= sizeof(uint32_t); - - tree_val = fdt_getprop_w(fdto, tree_node, name, &tree_len); - if (!tree_val) { - if (tree_len == -FDT_ERR_NOTFOUND) - return -FDT_ERR_BADOVERLAY; - - return tree_len; - } - - for (i = 0; i < fixup_len; i++) { - fdt32_t *refp; - - refp = (fdt32_t *)(tree_val + fdt32_ld_(fixup_val + i)); - - /* - * phandles to fixup can be unaligned, so use - * fdt32_{ld,st}() to read/write them. - */ - fdt32_st(refp, fdt32_ld(refp) + delta); - } - } - - fdt_for_each_subnode(fixup_child, fdto, fixup_node) { - const char *fixup_child_name = fdt_get_name(fdto, fixup_child, - NULL); - int tree_child; - - tree_child = fdt_subnode_offset(fdto, tree_node, - fixup_child_name); - if (tree_child == -FDT_ERR_NOTFOUND) - return -FDT_ERR_BADOVERLAY; - if (tree_child < 0) - return tree_child; - - ret = overlay_update_local_node_references(fdto, - tree_child, - fixup_child, - delta); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_update_local_references - Adjust the overlay references - * @fdto: Device tree overlay blob - * @delta: Offset to shift the phandles of - * - * overlay_update_local_references() update all the phandles pointing - * to a node within the device tree overlay by adding a constant - * delta to not conflict with the base overlay. - * - * This is mainly used as part of a device tree application process, - * where you want the device tree overlays phandles to not conflict - * with the ones from the base device tree before merging them. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_update_local_references(void *fdto, uint32_t delta) -{ - int fixups; - - fixups = fdt_path_offset(fdto, "/__local_fixups__"); - if (fixups < 0) { - /* There's no local phandles to adjust, bail out */ - if (fixups == -FDT_ERR_NOTFOUND) - return 0; - - return fixups; - } - - /* - * Update our local references from the root of the tree - */ - return overlay_update_local_node_references(fdto, 0, fixups, - delta); -} - -/** - * overlay_fixup_one_phandle - Set an overlay phandle to the base one - * @fdto: Device tree overlay blob - * @symbols_off: Node offset of the symbols node in the base device tree - * @path: Path to a node holding a phandle in the overlay - * @path_len: number of path characters to consider - * @name: Name of the property holding the phandle reference in the overlay - * @name_len: number of name characters to consider - * @poffset: Offset within the overlay property where the phandle is stored - * @phandle: Phandle referencing the node - * - * overlay_fixup_one_phandle() resolves an overlay phandle pointing to - * a node in the base device tree. - * - * This is part of the device tree overlay application process, when - * you want all the phandles in the overlay to point to the actual - * base dt nodes. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_fixup_one_phandle(void *fdto, int symbols_off, - const char *path, uint32_t path_len, - const char *name, uint32_t name_len, - int poffset, uint32_t phandle) -{ - fdt32_t phandle_prop; - int fixup_off; - - if (symbols_off < 0) - return symbols_off; - - fixup_off = fdt_path_offset_namelen(fdto, path, path_len); - if (fixup_off == -FDT_ERR_NOTFOUND) - return -FDT_ERR_BADOVERLAY; - if (fixup_off < 0) - return fixup_off; - - phandle_prop = cpu_to_fdt32(phandle); - return fdt_setprop_inplace_namelen_partial(fdto, fixup_off, - name, name_len, poffset, - &phandle_prop, - sizeof(phandle_prop)); -} - -/** - * overlay_fixup_phandle - Set an overlay phandle to the base one - * @fdt: Base Device Tree blob - * @fdto: Device tree overlay blob - * @symbols_off: Node offset of the symbols node in the base device tree - * @property: Property offset in the overlay holding the list of fixups - * - * overlay_fixup_phandle() resolves all the overlay phandles pointed - * to in a __fixups__ property, and updates them to match the phandles - * in use in the base device tree. - * - * This is part of the device tree overlay application process, when - * you want all the phandles in the overlay to point to the actual - * base dt nodes. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off, - int property) -{ - const char *value; - const char *label; - int len; - const char *symbol_path; - int prop_len; - int symbol_off; - uint32_t phandle; - - value = fdt_getprop_by_offset(fdto, property, - &label, &len); - if (!value) { - if (len == -FDT_ERR_NOTFOUND) - return -FDT_ERR_INTERNAL; - - return len; - } - - symbol_path = fdt_getprop(fdt, symbols_off, label, &prop_len); - if (!symbol_path) - return prop_len; - - symbol_off = fdt_path_offset(fdt, symbol_path); - if (symbol_off < 0) - return symbol_off; - - phandle = fdt_get_phandle(fdt, symbol_off); - if (!phandle) - return -FDT_ERR_NOTFOUND; - - do { - const char *path, *name, *fixup_end; - const char *fixup_str = value; - uint32_t path_len, name_len; - uint32_t fixup_len; - const char *sep; - char *endptr; - int poffset, ret; - - fixup_end = memchr(value, '\0', len); - if (!fixup_end) - return -FDT_ERR_BADOVERLAY; - fixup_len = fixup_end - fixup_str; - - len -= fixup_len + 1; - value += fixup_len + 1; - - path = fixup_str; - sep = memchr(fixup_str, ':', fixup_len); - if (!sep || *sep != ':') - return -FDT_ERR_BADOVERLAY; - - path_len = sep - path; - if (path_len == (fixup_len - 1)) - return -FDT_ERR_BADOVERLAY; - - fixup_len -= path_len + 1; - name = sep + 1; - sep = memchr(name, ':', fixup_len); - if (!sep || *sep != ':') - return -FDT_ERR_BADOVERLAY; - - name_len = sep - name; - if (!name_len) - return -FDT_ERR_BADOVERLAY; - - poffset = strtoul(sep + 1, &endptr, 10); - if ((*endptr != '\0') || (endptr <= (sep + 1))) - return -FDT_ERR_BADOVERLAY; - - ret = overlay_fixup_one_phandle(fdto, symbols_off, - path, path_len, name, name_len, - poffset, phandle); - if (ret) - return ret; - } while (len > 0); - - return 0; -} - -/** - * overlay_fixup_phandles - Resolve the overlay phandles to the base - * device tree - * @fdt: Base Device Tree blob - * @fdto: Device tree overlay blob - * - * overlay_fixup_phandles() resolves all the overlay phandles pointing - * to nodes in the base device tree. - * - * This is one of the steps of the device tree overlay application - * process, when you want all the phandles in the overlay to point to - * the actual base dt nodes. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_fixup_phandles(void *fdt, void *fdto) -{ - int fixups_off, symbols_off; - int property; - - /* We can have overlays without any fixups */ - fixups_off = fdt_path_offset(fdto, "/__fixups__"); - if (fixups_off == -FDT_ERR_NOTFOUND) - return 0; /* nothing to do */ - if (fixups_off < 0) - return fixups_off; - - /* And base DTs without symbols */ - symbols_off = fdt_path_offset(fdt, "/__symbols__"); - if ((symbols_off < 0 && (symbols_off != -FDT_ERR_NOTFOUND))) - return symbols_off; - - fdt_for_each_property_offset(property, fdto, fixups_off) { - int ret; - - ret = overlay_fixup_phandle(fdt, fdto, symbols_off, property); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_adjust_local_conflicting_phandle: Changes a phandle value - * @fdto: Device tree overlay - * @node: The node the phandle is set for - * @fdt_phandle: The new value for the phandle - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_adjust_local_conflicting_phandle(void *fdto, int node, - uint32_t fdt_phandle) -{ - const fdt32_t *php; - int len, ret; - - php = fdt_getprop(fdto, node, "phandle", &len); - if (php && len == sizeof(*php)) { - ret = fdt_setprop_inplace_u32(fdto, node, "phandle", fdt_phandle); - if (ret) - return ret; - } - - php = fdt_getprop(fdto, node, "linux,phandle", &len); - if (php && len == sizeof(*php)) { - ret = fdt_setprop_inplace_u32(fdto, node, "linux,phandle", fdt_phandle); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_update_node_conflicting_references - Recursively replace phandle values - * @fdto: Device tree overlay blob - * @tree_node: Node to recurse into - * @fixup_node: Node offset of the matching local fixups node - * @fdt_phandle: Value to replace phandles with - * @fdto_phandle: Value to be replaced - * - * Replaces all phandles with value @fdto_phandle by @fdt_phandle. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_update_node_conflicting_references(void *fdto, int tree_node, - int fixup_node, - uint32_t fdt_phandle, - uint32_t fdto_phandle) -{ - int fixup_prop; - int fixup_child; - int ret; - - fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) { - const fdt32_t *fixup_val; - const char *name; - char *tree_val; - int fixup_len; - int tree_len; - int i; - - fixup_val = fdt_getprop_by_offset(fdto, fixup_prop, - &name, &fixup_len); - if (!fixup_val) - return fixup_len; - - if (fixup_len % sizeof(uint32_t)) - return -FDT_ERR_BADOVERLAY; - fixup_len /= sizeof(uint32_t); - - tree_val = fdt_getprop_w(fdto, tree_node, name, &tree_len); - if (!tree_val) { - if (tree_len == -FDT_ERR_NOTFOUND) - return -FDT_ERR_BADOVERLAY; - - return tree_len; - } - - for (i = 0; i < fixup_len; i++) { - fdt32_t *refp; - uint32_t valp; - - refp = (fdt32_t *)(tree_val + fdt32_ld_(fixup_val + i)); - valp = fdt32_ld(refp); - - if (valp == fdto_phandle) - fdt32_st(refp, fdt_phandle); - } - } - - fdt_for_each_subnode(fixup_child, fdto, fixup_node) { - const char *fixup_child_name = fdt_get_name(fdto, fixup_child, NULL); - int tree_child; - - tree_child = fdt_subnode_offset(fdto, tree_node, fixup_child_name); - - if (tree_child == -FDT_ERR_NOTFOUND) - return -FDT_ERR_BADOVERLAY; - if (tree_child < 0) - return tree_child; - - ret = overlay_update_node_conflicting_references(fdto, tree_child, - fixup_child, - fdt_phandle, - fdto_phandle); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_update_local_conflicting_references - Recursively replace phandle values - * @fdto: Device tree overlay blob - * @fdt_phandle: Value to replace phandles with - * @fdto_phandle: Value to be replaced - * - * Replaces all phandles with value @fdto_phandle by @fdt_phandle. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_update_local_conflicting_references(void *fdto, - uint32_t fdt_phandle, - uint32_t fdto_phandle) -{ - int fixups; - - fixups = fdt_path_offset(fdto, "/__local_fixups__"); - if (fixups == -FDT_ERR_NOTFOUND) - return 0; - if (fixups < 0) - return fixups; - - return overlay_update_node_conflicting_references(fdto, 0, fixups, - fdt_phandle, - fdto_phandle); -} - -/** - * overlay_prevent_phandle_overwrite_node - Helper function for overlay_prevent_phandle_overwrite - * @fdt: Base Device tree blob - * @fdtnode: Node in fdt that is checked for an overwrite - * @fdto: Device tree overlay blob - * @fdtonode: Node in fdto matching @fdtnode - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_prevent_phandle_overwrite_node(void *fdt, int fdtnode, - void *fdto, int fdtonode) -{ - uint32_t fdt_phandle, fdto_phandle; - int fdtochild; - - fdt_phandle = fdt_get_phandle(fdt, fdtnode); - fdto_phandle = fdt_get_phandle(fdto, fdtonode); - - if (fdt_phandle && fdto_phandle) { - int ret; - - ret = overlay_adjust_local_conflicting_phandle(fdto, fdtonode, - fdt_phandle); - if (ret) - return ret; - - ret = overlay_update_local_conflicting_references(fdto, - fdt_phandle, - fdto_phandle); - if (ret) - return ret; - } - - fdt_for_each_subnode(fdtochild, fdto, fdtonode) { - const char *name = fdt_get_name(fdto, fdtochild, NULL); - int fdtchild; - int ret; - - fdtchild = fdt_subnode_offset(fdt, fdtnode, name); - if (fdtchild == -FDT_ERR_NOTFOUND) - /* - * no further overwrites possible here as this node is - * new - */ - continue; - - ret = overlay_prevent_phandle_overwrite_node(fdt, fdtchild, - fdto, fdtochild); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_prevent_phandle_overwrite - Fixes overlay phandles to not overwrite base phandles - * @fdt: Base Device Tree blob - * @fdto: Device tree overlay blob - * - * Checks recursively if applying fdto overwrites phandle values in the base - * dtb. When such a phandle is found, the fdto is changed to use the fdt's - * phandle value to not break references in the base. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_prevent_phandle_overwrite(void *fdt, void *fdto) -{ - int fragment; - - fdt_for_each_subnode(fragment, fdto, 0) { - int overlay; - int target; - int ret; - - overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); - if (overlay == -FDT_ERR_NOTFOUND) - continue; - - if (overlay < 0) - return overlay; - - target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL); - if (target == -FDT_ERR_NOTFOUND) - /* - * The subtree doesn't exist in the base, so nothing - * will be overwritten. - */ - continue; - else if (target < 0) - return target; - - ret = overlay_prevent_phandle_overwrite_node(fdt, target, - fdto, overlay); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_apply_node - Merges a node into the base device tree - * @fdt: Base Device Tree blob - * @target: Node offset in the base device tree to apply the fragment to - * @fdto: Device tree overlay blob - * @node: Node offset in the overlay holding the changes to merge - * - * overlay_apply_node() merges a node into a target base device tree - * node pointed. - * - * This is part of the final step in the device tree overlay - * application process, when all the phandles have been adjusted and - * resolved and you just have to merge overlay into the base device - * tree. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_apply_node(void *fdt, int target, - void *fdto, int node) -{ - int property; - int subnode; - - fdt_for_each_property_offset(property, fdto, node) { - const char *name; - const void *prop; - int prop_len; - int ret; - - prop = fdt_getprop_by_offset(fdto, property, &name, - &prop_len); - if (prop_len == -FDT_ERR_NOTFOUND) - return -FDT_ERR_INTERNAL; - if (prop_len < 0) - return prop_len; - - ret = fdt_setprop(fdt, target, name, prop, prop_len); - if (ret) - return ret; - } - - fdt_for_each_subnode(subnode, fdto, node) { - const char *name = fdt_get_name(fdto, subnode, NULL); - int nnode; - int ret; - - nnode = fdt_add_subnode(fdt, target, name); - if (nnode == -FDT_ERR_EXISTS) { - nnode = fdt_subnode_offset(fdt, target, name); - if (nnode == -FDT_ERR_NOTFOUND) - return -FDT_ERR_INTERNAL; - } - - if (nnode < 0) - return nnode; - - ret = overlay_apply_node(fdt, nnode, fdto, subnode); - if (ret) - return ret; - } - - return 0; -} - -/** - * overlay_merge - Merge an overlay into its base device tree - * @fdt: Base Device Tree blob - * @fdto: Device tree overlay blob - * - * overlay_merge() merges an overlay into its base device tree. - * - * This is the next to last step in the device tree overlay application - * process, when all the phandles have been adjusted and resolved and - * you just have to merge overlay into the base device tree. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_merge(void *fdt, void *fdto) -{ - int fragment; - - fdt_for_each_subnode(fragment, fdto, 0) { - int overlay; - int target; - int ret; - - /* - * Each fragments will have an __overlay__ node. If - * they don't, it's not supposed to be merged - */ - overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); - if (overlay == -FDT_ERR_NOTFOUND) - continue; - - if (overlay < 0) - return overlay; - - target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL); - if (target < 0) - return target; - - ret = overlay_apply_node(fdt, target, fdto, overlay); - if (ret) - return ret; - } - - return 0; -} - -static int get_path_len(const void *fdt, int nodeoffset) -{ - int len = 0, namelen; - const char *name; - - FDT_RO_PROBE(fdt); - - for (;;) { - name = fdt_get_name(fdt, nodeoffset, &namelen); - if (!name) - return namelen; - - /* root? we're done */ - if (namelen == 0) - break; - - nodeoffset = fdt_parent_offset(fdt, nodeoffset); - if (nodeoffset < 0) - return nodeoffset; - len += namelen + 1; - } - - /* in case of root pretend it's "/" */ - if (len == 0) - len++; - return len; -} - -/** - * overlay_symbol_update - Update the symbols of base tree after a merge - * @fdt: Base Device Tree blob - * @fdto: Device tree overlay blob - * - * overlay_symbol_update() updates the symbols of the base tree with the - * symbols of the applied overlay - * - * This is the last step in the device tree overlay application - * process, allowing the reference of overlay symbols by subsequent - * overlay operations. - * - * returns: - * 0 on success - * Negative error code on failure - */ -static int overlay_symbol_update(void *fdt, void *fdto) -{ - int root_sym, ov_sym, prop, path_len, fragment, target; - int len, frag_name_len, ret, rel_path_len; - const char *s, *e; - const char *path; - const char *name; - const char *frag_name; - const char *rel_path; - const char *target_path; - char *buf; - void *p; - - ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__"); - - /* if no overlay symbols exist no problem */ - if (ov_sym < 0) - return 0; - - root_sym = fdt_subnode_offset(fdt, 0, "__symbols__"); - - /* it no root symbols exist we should create them */ - if (root_sym == -FDT_ERR_NOTFOUND) - root_sym = fdt_add_subnode(fdt, 0, "__symbols__"); - - /* any error is fatal now */ - if (root_sym < 0) - return root_sym; - - /* iterate over each overlay symbol */ - fdt_for_each_property_offset(prop, fdto, ov_sym) { - path = fdt_getprop_by_offset(fdto, prop, &name, &path_len); - if (!path) - return path_len; - - /* verify it's a string property (terminated by a single \0) */ - if (path_len < 1 || memchr(path, '\0', path_len) != &path[path_len - 1]) - return -FDT_ERR_BADVALUE; - - /* keep end marker to avoid strlen() */ - e = path + path_len; - - if (*path != '/') - return -FDT_ERR_BADVALUE; - - /* get fragment name first */ - s = strchr(path + 1, '/'); - if (!s) { - /* Symbol refers to something that won't end - * up in the target tree */ - continue; - } - - frag_name = path + 1; - frag_name_len = s - path - 1; - - /* verify format; safe since "s" lies in \0 terminated prop */ - len = sizeof("/__overlay__/") - 1; - if ((e - s) > len && (memcmp(s, "/__overlay__/", len) == 0)) { - /* //__overlay__/ */ - rel_path = s + len; - rel_path_len = e - rel_path - 1; - } else if ((e - s) == len - && (memcmp(s, "/__overlay__", len - 1) == 0)) { - /* //__overlay__ */ - rel_path = ""; - rel_path_len = 0; - } else { - /* Symbol refers to something that won't end - * up in the target tree */ - continue; - } - - /* find the fragment index in which the symbol lies */ - ret = fdt_subnode_offset_namelen(fdto, 0, frag_name, - frag_name_len); - /* not found? */ - if (ret < 0) - return -FDT_ERR_BADOVERLAY; - fragment = ret; - - /* an __overlay__ subnode must exist */ - ret = fdt_subnode_offset(fdto, fragment, "__overlay__"); - if (ret < 0) - return -FDT_ERR_BADOVERLAY; - - /* get the target of the fragment */ - ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); - if (ret < 0) - return ret; - target = ret; - - /* if we have a target path use */ - if (!target_path) { - ret = get_path_len(fdt, target); - if (ret < 0) - return ret; - len = ret; - } else { - len = strlen(target_path); - } - - ret = fdt_setprop_placeholder(fdt, root_sym, name, - len + (len > 1) + rel_path_len + 1, &p); - if (ret < 0) - return ret; - - if (!target_path) { - /* again in case setprop_placeholder changed it */ - ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); - if (ret < 0) - return ret; - target = ret; - } - - buf = p; - if (len > 1) { /* target is not root */ - if (!target_path) { - ret = fdt_get_path(fdt, target, buf, len + 1); - if (ret < 0) - return ret; - } else - memcpy(buf, target_path, len + 1); - - } else - len--; - - buf[len] = '/'; - memcpy(buf + len + 1, rel_path, rel_path_len); - buf[len + 1 + rel_path_len] = '\0'; - } - - return 0; -} - -int fdt_overlay_apply(void *fdt, void *fdto) -{ - uint32_t delta; - int ret; - - FDT_RO_PROBE(fdt); - FDT_RO_PROBE(fdto); - - ret = fdt_find_max_phandle(fdt, &delta); - if (ret) - goto err; - - /* Increase all phandles in the fdto by delta */ - ret = overlay_adjust_local_phandles(fdto, delta); - if (ret) - goto err; - - /* Adapt the phandle values in fdto to the above increase */ - ret = overlay_update_local_references(fdto, delta); - if (ret) - goto err; - - /* Update fdto's phandles using symbols from fdt */ - ret = overlay_fixup_phandles(fdt, fdto); - if (ret) - goto err; - - /* Don't overwrite phandles in fdt */ - ret = overlay_prevent_phandle_overwrite(fdt, fdto); - if (ret) - goto err; - - ret = overlay_merge(fdt, fdto); - if (ret) - goto err; - - ret = overlay_symbol_update(fdt, fdto); - if (ret) - goto err; - - /* - * The overlay has been damaged, erase its magic. - */ - fdt_set_magic(fdto, ~0); - - return 0; - -err: - /* - * The overlay might have been damaged, erase its magic. - */ - fdt_set_magic(fdto, ~0); - - /* - * The base device tree might have been damaged, erase its - * magic. - */ - fdt_set_magic(fdt, ~0); - - return ret; -} diff --git a/scripts/dtc/libfdt/fdt_ro.c b/scripts/dtc/libfdt/fdt_ro.c deleted file mode 100644 index 63494fb..0000000 --- a/scripts/dtc/libfdt/fdt_ro.c +++ /dev/null @@ -1,888 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -static int fdt_nodename_eq_(const void *fdt, int offset, - const char *s, int len) -{ - int olen; - const char *p = fdt_get_name(fdt, offset, &olen); - - if (!p || olen < len) - /* short match */ - return 0; - - if (memcmp(p, s, len) != 0) - return 0; - - if (p[len] == '\0') - return 1; - else if (!memchr(s, '@', len) && (p[len] == '@')) - return 1; - else - return 0; -} - -const char *fdt_get_string(const void *fdt, int stroffset, int *lenp) -{ - int32_t totalsize; - uint32_t absoffset; - size_t len; - int err; - const char *s, *n; - - if (can_assume(VALID_INPUT)) { - s = (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset; - - if (lenp) - *lenp = strlen(s); - return s; - } - totalsize = fdt_ro_probe_(fdt); - err = totalsize; - if (totalsize < 0) - goto fail; - - err = -FDT_ERR_BADOFFSET; - absoffset = stroffset + fdt_off_dt_strings(fdt); - if (absoffset >= (unsigned)totalsize) - goto fail; - len = totalsize - absoffset; - - if (fdt_magic(fdt) == FDT_MAGIC) { - if (stroffset < 0) - goto fail; - if (can_assume(LATEST) || fdt_version(fdt) >= 17) { - if ((unsigned)stroffset >= fdt_size_dt_strings(fdt)) - goto fail; - if ((fdt_size_dt_strings(fdt) - stroffset) < len) - len = fdt_size_dt_strings(fdt) - stroffset; - } - } else if (fdt_magic(fdt) == FDT_SW_MAGIC) { - unsigned int sw_stroffset = -stroffset; - - if ((stroffset >= 0) || - (sw_stroffset > fdt_size_dt_strings(fdt))) - goto fail; - if (sw_stroffset < len) - len = sw_stroffset; - } else { - err = -FDT_ERR_INTERNAL; - goto fail; - } - - s = (const char *)fdt + absoffset; - n = memchr(s, '\0', len); - if (!n) { - /* missing terminating NULL */ - err = -FDT_ERR_TRUNCATED; - goto fail; - } - - if (lenp) - *lenp = n - s; - return s; - -fail: - if (lenp) - *lenp = err; - return NULL; -} - -const char *fdt_string(const void *fdt, int stroffset) -{ - return fdt_get_string(fdt, stroffset, NULL); -} - -static int fdt_string_eq_(const void *fdt, int stroffset, - const char *s, int len) -{ - int slen; - const char *p = fdt_get_string(fdt, stroffset, &slen); - - return p && (slen == len) && (memcmp(p, s, len) == 0); -} - -int fdt_find_max_phandle(const void *fdt, uint32_t *phandle) -{ - uint32_t max = 0; - int offset = -1; - - while (true) { - uint32_t value; - - offset = fdt_next_node(fdt, offset, NULL); - if (offset < 0) { - if (offset == -FDT_ERR_NOTFOUND) - break; - - return offset; - } - - value = fdt_get_phandle(fdt, offset); - - if (value > max) - max = value; - } - - if (phandle) - *phandle = max; - - return 0; -} - -int fdt_generate_phandle(const void *fdt, uint32_t *phandle) -{ - uint32_t max; - int err; - - err = fdt_find_max_phandle(fdt, &max); - if (err < 0) - return err; - - if (max == FDT_MAX_PHANDLE) - return -FDT_ERR_NOPHANDLES; - - if (phandle) - *phandle = max + 1; - - return 0; -} - -static const struct fdt_reserve_entry *fdt_mem_rsv(const void *fdt, int n) -{ - unsigned int offset = n * sizeof(struct fdt_reserve_entry); - unsigned int absoffset = fdt_off_mem_rsvmap(fdt) + offset; - - if (!can_assume(VALID_INPUT)) { - if (absoffset < fdt_off_mem_rsvmap(fdt)) - return NULL; - if (absoffset > fdt_totalsize(fdt) - - sizeof(struct fdt_reserve_entry)) - return NULL; - } - return fdt_mem_rsv_(fdt, n); -} - -int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) -{ - const struct fdt_reserve_entry *re; - - FDT_RO_PROBE(fdt); - re = fdt_mem_rsv(fdt, n); - if (!can_assume(VALID_INPUT) && !re) - return -FDT_ERR_BADOFFSET; - - *address = fdt64_ld_(&re->address); - *size = fdt64_ld_(&re->size); - return 0; -} - -int fdt_num_mem_rsv(const void *fdt) -{ - int i; - const struct fdt_reserve_entry *re; - - for (i = 0; (re = fdt_mem_rsv(fdt, i)) != NULL; i++) { - if (fdt64_ld_(&re->size) == 0) - return i; - } - return -FDT_ERR_TRUNCATED; -} - -static int nextprop_(const void *fdt, int offset) -{ - uint32_t tag; - int nextoffset; - - do { - tag = fdt_next_tag(fdt, offset, &nextoffset); - - switch (tag) { - case FDT_END: - if (nextoffset >= 0) - return -FDT_ERR_BADSTRUCTURE; - else - return nextoffset; - - case FDT_PROP: - return offset; - } - offset = nextoffset; - } while (tag == FDT_NOP); - - return -FDT_ERR_NOTFOUND; -} - -int fdt_subnode_offset_namelen(const void *fdt, int offset, - const char *name, int namelen) -{ - int depth; - - FDT_RO_PROBE(fdt); - - for (depth = 0; - (offset >= 0) && (depth >= 0); - offset = fdt_next_node(fdt, offset, &depth)) - if ((depth == 1) - && fdt_nodename_eq_(fdt, offset, name, namelen)) - return offset; - - if (depth < 0) - return -FDT_ERR_NOTFOUND; - return offset; /* error */ -} - -int fdt_subnode_offset(const void *fdt, int parentoffset, - const char *name) -{ - return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name)); -} - -int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen) -{ - const char *end = path + namelen; - const char *p = path; - int offset = 0; - - FDT_RO_PROBE(fdt); - - if (!can_assume(VALID_INPUT) && namelen <= 0) - return -FDT_ERR_BADPATH; - - /* see if we have an alias */ - if (*path != '/') { - const char *q = memchr(path, '/', end - p); - - if (!q) - q = end; - - p = fdt_get_alias_namelen(fdt, p, q - p); - if (!p) - return -FDT_ERR_BADPATH; - offset = fdt_path_offset(fdt, p); - - p = q; - } - - while (p < end) { - const char *q; - - while (*p == '/') { - p++; - if (p == end) - return offset; - } - q = memchr(p, '/', end - p); - if (! q) - q = end; - - offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p); - if (offset < 0) - return offset; - - p = q; - } - - return offset; -} - -int fdt_path_offset(const void *fdt, const char *path) -{ - return fdt_path_offset_namelen(fdt, path, strlen(path)); -} - -const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) -{ - const struct fdt_node_header *nh = fdt_offset_ptr_(fdt, nodeoffset); - const char *nameptr; - int err; - - if (!can_assume(VALID_DTB) && (((err = fdt_ro_probe_(fdt)) < 0) - || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0))) - goto fail; - - nameptr = nh->name; - - if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) { - /* - * For old FDT versions, match the naming conventions of V16: - * give only the leaf name (after all /). The actual tree - * contents are loosely checked. - */ - const char *leaf; - leaf = strrchr(nameptr, '/'); - if (leaf == NULL) { - err = -FDT_ERR_BADSTRUCTURE; - goto fail; - } - nameptr = leaf+1; - } - - if (len) - *len = strlen(nameptr); - - return nameptr; - - fail: - if (len) - *len = err; - return NULL; -} - -int fdt_first_property_offset(const void *fdt, int nodeoffset) -{ - int offset; - - if ((offset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) - return offset; - - return nextprop_(fdt, offset); -} - -int fdt_next_property_offset(const void *fdt, int offset) -{ - if ((offset = fdt_check_prop_offset_(fdt, offset)) < 0) - return offset; - - return nextprop_(fdt, offset); -} - -static const struct fdt_property *fdt_get_property_by_offset_(const void *fdt, - int offset, - int *lenp) -{ - int err; - const struct fdt_property *prop; - - if (!can_assume(VALID_INPUT) && - (err = fdt_check_prop_offset_(fdt, offset)) < 0) { - if (lenp) - *lenp = err; - return NULL; - } - - prop = fdt_offset_ptr_(fdt, offset); - - if (lenp) - *lenp = fdt32_ld_(&prop->len); - - return prop; -} - -const struct fdt_property *fdt_get_property_by_offset(const void *fdt, - int offset, - int *lenp) -{ - /* Prior to version 16, properties may need realignment - * and this API does not work. fdt_getprop_*() will, however. */ - - if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) { - if (lenp) - *lenp = -FDT_ERR_BADVERSION; - return NULL; - } - - return fdt_get_property_by_offset_(fdt, offset, lenp); -} - -static const struct fdt_property *fdt_get_property_namelen_(const void *fdt, - int offset, - const char *name, - int namelen, - int *lenp, - int *poffset) -{ - for (offset = fdt_first_property_offset(fdt, offset); - (offset >= 0); - (offset = fdt_next_property_offset(fdt, offset))) { - const struct fdt_property *prop; - - prop = fdt_get_property_by_offset_(fdt, offset, lenp); - if (!can_assume(LIBFDT_FLAWLESS) && !prop) { - offset = -FDT_ERR_INTERNAL; - break; - } - if (fdt_string_eq_(fdt, fdt32_ld_(&prop->nameoff), - name, namelen)) { - if (poffset) - *poffset = offset; - return prop; - } - } - - if (lenp) - *lenp = offset; - return NULL; -} - - -const struct fdt_property *fdt_get_property_namelen(const void *fdt, - int offset, - const char *name, - int namelen, int *lenp) -{ - /* Prior to version 16, properties may need realignment - * and this API does not work. fdt_getprop_*() will, however. */ - if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) { - if (lenp) - *lenp = -FDT_ERR_BADVERSION; - return NULL; - } - - return fdt_get_property_namelen_(fdt, offset, name, namelen, lenp, - NULL); -} - - -const struct fdt_property *fdt_get_property(const void *fdt, - int nodeoffset, - const char *name, int *lenp) -{ - return fdt_get_property_namelen(fdt, nodeoffset, name, - strlen(name), lenp); -} - -const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, - const char *name, int namelen, int *lenp) -{ - int poffset; - const struct fdt_property *prop; - - prop = fdt_get_property_namelen_(fdt, nodeoffset, name, namelen, lenp, - &poffset); - if (!prop) - return NULL; - - /* Handle realignment */ - if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 && - (poffset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8) - return prop->data + 4; - return prop->data; -} - -const void *fdt_getprop_by_offset(const void *fdt, int offset, - const char **namep, int *lenp) -{ - const struct fdt_property *prop; - - prop = fdt_get_property_by_offset_(fdt, offset, lenp); - if (!prop) - return NULL; - if (namep) { - const char *name; - int namelen; - - if (!can_assume(VALID_INPUT)) { - name = fdt_get_string(fdt, fdt32_ld_(&prop->nameoff), - &namelen); - *namep = name; - if (!name) { - if (lenp) - *lenp = namelen; - return NULL; - } - } else { - *namep = fdt_string(fdt, fdt32_ld_(&prop->nameoff)); - } - } - - /* Handle realignment */ - if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 && - (offset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8) - return prop->data + 4; - return prop->data; -} - -const void *fdt_getprop(const void *fdt, int nodeoffset, - const char *name, int *lenp) -{ - return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp); -} - -uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) -{ - const fdt32_t *php; - int len; - - /* FIXME: This is a bit sub-optimal, since we potentially scan - * over all the properties twice. */ - php = fdt_getprop(fdt, nodeoffset, "phandle", &len); - if (!php || (len != sizeof(*php))) { - php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len); - if (!php || (len != sizeof(*php))) - return 0; - } - - return fdt32_ld_(php); -} - -static const void *fdt_path_getprop_namelen(const void *fdt, const char *path, - const char *propname, int propnamelen, - int *lenp) -{ - int offset = fdt_path_offset(fdt, path); - - if (offset < 0) - return NULL; - - return fdt_getprop_namelen(fdt, offset, propname, propnamelen, lenp); -} - -const char *fdt_get_alias_namelen(const void *fdt, - const char *name, int namelen) -{ - int len; - const char *alias; - - alias = fdt_path_getprop_namelen(fdt, "/aliases", name, namelen, &len); - - if (!can_assume(VALID_DTB) && - !(alias && len > 0 && alias[len - 1] == '\0' && *alias == '/')) - return NULL; - - return alias; -} - -const char *fdt_get_alias(const void *fdt, const char *name) -{ - return fdt_get_alias_namelen(fdt, name, strlen(name)); -} - -const char *fdt_get_symbol_namelen(const void *fdt, - const char *name, int namelen) -{ - return fdt_path_getprop_namelen(fdt, "/__symbols__", name, namelen, NULL); -} - -const char *fdt_get_symbol(const void *fdt, const char *name) -{ - return fdt_get_symbol_namelen(fdt, name, strlen(name)); -} - -int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) -{ - int pdepth = 0, p = 0; - int offset, depth, namelen; - const char *name; - - FDT_RO_PROBE(fdt); - - if (buflen < 2) - return -FDT_ERR_NOSPACE; - - for (offset = 0, depth = 0; - (offset >= 0) && (offset <= nodeoffset); - offset = fdt_next_node(fdt, offset, &depth)) { - while (pdepth > depth) { - do { - p--; - } while (buf[p-1] != '/'); - pdepth--; - } - - if (pdepth >= depth) { - name = fdt_get_name(fdt, offset, &namelen); - if (!name) - return namelen; - if ((p + namelen + 1) <= buflen) { - memcpy(buf + p, name, namelen); - p += namelen; - buf[p++] = '/'; - pdepth++; - } - } - - if (offset == nodeoffset) { - if (pdepth < (depth + 1)) - return -FDT_ERR_NOSPACE; - - if (p > 1) /* special case so that root path is "/", not "" */ - p--; - buf[p] = '\0'; - return 0; - } - } - - if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) - return -FDT_ERR_BADOFFSET; - else if (offset == -FDT_ERR_BADOFFSET) - return -FDT_ERR_BADSTRUCTURE; - - return offset; /* error from fdt_next_node() */ -} - -int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, - int supernodedepth, int *nodedepth) -{ - int offset, depth; - int supernodeoffset = -FDT_ERR_INTERNAL; - - FDT_RO_PROBE(fdt); - - if (supernodedepth < 0) - return -FDT_ERR_NOTFOUND; - - for (offset = 0, depth = 0; - (offset >= 0) && (offset <= nodeoffset); - offset = fdt_next_node(fdt, offset, &depth)) { - if (depth == supernodedepth) - supernodeoffset = offset; - - if (offset == nodeoffset) { - if (nodedepth) - *nodedepth = depth; - - if (supernodedepth > depth) - return -FDT_ERR_NOTFOUND; - else - return supernodeoffset; - } - } - - if (!can_assume(VALID_INPUT)) { - if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) - return -FDT_ERR_BADOFFSET; - else if (offset == -FDT_ERR_BADOFFSET) - return -FDT_ERR_BADSTRUCTURE; - } - - return offset; /* error from fdt_next_node() */ -} - -int fdt_node_depth(const void *fdt, int nodeoffset) -{ - int nodedepth; - int err; - - err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth); - if (err) - return (can_assume(LIBFDT_FLAWLESS) || err < 0) ? err : - -FDT_ERR_INTERNAL; - return nodedepth; -} - -int fdt_parent_offset(const void *fdt, int nodeoffset) -{ - int nodedepth = fdt_node_depth(fdt, nodeoffset); - - if (nodedepth < 0) - return nodedepth; - return fdt_supernode_atdepth_offset(fdt, nodeoffset, - nodedepth - 1, NULL); -} - -int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, - const char *propname, - const void *propval, int proplen) -{ - int offset; - const void *val; - int len; - - FDT_RO_PROBE(fdt); - - /* FIXME: The algorithm here is pretty horrible: we scan each - * property of a node in fdt_getprop(), then if that didn't - * find what we want, we scan over them again making our way - * to the next node. Still it's the easiest to implement - * approach; performance can come later. */ - for (offset = fdt_next_node(fdt, startoffset, NULL); - offset >= 0; - offset = fdt_next_node(fdt, offset, NULL)) { - val = fdt_getprop(fdt, offset, propname, &len); - if (val && (len == proplen) - && (memcmp(val, propval, len) == 0)) - return offset; - } - - return offset; /* error from fdt_next_node() */ -} - -int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle) -{ - int offset; - - if ((phandle == 0) || (phandle == ~0U)) - return -FDT_ERR_BADPHANDLE; - - FDT_RO_PROBE(fdt); - - /* FIXME: The algorithm here is pretty horrible: we - * potentially scan each property of a node in - * fdt_get_phandle(), then if that didn't find what - * we want, we scan over them again making our way to the next - * node. Still it's the easiest to implement approach; - * performance can come later. */ - for (offset = fdt_next_node(fdt, -1, NULL); - offset >= 0; - offset = fdt_next_node(fdt, offset, NULL)) { - if (fdt_get_phandle(fdt, offset) == phandle) - return offset; - } - - return offset; /* error from fdt_next_node() */ -} - -int fdt_stringlist_contains(const char *strlist, int listlen, const char *str) -{ - int len = strlen(str); - const char *p; - - while (listlen >= len) { - if (memcmp(str, strlist, len+1) == 0) - return 1; - p = memchr(strlist, '\0', listlen); - if (!p) - return 0; /* malformed strlist.. */ - listlen -= (p-strlist) + 1; - strlist = p + 1; - } - return 0; -} - -int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property) -{ - const char *list, *end; - int length, count = 0; - - list = fdt_getprop(fdt, nodeoffset, property, &length); - if (!list) - return length; - - end = list + length; - - while (list < end) { - length = strnlen(list, end - list) + 1; - - /* Abort if the last string isn't properly NUL-terminated. */ - if (list + length > end) - return -FDT_ERR_BADVALUE; - - list += length; - count++; - } - - return count; -} - -int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, - const char *string) -{ - int length, len, idx = 0; - const char *list, *end; - - list = fdt_getprop(fdt, nodeoffset, property, &length); - if (!list) - return length; - - len = strlen(string) + 1; - end = list + length; - - while (list < end) { - length = strnlen(list, end - list) + 1; - - /* Abort if the last string isn't properly NUL-terminated. */ - if (list + length > end) - return -FDT_ERR_BADVALUE; - - if (length == len && memcmp(list, string, length) == 0) - return idx; - - list += length; - idx++; - } - - return -FDT_ERR_NOTFOUND; -} - -const char *fdt_stringlist_get(const void *fdt, int nodeoffset, - const char *property, int idx, - int *lenp) -{ - const char *list, *end; - int length; - - list = fdt_getprop(fdt, nodeoffset, property, &length); - if (!list) { - if (lenp) - *lenp = length; - - return NULL; - } - - end = list + length; - - while (list < end) { - length = strnlen(list, end - list) + 1; - - /* Abort if the last string isn't properly NUL-terminated. */ - if (list + length > end) { - if (lenp) - *lenp = -FDT_ERR_BADVALUE; - - return NULL; - } - - if (idx == 0) { - if (lenp) - *lenp = length - 1; - - return list; - } - - list += length; - idx--; - } - - if (lenp) - *lenp = -FDT_ERR_NOTFOUND; - - return NULL; -} - -int fdt_node_check_compatible(const void *fdt, int nodeoffset, - const char *compatible) -{ - const void *prop; - int len; - - prop = fdt_getprop(fdt, nodeoffset, "compatible", &len); - if (!prop) - return len; - - return !fdt_stringlist_contains(prop, len, compatible); -} - -int fdt_node_offset_by_compatible(const void *fdt, int startoffset, - const char *compatible) -{ - int offset, err; - - FDT_RO_PROBE(fdt); - - /* FIXME: The algorithm here is pretty horrible: we scan each - * property of a node in fdt_node_check_compatible(), then if - * that didn't find what we want, we scan over them again - * making our way to the next node. Still it's the easiest to - * implement approach; performance can come later. */ - for (offset = fdt_next_node(fdt, startoffset, NULL); - offset >= 0; - offset = fdt_next_node(fdt, offset, NULL)) { - err = fdt_node_check_compatible(fdt, offset, compatible); - if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) - return err; - else if (err == 0) - return offset; - } - - return offset; /* error from fdt_next_node() */ -} diff --git a/scripts/dtc/libfdt/fdt_rw.c b/scripts/dtc/libfdt/fdt_rw.c deleted file mode 100644 index 90ea14e..0000000 --- a/scripts/dtc/libfdt/fdt_rw.c +++ /dev/null @@ -1,512 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -static int fdt_blocks_misordered_(const void *fdt, - int mem_rsv_size, int struct_size) -{ - return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8)) - || (fdt_off_dt_struct(fdt) < - (fdt_off_mem_rsvmap(fdt) + mem_rsv_size)) - || (fdt_off_dt_strings(fdt) < - (fdt_off_dt_struct(fdt) + struct_size)) - || (fdt_totalsize(fdt) < - (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt))); -} - -static void fdt_downgrade_version(void *fdt) -{ - if (!can_assume(LATEST) && fdt_version(fdt) > FDT_LAST_SUPPORTED_VERSION) - fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); -} - -static int fdt_rw_probe_(void *fdt) -{ - if (can_assume(VALID_DTB)) - return 0; - FDT_RO_PROBE(fdt); - - if (!can_assume(LATEST) && fdt_version(fdt) < 17) - return -FDT_ERR_BADVERSION; - if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry), - fdt_size_dt_struct(fdt))) - return -FDT_ERR_BADLAYOUT; - - fdt_downgrade_version(fdt); - return 0; -} - -#define FDT_RW_PROBE(fdt) \ - { \ - int err_; \ - if ((err_ = fdt_rw_probe_(fdt)) != 0) \ - return err_; \ - } - -static inline unsigned int fdt_data_size_(void *fdt) -{ - return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); -} - -static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen) -{ - char *p = splicepoint; - unsigned int dsize = fdt_data_size_(fdt); - size_t soff = p - (char *)fdt; - - if ((oldlen < 0) || (soff + oldlen < soff) || (soff + oldlen > dsize)) - return -FDT_ERR_BADOFFSET; - if ((p < (char *)fdt) || (dsize + newlen < (unsigned)oldlen)) - return -FDT_ERR_BADOFFSET; - if (dsize - oldlen + newlen > fdt_totalsize(fdt)) - return -FDT_ERR_NOSPACE; - memmove(p + newlen, p + oldlen, ((char *)fdt + dsize) - (p + oldlen)); - return 0; -} - -static int fdt_splice_mem_rsv_(void *fdt, struct fdt_reserve_entry *p, - int oldn, int newn) -{ - int delta = (newn - oldn) * sizeof(*p); - int err; - err = fdt_splice_(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); - if (err) - return err; - fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta); - fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); - return 0; -} - -static int fdt_splice_struct_(void *fdt, void *p, - int oldlen, int newlen) -{ - int delta = newlen - oldlen; - int err; - - if ((err = fdt_splice_(fdt, p, oldlen, newlen))) - return err; - - fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta); - fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); - return 0; -} - -/* Must only be used to roll back in case of error */ -static void fdt_del_last_string_(void *fdt, const char *s) -{ - int newlen = strlen(s) + 1; - - fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) - newlen); -} - -static int fdt_splice_string_(void *fdt, int newlen) -{ - void *p = (char *)fdt - + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); - int err; - - if ((err = fdt_splice_(fdt, p, 0, newlen))) - return err; - - fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen); - return 0; -} - -/** - * fdt_find_add_string_() - Find or allocate a string - * - * @fdt: pointer to the device tree to check/adjust - * @s: string to find/add - * @allocated: Set to 0 if the string was found, 1 if not found and so - * allocated. Ignored if can_assume(NO_ROLLBACK) - * @return offset of string in the string table (whether found or added) - */ -static int fdt_find_add_string_(void *fdt, const char *s, int slen, - int *allocated) -{ - char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); - const char *p; - char *new; - int err; - - if (!can_assume(NO_ROLLBACK)) - *allocated = 0; - - p = fdt_find_string_len_(strtab, fdt_size_dt_strings(fdt), s, slen); - if (p) - /* found it */ - return (p - strtab); - - new = strtab + fdt_size_dt_strings(fdt); - err = fdt_splice_string_(fdt, slen + 1); - if (err) - return err; - - if (!can_assume(NO_ROLLBACK)) - *allocated = 1; - - memcpy(new, s, slen); - new[slen] = '\0'; - - return (new - strtab); -} - -int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) -{ - struct fdt_reserve_entry *re; - int err; - - FDT_RW_PROBE(fdt); - - re = fdt_mem_rsv_w_(fdt, fdt_num_mem_rsv(fdt)); - err = fdt_splice_mem_rsv_(fdt, re, 0, 1); - if (err) - return err; - - re->address = cpu_to_fdt64(address); - re->size = cpu_to_fdt64(size); - return 0; -} - -int fdt_del_mem_rsv(void *fdt, int n) -{ - struct fdt_reserve_entry *re = fdt_mem_rsv_w_(fdt, n); - - FDT_RW_PROBE(fdt); - - if (n >= fdt_num_mem_rsv(fdt)) - return -FDT_ERR_NOTFOUND; - - return fdt_splice_mem_rsv_(fdt, re, 1, 0); -} - -static int fdt_resize_property_(void *fdt, int nodeoffset, - const char *name, int namelen, - int len, struct fdt_property **prop) -{ - int oldlen; - int err; - - *prop = fdt_get_property_namelen_w(fdt, nodeoffset, name, namelen, - &oldlen); - if (!*prop) - return oldlen; - - if ((err = fdt_splice_struct_(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), - FDT_TAGALIGN(len)))) - return err; - - (*prop)->len = cpu_to_fdt32(len); - return 0; -} - -static int fdt_add_property_(void *fdt, int nodeoffset, const char *name, - int namelen, int len, struct fdt_property **prop) -{ - int proplen; - int nextoffset; - int namestroff; - int err; - int allocated; - - if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) - return nextoffset; - - namestroff = fdt_find_add_string_(fdt, name, namelen, &allocated); - if (namestroff < 0) - return namestroff; - - *prop = fdt_offset_ptr_w_(fdt, nextoffset); - proplen = sizeof(**prop) + FDT_TAGALIGN(len); - - err = fdt_splice_struct_(fdt, *prop, 0, proplen); - if (err) { - /* Delete the string if we failed to add it */ - if (!can_assume(NO_ROLLBACK) && allocated) - fdt_del_last_string_(fdt, name); - return err; - } - - (*prop)->tag = cpu_to_fdt32(FDT_PROP); - (*prop)->nameoff = cpu_to_fdt32(namestroff); - (*prop)->len = cpu_to_fdt32(len); - return 0; -} - -int fdt_set_name(void *fdt, int nodeoffset, const char *name) -{ - char *namep; - int oldlen, newlen; - int err; - - FDT_RW_PROBE(fdt); - - namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen); - if (!namep) - return oldlen; - - newlen = strlen(name); - - err = fdt_splice_struct_(fdt, namep, FDT_TAGALIGN(oldlen+1), - FDT_TAGALIGN(newlen+1)); - if (err) - return err; - - memcpy(namep, name, newlen+1); - return 0; -} - -int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name, - int namelen, int len, void **prop_data) -{ - struct fdt_property *prop; - int err; - - FDT_RW_PROBE(fdt); - - err = fdt_resize_property_(fdt, nodeoffset, name, namelen, len, &prop); - if (err == -FDT_ERR_NOTFOUND) - err = fdt_add_property_(fdt, nodeoffset, name, namelen, len, - &prop); - if (err) - return err; - - *prop_data = prop->data; - return 0; -} - -int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name, - int namelen, const void *val, int len) -{ - void *prop_data; - int err; - - err = fdt_setprop_placeholder_namelen(fdt, nodeoffset, name, namelen, - len, &prop_data); - if (err) - return err; - - if (len) - memcpy(prop_data, val, len); - return 0; -} - -int fdt_appendprop(void *fdt, int nodeoffset, const char *name, - const void *val, int len) -{ - struct fdt_property *prop; - int err, oldlen, newlen; - - FDT_RW_PROBE(fdt); - - prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); - if (prop) { - newlen = len + oldlen; - err = fdt_splice_struct_(fdt, prop->data, - FDT_TAGALIGN(oldlen), - FDT_TAGALIGN(newlen)); - if (err) - return err; - prop->len = cpu_to_fdt32(newlen); - memcpy(prop->data + oldlen, val, len); - } else { - err = fdt_add_property_(fdt, nodeoffset, name, strlen(name), - len, &prop); - if (err) - return err; - memcpy(prop->data, val, len); - } - return 0; -} - -int fdt_delprop(void *fdt, int nodeoffset, const char *name) -{ - struct fdt_property *prop; - int len, proplen; - - FDT_RW_PROBE(fdt); - - prop = fdt_get_property_w(fdt, nodeoffset, name, &len); - if (!prop) - return len; - - proplen = sizeof(*prop) + FDT_TAGALIGN(len); - return fdt_splice_struct_(fdt, prop, proplen, 0); -} - -int fdt_add_subnode_namelen(void *fdt, int parentoffset, - const char *name, int namelen) -{ - struct fdt_node_header *nh; - int offset, nextoffset; - int nodelen; - int err; - uint32_t tag; - fdt32_t *endtag; - - FDT_RW_PROBE(fdt); - - offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen); - if (offset >= 0) - return -FDT_ERR_EXISTS; - else if (offset != -FDT_ERR_NOTFOUND) - return offset; - - /* Try to place the new node after the parent's properties */ - tag = fdt_next_tag(fdt, parentoffset, &nextoffset); - /* the fdt_subnode_offset_namelen() should ensure this never hits */ - if (!can_assume(LIBFDT_FLAWLESS) && (tag != FDT_BEGIN_NODE)) - return -FDT_ERR_INTERNAL; - do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - } while ((tag == FDT_PROP) || (tag == FDT_NOP)); - - nh = fdt_offset_ptr_w_(fdt, offset); - nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE; - - err = fdt_splice_struct_(fdt, nh, 0, nodelen); - if (err) - return err; - - nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); - memset(nh->name, 0, FDT_TAGALIGN(namelen+1)); - memcpy(nh->name, name, namelen); - endtag = (fdt32_t *)((char *)nh + nodelen - FDT_TAGSIZE); - *endtag = cpu_to_fdt32(FDT_END_NODE); - - return offset; -} - -int fdt_add_subnode(void *fdt, int parentoffset, const char *name) -{ - return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name)); -} - -int fdt_del_node(void *fdt, int nodeoffset) -{ - int endoffset; - - FDT_RW_PROBE(fdt); - - endoffset = fdt_node_end_offset_(fdt, nodeoffset); - if (endoffset < 0) - return endoffset; - - return fdt_splice_struct_(fdt, fdt_offset_ptr_w_(fdt, nodeoffset), - endoffset - nodeoffset, 0); -} - -static void fdt_packblocks_(const char *old, char *new, - int mem_rsv_size, - int struct_size, - int strings_size) -{ - int mem_rsv_off, struct_off, strings_off; - - mem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8); - struct_off = mem_rsv_off + mem_rsv_size; - strings_off = struct_off + struct_size; - - memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size); - fdt_set_off_mem_rsvmap(new, mem_rsv_off); - - memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size); - fdt_set_off_dt_struct(new, struct_off); - fdt_set_size_dt_struct(new, struct_size); - - memmove(new + strings_off, old + fdt_off_dt_strings(old), strings_size); - fdt_set_off_dt_strings(new, strings_off); - fdt_set_size_dt_strings(new, fdt_size_dt_strings(old)); -} - -int fdt_open_into(const void *fdt, void *buf, int bufsize) -{ - int err; - int mem_rsv_size, struct_size; - int newsize; - const char *fdtstart = fdt; - const char *fdtend = fdtstart + fdt_totalsize(fdt); - char *tmp; - - FDT_RO_PROBE(fdt); - - mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) - * sizeof(struct fdt_reserve_entry); - - if (can_assume(LATEST) || fdt_version(fdt) >= 17) { - struct_size = fdt_size_dt_struct(fdt); - } else if (fdt_version(fdt) == 16) { - struct_size = 0; - while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END) - ; - if (struct_size < 0) - return struct_size; - } else { - return -FDT_ERR_BADVERSION; - } - - if (can_assume(LIBFDT_ORDER) || - !fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) { - /* no further work necessary */ - err = fdt_move(fdt, buf, bufsize); - if (err) - return err; - fdt_set_version(buf, 17); - fdt_set_size_dt_struct(buf, struct_size); - fdt_set_totalsize(buf, bufsize); - return 0; - } - - /* Need to reorder */ - newsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size - + struct_size + fdt_size_dt_strings(fdt); - - if (bufsize < newsize) - return -FDT_ERR_NOSPACE; - - /* First attempt to build converted tree at beginning of buffer */ - tmp = buf; - /* But if that overlaps with the old tree... */ - if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) { - /* Try right after the old tree instead */ - tmp = (char *)(uintptr_t)fdtend; - if ((tmp + newsize) > ((char *)buf + bufsize)) - return -FDT_ERR_NOSPACE; - } - - fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size, - fdt_size_dt_strings(fdt)); - memmove(buf, tmp, newsize); - - fdt_set_magic(buf, FDT_MAGIC); - fdt_set_totalsize(buf, bufsize); - fdt_set_version(buf, 17); - fdt_set_last_comp_version(buf, 16); - fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt)); - - return 0; -} - -int fdt_pack(void *fdt) -{ - int mem_rsv_size; - - FDT_RW_PROBE(fdt); - - mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) - * sizeof(struct fdt_reserve_entry); - fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt), - fdt_size_dt_strings(fdt)); - fdt_set_totalsize(fdt, fdt_data_size_(fdt)); - - return 0; -} diff --git a/scripts/dtc/libfdt/fdt_strerror.c b/scripts/dtc/libfdt/fdt_strerror.c deleted file mode 100644 index d852b77..0000000 --- a/scripts/dtc/libfdt/fdt_strerror.c +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -struct fdt_errtabent { - const char *str; -}; - -#define FDT_ERRTABENT(val) \ - [(val)] = { .str = #val, } - -static struct fdt_errtabent fdt_errtable[] = { - FDT_ERRTABENT(FDT_ERR_NOTFOUND), - FDT_ERRTABENT(FDT_ERR_EXISTS), - FDT_ERRTABENT(FDT_ERR_NOSPACE), - - FDT_ERRTABENT(FDT_ERR_BADOFFSET), - FDT_ERRTABENT(FDT_ERR_BADPATH), - FDT_ERRTABENT(FDT_ERR_BADPHANDLE), - FDT_ERRTABENT(FDT_ERR_BADSTATE), - - FDT_ERRTABENT(FDT_ERR_TRUNCATED), - FDT_ERRTABENT(FDT_ERR_BADMAGIC), - FDT_ERRTABENT(FDT_ERR_BADVERSION), - FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), - FDT_ERRTABENT(FDT_ERR_BADLAYOUT), - FDT_ERRTABENT(FDT_ERR_INTERNAL), - FDT_ERRTABENT(FDT_ERR_BADNCELLS), - FDT_ERRTABENT(FDT_ERR_BADVALUE), - FDT_ERRTABENT(FDT_ERR_BADOVERLAY), - FDT_ERRTABENT(FDT_ERR_NOPHANDLES), - FDT_ERRTABENT(FDT_ERR_BADFLAGS), - FDT_ERRTABENT(FDT_ERR_ALIGNMENT), -}; -#define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))) - -const char *fdt_strerror(int errval) -{ - if (errval > 0) - return ""; - else if (errval == 0) - return ""; - else if (-errval < FDT_ERRTABSIZE) { - const char *s = fdt_errtable[-errval].str; - - if (s) - return s; - } - - return ""; -} diff --git a/scripts/dtc/libfdt/fdt_sw.c b/scripts/dtc/libfdt/fdt_sw.c deleted file mode 100644 index 4c569ee..0000000 --- a/scripts/dtc/libfdt/fdt_sw.c +++ /dev/null @@ -1,384 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -static int fdt_sw_probe_(void *fdt) -{ - if (!can_assume(VALID_INPUT)) { - if (fdt_magic(fdt) == FDT_MAGIC) - return -FDT_ERR_BADSTATE; - else if (fdt_magic(fdt) != FDT_SW_MAGIC) - return -FDT_ERR_BADMAGIC; - } - - return 0; -} - -#define FDT_SW_PROBE(fdt) \ - { \ - int err; \ - if ((err = fdt_sw_probe_(fdt)) != 0) \ - return err; \ - } - -/* 'memrsv' state: Initial state after fdt_create() - * - * Allowed functions: - * fdt_add_reservemap_entry() - * fdt_finish_reservemap() [moves to 'struct' state] - */ -static int fdt_sw_probe_memrsv_(void *fdt) -{ - int err = fdt_sw_probe_(fdt); - if (err) - return err; - - if (!can_assume(VALID_INPUT) && fdt_off_dt_strings(fdt) != 0) - return -FDT_ERR_BADSTATE; - return 0; -} - -#define FDT_SW_PROBE_MEMRSV(fdt) \ - { \ - int err; \ - if ((err = fdt_sw_probe_memrsv_(fdt)) != 0) \ - return err; \ - } - -/* 'struct' state: Enter this state after fdt_finish_reservemap() - * - * Allowed functions: - * fdt_begin_node() - * fdt_end_node() - * fdt_property*() - * fdt_finish() [moves to 'complete' state] - */ -static int fdt_sw_probe_struct_(void *fdt) -{ - int err = fdt_sw_probe_(fdt); - if (err) - return err; - - if (!can_assume(VALID_INPUT) && - fdt_off_dt_strings(fdt) != fdt_totalsize(fdt)) - return -FDT_ERR_BADSTATE; - return 0; -} - -#define FDT_SW_PROBE_STRUCT(fdt) \ - { \ - int err; \ - if ((err = fdt_sw_probe_struct_(fdt)) != 0) \ - return err; \ - } - -static inline uint32_t sw_flags(void *fdt) -{ - /* assert: (fdt_magic(fdt) == FDT_SW_MAGIC) */ - return fdt_last_comp_version(fdt); -} - -/* 'complete' state: Enter this state after fdt_finish() - * - * Allowed functions: none - */ - -static void *fdt_grab_space_(void *fdt, size_t len) -{ - unsigned int offset = fdt_size_dt_struct(fdt); - unsigned int spaceleft; - - spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt) - - fdt_size_dt_strings(fdt); - - if ((offset + len < offset) || (offset + len > spaceleft)) - return NULL; - - fdt_set_size_dt_struct(fdt, offset + len); - return fdt_offset_ptr_w_(fdt, offset); -} - -int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags) -{ - const int hdrsize = FDT_ALIGN(sizeof(struct fdt_header), - sizeof(struct fdt_reserve_entry)); - void *fdt = buf; - - if (bufsize < hdrsize) - return -FDT_ERR_NOSPACE; - - if (flags & ~FDT_CREATE_FLAGS_ALL) - return -FDT_ERR_BADFLAGS; - - memset(buf, 0, bufsize); - - /* - * magic and last_comp_version keep intermediate state during the fdt - * creation process, which is replaced with the proper FDT format by - * fdt_finish(). - * - * flags should be accessed with sw_flags(). - */ - fdt_set_magic(fdt, FDT_SW_MAGIC); - fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); - fdt_set_last_comp_version(fdt, flags); - - fdt_set_totalsize(fdt, bufsize); - - fdt_set_off_mem_rsvmap(fdt, hdrsize); - fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt)); - fdt_set_off_dt_strings(fdt, 0); - - return 0; -} - -int fdt_create(void *buf, int bufsize) -{ - return fdt_create_with_flags(buf, bufsize, 0); -} - -int fdt_resize(void *fdt, void *buf, int bufsize) -{ - size_t headsize, tailsize; - char *oldtail, *newtail; - - FDT_SW_PROBE(fdt); - - if (bufsize < 0) - return -FDT_ERR_NOSPACE; - - headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); - tailsize = fdt_size_dt_strings(fdt); - - if (!can_assume(VALID_DTB) && - headsize + tailsize > fdt_totalsize(fdt)) - return -FDT_ERR_INTERNAL; - - if ((headsize + tailsize) > (unsigned)bufsize) - return -FDT_ERR_NOSPACE; - - oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize; - newtail = (char *)buf + bufsize - tailsize; - - /* Two cases to avoid clobbering data if the old and new - * buffers partially overlap */ - if (buf <= fdt) { - memmove(buf, fdt, headsize); - memmove(newtail, oldtail, tailsize); - } else { - memmove(newtail, oldtail, tailsize); - memmove(buf, fdt, headsize); - } - - fdt_set_totalsize(buf, bufsize); - if (fdt_off_dt_strings(buf)) - fdt_set_off_dt_strings(buf, bufsize); - - return 0; -} - -int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) -{ - struct fdt_reserve_entry *re; - int offset; - - FDT_SW_PROBE_MEMRSV(fdt); - - offset = fdt_off_dt_struct(fdt); - if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) - return -FDT_ERR_NOSPACE; - - re = (struct fdt_reserve_entry *)((char *)fdt + offset); - re->address = cpu_to_fdt64(addr); - re->size = cpu_to_fdt64(size); - - fdt_set_off_dt_struct(fdt, offset + sizeof(*re)); - - return 0; -} - -int fdt_finish_reservemap(void *fdt) -{ - int err = fdt_add_reservemap_entry(fdt, 0, 0); - - if (err) - return err; - - fdt_set_off_dt_strings(fdt, fdt_totalsize(fdt)); - return 0; -} - -int fdt_begin_node(void *fdt, const char *name) -{ - struct fdt_node_header *nh; - int namelen; - - FDT_SW_PROBE_STRUCT(fdt); - - namelen = strlen(name) + 1; - nh = fdt_grab_space_(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); - if (! nh) - return -FDT_ERR_NOSPACE; - - nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); - memcpy(nh->name, name, namelen); - return 0; -} - -int fdt_end_node(void *fdt) -{ - fdt32_t *en; - - FDT_SW_PROBE_STRUCT(fdt); - - en = fdt_grab_space_(fdt, FDT_TAGSIZE); - if (! en) - return -FDT_ERR_NOSPACE; - - *en = cpu_to_fdt32(FDT_END_NODE); - return 0; -} - -static int fdt_add_string_(void *fdt, const char *s) -{ - char *strtab = (char *)fdt + fdt_totalsize(fdt); - unsigned int strtabsize = fdt_size_dt_strings(fdt); - unsigned int len = strlen(s) + 1; - unsigned int struct_top, offset; - - offset = strtabsize + len; - struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); - if (fdt_totalsize(fdt) - offset < struct_top) - return 0; /* no more room :( */ - - memcpy(strtab - offset, s, len); - fdt_set_size_dt_strings(fdt, strtabsize + len); - return -offset; -} - -/* Must only be used to roll back in case of error */ -static void fdt_del_last_string_(void *fdt, const char *s) -{ - int strtabsize = fdt_size_dt_strings(fdt); - int len = strlen(s) + 1; - - fdt_set_size_dt_strings(fdt, strtabsize - len); -} - -static int fdt_find_add_string_(void *fdt, const char *s, int *allocated) -{ - char *strtab = (char *)fdt + fdt_totalsize(fdt); - int strtabsize = fdt_size_dt_strings(fdt); - const char *p; - - *allocated = 0; - - p = fdt_find_string_(strtab - strtabsize, strtabsize, s); - if (p) - return p - strtab; - - *allocated = 1; - - return fdt_add_string_(fdt, s); -} - -int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp) -{ - struct fdt_property *prop; - int nameoff; - int allocated; - - FDT_SW_PROBE_STRUCT(fdt); - - /* String de-duplication can be slow, _NO_NAME_DEDUP skips it */ - if (sw_flags(fdt) & FDT_CREATE_FLAG_NO_NAME_DEDUP) { - allocated = 1; - nameoff = fdt_add_string_(fdt, name); - } else { - nameoff = fdt_find_add_string_(fdt, name, &allocated); - } - if (nameoff == 0) - return -FDT_ERR_NOSPACE; - - prop = fdt_grab_space_(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); - if (! prop) { - if (allocated) - fdt_del_last_string_(fdt, name); - return -FDT_ERR_NOSPACE; - } - - prop->tag = cpu_to_fdt32(FDT_PROP); - prop->nameoff = cpu_to_fdt32(nameoff); - prop->len = cpu_to_fdt32(len); - *valp = prop->data; - return 0; -} - -int fdt_property(void *fdt, const char *name, const void *val, int len) -{ - void *ptr; - int ret; - - ret = fdt_property_placeholder(fdt, name, len, &ptr); - if (ret) - return ret; - memcpy(ptr, val, len); - return 0; -} - -int fdt_finish(void *fdt) -{ - char *p = (char *)fdt; - fdt32_t *end; - int oldstroffset, newstroffset; - uint32_t tag; - int offset, nextoffset; - - FDT_SW_PROBE_STRUCT(fdt); - - /* Add terminator */ - end = fdt_grab_space_(fdt, sizeof(*end)); - if (! end) - return -FDT_ERR_NOSPACE; - *end = cpu_to_fdt32(FDT_END); - - /* Relocate the string table */ - oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt); - newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); - memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt)); - fdt_set_off_dt_strings(fdt, newstroffset); - - /* Walk the structure, correcting string offsets */ - offset = 0; - while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) { - if (tag == FDT_PROP) { - struct fdt_property *prop = - fdt_offset_ptr_w_(fdt, offset); - int nameoff; - - nameoff = fdt32_to_cpu(prop->nameoff); - nameoff += fdt_size_dt_strings(fdt); - prop->nameoff = cpu_to_fdt32(nameoff); - } - offset = nextoffset; - } - if (nextoffset < 0) - return nextoffset; - - /* Finally, adjust the header */ - fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt)); - - /* And fix up fields that were keeping intermediate state. */ - fdt_set_last_comp_version(fdt, FDT_LAST_COMPATIBLE_VERSION); - fdt_set_magic(fdt, FDT_MAGIC); - - return 0; -} diff --git a/scripts/dtc/libfdt/fdt_wip.c b/scripts/dtc/libfdt/fdt_wip.c deleted file mode 100644 index c2d7566..0000000 --- a/scripts/dtc/libfdt/fdt_wip.c +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, - const char *name, int namelen, - uint32_t idx, const void *val, - int len) -{ - void *propval; - int proplen; - - propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen, - &proplen); - if (!propval) - return proplen; - - if ((unsigned)proplen < (len + idx)) - return -FDT_ERR_NOSPACE; - - memcpy((char *)propval + idx, val, len); - return 0; -} - -int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, - const void *val, int len) -{ - const void *propval; - int proplen; - - propval = fdt_getprop(fdt, nodeoffset, name, &proplen); - if (!propval) - return proplen; - - if (proplen != len) - return -FDT_ERR_NOSPACE; - - return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name, - strlen(name), 0, - val, len); -} - -static void fdt_nop_region_(void *start, int len) -{ - fdt32_t *p; - - for (p = start; (char *)p < ((char *)start + len); p++) - *p = cpu_to_fdt32(FDT_NOP); -} - -int fdt_nop_property(void *fdt, int nodeoffset, const char *name) -{ - struct fdt_property *prop; - int len; - - prop = fdt_get_property_w(fdt, nodeoffset, name, &len); - if (!prop) - return len; - - fdt_nop_region_(prop, len + sizeof(*prop)); - - return 0; -} - -int fdt_node_end_offset_(void *fdt, int offset) -{ - int depth = 0; - - while ((offset >= 0) && (depth >= 0)) - offset = fdt_next_node(fdt, offset, &depth); - - return offset; -} - -int fdt_nop_node(void *fdt, int nodeoffset) -{ - int endoffset; - - endoffset = fdt_node_end_offset_(fdt, nodeoffset); - if (endoffset < 0) - return endoffset; - - fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0), - endoffset - nodeoffset); - return 0; -} diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h deleted file mode 100644 index 81aaf7c..0000000 --- a/scripts/dtc/libfdt/libfdt.h +++ /dev/null @@ -1,2540 +0,0 @@ -/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ -#ifndef LIBFDT_H -#define LIBFDT_H -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - */ - -#include "libfdt_env.h" -#include "fdt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FDT_FIRST_SUPPORTED_VERSION 0x02 -#define FDT_LAST_COMPATIBLE_VERSION 0x10 -#define FDT_LAST_SUPPORTED_VERSION 0x11 - -/* Error codes: informative error codes */ -#define FDT_ERR_NOTFOUND 1 - /* FDT_ERR_NOTFOUND: The requested node or property does not exist */ -#define FDT_ERR_EXISTS 2 - /* FDT_ERR_EXISTS: Attempted to create a node or property which - * already exists */ -#define FDT_ERR_NOSPACE 3 - /* FDT_ERR_NOSPACE: Operation needed to expand the device - * tree, but its buffer did not have sufficient space to - * contain the expanded tree. Use fdt_open_into() to move the - * device tree to a buffer with more space. */ - -/* Error codes: codes for bad parameters */ -#define FDT_ERR_BADOFFSET 4 - /* FDT_ERR_BADOFFSET: Function was passed a structure block - * offset which is out-of-bounds, or which points to an - * unsuitable part of the structure for the operation. */ -#define FDT_ERR_BADPATH 5 - /* FDT_ERR_BADPATH: Function was passed a badly formatted path - * (e.g. missing a leading / for a function which requires an - * absolute path) */ -#define FDT_ERR_BADPHANDLE 6 - /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle. - * This can be caused either by an invalid phandle property - * length, or the phandle value was either 0 or -1, which are - * not permitted. */ -#define FDT_ERR_BADSTATE 7 - /* FDT_ERR_BADSTATE: Function was passed an incomplete device - * tree created by the sequential-write functions, which is - * not sufficiently complete for the requested operation. */ - -/* Error codes: codes for bad device tree blobs */ -#define FDT_ERR_TRUNCATED 8 - /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly - * terminated (overflows, goes outside allowed bounds, or - * isn't properly terminated). */ -#define FDT_ERR_BADMAGIC 9 - /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a - * device tree at all - it is missing the flattened device - * tree magic number. */ -#define FDT_ERR_BADVERSION 10 - /* FDT_ERR_BADVERSION: Given device tree has a version which - * can't be handled by the requested operation. For - * read-write functions, this may mean that fdt_open_into() is - * required to convert the tree to the expected version. */ -#define FDT_ERR_BADSTRUCTURE 11 - /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt - * structure block or other serious error (e.g. misnested - * nodes, or subnodes preceding properties). */ -#define FDT_ERR_BADLAYOUT 12 - /* FDT_ERR_BADLAYOUT: For read-write functions, the given - * device tree has it's sub-blocks in an order that the - * function can't handle (memory reserve map, then structure, - * then strings). Use fdt_open_into() to reorganize the tree - * into a form suitable for the read-write operations. */ - -/* "Can't happen" error indicating a bug in libfdt */ -#define FDT_ERR_INTERNAL 13 - /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion. - * Should never be returned, if it is, it indicates a bug in - * libfdt itself. */ - -/* Errors in device tree content */ -#define FDT_ERR_BADNCELLS 14 - /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells - * or similar property with a bad format or value */ - -#define FDT_ERR_BADVALUE 15 - /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected - * value. For example: a property expected to contain a string list - * is not NUL-terminated within the length of its value. */ - -#define FDT_ERR_BADOVERLAY 16 - /* FDT_ERR_BADOVERLAY: The device tree overlay, while - * correctly structured, cannot be applied due to some - * unexpected or missing value, property or node. */ - -#define FDT_ERR_NOPHANDLES 17 - /* FDT_ERR_NOPHANDLES: The device tree doesn't have any - * phandle available anymore without causing an overflow */ - -#define FDT_ERR_BADFLAGS 18 - /* FDT_ERR_BADFLAGS: The function was passed a flags field that - * contains invalid flags or an invalid combination of flags. */ - -#define FDT_ERR_ALIGNMENT 19 - /* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte - * aligned. */ - -#define FDT_ERR_MAX 19 - -/* constants */ -#define FDT_MAX_PHANDLE 0xfffffffe - /* Valid values for phandles range from 1 to 2^32-2. */ - -/**********************************************************************/ -/* Low-level functions (you probably don't need these) */ -/**********************************************************************/ - -/** - * fdt_offset_ptr - safely get a byte range within the device tree blob - * @fdt: Pointer to the device tree blob - * @offset: Offset within the blob to the desired byte range - * @checklen: Required length of the byte range - * - * fdt_offset_ptr() returns a pointer to the byte range of length @checklen at - * the given @offset within the device tree blob, after verifying that the byte - * range fits entirely within the blob and does not overflow. - * - * returns: - * pointer to the byte range, on success - * NULL, if the requested range does not fit within the blob - */ -#ifndef SWIG /* This function is not useful in Python */ -const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); -#endif -static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) -{ - return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); -} - -/** - * fdt_next_tag - get next tag in the device tree - * @fdt: Pointer to the device tree blob - * @offset: Offset within the blob to start searching - * @nextoffset: Pointer to variable to store the offset of the next tag - * - * fdt_next_tag() returns the tag type of the next tag in the device tree - * blob starting from the given @offset. If @nextoffset is non-NULL, it will - * be set to the offset immediately following the tag. - * - * returns: - * the tag type (FDT_BEGIN_NODE, FDT_END_NODE, FDT_PROP, FDT_NOP, FDT_END), - * FDT_END, if offset is out of bounds - */ -uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); - -/* - * External helpers to access words from a device tree blob. They're built - * to work even with unaligned pointers on platforms (such as ARMv5) that don't - * like unaligned loads and stores. - */ -static inline uint16_t fdt16_ld(const fdt16_t *p) -{ - const uint8_t *bp = (const uint8_t *)p; - - return ((uint16_t)bp[0] << 8) | bp[1]; -} - -static inline uint32_t fdt32_ld(const fdt32_t *p) -{ - const uint8_t *bp = (const uint8_t *)p; - - return ((uint32_t)bp[0] << 24) - | ((uint32_t)bp[1] << 16) - | ((uint32_t)bp[2] << 8) - | bp[3]; -} - -static inline void fdt32_st(void *property, uint32_t value) -{ - uint8_t *bp = (uint8_t *)property; - - bp[0] = value >> 24; - bp[1] = (value >> 16) & 0xff; - bp[2] = (value >> 8) & 0xff; - bp[3] = value & 0xff; -} - -static inline uint64_t fdt64_ld(const fdt64_t *p) -{ - const uint8_t *bp = (const uint8_t *)p; - - return ((uint64_t)bp[0] << 56) - | ((uint64_t)bp[1] << 48) - | ((uint64_t)bp[2] << 40) - | ((uint64_t)bp[3] << 32) - | ((uint64_t)bp[4] << 24) - | ((uint64_t)bp[5] << 16) - | ((uint64_t)bp[6] << 8) - | bp[7]; -} - -static inline void fdt64_st(void *property, uint64_t value) -{ - uint8_t *bp = (uint8_t *)property; - - bp[0] = value >> 56; - bp[1] = (value >> 48) & 0xff; - bp[2] = (value >> 40) & 0xff; - bp[3] = (value >> 32) & 0xff; - bp[4] = (value >> 24) & 0xff; - bp[5] = (value >> 16) & 0xff; - bp[6] = (value >> 8) & 0xff; - bp[7] = value & 0xff; -} - -/**********************************************************************/ -/* Traversal functions */ -/**********************************************************************/ - -int fdt_next_node(const void *fdt, int offset, int *depth); - -/** - * fdt_first_subnode() - get offset of first direct subnode - * @fdt: FDT blob - * @offset: Offset of node to check - * - * Return: offset of first subnode, or -FDT_ERR_NOTFOUND if there is none - */ -int fdt_first_subnode(const void *fdt, int offset); - -/** - * fdt_next_subnode() - get offset of next direct subnode - * @fdt: FDT blob - * @offset: Offset of previous subnode - * - * After first calling fdt_first_subnode(), call this function repeatedly to - * get direct subnodes of a parent node. - * - * Return: offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more - * subnodes - */ -int fdt_next_subnode(const void *fdt, int offset); - -/** - * fdt_for_each_subnode - iterate over all subnodes of a parent - * - * @node: child node (int, lvalue) - * @fdt: FDT blob (const void *) - * @parent: parent node (int) - * - * This is actually a wrapper around a for loop and would be used like so: - * - * fdt_for_each_subnode(node, fdt, parent) { - * Use node - * ... - * } - * - * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) { - * Error handling - * } - * - * Note that this is implemented as a macro and @node is used as - * iterator in the loop. The parent variable be constant or even a - * literal. - */ -#define fdt_for_each_subnode(node, fdt, parent) \ - for (node = fdt_first_subnode(fdt, parent); \ - node >= 0; \ - node = fdt_next_subnode(fdt, node)) - -/**********************************************************************/ -/* General functions */ -/**********************************************************************/ -#define fdt_get_header(fdt, field) \ - (fdt32_ld(&((const struct fdt_header *)(fdt))->field)) -#define fdt_magic(fdt) (fdt_get_header(fdt, magic)) -#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) -#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) -#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) -#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) -#define fdt_version(fdt) (fdt_get_header(fdt, version)) -#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) -#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) -#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) -#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) - -#define fdt_set_hdr_(name) \ - static inline void fdt_set_##name(void *fdt, uint32_t val) \ - { \ - struct fdt_header *fdth = (struct fdt_header *)fdt; \ - fdth->name = cpu_to_fdt32(val); \ - } -fdt_set_hdr_(magic) -fdt_set_hdr_(totalsize) -fdt_set_hdr_(off_dt_struct) -fdt_set_hdr_(off_dt_strings) -fdt_set_hdr_(off_mem_rsvmap) -fdt_set_hdr_(version) -fdt_set_hdr_(last_comp_version) -fdt_set_hdr_(boot_cpuid_phys) -fdt_set_hdr_(size_dt_strings) -fdt_set_hdr_(size_dt_struct) -#undef fdt_set_hdr_ - -/** - * fdt_header_size - return the size of the tree's header - * @fdt: pointer to a flattened device tree - * - * Return: size of DTB header in bytes - */ -size_t fdt_header_size(const void *fdt); - -/** - * fdt_header_size_ - internal function to get header size from a version number - * @version: device tree version number - * - * Return: size of DTB header in bytes - */ -size_t fdt_header_size_(uint32_t version); - -/** - * fdt_check_header - sanity check a device tree header - * @fdt: pointer to data which might be a flattened device tree - * - * fdt_check_header() checks that the given buffer contains what - * appears to be a flattened device tree, and that the header contains - * valid information (to the extent that can be determined from the - * header alone). - * - * returns: - * 0, if the buffer appears to contain a valid device tree - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_TRUNCATED, standard meanings, as above - */ -int fdt_check_header(const void *fdt); - -/** - * fdt_move - move a device tree around in memory - * @fdt: pointer to the device tree to move - * @buf: pointer to memory where the device is to be moved - * @bufsize: size of the memory space at buf - * - * fdt_move() relocates, if possible, the device tree blob located at - * fdt to the buffer at buf of size bufsize. The buffer may overlap - * with the existing device tree blob at fdt. Therefore, - * fdt_move(fdt, fdt, fdt_totalsize(fdt)) - * should always succeed. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, standard meanings - */ -int fdt_move(const void *fdt, void *buf, int bufsize); - -/**********************************************************************/ -/* Read-only functions */ -/**********************************************************************/ - -/** - * fdt_check_full - check device tree validity - * @fdt: pointer to the device tree blob - * @bufsize: size of the buffer containing the device tree - * - * fdt_check_full() checks that the given buffer contains a valid - * flattened device tree and that the tree structure is internally - * consistent. This is a more thorough check than fdt_check_header(). - * - * returns: - * 0, on success - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_check_full(const void *fdt, size_t bufsize); - -/** - * fdt_get_string - retrieve a string from the strings block of a device tree - * @fdt: pointer to the device tree blob - * @stroffset: offset of the string within the strings block (native endian) - * @lenp: optional pointer to return the string's length - * - * fdt_get_string() retrieves a pointer to a single string from the - * strings block of the device tree blob at fdt, and optionally also - * returns the string's length in *lenp. - * - * returns: - * a pointer to the string, on success - * NULL, if stroffset is out of bounds, or doesn't point to a valid string - */ -const char *fdt_get_string(const void *fdt, int stroffset, int *lenp); - -/** - * fdt_string - retrieve a string from the strings block of a device tree - * @fdt: pointer to the device tree blob - * @stroffset: offset of the string within the strings block (native endian) - * - * fdt_string() retrieves a pointer to a single string from the - * strings block of the device tree blob at fdt. - * - * returns: - * a pointer to the string, on success - * NULL, if stroffset is out of bounds, or doesn't point to a valid string - */ -const char *fdt_string(const void *fdt, int stroffset); - -/** - * fdt_find_max_phandle - find and return the highest phandle in a tree - * @fdt: pointer to the device tree blob - * @phandle: return location for the highest phandle value found in the tree - * - * fdt_find_max_phandle() finds the highest phandle value in the given device - * tree. The value returned in @phandle is only valid if the function returns - * success. - * - * returns: - * 0 on success or a negative error code on failure - */ -int fdt_find_max_phandle(const void *fdt, uint32_t *phandle); - -/** - * fdt_get_max_phandle - retrieves the highest phandle in a tree - * @fdt: pointer to the device tree blob - * - * fdt_get_max_phandle retrieves the highest phandle in the given - * device tree. This will ignore badly formatted phandles, or phandles - * with a value of 0 or -1. - * - * This function is deprecated in favour of fdt_find_max_phandle(). - * - * returns: - * the highest phandle on success - * 0, if no phandle was found in the device tree - * -1, if an error occurred - */ -static inline uint32_t fdt_get_max_phandle(const void *fdt) -{ - uint32_t phandle; - int err; - - err = fdt_find_max_phandle(fdt, &phandle); - if (err < 0) - return (uint32_t)-1; - - return phandle; -} - -/** - * fdt_generate_phandle - return a new, unused phandle for a device tree blob - * @fdt: pointer to the device tree blob - * @phandle: return location for the new phandle - * - * Walks the device tree blob and looks for the highest phandle value. On - * success, the new, unused phandle value (one higher than the previously - * highest phandle value in the device tree blob) will be returned in the - * @phandle parameter. - * - * Return: 0 on success or a negative error-code on failure - */ -int fdt_generate_phandle(const void *fdt, uint32_t *phandle); - -/** - * fdt_num_mem_rsv - retrieve the number of memory reserve map entries - * @fdt: pointer to the device tree blob - * - * Returns the number of entries in the device tree blob's memory - * reservation map. This does not include the terminating 0,0 entry - * or any other (0,0) entries reserved for expansion. - * - * returns: - * the number of entries - */ -int fdt_num_mem_rsv(const void *fdt); - -/** - * fdt_get_mem_rsv - retrieve one memory reserve map entry - * @fdt: pointer to the device tree blob - * @n: index of reserve map entry - * @address: pointer to 64-bit variable to hold the start address - * @size: pointer to 64-bit variable to hold the size of the entry - * - * On success, @address and @size will contain the address and size of - * the n-th reserve map entry from the device tree blob, in - * native-endian format. - * - * returns: - * 0, on success - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, standard meanings - */ -int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size); - -/** - * fdt_subnode_offset_namelen - find a subnode based on substring - * @fdt: pointer to the device tree blob - * @parentoffset: structure block offset of a node - * @name: name of the subnode to locate - * @namelen: number of characters of name to consider - * - * Identical to fdt_subnode_offset(), but only examine the first - * namelen characters of name for matching the subnode name. This is - * useful for finding subnodes based on a portion of a larger string, - * such as a full path. - * - * Return: offset of the subnode or -FDT_ERR_NOTFOUND if name not found. - */ -#ifndef SWIG /* Not available in Python */ -int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, - const char *name, int namelen); -#endif -/** - * fdt_subnode_offset - find a subnode of a given node - * @fdt: pointer to the device tree blob - * @parentoffset: structure block offset of a node - * @name: name of the subnode to locate - * - * fdt_subnode_offset() finds a subnode of the node at structure block - * offset parentoffset with the given name. name may include a unit - * address, in which case fdt_subnode_offset() will find the subnode - * with that unit address, or the unit address may be omitted, in - * which case fdt_subnode_offset() will find an arbitrary subnode - * whose name excluding unit address matches the given name. - * - * returns: - * structure block offset of the requested subnode (>=0), on success - * -FDT_ERR_NOTFOUND, if the requested subnode does not exist - * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE - * tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings. - */ -int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); - -/** - * fdt_path_offset_namelen - find a tree node by its full path - * @fdt: pointer to the device tree blob - * @path: full path of the node to locate - * @namelen: number of characters of path to consider - * - * Identical to fdt_path_offset(), but only consider the first namelen - * characters of path as the path name. - * - * Return: offset of the node or negative libfdt error value otherwise - */ -#ifndef SWIG /* Not available in Python */ -int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen); -#endif - -/** - * fdt_path_offset - find a tree node by its full path - * @fdt: pointer to the device tree blob - * @path: full path of the node to locate - * - * fdt_path_offset() finds a node of a given path in the device tree. - * Each path component may omit the unit address portion, but the - * results of this are undefined if any such path component is - * ambiguous (that is if there are multiple nodes at the relevant - * level matching the given component, differentiated only by unit - * address). - * - * If the path is not absolute (i.e. does not begin with '/'), the - * first component is treated as an alias. That is, the property by - * that name is looked up in the /aliases node, and the value of that - * property used in place of that first component. - * - * For example, for this small fragment - * - * / { - * aliases { - * i2c2 = &foo; // RHS compiles to "/soc@0/i2c@30a40000/eeprom@52" - * }; - * soc@0 { - * foo: i2c@30a40000 { - * bar: eeprom@52 { - * }; - * }; - * }; - * }; - * - * these would be equivalent: - * - * /soc@0/i2c@30a40000/eeprom@52 - * i2c2/eeprom@52 - * - * returns: - * structure block offset of the node with the requested path (>=0), on - * success - * -FDT_ERR_BADPATH, given path does not begin with '/' and the first - * component is not a valid alias - * -FDT_ERR_NOTFOUND, if the requested node does not exist - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings. - */ -int fdt_path_offset(const void *fdt, const char *path); - -/** - * fdt_get_name - retrieve the name of a given node - * @fdt: pointer to the device tree blob - * @nodeoffset: structure block offset of the starting node - * @lenp: pointer to an integer variable (will be overwritten) or NULL - * - * fdt_get_name() retrieves the name (including unit address) of the - * device tree node at structure block offset nodeoffset. If lenp is - * non-NULL, the length of this name is also returned, in the integer - * pointed to by lenp. - * - * returns: - * pointer to the node's name, on success - * If lenp is non-NULL, *lenp contains the length of that name - * (>=0) - * NULL, on error - * if lenp is non-NULL *lenp contains an error code (<0): - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE - * tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, standard meanings - */ -const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp); - -/** - * fdt_first_property_offset - find the offset of a node's first property - * @fdt: pointer to the device tree blob - * @nodeoffset: structure block offset of a node - * - * fdt_first_property_offset() finds the first property of the node at - * the given structure block offset. - * - * returns: - * structure block offset of the property (>=0), on success - * -FDT_ERR_NOTFOUND, if the requested node has no properties - * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings. - */ -int fdt_first_property_offset(const void *fdt, int nodeoffset); - -/** - * fdt_next_property_offset - step through a node's properties - * @fdt: pointer to the device tree blob - * @offset: structure block offset of a property - * - * fdt_next_property_offset() finds the property immediately after the - * one at the given structure block offset. This will be a property - * of the same node as the given property. - * - * returns: - * structure block offset of the next property (>=0), on success - * -FDT_ERR_NOTFOUND, if the given property is the last in its node - * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings. - */ -int fdt_next_property_offset(const void *fdt, int offset); - -/** - * fdt_for_each_property_offset - iterate over all properties of a node - * - * @property: property offset (int, lvalue) - * @fdt: FDT blob (const void *) - * @node: node offset (int) - * - * This is actually a wrapper around a for loop and would be used like so: - * - * fdt_for_each_property_offset(property, fdt, node) { - * Use property - * ... - * } - * - * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) { - * Error handling - * } - * - * Note that this is implemented as a macro and property is used as - * iterator in the loop. The node variable can be constant or even a - * literal. - */ -#define fdt_for_each_property_offset(property, fdt, node) \ - for (property = fdt_first_property_offset(fdt, node); \ - property >= 0; \ - property = fdt_next_property_offset(fdt, property)) - -/** - * fdt_get_property_by_offset - retrieve the property at a given offset - * @fdt: pointer to the device tree blob - * @offset: offset of the property to retrieve - * @lenp: pointer to an integer variable (will be overwritten) or NULL - * - * fdt_get_property_by_offset() retrieves a pointer to the - * fdt_property structure within the device tree blob at the given - * offset. If lenp is non-NULL, the length of the property value is - * also returned, in the integer pointed to by lenp. - * - * Note that this code only works on device tree versions >= 16. fdt_getprop() - * works on all versions. - * - * returns: - * pointer to the structure representing the property - * if lenp is non-NULL, *lenp contains the length of the property - * value (>=0) - * NULL, on error - * if lenp is non-NULL, *lenp contains an error code (<0): - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -const struct fdt_property *fdt_get_property_by_offset(const void *fdt, - int offset, - int *lenp); -static inline struct fdt_property *fdt_get_property_by_offset_w(void *fdt, - int offset, - int *lenp) -{ - return (struct fdt_property *)(uintptr_t) - fdt_get_property_by_offset(fdt, offset, lenp); -} - -/** - * fdt_get_property_namelen - find a property based on substring - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to find - * @name: name of the property to find - * @namelen: number of characters of name to consider - * @lenp: pointer to an integer variable (will be overwritten) or NULL - * - * Identical to fdt_get_property(), but only examine the first namelen - * characters of name for matching the property name. - * - * Return: pointer to the structure representing the property, or NULL - * if not found - */ -#ifndef SWIG /* Not available in Python */ -const struct fdt_property *fdt_get_property_namelen(const void *fdt, - int nodeoffset, - const char *name, - int namelen, int *lenp); -static inline struct fdt_property * -fdt_get_property_namelen_w(void *fdt, int nodeoffset, const char *name, - int namelen, int *lenp) -{ - return (struct fdt_property *)(uintptr_t)fdt_get_property_namelen( - fdt, nodeoffset, name, namelen, lenp); -} -#endif - -/** - * fdt_get_property - find a given property in a given node - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to find - * @name: name of the property to find - * @lenp: pointer to an integer variable (will be overwritten) or NULL - * - * fdt_get_property() retrieves a pointer to the fdt_property - * structure within the device tree blob corresponding to the property - * named 'name' of the node at offset nodeoffset. If lenp is - * non-NULL, the length of the property value is also returned, in the - * integer pointed to by lenp. - * - * returns: - * pointer to the structure representing the property - * if lenp is non-NULL, *lenp contains the length of the property - * value (>=0) - * NULL, on error - * if lenp is non-NULL, *lenp contains an error code (<0): - * -FDT_ERR_NOTFOUND, node does not have named property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE - * tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, - const char *name, int *lenp); -static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset, - const char *name, - int *lenp) -{ - return (struct fdt_property *)(uintptr_t) - fdt_get_property(fdt, nodeoffset, name, lenp); -} - -/** - * fdt_getprop_by_offset - retrieve the value of a property at a given offset - * @fdt: pointer to the device tree blob - * @offset: offset of the property to read - * @namep: pointer to a string variable (will be overwritten) or NULL - * @lenp: pointer to an integer variable (will be overwritten) or NULL - * - * fdt_getprop_by_offset() retrieves a pointer to the value of the - * property at structure block offset 'offset' (this will be a pointer - * to within the device blob itself, not a copy of the value). If - * lenp is non-NULL, the length of the property value is also - * returned, in the integer pointed to by lenp. If namep is non-NULL, - * the property's name will also be returned in the char * pointed to - * by namep (this will be a pointer to within the device tree's string - * block, not a new copy of the name). - * - * returns: - * pointer to the property's value - * if lenp is non-NULL, *lenp contains the length of the property - * value (>=0) - * if namep is non-NULL *namep contains a pointer to the property - * name. - * NULL, on error - * if lenp is non-NULL, *lenp contains an error code (<0): - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -#ifndef SWIG /* This function is not useful in Python */ -const void *fdt_getprop_by_offset(const void *fdt, int offset, - const char **namep, int *lenp); -#endif - -/** - * fdt_getprop_namelen - get property value based on substring - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to find - * @name: name of the property to find - * @namelen: number of characters of name to consider - * @lenp: pointer to an integer variable (will be overwritten) or NULL - * - * Identical to fdt_getprop(), but only examine the first namelen - * characters of name for matching the property name. - * - * Return: pointer to the property's value or NULL on error - */ -#ifndef SWIG /* Not available in Python */ -const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, - const char *name, int namelen, int *lenp); -static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset, - const char *name, int namelen, - int *lenp) -{ - return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name, - namelen, lenp); -} -#endif - -/** - * fdt_getprop - retrieve the value of a given property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to find - * @name: name of the property to find - * @lenp: pointer to an integer variable (will be overwritten) or NULL - * - * fdt_getprop() retrieves a pointer to the value of the property - * named @name of the node at offset @nodeoffset (this will be a - * pointer to within the device blob itself, not a copy of the value). - * If @lenp is non-NULL, the length of the property value is also - * returned, in the integer pointed to by @lenp. - * - * returns: - * pointer to the property's value - * if lenp is non-NULL, *lenp contains the length of the property - * value (>=0) - * NULL, on error - * if lenp is non-NULL, *lenp contains an error code (<0): - * -FDT_ERR_NOTFOUND, node does not have named property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE - * tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -const void *fdt_getprop(const void *fdt, int nodeoffset, - const char *name, int *lenp); -static inline void *fdt_getprop_w(void *fdt, int nodeoffset, - const char *name, int *lenp) -{ - return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp); -} - -/** - * fdt_get_phandle - retrieve the phandle of a given node - * @fdt: pointer to the device tree blob - * @nodeoffset: structure block offset of the node - * - * fdt_get_phandle() retrieves the phandle of the device tree node at - * structure block offset nodeoffset. - * - * returns: - * the phandle of the node at nodeoffset, on success (!= 0, != -1) - * 0, if the node has no phandle, or another error occurs - */ -uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); - -/** - * fdt_get_alias_namelen - get alias based on substring - * @fdt: pointer to the device tree blob - * @name: name of the alias to look up - * @namelen: number of characters of name to consider - * - * Identical to fdt_get_alias(), but only examine the first @namelen - * characters of @name for matching the alias name. - * - * Return: a pointer to the expansion of the alias named @name, if it exists, - * NULL otherwise - */ -#ifndef SWIG /* Not available in Python */ -const char *fdt_get_alias_namelen(const void *fdt, - const char *name, int namelen); -#endif - -/** - * fdt_get_alias - retrieve the path referenced by a given alias - * @fdt: pointer to the device tree blob - * @name: name of the alias to look up - * - * fdt_get_alias() retrieves the value of a given alias. That is, the - * value of the property named @name in the node /aliases. - * - * returns: - * a pointer to the expansion of the alias named 'name', if it exists - * NULL, if the given alias or the /aliases node does not exist - */ -const char *fdt_get_alias(const void *fdt, const char *name); - -/** - * fdt_get_symbol_namelen - get symbol based on substring - * @fdt: pointer to the device tree blob - * @name: name of the symbol to look up - * @namelen: number of characters of name to consider - * - * Identical to fdt_get_symbol(), but only examine the first @namelen - * characters of @name for matching the symbol name. - * - * Return: a pointer to the expansion of the symbol named @name, if it exists, - * NULL otherwise - */ -#ifndef SWIG /* Not available in Python */ -const char *fdt_get_symbol_namelen(const void *fdt, - const char *name, int namelen); -#endif - -/** - * fdt_get_symbol - retrieve the path referenced by a given symbol - * @fdt: pointer to the device tree blob - * @name: name of the symbol to look up - * - * fdt_get_symbol() retrieves the value of a given symbol. That is, - * the value of the property named @name in the node - * /__symbols__. Such a node exists only for a device tree blob that - * has been compiled with the -@ dtc option. Each property corresponds - * to a label appearing in the device tree source, with the name of - * the property being the label and the value being the full path of - * the node it is attached to. - * - * returns: - * a pointer to the expansion of the symbol named 'name', if it exists - * NULL, if the given symbol or the /__symbols__ node does not exist - */ -const char *fdt_get_symbol(const void *fdt, const char *name); - -/** - * fdt_get_path - determine the full path of a node - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose path to find - * @buf: character buffer to contain the returned path (will be overwritten) - * @buflen: size of the character buffer at buf - * - * fdt_get_path() computes the full path of the node at offset - * nodeoffset, and records that path in the buffer at buf. - * - * NOTE: This function is expensive, as it must scan the device tree - * structure from the start to nodeoffset. - * - * returns: - * 0, on success - * buf contains the absolute path of the node at - * nodeoffset, as a NUL-terminated string. - * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag - * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1) - * characters and will not fit in the given buffer. - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen); - -/** - * fdt_supernode_atdepth_offset - find a specific ancestor of a node - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose parent to find - * @supernodedepth: depth of the ancestor to find - * @nodedepth: pointer to an integer variable (will be overwritten) or NULL - * - * fdt_supernode_atdepth_offset() finds an ancestor of the given node - * at a specific depth from the root (where the root itself has depth - * 0, its immediate subnodes depth 1 and so forth). So - * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL); - * will always return 0, the offset of the root node. If the node at - * nodeoffset has depth D, then: - * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL); - * will return nodeoffset itself. - * - * NOTE: This function is expensive, as it must scan the device tree - * structure from the start to nodeoffset. - * - * returns: - * structure block offset of the node at node offset's ancestor - * of depth supernodedepth (>=0), on success - * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag - * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of - * nodeoffset - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, - int supernodedepth, int *nodedepth); - -/** - * fdt_node_depth - find the depth of a given node - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose parent to find - * - * fdt_node_depth() finds the depth of a given node. The root node - * has depth 0, its immediate subnodes depth 1 and so forth. - * - * NOTE: This function is expensive, as it must scan the device tree - * structure from the start to nodeoffset. - * - * returns: - * depth of the node at nodeoffset (>=0), on success - * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_node_depth(const void *fdt, int nodeoffset); - -/** - * fdt_parent_offset - find the parent of a given node - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose parent to find - * - * fdt_parent_offset() locates the parent node of a given node (that - * is, it finds the offset of the node which contains the node at - * nodeoffset as a subnode). - * - * NOTE: This function is expensive, as it must scan the device tree - * structure from the start to nodeoffset, *twice*. - * - * returns: - * structure block offset of the parent of the node at nodeoffset - * (>=0), on success - * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_parent_offset(const void *fdt, int nodeoffset); - -/** - * fdt_node_offset_by_prop_value - find nodes with a given property value - * @fdt: pointer to the device tree blob - * @startoffset: only find nodes after this offset - * @propname: property name to check - * @propval: property value to search for - * @proplen: length of the value in propval - * - * fdt_node_offset_by_prop_value() returns the offset of the first - * node after startoffset, which has a property named propname whose - * value is of length proplen and has value equal to propval; or if - * startoffset is -1, the very first such node in the tree. - * - * To iterate through all nodes matching the criterion, the following - * idiom can be used: - * offset = fdt_node_offset_by_prop_value(fdt, -1, propname, - * propval, proplen); - * while (offset != -FDT_ERR_NOTFOUND) { - * // other code here - * offset = fdt_node_offset_by_prop_value(fdt, offset, propname, - * propval, proplen); - * } - * - * Note the -1 in the first call to the function, if 0 is used here - * instead, the function will never locate the root node, even if it - * matches the criterion. - * - * returns: - * structure block offset of the located node (>= 0, >startoffset), - * on success - * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the - * tree after startoffset - * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, - const char *propname, - const void *propval, int proplen); - -/** - * fdt_node_offset_by_phandle - find the node with a given phandle - * @fdt: pointer to the device tree blob - * @phandle: phandle value - * - * fdt_node_offset_by_phandle() returns the offset of the node - * which has the given phandle value. If there is more than one node - * in the tree with the given phandle (an invalid tree), results are - * undefined. - * - * returns: - * structure block offset of the located node (>= 0), on success - * -FDT_ERR_NOTFOUND, no node with that phandle exists - * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1) - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle); - -/** - * fdt_node_check_compatible - check a node's compatible property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of a tree node - * @compatible: string to match against - * - * fdt_node_check_compatible() returns 0 if the given node contains a - * @compatible property with the given string as one of its elements, - * it returns non-zero otherwise, or on error. - * - * returns: - * 0, if the node has a 'compatible' property listing the given string - * 1, if the node has a 'compatible' property, but it does not list - * the given string - * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property - * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_node_check_compatible(const void *fdt, int nodeoffset, - const char *compatible); - -/** - * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value - * @fdt: pointer to the device tree blob - * @startoffset: only find nodes after this offset - * @compatible: 'compatible' string to match against - * - * fdt_node_offset_by_compatible() returns the offset of the first - * node after startoffset, which has a 'compatible' property which - * lists the given compatible string; or if startoffset is -1, the - * very first such node in the tree. - * - * To iterate through all nodes matching the criterion, the following - * idiom can be used: - * offset = fdt_node_offset_by_compatible(fdt, -1, compatible); - * while (offset != -FDT_ERR_NOTFOUND) { - * // other code here - * offset = fdt_node_offset_by_compatible(fdt, offset, compatible); - * } - * - * Note the -1 in the first call to the function, if 0 is used here - * instead, the function will never locate the root node, even if it - * matches the criterion. - * - * returns: - * structure block offset of the located node (>= 0, >startoffset), - * on success - * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the - * tree after startoffset - * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, standard meanings - */ -int fdt_node_offset_by_compatible(const void *fdt, int startoffset, - const char *compatible); - -/** - * fdt_stringlist_contains - check a string list property for a string - * @strlist: Property containing a list of strings to check - * @listlen: Length of property - * @str: String to search for - * - * This is a utility function provided for convenience. The list contains - * one or more strings, each terminated by \0, as is found in a device tree - * "compatible" property. - * - * Return: 1 if the string is found in the list, 0 not found, or invalid list - */ -int fdt_stringlist_contains(const char *strlist, int listlen, const char *str); - -/** - * fdt_stringlist_count - count the number of strings in a string list - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of a tree node - * @property: name of the property containing the string list - * - * Return: - * the number of strings in the given property - * -FDT_ERR_BADVALUE if the property value is not NUL-terminated - * -FDT_ERR_NOTFOUND if the property does not exist - */ -int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property); - -/** - * fdt_stringlist_search - find a string in a string list and return its index - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of a tree node - * @property: name of the property containing the string list - * @string: string to look up in the string list - * - * Note that it is possible for this function to succeed on property values - * that are not NUL-terminated. That's because the function will stop after - * finding the first occurrence of @string. This can for example happen with - * small-valued cell properties, such as #address-cells, when searching for - * the empty string. - * - * return: - * the index of the string in the list of strings - * -FDT_ERR_BADVALUE if the property value is not NUL-terminated - * -FDT_ERR_NOTFOUND if the property does not exist or does not contain - * the given string - */ -int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, - const char *string); - -/** - * fdt_stringlist_get() - obtain the string at a given index in a string list - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of a tree node - * @property: name of the property containing the string list - * @index: index of the string to return - * @lenp: return location for the string length or an error code on failure - * - * Note that this will successfully extract strings from properties with - * non-NUL-terminated values. For example on small-valued cell properties - * this function will return the empty string. - * - * If non-NULL, the length of the string (on success) or a negative error-code - * (on failure) will be stored in the integer pointer to by lenp. - * - * Return: - * A pointer to the string at the given index in the string list or NULL on - * failure. On success the length of the string will be stored in the memory - * location pointed to by the lenp parameter, if non-NULL. On failure one of - * the following negative error codes will be returned in the lenp parameter - * (if non-NULL): - * -FDT_ERR_BADVALUE if the property value is not NUL-terminated - * -FDT_ERR_NOTFOUND if the property does not exist - */ -const char *fdt_stringlist_get(const void *fdt, int nodeoffset, - const char *property, int index, - int *lenp); - -/**********************************************************************/ -/* Read-only functions (addressing related) */ -/**********************************************************************/ - -/** - * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells - * - * This is the maximum value for #address-cells, #size-cells and - * similar properties that will be processed by libfdt. IEE1275 - * requires that OF implementations handle values up to 4. - * Implementations may support larger values, but in practice higher - * values aren't used. - */ -#define FDT_MAX_NCELLS 4 - -/** - * fdt_address_cells - retrieve address size for a bus represented in the tree - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node to find the address size for - * - * When the node has a valid #address-cells property, returns its value. - * - * returns: - * 0 <= n < FDT_MAX_NCELLS, on success - * 2, if the node has no #address-cells property - * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid - * #address-cells property - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_address_cells(const void *fdt, int nodeoffset); - -/** - * fdt_size_cells - retrieve address range size for a bus represented in the - * tree - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node to find the address range size for - * - * When the node has a valid #size-cells property, returns its value. - * - * returns: - * 0 <= n < FDT_MAX_NCELLS, on success - * 1, if the node has no #size-cells property - * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid - * #size-cells property - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_size_cells(const void *fdt, int nodeoffset); - - -/**********************************************************************/ -/* Write-in-place functions */ -/**********************************************************************/ - -/** - * fdt_setprop_inplace_namelen_partial - change a property's value, - * but not its size - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @namelen: number of characters of name to consider - * @idx: index of the property to change in the array - * @val: pointer to data to replace the property value with - * @len: length of the property value - * - * Identical to fdt_setprop_inplace(), but modifies the given property - * starting from the given index, and using only the first characters - * of the name. It is useful when you want to manipulate only one value of - * an array and you have a string that doesn't end with \0. - * - * Return: 0 on success, negative libfdt error value otherwise - */ -#ifndef SWIG /* Not available in Python */ -int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, - const char *name, int namelen, - uint32_t idx, const void *val, - int len); -#endif - -/** - * fdt_setprop_inplace - change a property's value, but not its size - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: pointer to data to replace the property value with - * @len: length of the property value - * - * fdt_setprop_inplace() replaces the value of a given property with - * the data in val, of length len. This function cannot change the - * size of a property, and so will only work if len is equal to the - * current length of the property. - * - * This function will alter only the bytes in the blob which contain - * the given property value, and will not alter or move any other part - * of the tree. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if len is not equal to the property's current length - * -FDT_ERR_NOTFOUND, node does not have the named property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -#ifndef SWIG /* Not available in Python */ -int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, - const void *val, int len); -#endif - -/** - * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 32-bit integer value to replace the property with - * - * fdt_setprop_inplace_u32() replaces the value of a given property - * with the 32-bit integer value in val, converting val to big-endian - * if necessary. This function cannot change the size of a property, - * and so will only work if the property already exists and has length - * 4. - * - * This function will alter only the bytes in the blob which contain - * the given property value, and will not alter or move any other part - * of the tree. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if the property's length is not equal to 4 - * -FDT_ERR_NOTFOUND, node does not have the named property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset, - const char *name, uint32_t val) -{ - fdt32_t tmp = cpu_to_fdt32(val); - return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); -} - -/** - * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 64-bit integer value to replace the property with - * - * fdt_setprop_inplace_u64() replaces the value of a given property - * with the 64-bit integer value in val, converting val to big-endian - * if necessary. This function cannot change the size of a property, - * and so will only work if the property already exists and has length - * 8. - * - * This function will alter only the bytes in the blob which contain - * the given property value, and will not alter or move any other part - * of the tree. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if the property's length is not equal to 8 - * -FDT_ERR_NOTFOUND, node does not have the named property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset, - const char *name, uint64_t val) -{ - fdt64_t tmp = cpu_to_fdt64(val); - return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); -} - -/** - * fdt_setprop_inplace_cell - change the value of a single-cell property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node containing the property - * @name: name of the property to change the value of - * @val: new value of the 32-bit cell - * - * This is an alternative name for fdt_setprop_inplace_u32() - * Return: 0 on success, negative libfdt error number otherwise. - */ -static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, - const char *name, uint32_t val) -{ - return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val); -} - -/** - * fdt_nop_property - replace a property with nop tags - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to nop - * @name: name of the property to nop - * - * fdt_nop_property() will replace a given property's representation - * in the blob with FDT_NOP tags, effectively removing it from the - * tree. - * - * This function will alter only the bytes in the blob which contain - * the property, and will not alter or move any other part of the - * tree. - * - * returns: - * 0, on success - * -FDT_ERR_NOTFOUND, node does not have the named property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_nop_property(void *fdt, int nodeoffset, const char *name); - -/** - * fdt_nop_node - replace a node (subtree) with nop tags - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node to nop - * - * fdt_nop_node() will replace a given node's representation in the - * blob, including all its subnodes, if any, with FDT_NOP tags, - * effectively removing it from the tree. - * - * This function will alter only the bytes in the blob which contain - * the node and its properties and subnodes, and will not alter or - * move any other part of the tree. - * - * returns: - * 0, on success - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_nop_node(void *fdt, int nodeoffset); - -/**********************************************************************/ -/* Sequential write functions */ -/**********************************************************************/ - -/* fdt_create_with_flags flags */ -#define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1 - /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property - * names in the fdt. This can result in faster creation times, but - * a larger fdt. */ - -#define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP) - -/** - * fdt_create_with_flags - begin creation of a new fdt - * @buf: pointer to memory allocated where fdt will be created - * @bufsize: size of the memory space at fdt - * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0. - * - * fdt_create_with_flags() begins the process of creating a new fdt with - * the sequential write interface. - * - * fdt creation process must end with fdt_finish() to produce a valid fdt. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt - * -FDT_ERR_BADFLAGS, flags is not valid - */ -int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags); - -/** - * fdt_create - begin creation of a new fdt - * @buf: pointer to memory allocated where fdt will be created - * @bufsize: size of the memory space at fdt - * - * fdt_create() is equivalent to fdt_create_with_flags() with flags=0. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt - */ -int fdt_create(void *buf, int bufsize); - -/** - * fdt_resize - move and resize a device tree in sequential write state - * @fdt: Pointer to the device tree to resize - * @buf: Buffer where resized tree should be placed - * @bufsize: Size of the buffer at @buf - * - * fdt_resize() moves the device tree blob from @fdt to @buf and - * resizes it to fit in the new buffer size. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if @bufsize is too small - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, standard meanings - */ -int fdt_resize(void *fdt, void *buf, int bufsize); - -/** - * fdt_add_reservemap_entry - add an entry to the memory reserve map - * @fdt: Pointer to the device tree blob - * @addr: Start address of the reserve map entry - * @size: Size of the reserved region - * - * fdt_add_reservemap_entry() adds a memory reserve map entry to the - * device tree blob during the sequential write process. This function - * can only be called after fdt_create() and before fdt_finish_reservemap(). - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if there is insufficient space in the blob - * -FDT_ERR_BADSTATE, if not in the correct sequential write state - */ -int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); - -/** - * fdt_finish_reservemap - complete the memory reserve map - * @fdt: Pointer to the device tree blob - * - * fdt_finish_reservemap() completes the memory reserve map section - * of the device tree blob during sequential write. After calling this - * function, no more reserve map entries can be added and the blob - * moves to the structure creation phase. - * - * returns: - * 0, on success - * -FDT_ERR_BADSTATE, if not in the correct sequential write state - */ -int fdt_finish_reservemap(void *fdt); - -/** - * fdt_begin_node - start creation of a new node - * @fdt: Pointer to the device tree blob - * @name: Name of the node to create - * - * fdt_begin_node() starts the creation of a new node with the given - * @name during sequential write. After calling this function, properties - * can be added with fdt_property() and subnodes can be created with - * additional fdt_begin_node() calls. The node must be completed with - * fdt_end_node(). - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if there is insufficient space in the blob - * -FDT_ERR_BADSTATE, if not in the correct sequential write state - */ -int fdt_begin_node(void *fdt, const char *name); - -/** - * fdt_property - add a property to the current node - * @fdt: Pointer to the device tree blob - * @name: Name of the property to add - * @val: Pointer to the property value - * @len: Length of the property value in bytes - * - * fdt_property() adds a property with the given @name and value to - * the current node during sequential write. This function can only - * be called between fdt_begin_node() and fdt_end_node(). - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if there is insufficient space in the blob - * -FDT_ERR_BADSTATE, if not currently within a node - */ -int fdt_property(void *fdt, const char *name, const void *val, int len); -static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val) -{ - fdt32_t tmp = cpu_to_fdt32(val); - return fdt_property(fdt, name, &tmp, sizeof(tmp)); -} -static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) -{ - fdt64_t tmp = cpu_to_fdt64(val); - return fdt_property(fdt, name, &tmp, sizeof(tmp)); -} - -#ifndef SWIG /* Not available in Python */ -static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) -{ - return fdt_property_u32(fdt, name, val); -} -#endif - -/** - * fdt_property_placeholder - add a new property and return a ptr to its value - * - * @fdt: pointer to the device tree blob - * @name: name of property to add - * @len: length of property value in bytes - * @valp: returns a pointer to where the value should be placed - * - * returns: - * 0, on success - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_NOSPACE, standard meanings - */ -int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp); - -#define fdt_property_string(fdt, name, str) \ - fdt_property(fdt, name, str, strlen(str)+1) - -/** - * fdt_end_node - complete the current node - * @fdt: Pointer to the device tree blob - * - * fdt_end_node() completes the current node during sequential write. This - * function must be called to close each node started with - * fdt_begin_node(). After calling this function, no more properties or subnodes - * can be added to the node. - * - * returns: - * 0, on success - * -FDT_ERR_BADSTATE, if not currently within a node - */ -int fdt_end_node(void *fdt); - -/** - * fdt_finish - complete device tree creation - * @fdt: Pointer to the device tree blob - * - * fdt_finish() completes the device tree creation process started with - * fdt_create(). This function finalizes the device tree blob and makes it ready - * for use. After calling this function, the blob is complete and can be used - * with libfdt read-only and read-write functions, but not with sequential write - * functions. - * - * returns: - * 0, on success - * -FDT_ERR_BADSTATE, if the sequential write process is incomplete - */ -int fdt_finish(void *fdt); - -/**********************************************************************/ -/* Read-write functions */ -/**********************************************************************/ - -/** - * fdt_create_empty_tree - create an empty device tree - * @buf: Buffer where the empty tree should be created - * @bufsize: Size of the buffer at @buf - * - * fdt_create_empty_tree() creates a minimal empty device tree blob - * in the given buffer. The tree contains only a root node with no - * properties or subnodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if @bufsize is too small for even an empty tree - */ -int fdt_create_empty_tree(void *buf, int bufsize); - -/** - * fdt_open_into - move a device tree into a new buffer and make editable - * @fdt: Pointer to the device tree to move - * @buf: Buffer where the editable tree should be placed - * @bufsize: Size of the buffer at @buf - * - * fdt_open_into() moves and reorganizes the device tree blob from @fdt - * into @buf, converting it to a format suitable for read-write operations. - * The new buffer should allow space for modifications. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, if @bufsize is too small - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_open_into(const void *fdt, void *buf, int bufsize); - -/** - * fdt_pack - pack a device tree blob - * @fdt: Pointer to the device tree blob - * - * fdt_pack() reorganizes the device tree blob to eliminate any free space - * and pack it into the minimum possible size. This is useful after making - * modifications that might have left gaps in the blob. - * - * returns: - * 0, on success - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, standard meanings - */ -int fdt_pack(void *fdt); - -/** - * fdt_add_mem_rsv - add one memory reserve map entry - * @fdt: pointer to the device tree blob - * @address: 64-bit start address of the reserve map entry - * @size: 64-bit size of the reserved region - * - * Adds a reserve map entry to the given blob reserving a region at - * address address of length size. - * - * This function will insert data into the reserve map and will - * therefore change the indexes of some entries in the table. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new reservation entry - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size); - -/** - * fdt_del_mem_rsv - remove a memory reserve map entry - * @fdt: pointer to the device tree blob - * @n: entry to remove - * - * fdt_del_mem_rsv() removes the n-th memory reserve map entry from - * the blob. - * - * This function will delete data from the reservation table and will - * therefore change the indexes of some entries in the table. - * - * returns: - * 0, on success - * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there - * are less than n+1 reserve map entries) - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_del_mem_rsv(void *fdt, int n); - -/** - * fdt_set_name - change the name of a given node - * @fdt: pointer to the device tree blob - * @nodeoffset: structure block offset of a node - * @name: name to give the node - * - * fdt_set_name() replaces the name (including unit address, if any) - * of the given node with the given string. NOTE: this function can't - * efficiently check if the new name is unique amongst the given - * node's siblings; results are undefined if this function is invoked - * with a name equal to one of the given node's siblings. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob - * to contain the new name - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, standard meanings - */ -int fdt_set_name(void *fdt, int nodeoffset, const char *name); - -/** - * fdt_setprop_namelen - create or change a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @namelen: length of the name - * @val: pointer to data to set the property value to - * @len: length of the property value - * - * fdt_setprop_namelen() sets the value of the named property in the given - * node to the given value and length, creating the property if it - * does not already exist. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name, - int namelen, const void *val, int len); - -/** - * fdt_setprop - create or change a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: pointer to data to set the property value to - * @len: length of the property value - * - * fdt_setprop() sets the value of the named property in the given - * node to the given value and length, creating the property if it - * does not already exist. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_setprop(void *fdt, int nodeoffset, const char *name, - const void *val, int len) -{ - return fdt_setprop_namelen(fdt, nodeoffset, name, strlen(name), val, - len); -} - -/** - * fdt_setprop_placeholder_namelen - allocate space for a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @namelen: length of the name - * @len: length of the property value - * @prop_data: return pointer to property data - * - * fdt_setprop_placeholder_namelen() allocates the named property in the given node. - * If the property exists it is resized. In either case a pointer to the - * property data is returned. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name, - int namelen, int len, void **prop_data); - -/** - * fdt_setprop_placeholder - allocate space for a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @len: length of the property value - * @prop_data: return pointer to property data - * - * fdt_setprop_placeholder() allocates the named property in the given node. - * If the property exists it is resized. In either case a pointer to the - * property data is returned. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_setprop_placeholder(void *fdt, int nodeoffset, - const char *name, int len, - void **prop_data) -{ - return fdt_setprop_placeholder_namelen(fdt, nodeoffset, name, - strlen(name), len, prop_data); -} - -/** - * fdt_setprop_u32 - set a property to a 32-bit integer - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 32-bit integer value for the property (native endian) - * - * fdt_setprop_u32() sets the value of the named property in the given - * node to the given 32-bit integer value (converting to big-endian if - * necessary), or creates a new property with that value if it does - * not already exist. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name, - uint32_t val) -{ - fdt32_t tmp = cpu_to_fdt32(val); - return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); -} - -/** - * fdt_setprop_u64 - set a property to a 64-bit integer - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 64-bit integer value for the property (native endian) - * - * fdt_setprop_u64() sets the value of the named property in the given - * node to the given 64-bit integer value (converting to big-endian if - * necessary), or creates a new property with that value if it does - * not already exist. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name, - uint64_t val) -{ - fdt64_t tmp = cpu_to_fdt64(val); - return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); -} - -/** - * fdt_setprop_cell - set a property to a single cell value - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 32-bit integer value for the property (native endian) - * - * This is an alternative name for fdt_setprop_u32() - * - * Return: 0 on success, negative libfdt error value otherwise. - */ -static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name, - uint32_t val) -{ - return fdt_setprop_u32(fdt, nodeoffset, name, val); -} - -/** - * fdt_setprop_string - set a property to a string value - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @str: string value for the property - * - * fdt_setprop_string() sets the value of the named property in the - * given node to the given string value (using the length of the - * string to determine the new length of the property), or creates a - * new property with that value if it does not already exist. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -#define fdt_setprop_string(fdt, nodeoffset, name, str) \ - fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) - -/** - * fdt_setprop_namelen_string - set a property to a string value - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @namelen: number of characters of name to consider - * @str: string value for the property - * - * fdt_setprop_namelen_string() sets the value of the named property in the - * given node to the given string value (using the length of the - * string to determine the new length of the property), or creates a - * new property with that value if it does not already exist. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -#define fdt_setprop_namelen_string(fdt, nodeoffset, name, namelen, str) \ - fdt_setprop_namelen((fdt), (nodeoffset), (name), (namelen), (str), \ - strlen(str) + 1) - -/** - * fdt_setprop_empty - set a property to an empty value - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * - * fdt_setprop_empty() sets the value of the named property in the - * given node to an empty (zero length) value, or creates a new empty - * property if it does not already exist. - * - * This function may insert or delete data from the blob, and will - * therefore change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -#define fdt_setprop_empty(fdt, nodeoffset, name) \ - fdt_setprop((fdt), (nodeoffset), (name), NULL, 0) - -/** - * fdt_appendprop - append to or create a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to append to - * @val: pointer to data to append to the property value - * @len: length of the data to append to the property value - * - * fdt_appendprop() appends the value to the named property in the - * given node, creating the property if it does not already exist. - * - * This function may insert data into the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_appendprop(void *fdt, int nodeoffset, const char *name, - const void *val, int len); - -/** - * fdt_appendprop_u32 - append a 32-bit integer value to a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 32-bit integer value to append to the property (native endian) - * - * fdt_appendprop_u32() appends the given 32-bit integer value - * (converting to big-endian if necessary) to the value of the named - * property in the given node, or creates a new property with that - * value if it does not already exist. - * - * This function may insert data into the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_appendprop_u32(void *fdt, int nodeoffset, - const char *name, uint32_t val) -{ - fdt32_t tmp = cpu_to_fdt32(val); - return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); -} - -/** - * fdt_appendprop_u64 - append a 64-bit integer value to a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 64-bit integer value to append to the property (native endian) - * - * fdt_appendprop_u64() appends the given 64-bit integer value - * (converting to big-endian if necessary) to the value of the named - * property in the given node, or creates a new property with that - * value if it does not already exist. - * - * This function may insert data into the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -static inline int fdt_appendprop_u64(void *fdt, int nodeoffset, - const char *name, uint64_t val) -{ - fdt64_t tmp = cpu_to_fdt64(val); - return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); -} - -/** - * fdt_appendprop_cell - append a single cell value to a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @val: 32-bit integer value to append to the property (native endian) - * - * This is an alternative name for fdt_appendprop_u32() - * - * Return: 0 on success, negative libfdt error value otherwise. - */ -static inline int fdt_appendprop_cell(void *fdt, int nodeoffset, - const char *name, uint32_t val) -{ - return fdt_appendprop_u32(fdt, nodeoffset, name, val); -} - -/** - * fdt_appendprop_string - append a string to a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to change - * @name: name of the property to change - * @str: string value to append to the property - * - * fdt_appendprop_string() appends the given string to the value of - * the named property in the given node, or creates a new property - * with that value if it does not already exist. - * - * This function may insert data into the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain the new property value - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_TRUNCATED, standard meanings - */ -#define fdt_appendprop_string(fdt, nodeoffset, name, str) \ - fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) - -/** - * fdt_appendprop_addrrange - append a address range property - * @fdt: pointer to the device tree blob - * @parent: offset of the parent node - * @nodeoffset: offset of the node to add a property at - * @name: name of property - * @addr: start address of a given range - * @size: size of a given range - * - * fdt_appendprop_addrrange() appends an address range value (start - * address and size) to the value of the named property in the given - * node, or creates a new property with that value if it does not - * already exist. - * - * Cell sizes are determined by parent's #address-cells and #size-cells. - * - * This function may insert data into the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid - * #address-cells property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size - * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to - * contain a new property - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset, - const char *name, uint64_t addr, uint64_t size); - -/** - * fdt_delprop - delete a property - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node whose property to nop - * @name: name of the property to nop - * - * fdt_delprop() will delete the given property. - * - * This function will delete data from the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_NOTFOUND, node does not have the named property - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_delprop(void *fdt, int nodeoffset, const char *name); - -/** - * fdt_add_subnode_namelen - creates a new node based on substring - * @fdt: pointer to the device tree blob - * @parentoffset: structure block offset of a node - * @name: name of the subnode to create - * @namelen: number of characters of name to consider - * - * Identical to fdt_add_subnode(), but use only the first @namelen - * characters of @name as the name of the new node. This is useful for - * creating subnodes based on a portion of a larger string, such as a - * full path. - * - * Return: structure block offset of the created subnode (>=0), - * negative libfdt error value otherwise - */ -#ifndef SWIG /* Not available in Python */ -int fdt_add_subnode_namelen(void *fdt, int parentoffset, - const char *name, int namelen); -#endif - -/** - * fdt_add_subnode - creates a new node - * @fdt: pointer to the device tree blob - * @parentoffset: structure block offset of a node - * @name: name of the subnode to locate - * - * fdt_add_subnode() creates a new node as a subnode of the node at - * structure block offset parentoffset, with the given name (which - * should include the unit address, if any). - * - * This function will insert data into the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * structure block offset of the created subnode (>=0), on success - * -FDT_ERR_NOTFOUND, if the requested subnode does not exist - * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE - * tag - * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of - * the given name - * -FDT_ERR_NOSPACE, if there is insufficient free space in the - * blob to contain the new node - * -FDT_ERR_NOSPACE - * -FDT_ERR_BADLAYOUT - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings. - */ -int fdt_add_subnode(void *fdt, int parentoffset, const char *name); - -/** - * fdt_del_node - delete a node (subtree) - * @fdt: pointer to the device tree blob - * @nodeoffset: offset of the node to nop - * - * fdt_del_node() will remove the given node, including all its - * subnodes if any, from the blob. - * - * This function will delete data from the blob, and will therefore - * change the offsets of some existing nodes. - * - * returns: - * 0, on success - * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_del_node(void *fdt, int nodeoffset); - -/** - * fdt_overlay_apply - Applies a DT overlay on a base DT - * @fdt: pointer to the base device tree blob - * @fdto: pointer to the device tree overlay blob - * - * fdt_overlay_apply() will apply the given device tree overlay on the - * given base device tree. - * - * Expect the base device tree to be modified, even if the function - * returns an error. - * - * returns: - * 0, on success - * -FDT_ERR_NOSPACE, there's not enough space in the base device tree - * -FDT_ERR_NOTFOUND, the overlay points to some nonexistent nodes or - * properties in the base DT - * -FDT_ERR_BADPHANDLE, - * -FDT_ERR_BADOVERLAY, - * -FDT_ERR_NOPHANDLES, - * -FDT_ERR_INTERNAL, - * -FDT_ERR_BADLAYOUT, - * -FDT_ERR_BADMAGIC, - * -FDT_ERR_BADOFFSET, - * -FDT_ERR_BADPATH, - * -FDT_ERR_BADVERSION, - * -FDT_ERR_BADSTRUCTURE, - * -FDT_ERR_BADSTATE, - * -FDT_ERR_TRUNCATED, standard meanings - */ -int fdt_overlay_apply(void *fdt, void *fdto); - -/** - * fdt_overlay_target_offset - retrieves the offset of a fragment's target - * @fdt: Base device tree blob - * @fdto: Device tree overlay blob - * @fragment_offset: node offset of the fragment in the overlay - * @pathp: pointer which receives the path of the target (or NULL) - * - * fdt_overlay_target_offset() retrieves the target offset in the base - * device tree of a fragment, no matter how the actual targeting is - * done (through a phandle or a path) - * - * returns: - * the targeted node offset in the base device tree - * Negative error code on error - */ -int fdt_overlay_target_offset(const void *fdt, const void *fdto, - int fragment_offset, char const **pathp); - -/**********************************************************************/ -/* Debugging / informational functions */ -/**********************************************************************/ - -/** - * fdt_strerror - return string description of error code - * @errval: Error code returned by a libfdt function - * - * fdt_strerror() returns a string description of the error code passed - * in @errval. - * - * returns: - * pointer to a string describing the error code - */ -const char *fdt_strerror(int errval); - -#ifdef __cplusplus -} -#endif - -#endif /* LIBFDT_H */ diff --git a/scripts/dtc/libfdt/libfdt_env.h b/scripts/dtc/libfdt/libfdt_env.h deleted file mode 100644 index 5580b48..0000000 --- a/scripts/dtc/libfdt/libfdt_env.h +++ /dev/null @@ -1,69 +0,0 @@ -/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ -#ifndef LIBFDT_ENV_H -#define LIBFDT_ENV_H -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * Copyright 2012 Kim Phillips, Freescale Semiconductor. - */ - -#include -#include -#include -#include -#include -#include - -#ifdef __CHECKER__ -#define FDT_FORCE __attribute__((force)) -#define FDT_BITWISE __attribute__((bitwise)) -#else -#define FDT_FORCE -#define FDT_BITWISE -#endif - -typedef uint16_t FDT_BITWISE fdt16_t; -typedef uint32_t FDT_BITWISE fdt32_t; -typedef uint64_t FDT_BITWISE fdt64_t; - -#define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n]) -#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1)) -#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \ - (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3)) -#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \ - (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \ - (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \ - (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7)) - -static inline uint16_t fdt16_to_cpu(fdt16_t x) -{ - return (FDT_FORCE uint16_t)CPU_TO_FDT16(x); -} -static inline fdt16_t cpu_to_fdt16(uint16_t x) -{ - return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x); -} - -static inline uint32_t fdt32_to_cpu(fdt32_t x) -{ - return (FDT_FORCE uint32_t)CPU_TO_FDT32(x); -} -static inline fdt32_t cpu_to_fdt32(uint32_t x) -{ - return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x); -} - -static inline uint64_t fdt64_to_cpu(fdt64_t x) -{ - return (FDT_FORCE uint64_t)CPU_TO_FDT64(x); -} -static inline fdt64_t cpu_to_fdt64(uint64_t x) -{ - return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x); -} -#undef CPU_TO_FDT64 -#undef CPU_TO_FDT32 -#undef CPU_TO_FDT16 -#undef EXTRACT_BYTE - -#endif /* LIBFDT_ENV_H */ diff --git a/scripts/dtc/libfdt/libfdt_internal.h b/scripts/dtc/libfdt/libfdt_internal.h deleted file mode 100644 index 0e103ca..0000000 --- a/scripts/dtc/libfdt/libfdt_internal.h +++ /dev/null @@ -1,202 +0,0 @@ -/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ -#ifndef LIBFDT_INTERNAL_H -#define LIBFDT_INTERNAL_H -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - */ -#include - -#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) -#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) - -int32_t fdt_ro_probe_(const void *fdt); -#define FDT_RO_PROBE(fdt) \ - { \ - if (!can_assume(VALID_DTB)) { \ - int32_t totalsize_; \ - if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ - return totalsize_; \ - } \ - } - -int fdt_check_node_offset_(const void *fdt, int offset); -int fdt_check_prop_offset_(const void *fdt, int offset); - -const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s, - int s_len); -static inline const char *fdt_find_string_(const char *strtab, int tabsize, - const char *s) -{ - return fdt_find_string_len_(strtab, tabsize, s, strlen(s)); -} - -int fdt_node_end_offset_(void *fdt, int nodeoffset); - -static inline const void *fdt_offset_ptr_(const void *fdt, int offset) -{ - return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; -} - -static inline void *fdt_offset_ptr_w_(void *fdt, int offset) -{ - return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset); -} - -static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n) -{ - const struct fdt_reserve_entry *rsv_table = - (const struct fdt_reserve_entry *) - ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); - - return rsv_table + n; -} -static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n) -{ - return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n); -} - -/* - * Internal helpers to access structural elements of the device tree - * blob (rather than for example reading integers from within property - * values). We assume that we are either given a naturally aligned - * address for the platform or if we are not, we are on a platform - * where unaligned memory reads will be handled in a graceful manner. - * If not the external helpers fdtXX_ld() from libfdt.h can be used - * instead. - */ -static inline uint32_t fdt32_ld_(const fdt32_t *p) -{ - return fdt32_to_cpu(*p); -} - -static inline uint64_t fdt64_ld_(const fdt64_t *p) -{ - return fdt64_to_cpu(*p); -} - -#define FDT_SW_MAGIC (~FDT_MAGIC) - -/**********************************************************************/ -/* Checking controls */ -/**********************************************************************/ - -#ifndef FDT_ASSUME_MASK -#define FDT_ASSUME_MASK 0 -#endif - -/* - * Defines assumptions which can be enabled. Each of these can be enabled - * individually. For maximum safety, don't enable any assumptions! - * - * For minimal code size and no safety, use ASSUME_PERFECT at your own risk. - * You should have another method of validating the device tree, such as a - * signature or hash check before using libfdt. - * - * For situations where security is not a concern it may be safe to enable - * ASSUME_PERFECT. - */ -enum { - /* - * This does essentially no checks. Only the latest device-tree - * version is correctly handled. Inconsistencies or errors in the device - * tree may cause undefined behaviour or crashes. Invalid parameters - * passed to libfdt may do the same. - * - * If an error occurs when modifying the tree it may leave the tree in - * an intermediate (but valid) state. As an example, adding a property - * where there is insufficient space may result in the property name - * being added to the string table even though the property itself is - * not added to the struct section. - * - * Only use this if you have a fully validated device tree with - * the latest supported version and wish to minimise code size. - */ - ASSUME_PERFECT = 0xff, - - /* - * This assumes that the device tree is sane. i.e. header metadata - * and basic hierarchy are correct. - * - * With this assumption enabled, normal device trees produced by libfdt - * and the compiler should be handled safely. Malicious device trees and - * complete garbage may cause libfdt to behave badly or crash. Truncated - * device trees (e.g. those only partially loaded) can also cause - * problems. - * - * Note: Only checks that relate exclusively to the device tree itself - * (not the parameters passed to libfdt) are disabled by this - * assumption. This includes checking headers, tags and the like. - */ - ASSUME_VALID_DTB = 1 << 0, - - /* - * This builds on ASSUME_VALID_DTB and further assumes that libfdt - * functions are called with valid parameters, i.e. not trigger - * FDT_ERR_BADOFFSET or offsets that are out of bounds. It disables any - * extensive checking of parameters and the device tree, making various - * assumptions about correctness. - * - * It doesn't make sense to enable this assumption unless - * ASSUME_VALID_DTB is also enabled. - */ - ASSUME_VALID_INPUT = 1 << 1, - - /* - * This disables checks for device-tree version and removes all code - * which handles older versions. - * - * Only enable this if you know you have a device tree with the latest - * version. - */ - ASSUME_LATEST = 1 << 2, - - /* - * This assumes that it is OK for a failed addition to the device tree, - * due to lack of space or some other problem, to skip any rollback - * steps (such as dropping the property name from the string table). - * This is safe to enable in most circumstances, even though it may - * leave the tree in a sub-optimal state. - */ - ASSUME_NO_ROLLBACK = 1 << 3, - - /* - * This assumes that the device tree components appear in a 'convenient' - * order, i.e. the memory reservation block first, then the structure - * block and finally the string block. - * - * This order is not specified by the device-tree specification, - * but is expected by libfdt. The device-tree compiler always created - * device trees with this order. - * - * This assumption disables a check in fdt_open_into() and removes the - * ability to fix the problem there. This is safe if you know that the - * device tree is correctly ordered. See fdt_blocks_misordered_(). - */ - ASSUME_LIBFDT_ORDER = 1 << 4, - - /* - * This assumes that libfdt itself does not have any internal bugs. It - * drops certain checks that should never be needed unless libfdt has an - * undiscovered bug. - * - * This can generally be considered safe to enable. - */ - ASSUME_LIBFDT_FLAWLESS = 1 << 5, -}; - -/** - * can_assume_() - check if a particular assumption is enabled - * - * @mask: Mask to check (ASSUME_...) - * @return true if that assumption is enabled, else false - */ -static inline bool can_assume_(int mask) -{ - return FDT_ASSUME_MASK & mask; -} - -/** helper macros for checking assumptions */ -#define can_assume(_assume) can_assume_(ASSUME_ ## _assume) - -#endif /* LIBFDT_INTERNAL_H */ diff --git a/scripts/extract-asm-offsets.sed b/scripts/extract-asm-offsets.sed deleted file mode 100644 index c97ec2c..0000000 --- a/scripts/extract-asm-offsets.sed +++ /dev/null @@ -1,18 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Extract `->SYM val COMMENT` markers emitted by inline asm in -# asm-offsets.c into proper `#define SYM val /* COMMENT */` lines. -# 1:1 with Linux scripts/Makefile.lib `sed-offsets`. -# -# Input : assembly source produced by `gcc -S asm-offsets.c` — -# inline asm emits lines like -# .ascii "->KERNEL_MAP_VIRT_ADDR 0 offsetof(...)" -# Output : header fragment for include/generated/asm-offsets.h -# -# Step 1 unwraps the `.ascii "..."` directive so the actual payload -# (starting with `->`) is exposed. Steps 2-4 then rewrite into a -# proper #define. -s:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1: -/^->/{s:->#\(.*\):/* \1 */:; - s:^->\([^ ]*\) [\$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; - s:->::; - p;} diff --git a/scripts/gen_initramfs.sh b/scripts/gen_initramfs.sh deleted file mode 100755 index 8ad0cd7..0000000 --- a/scripts/gen_initramfs.sh +++ /dev/null @@ -1,250 +0,0 @@ -#!/bin/sh -# Copyright (C) Martin Schlemmer -# Copyright (C) 2006 Sam Ravnborg -# -# Released under the terms of the GNU GPL -# -# Generate a cpio packed initramfs. It uses gen_init_cpio to generate -# the cpio archive. -# This script assumes that gen_init_cpio is located in usr/ directory - -# error out on errors -set -e - -usage() { -cat << EOF -Usage: -$0 [-o ] [-l ] [-u ] [-g ] {-d | } ... - -o Create initramfs file named by using gen_init_cpio - -l Create dependency list named - -u User ID to map to user ID 0 (root). - is only meaningful if is a - directory. "squash" forces all files to uid 0. - -g Group ID to map to group ID 0 (root). - is only meaningful if is a - directory. "squash" forces all files to gid 0. - -d Use date for all file mtime values - File list or directory for cpio archive. - If is a .cpio file it will be used - as direct input to initramfs. - -All options except -o and -l may be repeated and are interpreted -sequentially and immediately. -u and -g states are preserved across - options so an explicit "-u 0 -g 0" is required -to reset the root/group mapping. -EOF -} - -# awk style field access -# $1 - field number; rest is argument string -field() { - shift $1 ; echo $1 -} - -filetype() { - local argv1="$1" - - # symlink test must come before file test - if [ -L "${argv1}" ]; then - echo "slink" - elif [ -f "${argv1}" ]; then - echo "file" - elif [ -d "${argv1}" ]; then - echo "dir" - elif [ -b "${argv1}" -o -c "${argv1}" ]; then - echo "nod" - elif [ -p "${argv1}" ]; then - echo "pipe" - elif [ -S "${argv1}" ]; then - echo "sock" - else - echo "invalid" - fi - return 0 -} - -print_mtime() { - local my_mtime="0" - - if [ -e "$1" ]; then - my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1) - fi - - echo "# Last modified: ${my_mtime}" >> $cpio_list - echo "" >> $cpio_list -} - -list_parse() { - if [ -z "$dep_list" -o -L "$1" ]; then - return - fi - echo "$1" | sed 's/:/\\:/g; s/$/ \\/' >> $dep_list -} - -# for each file print a line in following format -# -# for links, devices etc the format differs. See gen_init_cpio for details -parse() { - local location="$1" - local name="/${location#${srcdir}}" - # change '//' into '/' - name=$(echo "$name" | sed -e 's://*:/:g') - local mode="$2" - local uid="$3" - local gid="$4" - local ftype=$(filetype "${location}") - # remap uid/gid to 0 if necessary - [ "$root_uid" = "squash" ] && uid=0 || [ "$uid" -eq "$root_uid" ] && uid=0 - [ "$root_gid" = "squash" ] && gid=0 || [ "$gid" -eq "$root_gid" ] && gid=0 - local str="${mode} ${uid} ${gid}" - - [ "${ftype}" = "invalid" ] && return 0 - [ "${location}" = "${srcdir}" ] && return 0 - - case "${ftype}" in - "file") - str="${ftype} ${name} ${location} ${str}" - ;; - "nod") - local dev="`LC_ALL=C ls -l "${location}"`" - local maj=`field 5 ${dev}` - local min=`field 6 ${dev}` - maj=${maj%,} - - [ -b "${location}" ] && dev="b" || dev="c" - - str="${ftype} ${name} ${str} ${dev} ${maj} ${min}" - ;; - "slink") - local target=`readlink "${location}"` - str="${ftype} ${name} ${target} ${str}" - ;; - *) - str="${ftype} ${name} ${str}" - ;; - esac - - echo "${str}" >> $cpio_list - - return 0 -} - -unknown_option() { - printf "ERROR: unknown option \"$arg\"\n" >&2 - printf "If the filename validly begins with '-', " >&2 - printf "then it must be prefixed\n" >&2 - printf "by './' so that it won't be interpreted as an option." >&2 - printf "\n" >&2 - usage >&2 - exit 1 -} - -header() { - printf "\n#####################\n# $1\n" >> $cpio_list -} - -# process one directory (incl sub-directories) -dir_filelist() { - header "$1" - - srcdir=$(echo "$1" | sed -e 's://*:/:g') - dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LC_ALL=C sort) - - # If $dirlist is only one line, then the directory is empty - if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then - print_mtime "$1" - - echo "${dirlist}" | \ - while read x; do - list_parse $x - parse $x - done - fi -} - -input_file() { - source="$1" - if [ -f "$1" ]; then - # If a regular file is specified, assume it is in - # gen_init_cpio format - header "$1" - print_mtime "$1" >> $cpio_list - cat "$1" >> $cpio_list - if [ -n "$dep_list" ]; then - echo "$1 \\" >> $dep_list - cat "$1" | while read type dir file perm ; do - if [ "$type" = "file" ]; then - echo "$file \\" >> $dep_list - fi - done - fi - elif [ -d "$1" ]; then - # If a directory is specified then add all files in it to fs - dir_filelist "$1" - else - echo " ${prog}: Cannot open '$1'" >&2 - exit 1 - fi -} - -prog=$0 -root_uid=0 -root_gid=0 -dep_list= -timestamp= -cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX) -# gen_init_cpio writes to stdout by default -output="" - -trap "rm -f $cpio_list" EXIT - -while [ $# -gt 0 ]; do - arg="$1" - shift - case "$arg" in - "-l") # files included in initramfs - used by kbuild - dep_list="$1" - echo "deps_initramfs := \\" > $dep_list - shift - ;; - "-o") # generate cpio image named $1 - output="-o $1" - shift - ;; - "-u") # map $1 to uid=0 (root) - root_uid="$1" - [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0) - shift - ;; - "-g") # map $1 to gid=0 (root) - root_gid="$1" - [ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0) - shift - ;; - "-d") # date for file mtimes - timestamp="$(date -d"$1" +%s || :)" - if test -n "$timestamp"; then - timestamp="-t $timestamp" - fi - shift - ;; - "-h") - usage - exit 0 - ;; - *) - case "$arg" in - "-"*) - unknown_option - ;; - *) # input file/dir - process it - input_file "$arg" - ;; - esac - ;; - esac -done - -# If output_file is set we will generate cpio archive -# we are careful to delete tmp files -"${GEN_INIT_CPIO:-usr/gen_init_cpio}" $output $timestamp $cpio_list diff --git a/test/Build.mk b/test/Build.mk deleted file mode 100644 index cb8f200..0000000 --- a/test/Build.mk +++ /dev/null @@ -1,12 +0,0 @@ -targets += test/kernel -target.test/kernel.kind := kernel-test -target.test/kernel.sources := \ - test/selftest.cc test/test_pmm.cc test/test_slab.cc test/test_spinlock.cc \ - test/test_mutex.cc test/test_driver_model.cc test/test_rbtree.cc \ - test/test_vmm.cc test/test_vma.cc test/test_atomic.cc test/test_fdt.cc \ - test/test_trap.cc test/test_sched.cc test/test_klog.cc test/test_random.cc \ - test/test_waitqueue.cc test/test_uaccess.cc test/test_sys_mm.cc \ - test/test_smp.cc test/test_dcache.cc test/test_namei.cc \ - test/test_vfs_io.cc test/test_exec.cc test/test_pipe_devfs.cc \ - test/test_sys_process.cc test/test_signal.cc test/test_pid.cc \ - test/test_sys_fs_extra.cc test/test_page_cache.cc diff --git a/test/selftest.cc b/test/selftest.cc deleted file mode 100644 index e1bb2b4..0000000 --- a/test/selftest.cc +++ /dev/null @@ -1,83 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test Runner - * - * Entry point that invokes all registered self-test suites. - * Called from kernel_main() after all subsystem initialization. - */ - -#include - -/* Individual test suite entry points */ -void selftest_pmm(); -void selftest_slab(); -void selftest_spinlock(); -void selftest_mutex(); -void selftest_driver_model(); -void selftest_rbtree(); -void selftest_vmm(); -void selftest_fdt(); -void selftest_vma(); -void selftest_atomic(); -void selftest_trap(); -void selftest_sched(); -void selftest_klog(); -void selftest_random(); -void selftest_waitqueue(); -void selftest_uaccess(); -void selftest_sys_mm(); -void selftest_dcache(); -void selftest_namei(); -void selftest_vfs_io(); -void selftest_exec(); -void selftest_devfs(); -void selftest_pipe(); -void selftest_fcntl(); -void selftest_sys_process(); -void selftest_signal(); -void selftest_pid(); -void selftest_sys_fs_extra(); -void selftest_page_cache(); - -void selftest_run_all() -{ - kprintf("\n========================================\n"); - kprintf(" Boot Self-Test Suite\n"); - kprintf("========================================\n"); - - selftest_spinlock(); - selftest_mutex(); - selftest_driver_model(); - selftest_pmm(); - selftest_slab(); - selftest_rbtree(); - selftest_vmm(); - selftest_vma(); - selftest_atomic(); - selftest_fdt(); - selftest_trap(); - selftest_sched(); - selftest_klog(); - selftest_random(); - selftest_waitqueue(); - selftest_uaccess(); - selftest_sys_mm(); - selftest_dcache(); - selftest_namei(); - selftest_vfs_io(); - selftest_devfs(); - selftest_pipe(); - selftest_fcntl(); - selftest_sys_process(); - selftest_signal(); - selftest_pid(); - selftest_sys_fs_extra(); - selftest_page_cache(); - selftest_exec(); - - kprintf("========================================\n"); - kprintf(" All self-tests PASSED\n"); - kprintf("========================================\n\n"); -} diff --git a/test/test_atomic.cc b/test/test_atomic.cc deleted file mode 100644 index 9851e7b..0000000 --- a/test/test_atomic.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test: lume::atomic - * - * Tests: - * 1. Default construction (zero-initialized) - * 2. Explicit construction - * 3. store / load round-trip with different memory orders - * 4. exchange returns old value - * 5. fetch_add / fetch_sub arithmetic - * 6. compare_exchange success and failure paths - */ - -#include -#include - -void selftest_atomic() { - st_begin("atomic: default construction is zero"); - { - lume::atomic a; - ST_ASSERT_EQ(a.load(), 0U); - } - st_pass(); - - st_begin("atomic: explicit construction"); - { - lume::atomic a(42); - ST_ASSERT_EQ(a.load(), 42ULL); - } - st_pass(); - - st_begin("atomic: store/load round-trip"); - { - lume::atomic a; - a.store(0xDEAD, __ATOMIC_RELEASE); - ST_ASSERT_EQ(a.load(__ATOMIC_ACQUIRE), 0xDEADU); - - a.store(0, __ATOMIC_SEQ_CST); - ST_ASSERT_EQ(a.load(__ATOMIC_SEQ_CST), 0U); - } - st_pass(); - - st_begin("atomic: exchange returns old value"); - { - lume::atomic a(10); - uint32 old = a.exchange(20); - ST_ASSERT_EQ(old, 10U); - ST_ASSERT_EQ(a.load(), 20U); - } - st_pass(); - - st_begin("atomic: fetch_add / fetch_sub"); - { - lume::atomic a(100); - - uint32 old = a.fetch_add(5); - ST_ASSERT_EQ(old, 100U); - ST_ASSERT_EQ(a.load(), 105U); - - old = a.fetch_sub(10); - ST_ASSERT_EQ(old, 105U); - ST_ASSERT_EQ(a.load(), 95U); - - // Underflow wraps (unsigned) - lume::atomic b(0); - old = b.fetch_sub(1); - ST_ASSERT_EQ(old, 0U); - ST_ASSERT_EQ(b.load(), 0xFFFFFFFFU); - } - st_pass(); - - st_begin("atomic: compare_exchange success and failure"); - { - lume::atomic a(42); - - // Success path: expected matches, swap happens - uint32 expected = 42; - bool ok = a.compare_exchange(expected, 99); - ST_ASSERT(ok); - ST_ASSERT_EQ(a.load(), 99U); - ST_ASSERT_EQ(expected, 42U); // expected unchanged on success - - // Failure path: expected doesn't match, expected gets updated - expected = 0; // wrong - ok = a.compare_exchange(expected, 200); - ST_ASSERT(!ok); - ST_ASSERT_EQ(a.load(), 99U); // value unchanged - ST_ASSERT_EQ(expected, 99U); // expected updated to actual value - } - st_pass(); - - st_begin("atomic: 64-bit fetch_add correctness"); - { - lume::atomic a(0xFFFFFFFF00000000ULL); - uint64 old = a.fetch_add(1); - ST_ASSERT_EQ(old, 0xFFFFFFFF00000000ULL); - ST_ASSERT_EQ(a.load(), 0xFFFFFFFF00000001ULL); - } - st_pass(); -} diff --git a/test/test_dcache.cc b/test/test_dcache.cc deleted file mode 100644 index 9e0eec5..0000000 --- a/test/test_dcache.cc +++ /dev/null @@ -1,232 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_dcache.cc — Self-tests for the dentry cache layer - */ - -#include -#include -#include -#include -#include -#include - -/* Root dentry/mount from VFS init */ -extern dentry* g_root_dentry; -extern vfsmount* g_root_mnt; - -void selftest_dcache() -{ - /* ---- d_alloc: basic allocation under root ---- */ - st_begin("dcache: d_alloc basic"); - { - qstr name{}; - name.name = "test_child"; - name.len = 10; - name.hash = full_name_hash(name.name, name.len); - - dentry* child = d_alloc(g_root_dentry, &name); - ST_ASSERT(child != nullptr); - ST_ASSERT_EQ(child->d_name.len, 10u); - ST_ASSERT(child->d_parent == g_root_dentry); - ST_ASSERT(child->d_inode == nullptr); /* not instantiated yet */ - ST_ASSERT(child->d_sb == g_root_dentry->d_sb); - - /* Name was copied into inline buffer */ - bool match = true; - for (uint32 i = 0; i < name.len; i++) { - if (child->d_name.name[i] != name.name[i]) { match = false; break; } - } - ST_ASSERT(match); - - d_drop(child); - dput(child); - } - st_pass(); - - /* ---- d_lookup: find existing child ---- */ - st_begin("dcache: d_lookup finds child"); - { - qstr name{}; - name.name = "lookup_me"; - name.len = 9; - name.hash = full_name_hash(name.name, name.len); - - dentry* child = d_alloc(g_root_dentry, &name); - ST_ASSERT(child != nullptr); - - /* d_lookup should find it */ - dentry* found = d_lookup(g_root_dentry, &name); - ST_ASSERT(found != nullptr); - ST_ASSERT(found == child); - dput(found); /* drop d_lookup ref */ - - d_drop(child); - dput(child); - } - st_pass(); - - /* ---- d_lookup: miss returns nullptr ---- */ - st_begin("dcache: d_lookup miss returns nullptr"); - { - qstr name{}; - name.name = "nonexistent_xyz"; - name.len = 15; - name.hash = full_name_hash(name.name, name.len); - - dentry* found = d_lookup(g_root_dentry, &name); - ST_ASSERT(found == nullptr); - } - st_pass(); - - /* ---- d_instantiate: bind inode to dentry ---- */ - st_begin("dcache: d_instantiate binds inode"); - { - qstr name{}; - name.name = "has_inode"; - name.len = 9; - name.hash = full_name_hash(name.name, name.len); - - dentry* child = d_alloc(g_root_dentry, &name); - ST_ASSERT(child != nullptr); - ST_ASSERT(child->d_inode == nullptr); - - /* Create a dummy inode */ - inode* ip = new_inode(g_root_dentry->d_sb); - ST_ASSERT(ip != nullptr); - ip->i_mode = S_IFREG | 0644; - - d_instantiate(child, ip); - ST_ASSERT(child->d_inode == ip); - ST_ASSERT(child->d_flags & DCACHE_REGULAR_TYPE); - - d_drop(child); - dput(child); - } - st_pass(); - - /* ---- dget/dput: refcount ---- */ - st_begin("dcache: dget/dput refcount"); - { - qstr name{}; - name.name = "reftest"; - name.len = 7; - name.hash = full_name_hash(name.name, name.len); - - dentry* child = d_alloc(g_root_dentry, &name); - ST_ASSERT(child != nullptr); - /* d_alloc sets refcount = 1 */ - int rc1 = child->d_lockref.load(); - ST_ASSERT(rc1 >= 1); - - dget(child); - int rc2 = child->d_lockref.load(); - ST_ASSERT_EQ(rc2, rc1 + 1); - - dput(child); - int rc3 = child->d_lockref.load(); - ST_ASSERT_EQ(rc3, rc1); - - d_drop(child); - dput(child); - } - st_pass(); - - /* ---- d_drop: removes from parent children list ---- */ - st_begin("dcache: d_drop removes from parent"); - { - qstr name{}; - name.name = "dropme"; - name.len = 6; - name.hash = full_name_hash(name.name, name.len); - - dentry* child = d_alloc(g_root_dentry, &name); - ST_ASSERT(child != nullptr); - - /* Should be findable */ - dentry* f1 = d_lookup(g_root_dentry, &name); - ST_ASSERT(f1 != nullptr); - dput(f1); - - /* Drop it */ - d_drop(child); - - /* Should no longer be findable */ - dentry* f2 = d_lookup(g_root_dentry, &name); - ST_ASSERT(f2 == nullptr); - - dput(child); - } - st_pass(); - - /* ---- d_path: root returns "/" ---- */ - st_begin("dcache: d_path root returns /"); - { - path p{}; - p.de = g_root_dentry; - p.mnt = g_root_mnt; - - char buf[64]; - char* result = d_path(&p, buf, sizeof(buf)); - ST_ASSERT(result != nullptr); - ST_ASSERT(result[0] == '/'); - ST_ASSERT(result[1] == '\0'); - } - st_pass(); - - /* ---- d_path: child path ---- */ - st_begin("dcache: d_path child returns /name"); - { - qstr name{}; - name.name = "pathtest"; - name.len = 8; - name.hash = full_name_hash(name.name, name.len); - - dentry* child = d_alloc(g_root_dentry, &name); - ST_ASSERT(child != nullptr); - - path p{}; - p.de = child; - p.mnt = g_root_mnt; - - char buf[64]; - char* result = d_path(&p, buf, sizeof(buf)); - ST_ASSERT(result != nullptr); - - /* Should be "/pathtest" */ - const char* expected = "/pathtest"; - bool eq = true; - for (int i = 0; expected[i]; i++) { - if (result[i] != expected[i]) { eq = false; break; } - } - ST_ASSERT(eq); - - d_drop(child); - dput(child); - } - st_pass(); - - /* ---- d_alloc_anon: root-like dentry ---- */ - st_begin("dcache: d_alloc_anon"); - { - dentry* anon = d_alloc_anon(g_root_dentry->d_sb); - ST_ASSERT(anon != nullptr); - ST_ASSERT(anon->d_parent == anon); /* root: parent is self */ - ST_ASSERT(anon->d_sb == g_root_dentry->d_sb); - dput(anon); - } - st_pass(); - - /* ---- full_name_hash: deterministic ---- */ - st_begin("dcache: full_name_hash deterministic"); - { - uint32 h1 = full_name_hash("hello", 5); - uint32 h2 = full_name_hash("hello", 5); - ST_ASSERT_EQ(h1, h2); - - uint32 h3 = full_name_hash("world", 5); - ST_ASSERT_NE(h1, h3); - } - st_pass(); -} diff --git a/test/test_driver_model.cc b/test/test_driver_model.cc deleted file mode 100644 index 074a84e..0000000 --- a/test/test_driver_model.cc +++ /dev/null @@ -1,214 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_driver_model — exercises kref, kobject, and the bus/device/driver - * core. Uses a dummy bus + dummy driver + dummy device so the test is - * self-contained and doesn't depend on FDT/platform_device. - */ - -#include -#include -#include -#include -#include - -/* ------------------------------------------------------------------ */ -/* Test 1: kref get/put + release fires exactly once */ -/* ------------------------------------------------------------------ */ - -namespace { - -struct krefable { - kref ref; - int release_count; -}; - -void krefable_release(kref* r) -{ - auto* k = container_of(r, krefable, ref); - k->release_count++; -} - -void test_kref() -{ - st_begin("kref: init/get/put"); - - krefable k = {}; - kref_init(&k.ref); - - ST_ASSERT_EQ(kref_read(&k.ref), 1); - - kref_get(&k.ref); - kref_get(&k.ref); - ST_ASSERT_EQ(kref_read(&k.ref), 3); - - ST_ASSERT_EQ(kref_put(&k.ref, krefable_release), 0); - ST_ASSERT_EQ(kref_put(&k.ref, krefable_release), 0); - ST_ASSERT_EQ(k.release_count, 0); - - ST_ASSERT_EQ(kref_put(&k.ref, krefable_release), 1); - ST_ASSERT_EQ(k.release_count, 1); - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* Test 2: kobject parent/child + release on final put */ -/* ------------------------------------------------------------------ */ - -int g_child_released = 0; -int g_parent_released = 0; - -void child_release(kobject*) { g_child_released++; } -void parent_release(kobject*) { g_parent_released++; } - -const kobj_type child_ktype = { .release = child_release }; -const kobj_type parent_ktype = { .release = parent_release }; - -void test_kobject_hierarchy() -{ - st_begin("kobject: parent/child + ref counting"); - - g_child_released = 0; - g_parent_released = 0; - - kobject parent; - kobject_init(&parent, &parent_ktype); - - kobject child; - kobject_init(&child, &child_ktype); - kobject_add(&child, &parent, "child"); - - /* Adding child took a ref on parent. */ - ST_ASSERT_EQ(kref_read(&parent.refcount), 2); - ST_ASSERT(child.parent == &parent); - - /* Drop child's "added" reference — release should NOT fire because - * we (the test) still hold the original kobject_init ref. */ - kobject_del(&child); - ST_ASSERT(child.parent == nullptr); - ST_ASSERT_EQ(kref_read(&parent.refcount), 1); - ST_ASSERT_EQ(g_child_released, 0); - ST_ASSERT_EQ(g_parent_released, 0); - - /* Drop final refs. */ - kobject_put(&child); - ST_ASSERT_EQ(g_child_released, 1); - - kobject_put(&parent); - ST_ASSERT_EQ(g_parent_released, 1); - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* Test 3: bus / device / driver bind via match + probe */ -/* ------------------------------------------------------------------ */ - -struct dummy_dev { device dev; int probed; }; -struct dummy_drv { device_driver drv; const char* want; }; - -int g_probes = 0; - -int dummy_match(device* dev, device_driver* drv) -{ - auto* dd = container_of(drv, dummy_drv, drv); - return (dev->init_name != nullptr && - dd->want != nullptr && - __builtin_strcmp(dev->init_name, dd->want) == 0) ? 1 : 0; -} - -int dummy_probe(device* dev) -{ - auto* dd = container_of(dev, dummy_dev, dev); - dd->probed++; - g_probes++; - return 0; -} - -bus_type dummy_bus = { - .name = "test_dummy", - .match = dummy_match, - .probe = nullptr, /* fall through to drv->probe */ - .devices = {}, - .drivers = {}, - .lock = {}, - .registered = false, -}; - -void test_bus_bind() -{ - st_begin("driver model: bus / driver / device bind"); - - g_probes = 0; - ST_ASSERT_EQ(bus_register(&dummy_bus), 0); - - /* Register driver before any matching device exists. */ - dummy_drv drv_a = {}; - drv_a.drv.name = "drv_a"; - drv_a.drv.bus = &dummy_bus; - drv_a.drv.probe = dummy_probe; - drv_a.want = "compat_a"; - ST_ASSERT_EQ(driver_register(&drv_a.drv), 0); - - /* Register a device that should bind to drv_a immediately. */ - dummy_dev dev_a = {}; - dev_a.dev.bus = &dummy_bus; - dev_a.dev.init_name = "compat_a"; - ST_ASSERT_EQ(device_register(&dev_a.dev), 0); - ST_ASSERT_EQ(dev_a.probed, 1); - ST_ASSERT(dev_a.dev.driver == &drv_a.drv); - - /* Register a device first, then a driver — should also bind. */ - dummy_dev dev_b = {}; - dev_b.dev.bus = &dummy_bus; - dev_b.dev.init_name = "compat_b"; - ST_ASSERT_EQ(device_register(&dev_b.dev), 0); - ST_ASSERT_EQ(dev_b.probed, 0); - - dummy_drv drv_b = {}; - drv_b.drv.name = "drv_b"; - drv_b.drv.bus = &dummy_bus; - drv_b.drv.probe = dummy_probe; - drv_b.want = "compat_b"; - ST_ASSERT_EQ(driver_register(&drv_b.drv), 0); - ST_ASSERT_EQ(dev_b.probed, 1); - ST_ASSERT(dev_b.dev.driver == &drv_b.drv); - - /* Non-matching device sits unbound. */ - dummy_dev dev_c = {}; - dev_c.dev.bus = &dummy_bus; - dev_c.dev.init_name = "compat_unknown"; - ST_ASSERT_EQ(device_register(&dev_c.dev), 0); - ST_ASSERT_EQ(dev_c.probed, 0); - ST_ASSERT(dev_c.dev.driver == nullptr); - - ST_ASSERT_EQ(g_probes, 2); - - /* Cleanup. */ - device_unregister(&dev_a.dev); - device_unregister(&dev_b.dev); - device_unregister(&dev_c.dev); - driver_unregister(&drv_a.drv); - driver_unregister(&drv_b.drv); - - st_pass(); -} - -} // namespace - -/* ------------------------------------------------------------------ */ -/* Entry */ -/* ------------------------------------------------------------------ */ - -void selftest_driver_model() -{ - test_kref(); - test_kobject_hierarchy(); - test_bus_bind(); - - st_begin("driver model: platform IRQ chip probed"); - ST_ASSERT(g_irq_manager.get_chip() != nullptr); - st_pass(); -} diff --git a/test/test_exec.cc b/test/test_exec.cc deleted file mode 100644 index bbfa3b6..0000000 --- a/test/test_exec.cc +++ /dev/null @@ -1,447 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_exec.cc — Self-tests for execve / ELF loader - * - * Tests the ELF validation, binary loading, and user stack construction - * by creating synthetic ELF binaries in RamFS and invoking do_execve - * in a controlled environment. - * - * We cannot test the actual user-space transition (that requires - * sret to U-mode), but we CAN test everything up to and including - * the trapframe setup. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Extern: do_execve (kernel/exec.cc) */ -int do_execve(const char* pathname, const char* const* argv, - const char* const* envp); - -/* Extern: VFS file creation syscalls */ -int64 sys_openat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_write(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_close(uint64, uint64, uint64, uint64, uint64, uint64); - -/* ================================================================== */ -/* Helper: build a minimal valid RISC-V ELF64 in a buffer */ -/* ================================================================== */ - -struct TestElf { - Elf64_Ehdr ehdr; - Elf64_Phdr phdr; - uint8 code[16]; /* Tiny "program" — just a few NOPs */ -}; - -/* - * Build a minimal static ELF64 for RISC-V. - * Single PT_LOAD segment mapping the tiny code at 0x10000. - * Entry point = 0x10000 + offsetof(code). - */ -static void build_minimal_elf(TestElf* elf) -{ - /* Zero everything */ - for (uint64 i = 0; i < sizeof(*elf); i++) - reinterpret_cast(elf)[i] = 0; - - /* ELF header */ - Elf64_Ehdr* e = &elf->ehdr; - e->e_ident[EI_MAG0] = ELFMAG0; - e->e_ident[EI_MAG1] = ELFMAG1; - e->e_ident[EI_MAG2] = ELFMAG2; - e->e_ident[EI_MAG3] = ELFMAG3; - e->e_ident[EI_CLASS] = ELFCLASS64; - e->e_ident[EI_DATA] = ELFDATA2LSB; - e->e_ident[EI_VERSION] = 1; - e->e_type = ET_EXEC; - e->e_machine = EM_RISCV; - e->e_version = 1; - e->e_phoff = sizeof(Elf64_Ehdr); - e->e_phentsize = sizeof(Elf64_Phdr); - e->e_phnum = 1; - e->e_ehsize = sizeof(Elf64_Ehdr); - - /* Code section offset within the file */ - uint64 code_offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr); - - /* Entry point = vaddr of code */ - uint64 load_vaddr = 0x10000; - e->e_entry = load_vaddr + code_offset; - - /* Program header — single PT_LOAD covering entire file */ - Elf64_Phdr* p = &elf->phdr; - p->p_type = PT_LOAD; - p->p_flags = PF_R | PF_X; - p->p_offset = 0; - p->p_vaddr = load_vaddr; - p->p_paddr = load_vaddr; - p->p_filesz = sizeof(TestElf); - p->p_memsz = sizeof(TestElf); - p->p_align = 0x1000; - - /* Code: RISC-V "unimp" (all zeros = illegal instruction, but good enough for testing) */ - /* We just need the loader to succeed; we won't actually execute this. */ - elf->code[0] = 0x13; /* nop = addi x0, x0, 0 */ - elf->code[4] = 0x13; - elf->code[8] = 0x73; /* ebreak */ -} - -/* ================================================================== */ -/* Helper: write a buffer to a file in RamFS */ -/* ================================================================== */ - -static int create_test_file(const char* path, const void* data, uint64 size) -{ - /* Open with O_CREAT | O_WRONLY | O_TRUNC */ - int64 fd = sys_openat( - static_cast(-100), /* AT_FDCWD */ - reinterpret_cast(path), - O_CREAT | O_WRONLY | O_TRUNC, - 0755, 0, 0); - if (fd < 0) return static_cast(fd); - - int64 written = sys_write( - static_cast(fd), - reinterpret_cast(data), - size, 0, 0, 0); - - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - - if (written < 0) return static_cast(written); - if (static_cast(written) != size) return -EIO; - return 0; -} - -/* ================================================================== */ -/* Helper: ensure current task has VFS context for file ops */ -/* ================================================================== */ - -struct ExecTestCtx { - TaskControlBlock* curr; - VmSpace* old_mm; - arch::TrapFrame fake_tf; - arch::TrapFrame* old_tf; - uint64 saved_satp; -}; - -static void exec_test_setup(ExecTestCtx* ctx) -{ - ctx->curr = current_task(); - - /* Save kernel SATP so we can restore it in teardown */ - asm volatile("csrr %0, satp" : "=r"(ctx->saved_satp)); - - /* Save and replace mm with a fresh one */ - ctx->old_mm = ctx->curr->mm; - ctx->curr->mm = VmSpace::create(); - - /* Set up a fake trapframe so do_execve can modify it */ - for (uint64 i = 0; i < sizeof(ctx->fake_tf); i++) - reinterpret_cast(&ctx->fake_tf)[i] = 0; - ctx->old_tf = ctx->curr->trapframe; - ctx->curr->trapframe = &ctx->fake_tf; -} - -static void exec_test_teardown(ExecTestCtx* ctx) -{ - /* Restore trapframe */ - ctx->curr->trapframe = ctx->old_tf; - - /* Destroy the test mm (may have been replaced by do_execve) */ - VmSpace* test_mm = ctx->curr->mm; - ctx->curr->mm = ctx->old_mm; - if (test_mm && test_mm != ctx->old_mm) { - /* If do_execve succeeded, it activated new_mm's page table. - * Switch back to the kernel page table before destroying. */ - asm volatile("csrw satp, %0" :: "r"(ctx->saved_satp)); - asm volatile("sfence.vma"); - test_mm->put(); - } -} - -/* ================================================================== */ -/* Test cases */ -/* ================================================================== */ - -void selftest_exec() -{ - /* ---- 1a. Non-existent path under missing directory ---- */ - st_begin("exec: missing path returns error"); - { - const char* argv[] = { "/no_such_dir/no_file", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/no_such_dir/no_file", argv, envp); - ST_ASSERT(ret < 0); /* -ENOENT from filename_lookup */ - } - st_pass(); - - /* ---- 1b. Directory is not executable ---- */ - st_begin("exec: directory returns -EACCES"); - { - /* "/" exists and is a directory */ - const char* argv[] = { "/dev", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/dev", argv, envp); - ST_ASSERT_EQ(ret, -EACCES); - } - st_pass(); - - /* ---- 2. Bad ELF magic ---- */ - st_begin("exec: bad ELF magic returns -ENOEXEC"); - { - uint8 garbage[128]; - for (int i = 0; i < 128; i++) garbage[i] = 0xAA; - int err = create_test_file("/test_bad_magic", garbage, 128); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_bad_magic", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/test_bad_magic", argv, envp); - ST_ASSERT_EQ(ret, -ENOEXEC); - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 3. Wrong ELF class (32-bit) ---- */ - st_begin("exec: 32-bit ELF returns -ENOEXEC"); - { - TestElf elf; - build_minimal_elf(&elf); - elf.ehdr.e_ident[EI_CLASS] = 1; /* ELFCLASS32 */ - int err = create_test_file("/test_elf32", &elf, sizeof(elf)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_elf32", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/test_elf32", argv, envp); - ST_ASSERT_EQ(ret, -ENOEXEC); - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 4. Wrong endianness (big-endian) ---- */ - st_begin("exec: big-endian ELF returns -ENOEXEC"); - { - TestElf elf; - build_minimal_elf(&elf); - elf.ehdr.e_ident[EI_DATA] = 2; /* ELFDATA2MSB */ - int err = create_test_file("/test_be", &elf, sizeof(elf)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_be", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/test_be", argv, envp); - ST_ASSERT_EQ(ret, -ENOEXEC); - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 5. Wrong machine (x86_64 instead of RISC-V) ---- */ - st_begin("exec: wrong machine type returns -ENOEXEC"); - { - TestElf elf; - build_minimal_elf(&elf); - elf.ehdr.e_machine = 62; /* EM_X86_64 */ - int err = create_test_file("/test_x86", &elf, sizeof(elf)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_x86", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/test_x86", argv, envp); - ST_ASSERT_EQ(ret, -ENOEXEC); - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 6. Truncated ELF (too small for header) ---- */ - st_begin("exec: truncated ELF returns -ENOEXEC"); - { - /* Valid magic but file is too short for full header */ - uint8 tiny[8] = { 0x7f, 'E', 'L', 'F', 2, 1, 1, 0 }; - int err = create_test_file("/test_tiny", tiny, sizeof(tiny)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_tiny", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/test_tiny", argv, envp); - ST_ASSERT_EQ(ret, -ENOEXEC); - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 7. Zero program headers ---- */ - st_begin("exec: zero phnum returns -ENOEXEC"); - { - TestElf elf; - build_minimal_elf(&elf); - elf.ehdr.e_phnum = 0; - int err = create_test_file("/test_nophdr", &elf, sizeof(elf)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_nophdr", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/test_nophdr", argv, envp); - ST_ASSERT_EQ(ret, -ENOEXEC); - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 8. Valid ELF: successful load and trapframe setup ---- */ - st_begin("exec: valid ELF loads and sets up trapframe"); - { - TestElf elf; - build_minimal_elf(&elf); - int err = create_test_file("/test_valid", &elf, sizeof(elf)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_valid", nullptr }; - const char* envp[] = { "HOME=/", nullptr }; - int ret = do_execve("/test_valid", argv, envp); - ST_ASSERT_EQ(ret, 0); - - /* Verify trapframe was set up correctly */ - arch::TrapFrame* tf = &ctx.fake_tf; - - /* Entry point should match what we set in the ELF */ - uint64 code_offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr); - uint64 expected_entry = 0x10000 + code_offset; - ST_ASSERT_EQ(tf->epc, expected_entry); - - /* Stack pointer should be in user space, below the stack top */ - ST_ASSERT(tf->sp > 0); - ST_ASSERT(tf->sp < kUserStackTop); - ST_ASSERT(tf->sp >= kUserStackBase); - - /* sstatus: SPP=0 (U-mode), SPIE=1 (interrupts enabled on sret) */ - uint64 spp_bit = (1ULL << 8); - uint64 spie_bit = (1ULL << 5); - ST_ASSERT_EQ(tf->sstatus & spp_bit, 0ULL); /* Not S-mode */ - ST_ASSERT_EQ(tf->sstatus & spie_bit, spie_bit); /* SPIE set */ - - /* General registers should be zeroed */ - ST_ASSERT_EQ(tf->ra, 0ULL); - ST_ASSERT_EQ(tf->gp, 0ULL); - ST_ASSERT_EQ(tf->tp, 0ULL); - for (int i = 0; i < 7; i++) - ST_ASSERT_EQ(tf->t[i], 0ULL); - for (int i = 0; i < 12; i++) - ST_ASSERT_EQ(tf->s[i], 0ULL); - for (int i = 0; i < 8; i++) - ST_ASSERT_EQ(tf->a[i], 0ULL); - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 9. Verify user stack layout (argc/argv) ---- */ - st_begin("exec: user stack has correct argc/argv layout"); - { - TestElf elf; - build_minimal_elf(&elf); - int err = create_test_file("/test_stack", &elf, sizeof(elf)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - const char* argv[] = { "/test_stack", "arg1", nullptr }; - const char* envp[] = { "A=B", nullptr }; - int ret = do_execve("/test_stack", argv, envp); - ST_ASSERT_EQ(ret, 0); - - /* The stack was set up in the new mm. - * Read argc from the top of the stack using pmap lookup. */ - VmSpace* mm = ctx.curr->mm; - uint64 sp = ctx.fake_tf.sp; - - /* Look up the physical page for sp */ - uint64 pa = 0; - bool mapped = pmap::lookup(mm->root_pa, sp & ~(kPageSize - 1), &pa); - ST_ASSERT(mapped); - - /* Read argc (first uint64 on stack) */ - uint64 page_offset = sp & (kPageSize - 1); - uint8* kva = reinterpret_cast(pa_to_va(PhysAddr{pa}).raw); - uint64 argc = *reinterpret_cast(kva + page_offset); - ST_ASSERT_EQ(argc, 2ULL); /* "/test_stack" and "arg1" */ - - exec_test_teardown(&ctx); - } - st_pass(); - - /* ---- 10. Multiple consecutive execve replaces mm correctly ---- */ - st_begin("exec: consecutive execve replaces address space"); - { - TestElf elf; - build_minimal_elf(&elf); - int err = create_test_file("/test_reexec", &elf, sizeof(elf)); - ST_ASSERT_EQ(err, 0); - - ExecTestCtx ctx; - exec_test_setup(&ctx); - - /* First exec */ - const char* argv[] = { "/test_reexec", nullptr }; - const char* envp[] = { nullptr }; - int ret = do_execve("/test_reexec", argv, envp); - ST_ASSERT_EQ(ret, 0); - - VmSpace* first_mm = ctx.curr->mm; - ST_ASSERT(first_mm != nullptr); - - /* Second exec — should replace the first mm */ - ret = do_execve("/test_reexec", argv, envp); - ST_ASSERT_EQ(ret, 0); - - /* mm should be different (new address space) */ - VmSpace* second_mm = ctx.curr->mm; - ST_ASSERT(second_mm != nullptr); - ST_ASSERT_NE(first_mm, second_mm); - - exec_test_teardown(&ctx); - } - st_pass(); -} diff --git a/test/test_fdt.cc b/test/test_fdt.cc deleted file mode 100644 index cf09029..0000000 --- a/test/test_fdt.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test: FDT (Flattened Device Tree) - */ - -#include -#include - -// Manually declare what we need to avoid header conflicts with toolchain libc -extern "C" int strcmp(const char *s1, const char *s2); - -void selftest_fdt() { - st_begin("fdt: tree root access"); - { - DeviceNode* root = fdt_get_node_by_path("/"); - ST_ASSERT(root != nullptr); - ST_ASSERT_EQ(strcmp(root->get_name(), ""), 0); - } - st_pass(); - - st_begin("fdt: find existing compatible node (UART)"); - { - // QEMU virt RISC-V platform always has a ns16550a UART - DeviceNode* uart = fdt_find_compatible("ns16550a"); - ST_ASSERT(uart != nullptr); - - // Use get_prop_string which is convenience helper - const char* compat = uart->get_prop_string("compatible"); - ST_ASSERT(compat != nullptr); - - // Check raw property access - const FdtProperty* reg = uart->get_prop("reg"); - ST_ASSERT(reg != nullptr); - ST_ASSERT(reg->value != nullptr); - ST_ASSERT(reg->len > 0); - } - st_pass(); - - st_begin("fdt: non-existent node/compatible queries"); - { - DeviceNode* missing1 = fdt_get_node_by_path("/definitely_does_not_exist_node_12345"); - ST_ASSERT(missing1 == nullptr); - - DeviceNode* missing2 = fdt_find_compatible("invalid_compatible_string_xyz"); - ST_ASSERT(missing2 == nullptr); - } - st_pass(); -} diff --git a/test/test_klog.cc b/test/test_klog.cc deleted file mode 100644 index 896e7ed..0000000 --- a/test/test_klog.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test: klog - * - * Tests: - * 1. read vs read_consume semantics - * 2. subsystem mask filtering - * 3. ratelimit bookkeeping - * 4. flush advances console tail when console filtering is active - * 5. seq counter increments on writes - */ - -#include -#include -#include - -static void drain_klog() -{ - static char buf[512]; - while (true) { - int n = klog_read_consume(buf, sizeof(buf)); - if (n <= 0) { - break; - } - } -} - -static bool test_read_peek_and_consume() -{ - drain_klog(); - - klog_ex(KLOG_INFO, KLOG_SUBSYS_TEST, "klog_test_a"); - klog_ex(KLOG_INFO, KLOG_SUBSYS_TEST, "klog_test_b"); - - KlogStats s0; - klog_stats(&s0); - - char buf[1024]; - int n = klog_read(buf, sizeof(buf) - 1); - if (n <= 0) { - return false; - } - buf[n] = '\0'; - if (!strstr(buf, "klog_test_a") || !strstr(buf, "klog_test_b")) { - return false; - } - - KlogStats s1; - klog_stats(&s1); - if (s1.tail != s0.tail) { - return false; - } - - int n2 = klog_read_consume(buf, sizeof(buf) - 1); - if (n2 <= 0) { - return false; - } - buf[n2] = '\0'; - if (!strstr(buf, "klog_test_a") || !strstr(buf, "klog_test_b")) { - return false; - } - - KlogStats s2; - klog_stats(&s2); - return s2.tail != s0.tail; -} - -static bool test_subsys_mask() -{ - drain_klog(); - - const uint64 all_mask = (1ULL << KLOG_SUBSYS_MAX) - 1; - klog_set_subsys_mask(1ULL << KLOG_SUBSYS_TEST); - - klog_ex(KLOG_INFO, KLOG_SUBSYS_TEST, "klog_subsys_ok"); - klog_ex(KLOG_INFO, KLOG_SUBSYS_GENERIC, "klog_subsys_drop"); - - char buf[1024]; - int n = klog_read_consume(buf, sizeof(buf) - 1); - klog_set_subsys_mask(all_mask); - - if (n <= 0) { - return false; - } - buf[n] = '\0'; - return strstr(buf, "klog_subsys_ok") && !strstr(buf, "klog_subsys_drop"); -} - -static bool test_ratelimit() -{ - KlogRateLimit rl = {}; - rl.interval = 100; - rl.burst = 2; - - bool a = klog_ratelimit(&rl, 10); - bool b = klog_ratelimit(&rl, 20); - bool c = klog_ratelimit(&rl, 30); - - if (!a || !b || c) { - return false; - } - if (rl.printed != 2 || rl.suppressed != 1) { - return false; - } - - bool d = klog_ratelimit(&rl, 200); - if (!d) { - return false; - } - return rl.printed == 1 && rl.suppressed == 0; -} - -static bool test_flush_advances_console_tail() -{ - drain_klog(); - - klog_set_level(KLOG_ERR); - klog_ex(KLOG_INFO, KLOG_SUBSYS_TEST, "klog_flush_msg"); - - KlogStats s1; - klog_stats(&s1); - if (s1.console_tail == s1.head) { - klog_set_level(static_cast(KLOG_DEFAULT_LEVEL)); - return false; - } - - klog_flush(); - - KlogStats s2; - klog_stats(&s2); - - klog_set_level(static_cast(KLOG_DEFAULT_LEVEL)); - return s2.console_tail == s2.head; -} - -static bool test_seq_increments() -{ - drain_klog(); - - KlogStats s0; - klog_stats(&s0); - - klog_ex(KLOG_INFO, KLOG_SUBSYS_TEST, "klog_seq_1"); - klog_ex(KLOG_INFO, KLOG_SUBSYS_TEST, "klog_seq_2"); - - KlogStats s1; - klog_stats(&s1); - - return s1.seq >= s0.seq + 2; -} - -void selftest_klog() -{ - st_begin("klog: read vs read_consume"); - ST_ASSERT(test_read_peek_and_consume()); - st_pass(); - - st_begin("klog: subsys mask filters"); - ST_ASSERT(test_subsys_mask()); - st_pass(); - - st_begin("klog: ratelimit bookkeeping"); - ST_ASSERT(test_ratelimit()); - st_pass(); - - st_begin("klog: flush advances console tail"); - ST_ASSERT(test_flush_advances_console_tail()); - st_pass(); - - st_begin("klog: seq increments on write"); - ST_ASSERT(test_seq_increments()); - st_pass(); -} diff --git a/test/test_mutex.cc b/test/test_mutex.cc deleted file mode 100644 index e86c984..0000000 --- a/test/test_mutex.cc +++ /dev/null @@ -1,183 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_mutex — self-tests for the Mutex sleeping lock. - * - * Coverage: - * - basic lock/unlock single-thread - * - try_lock when free and when held - * - mutual exclusion across kthreads (no lost increments) - * - FIFO wake order (A acquires, B/C queue; release lets B in then C) - */ - -#include -#include -#include -#include -#include - -extern TaskControlBlock* kthread_create(const char* name, - void (*entry)(void*), void* arg, - uint8 priority); -extern void task_exit(int code); - -/* ------------------------------------------------------------------ */ -/* Test 1: basic lock/unlock */ -/* ------------------------------------------------------------------ */ - -static void test_basic() -{ - st_begin("mutex: basic lock/unlock"); - - Mutex m; - m.init("test_basic"); - - ST_ASSERT(!m.is_locked()); - m.lock(); - ST_ASSERT(m.is_locked()); - ST_ASSERT(m.is_owned_by_current()); - m.unlock(); - ST_ASSERT(!m.is_locked()); - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* Test 2: try_lock */ -/* ------------------------------------------------------------------ */ - -static void test_trylock() -{ - st_begin("mutex: try_lock"); - - Mutex m; - m.init("test_trylock"); - - ST_ASSERT(m.try_lock() == true); - ST_ASSERT(m.is_locked()); - - /* A second try_lock from the same task: since owner == current, - * we still return false (try_lock is non-recursive). */ - ST_ASSERT(m.try_lock() == false); - - m.unlock(); - ST_ASSERT(!m.is_locked()); - ST_ASSERT(m.try_lock() == true); - m.unlock(); - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* Test 3: mutual exclusion across kthreads */ -/* ------------------------------------------------------------------ */ - -static Mutex g_mut; -static volatile int32 g_counter = 0; -static volatile int32 g_done = 0; -static constexpr int32 kIters = 200; - -static void mutex_worker(void*) -{ - for (int i = 0; i < kIters; i++) { - g_mut.lock(); - int32 v = g_counter; - /* Yield inside the critical section to expose missing mutex. - * If the mutex were broken we'd see lost increments. */ - sched_yield(); - g_counter = v + 1; - g_mut.unlock(); - } - __sync_fetch_and_add(&g_done, 1); - task_exit(0); -} - -static void test_mutual_exclusion() -{ - st_begin("mutex: mutual exclusion (2 workers)"); - - g_mut.init("test_mutex_mx"); - g_counter = 0; - g_done = 0; - - kthread_create("mut_w1", mutex_worker, nullptr, 0); - kthread_create("mut_w2", mutex_worker, nullptr, 0); - - /* Spin-yield until both workers finish. */ - while (g_done < 2) { - sched_yield(); - } - - ST_ASSERT_EQ(g_counter, 2 * kIters); - ST_ASSERT(!g_mut.is_locked()); - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* Test 4: FIFO wake order */ -/* ------------------------------------------------------------------ */ - -static Mutex g_fifo_mut; -static volatile int32 g_fifo_seq = 0; // monotonically increases -static volatile int32 g_fifo_order[3]; // order each worker observed -static volatile int32 g_fifo_done = 0; - -static void fifo_worker(void* arg) -{ - int slot = static_cast(reinterpret_cast(arg)); - g_fifo_mut.lock(); - g_fifo_order[slot] = __sync_fetch_and_add(&g_fifo_seq, 1); - g_fifo_mut.unlock(); - __sync_fetch_and_add(&g_fifo_done, 1); - task_exit(0); -} - -static void test_fifo_order() -{ - st_begin("mutex: FIFO wake order (3 waiters)"); - - g_fifo_mut.init("test_mutex_fifo"); - g_fifo_seq = 0; - g_fifo_done = 0; - g_fifo_order[0] = g_fifo_order[1] = g_fifo_order[2] = -1; - - /* Main grabs the lock first so workers will queue up behind. */ - g_fifo_mut.lock(); - - /* Spawn workers in deterministic order. After each create() yield - * once so the new thread reaches mutex.lock() and enqueues itself - * before we spawn the next one. */ - kthread_create("fifo_A", fifo_worker, reinterpret_cast(0), 0); - sched_yield(); - kthread_create("fifo_B", fifo_worker, reinterpret_cast(1), 0); - sched_yield(); - kthread_create("fifo_C", fifo_worker, reinterpret_cast(2), 0); - sched_yield(); - - /* Release: A should fire next, then B, then C. */ - g_fifo_mut.unlock(); - - while (g_fifo_done < 3) { - sched_yield(); - } - - ST_ASSERT_EQ(g_fifo_order[0], 0); - ST_ASSERT_EQ(g_fifo_order[1], 1); - ST_ASSERT_EQ(g_fifo_order[2], 2); - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* Entry */ -/* ------------------------------------------------------------------ */ - -void selftest_mutex() -{ - test_basic(); - test_trylock(); - test_mutual_exclusion(); - test_fifo_order(); -} diff --git a/test/test_namei.cc b/test/test_namei.cc deleted file mode 100644 index 8e4ecb0..0000000 --- a/test/test_namei.cc +++ /dev/null @@ -1,173 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_namei.cc — Self-tests for pathname resolution (namei.cc) - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern dentry* g_root_dentry; -extern vfsmount* g_root_mnt; - -/* sys_mkdirat from kernel/sys_fs.cc */ -int64 sys_mkdirat(uint64, uint64, uint64, uint64, uint64, uint64); - -void selftest_namei() -{ - /* ---- lookup root "/" ---- */ - st_begin("namei: lookup root /"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/", 0, &p); - ST_ASSERT_EQ(err, 0); - ST_ASSERT(p.de == g_root_dentry); - ST_ASSERT(p.de->d_inode != nullptr); - ST_ASSERT(S_ISDIR(p.de->d_inode->i_mode)); - } - st_pass(); - - /* ---- lookup /dev (exists from boot) ---- */ - st_begin("namei: lookup /dev"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/dev", 0, &p); - ST_ASSERT_EQ(err, 0); - ST_ASSERT(p.de != nullptr); - ST_ASSERT(p.de->d_inode != nullptr); - ST_ASSERT(S_ISDIR(p.de->d_inode->i_mode)); - } - st_pass(); - - /* ---- lookup nonexistent path returns -ENOENT ---- */ - st_begin("namei: lookup nonexistent returns -ENOENT"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/this_does_not_exist", 0, &p); - ST_ASSERT_EQ(err, -ENOENT); - } - st_pass(); - - /* ---- lookup /dev/console (chardev) ---- */ - st_begin("namei: lookup /dev/console"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/dev/console", 0, &p); - ST_ASSERT_EQ(err, 0); - ST_ASSERT(p.de->d_inode != nullptr); - ST_ASSERT(S_ISCHR(p.de->d_inode->i_mode)); - } - st_pass(); - - /* ---- lookup with LOOKUP_DIRECTORY on non-dir returns -ENOTDIR ---- */ - st_begin("namei: LOOKUP_DIRECTORY on file returns -ENOTDIR"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/dev/console", LOOKUP_DIRECTORY, &p); - ST_ASSERT_EQ(err, -ENOTDIR); - } - st_pass(); - - /* ---- lookup with LOOKUP_DIRECTORY on dir succeeds ---- */ - st_begin("namei: LOOKUP_DIRECTORY on dir succeeds"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/dev", LOOKUP_DIRECTORY, &p); - ST_ASSERT_EQ(err, 0); - ST_ASSERT(S_ISDIR(p.de->d_inode->i_mode)); - } - st_pass(); - - /* ---- kern_path shortcut ---- */ - st_begin("namei: kern_path works like filename_lookup"); - { - path p{}; - int err = kern_path("/dev", 0, &p); - ST_ASSERT_EQ(err, 0); - ST_ASSERT(p.de->d_inode != nullptr); - } - st_pass(); - - /* ---- dot path: /dev/. resolves to /dev ---- */ - st_begin("namei: /dev/. resolves to /dev"); - { - path p1{}, p2{}; - int e1 = filename_lookup(AT_FDCWD, "/dev", 0, &p1); - int e2 = filename_lookup(AT_FDCWD, "/dev/.", 0, &p2); - ST_ASSERT_EQ(e1, 0); - ST_ASSERT_EQ(e2, 0); - ST_ASSERT(p1.de == p2.de); - } - st_pass(); - - /* ---- dotdot path: /dev/.. resolves to root ---- */ - st_begin("namei: /dev/.. resolves to root"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/dev/..", 0, &p); - ST_ASSERT_EQ(err, 0); - ST_ASSERT(p.de == g_root_dentry); - } - st_pass(); - - /* ---- lookup into non-dir returns -ENOTDIR ---- */ - st_begin("namei: path through non-dir returns -ENOTDIR"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/dev/console/child", 0, &p); - ST_ASSERT_EQ(err, -ENOTDIR); - } - st_pass(); - - /* ---- null/empty paths ---- */ - st_begin("namei: null name returns -EINVAL"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, nullptr, 0, &p); - ST_ASSERT_EQ(err, -EINVAL); - } - st_pass(); - - /* ---- LOOKUP_PARENT: returns parent dentry ---- */ - st_begin("namei: LOOKUP_PARENT returns parent"); - { - path p{}; - int err = filename_lookup(AT_FDCWD, "/dev/console", LOOKUP_PARENT, &p); - ST_ASSERT_EQ(err, 0); - /* Should return /dev, not /dev/console */ - path dev_path{}; - int e2 = filename_lookup(AT_FDCWD, "/dev", 0, &dev_path); - ST_ASSERT_EQ(e2, 0); - ST_ASSERT(p.de == dev_path.de); - } - st_pass(); - - /* ---- mkdir + lookup round-trip ---- */ - st_begin("namei: mkdir then lookup succeeds"); - { - /* Create /test_namei_dir via sys_mkdirat */ - int64 ret = sys_mkdirat( - static_cast(-100), - reinterpret_cast("/test_namei_dir"), - 0755, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - - /* Now lookup should find it */ - path p{}; - int err = filename_lookup(AT_FDCWD, "/test_namei_dir", 0, &p); - ST_ASSERT_EQ(err, 0); - ST_ASSERT(p.de->d_inode != nullptr); - ST_ASSERT(S_ISDIR(p.de->d_inode->i_mode)); - } - st_pass(); - - /* NOTE: trailing slash "/dev/" not tested — Phase 1 namei - * doesn't handle empty trailing components. */ -} diff --git a/test/test_page_cache.cc b/test/test_page_cache.cc deleted file mode 100644 index ee0e0e2..0000000 --- a/test/test_page_cache.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_page_cache.cc — Self-tests for the page cache hash table - * - * Tests: insert, get, remove, duplicate insert, invalidate, - * get_or_alloc, null args. - */ - -#include -#include -#include -#include -#include - -void selftest_page_cache() -{ - /* Use sentinel pointers as fake "mapping" identifiers. - * These are never dereferenced — only used as hash keys. */ - int mapping_a_tag = 0; - int mapping_b_tag = 0; - void* mapping_a = &mapping_a_tag; - void* mapping_b = &mapping_b_tag; - - /* ---- insert and get ---- */ - st_begin("page_cache: insert then get returns same page"); - { - Page* page = pmm_alloc_page(); - ST_ASSERT(page != nullptr); - - int ret = page_cache_insert(mapping_a, 0, page); - ST_ASSERT_EQ(ret, 0); - - Page* got = page_cache_get(mapping_a, 0); - ST_ASSERT_EQ(got, page); - - /* put the reference from get */ - page_cache_put(got); - - /* Clean up */ - page_cache_remove(mapping_a, 0); - pmm_free_page(page); - } - st_pass(); - - /* ---- get nonexistent returns nullptr ---- */ - st_begin("page_cache: get nonexistent returns nullptr"); - { - Page* got = page_cache_get(mapping_a, 99999); - ST_ASSERT(got == nullptr); - } - st_pass(); - - /* ---- duplicate insert returns -EEXIST ---- */ - st_begin("page_cache: duplicate insert returns -EEXIST"); - { - Page* page = pmm_alloc_page(); - ST_ASSERT(page != nullptr); - - int ret1 = page_cache_insert(mapping_a, 1, page); - ST_ASSERT_EQ(ret1, 0); - - Page* page2 = pmm_alloc_page(); - ST_ASSERT(page2 != nullptr); - - int ret2 = page_cache_insert(mapping_a, 1, page2); - ST_ASSERT_EQ(ret2, -EEXIST); - - /* Clean up */ - page_cache_remove(mapping_a, 1); - pmm_free_page(page); - pmm_free_page(page2); - } - st_pass(); - - /* ---- remove returns page ---- */ - st_begin("page_cache: remove returns page and deletes entry"); - { - Page* page = pmm_alloc_page(); - ST_ASSERT(page != nullptr); - - page_cache_insert(mapping_a, 2, page); - - Page* removed = page_cache_remove(mapping_a, 2); - ST_ASSERT_EQ(removed, page); - - /* Should be gone now */ - Page* got = page_cache_get(mapping_a, 2); - ST_ASSERT(got == nullptr); - - pmm_free_page(page); - } - st_pass(); - - /* ---- remove nonexistent returns nullptr ---- */ - st_begin("page_cache: remove nonexistent returns nullptr"); - { - Page* got = page_cache_remove(mapping_a, 77777); - ST_ASSERT(got == nullptr); - } - st_pass(); - - /* ---- different mappings are independent ---- */ - st_begin("page_cache: different mappings are independent"); - { - Page* pa = pmm_alloc_page(); - Page* pb = pmm_alloc_page(); - ST_ASSERT(pa != nullptr); - ST_ASSERT(pb != nullptr); - - page_cache_insert(mapping_a, 5, pa); - page_cache_insert(mapping_b, 5, pb); - - Page* got_a = page_cache_get(mapping_a, 5); - Page* got_b = page_cache_get(mapping_b, 5); - ST_ASSERT_EQ(got_a, pa); - ST_ASSERT_EQ(got_b, pb); - ST_ASSERT_NE(got_a, got_b); - - page_cache_put(got_a); - page_cache_put(got_b); - page_cache_remove(mapping_a, 5); - page_cache_remove(mapping_b, 5); - pmm_free_page(pa); - pmm_free_page(pb); - } - st_pass(); - - /* ---- invalidate removes all entries for a mapping ---- */ - st_begin("page_cache: invalidate removes all entries for mapping"); - { - Page* pages[4]; - for (int i = 0; i < 4; i++) { - pages[i] = pmm_alloc_page(); - ST_ASSERT(pages[i] != nullptr); - page_cache_insert(mapping_a, 10 + i, pages[i]); - } - - /* Also insert one for mapping_b */ - Page* pb = pmm_alloc_page(); - page_cache_insert(mapping_b, 10, pb); - - /* Invalidate mapping_a */ - page_cache_invalidate(mapping_a); - - /* All mapping_a entries should be gone */ - for (int i = 0; i < 4; i++) { - Page* got = page_cache_get(mapping_a, 10 + i); - ST_ASSERT(got == nullptr); - pmm_free_page(pages[i]); - } - - /* mapping_b should still be there */ - Page* got_b = page_cache_get(mapping_b, 10); - ST_ASSERT_EQ(got_b, pb); - page_cache_put(got_b); - page_cache_remove(mapping_b, 10); - pmm_free_page(pb); - } - st_pass(); - - /* ---- insert null mapping returns -EINVAL ---- */ - st_begin("page_cache: insert null mapping returns -EINVAL"); - { - Page* page = pmm_alloc_page(); - int ret = page_cache_insert(nullptr, 0, page); - ST_ASSERT_EQ(ret, -EINVAL); - pmm_free_page(page); - } - st_pass(); - - /* ---- insert null page returns -EINVAL ---- */ - st_begin("page_cache: insert null page returns -EINVAL"); - { - int ret = page_cache_insert(mapping_a, 0, nullptr); - ST_ASSERT_EQ(ret, -EINVAL); - } - st_pass(); -} diff --git a/test/test_pid.cc b/test/test_pid.cc deleted file mode 100644 index e79eb1e..0000000 --- a/test/test_pid.cc +++ /dev/null @@ -1,106 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_pid.cc — Self-tests for PID allocator - * - * Tests: alloc, free, re-use, exhaustion guard, reserved PIDs. - */ - -#include -#include - -void selftest_pid() -{ - /* Create a local PidAllocator for isolated testing */ - PidAllocator pa; - pa.init(); - - /* ---- PID 0 is reserved (idle/swapper) ---- */ - st_begin("pid: PID 0 is reserved"); - { - /* First alloc should return 1 (PID 0 reserved for idle) */ - int32 first = pa.alloc(); - ST_ASSERT(first >= 1); - } - st_pass(); - - /* ---- Sequential allocation returns unique PIDs ---- */ - st_begin("pid: sequential allocation returns unique PIDs"); - { - PidAllocator pa2; - pa2.init(); - - int32 p1 = pa2.alloc(); - int32 p2 = pa2.alloc(); - int32 p3 = pa2.alloc(); - ST_ASSERT(p1 >= 1); - ST_ASSERT(p2 >= 1); - ST_ASSERT(p3 >= 1); - ST_ASSERT_NE(p1, p2); - ST_ASSERT_NE(p2, p3); - ST_ASSERT_NE(p1, p3); - } - st_pass(); - - /* ---- Freed PID can be reused ---- */ - st_begin("pid: freed PID can be reused"); - { - PidAllocator pa3; - pa3.init(); - - /* Allocate all PIDs from 2..N */ - constexpr int kAllocCount = 60; - int32 pids[kAllocCount]; - for (int i = 0; i < kAllocCount; i++) { - pids[i] = pa3.alloc(); - ST_ASSERT(pids[i] >= 1); - } - - /* Free one in the middle */ - int32 freed_pid = pids[kAllocCount / 2]; - pa3.free(freed_pid); - - /* Allocate again — should eventually get the freed PID */ - bool found = false; - for (int i = 0; i < kAllocCount; i++) { - int32 p = pa3.alloc(); - if (p == freed_pid) { found = true; break; } - pa3.free(p); - } - ST_ASSERT(found); - } - st_pass(); - - /* ---- free invalid PID is safe ---- */ - st_begin("pid: free invalid PID is no-op"); - { - PidAllocator pa4; - pa4.init(); - - /* These should not crash */ - pa4.free(-1); - pa4.free(kMaxPid); - pa4.free(kMaxPid + 100); - - /* Allocator should still work — PID 0 still reserved */ - int32 p = pa4.alloc(); - ST_ASSERT(p >= 1); - } - st_pass(); - - /* ---- Monotonic allocation before wrap ---- */ - st_begin("pid: monotonic allocation"); - { - PidAllocator pa5; - pa5.init(); - - int32 prev = pa5.alloc(); - for (int i = 0; i < 10; i++) { - int32 next = pa5.alloc(); - ST_ASSERT(next > prev); - prev = next; - } - } - st_pass(); -} diff --git a/test/test_pipe_devfs.cc b/test/test_pipe_devfs.cc deleted file mode 100644 index ed375ed..0000000 --- a/test/test_pipe_devfs.cc +++ /dev/null @@ -1,420 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_pipe_devfs.cc — Self-tests for pipe, /dev/null, /dev/zero, fcntl - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* Syscall entry points */ -int64 sys_openat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_close(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_read(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_write(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_pipe2(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_fcntl(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_fstat_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); - -/* ================================================================== */ -/* Helpers */ -/* ================================================================== */ - -static int64 open_dev(const char* path, int flags) -{ - return sys_openat( - static_cast(-100), /* AT_FDCWD */ - reinterpret_cast(path), - static_cast(flags), - 0, 0, 0); -} - -static int64 do_close(int64 fd) -{ - return sys_close(static_cast(fd), 0, 0, 0, 0, 0); -} - -static int64 do_read(int64 fd, void* buf, uint64 count) -{ - return sys_read(static_cast(fd), - reinterpret_cast(buf), count, 0, 0, 0); -} - -static int64 do_write(int64 fd, const void* buf, uint64 count) -{ - return sys_write(static_cast(fd), - reinterpret_cast(buf), count, 0, 0, 0); -} - -/* fcntl command constants — must match sys_fs.cc */ -inline constexpr int F_DUPFD = 0; -inline constexpr int F_GETFD = 1; -inline constexpr int F_SETFD = 2; -inline constexpr int F_GETFL = 3; -inline constexpr int F_SETFL = 4; -inline constexpr int F_DUPFD_CLOEXEC = 1030; -inline constexpr int FD_CLOEXEC = 1; - -/* ================================================================== */ -/* /dev/null tests */ -/* ================================================================== */ - -void selftest_devfs() -{ - /* ---- /dev/null: read returns EOF ---- */ - st_begin("devfs: /dev/null read returns 0 (EOF)"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - char buf[16]; - int64 n = do_read(fd, buf, sizeof(buf)); - ST_ASSERT_EQ(n, (int64)0); - do_close(fd); - } - st_pass(); - - /* ---- /dev/null: write discards data ---- */ - st_begin("devfs: /dev/null write discards data"); - { - int64 fd = open_dev("/dev/null", O_WRONLY); - ST_ASSERT(fd >= 0); - - const char* msg = "discarded"; - int64 n = do_write(fd, msg, 9); - ST_ASSERT_EQ(n, (int64)9); - do_close(fd); - } - st_pass(); - - /* ---- /dev/null: fstat reports S_IFCHR ---- */ - st_begin("devfs: /dev/null fstat is S_IFCHR"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - kstat st{}; - int64 ret = sys_fstat_wrapper( - static_cast(fd), - reinterpret_cast(&st), 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - ST_ASSERT(S_ISCHR(st.st_mode)); - do_close(fd); - } - st_pass(); - - /* ---- /dev/zero: read returns zeros ---- */ - st_begin("devfs: /dev/zero read returns zeros"); - { - int64 fd = open_dev("/dev/zero", O_RDONLY); - ST_ASSERT(fd >= 0); - - char buf[32]; - /* Pre-fill with non-zero */ - for (int i = 0; i < 32; i++) buf[i] = 0xFF; - - int64 n = do_read(fd, buf, 32); - ST_ASSERT_EQ(n, (int64)32); - - bool all_zero = true; - for (int i = 0; i < 32; i++) { - if (buf[i] != 0) { all_zero = false; break; } - } - ST_ASSERT(all_zero); - do_close(fd); - } - st_pass(); - - /* ---- /dev/zero: write discards data ---- */ - st_begin("devfs: /dev/zero write discards data"); - { - int64 fd = open_dev("/dev/zero", O_WRONLY); - ST_ASSERT(fd >= 0); - - char buf[16] = {1, 2, 3}; - int64 n = do_write(fd, buf, 16); - ST_ASSERT_EQ(n, (int64)16); - do_close(fd); - } - st_pass(); -} - -/* ================================================================== */ -/* Pipe tests */ -/* ================================================================== */ - -void selftest_pipe() -{ - /* ---- pipe2: basic creation ---- */ - st_begin("pipe: pipe2 creates two valid fds"); - { - int fds[2] = {-1, -1}; - int64 ret = sys_pipe2( - reinterpret_cast(fds), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - ST_ASSERT(fds[0] >= 0); - ST_ASSERT(fds[1] >= 0); - ST_ASSERT_NE(fds[0], fds[1]); - - do_close(fds[0]); - do_close(fds[1]); - } - st_pass(); - - /* ---- pipe: write then read ---- */ - st_begin("pipe: write then read returns correct data"); - { - int fds[2]; - sys_pipe2(reinterpret_cast(fds), 0, 0, 0, 0, 0); - - const char* msg = "pipe_test"; - int64 w = do_write(fds[1], msg, 9); - ST_ASSERT_EQ(w, (int64)9); - - char buf[16] = {}; - int64 r = do_read(fds[0], buf, 16); - ST_ASSERT_EQ(r, (int64)9); - - bool match = true; - for (int i = 0; i < 9; i++) { - if (buf[i] != msg[i]) { match = false; break; } - } - ST_ASSERT(match); - - do_close(fds[0]); - do_close(fds[1]); - } - st_pass(); - - /* ---- pipe: read from closed write end returns EOF ---- */ - st_begin("pipe: read after writer close returns EOF"); - { - int fds[2]; - sys_pipe2(reinterpret_cast(fds), 0, 0, 0, 0, 0); - - /* Write some data, then close write end */ - const char* msg = "eof"; - do_write(fds[1], msg, 3); - do_close(fds[1]); - - /* Read the data */ - char buf[16]; - int64 r1 = do_read(fds[0], buf, 16); - ST_ASSERT_EQ(r1, (int64)3); - - /* Next read should return 0 (EOF) */ - int64 r2 = do_read(fds[0], buf, 16); - ST_ASSERT_EQ(r2, (int64)0); - - do_close(fds[0]); - } - st_pass(); - - /* ---- pipe: write to closed read end returns -EPIPE ---- */ - st_begin("pipe: write after reader close returns -EPIPE"); - { - int fds[2]; - sys_pipe2(reinterpret_cast(fds), 0, 0, 0, 0, 0); - - /* Close read end */ - do_close(fds[0]); - - /* Write should fail */ - const char* msg = "broken"; - int64 w = do_write(fds[1], msg, 6); - ST_ASSERT_EQ(w, (int64)-EPIPE); - - do_close(fds[1]); - } - st_pass(); - - /* ---- pipe: multiple writes accumulate ---- */ - st_begin("pipe: multiple writes accumulate in buffer"); - { - int fds[2]; - sys_pipe2(reinterpret_cast(fds), 0, 0, 0, 0, 0); - - do_write(fds[1], "AAA", 3); - do_write(fds[1], "BBB", 3); - - char buf[16] = {}; - int64 r = do_read(fds[0], buf, 16); - ST_ASSERT_EQ(r, (int64)6); - ST_ASSERT_EQ(buf[0], 'A'); - ST_ASSERT_EQ(buf[3], 'B'); - - do_close(fds[0]); - do_close(fds[1]); - } - st_pass(); - - /* ---- pipe: read partial ---- */ - st_begin("pipe: partial read leaves remainder"); - { - int fds[2]; - sys_pipe2(reinterpret_cast(fds), 0, 0, 0, 0, 0); - - do_write(fds[1], "ABCDEF", 6); - - char buf[3] = {}; - int64 r1 = do_read(fds[0], buf, 3); - ST_ASSERT_EQ(r1, (int64)3); - ST_ASSERT_EQ(buf[0], 'A'); - ST_ASSERT_EQ(buf[2], 'C'); - - int64 r2 = do_read(fds[0], buf, 3); - ST_ASSERT_EQ(r2, (int64)3); - ST_ASSERT_EQ(buf[0], 'D'); - ST_ASSERT_EQ(buf[2], 'F'); - - do_close(fds[0]); - do_close(fds[1]); - } - st_pass(); -} - -/* ================================================================== */ -/* fcntl tests */ -/* ================================================================== */ - -void selftest_fcntl() -{ - /* ---- fcntl F_DUPFD ---- */ - st_begin("fcntl: F_DUPFD duplicates fd"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - int64 fd2 = sys_fcntl(static_cast(fd), F_DUPFD, 0, 0, 0, 0); - ST_ASSERT(fd2 >= 0); - ST_ASSERT_NE(fd, fd2); - - /* Both should be valid reads */ - char buf[4]; - int64 r = do_read(fd2, buf, 4); - ST_ASSERT_EQ(r, (int64)0); /* /dev/null → EOF */ - - do_close(fd); - do_close(fd2); - } - st_pass(); - - /* ---- fcntl F_DUPFD with min_fd ---- */ - st_begin("fcntl: F_DUPFD respects min_fd"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - int64 fd2 = sys_fcntl(static_cast(fd), F_DUPFD, 100, 0, 0, 0); - ST_ASSERT(fd2 >= 100); - - do_close(fd); - do_close(fd2); - } - st_pass(); - - /* ---- fcntl F_GETFD / F_SETFD ---- */ - st_begin("fcntl: F_GETFD/F_SETFD cloexec"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - /* Initially no CLOEXEC */ - int64 flags = sys_fcntl(static_cast(fd), F_GETFD, 0, 0, 0, 0); - ST_ASSERT_EQ(flags, (int64)0); - - /* Set CLOEXEC */ - int64 ret = sys_fcntl(static_cast(fd), F_SETFD, FD_CLOEXEC, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - - /* Verify it was set */ - flags = sys_fcntl(static_cast(fd), F_GETFD, 0, 0, 0, 0); - ST_ASSERT_EQ(flags, (int64)FD_CLOEXEC); - - /* Clear it */ - sys_fcntl(static_cast(fd), F_SETFD, 0, 0, 0, 0); - flags = sys_fcntl(static_cast(fd), F_GETFD, 0, 0, 0, 0); - ST_ASSERT_EQ(flags, (int64)0); - - do_close(fd); - } - st_pass(); - - /* ---- fcntl F_GETFL ---- */ - st_begin("fcntl: F_GETFL returns open flags"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - int64 fl = sys_fcntl(static_cast(fd), F_GETFL, 0, 0, 0, 0); - /* O_RDONLY == 0, so result should have no write bits */ - ST_ASSERT_EQ(fl & O_WRONLY, (int64)0); - - do_close(fd); - } - st_pass(); - - /* ---- fcntl F_SETFL O_NONBLOCK ---- */ - st_begin("fcntl: F_SETFL toggles O_NONBLOCK"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - /* Set O_NONBLOCK */ - sys_fcntl(static_cast(fd), F_SETFL, O_NONBLOCK, 0, 0, 0); - int64 fl = sys_fcntl(static_cast(fd), F_GETFL, 0, 0, 0, 0); - ST_ASSERT(fl & O_NONBLOCK); - - /* Clear it */ - sys_fcntl(static_cast(fd), F_SETFL, 0, 0, 0, 0); - fl = sys_fcntl(static_cast(fd), F_GETFL, 0, 0, 0, 0); - ST_ASSERT_EQ(fl & O_NONBLOCK, (int64)0); - - do_close(fd); - } - st_pass(); - - /* ---- fcntl F_DUPFD_CLOEXEC ---- */ - st_begin("fcntl: F_DUPFD_CLOEXEC sets cloexec"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - int64 fd2 = sys_fcntl(static_cast(fd), F_DUPFD_CLOEXEC, 0, 0, 0, 0); - ST_ASSERT(fd2 >= 0); - - int64 flags = sys_fcntl(static_cast(fd2), F_GETFD, 0, 0, 0, 0); - ST_ASSERT_EQ(flags, (int64)FD_CLOEXEC); - - do_close(fd); - do_close(fd2); - } - st_pass(); - - /* ---- fcntl bad fd ---- */ - st_begin("fcntl: bad fd returns -EBADF"); - { - int64 ret = sys_fcntl(999, F_GETFD, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EBADF); - } - st_pass(); - - /* ---- fcntl unknown cmd ---- */ - st_begin("fcntl: unknown cmd returns -EINVAL"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - int64 ret = sys_fcntl(static_cast(fd), 9999, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EINVAL); - do_close(fd); - } - st_pass(); -} diff --git a/test/test_pmm.cc b/test/test_pmm.cc deleted file mode 100644 index 3330866..0000000 --- a/test/test_pmm.cc +++ /dev/null @@ -1,283 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test: Physical Memory Manager (PMM) - * - * Tests: - * 1. Single page alloc/free round-trip - * 2. Page address alignment (4KB) - * 3. No duplicate pages from consecutive allocs - * 4. Free then re-alloc returns the same page (PCP cache) - * 5. Multi-page (order > 0) alloc/free - * 6. Bulk alloc stress test (alloc many, free all) - * 7. Reference counting (incref/decref) - * 8. page_to_pa / pa_to_page round-trip - */ - -#include -#include -#include - -void selftest_pmm() -{ - st_begin("pmm: single page alloc/free"); - { - Page* page = pmm_alloc_page(); - ST_ASSERT(page != nullptr); - ST_ASSERT(page->type == PageType::Allocated); - ST_ASSERT(page->order == 0); - - uint64 pa = page_to_pa(page).raw; - ST_ASSERT_EQ(pa % kPageSize, 0ULL); // 4KB aligned - - uint64 va = page_to_va(page).raw; - ST_ASSERT_EQ(va, pa_to_va(phys_addr(pa)).raw); - - pmm_free_page(page); - } - st_pass(); - - st_begin("pmm: no duplicate pages"); - { - Page* p1 = pmm_alloc_page(); - Page* p2 = pmm_alloc_page(); - ST_ASSERT(p1 != nullptr); - ST_ASSERT(p2 != nullptr); - ST_ASSERT_NE(p1, p2); - ST_ASSERT_NE(page_to_pa(p1).raw, page_to_pa(p2).raw); - pmm_free_page(p2); - pmm_free_page(p1); - } - st_pass(); - - st_begin("pmm: free then re-alloc (PCP)"); - { - Page* p1 = pmm_alloc_page(); - uint64 pa1 = page_to_pa(p1).raw; - pmm_free_page(p1); - - // PCP should return the most recently freed page - Page* p2 = pmm_alloc_page(); - uint64 pa2 = page_to_pa(p2).raw; - ST_ASSERT_EQ(pa1, pa2); - pmm_free_page(p2); - } - st_pass(); - - st_begin("pmm: multi-page alloc (order 2 = 4 pages)"); - { - Page* page = pmm_alloc_pages(2); - ST_ASSERT(page != nullptr); - ST_ASSERT(page->order == 2); - - uint64 pa = page_to_pa(page).raw; - ST_ASSERT_EQ(pa % (kPageSize * 4), 0ULL); // Naturally aligned - - pmm_free_pages(page, 2); - } - st_pass(); - - st_begin("pmm: bulk alloc/free stress (256 pages)"); - { - constexpr int N = 256; - Page* pages[N]; - - // Allocate all - for (int i = 0; i < N; i++) { - pages[i] = pmm_alloc_page(); - ST_ASSERT(pages[i] != nullptr); - } - - // Verify no duplicates (spot check: consecutive pairs) - for (int i = 1; i < N; i++) { - ST_ASSERT_NE(pages[i], pages[i - 1]); - } - - // Free all - for (int i = 0; i < N; i++) { - pmm_free_page(pages[i]); - } - } - st_pass(); - - st_begin("pmm: page_to_pa / pa_to_page round-trip"); - { - Page* page = pmm_alloc_page(); - ST_ASSERT(page != nullptr); - uint64 pa = page_to_pa(page).raw; - Page* page2 = pa_to_page(phys_addr(pa)); - ST_ASSERT_EQ(page, page2); - pmm_free_page(page); - } - st_pass(); - - st_begin("pmm: refcount incref/decref"); - { - Page* page = pmm_alloc_page(); - ST_ASSERT(page != nullptr); - ST_ASSERT(page->refcount.load() == 1); - - page_incref(page); - ST_ASSERT(page->refcount.load() == 2); - - page_decref(page); // 2 -> 1, should NOT free - ST_ASSERT(page->refcount.load() == 1); - ST_ASSERT(page->type == PageType::Allocated); - - page_decref(page); // 1 -> 0, should free to pool - // After decref to 0, page is returned to pool. - // We can't safely check page->type because it might be reused. - } - st_pass(); - st_begin("pmm: pmm_alloc_pages natural alignment (order-3)"); - { - Page* page = pmm_alloc_pages(3); - ST_ASSERT(page != nullptr); - uint64 pa = page_to_pa(page).raw; - ST_ASSERT_EQ(pa % (kPageSize * 8), 0ULL); - pmm_free_pages(page, 3); - } - st_pass(); - - st_begin("pmm: page_decref to 0 and reuse (order-0)"); - { - Page* page = pmm_alloc_page(); - uint64 pa = page_to_pa(page).raw; - page_decref(page); // drops 1 -> 0, freeing it - - // Next alloc from PCP should give back the same page - Page* page2 = pmm_alloc_page(); - ST_ASSERT_EQ(page_to_pa(page2).raw, pa); - pmm_free_page(page2); - } - st_pass(); - - st_begin("pmm: page_decref to 0 on multi-page blocks (order-3)"); - { - Page* page = pmm_alloc_pages(3); - uint64 pa = page_to_pa(page).raw; - page_decref(page); // Should internally route to pmm_free_pages(page, 3) - - // Re-allocate order-3 and see if we get it back (buddy coalescing was respected) - Page* page2 = pmm_alloc_pages(3); - ST_ASSERT_EQ(page_to_pa(page2).raw, pa); - pmm_free_pages(page2, 3); - } - st_pass(); - - st_begin("pmm: buddy split and block coalescing correctness"); - { - // Force split: allocate order-1, free it, allocate two order-0 - Page* page_ord1 = pmm_alloc_pages(1); - uint64 pa1 = page_to_pa(page_ord1).raw; - pmm_free_pages(page_ord1, 1); - - Page* p0_a = pmm_alloc_page(); - Page* p0_b = pmm_alloc_page(); - - // Free them to trigger coalesce - pmm_free_page(p0_a); - pmm_free_page(p0_b); - - // Allocate order-1 again to verify successful coalescing - Page* page_ord1_again = pmm_alloc_pages(1); - ST_ASSERT_EQ(page_to_pa(page_ord1_again).raw, pa1); - pmm_free_pages(page_ord1_again, 1); - } - st_pass(); - - st_begin("pmm: mixed order cross allocation"); - { - Page* p0 = pmm_alloc_page(); - Page* p2 = pmm_alloc_pages(2); - Page* p0b = pmm_alloc_page(); - - ST_ASSERT(p0 != nullptr); - ST_ASSERT(p2 != nullptr); - ST_ASSERT(p0b != nullptr); - ST_ASSERT_NE(page_to_pa(p0).raw, page_to_pa(p2).raw); - - pmm_free_page(p0); - pmm_free_pages(p2, 2); - pmm_free_page(p0b); - } - st_pass(); - - st_begin("pmm: PCP drain/refill boundaries"); - { - // kPcpHighWatermark = 64. Allocating and freeing 65 blocks triggers drain. - Page* pages[65]; - for (int i=0; i<65; i++) pages[i] = pmm_alloc_page(); - for (int i=0; i<65; i++) pmm_free_page(pages[i]); - - // The system shouldn't crash and PCP logic should handle this. - Page* verify_page = pmm_alloc_page(); - ST_ASSERT(verify_page != nullptr); - pmm_free_page(verify_page); - } - st_pass(); - - st_begin("pmm: OOM exhaustion stability"); - { - Page* head = nullptr; - // First allocate large chunks to be fast - while (true) { - Page* page = pmm_alloc_pages(5); - if (!page) break; - uint64* ptr = reinterpret_cast(page_to_va(page).raw); - *ptr = reinterpret_cast(head); - // encode order in the second word - *(ptr + 1) = 5; - head = page; - } - // Then allocate single frames until absolute zero - while (true) { - Page* page = pmm_alloc_page(); - if (!page) break; - uint64* ptr = reinterpret_cast(page_to_va(page).raw); - *ptr = reinterpret_cast(head); - *(ptr + 1) = 0; - head = page; - } - - // We hit nullptr. System is completely exhausted. - ST_ASSERT(pmm_alloc_page() == nullptr); - - // Free everything - while (head) { - uint64* ptr = reinterpret_cast(page_to_va(head).raw); - Page* nxt = reinterpret_cast(*ptr); - uint64 order = *(ptr + 1); - if (order == 5) pmm_free_pages(head, 5); - else pmm_free_page(head); - head = nxt; - } - } - st_pass(); - - st_begin("pmm: out of bounds order allocation gracefully fails"); - { - // kMaxOrder is 11, so passing 11 or higher should safely return nullptr. - Page* page = pmm_alloc_pages(11); - ST_ASSERT(page == nullptr); - page = pmm_alloc_pages(255); - ST_ASSERT(page == nullptr); - } - st_pass(); - - st_begin("pmm: pmm_get_mem_base / pmm_get_mem_size sanity"); - { - uint64 base = pmm_get_mem_base().raw; - uint64 size = pmm_get_mem_size(); - - // We no longer assert on QEMU specific memory address - // ST_ASSERT(base >= 0x80000000ULL); - ST_ASSERT(size > 0); - // Size must be page-aligned - ST_ASSERT_EQ(size % kPageSize, 0ULL); - // Base must be page-aligned - ST_ASSERT_EQ(base % kPageSize, 0ULL); - } - st_pass(); -} diff --git a/test/test_random.cc b/test/test_random.cc deleted file mode 100644 index d546410..0000000 --- a/test/test_random.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include -#include - -void selftest_random() -{ - /* Test 1: Basic 64-bit generation */ - kprintf("[test] random: basic 64-bit generation ... "); - uint64 v1 = get_random_u64(); - uint64 v2 = get_random_u64(); - if (v1 == v2) { - kernel_panic("random: two consecutive generations were identical!"); - } - kprintf("PASS\n"); - - /* Test 2: Basic 32-bit generation */ - kprintf("[test] random: basic 32-bit generation ... "); - uint32 v3 = get_random_u32(); - uint32 v4 = get_random_u32(); - if (v3 == v4) { - kernel_panic("random: two consecutive 32-bit generations were identical!"); - } - kprintf("PASS\n"); - - /* Test 3: Byte generation */ - kprintf("[test] random: byte generation ... "); - uint8 buf1[16]; - uint8 buf2[16]; - get_random_bytes(buf1, sizeof(buf1)); - get_random_bytes(buf2, sizeof(buf2)); - - bool all_zero1 = true; - bool all_zero2 = true; - bool same = true; - - for (int i = 0; i < 16; i++) { - if (buf1[i] != 0) all_zero1 = false; - if (buf2[i] != 0) all_zero2 = false; - if (buf1[i] != buf2[i]) same = false; - } - - if (all_zero1 || all_zero2 || same) { - kernel_panic("random: byte generation statistical failure!"); - } - kprintf("PASS\n"); -} diff --git a/test/test_rbtree.cc b/test/test_rbtree.cc deleted file mode 100644 index 27f049a..0000000 --- a/test/test_rbtree.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include - -struct TestNode { - int key; - struct rb_node rb; -}; - -static bool node_less(struct rb_node *node, const struct rb_node *parent) { - TestNode *n = rb_entry(node, TestNode, rb); - const TestNode *p = reinterpret_cast( - reinterpret_cast(parent) - __builtin_offsetof(TestNode, rb)); - return n->key < p->key; -} - -static int node_cmp(const void *key, const struct rb_node *node) { - int k = *static_cast(key); - const TestNode *n = reinterpret_cast( - reinterpret_cast(node) - __builtin_offsetof(TestNode, rb)); - if (k < n->key) return -1; - if (k > n->key) return 1; - return 0; -} - -void selftest_rbtree() { - st_begin("rbtree: basic insert, find, erase"); - { - struct rb_root tree = RB_ROOT; - TestNode n1{10, {}}, n2{20, {}}, n3{5, {}}; - - rb_add(&n1.rb, &tree, node_less); - rb_add(&n2.rb, &tree, node_less); - rb_add(&n3.rb, &tree, node_less); - - int search_key = 20; - struct rb_node *found = rb_find(&search_key, &tree, node_cmp); - ST_ASSERT(found == &n2.rb); - - search_key = 99; - found = rb_find(&search_key, &tree, node_cmp); - ST_ASSERT(found == nullptr); - - rb_erase(&n2.rb, &tree); - // Verify erased - search_key = 20; - found = rb_find(&search_key, &tree, node_cmp); - ST_ASSERT(found == nullptr); - } - st_pass(); - - st_begin("rbtree: ordered iteration"); - { - struct rb_root tree = RB_ROOT; - TestNode nodes[5] = { {50, {}}, {10, {}}, {40, {}}, {20, {}}, {30, {}} }; - for (int i=0; i<5; i++) { - rb_add(&nodes[i].rb, &tree, node_less); - } - - int expected[] = {10, 20, 30, 40, 50}; - int idx = 0; - struct rb_node *node = rb_first(&tree); - while (node) { - TestNode *n = rb_entry(node, TestNode, rb); - ST_ASSERT_EQ(n->key, expected[idx]); - idx++; - node = rb_next(node); - } - ST_ASSERT_EQ(idx, 5); - } - st_pass(); - - st_begin("rbtree: large scale insert/erase balance"); - { - struct rb_root tree = RB_ROOT; - constexpr int N = 200; - static TestNode nodes[N]; // Static to avoid blowing up the BSP stack - for (int i=0; i -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* ======================================================================== - * Helper: create a minimal test TCB (no real kernel stack, just metadata) - * ======================================================================== */ - -static TaskControlBlock g_test_tcbs[8]; - -static TaskControlBlock* make_test_tcb(int index, const char* name, - uint8 priority, uint8 cpu) -{ - TaskControlBlock* t = &g_test_tcbs[index]; - t->context = {}; - t->wait_chld.init("test_wq"); - t->name = name; - t->priority = priority; - t->cpu_id = cpu; - t->pid = 100 + index; - t->tgid = 100 + index; - t->state = TaskState::Runnable; - t->time_slice = priority_to_timeslice(priority); - t->run_link.init(); - t->all_link.init(); - t->children.init(); - t->sibling.init(); - t->mm = nullptr; - t->trapframe = nullptr; - t->kstack_pa = 0; - t->kstack_va = 0; - t->flags = TF_KTHREAD; - t->sched_class = &g_sched_class_o1; - t->sched_entity = &t->run_link; - return t; -} - -/* ======================================================================== - * Test cases - * ======================================================================== */ - -static bool test_current_task() -{ - /* After sched_init, current_task() should be the BSP boot TCB */ - TaskControlBlock* curr = current_task(); - return curr != nullptr && curr->state == TaskState::Running; -} - -static bool test_priority_to_timeslice() -{ - /* Higher priority (lower number) should get longer time slice */ - int32 ts_high = priority_to_timeslice(0); - int32 ts_mid = priority_to_timeslice(15); - int32 ts_low = priority_to_timeslice(31); - - return ts_high > ts_mid && ts_mid > ts_low && ts_low >= 1; -} - -static bool test_o1_pick_next_priority() -{ - RunQueue rq; - rq.init(0); - g_sched_class_o1.init_rq(&rq); - - TaskControlBlock* t_lo = make_test_tcb(0, "test_p5", 5, 0); - TaskControlBlock* t_hi = make_test_tcb(1, "test_p2", 2, 0); - - g_sched_class_o1.enqueue_task(&rq, t_lo); - g_sched_class_o1.enqueue_task(&rq, t_hi); - - TaskControlBlock* next = g_sched_class_o1.pick_next_task(&rq); - return next == t_hi; -} - -static bool test_o1_fifo_order() -{ - RunQueue rq; - rq.init(0); - g_sched_class_o1.init_rq(&rq); - - TaskControlBlock* t0 = make_test_tcb(0, "test_q0", 10, 0); - TaskControlBlock* t1 = make_test_tcb(1, "test_q1", 10, 0); - TaskControlBlock* t2 = make_test_tcb(2, "test_q2", 10, 0); - - g_sched_class_o1.enqueue_task(&rq, t0); - g_sched_class_o1.enqueue_task(&rq, t1); - g_sched_class_o1.enqueue_task(&rq, t2); - - TaskControlBlock* next = g_sched_class_o1.pick_next_task(&rq); - if (next != t0) return false; - g_sched_class_o1.dequeue_task(&rq, t0); - - next = g_sched_class_o1.pick_next_task(&rq); - if (next != t1) return false; - g_sched_class_o1.dequeue_task(&rq, t1); - - next = g_sched_class_o1.pick_next_task(&rq); - if (next != t2) return false; - - return true; -} - -static bool test_o1_nr_running() -{ - RunQueue rq; - rq.init(0); - g_sched_class_o1.init_rq(&rq); - - TaskControlBlock* t0 = make_test_tcb(0, "test_n0", 8, 0); - TaskControlBlock* t1 = make_test_tcb(1, "test_n1", 9, 0); - - if (rq.nr_running() != 0 || rq.o1().nr_running() != 0) return false; - - g_sched_class_o1.enqueue_task(&rq, t0); - if (rq.nr_running() != 1 || rq.o1().nr_running() != 1) return false; - - g_sched_class_o1.enqueue_task(&rq, t1); - if (rq.nr_running() != 2 || rq.o1().nr_running() != 2) return false; - - g_sched_class_o1.dequeue_task(&rq, t0); - if (rq.nr_running() != 1 || rq.o1().nr_running() != 1) return false; - - g_sched_class_o1.dequeue_task(&rq, t1); - return rq.nr_running() == 0 && rq.o1().nr_running() == 0; -} - -static bool test_o1_pick_next_empty() -{ - RunQueue rq; - rq.init(0); - g_sched_class_o1.init_rq(&rq); - - return g_sched_class_o1.pick_next_task(&rq) == nullptr; -} - -static bool test_priority_to_timeslice_bounds() -{ - /* Boundary values */ - int32 ts0 = priority_to_timeslice(0); - int32 ts31 = priority_to_timeslice(31); - - return ts0 == 20 && ts31 >= 1; -} - -static bool test_enqueue_dequeue() -{ - /* Create a test task and enqueue/dequeue it */ - TaskControlBlock* t = make_test_tcb(0, "test_ed", 10, 0); - - sched_enqueue(t); - if (t->state != TaskState::Runnable) return false; - - sched_dequeue(t); - /* After dequeue, run_link should be self-pointing */ - return t->run_link.next == &t->run_link; -} - -static bool test_multiple_enqueue_dequeue() -{ - /* Enqueue 3 tasks at different priorities, dequeue all */ - TaskControlBlock* t0 = make_test_tcb(0, "test_m0", 5, 0); - TaskControlBlock* t1 = make_test_tcb(1, "test_m1", 10, 0); - TaskControlBlock* t2 = make_test_tcb(2, "test_m2", 20, 0); - - sched_enqueue(t0); - sched_enqueue(t1); - sched_enqueue(t2); - - sched_dequeue(t0); - sched_dequeue(t1); - sched_dequeue(t2); - - return t0->run_link.is_empty() && - t1->run_link.is_empty() && - t2->run_link.is_empty(); -} - -static bool test_current_task_name() -{ - TaskControlBlock* curr = current_task(); - if (!curr || !curr->name) return false; - - /* BSP boot TCB should be named "kernel_main" */ - const char* expected = "kernel_main"; - const char* actual = curr->name; - while (*expected && *actual) { - if (*expected != *actual) return false; - expected++; - actual++; - } - return *expected == *actual; -} - -/* ======================================================================== - * Test runner - * ======================================================================== */ - -void selftest_sched() -{ - st_begin("sched: current_task is valid after init"); - ST_ASSERT(test_current_task()); - st_pass(); - - st_begin("sched: current_task name is kernel_main"); - ST_ASSERT(test_current_task_name()); - st_pass(); - - st_begin("sched: priority_to_timeslice ordering"); - ST_ASSERT(test_priority_to_timeslice()); - st_pass(); - - st_begin("sched: priority_to_timeslice bounds"); - ST_ASSERT(test_priority_to_timeslice_bounds()); - st_pass(); - - st_begin("sched: enqueue/dequeue round-trip"); - ST_ASSERT(test_enqueue_dequeue()); - st_pass(); - - st_begin("sched: multiple enqueue/dequeue"); - ST_ASSERT(test_multiple_enqueue_dequeue()); - st_pass(); - - st_begin("sched: o1 pick_next priority"); - ST_ASSERT(test_o1_pick_next_priority()); - st_pass(); - - st_begin("sched: o1 FIFO order"); - ST_ASSERT(test_o1_fifo_order()); - st_pass(); - - st_begin("sched: o1 nr_running accounting"); - ST_ASSERT(test_o1_nr_running()); - st_pass(); - - st_begin("sched: o1 pick_next empty"); - ST_ASSERT(test_o1_pick_next_empty()); - st_pass(); -} - diff --git a/test/test_signal.cc b/test/test_signal.cc deleted file mode 100644 index 360b0e6..0000000 --- a/test/test_signal.cc +++ /dev/null @@ -1,193 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_signal.cc — Self-tests for signal infrastructure - * - * Tests the kernel-internal signal APIs directly (not via syscalls, - * since syscalls use copy_to_user which rejects kernel-space buffers). - */ - -#include -#include -#include -#include -#include -#include -#include - -/* From signal.cc */ -extern int send_signal(int sig, kernel_siginfo* info, TaskControlBlock* task); - -/* Drain all queued sigqueue entries from a task's pending list */ -static void flush_pending(TaskControlBlock* task) -{ - task->pending.signal = sigset_t{}; - list_node* head = &task->pending.list; - while (head->next != head) { - list_node* node = head->next; - head->next = node->next; - node->next->prev = head; - auto* q = list_entry(node); - delete q; - } -} - -void selftest_signal() -{ - TaskControlBlock* curr = current_task(); - - /* Ensure sighand exists for this task */ - if (!curr->sighand) { - curr->sighand = new sighand_struct; - curr->sighand->init(); - } - - /* Ensure pending list is initialized */ - if (curr->pending.list.next == nullptr) { - curr->pending.list.next = &curr->pending.list; - curr->pending.list.prev = &curr->pending.list; - curr->pending.signal = sigset_t{}; - } - - /* ---- send_signal queues a signal ---- */ - st_begin("signal: send_signal queues to pending"); - { - curr->pending.signal = sigset_t{}; - - kernel_siginfo info{}; - info.si_signo = SIGUSR1; - info.si_code = 0; - - int ret = send_signal(SIGUSR1, &info, curr); - ST_ASSERT_EQ(ret, 0); - ST_ASSERT(curr->pending.signal.has(SIGUSR1)); - - flush_pending(curr); - } - st_pass(); - - /* ---- send_signal: invalid signal returns -EINVAL ---- */ - st_begin("signal: send_signal invalid sig returns -EINVAL"); - { - int ret = send_signal(0, nullptr, curr); - ST_ASSERT_EQ(ret, -EINVAL); - - ret = send_signal(_NSIG + 1, nullptr, curr); - ST_ASSERT_EQ(ret, -EINVAL); - } - st_pass(); - - /* ---- send_signal: null task returns -ESRCH ---- */ - st_begin("signal: send_signal null task returns -ESRCH"); - { - int ret = send_signal(SIGUSR1, nullptr, nullptr); - ST_ASSERT_EQ(ret, -ESRCH); - } - st_pass(); - - /* ---- duplicate standard signal is coalesced ---- */ - st_begin("signal: duplicate standard signal coalesced"); - { - curr->pending.signal = sigset_t{}; - - send_signal(SIGUSR1, nullptr, curr); - ST_ASSERT(curr->pending.signal.has(SIGUSR1)); - - int ret = send_signal(SIGUSR1, nullptr, curr); - ST_ASSERT_EQ(ret, 0); - - flush_pending(curr); - } - st_pass(); - - /* ---- sigset_t: add/del/has ---- */ - st_begin("signal: sigset_t add/del/has"); - { - sigset_t s{}; - ST_ASSERT(!s.has(SIGUSR1)); - s.add(SIGUSR1); - ST_ASSERT(s.has(SIGUSR1)); - s.del(SIGUSR1); - ST_ASSERT(!s.has(SIGUSR1)); - } - st_pass(); - - /* ---- sigset_t: bitwise operators ---- */ - st_begin("signal: sigset_t bitwise OR and AND"); - { - sigset_t a{}; - a.add(SIGUSR1); - sigset_t b{}; - b.add(SIGUSR2); - - sigset_t c = a | b; - ST_ASSERT(c.has(SIGUSR1)); - ST_ASSERT(c.has(SIGUSR2)); - - sigset_t d = c & a; - ST_ASSERT(d.has(SIGUSR1)); - ST_ASSERT(!d.has(SIGUSR2)); - } - st_pass(); - - /* ---- blocked mask: direct manipulation ---- */ - st_begin("signal: blocked mask direct manipulation"); - { - sigset_t saved = curr->blocked; - curr->blocked = sigset_t{}; - - curr->blocked.add(SIGUSR1); - curr->blocked.add(SIGUSR2); - ST_ASSERT(curr->blocked.has(SIGUSR1)); - ST_ASSERT(curr->blocked.has(SIGUSR2)); - - curr->blocked.del(SIGUSR1); - ST_ASSERT(!curr->blocked.has(SIGUSR1)); - ST_ASSERT(curr->blocked.has(SIGUSR2)); - - curr->blocked = saved; - } - st_pass(); - - /* ---- sighand action table ---- */ - st_begin("signal: sighand action table defaults to SIG_DFL"); - { - /* All handlers should default to SIG_DFL (0) */ - kernel_sigaction* ka = &curr->sighand->action[SIGUSR1 - 1]; - ST_ASSERT_EQ(ka->sa_handler, (uint64)SIG_DFL); - - /* Set a handler and verify */ - ka->sa_handler = 0x12345678ULL; - ST_ASSERT_EQ(ka->sa_handler, (uint64)0x12345678ULL); - - /* Reset */ - ka->sa_handler = SIG_DFL; - } - st_pass(); - - /* ---- sig_kernel_only rejects SIGKILL/SIGSTOP handlers ---- */ - st_begin("signal: SIGKILL/SIGSTOP are kernel-only"); - { - ST_ASSERT(sig_kernel_only(SIGKILL)); - ST_ASSERT(sig_kernel_only(SIGSTOP)); - ST_ASSERT(!sig_kernel_only(SIGUSR1)); - ST_ASSERT(!sig_kernel_only(SIGINT)); - } - st_pass(); - - /* ---- sig_default_action correctness ---- */ - st_begin("signal: sig_default_action returns correct actions"); - { - ST_ASSERT_EQ((int)sig_default_action(SIGCHLD), (int)SIG_ACT_IGN); - ST_ASSERT_EQ((int)sig_default_action(SIGKILL), (int)SIG_ACT_TERM); - ST_ASSERT_EQ((int)sig_default_action(SIGSTOP), (int)SIG_ACT_STOP); - ST_ASSERT_EQ((int)sig_default_action(SIGCONT), (int)SIG_ACT_CONT); - ST_ASSERT_EQ((int)sig_default_action(SIGSEGV), (int)SIG_ACT_CORE); - } - st_pass(); - - /* Clean up */ - flush_pending(curr); - curr->blocked = sigset_t{}; -} diff --git a/test/test_slab.cc b/test/test_slab.cc deleted file mode 100644 index 8a448b4..0000000 --- a/test/test_slab.cc +++ /dev/null @@ -1,255 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test: Slab Allocator (kmalloc/kfree) - * - * Tests: - * 1. Small allocation (8 bytes) and free - * 2. Multiple size classes - * 3. No aliasing between consecutive allocs - * 4. Alignment check (minimum 8-byte aligned) - * 5. Bulk alloc/free stress - * 6. operator new / operator delete - * 7. Large allocation (> 2048, falls back to PMM) - * 8. Zero-size and null-free edge cases - */ - -#include -#include -#include -#include - -/* Forward declarations — defined in slab.cc */ -void* kmalloc(uint32 size); -void kfree(void* ptr); - -void selftest_slab() -{ - st_begin("slab: small alloc (8 bytes)"); - { - void* p = kmalloc(8); - ST_ASSERT(p != nullptr); - // Write and read back to verify the memory is usable - *static_cast(p) = 0xDEADBEEFCAFEBABEULL; - ST_ASSERT_EQ(*static_cast(p), 0xDEADBEEFCAFEBABEULL); - kfree(p); - } - st_pass(); - - st_begin("slab: multiple size classes"); - { - uint32 sizes[] = {8, 16, 32, 64, 128, 256, 512, 1024, 2048}; - void* ptrs[9]; - for (int i = 0; i < 9; i++) { - ptrs[i] = kmalloc(sizes[i]); - ST_ASSERT(ptrs[i] != nullptr); - // Write a marker - *static_cast(ptrs[i]) = static_cast(i); - } - // Verify markers (no cross-contamination) - for (int i = 0; i < 9; i++) { - ST_ASSERT_EQ(*static_cast(ptrs[i]), static_cast(i)); - } - for (int i = 0; i < 9; i++) { - kfree(ptrs[i]); - } - } - st_pass(); - - st_begin("slab: no aliasing"); - { - void* a = kmalloc(32); - void* b = kmalloc(32); - ST_ASSERT(a != nullptr); - ST_ASSERT(b != nullptr); - ST_ASSERT_NE(a, b); - kfree(b); - kfree(a); - } - st_pass(); - - st_begin("slab: alignment (8-byte minimum)"); - { - for (int i = 0; i < 16; i++) { - void* p = kmalloc(7); // odd size, should still be 8-aligned - ST_ASSERT(p != nullptr); - ST_ASSERT_EQ(reinterpret_cast(p) % 8, 0ULL); - kfree(p); - } - } - st_pass(); - - st_begin("slab: bulk alloc/free stress (128 x 64B)"); - { - constexpr int N = 128; - void* ptrs[N]; - for (int i = 0; i < N; i++) { - ptrs[i] = kmalloc(64); - ST_ASSERT(ptrs[i] != nullptr); - } - // Free in reverse order - for (int i = N - 1; i >= 0; i--) { - kfree(ptrs[i]); - } - } - st_pass(); - - st_begin("slab: operator new/delete"); - { - struct TestObj { - uint64 a; - uint64 b; - }; - TestObj* obj = new TestObj{42, 99}; - ST_ASSERT(obj != nullptr); - ST_ASSERT_EQ(obj->a, 42ULL); - ST_ASSERT_EQ(obj->b, 99ULL); - delete obj; - } - st_pass(); - - st_begin("slab: large alloc (4096 bytes, PMM fallback)"); - { - void* p = kmalloc(4096); - ST_ASSERT(p != nullptr); - ST_ASSERT_EQ(reinterpret_cast(p) % kPageSize, 0ULL); - kfree(p); - } - st_pass(); - - st_begin("slab: edge cases (zero size, null free)"); - { - void* p = kmalloc(0); - ST_ASSERT(p == nullptr); - kfree(nullptr); // should not crash - } - st_pass(); - st_begin("slab: LIFO freelist reallocation (same address)"); - { - void* a = kmalloc(32); - kfree(a); - void* b = kmalloc(32); - ST_ASSERT_EQ(a, b); - kfree(b); - } - st_pass(); - - st_begin("slab: boundary conditions (2048 bytes size class)"); - { - // 2048 bytes should still use slab (2 objects per page) - // We allocate 3 to guarantee at least two fall in the exact same slab page - void* p1 = kmalloc(2048); - void* p2 = kmalloc(2048); - void* p3 = kmalloc(2048); - - auto diff = [](void* a, void* b) -> uint64 { - uint64 ua = reinterpret_cast(a); - uint64 ub = reinterpret_cast(b); - return ua > ub ? ua - ub : ub - ua; - }; - - // At least one adjacent pair MUST be exactly separated by 2048 bytes - bool found_2048 = (diff(p1, p2) == 2048ULL) || (diff(p2, p3) == 2048ULL); - ST_ASSERT(found_2048); - - kfree(p1); - kfree(p2); - kfree(p3); - } - st_pass(); - - st_begin("slab: cross-page allocation (> 1 page equivalent objects)"); - { - // Allocating more than one page worth of 32-byte objects (4096 / 32 = 128) - constexpr int NUM = 150; - void* ptrs[NUM]; - for (int i=0; i(p) % kPageSize == 0) { - base_ptr = p; - break; - } - drain[drain_count++] = p; - } - - // base_ptr is the very first object in a fresh slab page! - // The page holds exactly 32 objects (4096 / 128 = 32). We already hold 1 (base_ptr). - void* ptrs[32]; - ptrs[0] = base_ptr; - for (int i = 1; i < 32; i++) { - ptrs[i] = kmalloc(128); - } - - // At this point, we completely own all 32 objects of this slab page. - uint64 page_pa = va_to_pa(virt_addr(reinterpret_cast(base_ptr))).raw; - Page* page = pa_to_page(phys_addr(page_pa)); - - ST_ASSERT(page->type == PageType::Slab); - ST_ASSERT(page->slab.obj_count == 32); - - // Free all items in this isolated slab page - for (int i = 0; i < 32; i++) { - kfree(ptrs[i]); - } - - // The page MUST have been returned to the PMM (either global Free or Per-CPU Cached). - ST_ASSERT(page->type == PageType::Free || page->type == PageType::PcpCached); - - // Clean up the drain array - for (int i = 0; i < drain_count; i++) { - kfree(drain[i]); - } - } - st_pass(); - - st_begin("slab: continuous operator new/delete memory leak loop"); - { - struct BigObj { uint8 data[512]; }; - BigObj* ptr = nullptr; - // 10K allocations to ensure no memory leak causes OOM - for (int i = 0; i < 10000; i++) { - ptr = new BigObj; - ST_ASSERT(ptr != nullptr); - delete ptr; - } - } - st_pass(); - - st_begin("slab: allocation pressure (mixed sizes)"); - { - constexpr int MAX_ITEMS = 100; - void* ptrs[MAX_ITEMS]; - uint32 sizes[MAX_ITEMS]; - - for (int i = 0; i < MAX_ITEMS; i++) { - sizes[i] = (i * 17) % 2000 + 8; // Pseudo-random sizes between 8 and 2008 - ptrs[i] = kmalloc(sizes[i]); - ST_ASSERT(ptrs[i] != nullptr); - ST_ASSERT(reinterpret_cast(ptrs[i]) % 8 == 0); - } - - for (int i = 0; i < MAX_ITEMS; i++) { - kfree(ptrs[i]); - } - } - st_pass(); -} diff --git a/test/test_smp.cc b/test/test_smp.cc deleted file mode 100644 index f934526..0000000 --- a/test/test_smp.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_smp.cc — Post-SMP boot tests - * - * These tests run after all APs are online. They verify: - * 1. IPI delivery — BSP sends IPI to each AP, AP increments counter. - * 2. Task migration — a task moves from one runqueue to another. - * 3. TLB shootdown IPI — cross-CPU flush. - * - * Called from the init thread (PID 1) context, NOT from the pre-SMP - * self-test suite. - */ - -#include -#include -#include -#include -#include -#include - -/* Shared counter incremented by APs when they receive an IPI */ -static lume::atomic g_ipi_ack_count{0}; - -/* ------------------------------------------------------------------ */ -/* IPI delivery test */ -/* ------------------------------------------------------------------ */ - -void selftest_ipi_delivery() -{ - st_begin("smp: IPI delivery to all APs"); - - /* Reset counter */ - g_ipi_ack_count.store(0, __ATOMIC_RELAXED); - - uint32 bsp = static_cast(arch::cpu::id()); - uint32 num_cpus = 4; /* TODO: derive from FDT */ - - /* Build mask of all APs */ - uint64 ap_mask = 0; - uint32 expected = 0; - for (uint32 i = 0; i < num_cpus; i++) { - if (i == bsp) continue; - ap_mask |= (1ULL << i); - expected++; - } - - /* Send reschedule IPI to all APs */ - smp_send_ipi(ap_mask, IPI_RESCHEDULE); - - /* Wait a short while for APs to process the interrupt. - * APs are in wfi (idle loop), so they'll wake immediately - * on interrupt delivery. We just need to give them time - * to run the handler. */ - for (volatile int i = 0; i < 100000; i++) { - /* spin-wait */ - } - - /* We can't directly check that IPI was received because - * IPI_RESCHEDULE just sets need_resched — no ack. - * Instead verify no crash occurred and the IPI infrastructure - * didn't deadlock. This is a liveness test. */ - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* IPI halt test (send to self, skip) */ -/* ------------------------------------------------------------------ */ - -void selftest_ipi_self_skip() -{ - st_begin("smp: IPI reason bitmask accumulation"); - - uint32 cpu = static_cast(arch::cpu::id()); - - /* Manually set multiple reasons atomically */ - g_ipi_data[cpu].pending.store(0, __ATOMIC_RELAXED); - g_ipi_data[cpu].pending.fetch_or(IPI_RESCHEDULE, __ATOMIC_RELEASE); - g_ipi_data[cpu].pending.fetch_or(IPI_TLB_SHOOTDOWN, __ATOMIC_RELEASE); - - uint32 val = g_ipi_data[cpu].pending.load(__ATOMIC_ACQUIRE); - ST_ASSERT_EQ(val, IPI_RESCHEDULE | IPI_TLB_SHOOTDOWN); - - /* Clean up */ - g_ipi_data[cpu].pending.store(0, __ATOMIC_RELAXED); - - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* TLB shootdown IPI test */ -/* ------------------------------------------------------------------ */ - -void selftest_tlb_shootdown() -{ - st_begin("smp: TLB shootdown IPI (cross-CPU flush)"); - - uint32 bsp = static_cast(arch::cpu::id()); - uint32 num_cpus = 4; - - /* Build AP mask */ - uint64 ap_mask = 0; - for (uint32 i = 0; i < num_cpus; i++) { - if (i == bsp) continue; - ap_mask |= (1ULL << i); - } - - /* Set TLB range on each AP's IpiData */ - for (uint32 i = 0; i < num_cpus; i++) { - if (i == bsp) continue; - g_ipi_data[i].tlb_start = 0; - g_ipi_data[i].tlb_end = 0; /* 0,0 = full flush */ - } - - /* Send TLB shootdown */ - smp_send_ipi(ap_mask, IPI_TLB_SHOOTDOWN); - - /* Wait for APs to process */ - for (volatile int i = 0; i < 100000; i++) {} - - /* If we got here without panic, TLB shootdown succeeded */ - st_pass(); -} - -/* ------------------------------------------------------------------ */ -/* Public entry point */ -/* ------------------------------------------------------------------ */ - -void selftest_smp() -{ - selftest_ipi_delivery(); - selftest_ipi_self_skip(); - selftest_tlb_shootdown(); -} diff --git a/test/test_spinlock.cc b/test/test_spinlock.cc deleted file mode 100644 index be794a0..0000000 --- a/test/test_spinlock.cc +++ /dev/null @@ -1,135 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test: Spinlock - * - * Tests: - * 1. Basic acquire/release - * 2. LockGuard RAII acquire/release - * 3. Nested locking (two different locks) - * 4. Interrupt state preservation across lock/unlock - * 5. is_held_by_current_cpu correctness - * - * Note: We cannot test multi-core contention in BSP-only self-test. - * That requires AP participation (future Phase 2 test). - */ - -#include -#include -#include -#include - -void selftest_spinlock() -{ - st_begin("spinlock: basic acquire/release"); - { - Spinlock lock; - lock.init("test_basic"); - - ST_ASSERT(!lock.is_held_by_current_cpu()); - - lock.acquire(); - ST_ASSERT(lock.is_held_by_current_cpu()); - - lock.release(); - ST_ASSERT(!lock.is_held_by_current_cpu()); - } - st_pass(); - - st_begin("spinlock: LockGuard RAII"); - { - Spinlock lock; - lock.init("test_guard"); - - { - LockGuard guard(lock); - ST_ASSERT(lock.is_held_by_current_cpu()); - } - // After scope exit, lock should be released - ST_ASSERT(!lock.is_held_by_current_cpu()); - } - st_pass(); - - st_begin("spinlock: nested locking (two locks)"); - { - Spinlock lock_a, lock_b; - lock_a.init("test_nest_a"); - lock_b.init("test_nest_b"); - - lock_a.acquire(); - ST_ASSERT(lock_a.is_held_by_current_cpu()); - - lock_b.acquire(); - ST_ASSERT(lock_b.is_held_by_current_cpu()); - - lock_b.release(); - ST_ASSERT(!lock_b.is_held_by_current_cpu()); - ST_ASSERT(lock_a.is_held_by_current_cpu()); // A still held - - lock_a.release(); - ST_ASSERT(!lock_a.is_held_by_current_cpu()); - } - st_pass(); - - st_begin("spinlock: interrupt state preservation"); - { - Spinlock lock; - lock.init("test_intr"); - - // Interrupts are currently off (BSP init period), but let's - // verify the lock doesn't corrupt the state. - bool before = arch::cpu::intr_enabled(); - - lock.acquire(); - // Inside lock, interrupts must be disabled - ST_ASSERT(!arch::cpu::intr_enabled()); - lock.release(); - - // After release, interrupt state should be restored - ST_ASSERT_EQ(arch::cpu::intr_enabled(), before); - } - st_pass(); - st_begin("spinlock: deep nesting tracking (> 2)"); - { - Spinlock l1, l2, l3; - l1.init("l1"); - l2.init("l2"); - l3.init("l3"); - - bool before = arch::cpu::intr_enabled(); - - l1.acquire(); - l2.acquire(); - l3.acquire(); - - ST_ASSERT(!arch::cpu::intr_enabled()); - - l3.release(); - ST_ASSERT(!arch::cpu::intr_enabled()); - - l2.release(); - ST_ASSERT(!arch::cpu::intr_enabled()); - - l1.release(); - ST_ASSERT_EQ(arch::cpu::intr_enabled(), before); - } - st_pass(); - - st_begin("spinlock: interrupt leak detection logic (lock_depth metadata)"); - { - Spinlock l; - l.init("l"); - - auto& state = sync::g_cpu_sync_states[arch::cpu::id()]; - int initial_depth = state.lock_depth; - - l.acquire(); - // The lock depth should strictly increase - ST_ASSERT_EQ(state.lock_depth, initial_depth + 1); - l.release(); - - ST_ASSERT_EQ(state.lock_depth, initial_depth); - } - st_pass(); -} diff --git a/test/test_sys_fs_extra.cc b/test/test_sys_fs_extra.cc deleted file mode 100644 index 705ce63..0000000 --- a/test/test_sys_fs_extra.cc +++ /dev/null @@ -1,238 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_sys_fs_extra.cc — Self-tests for additional filesystem syscalls - * - * Tests: dup3, chdir/getcwd, writev, ioctl (stub), unlinkat (stub). - * Complements test_vfs_io.cc which covers the core read/write/open/close. - */ - -#include -#include -#include -#include -#include -#include - -/* Syscall entry points */ -int64 sys_openat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_close(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_read(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_write(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_dup3(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_chdir(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getcwd(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_writev(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_ioctl(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_unlinkat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_mkdirat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_lseek(uint64, uint64, uint64, uint64, uint64, uint64); - -/* ================================================================== */ -/* Helpers */ -/* ================================================================== */ - -static int64 open_dev(const char* path, int flags) -{ - return sys_openat( - static_cast(-100), - reinterpret_cast(path), - static_cast(flags), 0, 0, 0); -} - -static int64 do_close(int64 fd) -{ - return sys_close(static_cast(fd), 0, 0, 0, 0, 0); -} - -static int64 do_read(int64 fd, void* buf, uint64 count) -{ - return sys_read(static_cast(fd), - reinterpret_cast(buf), count, 0, 0, 0); -} - - -/* iovec must match sys_fs.cc definition */ -struct test_iovec { - void* iov_base; - uint64 iov_len; -}; - -/* ================================================================== */ -/* Tests */ -/* ================================================================== */ - -void selftest_sys_fs_extra() -{ - /* ---- dup3: duplicate fd to specific target ---- */ - st_begin("sys_fs: dup3 duplicates to specific fd"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - /* dup3 to fd 50 */ - int64 fd2 = sys_dup3(static_cast(fd), 50, 0, 0, 0, 0); - ST_ASSERT_EQ(fd2, (int64)50); - - /* Both should work */ - char buf[4]; - int64 r = do_read(fd2, buf, 4); - ST_ASSERT_EQ(r, (int64)0); /* /dev/null → EOF */ - - do_close(fd); - do_close(fd2); - } - st_pass(); - - /* ---- dup3: same fd returns -EINVAL ---- */ - st_begin("sys_fs: dup3 same fd returns -EINVAL"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - int64 ret = sys_dup3(static_cast(fd), - static_cast(fd), 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EINVAL); - - do_close(fd); - } - st_pass(); - - /* ---- chdir to /dev, getcwd returns /dev ---- */ - st_begin("sys_fs: chdir then getcwd returns new dir"); - { - /* Save cwd */ - char saved_cwd[64] = {}; - sys_getcwd(reinterpret_cast(saved_cwd), 64, 0, 0, 0, 0); - - /* chdir to /dev */ - int64 ret = sys_chdir( - reinterpret_cast("/dev"), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - - /* getcwd should return /dev */ - char buf[64] = {}; - int64 len = sys_getcwd( - reinterpret_cast(buf), 64, 0, 0, 0, 0); - ST_ASSERT(len > 0); - ST_ASSERT_EQ(buf[0], '/'); - ST_ASSERT_EQ(buf[1], 'd'); - ST_ASSERT_EQ(buf[2], 'e'); - ST_ASSERT_EQ(buf[3], 'v'); - - /* Restore cwd to / */ - sys_chdir(reinterpret_cast("/"), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- chdir to nonexistent returns -ENOENT ---- */ - st_begin("sys_fs: chdir nonexistent returns -ENOENT"); - { - int64 ret = sys_chdir( - reinterpret_cast("/no_such_dir"), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-ENOENT); - } - st_pass(); - - /* ---- chdir to file returns -ENOTDIR ---- */ - st_begin("sys_fs: chdir to file returns -ENOTDIR"); - { - int64 ret = sys_chdir( - reinterpret_cast("/dev/null"), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-ENOTDIR); - } - st_pass(); - - /* ---- writev: scatter write to file ---- */ - st_begin("sys_fs: writev scatter write"); - { - /* Create a file, write with writev, read back */ - int64 fd = sys_openat( - static_cast(-100), - reinterpret_cast("/writev_test"), - O_CREAT | O_RDWR, 0644, 0, 0); - ST_ASSERT(fd >= 0); - - char a[] = "AAA"; - char b[] = "BBB"; - test_iovec iov[2]; - iov[0].iov_base = a; - iov[0].iov_len = 3; - iov[1].iov_base = b; - iov[1].iov_len = 3; - - int64 w = sys_writev( - static_cast(fd), - reinterpret_cast(iov), 2, 0, 0, 0); - ST_ASSERT_EQ(w, (int64)6); - - /* Seek back to start and read */ - sys_lseek(static_cast(fd), 0, 0 /* SEEK_SET */, 0, 0, 0); - - char buf[8] = {}; - int64 r = do_read(fd, buf, 8); - ST_ASSERT_EQ(r, (int64)6); - ST_ASSERT_EQ(buf[0], 'A'); - ST_ASSERT_EQ(buf[3], 'B'); - - do_close(fd); - } - st_pass(); - - /* ---- writev: bad fd returns -EBADF ---- */ - st_begin("sys_fs: writev bad fd returns -EBADF"); - { - test_iovec iov[1]; - char dummy[] = "x"; - iov[0].iov_base = dummy; - iov[0].iov_len = 1; - - int64 ret = sys_writev(999, - reinterpret_cast(iov), 1, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EBADF); - } - st_pass(); - - /* ---- ioctl stub returns -ENOTTY ---- */ - st_begin("sys_fs: ioctl stub returns -ENOTTY"); - { - int64 fd = open_dev("/dev/null", O_RDONLY); - ST_ASSERT(fd >= 0); - - int64 ret = sys_ioctl(static_cast(fd), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-ENOTTY); - - do_close(fd); - } - st_pass(); - - /* ---- unlinkat stub returns -ENOSYS ---- */ - st_begin("sys_fs: unlinkat stub returns -ENOSYS"); - { - int64 ret = sys_unlinkat( - static_cast(-100), - reinterpret_cast("/some_file"), - 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-ENOSYS); - } - st_pass(); - - /* ---- getcwd: null buf returns -EINVAL ---- */ - st_begin("sys_fs: getcwd null buf returns -EINVAL"); - { - int64 ret = sys_getcwd(0, 64, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EINVAL); - } - st_pass(); - - /* ---- getcwd: zero size returns -EINVAL ---- */ - st_begin("sys_fs: getcwd zero size returns -EINVAL"); - { - char buf[4]; - int64 ret = sys_getcwd( - reinterpret_cast(buf), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EINVAL); - } - st_pass(); -} diff --git a/test/test_sys_mm.cc b/test/test_sys_mm.cc deleted file mode 100644 index 2c1a7dc..0000000 --- a/test/test_sys_mm.cc +++ /dev/null @@ -1,178 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include -#include -#include -#include - -/* sys_mm.cc APIs */ -int64 sys_brk(uint64 new_brk, uint64, uint64, uint64, uint64, uint64); -int64 sys_mmap(uint64 addr, uint64 length, uint64 prot, - uint64 flags, uint64 fd, uint64 offset); -int64 sys_munmap(uint64 addr, uint64 length, uint64, uint64, uint64, uint64); -int64 sys_mprotect(uint64 addr, uint64 len, uint64 prot, - uint64, uint64, uint64); - -void selftest_sys_mm() -{ - st_begin("sys_mm: mmap invalid arguments"); - { - TaskControlBlock* curr = current_task(); - VmSpace* old_mm = curr->mm; - - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - curr->mm = space; - - ST_ASSERT_EQ(sys_mmap(0, 0, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0), -EINVAL); - ST_ASSERT_EQ(sys_mmap(0, 0x1000, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 1), -EINVAL); - ST_ASSERT_EQ(sys_mmap(0, 0x1000, PROT_READ, 0, 0, 0), -EINVAL); - ST_ASSERT_EQ(sys_mmap(0, 0x1000, PROT_READ, MAP_PRIVATE | MAP_SHARED, 0, 0), -EINVAL); - ST_ASSERT_EQ(sys_mmap(0x123, 0x1000, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0), -EINVAL); - - curr->mm = old_mm; - space->destroy(); - } - st_pass(); - - st_begin("sys_mm: mmap/munmap/mprotect basic flow"); - { - TaskControlBlock* curr = current_task(); - VmSpace* old_mm = curr->mm; - - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - curr->mm = space; - - int64 addr = sys_mmap(0, 0x3000, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - ST_ASSERT(addr > 0); - - ST_ASSERT_EQ(vmm_handle_page_fault(space, addr, VmFaultCause::Read), 0); - - int64 mp = sys_mprotect(addr + kPageSize, kPageSize, PROT_READ, 0, 0, 0); - ST_ASSERT_EQ(mp, 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, addr + kPageSize, VmFaultCause::Write), -EFAULT); - - int64 mu = sys_munmap(addr, 0x3000, 0, 0, 0, 0); - ST_ASSERT_EQ(mu, 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, addr, VmFaultCause::Read), -EFAULT); - - curr->mm = old_mm; - space->destroy(); - } - st_pass(); - - st_begin("sys_mm: MAP_FIXED replaces existing mapping"); - { - TaskControlBlock* curr = current_task(); - VmSpace* old_mm = curr->mm; - - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - curr->mm = space; - - uint64 base = 0x600000; - ST_ASSERT_EQ(sys_mmap(base, 0x2000, PROT_READ, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0), - static_cast(base)); - - ST_ASSERT_EQ(sys_mmap(base, 0x1000, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0), - static_cast(base)); - - ST_ASSERT_EQ(vmm_handle_page_fault(space, base, VmFaultCause::Read), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, base, VmFaultCause::Write), 0); - - curr->mm = old_mm; - space->destroy(); - } - st_pass(); - - st_begin("sys_mm: mmap hint fallback on overlap"); - { - TaskControlBlock* curr = current_task(); - VmSpace* old_mm = curr->mm; - - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - curr->mm = space; - - uint64 base = 0x700000; - ST_ASSERT_EQ(sys_mmap(base, 0x2000, PROT_READ, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0), - static_cast(base)); - - int64 hint = sys_mmap(base, 0x1000, PROT_READ, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - ST_ASSERT(hint > 0); - ST_ASSERT(hint != static_cast(base)); - ST_ASSERT_EQ(vmm_handle_page_fault(space, hint, VmFaultCause::Read), 0); - - curr->mm = old_mm; - space->destroy(); - } - st_pass(); - - st_begin("sys_mm: brk growth and shrink"); - { - TaskControlBlock* curr = current_task(); - VmSpace* old_mm = curr->mm; - - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - curr->mm = space; - - int64 brk0 = sys_brk(0x400000, 0, 0, 0, 0, 0); - ST_ASSERT_EQ(brk0, 0x400000); - - int64 brk1 = sys_brk(0x402000, 0, 0, 0, 0, 0); - ST_ASSERT_EQ(brk1, 0x402000); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x400000, VmFaultCause::Read), 0); - - int64 brk2 = sys_brk(0x400000, 0, 0, 0, 0, 0); - ST_ASSERT_EQ(brk2, 0x400000); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x401000, VmFaultCause::Read), -EFAULT); - - curr->mm = old_mm; - space->destroy(); - } - st_pass(); - - st_begin("sys_mm: brk invalid shrink below start"); - { - TaskControlBlock* curr = current_task(); - VmSpace* old_mm = curr->mm; - - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - curr->mm = space; - - ST_ASSERT_EQ(sys_brk(0x500000, 0, 0, 0, 0, 0), 0x500000); - ST_ASSERT_EQ(sys_brk(0x4FF000, 0, 0, 0, 0, 0), -EINVAL); - - curr->mm = old_mm; - space->destroy(); - } - st_pass(); - - st_begin("sys_mm: mprotect invalid range"); - { - TaskControlBlock* curr = current_task(); - VmSpace* old_mm = curr->mm; - - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - curr->mm = space; - - ST_ASSERT_EQ(sys_mmap(0, 0x1000, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0) > 0, true); - ST_ASSERT_EQ(sys_mprotect(0x123, 0x1000, PROT_READ, 0, 0, 0), -EINVAL); - ST_ASSERT_EQ(sys_mprotect(0x900000, 0x1000, PROT_READ, 0, 0, 0), -ENOMEM); - - curr->mm = old_mm; - space->destroy(); - } - st_pass(); -} diff --git a/test/test_sys_process.cc b/test/test_sys_process.cc deleted file mode 100644 index 686bed6..0000000 --- a/test/test_sys_process.cc +++ /dev/null @@ -1,93 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_sys_process.cc — Self-tests for process-control syscalls - * - * Tests: getpid, gettid, getppid, getuid, getgid, set_tid_address, - * sched_yield, uname. - */ - -#include -#include -#include -#include - -/* Syscall entry points */ -int64 sys_getpid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_gettid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getppid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getuid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getgid(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_set_tid_address(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_sched_yield_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); - -void selftest_sys_process() -{ - /* ---- getpid returns current tgid ---- */ - st_begin("sys_process: getpid returns valid pid"); - { - int64 pid = sys_getpid(0, 0, 0, 0, 0, 0); - /* Boot task pid is -1 but tgid may differ; just verify it returns */ - TaskControlBlock* curr = current_task(); - ST_ASSERT_EQ(pid, (int64)curr->tgid); - } - st_pass(); - - /* ---- gettid returns current pid (tid) ---- */ - st_begin("sys_process: gettid returns current tid"); - { - int64 tid = sys_gettid(0, 0, 0, 0, 0, 0); - TaskControlBlock* curr = current_task(); - ST_ASSERT_EQ(tid, (int64)curr->pid); - } - st_pass(); - - /* ---- getppid returns parent tgid ---- */ - st_begin("sys_process: getppid returns parent tgid"); - { - int64 ppid = sys_getppid(0, 0, 0, 0, 0, 0); - TaskControlBlock* curr = current_task(); - int64 expected = curr->parent ? (int64)curr->parent->tgid : 0; - ST_ASSERT_EQ(ppid, expected); - } - st_pass(); - - /* ---- getuid returns 0 (root) ---- */ - st_begin("sys_process: getuid returns 0 (root)"); - { - int64 uid = sys_getuid(0, 0, 0, 0, 0, 0); - ST_ASSERT_EQ(uid, (int64)0); - } - st_pass(); - - /* ---- getgid returns 0 (root) ---- */ - st_begin("sys_process: getgid returns 0 (root)"); - { - int64 gid = sys_getgid(0, 0, 0, 0, 0, 0); - ST_ASSERT_EQ(gid, (int64)0); - } - st_pass(); - - /* ---- set_tid_address stores pointer and returns tid ---- */ - st_begin("sys_process: set_tid_address returns tid"); - { - uint64 dummy_addr = 0x12345678ULL; - int64 tid = sys_set_tid_address(dummy_addr, 0, 0, 0, 0, 0); - TaskControlBlock* curr = current_task(); - ST_ASSERT_EQ(tid, (int64)curr->pid); - ST_ASSERT_EQ(curr->clear_child_tid, dummy_addr); - - /* Reset it to avoid side effects */ - curr->clear_child_tid = 0; - } - st_pass(); - - /* ---- sched_yield returns 0 ---- */ - st_begin("sys_process: sched_yield returns 0"); - { - int64 ret = sys_sched_yield_wrapper(0, 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - } -} - diff --git a/test/test_trap.cc b/test/test_trap.cc deleted file mode 100644 index c91948a..0000000 --- a/test/test_trap.cc +++ /dev/null @@ -1,197 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot self-tests for the Trap/IRQ subsystem. - * - * Tests MD→MI translation, IrqManager register/dispatch/unregister, - * and stvec installation verification. - */ - -#include -#include -#include -#include -#include -#include -#include - -TrapCause trap_translate_scause(uint64 scause); - -/* ======================================================================== - * IrqManager test helpers - * ======================================================================== */ - -static volatile uint32 g_test_irq_fired = 0; -static volatile void* g_test_irq_arg = nullptr; - -static void test_irq_handler(uint32 irq, void* arg) -{ - g_test_irq_fired = irq; - g_test_irq_arg = arg; -} - -/* ======================================================================== - * Test cases - * ======================================================================== */ - -static bool test_stvec_installed() { - uint64 vec = arch::trap::get_vector(); - return vec != 0; -} - -static bool test_scause_exception_translation() { - /* Verify all exception causes map correctly */ - bool ok = true; - ok = ok && (trap_translate_scause(EXC_LOAD_PAGE_FAULT) == TrapCause::PageFaultLoad); - ok = ok && (trap_translate_scause(EXC_STORE_PAGE_FAULT) == TrapCause::PageFaultStore); - ok = ok && (trap_translate_scause(EXC_INST_PAGE_FAULT) == TrapCause::PageFaultExec); - ok = ok && (trap_translate_scause(EXC_ECALL_FROM_U) == TrapCause::Syscall); - ok = ok && (trap_translate_scause(EXC_ILLEGAL_INST) == TrapCause::IllegalInst); - ok = ok && (trap_translate_scause(EXC_BREAKPOINT) == TrapCause::Breakpoint); - ok = ok && (trap_translate_scause(EXC_LOAD_ACCESS_FAULT) == TrapCause::AccessFault); - ok = ok && (trap_translate_scause(EXC_INST_MISALIGNED) == TrapCause::AlignFault); - return ok; -} - -static bool test_scause_interrupt_translation() { - bool ok = true; - ok = ok && (trap_translate_scause(SCAUSE_INTERRUPT | IRQ_S_TIMER) == TrapCause::IrqTimer); - ok = ok && (trap_translate_scause(SCAUSE_INTERRUPT | IRQ_S_SOFTWARE) == TrapCause::IrqSoftware); - ok = ok && (trap_translate_scause(SCAUSE_INTERRUPT | IRQ_S_EXTERNAL) == TrapCause::IrqExternal); - ok = ok && (trap_translate_scause(SCAUSE_INTERRUPT | 99) == TrapCause::Unknown); - return ok; -} - -static bool test_scause_unknown() { - /* ecall from S-mode should map to Unknown (we only handle U-mode ecall) */ - return trap_translate_scause(EXC_ECALL_FROM_S) == TrapCause::Unknown; -} - -static bool test_irqmanager_register_dispatch() { - IrqManager mgr; - mgr.init(); - - g_test_irq_fired = 0; - g_test_irq_arg = nullptr; - - int dummy_arg = 42; - int ret = mgr.register_handler(10, test_irq_handler, &dummy_arg); - if (ret != 0) return false; - - /* Dispatch IRQ 10 — handler should be called */ - mgr.dispatch(10); - - if (g_test_irq_fired != 10) return false; - if (g_test_irq_arg != &dummy_arg) return false; - - return true; -} - -static bool test_irqmanager_unregister() { - IrqManager mgr; - mgr.init(); - - g_test_irq_fired = 0; - - mgr.register_handler(5, test_irq_handler, nullptr); - mgr.unregister_handler(5); - - /* Dispatch after unregister — handler should NOT be called */ - mgr.dispatch(5); - - return g_test_irq_fired == 0; -} - -static bool test_irqmanager_double_register() { - IrqManager mgr; - mgr.init(); - - int ret1 = mgr.register_handler(7, test_irq_handler, nullptr); - int ret2 = mgr.register_handler(7, test_irq_handler, nullptr); - - return ret1 == 0 && ret2 == -EBUSY; -} - -static bool test_irqmanager_invalid_irq() { - IrqManager mgr; - mgr.init(); - - int ret = mgr.register_handler(999, test_irq_handler, nullptr); - return ret == -EINVAL; -} - -static bool test_irqmanager_has_handler() { - IrqManager mgr; - mgr.init(); - - if (mgr.has_handler(10)) return false; /* not yet registered */ - - mgr.register_handler(10, test_irq_handler, nullptr); - if (!mgr.has_handler(10)) return false; /* now registered */ - - mgr.unregister_handler(10); - if (mgr.has_handler(10)) return false; /* unregistered */ - - return true; -} - -static bool test_irqmanager_spurious_dispatch() { - IrqManager mgr; - mgr.init(); - - g_test_irq_fired = 0; - - /* Dispatch an unregistered IRQ — should not crash or fire */ - mgr.dispatch(0); - mgr.dispatch(63); - - return g_test_irq_fired == 0; -} - -/* ======================================================================== - * Test runner - * ======================================================================== */ - -void selftest_trap() -{ - st_begin("trap: stvec is installed"); - ST_ASSERT(test_stvec_installed()); - st_pass(); - - st_begin("trap: scause exception translation"); - ST_ASSERT(test_scause_exception_translation()); - st_pass(); - - st_begin("trap: scause interrupt translation"); - ST_ASSERT(test_scause_interrupt_translation()); - st_pass(); - - st_begin("trap: scause unknown (ecall from S)"); - ST_ASSERT(test_scause_unknown()); - st_pass(); - - st_begin("trap: IrqManager register/dispatch"); - ST_ASSERT(test_irqmanager_register_dispatch()); - st_pass(); - - st_begin("trap: IrqManager unregister"); - ST_ASSERT(test_irqmanager_unregister()); - st_pass(); - - st_begin("trap: IrqManager double register"); - ST_ASSERT(test_irqmanager_double_register()); - st_pass(); - - st_begin("trap: IrqManager invalid IRQ"); - ST_ASSERT(test_irqmanager_invalid_irq()); - st_pass(); - - st_begin("trap: IrqManager has_handler"); - ST_ASSERT(test_irqmanager_has_handler()); - st_pass(); - - st_begin("trap: IrqManager spurious dispatch"); - ST_ASSERT(test_irqmanager_spurious_dispatch()); - st_pass(); -} diff --git a/test/test_uaccess.cc b/test/test_uaccess.cc deleted file mode 100644 index c5a8c6c..0000000 --- a/test/test_uaccess.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -void selftest_uaccess() -{ - /* To test valid user addresses (< kKernelVaBase), we need a writable page mapped there. - * We cannot use VmSpace::create() because it does not yet inherit kernel mappings, - * so switching to it hangs. We also cannot map it with the U bit because S-mode - * would need the SUM bit enabled. - * So we manually allocate a physical page and map it into the CURRENT page table - * at 0x100000 without the U bit, just for this test. - */ - uint64 mock_user_addr = 0x100000; - - uint64 satp; - asm volatile("csrr %0, satp" : "=r"(satp)); - uint64 root_pa = (satp & 0xFFFFFFFFFFFULL) << 12; - - Page* page = pmm_alloc_page(); - ST_ASSERT(page != nullptr); - uint64 paddr = page_to_pa(page).raw; - - pmap::map(root_pa, mock_user_addr, paddr, pmap::PTE_R | pmap::PTE_W | pmap::PTE_V | pmap::PTE_A | pmap::PTE_D); - - /* Flush TLB to see the new mapping */ - tlb_shootdown_all(); - - st_begin("uaccess: copy_to_user valid range"); - char kernel_buf[32] = "Hello User Space!"; - int ret = copy_to_user(mock_user_addr, kernel_buf, 18); - ST_ASSERT_EQ(ret, 0); - st_pass(); - - st_begin("uaccess: copy_from_user valid range"); - char read_buf[32] = {0}; - /* We wrote "Hello User Space!" to mock_user_addr previously */ - ret = copy_from_user(read_buf, mock_user_addr, 18); - ST_ASSERT_EQ(ret, 0); - ST_ASSERT(read_buf[0] == 'H'); - ST_ASSERT(read_buf[1] == 'e'); - ST_ASSERT(read_buf[6] == 'U'); - st_pass(); - - st_begin("uaccess: strncpy_from_user valid range"); - char str_buf[32] = {0}; - int64 len = strncpy_from_user(str_buf, mock_user_addr, 32); - ST_ASSERT_EQ(len, 17); /* "Hello User Space!" is 17 chars long */ - ST_ASSERT(str_buf[0] == 'H'); - st_pass(); - - st_begin("uaccess: strncpy_from_user max_len truncation"); - char trunc_buf[32] = {0}; - len = strncpy_from_user(trunc_buf, mock_user_addr, 6); - ST_ASSERT_EQ(len, 5); /* Will copy 5 chars and NUL terminate */ - ST_ASSERT(trunc_buf[4] == 'o'); - ST_ASSERT(trunc_buf[5] == '\0'); - st_pass(); - - st_begin("uaccess: copy_to_user invalid range (crosses boundary)"); - ret = copy_to_user(kKernelVaBase - 10, kernel_buf, 20); - ST_ASSERT_EQ(ret, -EFAULT); - st_pass(); - - st_begin("uaccess: copy_to_user invalid range (entirely in kernel)"); - ret = copy_to_user(kKernelVaBase + 0x1000, kernel_buf, 20); - ST_ASSERT_EQ(ret, -EFAULT); - st_pass(); - - st_begin("uaccess: copy_to_user invalid range (overflow)"); - ret = copy_to_user(0xFFFFFFFFFFFFFFF0ULL, kernel_buf, 0x100); - ST_ASSERT_EQ(ret, -EFAULT); - st_pass(); - - st_begin("uaccess: copy_from_user invalid ranges"); - ret = copy_from_user(read_buf, kKernelVaBase - 5, 10); - ST_ASSERT_EQ(ret, -EFAULT); - - ret = copy_from_user(read_buf, kKernelVaBase, 10); - ST_ASSERT_EQ(ret, -EFAULT); - st_pass(); - - st_begin("uaccess: strncpy_from_user invalid range"); - uint64 invalid_addr = kKernelVaBase + 0x1000; - len = strncpy_from_user(str_buf, invalid_addr, 10); - ST_ASSERT_EQ(len, -EFAULT); - st_pass(); -} diff --git a/test/test_vfs_io.cc b/test/test_vfs_io.cc deleted file mode 100644 index 3d3b125..0000000 --- a/test/test_vfs_io.cc +++ /dev/null @@ -1,345 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * test_vfs_io.cc — Self-tests for VFS file I/O via syscalls - * - * Tests openat, read, write, close, lseek, dup, fstat, getdents64, - * getcwd, chdir, and mkdirat through the kernel syscall layer. - */ - -#include -#include -#include -#include -#include -#include -#include - -/* Syscall entry points */ -int64 sys_openat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_close(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_read(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_write(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_lseek(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_dup(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_dup3(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_fstat_wrapper(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getcwd(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_chdir(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_mkdirat(uint64, uint64, uint64, uint64, uint64, uint64); -int64 sys_getdents64(uint64, uint64, uint64, uint64, uint64, uint64); - -/* Helper: open a file, returns fd or negative error */ -static int64 open_file(const char* path, int flags, uint32 mode) -{ - return sys_openat( - static_cast(-100), /* AT_FDCWD */ - reinterpret_cast(path), - static_cast(flags), - static_cast(mode), 0, 0); -} - -void selftest_vfs_io() -{ - /* ---- openat O_CREAT creates a file ---- */ - st_begin("vfs_io: openat O_CREAT creates file"); - { - int64 fd = open_file("/vfs_test_file", O_CREAT | O_WRONLY, 0644); - ST_ASSERT(fd >= 0); - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- openat existing file ---- */ - st_begin("vfs_io: openat existing file succeeds"); - { - int64 fd = open_file("/vfs_test_file", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- openat nonexistent without O_CREAT returns -ENOENT ---- */ - st_begin("vfs_io: openat nonexistent returns -ENOENT"); - { - int64 fd = open_file("/no_such_file_ever", O_RDONLY, 0); - ST_ASSERT_EQ(fd, (int64)-ENOENT); - } - st_pass(); - - /* ---- write then read ---- */ - st_begin("vfs_io: write then read back data"); - { - /* Write */ - int64 fd = open_file("/vfs_rw_test", O_CREAT | O_WRONLY, 0644); - ST_ASSERT(fd >= 0); - - const char* msg = "Hello VFS!"; - int64 written = sys_write( - static_cast(fd), - reinterpret_cast(msg), - 10, 0, 0, 0); - ST_ASSERT_EQ(written, (int64)10); - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - - /* Read */ - fd = open_file("/vfs_rw_test", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - char buf[32] = {}; - int64 nread = sys_read( - static_cast(fd), - reinterpret_cast(buf), - sizeof(buf), 0, 0, 0); - ST_ASSERT_EQ(nread, (int64)10); - - bool match = true; - for (int i = 0; i < 10; i++) { - if (buf[i] != msg[i]) { match = false; break; } - } - ST_ASSERT(match); - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- read past EOF returns 0 ---- */ - st_begin("vfs_io: read past EOF returns 0"); - { - int64 fd = open_file("/vfs_rw_test", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - char buf[64]; - /* First read: 10 bytes */ - int64 n1 = sys_read(static_cast(fd), - reinterpret_cast(buf), 64, 0, 0, 0); - ST_ASSERT_EQ(n1, (int64)10); - - /* Second read: should be 0 (EOF) */ - int64 n2 = sys_read(static_cast(fd), - reinterpret_cast(buf), 64, 0, 0, 0); - ST_ASSERT_EQ(n2, (int64)0); - - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- O_TRUNC clears file content ---- */ - st_begin("vfs_io: O_TRUNC clears file content"); - { - int64 fd = open_file("/vfs_rw_test", O_WRONLY | O_TRUNC, 0); - ST_ASSERT(fd >= 0); - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - - fd = open_file("/vfs_rw_test", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - char buf[16]; - int64 n = sys_read(static_cast(fd), - reinterpret_cast(buf), 16, 0, 0, 0); - ST_ASSERT_EQ(n, (int64)0); /* truncated = empty */ - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- close invalid fd returns -EBADF ---- */ - st_begin("vfs_io: close bad fd returns -EBADF"); - { - int64 ret = sys_close(999, 0, 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EBADF); - } - st_pass(); - - /* ---- read/write on bad fd returns -EBADF ---- */ - st_begin("vfs_io: read/write bad fd returns -EBADF"); - { - char buf[8]; - int64 r = sys_read(999, reinterpret_cast(buf), 8, 0, 0, 0); - ST_ASSERT_EQ(r, (int64)-EBADF); - - int64 w = sys_write(999, reinterpret_cast(buf), 8, 0, 0, 0); - ST_ASSERT_EQ(w, (int64)-EBADF); - } - st_pass(); - - /* ---- lseek SEEK_SET / SEEK_CUR / SEEK_END ---- */ - st_begin("vfs_io: lseek SEEK_SET/CUR/END"); - { - /* Write 20 bytes */ - int64 fd = open_file("/vfs_lseek_test", O_CREAT | O_RDWR, 0644); - ST_ASSERT(fd >= 0); - - char data[20]; - for (int i = 0; i < 20; i++) data[i] = static_cast('A' + i); - sys_write(static_cast(fd), - reinterpret_cast(data), 20, 0, 0, 0); - - /* SEEK_SET to 5 */ - int64 pos = sys_lseek(static_cast(fd), 5, SEEK_SET, 0, 0, 0); - ST_ASSERT_EQ(pos, (int64)5); - - /* Read 1 byte, should be 'F' */ - char c = 0; - sys_read(static_cast(fd), - reinterpret_cast(&c), 1, 0, 0, 0); - ST_ASSERT_EQ(c, 'F'); - - /* SEEK_CUR +3 → pos 9 */ - pos = sys_lseek(static_cast(fd), 3, SEEK_CUR, 0, 0, 0); - ST_ASSERT_EQ(pos, (int64)9); - - /* SEEK_END -1 → pos 19 */ - pos = sys_lseek(static_cast(fd), -1, SEEK_END, 0, 0, 0); - ST_ASSERT_EQ(pos, (int64)19); - - sys_read(static_cast(fd), - reinterpret_cast(&c), 1, 0, 0, 0); - ST_ASSERT_EQ(c, 'T'); - - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- lseek invalid whence returns -EINVAL ---- */ - st_begin("vfs_io: lseek invalid whence"); - { - int64 fd = open_file("/vfs_lseek_test", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - int64 ret = sys_lseek(static_cast(fd), 0, 99, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)-EINVAL); - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- dup: duplicate fd shares file position ---- */ - st_begin("vfs_io: dup shares file position"); - { - int64 fd1 = open_file("/vfs_lseek_test", O_RDONLY, 0); - ST_ASSERT(fd1 >= 0); - - int64 fd2 = sys_dup(static_cast(fd1), 0, 0, 0, 0, 0); - ST_ASSERT(fd2 >= 0); - ST_ASSERT_NE(fd1, fd2); - - /* Both should work for reading */ - char c = 0; - int64 n = sys_read(static_cast(fd2), - reinterpret_cast(&c), 1, 0, 0, 0); - ST_ASSERT_EQ(n, (int64)1); - - sys_close(static_cast(fd1), 0, 0, 0, 0, 0); - sys_close(static_cast(fd2), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- fstat: basic stat ---- */ - st_begin("vfs_io: fstat returns valid kstat"); - { - int64 fd = open_file("/vfs_lseek_test", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - kstat st{}; - int64 ret = sys_fstat_wrapper( - static_cast(fd), - reinterpret_cast(&st), 0, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - ST_ASSERT(S_ISREG(st.st_mode)); - ST_ASSERT_EQ(st.st_size, (int64)20); - - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- getcwd: returns "/" ---- */ - st_begin("vfs_io: getcwd returns /"); - { - char buf[64] = {}; - int64 len = sys_getcwd( - reinterpret_cast(buf), 64, 0, 0, 0, 0); - ST_ASSERT(len > 0); - ST_ASSERT_EQ(buf[0], '/'); - } - st_pass(); - - /* ---- mkdirat: create directory ---- */ - st_begin("vfs_io: mkdirat creates directory"); - { - int64 ret = sys_mkdirat( - static_cast(-100), - reinterpret_cast("/vfs_io_dir"), - 0755, 0, 0, 0); - ST_ASSERT_EQ(ret, (int64)0); - - /* Open it to confirm it's a directory */ - int64 fd = open_file("/vfs_io_dir", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - kstat st{}; - sys_fstat_wrapper(static_cast(fd), - reinterpret_cast(&st), 0, 0, 0, 0); - ST_ASSERT(S_ISDIR(st.st_mode)); - - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- getdents64: list root directory ---- */ - st_begin("vfs_io: getdents64 lists root children"); - { - int64 fd = open_file("/", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - char buf[512] = {}; - int64 n = sys_getdents64( - static_cast(fd), - reinterpret_cast(buf), - 512, 0, 0, 0); - ST_ASSERT(n > 0); /* At least "." and ".." */ - - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- write to O_RDONLY fd returns -EBADF ---- */ - st_begin("vfs_io: write to O_RDONLY returns -EBADF"); - { - int64 fd = open_file("/vfs_rw_test", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - char buf[] = "x"; - int64 w = sys_write(static_cast(fd), - reinterpret_cast(buf), 1, 0, 0, 0); - ST_ASSERT_EQ(w, (int64)-EBADF); - sys_close(static_cast(fd), 0, 0, 0, 0, 0); - } - st_pass(); - - /* ---- double close returns -EBADF ---- */ - st_begin("vfs_io: double close returns -EBADF"); - { - int64 fd = open_file("/vfs_rw_test", O_RDONLY, 0); - ST_ASSERT(fd >= 0); - - int64 r1 = sys_close(static_cast(fd), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(r1, (int64)0); - - int64 r2 = sys_close(static_cast(fd), 0, 0, 0, 0, 0); - ST_ASSERT_EQ(r2, (int64)-EBADF); - } - st_pass(); - - /* ---- fd reuse after close ---- */ - st_begin("vfs_io: fd reuse after close"); - { - int64 fd1 = open_file("/vfs_rw_test", O_RDONLY, 0); - ST_ASSERT(fd1 >= 0); - sys_close(static_cast(fd1), 0, 0, 0, 0, 0); - - int64 fd2 = open_file("/vfs_rw_test", O_RDONLY, 0); - ST_ASSERT(fd2 >= 0); - /* fd2 should reuse the slot of fd1 */ - ST_ASSERT(fd2 <= fd1); - sys_close(static_cast(fd2), 0, 0, 0, 0, 0); - } - st_pass(); -} diff --git a/test/test_vma.cc b/test/test_vma.cc deleted file mode 100644 index 5278914..0000000 --- a/test/test_vma.cc +++ /dev/null @@ -1,282 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include -#include -#include -#include - -void selftest_vma() { - st_begin("vma: create and destroy VmSpace"); - { - VmSpace* space = VmSpace::create(); - ST_ASSERT(space != nullptr); - ST_ASSERT(space->root_pa != 0); - - // Add a few regions to ensure destruction works - vmm_map_user(space, 0x1000, 0x1000, VM_READ); - vmm_map_user(space, 0x3000, 0x1000, VM_READ | VM_WRITE); - - space->destroy(); - } - st_pass(); - - st_begin("vma: map user region and handle demand paging"); - { - VmSpace* space = VmSpace::create(); - - // Map 8KB (2 pages) at 0x400000 using MI-layer flags - int ret = vmm_map_user(space, 0x400000, 0x2000, VM_READ | VM_WRITE); - ST_ASSERT_EQ(ret, 0); - - // Fault in the first page - ret = vmm_handle_page_fault(space, 0x400500, VmFaultCause::Read); - ST_ASSERT_EQ(ret, 0); - - // Verify mapping in hardware page table - uint64 pa = 0; - bool mapped = pmap::lookup(space->root_pa, 0x400000, &pa); - ST_ASSERT(mapped); - ST_ASSERT_NE(pa, 0ULL); - - // Fault in the second page - ret = vmm_handle_page_fault(space, 0x401FFF, VmFaultCause::Read); - ST_ASSERT_EQ(ret, 0); - - // Should reject fault outside VMA with -EFAULT - ret = vmm_handle_page_fault(space, 0x402000, VmFaultCause::Read); - ST_ASSERT_EQ(ret, -EFAULT); - - space->destroy(); - } - st_pass(); - - st_begin("vma: unmap user region prevents page fault"); - { - VmSpace* space = VmSpace::create(); - vmm_map_user(space, 0x10000, 0x2000, VM_READ); - - // Inside the region — should succeed - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x10500, VmFaultCause::Read), 0); - - // Unmap exactly - vmm_unmap_user(space, 0x10000, 0x2000); - - // Should fail now with -EFAULT - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x10500, VmFaultCause::Read), -EFAULT); - - space->destroy(); - } - st_pass(); - - st_begin("vma: duplicate page fault on same page returns 0"); - { - VmSpace* space = VmSpace::create(); - vmm_map_user(space, 0x200000, 0x1000, VM_READ | VM_WRITE); - - // First fault allocates the physical page - int ret = vmm_handle_page_fault(space, 0x200000, VmFaultCause::Read); - ST_ASSERT_EQ(ret, 0); - - // Second fault on the same page should hit "already mapped" path - ret = vmm_handle_page_fault(space, 0x200100, VmFaultCause::Read); - ST_ASSERT_EQ(ret, 0); - - // Verify both land on the same physical page - uint64 pa1 = 0, pa2 = 0; - pmap::lookup(space->root_pa, 0x200000, &pa1); - pmap::lookup(space->root_pa, 0x200100, &pa2); - // Same page, so PA for both addresses should be the same base page - ST_ASSERT_EQ(pa1, pa2); - - space->destroy(); - } - st_pass(); - - st_begin("vma: vm_perm_to_pte flag translation correctness"); - { - // Test each MI flag maps to correct hardware PTE bit - uint64 pte_r = pmap::vm_perm_to_pte(VM_READ); - ST_ASSERT(pte_r & pmap::PTE_R); - ST_ASSERT(!(pte_r & pmap::PTE_W)); - ST_ASSERT(!(pte_r & pmap::PTE_X)); - ST_ASSERT(!(pte_r & pmap::PTE_U)); - - uint64 pte_rw = pmap::vm_perm_to_pte(VM_READ | VM_WRITE); - ST_ASSERT(pte_rw & pmap::PTE_R); - ST_ASSERT(pte_rw & pmap::PTE_W); - - uint64 pte_rx = pmap::vm_perm_to_pte(VM_READ | VM_EXEC); - ST_ASSERT(pte_rx & pmap::PTE_R); - ST_ASSERT(pte_rx & pmap::PTE_X); - ST_ASSERT(!(pte_rx & pmap::PTE_W)); - - uint64 pte_u = pmap::vm_perm_to_pte(VM_READ | VM_USER); - ST_ASSERT(pte_u & pmap::PTE_R); - ST_ASSERT(pte_u & pmap::PTE_U); - - // All combined - uint64 pte_all = pmap::vm_perm_to_pte(VM_READ | VM_WRITE | VM_EXEC | VM_USER); - ST_ASSERT(pte_all & pmap::PTE_R); - ST_ASSERT(pte_all & pmap::PTE_W); - ST_ASSERT(pte_all & pmap::PTE_X); - ST_ASSERT(pte_all & pmap::PTE_U); - ST_ASSERT(pte_all & pmap::PTE_V); // Always valid - } - st_pass(); - - st_begin("vma: unmap subset only removes contained VMAs"); - { - VmSpace* space = VmSpace::create(); - // Map three separate regions - vmm_map_user(space, 0x50000, 0x1000, VM_READ); - vmm_map_user(space, 0x60000, 0x1000, VM_READ); - vmm_map_user(space, 0x70000, 0x1000, VM_READ); - - // Unmap only the middle one (range covers 0x60000-0x61000) - vmm_unmap_user(space, 0x60000, 0x1000); - - // First and third should still be reachable - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x50000, VmFaultCause::Read), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x70000, VmFaultCause::Read), 0); - - // Middle should fail - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x60000, VmFaultCause::Read), -EFAULT); - - space->destroy(); - } - st_pass(); - - st_begin("vma: null space returns -EINVAL"); - { - ST_ASSERT_EQ(vmm_map_user(nullptr, 0x1000, 0x1000, VM_READ), -EINVAL); - ST_ASSERT_EQ(vmm_unmap_user(nullptr, 0x1000, 0x1000), -EINVAL); - ST_ASSERT_EQ(vmm_handle_page_fault(nullptr, 0x1000, VmFaultCause::Read), -EINVAL); - } - st_pass(); - - st_begin("vma: clone and copy-on-write"); - { - VmSpace* parent = VmSpace::create(); - vmm_map_user(parent, 0x80000, 0x1000, VM_READ | VM_WRITE); - - /* Trigger read fault in parent to allocate physical page */ - ST_ASSERT_EQ(vmm_handle_page_fault(parent, 0x80000, VmFaultCause::Read), 0); - uint64 parent_pa_initial; - ST_ASSERT(pmap::lookup(parent->root_pa, 0x80000, &parent_pa_initial)); - - /* Clone the address space */ - VmSpace* child = vmm_clone(parent); - ST_ASSERT(child != nullptr); - - /* Verify child has the same physical page mapped but COW */ - uint64 child_pa; - ST_ASSERT(pmap::lookup(child->root_pa, 0x80000, &child_pa)); - ST_ASSERT_EQ(child_pa, parent_pa_initial); - ST_ASSERT(pmap::is_cow(child->root_pa, 0x80000)); - ST_ASSERT(pmap::is_cow(parent->root_pa, 0x80000)); /* Parent also marked COW */ - - /* Trigger Store Page Fault (cause=15) in child */ - ST_ASSERT_EQ(vmm_handle_page_fault(child, 0x80000, VmFaultCause::Write), 0); - - /* Child should now have a new physical page, no longer COW */ - uint64 child_pa_new; - ST_ASSERT(pmap::lookup(child->root_pa, 0x80000, &child_pa_new)); - ST_ASSERT(child_pa_new != parent_pa_initial); - ST_ASSERT(!pmap::is_cow(child->root_pa, 0x80000)); - - /* Parent is still mapped to the old page, still COW because it hasn't written */ - uint64 parent_pa_current; - ST_ASSERT(pmap::lookup(parent->root_pa, 0x80000, &parent_pa_current)); - ST_ASSERT_EQ(parent_pa_current, parent_pa_initial); - ST_ASSERT(pmap::is_cow(parent->root_pa, 0x80000)); - - /* Trigger Store Page Fault in parent */ - ST_ASSERT_EQ(vmm_handle_page_fault(parent, 0x80000, VmFaultCause::Write), 0); - ST_ASSERT(!pmap::is_cow(parent->root_pa, 0x80000)); - - child->destroy(); - parent->destroy(); - } - st_pass(); - - st_begin("vma: gap search finds next free range"); - { - VmSpace* space = VmSpace::create(); - vmm_map_user(space, 0x1000, 0x3000, VM_READ); - - uint64 va = mm_find_free_va(space, 0x1000, kPageSize); - ST_ASSERT_EQ(va, 0x4000ULL); - - space->destroy(); - } - st_pass(); - - st_begin("vma: reject overlapping mapping"); - { - VmSpace* space = VmSpace::create(); - ST_ASSERT_EQ(vmm_map_user(space, 0x20000, 0x2000, VM_READ), 0); - ST_ASSERT_EQ(vmm_map_user(space, 0x21000, 0x1000, VM_READ), -EINVAL); - space->destroy(); - } - st_pass(); - - st_begin("vma: partial unmap splits a single VMA"); - { - VmSpace* space = VmSpace::create(); - ST_ASSERT_EQ(vmm_map_user(space, 0x80000, 0x3000, VM_READ | VM_WRITE), 0); - - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x80000, VmFaultCause::Read), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x81000, VmFaultCause::Read), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x82000, VmFaultCause::Read), 0); - - ST_ASSERT_EQ(vmm_unmap_user(space, 0x81000, 0x1000), 0); - - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x80000, VmFaultCause::Read), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x82000, VmFaultCause::Read), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x81000, VmFaultCause::Read), -EFAULT); - - space->destroy(); - } - st_pass(); - - st_begin("vma: mprotect read-only blocks write faults"); - { - VmSpace* space = VmSpace::create(); - ST_ASSERT_EQ(vmm_map_user(space, 0x90000, 0x2000, VM_READ | VM_WRITE), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x90000, VmFaultCause::Read), 0); - - ST_ASSERT_EQ(vmm_protect_user(space, 0x90000, 0x1000, VM_READ), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x90000, VmFaultCause::Write), -EFAULT); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0x91000, VmFaultCause::Write), 0); - - space->destroy(); - } - st_pass(); - - st_begin("vma: PROT_NONE unmaps existing pages"); - { - VmSpace* space = VmSpace::create(); - ST_ASSERT_EQ(vmm_map_user(space, 0xA0000, 0x1000, VM_READ | VM_WRITE), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0xA0000, VmFaultCause::Read), 0); - - ST_ASSERT_EQ(vmm_protect_user(space, 0xA0000, 0x1000, 0), 0); - ST_ASSERT_EQ(vmm_handle_page_fault(space, 0xA0000, VmFaultCause::Read), -EFAULT); - - space->destroy(); - } - st_pass(); - - st_begin("vma: range covered check"); - { - VmSpace* space = VmSpace::create(); - ST_ASSERT_EQ(vmm_map_user(space, 0xB0000, 0x2000, VM_READ), 0); - - ST_ASSERT(vma_range_covered(space, 0xB0000, 0xB1000)); - ST_ASSERT(!vma_range_covered(space, 0xB0000, 0xB3000)); - - space->destroy(); - } - st_pass(); -} diff --git a/test/test_vmm.cc b/test/test_vmm.cc deleted file mode 100644 index 635e3f3..0000000 --- a/test/test_vmm.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -/* - * Boot Self-Test: VMM and Address Translation - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace { -constexpr uint64 kUartBase = 0x10000000ULL; -constexpr uint64 kPageOffsetMask = kPageSize - 1; -} - -void selftest_vmm() { - st_begin("vmm: virtual/physical address translation"); - { - PhysAddr pa = pmm_get_mem_base(); - VirtAddr va = pa_to_va(pa); - ST_ASSERT_EQ(va.raw, arch::g_direct_map_base + pa.raw); - ST_ASSERT_EQ(va_to_pa(va).raw, pa.raw); - - Pfn p = pa_to_pfn(pa); - ST_ASSERT_EQ(p.raw, pa.raw / kPageSize); - ST_ASSERT_EQ(pfn_to_pa(p).raw, pa.raw); - } - st_pass(); - - st_begin("vmm: page alignment macros"); - { - uint64 base = pmm_get_mem_base().raw; - uint64 addr = base + kPageOffsetMask; - ST_ASSERT_EQ(page_align_down(addr), base); - ST_ASSERT_EQ(page_align_up(addr), base + kPageSize); - ST_ASSERT_EQ(page_align_down(base), base); - ST_ASSERT_EQ(page_align_up(base), base); - } - st_pass(); - - st_begin("vmm: mapping kernel MMIO (driver API)"); - { - /* Use UART MMIO address (0x10000000 on RISC-V virt). - * Must NOT use pmm_get_mem_base() — that's PMP-protected firmware. */ - uint64 mmio_pa = kUartBase; - vmm_map_kernel_mmio(mmio_pa, kPageSize); - - // Verify it doesn't crash and address is reachable in higher half - uint64 va = pa_to_va(phys_addr(mmio_pa)).raw; - ST_ASSERT(va >= arch::g_direct_map_base); - } - st_pass(); -} diff --git a/test/test_waitqueue.cc b/test/test_waitqueue.cc deleted file mode 100644 index 7f50d6b..0000000 --- a/test/test_waitqueue.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Copyright (C) 2026 Richard Qin */ - -#include -#include -#include -#include - -static WaitQueue g_test_wq; -static volatile bool g_thread_woken = false; -static volatile bool g_thread_started = false; -static volatile int g_wake_count = 0; - -extern TaskControlBlock* kthread_create(const char* name, void (*entry)(void*), void* arg, uint8 priority); - -static void waitqueue_test_thread(void*) -{ - g_thread_started = true; - g_test_wq.sleep(); - g_thread_woken = true; - - extern void task_exit(int code); - task_exit(0); -} - -static void waitqueue_test_thread_all(void*) -{ - g_test_wq.sleep(); - __sync_fetch_and_add(&g_wake_count, 1); - - extern void task_exit(int code); - task_exit(0); -} - -void selftest_waitqueue() -{ - st_begin("waitqueue: sleep and wake_one"); - - g_test_wq.init("test_wq"); - g_thread_started = false; - g_thread_woken = false; - - TaskControlBlock* child = kthread_create("test_wq_child", waitqueue_test_thread, nullptr, 0); - ST_ASSERT(child != nullptr); - - sched_yield(); - - ST_ASSERT(g_thread_started == true); - ST_ASSERT(g_thread_woken == false); - ST_ASSERT(!g_test_wq.is_empty()); - - kprintf("[test_wq] waking child\n"); - bool woken = g_test_wq.wake_one(); - ST_ASSERT(woken == true); - ST_ASSERT(g_test_wq.is_empty()); - - kprintf("[test_wq] yielding to child again\n"); - sched_yield(); - kprintf("[test_wq] returned from yield 2\n"); - - ST_ASSERT(g_thread_woken == true); - - st_pass(); - - st_begin("waitqueue: wake_all"); - g_wake_count = 0; - for (int i = 0; i < 3; i++) { - kthread_create("test_wq_all", waitqueue_test_thread_all, nullptr, 0); - } - - /* Give all 3 threads a chance to start and sleep */ - kprintf("[test_wq] yielding 1 for wake_all\n"); - sched_yield(); - sched_yield(); - sched_yield(); - - ST_ASSERT(!g_test_wq.is_empty()); - - int woken_count = g_test_wq.wake_all(); - - ST_ASSERT_EQ(woken_count, 3); - ST_ASSERT(g_test_wq.is_empty()); - - /* Give all 3 threads a chance to wake up and run */ - sched_yield(); - sched_yield(); - sched_yield(); - - ST_ASSERT_EQ(g_wake_count, 3); - st_pass(); -} diff --git a/third_party/libcxx/LICENSE b/third_party/libcxx/LICENSE deleted file mode 100644 index d93fd2a..0000000 --- a/third_party/libcxx/LICENSE +++ /dev/null @@ -1,2989 +0,0 @@ -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== -University of Illinois/NCSA -Open Source License - -Copyright (c) 2007-2019 University of Illinois at Urbana-Champaign. -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== -University of Illinois/NCSA -Open Source License - -Copyright (c) 2007-2019 University of Illinois at Urbana-Champaign. -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== -University of Illinois/NCSA -Open Source License - -Copyright (c) 2011-2019 by the contributors listed in CREDITS.TXT -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== -University of Illinois/NCSA -Open Source License - -Copyright (c) 2003-2019 University of Illinois at Urbana-Champaign. -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. - -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== -University of Illinois/NCSA -Open Source License - -Copyright (c) 2009-2019 Polly Team -All rights reserved. - -Developed by: - - Polly Team - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the Polly Team, copyright holders, nor the names of - its contributors may be used to endorse or promote products derived from - this Software without specific prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== - -The compiler_rt library is dual licensed under both the University of Illinois -"BSD-Like" license and the MIT license. As a user of this code you may choose -to use it under either license. As a contributor, you agree to allow your code -to be used under both. - -Full text of the relevant licenses is included below. - -============================================================================== - -University of Illinois/NCSA -Open Source License - -Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT - -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. - -============================================================================== - -Copyright (c) 2009-2015 by the contributors listed in CREDITS.TXT - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== - -The libc++ library is dual licensed under both the University of Illinois -"BSD-Like" license and the MIT license. As a user of this code you may choose -to use it under either license. As a contributor, you agree to allow your code -to be used under both. - -Full text of the relevant licenses is included below. - -============================================================================== - -University of Illinois/NCSA -Open Source License - -Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT - -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. - -============================================================================== - -Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== - -The libc++abi library is dual licensed under both the University of Illinois -"BSD-Like" license and the MIT license. As a user of this code you may choose -to use it under either license. As a contributor, you agree to allow your code -to be used under both. - -Full text of the relevant licenses is included below. - -============================================================================== - -University of Illinois/NCSA -Open Source License - -Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT - -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. - -============================================================================== - -Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -============================================================================== -The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: -============================================================================== - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ----- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - -============================================================================== -Software from third parties included in the LLVM Project: -============================================================================== -The LLVM Project contains third party software which is under different license -terms. All such code will be identified clearly using at least one of two -mechanisms: -1) It will be in a separate directory tree with its own `LICENSE.txt` or - `LICENSE` file at the top containing the specific license and restrictions - which apply to that software, or -2) It will contain specific license and restriction terms at the top of every - file. - -============================================================================== -Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): -============================================================================== - -The libunwind library is dual licensed under both the University of Illinois -"BSD-Like" license and the MIT license. As a user of this code you may choose -to use it under either license. As a contributor, you agree to allow your code -to be used under both. - -Full text of the relevant licenses is included below. - -============================================================================== - -University of Illinois/NCSA -Open Source License - -Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT - -All rights reserved. - -Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - http://llvm.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal with -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimers in the - documentation and/or other materials provided with the distribution. - - * Neither the names of the LLVM Team, University of Illinois at - Urbana-Champaign, nor the names of its contributors may be used to - endorse or promote products derived from this Software without specific - prior written permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE -SOFTWARE. - -============================================================================== - -Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -============================================================================== - -MIT License (MIT) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -============================================================================== - -UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE - -See Terms of Use -for definitions of Unicode Inc.’s Data Files and Software. - -NOTICE TO USER: Carefully read the following legal agreement. -BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S -DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), -YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE -TERMS AND CONDITIONS OF THIS AGREEMENT. -IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE -THE DATA FILES OR SOFTWARE. - -COPYRIGHT AND PERMISSION NOTICE - -Copyright © 1991-2022 Unicode, Inc. All rights reserved. -Distributed under the Terms of Use in https://www.unicode.org/copyright.html. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Unicode data files and any associated documentation -(the "Data Files") or Unicode software and any associated documentation -(the "Software") to deal in the Data Files or Software -without restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, and/or sell copies of -the Data Files or Software, and to permit persons to whom the Data Files -or Software are furnished to do so, provided that either -(a) this copyright and permission notice appear with all copies -of the Data Files or Software, or -(b) this copyright and permission notice appear in associated -Documentation. - -THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT OF THIRD PARTY RIGHTS. -IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS -NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL -DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THE DATA FILES OR SOFTWARE. - -Except as contained in this notice, the name of a copyright holder -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in these Data Files or Software without prior -written authorization of the copyright holder. - -============================================================================== - -Except where otherwise noted in the source code (e.g. the files hash.c, -list.c and the trio files, which are covered by a similar licence but -with different Copyright notices) all the files are: - - Copyright (C) 1998-2012 Daniel Veillard. All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is fur- -nished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- -NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -============================================================================== - - Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - -============================================================================== - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - -Licenses for support code -------------------------- - -Parts of the TLS test suite are under the Go license. This code is not included -in BoringSSL (i.e. libcrypto and libssl) when compiled, however, so -distributing code linked against BoringSSL does not trigger this license: - -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/third_party/libcxx/README.lume b/third_party/libcxx/README.lume deleted file mode 100644 index 48f852f..0000000 --- a/third_party/libcxx/README.lume +++ /dev/null @@ -1,19 +0,0 @@ -libc++ header snapshot used by the LumeOS kernel build - -Upstream project: LLVM libc++ -Upstream repository: https://llvm.googlesource.com/llvm-project -LLVM revision: a3f244e2d5550e110daee562b88bee247b75d66c -Fuchsia revision: f8d670ab4bbb71bfb4d569893ba12fbb8a83bacd -Fuchsia package: fuchsia/third_party/clang/linux-amd64 -Fuchsia CIPD instance: OK_SEDKvq0UYv-R79oEeWcc3zd2zud7UQB23IxJkRdoC - -Imported files: - include/c++/v1 - LICENSE - source_manifest.json - -Only headers and provenance/license data are imported. LumeOS does not -vendor or link the package's libc++.a, libc++abi, or libunwind. The kernel's -KTL configuration overlay under lib/ktl and compiler builtins are maintained -separately. In particular, Linux/Fuchsia userland __config_site files from -the prebuilt package are intentionally not imported. diff --git a/third_party/libcxx/include/c++/v1/__algorithm/adjacent_find.h b/third_party/libcxx/include/c++/v1/__algorithm/adjacent_find.h deleted file mode 100644 index 2508250..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/adjacent_find.h +++ /dev/null @@ -1,60 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_ADJACENT_FIND_H -#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H - -#include <__algorithm/comp.h> -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/invoke.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter -__adjacent_find(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - if (__first == __last) - return __first; - - _Iter __i = __first; - while (++__i != __last) { - if (std::__invoke(__pred, std::__invoke(__proj, *__first), std::__invoke(__proj, *__i))) - return __first; - __first = __i; - } - return __i; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { - __identity __proj; - return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -adjacent_find(_ForwardIterator __first, _ForwardIterator __last) { - return std::adjacent_find(std::move(__first), std::move(__last), __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_ADJACENT_FIND_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/all_of.h b/third_party/libcxx/include/c++/v1/__algorithm/all_of.h deleted file mode 100644 index 9bdb20a..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/all_of.h +++ /dev/null @@ -1,48 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_ALL_OF_H -#define _LIBCPP___ALGORITHM_ALL_OF_H - -#include <__algorithm/any_of.h> -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/invoke.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -__all_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - using _Ref = decltype(std::__invoke(__proj, *__first)); - auto __negated_pred = [&__pred](_Ref __arg) -> bool { return !std::__invoke(__pred, std::forward<_Ref>(__arg)); }; - return !std::__any_of(std::move(__first), std::move(__last), __negated_pred, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - __identity __proj; - return std::__all_of(__first, __last, __pred, __proj); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_ALL_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/any_of.h b/third_party/libcxx/include/c++/v1/__algorithm/any_of.h deleted file mode 100644 index 4b6eb94..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/any_of.h +++ /dev/null @@ -1,42 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_ANY_OF_H -#define _LIBCPP___ALGORITHM_ANY_OF_H - -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/invoke.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -__any_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::__invoke(__pred, std::__invoke(__proj, *__first))) - return true; - } - return false; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - __identity __proj; - return std::__any_of(__first, __last, __pred, __proj); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_ANY_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/binary_search.h b/third_party/libcxx/include/c++/v1/__algorithm/binary_search.h deleted file mode 100644 index 4940059..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/binary_search.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_BINARY_SEARCH_H -#define _LIBCPP___ALGORITHM_BINARY_SEARCH_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/lower_bound.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp); - return __first != __last && !__comp(__value, *__first); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::binary_search(__first, __last, __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_BINARY_SEARCH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/clamp.h b/third_party/libcxx/include/c++/v1/__algorithm/clamp.h deleted file mode 100644 index 1a5a3d0..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/clamp.h +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_CLAMP_H -#define _LIBCPP___ALGORITHM_CLAMP_H - -#include <__algorithm/comp.h> -#include <__assert> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 -template -[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& -clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v, - _LIBCPP_LIFETIMEBOUND const _Tp& __lo, - _LIBCPP_LIFETIMEBOUND const _Tp& __hi, - _Compare __comp) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__comp(__hi, __lo), "Bad bounds passed to std::clamp"); - return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v; -} - -template -[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& -clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v, - _LIBCPP_LIFETIMEBOUND const _Tp& __lo, - _LIBCPP_LIFETIMEBOUND const _Tp& __hi) { - return std::clamp(__v, __lo, __hi, __less<>()); -} -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_CLAMP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/comp.h b/third_party/libcxx/include/c++/v1/__algorithm/comp.h deleted file mode 100644 index 38e2fb9..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/comp.h +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COMP_H -#define _LIBCPP___ALGORITHM_COMP_H - -#include <__config> -#include <__type_traits/desugars_to.h> -#include <__type_traits/is_generic_transparent_comparator.h> -#include <__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -struct __equal_to { - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T2& __y) const { - return __x == __y; - } -}; - -template -inline const bool __desugars_to_v<__equal_tag, __equal_to, _Tp, _Up> = true; - -// The definition is required because __less is part of the ABI, but it's empty -// because all comparisons should be transparent. -template -struct __less {}; - -template <> -struct __less { - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __lhs, const _Up& __rhs) const { - return __lhs < __rhs; - } -}; - -template -inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true; - -template -inline const bool __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> = is_integral<_Tp>::value; - -template <> -inline const bool __is_generic_transparent_comparator_v<__less<> > = true; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_COMP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/comp_ref_type.h b/third_party/libcxx/include/c++/v1/__algorithm/comp_ref_type.h deleted file mode 100644 index 6a9d5ce..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/comp_ref_type.h +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COMP_REF_TYPE_H -#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H - -#include <__assert> -#include <__config> -#include <__utility/declval.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __debug_less { - _Compare& __comp_; - _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {} - - template - _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Up& __y) { - bool __r = __comp_(__x, __y); - if (__r) - __do_compare_assert(0, __y, __x); - return __r; - } - - template - _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(_Tp& __x, _Up& __y) { - bool __r = __comp_(__x, __y); - if (__r) - __do_compare_assert(0, __y, __x); - return __r; - } - - template - _LIBCPP_CONSTEXPR_SINCE_CXX14 inline - _LIBCPP_HIDE_FROM_ABI decltype((void)std::declval<_Compare&>()(std::declval<_LHS&>(), std::declval<_RHS&>())) - __do_compare_assert(int, _LHS& __l, _RHS& __r) { - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering"); - (void)__l; - (void)__r; - } - - template - _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI void __do_compare_assert(long, _LHS&, _RHS&) {} -}; - -// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference. -#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -template -using __comp_ref_type _LIBCPP_NODEBUG = __debug_less<_Comp>; -#else -template -using __comp_ref_type _LIBCPP_NODEBUG = _Comp&; -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_COMP_REF_TYPE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/copy.h b/third_party/libcxx/include/c++/v1/__algorithm/copy.h deleted file mode 100644 index 344a53e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/copy.h +++ /dev/null @@ -1,135 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COPY_H -#define _LIBCPP___ALGORITHM_COPY_H - -#include <__algorithm/copy_move_common.h> -#include <__algorithm/for_each_segment.h> -#include <__algorithm/min.h> -#include <__algorithm/specialized_algorithms.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__type_traits/common_type.h> -#include <__type_traits/enable_if.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result); - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter); - -struct __copy_impl { - template , - __single_iterator<_OutIter> >::__has_algorithm, - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - while (__first != __last) { - *__result = *__first; - ++__first; - ++__result; - } - - return std::make_pair(std::move(__first), std::move(__result)); - } - - template , - __single_iterator<_OutIter> >::__has_algorithm, - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static pair<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) { - return __specialized_algorithm<_Algorithm::__copy, __iterator_pair<_InIter, _Sent>, __single_iterator<_OutIter> >()( - std::move(__first), std::move(__last), std::move(__result)); - } - - template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; - std::__for_each_segment(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__copy(std::move(__lfirst), std::move(__llast), std::move(__result)).second; - }); - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - using _DiffT = - typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type; - - if (__first == __last) - return std::make_pair(std::move(__first), std::move(__result)); - - auto __local_first = _Traits::__local(__result); - auto __segment_iterator = _Traits::__segment(__result); - while (true) { - auto __local_last = _Traits::__end(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iters = std::__copy(__first, __first + __size, __local_first); - __first = std::move(__iters.first); - - if (__first == __last) - return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); - - __local_first = _Traits::__begin(++__segment_iterator); - } - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> - operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_trivial_impl(__first, __last, __result); - } -}; - -template -pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 -__copy(_InIter __first, _Sent __last, _OutIter __result) { - return std::__copy_move_unwrap_iters<__copy_impl>(std::move(__first), std::move(__last), std::move(__result)); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::__copy(__first, __last, __result).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/copy_backward.h b/third_party/libcxx/include/c++/v1/__algorithm/copy_backward.h deleted file mode 100644 index 8758d2c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/copy_backward.h +++ /dev/null @@ -1,255 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COPY_BACKWARD_H -#define _LIBCPP___ALGORITHM_COPY_BACKWARD_H - -#include <__algorithm/copy_move_common.h> -#include <__algorithm/copy_n.h> -#include <__algorithm/for_each_segment.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> -#include <__config> -#include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__memory/pointer_traits.h> -#include <__type_traits/common_type.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter> -__copy_backward(_InIter __first, _Sent __last, _OutIter __result); - -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_aligned( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__last.__ctz_ != 0) { - difference_type __dn = std::min(static_cast(__last.__ctz_), __n); - __n -= __dn; - unsigned __clz = __bits_per_word - __last.__ctz_; - __storage_type __m = std::__middle_mask<__storage_type>(__clz, __last.__ctz_ - __dn); - __storage_type __b = *__last.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); - // __last.__ctz_ = 0 - } - // __last.__ctz_ == 0 || __n == 0 - // __result.__ctz_ == 0 || __n == 0 - // do middle words - __storage_type __nw = __n / __bits_per_word; - __result.__seg_ -= __nw; - __last.__seg_ -= __nw; - std::copy_n(std::__to_address(__last.__seg_), __nw, std::__to_address(__result.__seg_)); - __n -= __nw * __bits_per_word; - // do last word - if (__n > 0) { - __storage_type __m = std::__leading_mask<__storage_type>(__bits_per_word - __n); - __storage_type __b = *--__last.__seg_ & __m; - *--__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); - } - } - return __result; -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_unaligned( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__last.__ctz_ != 0) { - difference_type __dn = std::min(static_cast(__last.__ctz_), __n); - __n -= __dn; - unsigned __clz_l = __bits_per_word - __last.__ctz_; - __storage_type __m = std::__middle_mask<__storage_type>(__clz_l, __last.__ctz_ - __dn); - __storage_type __b = *__last.__seg_ & __m; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __ddn = std::min(__dn, static_cast(__result.__ctz_)); - if (__ddn > 0) { - __m = std::__middle_mask<__storage_type>(__clz_r, __result.__ctz_ - __ddn); - *__result.__seg_ &= ~__m; - if (__result.__ctz_ > __last.__ctz_) - *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); - else - *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_); - __result.__ctz_ = static_cast(((-__ddn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); - __dn -= __ddn; - } - if (__dn > 0) { - // __result.__ctz_ == 0 - --__result.__seg_; - __result.__ctz_ = static_cast(-__dn & (__bits_per_word - 1)); - __m = std::__leading_mask<__storage_type>(__result.__ctz_); - *__result.__seg_ &= ~__m; - __last.__ctz_ -= __dn + __ddn; - *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); - } - // __last.__ctz_ = 0 - } - // __last.__ctz_ == 0 || __n == 0 - // __result.__ctz_ != 0 || __n == 0 - // do middle words - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __m = std::__trailing_mask<__storage_type>(__clz_r); - for (; __n >= __bits_per_word; __n -= __bits_per_word) { - __storage_type __b = *--__last.__seg_; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> __clz_r; - *--__result.__seg_ &= __m; - *__result.__seg_ |= __b << __result.__ctz_; - } - // do last word - if (__n > 0) { - __m = std::__leading_mask<__storage_type>(__bits_per_word - __n); - __storage_type __b = *--__last.__seg_ & __m; - __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __dn = std::min(__n, static_cast(__result.__ctz_)); - __m = std::__middle_mask<__storage_type>(__clz_r, __result.__ctz_ - __dn); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_); - __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - // __result.__ctz_ == 0 - --__result.__seg_; - __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); - __m = std::__leading_mask<__storage_type>(__result.__ctz_); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn)); - } - } - } - return __result; -} - -template -struct __copy_backward_impl { - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - auto __original_last_iter = __last_iter; - - while (__first != __last_iter) { - *--__result = *--__last_iter; - } - - return std::make_pair(std::move(__original_last_iter), std::move(__result)); - } - - template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; - std::__for_each_segment_backward(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__copy_backward<_AlgPolicy>(std::move(__lfirst), std::move(__llast), std::move(__result)).second; - }); - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - auto __orig_last = __last; - auto __segment_iterator = _Traits::__segment(__result); - - // When the range contains no elements, __result might not be a valid iterator - if (__first == __last) - return std::make_pair(__first, __result); - - auto __local_last = _Traits::__local(__result); - while (true) { - using _DiffT = - typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type; - - auto __local_first = _Traits::__begin(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iter = std::__copy_backward<_AlgPolicy>(__last - __size, __last, __local_last).second; - __last -= __size; - - if (__first == __last) - return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); - --__segment_iterator; - __local_last = _Traits::__end(__segment_iterator); - } - } - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > - operator()(__bit_iterator<_Cp, _IsConst> __first, - __bit_iterator<_Cp, _IsConst> __last, - __bit_iterator<_Cp, false> __result) { - if (__last.__ctz_ == __result.__ctz_) - return std::make_pair(__last, std::__copy_backward_aligned(__first, __last, __result)); - return std::make_pair(__last, std::__copy_backward_unaligned(__first, __last, __result)); - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> - operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_backward_trivial_impl(__first, __last, __result); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> -__copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { - return std::__copy_move_unwrap_iters<__copy_backward_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2 -copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && - std::is_copy_constructible<_BidirectionalIterator1>::value, - "Iterators must be copy constructible."); - - return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_COPY_BACKWARD_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/copy_if.h b/third_party/libcxx/include/c++/v1/__algorithm/copy_if.h deleted file mode 100644 index ffea621..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/copy_if.h +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COPY_IF_H -#define _LIBCPP___ALGORITHM_COPY_IF_H - -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/invoke.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> -__copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::__invoke(__pred, std::__invoke(__proj, *__first))) { - *__result = *__first; - ++__result; - } - } - return std::make_pair(std::move(__first), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { - __identity __proj; - return std::__copy_if(__first, __last, __result, __pred, __proj).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/copy_move_common.h b/third_party/libcxx/include/c++/v1/__algorithm/copy_move_common.h deleted file mode 100644 index 7471012..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/copy_move_common.h +++ /dev/null @@ -1,113 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H -#define _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H - -#include <__algorithm/unwrap_iter.h> -#include <__algorithm/unwrap_range.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__iterator/iterator_traits.h> -#include <__memory/pointer_traits.h> -#include <__string/constexpr_c_functions.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_always_bitcastable.h> -#include <__type_traits/is_constant_evaluated.h> -#include <__type_traits/is_constructible.h> -#include <__type_traits/is_trivially_assignable.h> -#include <__type_traits/is_volatile.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Type traits. - -template -struct __can_lower_copy_assignment_to_memmove { - static const bool value = - // If the types are always bitcastable, it's valid to do a bitwise copy between them. - __is_always_bitcastable<_From, _To>::value && - // Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays). - is_trivially_assignable<_To&, const _From&>::value && - // `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case. - !is_volatile<_From>::value && !is_volatile<_To>::value; -}; - -template -struct __can_lower_move_assignment_to_memmove { - static const bool value = - __is_always_bitcastable<_From, _To>::value && is_trivially_assignable<_To&, _From&&>::value && - !is_volatile<_From>::value && !is_volatile<_To>::value; -}; - -// `memmove` algorithms implementation. - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> -__copy_trivial_impl(_In* __first, _In* __last, _Out* __result) { - const size_t __n = static_cast(__last - __first); - - std::__constexpr_memmove(__result, __first, __element_count(__n)); - - return std::make_pair(__last, __result + __n); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> -__copy_backward_trivial_impl(_In* __first, _In* __last, _Out* __result) { - const size_t __n = static_cast(__last - __first); - __result -= __n; - - std::__constexpr_memmove(__result, __first, __element_count(__n)); - - return std::make_pair(__last, __result); -} - -// Iterator unwrapping and dispatching to the correct overload. - -template -struct __can_rewrap - : integral_constant::value && is_copy_constructible<_OutIter>::value> {}; - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter> -__copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) { - auto __range = std::__unwrap_range(__first, std::move(__last)); - auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first)); - return std::make_pair(std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.first)), - std::__rewrap_iter(std::move(__out_first), std::move(__result.second))); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter> -__copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) { - return _Algorithm()(std::move(__first), std::move(__last), std::move(__out_first)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/copy_n.h b/third_party/libcxx/include/c++/v1/__algorithm/copy_n.h deleted file mode 100644 index 56fb448..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/copy_n.h +++ /dev/null @@ -1,94 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COPY_N_H -#define _LIBCPP___ALGORITHM_COPY_N_H - -#include <__algorithm/copy.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/enable_if.h> -#include <__utility/convert_to_integral.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter> -__copy_n(_InIter __first, typename _IterOps<_AlgPolicy>::template __difference_type<_InIter> __n, _OutIter __result) { - return std::__copy(__first, __first + __n, std::move(__result)); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter> -__copy_n(_InIter __first, typename _IterOps<_AlgPolicy>::template __difference_type<_InIter> __n, _OutIter __result) { - while (__n != 0) { - *__result = *__first; - ++__first; - ++__result; - --__n; - } - return std::make_pair(std::move(__first), std::move(__result)); -} - -// The InputIterator case is handled specially here because it's been written in a way to avoid incrementing __first -// if not absolutely required. This was done to allow its use with istream_iterator and we want to avoid breaking -// people, at least currently. -// See https://github.com/llvm/llvm-project/commit/99847d2bf132854fffa019bab19818768102ccad -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -copy_n(_InputIterator __first, _Size __n, _OutputIterator __result) { - using _IntegralSize = decltype(std::__convert_to_integral(__n)); - _IntegralSize __converted = __n; - if (__converted > 0) { - *__result = *__first; - ++__result; - for (--__converted; __converted > 0; --__converted) { - ++__first; - *__result = *__first; - ++__result; - } - } - return __result; -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -copy_n(_InputIterator __first, _Size __n, _OutputIterator __result) { - using _IntegralSize = decltype(std::__convert_to_integral(__n)); - _IntegralSize __converted = __n; - return std::__copy_n<_ClassicAlgPolicy>(__first, __iterator_difference_type<_InputIterator>(__converted), __result) - .second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_COPY_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/count.h b/third_party/libcxx/include/c++/v1/__algorithm/count.h deleted file mode 100644 index 8529d11..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/count.h +++ /dev/null @@ -1,95 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COUNT_H -#define _LIBCPP___ALGORITHM_COUNT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> -#include <__bit/invert_if.h> -#include <__bit/popcount.h> -#include <__config> -#include <__functional/identity.h> -#include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// generic implementation -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> -__count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __r(0); - for (; __first != __last; ++__first) - if (std::__invoke(__proj, *__first) == __value) - ++__r; - return __r; -} - -// __bit_iterator implementation -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bit_iterator<_Cp, _IsConst>::difference_type -__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) { - using _It = __bit_iterator<_Cp, _IsConst>; - using __storage_type = typename _It::__storage_type; - using difference_type = typename _It::difference_type; - - const int __bits_per_word = _It::__bits_per_word; - difference_type __r = 0; - // do first partial word - if (__first.__ctz_ != 0) { - __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); - __storage_type __dn = std::min(__clz_f, __n); - __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first.__ctz_); - __r = std::__popcount(__storage_type(std::__invert_if(*__first.__seg_) & __m)); - __n -= __dn; - ++__first.__seg_; - } - // do middle whole words - for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) - __r += std::__popcount(std::__invert_if(*__first.__seg_)); - // do last partial word - if (__n > 0) { - __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - __r += std::__popcount(__storage_type(std::__invert_if(*__first.__seg_) & __m)); - } - return __r; -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iterator_difference_type<__bit_iterator<_Cp, _IsConst> > -__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) { - if (__value) - return std::__count_bool( - __first, static_cast::size_type>(__last - __first)); - return std::__count_bool( - __first, static_cast::size_type>(__last - __first)); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iterator_difference_type<_InputIterator> -count(_InputIterator __first, _InputIterator __last, const _Tp& __value) { - __identity __proj; - return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_COUNT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/count_if.h b/third_party/libcxx/include/c++/v1/__algorithm/count_if.h deleted file mode 100644 index 26f945e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/count_if.h +++ /dev/null @@ -1,46 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_COUNT_IF_H -#define _LIBCPP___ALGORITHM_COUNT_IF_H - -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/invoke.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t<_AlgPolicy, _Iter> -__count_if(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - __policy_iter_diff_t<_AlgPolicy, _Iter> __counter(0); - for (; __first != __last; ++__first) { - if (std::__invoke(__pred, std::__invoke(__proj, *__first))) - ++__counter; - } - return __counter; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 -typename iterator_traits<_InputIterator>::difference_type -count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - __identity __proj; - return std::__count_if<_ClassicAlgPolicy>(__first, __last, __pred, __proj); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_COUNT_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/equal.h b/third_party/libcxx/include/c++/v1/__algorithm/equal.h deleted file mode 100644 index b6247c1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/equal.h +++ /dev/null @@ -1,325 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_EQUAL_H -#define _LIBCPP___ALGORITHM_EQUAL_H - -#include <__algorithm/comp.h> -#include <__algorithm/find_segment_if.h> -#include <__algorithm/min.h> -#include <__algorithm/unwrap_iter.h> -#include <__config> -#include <__functional/identity.h> -#include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__string/constexpr_c_functions.h> -#include <__type_traits/common_type.h> -#include <__type_traits/desugars_to.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_equality_comparable.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_volatile.h> -#include <__utility/move.h> -#include <__utility/unreachable.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool -__equal_unaligned(__bit_iterator<_Cp, _IsConst1> __first1, - __bit_iterator<_Cp, _IsConst1> __last1, - __bit_iterator<_Cp, _IsConst2> __first2) { - using _It = __bit_iterator<_Cp, _IsConst1>; - using difference_type = typename _It::difference_type; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - difference_type __n = __last1 - __first1; - if (__n > 0) { - // do first word - if (__first1.__ctz_ != 0) { - unsigned __clz_f = __bits_per_word - __first1.__ctz_; - difference_type __dn = std::min(static_cast(__clz_f), __n); - __n -= __dn; - __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first1.__ctz_); - __storage_type __b = *__first1.__seg_ & __m; - unsigned __clz_r = __bits_per_word - __first2.__ctz_; - __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); - __m = std::__middle_mask<__storage_type>(__clz_r - __ddn, __first2.__ctz_); - if (__first2.__ctz_ > __first1.__ctz_) { - if (static_cast<__storage_type>(*__first2.__seg_ & __m) != - static_cast<__storage_type>(__b << (__first2.__ctz_ - __first1.__ctz_))) - return false; - } else { - if (static_cast<__storage_type>(*__first2.__seg_ & __m) != - static_cast<__storage_type>(__b >> (__first1.__ctz_ - __first2.__ctz_))) - return false; - } - __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word; - __first2.__ctz_ = static_cast((__ddn + __first2.__ctz_) % __bits_per_word); - __dn -= __ddn; - if (__dn > 0) { - __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - if (static_cast<__storage_type>(*__first2.__seg_ & __m) != - static_cast<__storage_type>(__b >> (__first1.__ctz_ + __ddn))) - return false; - __first2.__ctz_ = static_cast(__dn); - } - ++__first1.__seg_; - // __first1.__ctz_ = 0; - } - // __first1.__ctz_ == 0; - // do middle words - unsigned __clz_r = __bits_per_word - __first2.__ctz_; - __storage_type __m = std::__leading_mask<__storage_type>(__first2.__ctz_); - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) { - __storage_type __b = *__first1.__seg_; - if (static_cast<__storage_type>(*__first2.__seg_ & __m) != static_cast<__storage_type>(__b << __first2.__ctz_)) - return false; - ++__first2.__seg_; - if (static_cast<__storage_type>(*__first2.__seg_ & static_cast<__storage_type>(~__m)) != - static_cast<__storage_type>(__b >> __clz_r)) - return false; - } - // do last word - if (__n > 0) { - __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - __storage_type __b = *__first1.__seg_ & __m; - __storage_type __dn = std::min(__n, static_cast(__clz_r)); - __m = std::__middle_mask<__storage_type>(__clz_r - __dn, __first2.__ctz_); - if (static_cast<__storage_type>(*__first2.__seg_ & __m) != static_cast<__storage_type>(__b << __first2.__ctz_)) - return false; - __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word; - __first2.__ctz_ = static_cast((__dn + __first2.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - if (static_cast<__storage_type>(*__first2.__seg_ & __m) != static_cast<__storage_type>(__b >> __dn)) - return false; - } - } - } - return true; -} - -template -[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool -__equal_aligned(__bit_iterator<_Cp, _IsConst1> __first1, - __bit_iterator<_Cp, _IsConst1> __last1, - __bit_iterator<_Cp, _IsConst2> __first2) { - using _It = __bit_iterator<_Cp, _IsConst1>; - using difference_type = typename _It::difference_type; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - difference_type __n = __last1 - __first1; - if (__n > 0) { - // do first word - if (__first1.__ctz_ != 0) { - unsigned __clz = __bits_per_word - __first1.__ctz_; - difference_type __dn = std::min(static_cast(__clz), __n); - __n -= __dn; - __storage_type __m = std::__middle_mask<__storage_type>(__clz - __dn, __first1.__ctz_); - if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) - return false; - ++__first2.__seg_; - ++__first1.__seg_; - // __first1.__ctz_ = 0; - // __first2.__ctz_ = 0; - } - // __first1.__ctz_ == 0; - // __first2.__ctz_ == 0; - // do middle words - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_) - if (*__first2.__seg_ != *__first1.__seg_) - return false; - // do last word - if (__n > 0) { - __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) - return false; - } - } - return true; -} - -template ::value && __is_identity<_Proj2>::value && - __desugars_to_v<__equal_tag, _BinaryPredicate, bool, bool>, - int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl( - __bit_iterator<_Cp, _IsConst1> __first1, - __bit_iterator<_Cp, _IsConst1> __last1, - __bit_iterator<_Cp, _IsConst2> __first2, - _BinaryPredicate, - _Proj1&, - _Proj2&) { - if (__first1.__ctz_ == __first2.__ctz_) - return std::__equal_aligned(__first1, __last1, __first2); - return std::__equal_unaligned(__first1, __last1, __first2); -} - -template ::value && __is_identity<_Proj2>::value && - __desugars_to_v<__equal_tag, _BinaryPredicate, _Tp, _Up> && !is_volatile<_Tp>::value && - !is_volatile<_Up>::value && __is_trivially_equality_comparable_v<_Tp, _Up>, - int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -__equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&, _Proj1&, _Proj2&) { - return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1)); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { -#ifndef _LIBCPP_CXX03_LANG - if constexpr (__has_random_access_iterator_category<_InIter1>::value && - __has_random_access_iterator_category<_InIter2>::value) { - if constexpr (is_same<_InIter1, _Sent1>::value && __is_segmented_iterator_v<_InIter1>) { - using __local_iterator_t = typename __segmented_iterator_traits<_InIter1>::__local_iterator; - bool __is_equal = true; - std::__find_segment_if(__first1, __last1, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) { - if (std::__equal_iter_impl( - std::__unwrap_iter(__lfirst), std::__unwrap_iter(__llast), __first2, __pred, __proj1, __proj2)) { - __first2 += __llast - __lfirst; - return __llast; - } - __is_equal = false; - return __lfirst; - }); - return __is_equal; - } else if constexpr (__is_segmented_iterator_v<_InIter2>) { - using _Traits = __segmented_iterator_traits<_InIter2>; - using _DiffT = - typename common_type<__iterator_difference_type<_InIter1>, __iterator_difference_type<_InIter2> >::type; - - if (__first1 == __last1) - return true; - - auto __local_first = _Traits::__local(__first2); - auto __segment_iterator = _Traits::__segment(__first2); - - while (true) { - auto __local_last = _Traits::__end(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last1 - __first1); - if (!std::__equal_iter_impl( - __first1, __first1 + __size, std::__unwrap_iter(__local_first), __pred, __proj1, __proj2)) - return false; - - __first1 += __size; - if (__first1 == __last1) - return true; - - __local_first = _Traits::__begin(++__segment_iterator); - } - } - } -#endif - for (; __first1 != __last1; ++__first1, (void)++__first2) - if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - return false; - return true; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { - __identity __proj; - return std::__equal_iter_impl( - std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred, __proj, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { - return std::equal(__first1, __last1, __first2, __equal_to()); -} - -#if _LIBCPP_STD_VER >= 14 - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __comp, _Proj1& __proj1, _Proj2& __proj2) { - if constexpr (__known_equal_length) { - return std::__equal_iter_impl( - std::move(__first1), std::move(__last1), std::move(__first2), __comp, __proj1, __proj2); - } else { - while (__first1 != __last1 && __first2 != __last2) { - if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - return false; - ++__first1; - ++__first2; - } - return __first1 == __last1 && __first2 == __last2; - } -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -equal(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _BinaryPredicate __pred) { - constexpr bool __both_random_access = - __has_random_access_iterator_category<_InputIterator1>::value && - __has_random_access_iterator_category<_InputIterator2>::value; - if constexpr (__both_random_access) { - if (__last1 - __first1 != __last2 - __first2) - return false; - } - __identity __proj; - return std::__equal_impl<__both_random_access>( - std::__unwrap_iter(__first1), - std::__unwrap_iter(__last1), - std::__unwrap_iter(__first2), - std::__unwrap_iter(__last2), - __pred, - __proj, - __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - return std::equal(__first1, __last1, __first2, __last2, __equal_to()); -} - -#endif // _LIBCPP_STD_VER >= 14 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_EQUAL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/equal_range.h b/third_party/libcxx/include/c++/v1/__algorithm/equal_range.h deleted file mode 100644 index ff6f4f2..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/equal_range.h +++ /dev/null @@ -1,81 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_EQUAL_RANGE_H -#define _LIBCPP___ALGORITHM_EQUAL_RANGE_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/half_positive.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/lower_bound.h> -#include <__algorithm/upper_bound.h> -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter> -__equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) { - auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); - _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); - while (__len != 0) { - auto __half_len = std::__half_positive(__len); - _Iter __mid = _IterOps<_AlgPolicy>::next(__first, __half_len); - if (std::__invoke(__comp, std::__invoke(__proj, *__mid), __value)) { - __first = ++__mid; - __len -= __half_len + 1; - } else if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid))) { - __end = __mid; - __len = __half_len; - } else { - _Iter __mp1 = __mid; - return pair<_Iter, _Iter>(std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj), - std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj)); - } - } - return pair<_Iter, _Iter>(__first, __first); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> -equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); - static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); - return std::__equal_range<_ClassicAlgPolicy>( - std::move(__first), - std::move(__last), - __value, - static_cast<__comp_ref_type<_Compare> >(__comp), - std::__identity()); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> -equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::equal_range(std::move(__first), std::move(__last), __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_EQUAL_RANGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/fill.h b/third_party/libcxx/include/c++/v1/__algorithm/fill.h deleted file mode 100644 index 37732cc..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/fill.h +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FILL_H -#define _LIBCPP___ALGORITHM_FILL_H - -#include <__algorithm/fill_n.h> -#include <__algorithm/for_each_segment.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_same.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset. - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -__fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __value) { -#ifndef _LIBCPP_CXX03_LANG - if constexpr (is_same<_ForwardIterator, _Sentinel>::value && __is_segmented_iterator_v<_ForwardIterator>) { - using __local_iterator_t = typename __segmented_iterator_traits<_ForwardIterator>::__local_iterator; - std::__for_each_segment(__first, __last, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) { - std::__fill(__lfirst, __llast, __value); - }); - return __last; - } -#endif - for (; __first != __last; ++__first) - *__first = __value; - return __first; -} - -template ::value && - !__is_segmented_iterator_v<_RandomAccessIterator>, - int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator -__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value) { - return std::__fill_n(__first, __last - __first, __value); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - std::__fill(__first, __last, __value); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FILL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/fill_n.h b/third_party/libcxx/include/c++/v1/__algorithm/fill_n.h deleted file mode 100644 index 3d06ea4..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/fill_n.h +++ /dev/null @@ -1,75 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FILL_N_H -#define _LIBCPP___ALGORITHM_FILL_N_H - -#include <__algorithm/for_each_n_segment.h> -#include <__algorithm/specialized_algorithms.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__type_traits/enable_if.h> -#include <__utility/convert_to_integral.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset. - -template < - class _OutputIterator, - class _Size, - class _Tp, - __enable_if_t >::__has_algorithm, - int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) { -#ifndef _LIBCPP_CXX03_LANG - if constexpr (__is_segmented_iterator_v<_OutputIterator>) { - using __local_iterator = typename __segmented_iterator_traits<_OutputIterator>::__local_iterator; - if constexpr (__has_random_access_iterator_category<__local_iterator>::value) { - return std::__for_each_n_segment(__first, __n, [&](__local_iterator __lfirst, __local_iterator __llast) { - std::__fill_n(__lfirst, __llast - __lfirst, __value); - }); - } - } -#endif - for (; __n > 0; ++__first, (void)--__n) - *__first = __value; - return __first; -} - -template >::__has_algorithm, - int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutIter __fill_n(_OutIter __first, _Size __n, const _Tp& __value) { - return __specialized_algorithm<_Algorithm::__fill_n, __single_iterator<_OutIter> >()( - std::move(__first), __n, __value); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) { - return std::__fill_n(__first, std::__convert_to_integral(__n), __value); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_FILL_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/find.h b/third_party/libcxx/include/c++/v1/__algorithm/find.h deleted file mode 100644 index f677fb2..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/find.h +++ /dev/null @@ -1,240 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FIND_H -#define _LIBCPP___ALGORITHM_FIND_H - -#include <__algorithm/find_if.h> -#include <__algorithm/find_segment_if.h> -#include <__algorithm/min.h> -#include <__algorithm/simd_utils.h> -#include <__algorithm/unwrap_iter.h> -#include <__bit/countr.h> -#include <__bit/invert_if.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/identity.h> -#include <__fwd/bit_reference.h> -#include <__iterator/segmented_iterator.h> -#include <__string/constexpr_c_functions.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_constant_evaluated.h> -#include <__type_traits/is_equality_comparable.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_signed.h> -#include <__utility/move.h> -#include - -#if _LIBCPP_HAS_WIDE_CHARACTERS -# include -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// generic implementation -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter -__find_generic(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - return std::__find_if( - std::move(__first), - std::move(__last), - [&](_ValT&& __val) -> bool { return __val == __value; }, - __proj); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter -__find(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - return std::__find_generic(std::move(__first), std::move(__last), __value, __proj); -} - -#if _LIBCPP_VECTORIZE_ALGORITHMS -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find_vectorized(_Tp* __first, _Tp* __last, _Up __value) { - if (!__libcpp_is_constant_evaluated()) { - constexpr size_t __unroll_count = 4; - constexpr size_t __vec_size = __native_vector_size<_Tp>; - using __vec = __simd_vector<_Tp, __vec_size>; - - auto __orig_first = __first; - - auto __values = static_cast<__simd_vector<_Tp, __vec_size>>(__value); // broadcast the value - while (static_cast(__last - __first) >= __unroll_count * __vec_size) [[__unlikely__]] { - __vec __lhs[__unroll_count]; - - for (size_t __i = 0; __i != __unroll_count; ++__i) - __lhs[__i] = std::__load_vector<__vec>(__first + __i * __vec_size); - - for (size_t __i = 0; __i != __unroll_count; ++__i) { - if (auto __cmp_res = __lhs[__i] == __values; std::__any_of(__cmp_res)) { - auto __offset = __i * __vec_size + std::__find_first_set(__cmp_res); - return __first + __offset; - } - } - - __first += __unroll_count * __vec_size; - } - - // check the remaining 0-3 vectors - while (static_cast(__last - __first) >= __vec_size) { - if (auto __cmp_res = std::__load_vector<__vec>(__first) == __values; std::__any_of(__cmp_res)) { - return __first + std::__find_first_set(__cmp_res); - } - __first += __vec_size; - } - - if (__last - __first == 0) - return __first; - - // Check if we can load elements in front of the current pointer. If that's the case load a vector at - // (last - vector_size) to check the remaining elements - if (static_cast(__first - __orig_first) >= __vec_size) { - __first = __last - __vec_size; - return __first + std::__find_first_set(std::__load_vector<__vec>(__first) == __values); - } - } - - __identity __proj; - return std::__find_generic(__first, __last, __value, __proj); -} -#endif - -#ifndef _LIBCPP_CXX03_LANG -// trivially equality comparable implementations -template ::value && __is_trivially_equality_comparable_v<_Tp, _Up>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) { - if constexpr (sizeof(_Tp) == 1) { - if (auto __ret = std::__constexpr_memchr(__first, __value, __last - __first)) - return __ret; - return __last; - } -# if _LIBCPP_HAS_WIDE_CHARACTERS - else if constexpr (sizeof(_Tp) == sizeof(wchar_t) && _LIBCPP_ALIGNOF(_Tp) >= _LIBCPP_ALIGNOF(wchar_t)) { - if (auto __ret = std::__constexpr_wmemchr(__first, __value, __last - __first)) - return __ret; - return __last; - } -# endif -# if _LIBCPP_VECTORIZE_ALGORITHMS - else if constexpr (is_integral<_Tp>::value) { - return std::__find_vectorized(__first, __last, __value); - } -# endif - else { - __identity __proj; - return std::__find_generic(__first, __last, __value, __proj); - } -} -#endif - -// TODO: This should also be possible to get right with different signedness -// cast integral types to allow vectorization -template ::value && !__is_trivially_equality_comparable_v<_Tp, _Up> && - is_integral<_Tp>::value && is_integral<_Up>::value && - is_signed<_Tp>::value == is_signed<_Up>::value, - int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* -__find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) { - if (__value < numeric_limits<_Tp>::min() || __value > numeric_limits<_Tp>::max()) - return __last; - return std::__find(__first, __last, _Tp(__value), __proj); -} - -// __bit_iterator implementation -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst> -__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) { - using _It = __bit_iterator<_Cp, _IsConst>; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - // do first partial word - if (__first.__ctz_ != 0) { - __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); - __storage_type __dn = std::min(__clz_f, __n); - __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first.__ctz_); - __storage_type __b = std::__invert_if(*__first.__seg_) & __m; - if (__b) - return _It(__first.__seg_, static_cast(std::__countr_zero(__b))); - if (__n == __dn) - return __first + __n; - __n -= __dn; - ++__first.__seg_; - } - // do middle whole words - for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) { - __storage_type __b = std::__invert_if(*__first.__seg_); - if (__b) - return _It(__first.__seg_, static_cast(std::__countr_zero(__b))); - } - // do last partial word - if (__n > 0) { - __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - __storage_type __b = std::__invert_if(*__first.__seg_) & __m; - if (__b) - return _It(__first.__seg_, static_cast(std::__countr_zero(__b))); - } - return _It(__first.__seg_, static_cast(__n)); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, _IsConst> -__find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) { - if (static_cast(__value)) - return std::__find_bool( - __first, static_cast::size_type>(__last - __first)); - return std::__find_bool( - __first, static_cast::size_type>(__last - __first)); -} - -// segmented iterator implementation - -template , int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator -__find(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj& __proj) { - using __local_iterator = typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator; - return std::__find_segment_if( - std::move(__first), std::move(__last), [&__value, &__proj](__local_iterator __lfirst, __local_iterator __llast) { - return std::__rewrap_iter( - __lfirst, std::__find(std::__unwrap_iter(__lfirst), std::__unwrap_iter(__llast), __value, __proj)); - }); -} - -// public API -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -find(_InputIterator __first, _InputIterator __last, const _Tp& __value) { - __identity __proj; - return std::__rewrap_iter( - __first, std::__find(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __value, __proj)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_FIND_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/find_end.h b/third_party/libcxx/include/c++/v1/__algorithm/find_end.h deleted file mode 100644 index 84b43e3..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/find_end.h +++ /dev/null @@ -1,223 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FIND_END_OF_H -#define _LIBCPP___ALGORITHM_FIND_END_OF_H - -#include <__algorithm/comp.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/invoke.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template < class _AlgPolicy, - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Pred, - class _Proj1, - class _Proj2> -_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __find_end_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - forward_iterator_tag, - forward_iterator_tag) { - // modeled after search algorithm - _Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1); // __last1 is the "default" answer - _Iter1 __match_last = __match_first; - if (__first2 == __last2) - return pair<_Iter1, _Iter1>(__match_last, __match_last); - while (true) { - while (true) { - if (__first1 == __last1) // if source exhausted return last correct answer (or __last1 if never found) - return pair<_Iter1, _Iter1>(__match_first, __match_last); - if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - } - // *__first1 matches *__first2, now match elements after here - _Iter1 __m1 = __first1; - _Iter2 __m2 = __first2; - while (true) { - if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one - __match_first = __first1; - __match_last = ++__m1; - ++__first1; - break; - } - if (++__m1 == __last1) // Source exhausted, return last answer - return pair<_Iter1, _Iter1>(__match_first, __match_last); - // mismatch, restart with a new __first - if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) { - ++__first1; - break; - } // else there is a match, check next elements - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter1> __find_end_impl( - _Iter1 __first1, - _Sent1 __sent1, - _Iter2 __first2, - _Sent2 __sent2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - bidirectional_iterator_tag, - bidirectional_iterator_tag) { - auto __last1 = _IterOps<_AlgPolicy>::next(__first1, __sent1); - auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __sent2); - // modeled after search algorithm (in reverse) - if (__first2 == __last2) - return std::make_pair(__last1, __last1); // Everything matches an empty sequence - _Iter1 __l1 = __last1; - _Iter2 __l2 = __last2; - --__l2; - while (true) { - // Find last element in sequence 1 that matches *(__last2-1), with a mininum of loop checks - while (true) { - if (__first1 == __l1) // return __last1 if no element matches *__first2 - return std::make_pair(__last1, __last1); - if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2))) - break; - } - // *__l1 matches *__l2, now match elements before here - _Iter1 __match_last = __l1; - _Iter1 __m1 = __l1; - _Iter2 __m2 = __l2; - while (true) { - if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern) - return std::make_pair(__m1, ++__match_last); - if (__m1 == __first1) // Otherwise if source exhaused, pattern not found - return std::make_pair(__last1, __last1); - - // if there is a mismatch, restart with a new __l1 - if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) { - break; - } // else there is a match, check next elements - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __find_end_impl( - _Iter1 __first1, - _Sent1 __sent1, - _Iter2 __first2, - _Sent2 __sent2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - random_access_iterator_tag, - random_access_iterator_tag) { - typedef typename iterator_traits<_Iter1>::difference_type _D1; - auto __last1 = _IterOps<_AlgPolicy>::next(__first1, __sent1); - auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __sent2); - // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern - auto __len2 = __last2 - __first2; - if (__len2 == 0) - return std::make_pair(__last1, __last1); - auto __len1 = __last1 - __first1; - if (__len1 < __len2) - return std::make_pair(__last1, __last1); - const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here - _Iter1 __l1 = __last1; - _Iter2 __l2 = __last2; - --__l2; - while (true) { - while (true) { - if (__s == __l1) - return std::make_pair(__last1, __last1); - if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2))) - break; - } - _Iter1 __last_match = __l1; - _Iter1 __m1 = __l1; - _Iter2 __m2 = __l2; - while (true) { - if (__m2 == __first2) - return std::make_pair(__m1, ++__last_match); - // no need to check range on __m1 because __s guarantees we have enough source - if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) { - break; - } - } - } -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate& __pred) { - auto __proj = __identity(); - return std::__find_end_impl<_ClassicAlgPolicy>( - __first1, - __last1, - __first2, - __last2, - __pred, - __proj, - __proj, - typename iterator_traits<_ForwardIterator1>::iterator_category(), - typename iterator_traits<_ForwardIterator2>::iterator_category()) - .first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate __pred) { - return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 -find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::find_end(__first1, __last1, __first2, __last2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FIND_END_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/find_first_of.h b/third_party/libcxx/include/c++/v1/__algorithm/find_first_of.h deleted file mode 100644 index 45ec133..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/find_first_of.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FIND_FIRST_OF_H -#define _LIBCPP___ALGORITHM_FIND_FIRST_OF_H - -#include <__algorithm/comp.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate&& __pred) { - for (; __first1 != __last1; ++__first1) - for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) - if (__pred(*__first1, *__j)) - return __first1; - return __last1; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate __pred) { - return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of( - _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FIND_FIRST_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/find_if.h b/third_party/libcxx/include/c++/v1/__algorithm/find_if.h deleted file mode 100644 index 2a96e13..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/find_if.h +++ /dev/null @@ -1,43 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FIND_IF_H -#define _LIBCPP___ALGORITHM_FIND_IF_H - -#include <__config> -#include <__functional/identity.h> -#include <__memory/valid_range.h> -#include <__type_traits/invoke.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter -__find_if(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) { - std::__assume_valid_range(__first, __last); - - for (; __first != __last; ++__first) - if (std::__invoke(__pred, std::__invoke(__proj, *__first))) - break; - return __first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - return std::__find_if(__first, __last, __pred, __identity()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FIND_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/find_if_not.h b/third_party/libcxx/include/c++/v1/__algorithm/find_if_not.h deleted file mode 100644 index d37da4c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/find_if_not.h +++ /dev/null @@ -1,48 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FIND_IF_NOT_H -#define _LIBCPP___ALGORITHM_FIND_IF_NOT_H - -#include <__algorithm/find_if.h> -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/invoke.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter -__find_if_not(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) { - return std::__find_if( - std::move(__first), - std::move(__last), - [&](_ValT&& __val) -> bool { return !std::__invoke(__pred, __val); }, - __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - return std::__find_if_not(__first, __last, __pred, __identity()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_FIND_IF_NOT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/find_segment_if.h b/third_party/libcxx/include/c++/v1/__algorithm/find_segment_if.h deleted file mode 100644 index 558f8a1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/find_segment_if.h +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FIND_SEGMENT_IF_H -#define _LIBCPP___ALGORITHM_FIND_SEGMENT_IF_H - -#include <__config> -#include <__iterator/segmented_iterator.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __find_segment_if is a utility function for optimizing iteration over segmented iterators linearly. -// [__first, __last) has to be a segmented range. __pred is expected to take a range of local iterators. -// It returns an iterator to the first element that satisfies the predicate, or a one-past-the-end iterator if there was -// no match. - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator -__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred) { - using _Traits = __segmented_iterator_traits<_SegmentedIterator>; - - auto __sfirst = _Traits::__segment(__first); - auto __slast = _Traits::__segment(__last); - - // We are in a single segment, so we might not be at the beginning or end - if (__sfirst == __slast) - return _Traits::__compose(__sfirst, __pred(_Traits::__local(__first), _Traits::__local(__last))); - - { // We have more than one segment. Iterate over the first segment, since we might not start at the beginning - auto __llast = _Traits::__end(__sfirst); - auto __liter = __pred(_Traits::__local(__first), __llast); - if (__liter != __llast) - return _Traits::__compose(__sfirst, __liter); - } - ++__sfirst; - - // Iterate over the segments which are guaranteed to be completely in the range - while (__sfirst != __slast) { - auto __llast = _Traits::__end(__sfirst); - auto __liter = __pred(_Traits::__begin(__sfirst), _Traits::__end(__sfirst)); - if (__liter != __llast) - return _Traits::__compose(__sfirst, __liter); - ++__sfirst; - } - - // Iterate over the last segment - return _Traits::__compose(__sfirst, __pred(_Traits::__begin(__sfirst), _Traits::__local(__last))); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FIND_SEGMENT_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/for_each.h b/third_party/libcxx/include/c++/v1/__algorithm/for_each.h deleted file mode 100644 index bb656a2..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/for_each.h +++ /dev/null @@ -1,59 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FOR_EACH_H -#define _LIBCPP___ALGORITHM_FOR_EACH_H - -#include <__algorithm/for_each_segment.h> -#include <__algorithm/specialized_algorithms.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/segmented_iterator.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_same.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -__for_each(_InputIterator __first, _Sent __last, _Func&& __func, _Proj& __proj) { -#ifndef _LIBCPP_CXX03_LANG - if constexpr (using _SpecialAlg = - __specialized_algorithm<_Algorithm::__for_each, __iterator_pair<_InputIterator, _Sent>>; - _SpecialAlg::__has_algorithm) { - _SpecialAlg()(__first, __last, __func, __proj); - return __last; - } else if constexpr (is_same<_InputIterator, _Sent>::value && __is_segmented_iterator_v<_InputIterator>) { - using __local_iterator_t = typename __segmented_iterator_traits<_InputIterator>::__local_iterator; - std::__for_each_segment(__first, __last, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) { - std::__for_each(__lfirst, __llast, __func, __proj); - }); - return __last; - } -#endif - for (; __first != __last; ++__first) - std::__invoke(__func, std::__invoke(__proj, *__first)); - return __first; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Func -for_each(_InputIterator __first, _InputIterator __last, _Func __f) { - __identity __proj; - std::__for_each(__first, __last, __f, __proj); - return __f; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FOR_EACH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/for_each_n.h b/third_party/libcxx/include/c++/v1/__algorithm/for_each_n.h deleted file mode 100644 index 7ff3f9b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/for_each_n.h +++ /dev/null @@ -1,76 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FOR_EACH_N_H -#define _LIBCPP___ALGORITHM_FOR_EACH_N_H - -#include <__algorithm/for_each.h> -#include <__algorithm/for_each_n_segment.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__type_traits/invoke.h> -#include <__utility/convert_to_integral.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -__for_each_n(_InputIterator __first, _Size __orig_n, _Func&& __f, _Proj& __proj) { - typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; - _IntegralSize __n = __orig_n; - -#ifndef _LIBCPP_CXX03_LANG - if constexpr (__is_segmented_iterator_v<_InputIterator>) { - using __local_iterator = typename __segmented_iterator_traits<_InputIterator>::__local_iterator; - if constexpr (__has_random_access_iterator_category<__local_iterator>::value) { - return std::__for_each_n_segment(__first, __orig_n, [&](__local_iterator __lfirst, __local_iterator __llast) { - std::__for_each(__lfirst, __llast, __f, __proj); - }); - } else { - return std::__for_each(__first, __first + __n, std::forward<_Func>(__f), __proj); - } - } else -#endif - { - while (__n > 0) { - std::__invoke(__f, std::__invoke(__proj, *__first)); - ++__first; - --__n; - } - return std::move(__first); - } -} - -#if _LIBCPP_STD_VER >= 17 - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator -for_each_n(_InputIterator __first, _Size __orig_n, _Func __f) { - __identity __proj; - return std::__for_each_n(__first, __orig_n, __f, __proj); -} - -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_FOR_EACH_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/for_each_n_segment.h b/third_party/libcxx/include/c++/v1/__algorithm/for_each_n_segment.h deleted file mode 100644 index a433df5..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/for_each_n_segment.h +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FOR_EACH_N_SEGMENT_H -#define _LIBCPP___ALGORITHM_FOR_EACH_N_SEGMENT_H - -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __for_each_n_segment optimizes linear iteration over segmented iterators. It processes a segmented -// input range [__first, __first + __n) by applying the functor __func to each element within the segment. -// The return value of __func is ignored, and the function returns an iterator pointing to one past the -// last processed element in the input range. - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator -__for_each_n_segment(_SegmentedIterator __first, _Size __orig_n, _Functor __func) { - static_assert(__is_segmented_iterator_v<_SegmentedIterator> && - __has_random_access_iterator_category< - typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator>::value, - "__for_each_n_segment only works with segmented iterators with random-access local iterators"); - if (__orig_n <= 0) - return __first; - - using _Traits = __segmented_iterator_traits<_SegmentedIterator>; - using __local_iter_t = typename _Traits::__local_iterator; - using __difference_t = typename std::iterator_traits<__local_iter_t>::difference_type; - __difference_t __n = __orig_n; - auto __seg = _Traits::__segment(__first); - auto __local_first = _Traits::__local(__first); - __local_iter_t __local_last; - - while (__n > 0) { - __local_last = _Traits::__end(__seg); - auto __seg_size = __local_last - __local_first; - if (__n <= __seg_size) { - __local_last = __local_first + __n; - __func(__local_first, __local_last); - break; - } - __func(__local_first, __local_last); - __n -= __seg_size; - __local_first = _Traits::__begin(++__seg); - } - - return _Traits::__compose(__seg, __local_last); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FOR_EACH_N_SEGMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/for_each_segment.h b/third_party/libcxx/include/c++/v1/__algorithm/for_each_segment.h deleted file mode 100644 index c02436c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/for_each_segment.h +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_FOR_EACH_SEGMENT_H -#define _LIBCPP___ALGORITHM_FOR_EACH_SEGMENT_H - -#include <__config> -#include <__iterator/segmented_iterator.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __for_each_segment is a utility function for optimizing iterating over segmented iterators linearly. -// __first and __last are expected to be a segmented range. __func is expected to take a range of local iterators. -// Anything that is returned from __func is ignored. - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__for_each_segment(_SegmentedIterator __first, _SegmentedIterator __last, _Functor __func) { - using _Traits = __segmented_iterator_traits<_SegmentedIterator>; - - auto __sfirst = _Traits::__segment(__first); - auto __slast = _Traits::__segment(__last); - - // We are in a single segment, so we might not be at the beginning or end - if (__sfirst == __slast) { - __func(_Traits::__local(__first), _Traits::__local(__last)); - return; - } - - // We have more than one segment. Iterate over the first segment, since we might not start at the beginning - __func(_Traits::__local(__first), _Traits::__end(__sfirst)); - ++__sfirst; - // iterate over the segments which are guaranteed to be completely in the range - while (__sfirst != __slast) { - __func(_Traits::__begin(__sfirst), _Traits::__end(__sfirst)); - ++__sfirst; - } - // iterate over the last segment - __func(_Traits::__begin(__sfirst), _Traits::__local(__last)); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__for_each_segment_backward(_SegmentedIterator __first, _SegmentedIterator __last, _Functor __func) { - using _Traits = __segmented_iterator_traits<_SegmentedIterator>; - - auto __sfirst = _Traits::__segment(__first); - auto __slast = _Traits::__segment(__last); - - // We are in a single segment, so we might not be at the beginning or end - if (__sfirst == __slast) { - __func(_Traits::__local(__first), _Traits::__local(__last)); - return; - } - - // We have more than one segment. Iterate over the last segment, since we might not start at the end - __func(_Traits::__begin(__slast), _Traits::__local(__last)); - --__slast; - // iterate over the segments which are guaranteed to be completely in the range - while (__sfirst != __slast) { - __func(_Traits::__begin(__slast), _Traits::__end(__slast)); - --__slast; - } - // iterate over the first segment - __func(_Traits::__local(__first), _Traits::__end(__slast)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_FOR_EACH_SEGMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/generate.h b/third_party/libcxx/include/c++/v1/__algorithm/generate.h deleted file mode 100644 index c4cd75c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/generate.h +++ /dev/null @@ -1,31 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_GENERATE_H -#define _LIBCPP___ALGORITHM_GENERATE_H - -#include <__algorithm/for_each.h> -#include <__config> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) { - using __iter_ref = decltype(*__first); - std::for_each(__first, __last, [&](__iter_ref __element) { std::forward<__iter_ref>(__element) = __gen(); }); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_GENERATE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/generate_n.h b/third_party/libcxx/include/c++/v1/__algorithm/generate_n.h deleted file mode 100644 index ba04eb6..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/generate_n.h +++ /dev/null @@ -1,49 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_GENERATE_N_H -#define _LIBCPP___ALGORITHM_GENERATE_N_H - -#include <__algorithm/for_each_n.h> -#include <__config> -#include <__functional/identity.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -__generate_n(_OutputIterator __first, _Size __orig_n, _Generator& __gen) { - using __iter_ref = decltype(*__first); - __identity __proj; - return std::__for_each_n( - std::move(__first), - __orig_n, - [&](__iter_ref __element) { std::forward<__iter_ref>(__element) = __gen(); }, - __proj); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) { - return std::__generate_n(std::move(__first), __orig_n, __gen); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_GENERATE_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/half_positive.h b/third_party/libcxx/include/c++/v1/__algorithm/half_positive.h deleted file mode 100644 index ebda0da..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/half_positive.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_HALF_POSITIVE_H -#define _LIBCPP___ALGORITHM_HALF_POSITIVE_H - -#include <__config> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/make_unsigned.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Perform division by two quickly for positive integers (llvm.org/PR39129) - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Integral __half_positive(_Integral __value) { - return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp __half_positive(_Tp __value) { - return __value / 2; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_HALF_POSITIVE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/in_found_result.h b/third_party/libcxx/include/c++/v1/__algorithm/in_found_result.h deleted file mode 100644 index a67ae38..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/in_found_result.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H -#define _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -template -struct in_found_result { - _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in; - bool found; - - template - requires convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() const& { - return {in, found}; - } - - template - requires convertible_to<_InIter1, _InIter2> - _LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() && { - return {std::move(in), found}; - } -}; -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/in_fun_result.h b/third_party/libcxx/include/c++/v1/__algorithm/in_fun_result.h deleted file mode 100644 index a22069a..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/in_fun_result.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IN_FUN_RESULT_H -#define _LIBCPP___ALGORITHM_IN_FUN_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { -template -struct in_fun_result { - _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in; - _LIBCPP_NO_UNIQUE_ADDRESS _Func1 fun; - - template - requires convertible_to && convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() const& { - return {in, fun}; - } - - template - requires convertible_to<_InIter1, _InIter2> && convertible_to<_Func1, _Func2> - _LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() && { - return {std::move(in), std::move(fun)}; - } -}; -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_IN_FUN_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/in_in_out_result.h b/third_party/libcxx/include/c++/v1/__algorithm/in_in_out_result.h deleted file mode 100644 index ba0380b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/in_in_out_result.h +++ /dev/null @@ -1,59 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H -#define _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { - -template -struct in_in_out_result { - _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in1; - _LIBCPP_NO_UNIQUE_ADDRESS _InIter2 in2; - _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out; - - template - requires convertible_to && convertible_to && - convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() const& { - return {in1, in2, out}; - } - - template - requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4> && - convertible_to<_OutIter1, _OutIter2> - _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && { - return {std::move(in1), std::move(in2), std::move(out)}; - } -}; - -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/in_in_result.h b/third_party/libcxx/include/c++/v1/__algorithm/in_in_result.h deleted file mode 100644 index 994573f..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/in_in_result.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IN_IN_RESULT_H -#define _LIBCPP___ALGORITHM_IN_IN_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { - -template -struct in_in_result { - _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in1; - _LIBCPP_NO_UNIQUE_ADDRESS _InIter2 in2; - - template - requires convertible_to && convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() const& { - return {in1, in2}; - } - - template - requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4> - _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() && { - return {std::move(in1), std::move(in2)}; - } -}; - -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_IN_IN_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/in_out_out_result.h b/third_party/libcxx/include/c++/v1/__algorithm/in_out_out_result.h deleted file mode 100644 index 8ceb452..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/in_out_out_result.h +++ /dev/null @@ -1,57 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H -#define _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { -template -struct in_out_out_result { - _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in; - _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out1; - _LIBCPP_NO_UNIQUE_ADDRESS _OutIter2 out2; - - template - requires convertible_to && convertible_to && - convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() const& { - return {in, out1, out2}; - } - - template - requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter3> && - convertible_to<_OutIter2, _OutIter4> - _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() && { - return {std::move(in), std::move(out1), std::move(out2)}; - } -}; -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/in_out_result.h b/third_party/libcxx/include/c++/v1/__algorithm/in_out_result.h deleted file mode 100644 index a7a986c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/in_out_result.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IN_OUT_RESULT_H -#define _LIBCPP___ALGORITHM_IN_OUT_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { - -template -struct in_out_result { - _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in; - _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out; - - template - requires convertible_to && convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() const& { - return {in, out}; - } - - template - requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter2> - _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() && { - return {std::move(in), std::move(out)}; - } -}; - -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_IN_OUT_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/includes.h b/third_party/libcxx/include/c++/v1/__algorithm/includes.h deleted file mode 100644 index bc6c657..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/includes.h +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_INCLUDES_H -#define _LIBCPP___ALGORITHM_INCLUDES_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Comp&& __comp, - _Proj1&& __proj1, - _Proj2&& __proj2) { - for (; __first2 != __last2; ++__first1) { - if (__first1 == __last1 || - std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1))) - return false; - if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - ++__first2; - } - return true; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -includes(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _Compare __comp) { - static_assert( - __is_callable<_Compare&, decltype(*__first1), decltype(*__first2)>::value, "The comparator has to be callable"); - - return std::__includes( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - static_cast<__comp_ref_type<_Compare> >(__comp), - __identity(), - __identity()); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_INCLUDES_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/inplace_merge.h b/third_party/libcxx/include/c++/v1/__algorithm/inplace_merge.h deleted file mode 100644 index fbfe899..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/inplace_merge.h +++ /dev/null @@ -1,243 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_INPLACE_MERGE_H -#define _LIBCPP___ALGORITHM_INPLACE_MERGE_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/lower_bound.h> -#include <__algorithm/min.h> -#include <__algorithm/move.h> -#include <__algorithm/rotate.h> -#include <__algorithm/upper_bound.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/reverse_iterator.h> -#include <__memory/construct_at.h> -#include <__memory/destruct_n.h> -#include <__memory/unique_ptr.h> -#include <__memory/unique_temporary_buffer.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __invert // invert the sense of a comparison -{ -private: - _Predicate __p_; - -public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __invert() {} - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __invert(_Predicate __p) : __p_(__p) {} - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _T1& __x) { - return !__p_(__x); - } - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _T1& __x, const _T2& __y) { - return __p_(__y, __x); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __half_inplace_merge( - _InputIterator1 __first1, - _Sent1 __last1, - _InputIterator2 __first2, - _Sent2 __last2, - _OutputIterator __result, - _Compare&& __comp) { - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) { - std::__move<_AlgPolicy>(__first1, __last1, __result); - return; - } - - if (__comp(*__first2, *__first1)) { - *__result = _IterOps<_AlgPolicy>::__iter_move(__first2); - ++__first2; - } else { - *__result = _IterOps<_AlgPolicy>::__iter_move(__first1); - ++__first1; - } - } - // __first2 through __last2 are already in the right spot. -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __buffered_inplace_merge( - _BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Compare&& __comp, - typename iterator_traits<_BidirectionalIterator>::difference_type __len1, - typename iterator_traits<_BidirectionalIterator>::difference_type __len2, - typename iterator_traits<_BidirectionalIterator>::value_type* __buff) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h2(__buff, __d); - if (__len1 <= __len2) { - value_type* __p = __buff; - for (_BidirectionalIterator __i = __first; __i != __middle; - __d.template __incr(), (void)++__i, (void)++__p) - std::__construct_at(__p, _IterOps<_AlgPolicy>::__iter_move(__i)); - std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp); - } else { - value_type* __p = __buff; - for (_BidirectionalIterator __i = __middle; __i != __last; - __d.template __incr(), (void)++__i, (void)++__p) - std::__construct_at(__p, _IterOps<_AlgPolicy>::__iter_move(__i)); - typedef reverse_iterator<_BidirectionalIterator> _RBi; - typedef reverse_iterator _Rv; - typedef __invert<_Compare> _Inverted; - std::__half_inplace_merge<_AlgPolicy>( - _Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), _Inverted(__comp)); - } -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX26 void __inplace_merge( - _BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Compare&& __comp, - typename iterator_traits<_BidirectionalIterator>::difference_type __len1, - typename iterator_traits<_BidirectionalIterator>::difference_type __len2, - typename iterator_traits<_BidirectionalIterator>::value_type* __buff, - ptrdiff_t __buff_size) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - while (true) { - // if __middle == __last, we're done - if (__len2 == 0) - return; - if (__len1 <= __buff_size || __len2 <= __buff_size) - return std::__buffered_inplace_merge<_AlgPolicy>(__first, __middle, __last, __comp, __len1, __len2, __buff); - // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 - for (; true; ++__first, (void)--__len1) { - if (__len1 == 0) - return; - if (__comp(*__middle, *__first)) - break; - } - // __first < __middle < __last - // *__first > *__middle - // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that - // all elements in: - // [__first, __m1) <= [__middle, __m2) - // [__middle, __m2) < [__m1, __middle) - // [__m1, __middle) <= [__m2, __last) - // and __m1 or __m2 is in the middle of its range - _BidirectionalIterator __m1; // "median" of [__first, __middle) - _BidirectionalIterator __m2; // "median" of [__middle, __last) - difference_type __len11; // distance(__first, __m1) - difference_type __len21; // distance(__middle, __m2) - // binary search smaller range - if (__len1 < __len2) { // __len >= 1, __len2 >= 2 - __len21 = __len2 / 2; - __m2 = __middle; - _Ops::advance(__m2, __len21); - __m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity()); - __len11 = _Ops::distance(__first, __m1); - } else { - if (__len1 == 1) { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1 - // It is known *__first > *__middle - _Ops::iter_swap(__first, __middle); - return; - } - // __len1 >= 2, __len2 >= 1 - __len11 = __len1 / 2; - __m1 = __first; - _Ops::advance(__m1, __len11); - __m2 = std::lower_bound(__middle, __last, *__m1, __comp); - __len21 = _Ops::distance(__middle, __m2); - } - difference_type __len12 = __len1 - __len11; // distance(__m1, __middle) - difference_type __len22 = __len2 - __len21; // distance(__m2, __last) - // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) - // swap middle two partitions - __middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first; - // __len12 and __len21 now have swapped meanings - // merge smaller range with recursive call and larger with tail recursion elimination - if (__len11 + __len21 < __len12 + __len22) { - std::__inplace_merge<_AlgPolicy>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); - __first = __middle; - __middle = __m2; - __len1 = __len12; - __len2 = __len22; - } else { - std::__inplace_merge<_AlgPolicy>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); - __last = __middle; - __middle = __m1; - __len1 = __len11; - __len2 = __len21; - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __inplace_merge( - _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle); - difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last); - difference_type __buf_size = std::min(__len1, __len2); - __unique_temporary_buffer __unique_buf = std::__allocate_unique_temporary_buffer(__buf_size); - return std::__inplace_merge<_AlgPolicy>( - std::move(__first), - std::move(__middle), - std::move(__last), - __comp, - __len1, - __len2, - __unique_buf.get(), - __unique_buf.get_deleter().__count_); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void inplace_merge( - _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) { - std::__inplace_merge<_ClassicAlgPolicy>( - std::move(__first), std::move(__middle), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void -inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) { - std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_INPLACE_MERGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/is_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/is_heap.h deleted file mode 100644 index dfe0620..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/is_heap.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IS_HEAP_H -#define _LIBCPP___ALGORITHM_IS_HEAP_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/is_heap_until.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - return std::is_heap(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_IS_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/is_heap_until.h b/third_party/libcxx/include/c++/v1/__algorithm/is_heap_until.h deleted file mode 100644 index 7444d97..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/is_heap_until.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H -#define _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__config> -#include <__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator -__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __len = __last - __first; - difference_type __p = 0; - difference_type __c = 1; - _RandomAccessIterator __pp = __first; - while (__c < __len) { - _RandomAccessIterator __cp = __first + __c; - if (__comp(*__pp, *__cp)) - return __cp; - ++__c; - ++__cp; - if (__c == __len) - return __last; - if (__comp(*__pp, *__cp)) - return __cp; - ++__p; - ++__pp; - __c = 2 * __p + 1; - } - return __last; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator -is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator -is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) { - return std::__is_heap_until(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/is_partitioned.h b/third_party/libcxx/include/c++/v1/__algorithm/is_partitioned.h deleted file mode 100644 index 700e452..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/is_partitioned.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IS_PARTITIONED_H -#define _LIBCPP___ALGORITHM_IS_PARTITIONED_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (!__pred(*__first)) - break; - if (__first == __last) - return true; - ++__first; - for (; __first != __last; ++__first) - if (__pred(*__first)) - return false; - return true; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_IS_PARTITIONED_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/is_permutation.h b/third_party/libcxx/include/c++/v1/__algorithm/is_permutation.h deleted file mode 100644 index 86f469c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/is_permutation.h +++ /dev/null @@ -1,309 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IS_PERMUTATION_H -#define _LIBCPP___ALGORITHM_IS_PERMUTATION_H - -#include <__algorithm/comp.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__type_traits/is_same.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _ConstTimeDistance : false_type {}; - -#if _LIBCPP_STD_VER >= 20 - -template -struct _ConstTimeDistance<_Iter1, - _Sent1, - _Iter2, - _Sent2, - __enable_if_t< sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2> >> - : true_type {}; - -#else - -template -struct _ConstTimeDistance< - _Iter1, - _Iter1, - _Iter2, - _Iter2, - __enable_if_t< is_same::iterator_category, random_access_iterator_tag>::value && - is_same::iterator_category, random_access_iterator_tag>::value > > - : true_type {}; - -#endif // _LIBCPP_STD_VER >= 20 - -// Internal functions - -// For each element in [f1, l1) see if there are the same number of equal elements in [f2, l2) -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2) { - using _D1 = __iterator_difference_type<_Iter1>; - - for (auto __i = __first1; __i != __last1; ++__i) { - // Have we already counted the number of *__i in [f1, l1)? - auto __match = __first1; - for (; __match != __i; ++__match) { - if (std::__invoke(__pred, std::__invoke(__proj1, *__match), std::__invoke(__proj1, *__i))) - break; - } - - if (__match == __i) { - // Count number of *__i in [f2, l2) - _D1 __c2 = 0; - for (auto __j = __first2; __j != __last2; ++__j) { - if (std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj2, *__j))) - ++__c2; - } - if (__c2 == 0) - return false; - - // Count number of *__i in [__i, l1) (we can start with 1) - _D1 __c1 = 1; - for (auto __j = _IterOps<_AlgPolicy>::next(__i); __j != __last1; ++__j) { - if (std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj1, *__j))) - ++__c1; - } - if (__c1 != __c2) - return false; - } - } - - return true; -} - -// 2+1 iterators, predicate. Not used by range algorithms. -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation( - _ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) { - // Shorten sequences as much as possible by lopping of any equal prefix. - for (; __first1 != __last1; ++__first1, (void)++__first2) { - if (!__pred(*__first1, *__first2)) - break; - } - - if (__first1 == __last1) - return true; - - // __first1 != __last1 && *__first1 != *__first2 - using _D1 = __iterator_difference_type<_ForwardIterator1>; - _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1); - if (__l1 == _D1(1)) - return false; - auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __l1); - - return std::__is_permutation_impl<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __identity(), - __identity()); -} - -// 2+2 iterators, predicate, non-constant time `distance`. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2, - /*_ConstTimeDistance=*/false_type) { - // Shorten sequences as much as possible by lopping of any equal prefix. - while (__first1 != __last1 && __first2 != __last2) { - if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - ++__first2; - } - - if (__first1 == __last1) - return __first2 == __last2; - if (__first2 == __last2) // Second range is shorter - return false; - - using _D1 = __iterator_difference_type<_Iter1>; - _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1); - - using _D2 = __iterator_difference_type<_Iter2>; - _D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2); - if (__l1 != __l2) - return false; - - return std::__is_permutation_impl<_AlgPolicy>( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); -} - -// 2+2 iterators, predicate, specialization for constant-time `distance` call. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2, - /*_ConstTimeDistance=*/true_type) { - if (std::distance(__first1, __last1) != std::distance(__first2, __last2)) - return false; - return std::__is_permutation<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __proj1, - __proj2, - /*_ConstTimeDistance=*/false_type()); -} - -// 2+2 iterators, predicate -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2) { - return std::__is_permutation<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __proj1, - __proj2, - _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2>()); -} - -// Public interface - -// 2+1 iterators, predicate -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( - _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value, - "The comparator has to be callable"); - - return std::__is_permutation<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2), __pred); -} - -// 2+1 iterators -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { - return std::is_permutation(__first1, __last1, __first2, __equal_to()); -} - -#if _LIBCPP_STD_VER >= 14 - -// 2+2 iterators -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( - _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::__is_permutation<_ClassicAlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __equal_to(), - __identity(), - __identity()); -} - -// 2+2 iterators, predicate -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value, - "The comparator has to be callable"); - - return std::__is_permutation<_ClassicAlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __identity(), - __identity()); -} - -#endif // _LIBCPP_STD_VER >= 14 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/is_sorted.h b/third_party/libcxx/include/c++/v1/__algorithm/is_sorted.h deleted file mode 100644 index 196ae0b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/is_sorted.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IS_SORTED_H -#define _LIBCPP___ALGORITHM_IS_SORTED_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/is_sorted_until.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -is_sorted(_ForwardIterator __first, _ForwardIterator __last) { - return std::is_sorted(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_IS_SORTED_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/is_sorted_until.h b/third_party/libcxx/include/c++/v1/__algorithm/is_sorted_until.h deleted file mode 100644 index 6066419..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/is_sorted_until.h +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H -#define _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) { - if (__comp(*__i, *__first)) - return __i; - __first = __i; - } - } - return __last; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) { - return std::is_sorted_until(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/iter_swap.h b/third_party/libcxx/include/c++/v1/__algorithm/iter_swap.h deleted file mode 100644 index a1412e5..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/iter_swap.h +++ /dev/null @@ -1,31 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_ITER_SWAP_H -#define _LIBCPP___ALGORITHM_ITER_SWAP_H - -#include <__config> -#include <__utility/declval.h> -#include <__utility/swap.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) - // _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b))) - _NOEXCEPT_(_NOEXCEPT_(swap(*std::declval<_ForwardIterator1>(), *std::declval<_ForwardIterator2>()))) { - swap(*__a, *__b); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_ITER_SWAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/iterator_operations.h b/third_party/libcxx/include/c++/v1/__algorithm/iterator_operations.h deleted file mode 100644 index 1aa2f8d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/iterator_operations.h +++ /dev/null @@ -1,229 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H -#define _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H - -#include <__algorithm/iter_swap.h> -#include <__algorithm/ranges_iterator_concept.h> -#include <__assert> -#include <__config> -#include <__iterator/advance.h> -#include <__iterator/distance.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/iter_move.h> -#include <__iterator/iter_swap.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/prev.h> -#include <__iterator/readable_traits.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_reference.h> -#include <__type_traits/is_same.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/declval.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _IterOps; - -#if _LIBCPP_STD_VER >= 20 -struct _RangeAlgPolicy {}; - -template <> -struct _IterOps<_RangeAlgPolicy> { - template - using __value_type _LIBCPP_NODEBUG = iter_value_t<_Iter>; - - template - using __iterator_category _LIBCPP_NODEBUG = ranges::__iterator_concept<_Iter>; - - template - using __difference_type _LIBCPP_NODEBUG = iter_difference_t<_Iter>; - - static constexpr auto advance = ranges::advance; - static constexpr auto distance = ranges::distance; - static constexpr auto __iter_move = ranges::iter_move; - static constexpr auto iter_swap = ranges::iter_swap; - static constexpr auto next = ranges::next; - static constexpr auto prev = ranges::prev; - static constexpr auto __advance_to = ranges::advance; -}; - -#endif - -struct _ClassicAlgPolicy {}; - -template <> -struct _IterOps<_ClassicAlgPolicy> { - template - using __value_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type; - - template - using __iterator_category _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category; - - template - using __difference_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type; - - // advance - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void advance(_Iter& __iter, _Distance __count) { - std::advance(__iter, __count); - } - - // distance - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static typename iterator_traits<_Iter>::difference_type - distance(_Iter __first, _Iter __last) { - return std::distance(__first, __last); - } - - template - using __deref_t _LIBCPP_NODEBUG = decltype(*std::declval<_Iter&>()); - - template - using __move_t _LIBCPP_NODEBUG = decltype(std::move(*std::declval<_Iter&>())); - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void __validate_iter_reference() { - static_assert( - is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_t<_Iter> >::reference>::value, - "It looks like your iterator's `iterator_traits::reference` does not match the return type of " - "dereferencing the iterator, i.e., calling `*it`. This is undefined behavior according to [input.iterators] " - "and can lead to dangling reference issues at runtime, so we are flagging this."); - } - - // iter_move - template >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static - // If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it. - // Note that the C++03 mode doesn't support `decltype(auto)` as the return type. - __move_t<_Iter> - __iter_move(_Iter&& __i) { - __validate_iter_reference<_Iter>(); - - return std::move(*std::forward<_Iter>(__i)); - } - - template >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static - // If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a - // value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to - // that temporary. Note that the C++03 mode doesn't support `auto` as the return type. - __deref_t<_Iter> - __iter_move(_Iter&& __i) { - __validate_iter_reference<_Iter>(); - - return *std::forward<_Iter>(__i); - } - - // iter_swap - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void iter_swap(_Iter1&& __a, _Iter2&& __b) { - std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b)); - } - - // next - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator next(_Iterator, _Iterator __last) { - return __last; - } - - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter> - next(_Iter&& __it, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) { - return std::next(std::forward<_Iter>(__it), __n); - } - - // prev - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter> - prev(_Iter&& __iter, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) { - return std::prev(std::forward<_Iter>(__iter), __n); - } - - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 void __advance_to(_Iter& __first, _Iter __last) { - __first = __last; - } - - // advance with sentinel, a la std::ranges::advance - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_Iter> - __advance_to(_Iter& __iter, __difference_type<_Iter> __count, const _Iter& __sentinel) { - return _IterOps::__advance_to(__iter, __count, __sentinel, typename iterator_traits<_Iter>::iterator_category()); - } - -private: - // advance with sentinel, a la std::ranges::advance -- InputIterator specialization - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_InputIter> __advance_to( - _InputIter& __iter, __difference_type<_InputIter> __count, const _InputIter& __sentinel, input_iterator_tag) { - __difference_type<_InputIter> __dist = 0; - for (; __dist < __count && __iter != __sentinel; ++__dist) - ++__iter; - return __count - __dist; - } - - // advance with sentinel, a la std::ranges::advance -- BidirectionalIterator specialization - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_BiDirIter> - __advance_to(_BiDirIter& __iter, - __difference_type<_BiDirIter> __count, - const _BiDirIter& __sentinel, - bidirectional_iterator_tag) { - __difference_type<_BiDirIter> __dist = 0; - if (__count >= 0) - for (; __dist < __count && __iter != __sentinel; ++__dist) - ++__iter; - else - for (__count = -__count; __dist < __count && __iter != __sentinel; ++__dist) - --__iter; - return __count - __dist; - } - - // advance with sentinel, a la std::ranges::advance -- RandomIterator specialization - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_RandIter> - __advance_to(_RandIter& __iter, - __difference_type<_RandIter> __count, - const _RandIter& __sentinel, - random_access_iterator_tag) { - auto __dist = _IterOps::distance(__iter, __sentinel); - _LIBCPP_ASSERT_VALID_INPUT_RANGE( - __count == 0 || (__dist < 0) == (__count < 0), "__sentinel must precede __iter when __count < 0"); - if (__count < 0) - __dist = __dist > __count ? __dist : __count; - else - __dist = __dist < __count ? __dist : __count; - __iter += __dist; - return __count - __dist; - } -}; - -template -using __policy_iter_diff_t _LIBCPP_NODEBUG = typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>; - -template -using __policy_value_type _LIBCPP_NODEBUG = typename _IterOps<_AlgPolicy>::template __value_type<_Iter>; - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare.h b/third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare.h deleted file mode 100644 index a12add6..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare.h +++ /dev/null @@ -1,129 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H -#define _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H - -#include <__algorithm/comp.h> -#include <__algorithm/min.h> -#include <__algorithm/mismatch.h> -#include <__algorithm/simd_utils.h> -#include <__algorithm/unwrap_iter.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__string/constexpr_c_functions.h> -#include <__type_traits/desugars_to.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_equality_comparable.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_trivially_lexicographically_comparable.h> -#include <__type_traits/is_volatile.h> - -#if _LIBCPP_HAS_WIDE_CHARACTERS -# include -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) { - while (__first2 != __last2) { - if (__first1 == __last1 || - std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - return true; - if (std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1))) - return false; - ++__first1; - ++__first2; - } - return false; -} - -#if _LIBCPP_STD_VER >= 14 - -// If the comparison operation is equivalent to < and that is a total order, we know that we can use equality comparison -// on that type instead to extract some information. Furthermore, if equality comparison on that type is trivial, the -// user can't observe that we're calling it. So instead of using the user-provided total order, we use std::mismatch, -// which uses equality comparison (and is vertorized). Additionally, if the type is trivially lexicographically -// comparable, we can go one step further and use std::memcmp directly instead of calling std::mismatch. -template && !is_volatile<_Tp>::value && - __is_trivially_equality_comparable_v<_Tp, _Tp> && __is_identity<_Proj1>::value && - __is_identity<_Proj2>::value, - int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -__lexicographical_compare(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Comp&, _Proj1&, _Proj2&) { - if constexpr (__is_trivially_lexicographically_comparable_v<_Tp, _Tp>) { - auto __res = - std::__constexpr_memcmp(__first1, __first2, __element_count(std::min(__last1 - __first1, __last2 - __first2))); - if (__res == 0) - return __last1 - __first1 < __last2 - __first2; - return __res < 0; - } -# if _LIBCPP_HAS_WIDE_CHARACTERS - else if constexpr (is_same<__remove_cv_t<_Tp>, wchar_t>::value) { - auto __res = std::__constexpr_wmemcmp(__first1, __first2, std::min(__last1 - __first1, __last2 - __first2)); - if (__res == 0) - return __last1 - __first1 < __last2 - __first2; - return __res < 0; - } -# endif // _LIBCPP_HAS_WIDE_CHARACTERS - else { - auto __res = std::mismatch(__first1, __last1, __first2, __last2); - if (__res.second == __last2) - return false; - if (__res.first == __last1) - return true; - return *__res.first < *__res.second; - } -} - -#endif // _LIBCPP_STD_VER >= 14 - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _Compare __comp) { - __identity __proj; - return std::__lexicographical_compare( - std::__unwrap_iter(__first1), - std::__unwrap_iter(__last1), - std::__unwrap_iter(__first2), - std::__unwrap_iter(__last2), - __comp, - __proj, - __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare( - _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare_three_way.h b/third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare_three_way.h deleted file mode 100644 index 442223e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/lexicographical_compare_three_way.h +++ /dev/null @@ -1,125 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_THREE_WAY_H -#define _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_THREE_WAY_H - -#include <__algorithm/min.h> -#include <__algorithm/three_way_comp_ref_type.h> -#include <__compare/compare_three_way.h> -#include <__compare/ordering.h> -#include <__concepts/arithmetic.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/common_type.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// Fast path for random access iterators which computes the number of loop iterations up-front and -// then skips the iterator comparisons inside the loop. -template -_LIBCPP_HIDE_FROM_ABI constexpr auto __lexicographical_compare_three_way_fast_path( - _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Cmp& __comp) - -> decltype(__comp(*__first1, *__first2)) { - static_assert(signed_integral<__iterator_difference_type<_InputIterator1>>, - "Using a non-integral difference_type is undefined behavior."); - static_assert(signed_integral<__iterator_difference_type<_InputIterator2>>, - "Using a non-integral difference_type is undefined behavior."); - - using _Len1 = __iterator_difference_type<_InputIterator1>; - using _Len2 = __iterator_difference_type<_InputIterator2>; - using _Common = common_type_t<_Len1, _Len2>; - - _Len1 __len1 = __last1 - __first1; - _Len2 __len2 = __last2 - __first2; - _Common __min_len = std::min<_Common>(__len1, __len2); - - for (_Common __i = 0; __i < __min_len; ++__i) { - auto __c = __comp(*__first1, *__first2); - if (__c != 0) { - return __c; - } - ++__first1; - ++__first2; - } - - return __len1 <=> __len2; -} - -// Unoptimized implementation which compares the iterators against the end in every loop iteration -template -_LIBCPP_HIDE_FROM_ABI constexpr auto __lexicographical_compare_three_way_slow_path( - _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Cmp& __comp) - -> decltype(__comp(*__first1, *__first2)) { - while (true) { - bool __exhausted1 = __first1 == __last1; - bool __exhausted2 = __first2 == __last2; - - if (__exhausted1 || __exhausted2) { - if (!__exhausted1) - return strong_ordering::greater; - if (!__exhausted2) - return strong_ordering::less; - return strong_ordering::equal; - } - - auto __c = __comp(*__first1, *__first2); - if (__c != 0) { - return __c; - } - - ++__first1; - ++__first2; - } -} - -template -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto lexicographical_compare_three_way( - _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Cmp __comp) - -> decltype(__comp(*__first1, *__first2)) { - static_assert(__comparison_category, - "The comparator passed to lexicographical_compare_three_way must return a comparison category type."); - static_assert(std::is_copy_constructible_v<_InputIterator1>, "Iterators must be copy constructible."); - static_assert(std::is_copy_constructible_v<_InputIterator2>, "Iterators must be copy constructible."); - __three_way_comp_ref_type<_Cmp> __wrapped_comp_ref(__comp); - if constexpr (__has_random_access_iterator_category<_InputIterator1>::value && - __has_random_access_iterator_category<_InputIterator2>::value) { - return std::__lexicographical_compare_three_way_fast_path( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __wrapped_comp_ref); - } else { - // Unoptimized implementation which compares the iterators against the end in every loop iteration - return std::__lexicographical_compare_three_way_slow_path( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __wrapped_comp_ref); - } -} - -template -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto lexicographical_compare_three_way( - _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - return std::lexicographical_compare_three_way( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::compare_three_way()); -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_THREE_WAY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/lower_bound.h b/third_party/libcxx/include/c++/v1/__algorithm/lower_bound.h deleted file mode 100644 index 4fba674..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/lower_bound.h +++ /dev/null @@ -1,108 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_LOWER_BOUND_H -#define _LIBCPP___ALGORITHM_LOWER_BOUND_H - -#include <__algorithm/comp.h> -#include <__algorithm/half_positive.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/advance.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lower_bound_bisecting( - _Iter __first, - const _Type& __value, - typename iterator_traits<_Iter>::difference_type __len, - _Comp& __comp, - _Proj& __proj) { - while (__len != 0) { - auto __l2 = std::__half_positive(__len); - _Iter __m = __first; - _IterOps<_AlgPolicy>::advance(__m, __l2); - if (std::__invoke(__comp, std::__invoke(__proj, *__m), __value)) { - __first = ++__m; - __len -= __l2 + 1; - } else { - __len = __l2; - } - } - return __first; -} - -// One-sided binary search, aka meta binary search, has been in the public domain for decades, and has the general -// advantage of being \Omega(1) rather than the classic algorithm's \Omega(log(n)), with the downside of executing at -// most 2*log(n) comparisons vs the classic algorithm's exact log(n). There are two scenarios in which it really shines: -// the first one is when operating over non-random-access iterators, because the classic algorithm requires knowing the -// container's size upfront, which adds \Omega(n) iterator increments to the complexity. The second one is when you're -// traversing the container in order, trying to fast-forward to the next value: in that case, the classic algorithm -// would yield \Omega(n*log(n)) comparisons and, for non-random-access iterators, \Omega(n^2) iterator increments, -// whereas the one-sided version will yield O(n) operations on both counts, with a \Omega(log(n)) bound on the number of -// comparisons. -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -__lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { - // step = 0, ensuring we can always short-circuit when distance is 1 later on - if (__first == __last || !std::__invoke(__comp, std::__invoke(__proj, *__first), __value)) - return __first; - - using _Distance = typename iterator_traits<_ForwardIterator>::difference_type; - for (_Distance __step = 1; __first != __last; __step <<= 1) { - auto __it = __first; - auto __dist = __step - _IterOps<_AlgPolicy>::__advance_to(__it, __step, __last); - // once we reach the last range where needle can be we must start - // looking inwards, bisecting that range - if (__it == __last || !std::__invoke(__comp, std::__invoke(__proj, *__it), __value)) { - // we've already checked the previous value and it was less, we can save - // one comparison by skipping bisection - if (__dist == 1) - return __it; - return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj); - } - // range not found, move forward! - __first = __it; - } - return __first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -__lower_bound(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { - const auto __dist = _IterOps<_AlgPolicy>::distance(__first, __last); - return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); - auto __proj = std::__identity(); - return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::lower_bound(__first, __last, __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_LOWER_BOUND_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/make_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/make_heap.h deleted file mode 100644 index f98a0d2..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/make_heap.h +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MAKE_HEAP_H -#define _LIBCPP___ALGORITHM_MAKE_HEAP_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/push_heap.h> -#include <__algorithm/sift_down.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/is_arithmetic.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - __comp_ref_type<_Compare> __comp_ref = __comp; - - using __diff_t = __iterator_difference_type<_RandomAccessIterator>; - const __diff_t __n = __last - __first; - - const bool __assume_both_children = is_arithmetic<__iterator_value_type<_RandomAccessIterator> >::value; - - // While it would be correct to always assume we have both children, in practice we observed this to be a performance - // improvement only for arithmetic types. - const __diff_t __sift_down_n = __assume_both_children ? ((__n & 1) ? __n : __n - 1) : __n; - - if (__n > 1) { - // start from the first parent, there is no need to consider children - - for (__diff_t __start = (__sift_down_n - 2) / 2; __start >= 0; --__start) { - std::__sift_down<_AlgPolicy, __assume_both_children>(__first, __comp_ref, __sift_down_n, __start); - } - if _LIBCPP_CONSTEXPR (__assume_both_children) - std::__sift_up<_AlgPolicy>(__first, __last, __comp, __n); - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::make_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MAKE_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/make_projected.h b/third_party/libcxx/include/c++/v1/__algorithm/make_projected.h deleted file mode 100644 index 4a25822..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/make_projected.h +++ /dev/null @@ -1,104 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MAKE_PROJECTED_H -#define _LIBCPP___ALGORITHM_MAKE_PROJECTED_H - -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__type_traits/decay.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_member_pointer.h> -#include <__utility/declval.h> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _ProjectedPred { - _Pred& __pred; // Can be a unary or a binary predicate. - _Proj& __proj; - - _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _ProjectedPred(_Pred& __pred_arg, _Proj& __proj_arg) - : __pred(__pred_arg), __proj(__proj_arg) {} - - template - __invoke_result_t<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))> _LIBCPP_CONSTEXPR - _LIBCPP_HIDE_FROM_ABI - operator()(_Tp&& __v) const { - return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v))); - } - - template - __invoke_result_t<_Pred&, - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())), - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))> _LIBCPP_CONSTEXPR - _LIBCPP_HIDE_FROM_ABI - operator()(_T1&& __lhs, _T2&& __rhs) const { - return std::__invoke( - __pred, std::__invoke(__proj, std::forward<_T1>(__lhs)), std::__invoke(__proj, std::forward<_T2>(__rhs))); - } -}; - -template < - class _Pred, - class _Proj, - __enable_if_t >::value && __is_identity<__decay_t<_Proj> >::value), int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj> __make_projected(_Pred& __pred, _Proj& __proj) { - return _ProjectedPred<_Pred, _Proj>(__pred, __proj); -} - -// Avoid creating the functor and just use the pristine comparator -- for certain algorithms, this would enable -// optimizations that rely on the type of the comparator. Additionally, this results in less layers of indirection in -// the call stack when the comparator is invoked, even in an unoptimized build. -template < - class _Pred, - class _Proj, - __enable_if_t >::value && __is_identity<__decay_t<_Proj> >::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Pred& __make_projected(_Pred& __pred, _Proj&) { - return __pred; -} - -_LIBCPP_END_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) { - if constexpr (__is_identity>::value && __is_identity>::value && - !is_member_pointer_v>) { - // Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable - // optimizations that rely on the type of the comparator. - return __comp; - - } else { - return [&](auto&& __lhs, auto&& __rhs) -> bool { - return std::invoke(__comp, - std::invoke(__proj1, std::forward(__lhs)), - std::invoke(__proj2, std::forward(__rhs))); - }; - } -} - -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_MAKE_PROJECTED_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/max.h b/third_party/libcxx/include/c++/v1/__algorithm/max.h deleted file mode 100644 index 1673e6b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/max.h +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MAX_H -#define _LIBCPP___ALGORITHM_MAX_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/max_element.h> -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& -max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { - return __comp(__a, __b) ? __b : __a; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& -max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { - return std::max(__a, __b, __less<>()); -} - -#ifndef _LIBCPP_CXX03_LANG - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp -max(initializer_list<_Tp> __t, _Compare __comp) { - return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) { - return *std::max_element(__t.begin(), __t.end(), __less<>()); -} - -#endif // _LIBCPP_CXX03_LANG - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MAX_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/max_element.h b/third_party/libcxx/include/c++/v1/__algorithm/max_element.h deleted file mode 100644 index 929f337..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/max_element.h +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MAX_ELEMENT_H -#define _LIBCPP___ALGORITHM_MAX_ELEMENT_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/is_callable.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator -__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert( - __has_forward_iterator_category<_ForwardIterator>::value, "std::max_element requires a ForwardIterator"); - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) - if (__comp(*__first, *__i)) - __first = __i; - } - return __first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator -max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert( - __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); - return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator -max_element(_ForwardIterator __first, _ForwardIterator __last) { - return std::max_element(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_MAX_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/merge.h b/third_party/libcxx/include/c++/v1/__algorithm/merge.h deleted file mode 100644 index ae859b7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/merge.h +++ /dev/null @@ -1,68 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MERGE_H -#define _LIBCPP___ALGORITHM_MERGE_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/copy.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __merge( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) - return std::copy(__first1, __last1, __result); - if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__first2; - } else { - *__result = *__first1; - ++__first1; - } - } - return std::copy(__first2, __last2, __result); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -merge(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -merge(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::merge(__first1, __last1, __first2, __last2, __result, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_MERGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/min.h b/third_party/libcxx/include/c++/v1/__algorithm/min.h deleted file mode 100644 index 660e0b2..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/min.h +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MIN_H -#define _LIBCPP___ALGORITHM_MIN_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/min_element.h> -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& -min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { - return __comp(__b, __a) ? __b : __a; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& -min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { - return std::min(__a, __b, __less<>()); -} - -#ifndef _LIBCPP_CXX03_LANG - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp -min(initializer_list<_Tp> __t, _Compare __comp) { - return *std::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) { - return *std::min_element(__t.begin(), __t.end(), __less<>()); -} - -#endif // _LIBCPP_CXX03_LANG - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MIN_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/min_element.h b/third_party/libcxx/include/c++/v1/__algorithm/min_element.h deleted file mode 100644 index fdab63a..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/min_element.h +++ /dev/null @@ -1,71 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MIN_ELEMENT_H -#define _LIBCPP___ALGORITHM_MIN_ELEMENT_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter -__min_element(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - if (__first == __last) - return __first; - - _Iter __i = __first; - while (++__i != __last) - if (std::__invoke(__comp, std::__invoke(__proj, *__i), std::__invoke(__proj, *__first))) - __first = __i; - - return __first; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) { - auto __proj = __identity(); - return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator -min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert( - __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator"); - static_assert( - __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); - - return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator -min_element(_ForwardIterator __first, _ForwardIterator __last) { - return std::min_element(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/min_max_result.h b/third_party/libcxx/include/c++/v1/__algorithm/min_max_result.h deleted file mode 100644 index e988df7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/min_max_result.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H -#define _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { - -template -struct min_max_result { - _LIBCPP_NO_UNIQUE_ADDRESS _T1 min; - _LIBCPP_NO_UNIQUE_ADDRESS _T1 max; - - template - requires convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() const& { - return {min, max}; - } - - template - requires convertible_to<_T1, _T2> - _LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() && { - return {std::move(min), std::move(max)}; - } -}; - -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/minmax.h b/third_party/libcxx/include/c++/v1/__algorithm/minmax.h deleted file mode 100644 index de0bec0..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/minmax.h +++ /dev/null @@ -1,59 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MINMAX_H -#define _LIBCPP___ALGORITHM_MINMAX_H - -#include <__algorithm/comp.h> -#include <__algorithm/minmax_element.h> -#include <__config> -#include <__functional/identity.h> -#include <__type_traits/is_callable.h> -#include <__utility/pair.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair -minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { - return __comp(__b, __a) ? pair(__b, __a) : pair(__a, __b); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair -minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { - return std::minmax(__a, __b, __less<>()); -} - -#ifndef _LIBCPP_CXX03_LANG - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> -minmax(initializer_list<_Tp> __t, _Compare __comp) { - static_assert(__is_callable<_Compare&, _Tp, _Tp>::value, "The comparator has to be callable"); - __identity __proj; - auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj); - return pair<_Tp, _Tp>(*__ret.first, *__ret.second); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> -minmax(initializer_list<_Tp> __t) { - return std::minmax(__t, __less<>()); -} - -#endif // _LIBCPP_CXX03_LANG - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_MINMAX_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/minmax_element.h b/third_party/libcxx/include/c++/v1/__algorithm/minmax_element.h deleted file mode 100644 index dc0c3a8..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/minmax_element.h +++ /dev/null @@ -1,100 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H -#define _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H - -#include <__algorithm/comp.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _MinmaxElementLessFunc { - _Comp& __comp_; - _Proj& __proj_; - -public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) - : __comp_(__comp), __proj_(__proj) {} - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(_Iter& __it1, _Iter& __it2) { - return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2)); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> -__minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj); - - pair<_Iter, _Iter> __result(__first, __first); - if (__first == __last || ++__first == __last) - return __result; - - if (__less(__first, __result.first)) - __result.first = __first; - else - __result.second = __first; - - while (++__first != __last) { - _Iter __i = __first; - if (++__first == __last) { - if (__less(__i, __result.first)) - __result.first = __i; - else if (!__less(__i, __result.second)) - __result.second = __i; - return __result; - } - - if (__less(__first, __i)) { - if (__less(__first, __result.first)) - __result.first = __first; - if (!__less(__i, __result.second)) - __result.second = __i; - } else { - if (__less(__i, __result.first)) - __result.first = __i; - if (!__less(__first, __result.second)) - __result.second = __first; - } - } - - return __result; -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> -minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert( - __has_forward_iterator_category<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator"); - static_assert( - __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); - auto __proj = __identity(); - return std::__minmax_element_impl(__first, __last, __comp, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> -minmax_element(_ForwardIterator __first, _ForwardIterator __last) { - return std::minmax_element(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/mismatch.h b/third_party/libcxx/include/c++/v1/__algorithm/mismatch.h deleted file mode 100644 index 7111cd9..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/mismatch.h +++ /dev/null @@ -1,218 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MISMATCH_H -#define _LIBCPP___ALGORITHM_MISMATCH_H - -#include <__algorithm/comp.h> -#include <__algorithm/min.h> -#include <__algorithm/simd_utils.h> -#include <__algorithm/unwrap_iter.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/identity.h> -#include <__iterator/aliasing_iterator.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/desugars_to.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_constant_evaluated.h> -#include <__type_traits/is_equality_comparable.h> -#include <__type_traits/is_integral.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> -__mismatch_loop(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - while (__first1 != __last1) { - if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - ++__first2; - } - return std::make_pair(std::move(__first1), std::move(__first2)); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> -__mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2); -} - -#if _LIBCPP_VECTORIZE_ALGORITHMS - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter> -__mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) { - using __value_type = __iterator_value_type<_Iter>; - constexpr size_t __unroll_count = 4; - constexpr size_t __vec_size = __native_vector_size<__value_type>; - using __vec = __simd_vector<__value_type, __vec_size>; - - if (!__libcpp_is_constant_evaluated()) { - auto __orig_first1 = __first1; - auto __last2 = __first2 + (__last1 - __first1); - while (static_cast(__last1 - __first1) >= __unroll_count * __vec_size) [[__unlikely__]] { - __vec __lhs[__unroll_count]; - __vec __rhs[__unroll_count]; - - for (size_t __i = 0; __i != __unroll_count; ++__i) { - __lhs[__i] = std::__load_vector<__vec>(__first1 + __i * __vec_size); - __rhs[__i] = std::__load_vector<__vec>(__first2 + __i * __vec_size); - } - - for (size_t __i = 0; __i != __unroll_count; ++__i) { - if (auto __cmp_res = __lhs[__i] == __rhs[__i]; !std::__all_of(__cmp_res)) { - auto __offset = __i * __vec_size + std::__find_first_not_set(__cmp_res); - return {__first1 + __offset, __first2 + __offset}; - } - } - - __first1 += __unroll_count * __vec_size; - __first2 += __unroll_count * __vec_size; - } - - // check the remaining 0-3 vectors - while (static_cast(__last1 - __first1) >= __vec_size) { - if (auto __cmp_res = std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2); - !std::__all_of(__cmp_res)) { - auto __offset = std::__find_first_not_set(__cmp_res); - return {__first1 + __offset, __first2 + __offset}; - } - __first1 += __vec_size; - __first2 += __vec_size; - } - - if (__last1 - __first1 == 0) - return {__first1, __first2}; - - // Check if we can load elements in front of the current pointer. If that's the case load a vector at - // (last - vector_size) to check the remaining elements - if (static_cast(__first1 - __orig_first1) >= __vec_size) { - __first1 = __last1 - __vec_size; - __first2 = __last2 - __vec_size; - auto __offset = - std::__find_first_not_set(std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2)); - return {__first1 + __offset, __first2 + __offset}; - } // else loop over the elements individually - } - - __equal_to __pred; - __identity __proj; - return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj, __proj); -} - -template ::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> && - __is_identity<_Proj1>::value && __is_identity<_Proj2>::value, - int> = 0> -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> -__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred&, _Proj1&, _Proj2&) { - return std::__mismatch_vectorized(__first1, __last1, __first2); -} - -template ::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> && - __is_identity<_Proj1>::value && __is_identity<_Proj2>::value && - __can_map_to_integer_v<_Tp> && __is_trivially_equality_comparable_v<_Tp, _Tp>, - int> = 0> -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> -__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - if (__libcpp_is_constant_evaluated()) { - return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2); - } else { - using _Iter = __aliasing_iterator<_Tp*, __get_as_integer_type_t<_Tp>>; - auto __ret = std::__mismatch_vectorized(_Iter(__first1), _Iter(__last1), _Iter(__first2)); - return {__ret.first.__base(), __ret.second.__base()}; - } -} -#endif // _LIBCPP_VECTORIZE_ALGORITHMS - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> -mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { - __identity __proj; - auto __res = std::__mismatch( - std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred, __proj, __proj); - return std::make_pair(std::__rewrap_iter(__first1, __res.first), std::__rewrap_iter(__first2, __res.second)); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> -mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { - return std::mismatch(__first1, __last1, __first2, __equal_to()); -} - -#if _LIBCPP_STD_VER >= 14 -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - while (__first1 != __last1 && __first2 != __last2) { - if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - ++__first2; - } - return {std::move(__first1), std::move(__first2)}; -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> -__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - auto __len = std::min(__last1 - __first1, __last2 - __first2); - return std::__mismatch(__first1, __first1 + __len, __first2, __pred, __proj1, __proj2); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> -mismatch(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _BinaryPredicate __pred) { - __identity __proj; - auto __res = std::__mismatch( - std::__unwrap_iter(__first1), - std::__unwrap_iter(__last1), - std::__unwrap_iter(__first2), - std::__unwrap_iter(__last2), - __pred, - __proj, - __proj); - return {std::__rewrap_iter(__first1, __res.first), std::__rewrap_iter(__first2, __res.second)}; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> -mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - return std::mismatch(__first1, __last1, __first2, __last2, __equal_to()); -} -#endif - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MISMATCH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/move.h b/third_party/libcxx/include/c++/v1/__algorithm/move.h deleted file mode 100644 index ddadfa7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/move.h +++ /dev/null @@ -1,128 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MOVE_H -#define _LIBCPP___ALGORITHM_MOVE_H - -#include <__algorithm/copy.h> -#include <__algorithm/copy_move_common.h> -#include <__algorithm/for_each_segment.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> -#include <__config> -#include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__type_traits/common_type.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> -__move(_InIter __first, _Sent __last, _OutIter __result); - -template -struct __move_impl { - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - while (__first != __last) { - *__result = _IterOps<_AlgPolicy>::__iter_move(__first); - ++__first; - ++__result; - } - return std::make_pair(std::move(__first), std::move(__result)); - } - - template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; - std::__for_each_segment(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__move<_AlgPolicy>(__lfirst, __llast, std::move(__result)).second; - }); - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - using _DiffT = - typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type; - - if (__first == __last) - return std::make_pair(std::move(__first), std::move(__result)); - - auto __local_first = _Traits::__local(__result); - auto __segment_iterator = _Traits::__segment(__result); - while (true) { - auto __local_last = _Traits::__end(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iters = std::__move<_AlgPolicy>(__first, __first + __size, __local_first); - __first = std::move(__iters.first); - - if (__first == __last) - return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); - - __local_first = _Traits::__begin(++__segment_iterator); - } - } - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > - operator()(__bit_iterator<_Cp, _IsConst> __first, - __bit_iterator<_Cp, _IsConst> __last, - __bit_iterator<_Cp, false> __result) { - return std::__copy(__first, __last, __result); - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> - operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_trivial_impl(__first, __last, __result); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> -__move(_InIter __first, _Sent __last, _OutIter __result) { - return std::__copy_move_unwrap_iters<__move_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - static_assert(is_copy_constructible<_InputIterator>::value, "Iterators has to be copy constructible."); - static_assert(is_copy_constructible<_OutputIterator>::value, "The output iterator has to be copy constructible."); - - return std::__move<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MOVE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/move_backward.h b/third_party/libcxx/include/c++/v1/__algorithm/move_backward.h deleted file mode 100644 index 43b7205..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/move_backward.h +++ /dev/null @@ -1,134 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_MOVE_BACKWARD_H -#define _LIBCPP___ALGORITHM_MOVE_BACKWARD_H - -#include <__algorithm/copy_backward.h> -#include <__algorithm/copy_move_common.h> -#include <__algorithm/for_each_segment.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> -#include <__config> -#include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/segmented_iterator.h> -#include <__type_traits/common_type.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> -__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result); - -template -struct __move_backward_impl { - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - auto __original_last_iter = __last_iter; - - while (__first != __last_iter) { - *--__result = _IterOps<_AlgPolicy>::__iter_move(--__last_iter); - } - - return std::make_pair(std::move(__original_last_iter), std::move(__result)); - } - - template , int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using __local_iterator = typename __segmented_iterator_traits<_InIter>::__local_iterator; - std::__for_each_segment_backward(__first, __last, [&__result](__local_iterator __lfirst, __local_iterator __llast) { - __result = std::__move_backward<_AlgPolicy>(std::move(__lfirst), std::move(__llast), std::move(__result)).second; - }); - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator_v<_InIter> && __is_segmented_iterator_v<_OutIter>, - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> - operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - using _DiffT = - typename common_type<__iterator_difference_type<_InIter>, __iterator_difference_type<_OutIter> >::type; - - // When the range contains no elements, __result might not be a valid iterator - if (__first == __last) - return std::make_pair(__first, __result); - - auto __orig_last = __last; - - auto __local_last = _Traits::__local(__result); - auto __segment_iterator = _Traits::__segment(__result); - while (true) { - auto __local_first = _Traits::__begin(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iter = std::__move_backward<_AlgPolicy>(__last - __size, __last, __local_last).second; - __last -= __size; - - if (__first == __last) - return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); - - __local_last = _Traits::__end(--__segment_iterator); - } - } - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > - operator()(__bit_iterator<_Cp, _IsConst> __first, - __bit_iterator<_Cp, _IsConst> __last, - __bit_iterator<_Cp, false> __result) { - return std::__copy_backward<_ClassicAlgPolicy>(__first, __last, __result); - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> - operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_backward_trivial_impl(__first, __last, __result); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> -__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { - static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && - std::is_copy_constructible<_BidirectionalIterator1>::value, - "Iterators must be copy constructible."); - - return std::__copy_move_unwrap_iters<__move_backward_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2 -move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_MOVE_BACKWARD_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/next_permutation.h b/third_party/libcxx/include/c++/v1/__algorithm/next_permutation.h deleted file mode 100644 index 011ee02..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/next_permutation.h +++ /dev/null @@ -1,75 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H -#define _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/reverse.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool> -__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) { - using _Result = pair<_BidirectionalIterator, bool>; - - _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - _BidirectionalIterator __i = __last_iter; - if (__first == __last || __first == --__i) - return _Result(std::move(__last_iter), false); - - while (true) { - _BidirectionalIterator __ip1 = __i; - if (__comp(*--__i, *__ip1)) { - _BidirectionalIterator __j = __last_iter; - while (!__comp(*__i, *--__j)) - ; - _IterOps<_AlgPolicy>::iter_swap(__i, __j); - std::__reverse<_AlgPolicy>(__ip1, __last_iter); - return _Result(std::move(__last_iter), true); - } - if (__i == __first) { - std::__reverse<_AlgPolicy>(__first, __last_iter); - return _Result(std::move(__last_iter), false); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - return std::__next_permutation<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { - return std::next_permutation(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/none_of.h b/third_party/libcxx/include/c++/v1/__algorithm/none_of.h deleted file mode 100644 index 1e1c8d1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/none_of.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_NONE_OF_H -#define _LIBCPP___ALGORITHM_NONE_OF_H - -#include <__algorithm/any_of.h> -#include <__config> -#include <__functional/identity.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - __identity __proj; - return !std::__any_of(__first, __last, __pred, __proj); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_NONE_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/nth_element.h b/third_party/libcxx/include/c++/v1/__algorithm/nth_element.h deleted file mode 100644 index da748d7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/nth_element.h +++ /dev/null @@ -1,261 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_NTH_ELEMENT_H -#define _LIBCPP___ALGORITHM_NTH_ELEMENT_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/sort.h> -#include <__assert> -#include <__config> -#include <__debug_utils/randomize_range.h> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __nth_element_find_guard( - _RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator __m, _Compare __comp) { - // manually guard downward moving __j against __i - while (true) { - if (__i == --__j) { - return false; - } - if (__comp(*__j, *__m)) { - return true; // found guard for downward moving __j, now use unguarded partition - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -// NOLINTNEXTLINE(readability-function-cognitive-complexity) -__nth_element( - _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - // _Compare is known to be a reference type - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - const difference_type __limit = 7; - while (true) { - if (__nth == __last) - return; - difference_type __len = __last - __first; - switch (__len) { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - _Ops::iter_swap(__first, __last); - return; - case 3: { - _RandomAccessIterator __m = __first; - std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp); - return; - } - } - if (__len <= __limit) { - std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp); - return; - } - // __len > __limit >= 3 - _RandomAccessIterator __m = __first + __len / 2; - _RandomAccessIterator __lm1 = __last; - unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp); - // *__m is median - // partition [__first, __m) < *__m and *__m <= [__m, __last) - // (this inhibits tossing elements equivalent to __m around unnecessarily) - _RandomAccessIterator __i = __first; - _RandomAccessIterator __j = __lm1; - // j points beyond range to be tested, *__lm1 is known to be <= *__m - // The search going up is known to be guarded but the search coming down isn't. - // Prime the downward search with a guard. - if (!__comp(*__i, *__m)) // if *__first == *__m - { - // *__first == *__m, *__first doesn't go in first part - if (std::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) { - _Ops::iter_swap(__i, __j); - ++__n_swaps; - } else { - // *__first == *__m, *__m <= all other elements - // Partition instead into [__first, __i) == *__first and *__first < [__i, __last) - ++__i; // __first + 1 - __j = __last; - if (!__comp(*__first, *--__j)) { // we need a guard if *__first == *(__last-1) - while (true) { - if (__i == __j) { - return; // [__first, __last) all equivalent elements - } else if (__comp(*__first, *__i)) { - _Ops::iter_swap(__i, __j); - ++__n_swaps; - ++__i; - break; - } - ++__i; - } - } - // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 - if (__i == __j) { - return; - } - while (true) { - while (!__comp(*__first, *__i)) { - ++__i; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __i != __last, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __j != __first, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__j; - } while (__comp(*__first, *__j)); - if (__i >= __j) - break; - _Ops::iter_swap(__i, __j); - ++__n_swaps; - ++__i; - } - // [__first, __i) == *__first and *__first < [__i, __last) - // The first part is sorted, - if (__nth < __i) { - return; - } - // __nth_element the second part - // std::__nth_element<_Compare>(__i, __nth, __last, __comp); - __first = __i; - continue; - } - } - ++__i; - // j points beyond range to be tested, *__lm1 is known to be <= *__m - // if not yet partitioned... - if (__i < __j) { - // known that *(__i - 1) < *__m - while (true) { - // __m still guards upward moving __i - while (__comp(*__i, *__m)) { - ++__i; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __i != __last, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } - // It is now known that a guard exists for downward moving __j - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __j != __first, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__j; - } while (!__comp(*__j, *__m)); - if (__i >= __j) - break; - _Ops::iter_swap(__i, __j); - ++__n_swaps; - // It is known that __m != __j - // If __m just moved, follow it - if (__m == __i) - __m = __j; - ++__i; - } - } - // [__first, __i) < *__m and *__m <= [__i, __last) - if (__i != __m && __comp(*__m, *__i)) { - _Ops::iter_swap(__i, __m); - ++__n_swaps; - } - // [__first, __i) < *__i and *__i <= [__i+1, __last) - if (__nth == __i) - return; - if (__n_swaps == 0) { - // We were given a perfectly partitioned sequence. Coincidence? - if (__nth < __i) { - // Check for [__first, __i) already sorted - __j = __m = __first; - while (true) { - if (++__j == __i) { - // [__first, __i) sorted - return; - } - if (__comp(*__j, *__m)) { - // not yet sorted, so sort - break; - } - __m = __j; - } - } else { - // Check for [__i, __last) already sorted - __j = __m = __i; - while (true) { - if (++__j == __last) { - // [__i, __last) sorted - return; - } - if (__comp(*__j, *__m)) { - // not yet sorted, so sort - break; - } - __m = __j; - } - } - } - // __nth_element on range containing __nth - if (__nth < __i) { - // std::__nth_element<_Compare>(__first, __nth, __i, __comp); - __last = __i; - } else { - // std::__nth_element<_Compare>(__i+1, __nth, __last, __comp); - __first = ++__i; - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __nth_element_impl( - _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare& __comp) { - if (__nth == __last) - return; - - std::__debug_randomize_range<_AlgPolicy>(__first, __last); - - std::__nth_element<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __nth, __last, __comp); - - std::__debug_randomize_range<_AlgPolicy>(__first, __nth); - if (__nth != __last) { - std::__debug_randomize_range<_AlgPolicy>(++__nth, __last); - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { - std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) { - std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_NTH_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/out_value_result.h b/third_party/libcxx/include/c++/v1/__algorithm/out_value_result.h deleted file mode 100644 index 9e1e0e0..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/out_value_result.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H -#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 23 - -namespace ranges { - -template -struct out_value_result { - _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out; - _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value; - - template - requires convertible_to && convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator out_value_result<_OutIter2, _ValType2>() const& { - return {out, value}; - } - - template - requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, _ValType2> - _LIBCPP_HIDE_FROM_ABI constexpr operator out_value_result<_OutIter2, _ValType2>() && { - return {std::move(out), std::move(value)}; - } -}; - -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/partial_sort.h b/third_party/libcxx/include/c++/v1/__algorithm/partial_sort.h deleted file mode 100644 index 4b39ae0..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/partial_sort.h +++ /dev/null @@ -1,91 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PARTIAL_SORT_H -#define _LIBCPP___ALGORITHM_PARTIAL_SORT_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_heap.h> -#include <__algorithm/sift_down.h> -#include <__algorithm/sort_heap.h> -#include <__config> -#include <__debug_utils/randomize_range.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/is_assignable.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator __partial_sort_impl( - _RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) { - if (__first == __middle) { - return _IterOps<_AlgPolicy>::next(__middle, __last); - } - - std::__make_heap<_AlgPolicy>(__first, __middle, __comp); - - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first; - _RandomAccessIterator __i = __middle; - for (; __i != __last; ++__i) { - if (__comp(*__i, *__first)) { - _IterOps<_AlgPolicy>::iter_swap(__i, __first); - std::__sift_down<_AlgPolicy, false>(__first, __comp, __len, 0); - } - } - std::__sort_heap<_AlgPolicy>(std::move(__first), std::move(__middle), __comp); - - return __i; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator -__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare& __comp) { - if (__first == __middle) - return _IterOps<_AlgPolicy>::next(__middle, __last); - - std::__debug_randomize_range<_AlgPolicy>(__first, __last); - - auto __last_iter = - std::__partial_sort_impl<_AlgPolicy>(__first, __middle, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); - - std::__debug_randomize_range<_AlgPolicy>(__middle, __last); - - return __last_iter; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void partial_sort( - _RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - (void)std::__partial_sort<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) { - std::partial_sort(__first, __middle, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/partial_sort_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/partial_sort_copy.h deleted file mode 100644 index 2230dfc..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/partial_sort_copy.h +++ /dev/null @@ -1,106 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H -#define _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_heap.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/sift_down.h> -#include <__algorithm/sort_heap.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy( - _InputIterator __first, - _Sentinel1 __last, - _RandomAccessIterator __result_first, - _Sentinel2 __result_last, - _Compare&& __comp, - _Proj1&& __proj1, - _Proj2&& __proj2) { - _RandomAccessIterator __r = __result_first; - auto&& __projected_comp = std::__make_projected(__comp, __proj2); - - if (__r != __result_last) { - for (; __first != __last && __r != __result_last; ++__first, (void)++__r) - *__r = *__first; - std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp); - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first; - for (; __first != __last; ++__first) - if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) { - *__result_first = *__first; - std::__sift_down<_AlgPolicy, false>(__result_first, __projected_comp, __len, 0); - } - std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp); - } - - return pair<_InputIterator, _RandomAccessIterator>( - _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy( - _InputIterator __first, - _InputIterator __last, - _RandomAccessIterator __result_first, - _RandomAccessIterator __result_last, - _Compare __comp) { - static_assert(__is_callable<_Compare&, decltype(*__first), decltype(*__result_first)>::value, - "The comparator has to be callable"); - - auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>( - __first, - __last, - __result_first, - __result_last, - static_cast<__comp_ref_type<_Compare> >(__comp), - __identity(), - __identity()); - return __result.second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy( - _InputIterator __first, - _InputIterator __last, - _RandomAccessIterator __result_first, - _RandomAccessIterator __result_last) { - return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/partition.h b/third_party/libcxx/include/c++/v1/__algorithm/partition.h deleted file mode 100644 index 669aac3..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/partition.h +++ /dev/null @@ -1,91 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PARTITION_H -#define _LIBCPP___ALGORITHM_PARTITION_H - -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> -__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) { - while (true) { - if (__first == __last) - return std::make_pair(__first, __first); - if (!__pred(*__first)) - break; - ++__first; - } - - _ForwardIterator __p = __first; - while (++__p != __last) { - if (__pred(*__p)) { - _IterOps<_AlgPolicy>::iter_swap(__first, __p); - ++__first; - } - } - return std::make_pair(std::move(__first), std::move(__p)); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, _BidirectionalIterator> -__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, bidirectional_iterator_tag) { - _BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel); - _BidirectionalIterator __last = __original_last; - - while (true) { - while (true) { - if (__first == __last) - return std::make_pair(std::move(__first), std::move(__original_last)); - if (!__pred(*__first)) - break; - ++__first; - } - do { - if (__first == --__last) - return std::make_pair(std::move(__first), std::move(__original_last)); - } while (!__pred(*__last)); - _IterOps<_AlgPolicy>::iter_swap(__first, __last); - ++__first; - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> -__partition(_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) { - return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>( - std::move(__first), std::move(__last), __pred, __iter_category); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category; - auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory()); - return __result.first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_PARTITION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/partition_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/partition_copy.h deleted file mode 100644 index 147b45c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/partition_copy.h +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PARTITION_COPY_H -#define _LIBCPP___ALGORITHM_PARTITION_COPY_H - -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2> partition_copy( - _InputIterator __first, - _InputIterator __last, - _OutputIterator1 __out_true, - _OutputIterator2 __out_false, - _Predicate __pred) { - for (; __first != __last; ++__first) { - if (__pred(*__first)) { - *__out_true = *__first; - ++__out_true; - } else { - *__out_false = *__first; - ++__out_false; - } - } - return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_PARTITION_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/partition_point.h b/third_party/libcxx/include/c++/v1/__algorithm/partition_point.h deleted file mode 100644 index 504dbf1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/partition_point.h +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PARTITION_POINT_H -#define _LIBCPP___ALGORITHM_PARTITION_POINT_H - -#include <__algorithm/half_positive.h> -#include <__config> -#include <__iterator/advance.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; - difference_type __len = std::distance(__first, __last); - while (__len != 0) { - difference_type __l2 = std::__half_positive(__len); - _ForwardIterator __m = __first; - std::advance(__m, __l2); - if (__pred(*__m)) { - __first = ++__m; - __len -= __l2 + 1; - } else - __len = __l2; - } - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_PARTITION_POINT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/pop_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/pop_heap.h deleted file mode 100644 index 6d23830..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/pop_heap.h +++ /dev/null @@ -1,81 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_POP_HEAP_H -#define _LIBCPP___ALGORITHM_POP_HEAP_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/push_heap.h> -#include <__algorithm/sift_down.h> -#include <__assert> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/is_assignable.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__pop_heap(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare& __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len) { - // Calling `pop_heap` on an empty range is undefined behavior, but in practice it will be a no-op. - _LIBCPP_ASSERT_PEDANTIC(__len > 0, "The heap given to pop_heap must be non-empty"); - - __comp_ref_type<_Compare> __comp_ref = __comp; - - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - if (__len > 1) { - value_type __top = _IterOps<_AlgPolicy>::__iter_move(__first); // create a hole at __first - _RandomAccessIterator __hole = std::__floyd_sift_down<_AlgPolicy>(__first, __comp_ref, __len); - --__last; - - if (__hole == __last) { - *__hole = std::move(__top); - } else { - *__hole = _IterOps<_AlgPolicy>::__iter_move(__last); - ++__hole; - *__last = std::move(__top); - std::__sift_up<_AlgPolicy>(__first, __hole, __comp_ref, __hole - __first); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first; - std::__pop_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp, __len); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::pop_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_POP_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/prev_permutation.h b/third_party/libcxx/include/c++/v1/__algorithm/prev_permutation.h deleted file mode 100644 index 8d15b68..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/prev_permutation.h +++ /dev/null @@ -1,75 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PREV_PERMUTATION_H -#define _LIBCPP___ALGORITHM_PREV_PERMUTATION_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/reverse.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool> -__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) { - using _Result = pair<_BidirectionalIterator, bool>; - - _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - _BidirectionalIterator __i = __last_iter; - if (__first == __last || __first == --__i) - return _Result(std::move(__last_iter), false); - - while (true) { - _BidirectionalIterator __ip1 = __i; - if (__comp(*__ip1, *--__i)) { - _BidirectionalIterator __j = __last_iter; - while (!__comp(*--__j, *__i)) - ; - _IterOps<_AlgPolicy>::iter_swap(__i, __j); - std::__reverse<_AlgPolicy>(__ip1, __last_iter); - return _Result(std::move(__last_iter), true); - } - if (__i == __first) { - std::__reverse<_AlgPolicy>(__first, __last_iter); - return _Result(std::move(__last_iter), false); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - return std::__prev_permutation<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { - return std::prev_permutation(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_PREV_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/pstl.h b/third_party/libcxx/include/c++/v1/__algorithm/pstl.h deleted file mode 100644 index 10625ea..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/pstl.h +++ /dev/null @@ -1,688 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PSTL_H -#define _LIBCPP___ALGORITHM_PSTL_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 - -# include <__functional/operations.h> -# include <__iterator/cpp17_iterator_concepts.h> -# include <__iterator/iterator_traits.h> -# include <__pstl/backend.h> -# include <__pstl/dispatch.h> -# include <__pstl/handle_exception.h> -# include <__type_traits/enable_if.h> -# include <__type_traits/is_execution_policy.h> -# include <__type_traits/remove_cvref.h> -# include <__utility/forward.h> -# include <__utility/move.h> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "any_of requires a ForwardIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__any_of, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "all_of requires a ForwardIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__all_of, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "none_of requires a ForwardIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__none_of, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator -copy(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR( - _ForwardIterator, "copy(first, last, result) requires [first, last) to be ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR( - _ForwardOutIterator, "copy(first, last, result) requires result to be a ForwardIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(*__first), "copy(first, last, result) requires result to be an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__copy, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__result)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator -copy_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _ForwardOutIterator __result) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR( - _ForwardIterator, "copy_n(first, n, result) requires first to be a ForwardIterator"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR( - _ForwardOutIterator, "copy_n(first, n, result) requires result to be a ForwardIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(*__first), "copy_n(first, n, result) requires result to be an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__copy_n, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__n), std::move(__result)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __iterator_difference_type<_ForwardIterator> -count_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR( - _ForwardIterator, "count_if(first, last, pred) requires [first, last) to be ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__count_if, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __iterator_difference_type<_ForwardIterator> -count(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR( - _ForwardIterator, "count(first, last, val) requires [first, last) to be ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__count, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -equal(_ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _Pred __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__equal_3leg, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -equal(_ExecutionPolicy&& __policy, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__equal_3leg, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first1), - std::move(__last1), - std::move(__first2), - equal_to{}); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -equal(_ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _Pred __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__equal, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -equal(_ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__equal, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - equal_to{}); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "fill requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__fill, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, const _Tp& __value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "fill_n requires a ForwardIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__fill_n, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__n), __value); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ForwardIterator -find_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "find_if requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__find_if, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ForwardIterator -find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "find_if_not requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__find_if_not, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ForwardIterator -find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "find requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__find, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -for_each(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Function __func) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "for_each requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__for_each, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__func)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -for_each_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __size, _Function __func) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "for_each_n requires a ForwardIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__for_each_n, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__size), std::move(__func)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -generate(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "generate requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__generate, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__gen)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -generate_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _Generator __gen) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "generate_n requires a ForwardIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__generate_n, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__n), std::move(__gen)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_partitioned requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__is_partitioned, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator -merge(_ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _ForwardOutIterator __result, - _Comp __comp) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "merge requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "merge requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first1), "merge requires an OutputIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first2), "merge requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__merge, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - std::move(__comp)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator -merge(_ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _ForwardOutIterator __result) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "merge requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "merge requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first1), "merge requires an OutputIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first2), "merge requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__merge, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - less{}); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator -move(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "move requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "move requires an OutputIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(std::move(*__first)), "move requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__move, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__result)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -replace_if(_ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _Pred __pred, - const _Tp& __new_value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace_if requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__replace_if, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred), __new_value); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -replace(_ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - const _Tp& __old_value, - const _Tp& __new_value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__replace, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __old_value, __new_value); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void replace_copy_if( - _ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _ForwardOutIterator __result, - _Pred __pred, - const _Tp& __new_value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace_copy_if requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "replace_copy_if requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(*__first), "replace_copy_if requires an OutputIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, const _Tp&, "replace_copy requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__replace_copy_if, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first), - std::move(__last), - std::move(__result), - std::move(__pred), - __new_value); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void replace_copy( - _ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _ForwardOutIterator __result, - const _Tp& __old_value, - const _Tp& __new_value) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace_copy requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "replace_copy requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(*__first), "replace_copy requires an OutputIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, const _Tp&, "replace_copy requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__replace_copy, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first), - std::move(__last), - std::move(__result), - __old_value, - __new_value); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator rotate_copy( - _ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __middle, - _ForwardIterator __last, - _ForwardOutIterator __result) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "rotate_copy requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "rotate_copy requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(*__first), "rotate_copy requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__rotate_copy, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first), - std::move(__middle), - std::move(__last), - std::move(__result)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { - _LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "sort requires RandomAccessIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__sort, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__comp)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last) { - _LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "sort requires RandomAccessIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__sort, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), less{}); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -stable_sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { - _LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "stable_sort requires RandomAccessIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__stable_sort, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__comp)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI void -stable_sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last) { - _LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "stable_sort requires RandomAccessIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__stable_sort, __pstl::__current_configuration, _RawPolicy>; - __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), less{}); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform( - _ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _ForwardOutIterator __result, - _UnaryOperation __op) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "transform requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "transform requires an OutputIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(__op(*__first)), "transform requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__transform, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first), - std::move(__last), - std::move(__result), - std::move(__op)); -} - -template , - enable_if_t, int> = 0> -_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform( - _ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardOutIterator __result, - _BinaryOperation __op) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "transform requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "transform requires ForwardIterators"); - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "transform requires an OutputIterator"); - _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR( - _ForwardOutIterator, decltype(__op(*__first1, *__first2)), "transform requires an OutputIterator"); - using _Implementation = __pstl::__dispatch<__pstl::__transform_binary, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__result), - std::move(__op)); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -is_sorted(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_sorted requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__is_sorted, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), less{}); -} - -template , - enable_if_t, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool -is_sorted(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Comp __comp) { - _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_sorted requires ForwardIterators"); - using _Implementation = __pstl::__dispatch<__pstl::__is_sorted, __pstl::__current_configuration, _RawPolicy>; - return __pstl::__handle_exception<_Implementation>( - std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__comp)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_PSTL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/push_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/push_heap.h deleted file mode 100644 index ec0b445..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/push_heap.h +++ /dev/null @@ -1,84 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_PUSH_HEAP_H -#define _LIBCPP___ALGORITHM_PUSH_HEAP_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/is_assignable.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__sift_up(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare&& __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len) { - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - - if (__len > 1) { - __len = (__len - 2) / 2; - _RandomAccessIterator __ptr = __first + __len; - - if (__comp(*__ptr, *--__last)) { - value_type __t(_IterOps<_AlgPolicy>::__iter_move(__last)); - do { - *__last = _IterOps<_AlgPolicy>::__iter_move(__ptr); - __last = __ptr; - if (__len == 0) - break; - __len = (__len - 1) / 2; - __ptr = __first + __len; - } while (__comp(*__ptr, __t)); - - *__last = std::move(__t); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first; - std::__sift_up<_AlgPolicy, __comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp, __len); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - std::__push_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::push_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_PUSH_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/radix_sort.h b/third_party/libcxx/include/c++/v1/__algorithm/radix_sort.h deleted file mode 100644 index 5549a69..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/radix_sort.h +++ /dev/null @@ -1,431 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RADIX_SORT_H -#define _LIBCPP___ALGORITHM_RADIX_SORT_H - -// This is an implementation of classic LSD radix sort algorithm, running in linear time and using `O(max(N, M))` -// additional memory, where `N` is size of an input range, `M` - maximum value of -// a radix of the sorted integer type. Type of the radix and its maximum value are determined at compile time -// based on type returned by function `__radix`. The default radix is uint8. - -// The algorithm is equivalent to several consecutive calls of counting sort for each -// radix of the sorted numbers from low to high byte. -// The algorithm uses a temporary buffer of size equal to size of the input range. Each `i`-th pass -// of the algorithm sorts values by `i`-th radix and moves values to the temporary buffer (for each even `i`, counted -// from zero), or moves them back to the initial range (for each odd `i`). If there is only one radix in sorted integers -// (e.g. int8), the sorted values are placed to the buffer, and then moved back to the initial range. - -// The implementation also has several optimizations: -// - the counters for the counting sort are calculated in one pass for all radices; -// - if all values of a radix are the same, we do not sort that radix, and just move items to the buffer; -// - if two consecutive radices satisfies condition above, we do nothing for these two radices. - -#include <__algorithm/for_each.h> -#include <__algorithm/move.h> -#include <__bit/bit_cast.h> -#include <__bit/bit_log2.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/identity.h> -#include <__iterator/access.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/move_iterator.h> -#include <__iterator/next.h> -#include <__iterator/reverse_iterator.h> -#include <__numeric/partial_sum.h> -#include <__type_traits/decay.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_assignable.h> -#include <__type_traits/is_enum.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_unsigned.h> -#include <__type_traits/make_unsigned.h> -#include <__type_traits/void_t.h> -#include <__utility/declval.h> -#include <__utility/forward.h> -#include <__utility/integer_sequence.h> -#include <__utility/move.h> -#include <__utility/pair.h> -#include -#include -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 14 - -template -_LIBCPP_HIDE_FROM_ABI constexpr pair<_OutputIterator, __iterator_value_type<_InputIterator>> -__partial_sum_max(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - if (__first == __last) - return {__result, 0}; - - auto __max = *__first; - __iterator_value_type<_InputIterator> __sum = *__first; - *__result = __sum; - - while (++__first != __last) { - if (__max < *__first) { - __max = *__first; - } - __sum = std::move(__sum) + *__first; - *++__result = __sum; - } - return {++__result, __max}; -} - -template -struct __radix_sort_traits { - using __image_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Map, _Value>>; - static_assert(is_unsigned<__image_type>::value); - - using __radix_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Radix, __image_type>>; - static_assert(is_integral<__radix_type>::value); - - static constexpr auto __radix_value_range = numeric_limits<__radix_type>::max() + 1; - static constexpr auto __radix_size = std::__bit_log2(__radix_value_range); - static constexpr auto __radix_count = sizeof(__image_type) * CHAR_BIT / __radix_size; -}; - -template -struct __counting_sort_traits { - using __image_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Map, _Value>>; - static_assert(is_unsigned<__image_type>::value); - - static constexpr const auto __value_range = numeric_limits<__image_type>::max() + 1; - static constexpr auto __radix_size = std::__bit_log2(__value_range); -}; - -template -_LIBCPP_HIDE_FROM_ABI constexpr auto __nth_radix(size_t __radix_number, _Radix __radix, _Integer __n) { - static_assert(is_unsigned<_Integer>::value); - using __traits = __counting_sort_traits<_Integer, _Radix>; - - return __radix(static_cast<_Integer>(__n >> __traits::__radix_size * __radix_number)); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr void -__collect(_ForwardIterator __first, _ForwardIterator __last, _Map __map, _RandomAccessIterator __counters) { - using __value_type = __iterator_value_type<_ForwardIterator>; - using __traits = __counting_sort_traits<__value_type, _Map>; - - std::for_each(__first, __last, [&__counters, &__map](const auto& __preimage) { ++__counters[__map(__preimage)]; }); - - const auto __counters_end = __counters + __traits::__value_range; - std::partial_sum(__counters, __counters_end, __counters); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr void -__dispose(_ForwardIterator __first, - _ForwardIterator __last, - _RandomAccessIterator1 __result, - _Map __map, - _RandomAccessIterator2 __counters) { - std::for_each(__first, __last, [&__result, &__counters, &__map](auto&& __preimage) { - auto __index = __counters[__map(__preimage)]++; - __result[__index] = std::move(__preimage); - }); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __collect_impl( - _ForwardIterator __first, - _ForwardIterator __last, - _Map __map, - _Radix __radix, - _RandomAccessIterator1 __counters, - _RandomAccessIterator2 __maximums, - index_sequence<_Radices...>) { - using __value_type = __iterator_value_type<_ForwardIterator>; - constexpr auto __radix_value_range = __radix_sort_traits<__value_type, _Map, _Radix>::__radix_value_range; - - auto __previous = numeric_limits<__invoke_result_t<_Map, __value_type>>::min(); - auto __is_sorted = true; - std::for_each(__first, __last, [&__counters, &__map, &__radix, &__previous, &__is_sorted](const auto& __value) { - auto __current = __map(__value); - __is_sorted &= (__current >= __previous); - __previous = __current; - - (++__counters[_Radices][std::__nth_radix(_Radices, __radix, __current)], ...); - }); - - ((__maximums[_Radices] = - std::__partial_sum_max(__counters[_Radices], __counters[_Radices] + __radix_value_range, __counters[_Radices]) - .second), - ...); - - return __is_sorted; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool -__collect(_ForwardIterator __first, - _ForwardIterator __last, - _Map __map, - _Radix __radix, - _RandomAccessIterator1 __counters, - _RandomAccessIterator2 __maximums) { - using __value_type = __iterator_value_type<_ForwardIterator>; - constexpr auto __radix_count = __radix_sort_traits<__value_type, _Map, _Radix>::__radix_count; - return std::__collect_impl( - __first, __last, __map, __radix, __counters, __maximums, make_index_sequence<__radix_count>()); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr void __dispose_backward( - _BidirectionalIterator __first, - _BidirectionalIterator __last, - _RandomAccessIterator1 __result, - _Map __map, - _RandomAccessIterator2 __counters) { - std::for_each(std::make_reverse_iterator(__last), - std::make_reverse_iterator(__first), - [&__result, &__counters, &__map](auto&& __preimage) { - auto __index = --__counters[__map(__preimage)]; - __result[__index] = std::move(__preimage); - }); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr _RandomAccessIterator -__counting_sort_impl(_ForwardIterator __first, _ForwardIterator __last, _RandomAccessIterator __result, _Map __map) { - using __value_type = __iterator_value_type<_ForwardIterator>; - using __traits = __counting_sort_traits<__value_type, _Map>; - - __iterator_difference_type<_RandomAccessIterator> __counters[__traits::__value_range + 1] = {0}; - - std::__collect(__first, __last, __map, std::next(std::begin(__counters))); - std::__dispose(__first, __last, __result, __map, std::begin(__counters)); - - return __result + __counters[__traits::__value_range]; -} - -template < - class _RandomAccessIterator1, - class _RandomAccessIterator2, - class _Map, - class _Radix, - enable_if_t<__radix_sort_traits<__iterator_value_type<_RandomAccessIterator1>, _Map, _Radix>::__radix_count == 1, - int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr void __radix_sort_impl( - _RandomAccessIterator1 __first, - _RandomAccessIterator1 __last, - _RandomAccessIterator2 __buffer, - _Map __map, - _Radix __radix) { - auto __buffer_end = std::__counting_sort_impl(__first, __last, __buffer, [&__map, &__radix](const auto& __value) { - return __radix(__map(__value)); - }); - - std::move(__buffer, __buffer_end, __first); -} - -template , _Map, _Radix>::__radix_count % 2 == 0, - int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr void __radix_sort_impl( - _RandomAccessIterator1 __first, - _RandomAccessIterator1 __last, - _RandomAccessIterator2 __buffer_begin, - _Map __map, - _Radix __radix) { - using __value_type = __iterator_value_type<_RandomAccessIterator1>; - using __traits = __radix_sort_traits<__value_type, _Map, _Radix>; - - __iterator_difference_type<_RandomAccessIterator1> - __counters[__traits::__radix_count][__traits::__radix_value_range] = {{0}}; - __iterator_difference_type<_RandomAccessIterator1> __maximums[__traits::__radix_count] = {0}; - const auto __is_sorted = std::__collect(__first, __last, __map, __radix, __counters, __maximums); - if (!__is_sorted) { - const auto __range_size = std::distance(__first, __last); - auto __buffer_end = __buffer_begin + __range_size; - for (size_t __radix_number = 0; __radix_number < __traits::__radix_count; __radix_number += 2) { - const auto __n0th_is_single = __maximums[__radix_number] == __range_size; - const auto __n1th_is_single = __maximums[__radix_number + 1] == __range_size; - - if (__n0th_is_single && __n1th_is_single) { - continue; - } - - if (__n0th_is_single) { - std::move(__first, __last, __buffer_begin); - } else { - auto __n0th = [__radix_number, &__map, &__radix](const auto& __v) { - return std::__nth_radix(__radix_number, __radix, __map(__v)); - }; - std::__dispose_backward(__first, __last, __buffer_begin, __n0th, __counters[__radix_number]); - } - - if (__n1th_is_single) { - std::move(__buffer_begin, __buffer_end, __first); - } else { - auto __n1th = [__radix_number, &__map, &__radix](const auto& __v) { - return std::__nth_radix(__radix_number + 1, __radix, __map(__v)); - }; - std::__dispose_backward(__buffer_begin, __buffer_end, __first, __n1th, __counters[__radix_number + 1]); - } - } - } -} - -_LIBCPP_HIDE_FROM_ABI constexpr auto __shift_to_unsigned(bool __b) { return __b; } - -template -_LIBCPP_HIDE_FROM_ABI constexpr auto __shift_to_unsigned(_Ip __n) { - constexpr const auto __min_value = numeric_limits<_Ip>::min(); - return static_cast >(__n ^ __min_value); -} - -template -struct __unsigned_integer_of_size; - -template <> -struct __unsigned_integer_of_size<1> { - using type _LIBCPP_NODEBUG = uint8_t; -}; - -template <> -struct __unsigned_integer_of_size<2> { - using type _LIBCPP_NODEBUG = uint16_t; -}; - -template <> -struct __unsigned_integer_of_size<4> { - using type _LIBCPP_NODEBUG = uint32_t; -}; - -template <> -struct __unsigned_integer_of_size<8> { - using type _LIBCPP_NODEBUG = uint64_t; -}; - -# if _LIBCPP_HAS_INT128 -template <> -struct __unsigned_integer_of_size<16> { - using type _LIBCPP_NODEBUG = unsigned __int128; -}; -# endif - -template -using __unsigned_integer_of_size_t _LIBCPP_NODEBUG = typename __unsigned_integer_of_size<_Size>::type; - -template -using __unsigned_representation_for_t _LIBCPP_NODEBUG = __unsigned_integer_of_size_t; - -// The function `__to_ordered_integral` is defined for integers and IEEE 754 floating-point numbers. -// Returns an integer representation such that for any `x` and `y` such that `x < y`, the expression -// `__to_ordered_integral(x) < __to_ordered_integral(y)` is true, where `x`, `y` are integers or IEEE 754 floats. -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Integral __n) { - return __n; -} - -// An overload for IEEE 754 floating-point numbers - -// For the floats conforming to IEEE 754 (IEC 559) standard, we know that: -// 1. The bit representation of positive floats directly reflects their order: -// When comparing floats by magnitude, the number with the larger exponent is greater, and if the exponents are -// equal, the one with the larger mantissa is greater. -// 2. The bit representation of negative floats reflects their reverse order (for the same reasons). -// 3. The most significant bit (sign bit) is zero for positive floats and one for negative floats. Therefore, in the raw -// bit representation, any negative number will be greater than any positive number. - -// The only exception from this rule is `NaN`, which is unordered by definition. - -// Based on the above, to obtain correctly ordered integral representation of floating-point numbers, we need to: -// 1. Invert the bit representation (including the sign bit) of negative floats to switch from reverse order to direct -// order; -// 2. Invert the sign bit for positive floats. - -// Thus, in final integral representation, we have reversed the order for negative floats and made all negative floats -// smaller than all positive numbers (by inverting the sign bit). -template ::is_iec559, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Floating __f) { - using __integral_type = __unsigned_representation_for_t<_Floating>; - constexpr auto __bit_count = std::numeric_limits<__integral_type>::digits; - constexpr auto __sign_bit_mask = static_cast<__integral_type>(__integral_type{1} << (__bit_count - 1)); - - const auto __u = std::__bit_cast<__integral_type>(__f); - - return static_cast<__integral_type>(__u & __sign_bit_mask ? ~__u : __u ^ __sign_bit_mask); -} - -// There may exist user-defined comparison for enum, so we cannot compare enums just like integers. -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Enum __e) = delete; - -// `long double` varies significantly across platforms and compilers, making it practically -// impossible to determine its actual bit width for conversion to an ordered integer. -inline _LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(long double) = delete; - -template -inline const bool __is_ordered_integer_representable_v = false; - -template -inline const bool - __is_ordered_integer_representable_v<_Tp, __void_t()))>> = - true; - -struct __low_byte_fn { - template - _LIBCPP_HIDE_FROM_ABI constexpr uint8_t operator()(_Ip __integer) const { - static_assert(is_unsigned<_Ip>::value); - - return static_cast(__integer & 0xff); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI constexpr void -__radix_sort(_RandomAccessIterator1 __first, - _RandomAccessIterator1 __last, - _RandomAccessIterator2 __buffer, - _Map __map, - _Radix __radix) { - auto __map_to_unsigned = [__map = std::move(__map)](const auto& __x) { - return std::__shift_to_unsigned(__map(std::__to_ordered_integral(__x))); - }; - std::__radix_sort_impl(__first, __last, __buffer, __map_to_unsigned, __radix); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr void -__radix_sort(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __buffer) { - std::__radix_sort(__first, __last, __buffer, __identity{}, __low_byte_fn{}); -} - -#endif // _LIBCPP_STD_VER >= 14 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RADIX_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_adjacent_find.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_adjacent_find.h deleted file mode 100644 index 731142b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_adjacent_find.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H -#define _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H - -#include <__algorithm/adjacent_find.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __adjacent_find { - template _Sent, - class _Proj = identity, - indirect_binary_predicate, projected<_Iter, _Proj>> _Pred = ranges::equal_to> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { - return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>, projected, _Proj>> - _Pred = ranges::equal_to> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __range, _Pred __pred = {}, _Proj __proj = {}) const { - return std::__adjacent_find(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto adjacent_find = __adjacent_find{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_all_of.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_all_of.h deleted file mode 100644 index c3d6dc0..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_all_of.h +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_ALL_OF_H -#define _LIBCPP___ALGORITHM_RANGES_ALL_OF_H - -#include <__algorithm/all_of.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __all_of { - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { - return std::__all_of(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return std::__all_of(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto all_of = __all_of{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_any_of.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_any_of.h deleted file mode 100644 index 7f0fd29..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_any_of.h +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_ANY_OF_H -#define _LIBCPP___ALGORITHM_RANGES_ANY_OF_H - -#include <__algorithm/any_of.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __any_of { - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { - return std::__any_of(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return std::__any_of(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto any_of = __any_of{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_ANY_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_binary_search.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_binary_search.h deleted file mode 100644 index 47bd099..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_binary_search.h +++ /dev/null @@ -1,71 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H -#define _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/lower_bound.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __binary_search { - template _Sent, - class _Type, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj); - return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret)); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { - auto __first = ranges::begin(__r); - auto __last = ranges::end(__r); - auto __ret = std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj); - return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret)); - } -}; - -inline namespace __cpo { -inline constexpr auto binary_search = __binary_search{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_clamp.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_clamp.h deleted file mode 100644 index 4bb3e46..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_clamp.h +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_CLAMP_H -#define _LIBCPP___ALGORITHM_RANGES_CLAMP_H - -#include <__assert> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __clamp { - template > _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Type& operator()( - const _Type& __value, const _Type& __low, const _Type& __high, _Comp __comp = {}, _Proj __proj = {}) const { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - !bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))), - "Bad bounds passed to std::ranges::clamp"); - - auto&& __projected = std::invoke(__proj, __value); - if (std::invoke(__comp, std::forward(__projected), std::invoke(__proj, __low))) - return __low; - else if (std::invoke(__comp, std::invoke(__proj, __high), std::forward(__projected))) - return __high; - else - return __value; - } -}; - -inline namespace __cpo { -inline constexpr auto clamp = __clamp{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_CLAMP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_contains.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_contains.h deleted file mode 100644 index 88de215..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_contains.h +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H -#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H - -#include <__algorithm/ranges_find.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__functional/reference_wrapper.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 23 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __contains { - template _Sent, class _Type, class _Proj = identity> - requires indirect_binary_predicate, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static - operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) { - return ranges::find(std::move(__first), __last, __value, std::ref(__proj)) != __last; - } - - template - requires indirect_binary_predicate, _Proj>, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static - operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) { - return ranges::find(ranges::begin(__range), ranges::end(__range), __value, std::ref(__proj)) != - ranges::end(__range); - } -}; - -inline namespace __cpo { -inline constexpr auto contains = __contains{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_contains_subrange.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_contains_subrange.h deleted file mode 100644 index e8740d6..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_contains_subrange.h +++ /dev/null @@ -1,95 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H -#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H - -#include <__algorithm/ranges_search.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__functional/reference_wrapper.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/size.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 23 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __contains_subrange { - template _Sent1, - forward_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) { - if (__first2 == __last2) - return true; - - auto __ret = ranges::search( - std::move(__first1), __last1, std::move(__first2), __last2, __pred, std::ref(__proj1), std::ref(__proj2)); - return __ret.empty() == false; - } - - template - requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static - operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) { - if constexpr (sized_range<_Range2>) { - if (ranges::size(__range2) == 0) - return true; - } else { - if (ranges::begin(__range2) == ranges::end(__range2)) - return true; - } - - auto __ret = ranges::search(__range1, __range2, __pred, std::ref(__proj1), std::ref(__proj2)); - return __ret.empty() == false; - } -}; - -inline namespace __cpo { -inline constexpr auto contains_subrange = __contains_subrange{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy.h deleted file mode 100644 index a69af9b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy.h +++ /dev/null @@ -1,68 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_COPY_H - -#include <__algorithm/copy.h> -#include <__algorithm/in_out_result.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/concepts.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using copy_result = in_out_result<_InIter, _OutIter>; - -struct __copy { - template _Sent, weakly_incrementable _OutIter> - requires indirectly_copyable<_InIter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr copy_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - auto __ret = std::__copy(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template - requires indirectly_copyable, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr copy_result, _OutIter> - operator()(_Range&& __r, _OutIter __result) const { - auto __ret = std::__copy(ranges::begin(__r), ranges::end(__r), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto copy = __copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_backward.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_backward.h deleted file mode 100644 index 81d14e4..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_backward.h +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H -#define _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H - -#include <__algorithm/copy_backward.h> -#include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using copy_backward_result = in_out_result<_Ip, _Op>; - -struct __copy_backward { - template _Sent1, bidirectional_iterator _InIter2> - requires indirectly_copyable<_InIter1, _InIter2> - _LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result<_InIter1, _InIter2> - operator()(_InIter1 __first, _Sent1 __last, _InIter2 __result) const { - auto __ret = std::__copy_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template - requires indirectly_copyable, _Iter> - _LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result, _Iter> - operator()(_Range&& __r, _Iter __result) const { - auto __ret = std::__copy_backward<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto copy_backward = __copy_backward{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_if.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_if.h deleted file mode 100644 index acf74b6..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_if.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_IF_H -#define _LIBCPP___ALGORITHM_RANGES_COPY_IF_H - -#include <__algorithm/copy_if.h> -#include <__algorithm/in_out_result.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using copy_if_result = in_out_result<_Ip, _Op>; - -struct __copy_if { - template _Sent, - weakly_incrementable _OutIter, - class _Proj = identity, - indirect_unary_predicate> _Pred> - requires indirectly_copyable<_Iter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result<_Iter, _OutIter> - operator()(_Iter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - auto __res = std::__copy_if(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); - return {std::move(__res.first), std::move(__res.second)}; - } - - template , _Proj>> _Pred> - requires indirectly_copyable, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result, _OutIter> - operator()(_Range&& __r, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - auto __res = std::__copy_if(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj); - return {std::move(__res.first), std::move(__res.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto copy_if = __copy_if{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_n.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_n.h deleted file mode 100644 index 6bee4c3..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_copy_n.h +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_N_H -#define _LIBCPP___ALGORITHM_RANGES_COPY_N_H - -#include <__algorithm/copy_n.h> -#include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/incrementable_traits.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { - -template -using copy_n_result = in_out_result<_Ip, _Op>; - -struct __copy_n { - template - requires indirectly_copyable<_Ip, _Op> - _LIBCPP_HIDE_FROM_ABI constexpr copy_n_result<_Ip, _Op> - operator()(_Ip __first, iter_difference_t<_Ip> __n, _Op __result) const { - auto __res = std::__copy_n<_RangeAlgPolicy>(std::move(__first), __n, std::move(__result)); - return {std::move(__res.first), std::move(__res.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto copy_n = __copy_n{}; -} // namespace __cpo -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_COPY_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_count.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_count.h deleted file mode 100644 index 2b3969e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_count.h +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_H -#define _LIBCPP___ALGORITHM_RANGES_COUNT_H - -#include <__algorithm/count.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __count { - template _Sent, class _Type, class _Proj = identity> - requires indirect_binary_predicate, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> - operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const { - return std::__count<_RangeAlgPolicy>(std::move(__first), std::move(__last), __value, __proj); - } - - template - requires indirect_binary_predicate, _Proj>, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range> - operator()(_Range&& __r, const _Type& __value, _Proj __proj = {}) const { - return std::__count<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto count = __count{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_count_if.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_count_if.h deleted file mode 100644 index 6adeb78..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_count_if.h +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H -#define _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H - -#include <__algorithm/count_if.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __count_if { - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Predicate> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> - operator()(_Iter __first, _Sent __last, _Predicate __pred, _Proj __proj = {}) const { - return std::__count_if<_RangeAlgPolicy>(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Predicate> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range> - operator()(_Range&& __r, _Predicate __pred, _Proj __proj = {}) const { - return std::__count_if<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto count_if = __count_if{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_ends_with.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_ends_with.h deleted file mode 100644 index 3621bda..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_ends_with.h +++ /dev/null @@ -1,200 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_ENDS_WITH_H -#define _LIBCPP___ALGORITHM_RANGES_ENDS_WITH_H - -#include <__algorithm/ranges_equal.h> -#include <__algorithm/ranges_starts_with.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__functional/reference_wrapper.h> -#include <__iterator/advance.h> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/indirectly_comparable.h> -#include <__iterator/reverse_iterator.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/size.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 23 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __ends_with { - template - _LIBCPP_HIDE_FROM_ABI static constexpr bool __ends_with_fn_impl_bidirectional( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2) { - auto __rbegin1 = std::make_reverse_iterator(__last1); - auto __rend1 = std::make_reverse_iterator(__first1); - auto __rbegin2 = std::make_reverse_iterator(__last2); - auto __rend2 = std::make_reverse_iterator(__first2); - return ranges::starts_with( - __rbegin1, __rend1, __rbegin2, __rend2, std::ref(__pred), std::ref(__proj1), std::ref(__proj2)); - } - - template - _LIBCPP_HIDE_FROM_ABI static constexpr bool __ends_with_fn_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2) { - if constexpr (std::bidirectional_iterator<_Sent1> && std::bidirectional_iterator<_Sent2> && - (!std::random_access_iterator<_Sent1>) && (!std::random_access_iterator<_Sent2>)) { - return __ends_with_fn_impl_bidirectional(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2); - - } else { - auto __n1 = ranges::distance(__first1, __last1); - auto __n2 = ranges::distance(__first2, __last2); - if (__n2 == 0) - return true; - if (__n2 > __n1) - return false; - - return __ends_with_fn_impl_with_offset( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __proj1, - __proj2, - __n1 - __n2); - } - } - - template - static _LIBCPP_HIDE_FROM_ABI constexpr bool __ends_with_fn_impl_with_offset( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - _Offset __offset) { - if constexpr (std::bidirectional_iterator<_Sent1> && std::bidirectional_iterator<_Sent2> && - !std::random_access_iterator<_Sent1> && !std::random_access_iterator<_Sent2>) { - return __ends_with_fn_impl_bidirectional( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); - - } else { - ranges::advance(__first1, __offset); - return ranges::equal( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::ref(__pred), - std::ref(__proj1), - std::ref(__proj2)); - } - } - - template _Sent1, - input_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires(forward_iterator<_Iter1> || sized_sentinel_for<_Sent1, _Iter1>) && - (forward_iterator<_Iter2> || sized_sentinel_for<_Sent2, _Iter2>) && - indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return __ends_with_fn_impl( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); - } - - template - requires(forward_range<_Range1> || sized_range<_Range1>) && (forward_range<_Range2> || sized_range<_Range2>) && - indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - if constexpr (sized_range<_Range1> && sized_range<_Range2>) { - auto __n1 = ranges::size(__range1); - auto __n2 = ranges::size(__range2); - if (__n2 == 0) - return true; - if (__n2 > __n1) - return false; - auto __offset = __n1 - __n2; - - return __ends_with_fn_impl_with_offset( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __pred, - __proj1, - __proj2, - __offset); - - } else { - return __ends_with_fn_impl( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __pred, - __proj1, - __proj2); - } - } -}; - -inline namespace __cpo { -inline constexpr auto ends_with = __ends_with{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_ENDS_WITH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_equal.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_equal.h deleted file mode 100644 index 98f0baa..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_equal.h +++ /dev/null @@ -1,98 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_EQUAL_H -#define _LIBCPP___ALGORITHM_RANGES_EQUAL_H - -#include <__algorithm/equal.h> -#include <__algorithm/unwrap_range.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/size.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __equal { - template _Sent1, - input_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - constexpr bool __both_sized = sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2>; - if constexpr (__both_sized) { - if (__last1 - __first1 != __last2 - __first2) - return false; - } - - auto [__ufirst1, __ulast1] = std::__unwrap_range(std::move(__first1), std::move(__last1)); - auto [__ufirst2, __ulast2] = std::__unwrap_range(std::move(__first2), std::move(__last2)); - - return std::__equal_impl<__both_sized>( - std::move(__ufirst1), std::move(__ulast1), std::move(__ufirst2), std::move(__ulast2), __pred, __proj1, __proj2); - } - - template - requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - constexpr bool __both_sized = sized_range<_Range1> && sized_range<_Range2>; - if constexpr (__both_sized) { - if (ranges::size(__range1) != ranges::size(__range2)) - return false; - } - - auto [__ufirst1, __ulast1] = std::__unwrap_range(ranges::begin(__range1), ranges::end(__range1)); - auto [__ufirst2, __ulast2] = std::__unwrap_range(ranges::begin(__range2), ranges::end(__range2)); - return std::__equal_impl<__both_sized>( - std::move(__ufirst1), std::move(__ulast1), std::move(__ufirst2), std::move(__ulast2), __pred, __proj1, __proj2); - } -}; - -inline namespace __cpo { -inline constexpr auto equal = __equal{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_equal_range.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_equal_range.h deleted file mode 100644 index cc765f1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_equal_range.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H -#define _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H - -#include <__algorithm/equal_range.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__ranges/subrange.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __equal_range { - template _Sent, - class _Tp, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> - operator()(_Iter __first, _Sent __last, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__equal_range<_RangeAlgPolicy>(std::move(__first), std::move(__last), __value, __comp, __proj); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = - std::__equal_range<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), __value, __comp, __proj); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto equal_range = __equal_range{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_fill.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_fill.h deleted file mode 100644 index 814ae63..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_fill.h +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_H -#define _LIBCPP___ALGORITHM_RANGES_FILL_H - -#include <__algorithm/fill.h> -#include <__algorithm/fill_n.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __fill { - template _Iter, sentinel_for<_Iter> _Sent> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const { - if constexpr (sized_sentinel_for<_Sent, _Iter>) { - auto __n = __last - __first; - return std::__fill_n(std::move(__first), __n, __value); - } else { - return std::__fill(std::move(__first), std::move(__last), __value); - } - } - - template _Range> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, const _Type& __value) const { - return (*this)(ranges::begin(__range), ranges::end(__range), __value); - } -}; - -inline namespace __cpo { -inline constexpr auto fill = __fill{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FILL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_fill_n.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_fill_n.h deleted file mode 100644 index 1276f13..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_fill_n.h +++ /dev/null @@ -1,49 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_N_H -#define _LIBCPP___ALGORITHM_RANGES_FILL_N_H - -#include <__algorithm/fill_n.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/incrementable_traits.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __fill_n { - template _Iter> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, iter_difference_t<_Iter> __n, const _Type& __value) const { - return std::__fill_n(std::move(__first), __n, __value); - } -}; - -inline namespace __cpo { -inline constexpr auto fill_n = __fill_n{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FILL_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_find.h deleted file mode 100644 index 1eac4cf..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find.h +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_H -#define _LIBCPP___ALGORITHM_RANGES_FIND_H - -#include <__algorithm/find.h> -#include <__algorithm/ranges_find_if.h> -#include <__algorithm/unwrap_range.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __find { - template - _LIBCPP_HIDE_FROM_ABI static constexpr _Iter - __find_unwrap(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - if constexpr (forward_iterator<_Iter>) { - auto [__first_un, __last_un] = std::__unwrap_range(__first, std::move(__last)); - return std::__rewrap_range<_Sent>( - std::move(__first), std::__find(std::move(__first_un), std::move(__last_un), __value, __proj)); - } else { - return std::__find(std::move(__first), std::move(__last), __value, __proj); - } - } - - template _Sp, class _Tp, class _Proj = identity> - requires indirect_binary_predicate, const _Tp*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip - operator()(_Ip __first, _Sp __last, const _Tp& __value, _Proj __proj = {}) const { - return __find_unwrap(std::move(__first), std::move(__last), __value, __proj); - } - - template - requires indirect_binary_predicate, _Proj>, const _Tp*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> - operator()(_Rp&& __r, const _Tp& __value, _Proj __proj = {}) const { - return __find_unwrap(ranges::begin(__r), ranges::end(__r), __value, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto find = __find{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FIND_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_end.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_end.h deleted file mode 100644 index 682724a..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_end.h +++ /dev/null @@ -1,101 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_END_H -#define _LIBCPP___ALGORITHM_RANGES_FIND_END_H - -#include <__algorithm/find_end.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/ranges_iterator_concept.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__iterator/iterator_traits.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __find_end { - template _Sent1, - forward_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter1> operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__find_end_impl<_RangeAlgPolicy>( - __first1, - __last1, - __first2, - __last2, - __pred, - __proj1, - __proj2, - __iterator_concept<_Iter1>(), - __iterator_concept<_Iter2>()); - return {__ret.first, __ret.second}; - } - - template - requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range1> operator()( - _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__find_end_impl<_RangeAlgPolicy>( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __pred, - __proj1, - __proj2, - __iterator_concept>(), - __iterator_concept>()); - return {__ret.first, __ret.second}; - } -}; - -inline namespace __cpo { -inline constexpr auto find_end = __find_end{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FIND_END_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_first_of.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_first_of.h deleted file mode 100644 index 102e16d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_first_of.h +++ /dev/null @@ -1,104 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H -#define _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H - -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __find_first_of { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter1 __find_first_of_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2) { - for (; __first1 != __last1; ++__first1) { - for (auto __j = __first2; __j != __last2; ++__j) { - if (std::invoke(__pred, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__j))) - return __first1; - } - } - return __first1; - } - - template _Sent1, - forward_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter1 operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return __find_first_of_impl( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); - } - - template - requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range1> operator()( - _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - return __find_first_of_impl( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __pred, - __proj1, - __proj2); - } -}; - -inline namespace __cpo { -inline constexpr auto find_first_of = __find_first_of{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if.h deleted file mode 100644 index c72ade0..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if.h +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_H -#define _LIBCPP___ALGORITHM_RANGES_FIND_IF_H - -#include <__algorithm/find_if.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -struct __find_if { - template _Sp, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip - operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const { - return std::__find_if(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> - operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const { - return std::__find_if(ranges::begin(__r), ranges::end(__r), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto find_if = __find_if{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if_not.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if_not.h deleted file mode 100644 index ae0d64f..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_if_not.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H -#define _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H - -#include <__algorithm/find_if_not.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __find_if_not { - template _Sp, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip - operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const { - return std::__find_if_not(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> - operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const { - return std::__find_if_not(ranges::begin(__r), ranges::end(__r), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto find_if_not = __find_if_not{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_last.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_last.h deleted file mode 100644 index e7dae17..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_find_last.h +++ /dev/null @@ -1,170 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_LAST_H -#define _LIBCPP___ALGORITHM_RANGES_FIND_LAST_H - -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__iterator/next.h> -#include <__iterator/prev.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 23 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -_LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> -__find_last_impl(_Iter __first, _Sent __last, _Pred __pred, _Proj& __proj) { - if (__first == __last) { - return subrange<_Iter>(__first, __first); - } - - if constexpr (bidirectional_iterator<_Iter>) { - auto __last_it = ranges::next(__first, __last); - for (auto __it = ranges::prev(__last_it); __it != __first; --__it) { - if (__pred(std::invoke(__proj, *__it))) { - return subrange<_Iter>(std::move(__it), std::move(__last_it)); - } - } - if (__pred(std::invoke(__proj, *__first))) { - return subrange<_Iter>(std::move(__first), std::move(__last_it)); - } - return subrange<_Iter>(__last_it, __last_it); - } else { - bool __found = false; - _Iter __found_it; - for (; __first != __last; ++__first) { - if (__pred(std::invoke(__proj, *__first))) { - __found = true; - __found_it = __first; - } - } - - if (__found) { - return subrange<_Iter>(std::move(__found_it), std::move(__first)); - } else { - return subrange<_Iter>(__first, __first); - } - } -} - -struct __find_last { - template - struct __op { - const _Type& __value; - template - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Elem&& __elem) const { - return std::forward<_Elem>(__elem) == __value; - } - }; - - template _Sent, class _Type, class _Proj = identity> - requires indirect_binary_predicate, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> - operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) { - return ranges::__find_last_impl(std::move(__first), std::move(__last), __op<_Type>{__value}, __proj); - } - - template - requires indirect_binary_predicate, _Proj>, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static borrowed_subrange_t<_Range> - operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) { - return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Type>{__value}, __proj); - } -}; - -struct __find_last_if { - template - struct __op { - _Pred& __pred; - template - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Elem&& __elem) const { - return std::invoke(__pred, std::forward<_Elem>(__elem)); - } - }; - - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> - operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) { - return ranges::__find_last_impl(std::move(__first), std::move(__last), __op<_Pred>{__pred}, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static borrowed_subrange_t<_Range> - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) { - return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Pred>{__pred}, __proj); - } -}; - -struct __find_last_if_not { - template - struct __op { - _Pred& __pred; - template - _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Elem&& __elem) const { - return !std::invoke(__pred, std::forward<_Elem>(__elem)); - } - }; - - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> - operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) { - return ranges::__find_last_impl(std::move(__first), std::move(__last), __op<_Pred>{__pred}, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static borrowed_subrange_t<_Range> - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) { - return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Pred>{__pred}, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto find_last = __find_last{}; -inline constexpr auto find_last_if = __find_last_if{}; -inline constexpr auto find_last_if_not = __find_last_if_not{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FIND_LAST_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_fold.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_fold.h deleted file mode 100644 index c2d150a..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_fold.h +++ /dev/null @@ -1,137 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FOLD_H -#define _LIBCPP___ALGORITHM_RANGES_FOLD_H - -#include <__algorithm/for_each.h> -#include <__concepts/assignable.h> -#include <__concepts/constructible.h> -#include <__concepts/convertible_to.h> -#include <__concepts/invocable.h> -#include <__concepts/movable.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/reference_wrapper.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/decay.h> -#include <__type_traits/invoke.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 23 - -namespace ranges { -template -struct in_value_result { - _LIBCPP_NO_UNIQUE_ADDRESS _Ip in; - _LIBCPP_NO_UNIQUE_ADDRESS _Tp value; - - template - requires convertible_to && convertible_to - _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() const& { - return {in, value}; - } - - template - requires convertible_to<_Ip, _I2> && convertible_to<_Tp, _T2> - _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() && { - return {std::move(in), std::move(value)}; - } -}; - -template -using fold_left_with_iter_result = in_value_result<_Ip, _Tp>; - -template > -concept __indirectly_binary_left_foldable_impl = - convertible_to<_Rp, _Up> && // - movable<_Tp> && // - movable<_Up> && // - convertible_to<_Tp, _Up> && // - invocable<_Fp&, _Up, iter_reference_t<_Ip>> && // - assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>; - -template -concept __indirectly_binary_left_foldable = - copy_constructible<_Fp> && // - invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && // - __indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>; - -struct __fold_left_with_iter { - template _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) { - using _Up = decay_t>>; - - if (__first == __last) { - return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), _Up(std::move(__init))}; - } - - _Up __result = std::invoke(__f, std::move(__init), *__first); - ++__first; - __identity __proj; - auto __end = std::__for_each( - std::move(__first), - std::move(__last), - [&](auto&& __element) { - __result = std::invoke(__f, std::move(__result), std::forward(__element)); - }, - __proj); - - return fold_left_with_iter_result<_Ip, _Up>{std::move(__end), std::move(__result)}; - } - - template > _Fp> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) { - auto __result = operator()(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f)); - - using _Up = decay_t>>; - return fold_left_with_iter_result, _Up>{std::move(__result.in), std::move(__result.value)}; - } -}; - -inline constexpr auto fold_left_with_iter = __fold_left_with_iter(); - -struct __fold_left { - template _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) { - return fold_left_with_iter(std::move(__first), std::move(__last), std::move(__init), std::ref(__f)).value; - } - - template > _Fp> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) { - return fold_left_with_iter(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f)).value; - } -}; - -inline constexpr auto fold_left = __fold_left(); -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FOLD_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each.h deleted file mode 100644 index 7a547fb..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each.h +++ /dev/null @@ -1,97 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H -#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H - -#include <__algorithm/for_each.h> -#include <__algorithm/for_each_n.h> -#include <__algorithm/in_fun_result.h> -#include <__algorithm/specialized_algorithms.h> -#include <__concepts/assignable.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using for_each_result = in_fun_result<_Iter, _Func>; - -struct __for_each { -private: - template - _LIBCPP_HIDE_FROM_ABI constexpr static for_each_result<_Iter, _Func> - __for_each_impl(_Iter __first, _Sent __last, _Func& __func, _Proj& __proj) { - // In the case where we have different iterator and sentinel types, the segmented iterator optimization - // in std::for_each will not kick in. Therefore, we prefer std::for_each_n in that case (whenever we can - // obtain the `n`). - if constexpr (!std::assignable_from<_Iter&, _Sent> && std::sized_sentinel_for<_Sent, _Iter>) { - auto __n = __last - __first; - auto __end = std::__for_each_n(std::move(__first), __n, __func, __proj); - return {std::move(__end), std::move(__func)}; - } else { - auto __end = std::__for_each(std::move(__first), std::move(__last), __func, __proj); - return {std::move(__end), std::move(__func)}; - } - } - -public: - template _Sent, - class _Proj = identity, - indirectly_unary_invocable> _Func> - _LIBCPP_HIDE_FROM_ABI constexpr for_each_result<_Iter, _Func> - operator()(_Iter __first, _Sent __last, _Func __func, _Proj __proj = {}) const { - return __for_each_impl(std::move(__first), std::move(__last), __func, __proj); - } - - template , _Proj>> _Func> - _LIBCPP_HIDE_FROM_ABI constexpr for_each_result, _Func> - operator()(_Range&& __range, _Func __func, _Proj __proj = {}) const { - using _SpecialAlg = __specialized_algorithm<_Algorithm::__for_each, __single_range>>; - if constexpr (_SpecialAlg::__has_algorithm) { - auto [__iter, __func2] = _SpecialAlg()(__range, std::move(__func), std::move(__proj)); - return {std::move(__iter), std::move(__func)}; - } else { - return __for_each_impl(ranges::begin(__range), ranges::end(__range), __func, __proj); - } - } -}; - -inline namespace __cpo { -inline constexpr auto for_each = __for_each{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each_n.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each_n.h deleted file mode 100644 index 3aab1b7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_for_each_n.h +++ /dev/null @@ -1,59 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H -#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H - -#include <__algorithm/for_each_n.h> -#include <__algorithm/in_fun_result.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/concepts.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using for_each_n_result = in_fun_result<_Iter, _Func>; - -struct __for_each_n { - template > _Func> - _LIBCPP_HIDE_FROM_ABI constexpr for_each_n_result<_Iter, _Func> - operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const { - auto __last = std::__for_each_n(std::move(__first), __count, __func, __proj); - return {std::move(__last), std::move(__func)}; - } -}; - -inline namespace __cpo { -inline constexpr auto for_each_n = __for_each_n{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_generate.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_generate.h deleted file mode 100644 index 04333b3..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_generate.h +++ /dev/null @@ -1,69 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_GENERATE_H -#define _LIBCPP___ALGORITHM_RANGES_GENERATE_H - -#include <__concepts/constructible.h> -#include <__concepts/invocable.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/invoke.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __generate { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _OutIter __generate_fn_impl(_OutIter __first, _Sent __last, _Func& __gen) { - for (; __first != __last; ++__first) { - *__first = __gen(); - } - - return __first; - } - - template _Sent, copy_constructible _Func> - requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>> - _LIBCPP_HIDE_FROM_ABI constexpr _OutIter operator()(_OutIter __first, _Sent __last, _Func __gen) const { - return __generate_fn_impl(std::move(__first), std::move(__last), __gen); - } - - template - requires invocable<_Func&> && output_range<_Range, invoke_result_t<_Func&>> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, _Func __gen) const { - return __generate_fn_impl(ranges::begin(__range), ranges::end(__range), __gen); - } -}; - -inline namespace __cpo { -inline constexpr auto generate = __generate{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_generate_n.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_generate_n.h deleted file mode 100644 index 0cc9ce7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_generate_n.h +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H -#define _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H - -#include <__algorithm/generate_n.h> -#include <__concepts/constructible.h> -#include <__concepts/invocable.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/concepts.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/iterator_traits.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__type_traits/invoke.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __generate_n { - template - requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>> - _LIBCPP_HIDE_FROM_ABI constexpr _OutIter - operator()(_OutIter __first, iter_difference_t<_OutIter> __n, _Func __gen) const { - return std::__generate_n(std::move(__first), __n, __gen); - } -}; - -inline namespace __cpo { -inline constexpr auto generate_n = __generate_n{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_includes.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_includes.h deleted file mode 100644 index 9145f3b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_includes.h +++ /dev/null @@ -1,94 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_INCLUDES_H -#define _LIBCPP___ALGORITHM_RANGES_INCLUDES_H - -#include <__algorithm/includes.h> -#include <__algorithm/make_projected.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __includes { - template _Sent1, - input_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Proj1 = identity, - class _Proj2 = identity, - indirect_strict_weak_order, projected<_Iter2, _Proj2>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return std::__includes( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__comp), - std::move(__proj1), - std::move(__proj2)); - } - - template , _Proj1>, projected, _Proj2>> - _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - return std::__includes( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - std::move(__comp), - std::move(__proj1), - std::move(__proj2)); - } -}; - -inline namespace __cpo { -inline constexpr auto includes = __includes{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_INCLUDES_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_inplace_merge.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_inplace_merge.h deleted file mode 100644 index 54581af..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_inplace_merge.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H -#define _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H - -#include <__algorithm/inplace_merge.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __inplace_merge { - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX26 auto - __inplace_merge_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp&& __comp, _Proj&& __proj) { - auto __last_iter = ranges::next(__middle, __last); - std::__inplace_merge<_RangeAlgPolicy>( - std::move(__first), std::move(__middle), __last_iter, std::__make_projected(__comp, __proj)); - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _Iter - operator()(_Iter __first, _Iter __middle, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __inplace_merge_impl( - std::move(__first), std::move(__middle), std::move(__last), std::move(__comp), std::move(__proj)); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_iterator_t<_Range> - operator()(_Range&& __range, iterator_t<_Range> __middle, _Comp __comp = {}, _Proj __proj = {}) const { - return __inplace_merge_impl( - ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__comp), std::move(__proj)); - } -}; - -inline namespace __cpo { -inline constexpr auto inplace_merge = __inplace_merge{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap.h deleted file mode 100644 index b4724ab..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap.h +++ /dev/null @@ -1,77 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H -#define _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H - -#include <__algorithm/is_heap_until.h> -#include <__algorithm/make_projected.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __is_heap { - template - _LIBCPP_HIDE_FROM_ABI constexpr static bool - __is_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - auto&& __projected_comp = std::__make_projected(__comp, __proj); - - auto __result = std::__is_heap_until(std::move(__first), std::move(__last_iter), __projected_comp); - return __result == __last; - } - - template _Sent, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __is_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { - return __is_heap_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto is_heap = __is_heap{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap_until.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap_until.h deleted file mode 100644 index 25f3b48..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_heap_until.h +++ /dev/null @@ -1,77 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H -#define _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H - -#include <__algorithm/is_heap_until.h> -#include <__algorithm/make_projected.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __is_heap_until { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __is_heap_until_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - auto&& __projected_comp = std::__make_projected(__comp, __proj); - - return std::__is_heap_until(std::move(__first), std::move(__last_iter), __projected_comp); - } - - template _Sent, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __is_heap_until_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { - return __is_heap_until_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto is_heap_until = __is_heap_until{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_partitioned.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_partitioned.h deleted file mode 100644 index 8092abf..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_partitioned.h +++ /dev/null @@ -1,84 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H -#define _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H - -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __is_partitioned { - template - _LIBCPP_HIDE_FROM_ABI constexpr static bool - __is_partitioned_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (!std::invoke(__pred, std::invoke(__proj, *__first))) - break; - } - - if (__first == __last) - return true; - ++__first; - - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) - return false; - } - - return true; - } - - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { - return __is_partitioned_impl(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return __is_partitioned_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto is_partitioned = __is_partitioned{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_permutation.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_permutation.h deleted file mode 100644 index 53a431d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_permutation.h +++ /dev/null @@ -1,105 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H -#define _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H - -#include <__algorithm/is_permutation.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __is_permutation { - template - _LIBCPP_HIDE_FROM_ABI constexpr static bool __is_permutation_func_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2) { - return std::__is_permutation<_RangeAlgPolicy>( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); - } - - template < - forward_iterator _Iter1, - sentinel_for<_Iter1> _Sent1, - forward_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Proj1 = identity, - class _Proj2 = identity, - indirect_equivalence_relation, projected<_Iter2, _Proj2>> _Pred = ranges::equal_to> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return __is_permutation_func_impl( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); - } - - template , _Proj1>, - projected, _Proj2>> _Pred = ranges::equal_to> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - if constexpr (sized_range<_Range1> && sized_range<_Range2>) { - if (ranges::distance(__range1) != ranges::distance(__range2)) - return false; - } - - return __is_permutation_func_impl( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __pred, - __proj1, - __proj2); - } -}; - -inline namespace __cpo { -inline constexpr auto is_permutation = __is_permutation{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted.h deleted file mode 100644 index ab06706..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted.h +++ /dev/null @@ -1,65 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H -#define _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H - -#include <__algorithm/ranges_is_sorted_until.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __is_sorted { - template _Sent, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return ranges::__is_sorted_until_impl(std::move(__first), __last, __comp, __proj) == __last; - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { - auto __last = ranges::end(__range); - return ranges::__is_sorted_until_impl(ranges::begin(__range), __last, __comp, __proj) == __last; - } -}; - -inline namespace __cpo { -inline constexpr auto is_sorted = __is_sorted{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted_until.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted_until.h deleted file mode 100644 index f2e51c2..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_is_sorted_until.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H -#define _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H - -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -_LIBCPP_HIDE_FROM_ABI constexpr _Iter -__is_sorted_until_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - if (__first == __last) - return __first; - auto __i = __first; - while (++__i != __last) { - if (std::invoke(__comp, std::invoke(__proj, *__i), std::invoke(__proj, *__first))) - return __i; - __first = __i; - } - return __i; -} - -struct __is_sorted_until { - template _Sent, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return ranges::__is_sorted_until_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { - return ranges::__is_sorted_until_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto is_sorted_until = __is_sorted_until{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_iterator_concept.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_iterator_concept.h deleted file mode 100644 index 947dfa4..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_iterator_concept.h +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H -#define _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H - -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/remove_cvref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -consteval auto __get_iterator_concept() { - using _Iter = __remove_cvref_t<_IterMaybeQualified>; - - if constexpr (contiguous_iterator<_Iter>) - return contiguous_iterator_tag(); - else if constexpr (random_access_iterator<_Iter>) - return random_access_iterator_tag(); - else if constexpr (bidirectional_iterator<_Iter>) - return bidirectional_iterator_tag(); - else if constexpr (forward_iterator<_Iter>) - return forward_iterator_tag(); - else if constexpr (input_iterator<_Iter>) - return input_iterator_tag(); -} - -template -using __iterator_concept _LIBCPP_NODEBUG = decltype(ranges::__get_iterator_concept<_Iter>()); - -} // namespace ranges -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_lexicographical_compare.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_lexicographical_compare.h deleted file mode 100644 index ec12b0c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_lexicographical_compare.h +++ /dev/null @@ -1,107 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H -#define _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H - -#include <__algorithm/lexicographical_compare.h> -#include <__algorithm/unwrap_range.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __lexicographical_compare { - template - static _LIBCPP_HIDE_FROM_ABI constexpr bool __lexicographical_compare_unwrap( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Comp& __comp, - _Proj1& __proj1, - _Proj2& __proj2) { - auto [__first1_un, __last1_un] = std::__unwrap_range(std::move(__first1), std::move(__last1)); - auto [__first2_un, __last2_un] = std::__unwrap_range(std::move(__first2), std::move(__last2)); - return std::__lexicographical_compare( - std::move(__first1_un), - std::move(__last1_un), - std::move(__first2_un), - std::move(__last2_un), - __comp, - __proj1, - __proj2); - } - - template _Sent1, - input_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Proj1 = identity, - class _Proj2 = identity, - indirect_strict_weak_order, projected<_Iter2, _Proj2>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return __lexicographical_compare_unwrap( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __comp, __proj1, __proj2); - } - - template , _Proj1>, projected, _Proj2>> - _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( - _Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - return __lexicographical_compare_unwrap( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __comp, - __proj1, - __proj2); - } -}; - -inline namespace __cpo { -inline constexpr auto lexicographical_compare = __lexicographical_compare{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_lower_bound.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_lower_bound.h deleted file mode 100644 index d1b3328..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_lower_bound.h +++ /dev/null @@ -1,71 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H -#define _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/lower_bound.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/advance.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -struct __lower_bound { - template _Sent, - class _Type, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { - return std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { - return std::__lower_bound<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto lower_bound = __lower_bound{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_make_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_make_heap.h deleted file mode 100644 index 97148f7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_make_heap.h +++ /dev/null @@ -1,81 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H -#define _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_heap.h> -#include <__algorithm/make_projected.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __make_heap { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __make_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - - auto&& __projected_comp = std::__make_projected(__comp, __proj); - std::__make_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp); - - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __make_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - return __make_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto make_heap = __make_heap{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_max.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_max.h deleted file mode 100644 index a8fe13a..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_max.h +++ /dev/null @@ -1,101 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MAX_H -#define _LIBCPP___ALGORITHM_RANGES_MAX_H - -#include <__algorithm/min_element.h> -#include <__assert> -#include <__concepts/copyable.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__type_traits/is_trivially_copyable.h> -#include <__utility/move.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __max { - template > _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& - operator()(_LIBCPP_LIFETIMEBOUND const _Tp& __a, - _LIBCPP_LIFETIMEBOUND const _Tp& __b, - _Comp __comp = {}, - _Proj __proj = {}) const { - return std::invoke(__comp, std::invoke(__proj, __a), std::invoke(__proj, __b)) ? __b : __a; - } - - template > _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp - operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __il.begin() != __il.end(), "initializer_list must contain at least one element"); - - auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); }; - return *std::__min_element(__il.begin(), __il.end(), __comp_lhs_rhs_swapped, __proj); - } - - template , _Proj>> _Comp = ranges::less> - requires indirectly_copyable_storable, range_value_t<_Rp>*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_value_t<_Rp> - operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - auto __first = ranges::begin(__r); - auto __last = ranges::end(__r); - - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range must contain at least one element"); - - if constexpr (forward_range<_Rp> && !__is_cheap_to_copy>) { - auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { - return std::invoke(__comp, __rhs, __lhs); - }; - return *std::__min_element(std::move(__first), std::move(__last), __comp_lhs_rhs_swapped, __proj); - } else { - range_value_t<_Rp> __result = *__first; - while (++__first != __last) { - if (std::invoke(__comp, std::invoke(__proj, __result), std::invoke(__proj, *__first))) - __result = *__first; - } - return __result; - } - } -}; - -inline namespace __cpo { -inline constexpr auto max = __max{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_RANGES_MAX_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_max_element.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_max_element.h deleted file mode 100644 index db6d5f6..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_max_element.h +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H -#define _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H - -#include <__algorithm/min_element.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __max_element { - template _Sp, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip - operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const { - auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); }; - return std::__min_element(__first, __last, __comp_lhs_rhs_swapped, __proj); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> - operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); }; - return std::__min_element(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto max_element = __max_element{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_merge.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_merge.h deleted file mode 100644 index f3e0486..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_merge.h +++ /dev/null @@ -1,134 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MERGE_H -#define _LIBCPP___ALGORITHM_RANGES_MERGE_H - -#include <__algorithm/in_in_out_result.h> -#include <__algorithm/ranges_copy.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/mergeable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using merge_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; - -struct __merge { - template _Sent1, - input_iterator _InIter2, - sentinel_for<_InIter2> _Sent2, - weakly_incrementable _OutIter, - class _Comp = less, - class _Proj1 = identity, - class _Proj2 = identity> - requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr merge_result<_InIter1, _InIter2, _OutIter> operator()( - _InIter1 __first1, - _Sent1 __last1, - _InIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return __merge::__merge_impl(__first1, __last1, __first2, __last2, __result, __comp, __proj1, __proj2); - } - - template - requires mergeable, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr merge_result, borrowed_iterator_t<_Range2>, _OutIter> - operator()(_Range1&& __range1, - _Range2&& __range2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return __merge::__merge_impl( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __result, - __comp, - __proj1, - __proj2); - } - - template < class _InIter1, - class _Sent1, - class _InIter2, - class _Sent2, - class _OutIter, - class _Comp, - class _Proj1, - class _Proj2> - _LIBCPP_HIDE_FROM_ABI static constexpr merge_result<__remove_cvref_t<_InIter1>, - __remove_cvref_t<_InIter2>, - __remove_cvref_t<_OutIter>> - __merge_impl(_InIter1&& __first1, - _Sent1&& __last1, - _InIter2&& __first2, - _Sent2&& __last2, - _OutIter&& __result, - _Comp&& __comp, - _Proj1&& __proj1, - _Proj2&& __proj2) { - for (; __first1 != __last1 && __first2 != __last2; ++__result) { - if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1))) { - *__result = *__first2; - ++__first2; - } else { - *__result = *__first1; - ++__first1; - } - } - auto __ret1 = ranges::copy(std::move(__first1), std::move(__last1), std::move(__result)); - auto __ret2 = ranges::copy(std::move(__first2), std::move(__last2), std::move(__ret1.out)); - return {std::move(__ret1.in), std::move(__ret2.in), std::move(__ret2.out)}; - } -}; - -inline namespace __cpo { -inline constexpr auto merge = __merge{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MERGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_min.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_min.h deleted file mode 100644 index 9f1c78e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_min.h +++ /dev/null @@ -1,93 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MIN_H -#define _LIBCPP___ALGORITHM_RANGES_MIN_H - -#include <__algorithm/min_element.h> -#include <__assert> -#include <__concepts/copyable.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__type_traits/is_trivially_copyable.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __min { - template > _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& - operator()(_LIBCPP_LIFETIMEBOUND const _Tp& __a, - _LIBCPP_LIFETIMEBOUND const _Tp& __b, - _Comp __comp = {}, - _Proj __proj = {}) const { - return std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a)) ? __b : __a; - } - - template > _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp - operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __il.begin() != __il.end(), "initializer_list must contain at least one element"); - return *std::__min_element(__il.begin(), __il.end(), __comp, __proj); - } - - template , _Proj>> _Comp = ranges::less> - requires indirectly_copyable_storable, range_value_t<_Rp>*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_value_t<_Rp> - operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - auto __first = ranges::begin(__r); - auto __last = ranges::end(__r); - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range must contain at least one element"); - if constexpr (forward_range<_Rp> && !__is_cheap_to_copy>) { - return *std::__min_element(__first, __last, __comp, __proj); - } else { - range_value_t<_Rp> __result = *__first; - while (++__first != __last) { - if (std::invoke(__comp, std::invoke(__proj, *__first), std::invoke(__proj, __result))) - __result = *__first; - } - return __result; - } - } -}; - -inline namespace __cpo { -inline constexpr auto min = __min{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_RANGES_MIN_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_min_element.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_min_element.h deleted file mode 100644 index 5deb409..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_min_element.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H -#define _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H - -#include <__algorithm/min_element.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __min_element { - template _Sp, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip - operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const { - return std::__min_element(__first, __last, __comp, __proj); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp> - operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - return std::__min_element(ranges::begin(__r), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto min_element = __min_element{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax.h deleted file mode 100644 index 5f2e5cb..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax.h +++ /dev/null @@ -1,174 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MINMAX_H -#define _LIBCPP___ALGORITHM_RANGES_MINMAX_H - -#include <__algorithm/min_max_result.h> -#include <__algorithm/minmax_element.h> -#include <__assert> -#include <__concepts/copyable.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__type_traits/desugars_to.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_reference.h> -#include <__type_traits/is_trivially_copyable.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/pair.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -template -using minmax_result = min_max_result<_T1>; - -struct __minmax { - template > _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result - operator()(_LIBCPP_LIFETIMEBOUND const _Type& __a, - _LIBCPP_LIFETIMEBOUND const _Type& __b, - _Comp __comp = {}, - _Proj __proj = {}) const { - if (std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a))) - return {__b, __a}; - return {__a, __b}; - } - - template > _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result<_Type> - operator()(initializer_list<_Type> __il, _Comp __comp = {}, _Proj __proj = {}) const { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __il.begin() != __il.end(), "initializer_list has to contain at least one element"); - auto __iters = std::__minmax_element_impl(__il.begin(), __il.end(), __comp, __proj); - return ranges::minmax_result<_Type>{*__iters.first, *__iters.second}; - } - - template , _Proj>> _Comp = ranges::less> - requires indirectly_copyable_storable, range_value_t<_Range>*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result> - operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - auto __first = ranges::begin(__r); - auto __last = ranges::end(__r); - using _ValueT = range_value_t<_Range>; - - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range has to contain at least one element"); - - // This optimiation is not in minmax_element because clang doesn't see through the pointers and as a result doesn't - // vectorize the code. - if constexpr (contiguous_range<_Range> && is_integral_v<_ValueT> && - __is_cheap_to_copy<_ValueT> & __is_identity<_Proj>::value && - __desugars_to_v<__less_tag, _Comp, _ValueT, _ValueT>) { - minmax_result<_ValueT> __result = {__r[0], __r[0]}; - for (auto __e : __r) { - if (__e < __result.min) - __result.min = __e; - if (__result.max < __e) - __result.max = __e; - } - return __result; - } else if constexpr (forward_range<_Range>) { - // Special-case the one element case. Avoid repeatedly initializing objects from the result of an iterator - // dereference when doing so might not be idempotent. The `if constexpr` avoids the extra branch in cases where - // it's not needed. - if constexpr (!same_as>, _ValueT> || - is_rvalue_reference_v>) { - if (ranges::next(__first) == __last) { - // During initialization, members are allowed to refer to already initialized members - // (see http://eel.is/c++draft/dcl.init.aggr#6) - minmax_result<_ValueT> __result = {*__first, __result.min}; - return __result; - } - } - auto __result = std::__minmax_element_impl(__first, __last, __comp, __proj); - return {*__result.first, *__result.second}; - } else { - // input_iterators can't be copied, so the implementation for input_iterators has to store - // the values instead of a pointer to the correct values - auto __less = [&](auto&& __a, auto&& __b) -> bool { - return std::invoke(__comp, - std::invoke(__proj, std::forward(__a)), - std::invoke(__proj, std::forward(__b))); - }; - - // During initialization, members are allowed to refer to already initialized members - // (see http://eel.is/c++draft/dcl.init.aggr#6) - ranges::minmax_result<_ValueT> __result = {*__first, __result.min}; - if (__first == __last || ++__first == __last) - return __result; - - if (__less(*__first, __result.min)) - __result.min = *__first; - else - __result.max = *__first; - - while (++__first != __last) { - _ValueT __i = *__first; - if (++__first == __last) { - if (__less(__i, __result.min)) - __result.min = __i; - else if (!__less(__i, __result.max)) - __result.max = __i; - return __result; - } - - if (__less(*__first, __i)) { - if (__less(*__first, __result.min)) - __result.min = *__first; - if (!__less(__i, __result.max)) - __result.max = std::move(__i); - } else { - if (__less(__i, __result.min)) - __result.min = std::move(__i); - if (!__less(*__first, __result.max)) - __result.max = *__first; - } - } - return __result; - } - } -}; - -inline namespace __cpo { -inline constexpr auto minmax = __minmax{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax_element.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax_element.h deleted file mode 100644 index e1a22dd..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_minmax_element.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MINMAX_ELEMENT_H -#define _LIBCPP___ALGORITHM_RANGES_MINMAX_ELEMENT_H - -#include <__algorithm/min_max_result.h> -#include <__algorithm/minmax_element.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using minmax_element_result = min_max_result<_T1>; - -struct __minmax_element { - template _Sp, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_element_result<_Ip> - operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__minmax_element_impl(std::move(__first), std::move(__last), __comp, __proj); - return {__ret.first, __ret.second}; - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_element_result> - operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__minmax_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); - return {__ret.first, __ret.second}; - } -}; - -inline namespace __cpo { -inline constexpr auto minmax_element = __minmax_element{}; -} // namespace __cpo - -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_mismatch.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_mismatch.h deleted file mode 100644 index b35747d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_mismatch.h +++ /dev/null @@ -1,98 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MISMATCH_H -#define _LIBCPP___ALGORITHM_RANGES_MISMATCH_H - -#include <__algorithm/in_in_result.h> -#include <__algorithm/mismatch.h> -#include <__algorithm/unwrap_range.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace ranges { - -template -using mismatch_result = in_in_result<_I1, _I2>; - -struct __mismatch { - template - static _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2> - __go(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - if constexpr (forward_iterator<_I1> && forward_iterator<_I2>) { - auto __range1 = std::__unwrap_range(__first1, __last1); - auto __range2 = std::__unwrap_range(__first2, __last2); - auto __res = - std::__mismatch(__range1.first, __range1.second, __range2.first, __range2.second, __pred, __proj1, __proj2); - return {std::__rewrap_range<_S1>(__first1, __res.first), std::__rewrap_range<_S2>(__first2, __res.second)}; - } else { - auto __res = std::__mismatch( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); - return {std::move(__res.first), std::move(__res.second)}; - } - } - - template _S1, - input_iterator _I2, - sentinel_for<_I2> _S2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_comparable<_I1, _I2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2> operator()( - _I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) - const { - return __go(std::move(__first1), __last1, std::move(__first2), __last2, __pred, __proj1, __proj2); - } - - template - requires indirectly_comparable, iterator_t<_R2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] - _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result, borrowed_iterator_t<_R2>> - operator()(_R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - return __go( - ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2), __pred, __proj1, __proj2); - } -}; - -inline namespace __cpo { -constexpr inline auto mismatch = __mismatch{}; -} // namespace __cpo -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MISMATCH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_move.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_move.h deleted file mode 100644 index 02bf7fd..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_move.h +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MOVE_H -#define _LIBCPP___ALGORITHM_RANGES_MOVE_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/move.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using move_result = in_out_result<_InIter, _OutIter>; - -struct __move { - template - _LIBCPP_HIDE_FROM_ABI constexpr static move_result<_InIter, _OutIter> - __move_impl(_InIter __first, _Sent __last, _OutIter __result) { - auto __ret = std::__move<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template _Sent, weakly_incrementable _OutIter> - requires indirectly_movable<_InIter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr move_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - return __move_impl(std::move(__first), std::move(__last), std::move(__result)); - } - - template - requires indirectly_movable, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr move_result, _OutIter> - operator()(_Range&& __range, _OutIter __result) const { - return __move_impl(ranges::begin(__range), ranges::end(__range), std::move(__result)); - } -}; - -inline namespace __cpo { -inline constexpr auto move = __move{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MOVE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_move_backward.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_move_backward.h deleted file mode 100644 index 4737e6c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_move_backward.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H -#define _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/move_backward.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iter_move.h> -#include <__iterator/next.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using move_backward_result = in_out_result<_InIter, _OutIter>; - -struct __move_backward { - template - _LIBCPP_HIDE_FROM_ABI constexpr static move_backward_result<_InIter, _OutIter> - __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) { - auto __ret = std::__move_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template _Sent, bidirectional_iterator _OutIter> - requires indirectly_movable<_InIter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr move_backward_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - return __move_backward_impl(std::move(__first), std::move(__last), std::move(__result)); - } - - template - requires indirectly_movable, _Iter> - _LIBCPP_HIDE_FROM_ABI constexpr move_backward_result, _Iter> - operator()(_Range&& __range, _Iter __result) const { - return __move_backward_impl(ranges::begin(__range), ranges::end(__range), std::move(__result)); - } -}; - -inline namespace __cpo { -inline constexpr auto move_backward = __move_backward{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_next_permutation.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_next_permutation.h deleted file mode 100644 index 1b48542..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_next_permutation.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H -#define _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H - -#include <__algorithm/in_found_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/next_permutation.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using next_permutation_result = in_found_result<_InIter>; - -struct __next_permutation { - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr next_permutation_result<_Iter> - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - auto __result = std::__next_permutation<_RangeAlgPolicy>( - std::move(__first), std::move(__last), std::__make_projected(__comp, __proj)); - return {std::move(__result.first), std::move(__result.second)}; - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr next_permutation_result> - operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { - auto __result = std::__next_permutation<_RangeAlgPolicy>( - ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj)); - return {std::move(__result.first), std::move(__result.second)}; - } -}; - -inline namespace __cpo { -constexpr inline auto next_permutation = __next_permutation{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_NEXT_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_none_of.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_none_of.h deleted file mode 100644 index a161282..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_none_of.h +++ /dev/null @@ -1,73 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_NONE_OF_H -#define _LIBCPP___ALGORITHM_RANGES_NONE_OF_H - -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __none_of { - template - _LIBCPP_HIDE_FROM_ABI constexpr static bool - __none_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) - return false; - } - return true; - } - - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { - return __none_of_impl(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return __none_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto none_of = __none_of{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_NONE_OF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_nth_element.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_nth_element.h deleted file mode 100644 index e92c51e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_nth_element.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H -#define _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/nth_element.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __nth_element { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __nth_element_fn_impl(_Iter __first, _Iter __nth, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - - auto&& __projected_comp = std::__make_projected(__comp, __proj); - std::__nth_element_impl<_RangeAlgPolicy>(std::move(__first), std::move(__nth), __last_iter, __projected_comp); - - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Iter __nth, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __nth_element_fn_impl(std::move(__first), std::move(__nth), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, iterator_t<_Range> __nth, _Comp __comp = {}, _Proj __proj = {}) const { - return __nth_element_fn_impl(ranges::begin(__r), std::move(__nth), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto nth_element = __nth_element{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort.h deleted file mode 100644 index fc8a1f7..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort.h +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H -#define _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/partial_sort.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __partial_sort { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __partial_sort_fn_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto&& __projected_comp = std::__make_projected(__comp, __proj); - return std::__partial_sort<_RangeAlgPolicy>(std::move(__first), std::move(__middle), __last, __projected_comp); - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Iter __middle, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __partial_sort_fn_impl(std::move(__first), std::move(__middle), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, iterator_t<_Range> __middle, _Comp __comp = {}, _Proj __proj = {}) const { - return __partial_sort_fn_impl(ranges::begin(__r), std::move(__middle), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto partial_sort = __partial_sort{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort_copy.h deleted file mode 100644 index f221504..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partial_sort_copy.h +++ /dev/null @@ -1,110 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/partial_sort_copy.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using partial_sort_copy_result = in_out_result<_InIter, _OutIter>; - -struct __partial_sort_copy { - template _Sent1, - random_access_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Comp = ranges::less, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_copyable<_Iter1, _Iter2> && sortable<_Iter2, _Comp, _Proj2> && - indirect_strict_weak_order<_Comp, projected<_Iter1, _Proj1>, projected<_Iter2, _Proj2>> - _LIBCPP_HIDE_FROM_ABI constexpr partial_sort_copy_result<_Iter1, _Iter2> operator()( - _Iter1 __first, - _Sent1 __last, - _Iter2 __result_first, - _Sent2 __result_last, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __result = std::__partial_sort_copy<_RangeAlgPolicy>( - std::move(__first), - std::move(__last), - std::move(__result_first), - std::move(__result_last), - __comp, - __proj1, - __proj2); - return {std::move(__result.first), std::move(__result.second)}; - } - - template - requires indirectly_copyable, iterator_t<_Range2>> && - sortable, _Comp, _Proj2> && - indirect_strict_weak_order<_Comp, - projected, _Proj1>, - projected, _Proj2>> - _LIBCPP_HIDE_FROM_ABI constexpr partial_sort_copy_result, borrowed_iterator_t<_Range2>> - operator()( - _Range1&& __range, _Range2&& __result_range, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __result = std::__partial_sort_copy<_RangeAlgPolicy>( - ranges::begin(__range), - ranges::end(__range), - ranges::begin(__result_range), - ranges::end(__result_range), - __comp, - __proj1, - __proj2); - return {std::move(__result.first), std::move(__result.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto partial_sort_copy = __partial_sort_copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition.h deleted file mode 100644 index b9cc3c1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition.h +++ /dev/null @@ -1,85 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_H -#define _LIBCPP___ALGORITHM_RANGES_PARTITION_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/partition.h> -#include <__algorithm/ranges_iterator_concept.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/permutable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __partition { - template - _LIBCPP_HIDE_FROM_ABI static constexpr subrange<__remove_cvref_t<_Iter>> - __partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { - auto&& __projected_pred = std::__make_projected(__pred, __proj); - auto __result = std::__partition<_RangeAlgPolicy>( - std::move(__first), std::move(__last), __projected_pred, __iterator_concept<_Iter>()); - - return {std::move(__result.first), std::move(__result.second)}; - } - - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> - operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { - return __partition_fn_impl(__first, __last, __pred, __proj); - } - - template , _Proj>> _Pred> - requires permutable> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return __partition_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto partition = __partition{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_copy.h deleted file mode 100644 index 47878a4..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_copy.h +++ /dev/null @@ -1,106 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H - -#include <__algorithm/in_out_out_result.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using partition_copy_result = in_out_out_result<_InIter, _OutIter1, _OutIter2>; - -struct __partition_copy { - // TODO(ranges): delegate to the classic algorithm. - template - _LIBCPP_HIDE_FROM_ABI constexpr static partition_copy_result<__remove_cvref_t<_InIter>, - __remove_cvref_t<_OutIter1>, - __remove_cvref_t<_OutIter2> > - __partition_copy_fn_impl( - _InIter&& __first, - _Sent&& __last, - _OutIter1&& __out_true, - _OutIter2&& __out_false, - _Pred& __pred, - _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) { - *__out_true = *__first; - ++__out_true; - - } else { - *__out_false = *__first; - ++__out_false; - } - } - - return {std::move(__first), std::move(__out_true), std::move(__out_false)}; - } - - template _Sent, - weakly_incrementable _OutIter1, - weakly_incrementable _OutIter2, - class _Proj = identity, - indirect_unary_predicate> _Pred> - requires indirectly_copyable<_InIter, _OutIter1> && indirectly_copyable<_InIter, _OutIter2> - _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result<_InIter, _OutIter1, _OutIter2> operator()( - _InIter __first, _Sent __last, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {}) - const { - return __partition_copy_fn_impl( - std::move(__first), std::move(__last), std::move(__out_true), std::move(__out_false), __pred, __proj); - } - - template , _Proj>> _Pred> - requires indirectly_copyable, _OutIter1> && indirectly_copyable, _OutIter2> - _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result, _OutIter1, _OutIter2> - operator()(_Range&& __range, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {}) const { - return __partition_copy_fn_impl( - ranges::begin(__range), ranges::end(__range), std::move(__out_true), std::move(__out_false), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto partition_copy = __partition_copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_point.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_point.h deleted file mode 100644 index 324efbb..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_partition_point.h +++ /dev/null @@ -1,89 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H -#define _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H - -#include <__algorithm/half_positive.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __partition_point { - // TODO(ranges): delegate to the classic algorithm. - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __partition_point_fn_impl(_Iter&& __first, _Sent&& __last, _Pred& __pred, _Proj& __proj) { - auto __len = ranges::distance(__first, __last); - - while (__len != 0) { - auto __half_len = std::__half_positive(__len); - auto __mid = ranges::next(__first, __half_len); - - if (std::invoke(__pred, std::invoke(__proj, *__mid))) { - __first = ++__mid; - __len -= __half_len + 1; - - } else { - __len = __half_len; - } - } - - return __first; - } - - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { - return __partition_point_fn_impl(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return __partition_point_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto partition_point = __partition_point{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_pop_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_pop_heap.h deleted file mode 100644 index eccf54c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_pop_heap.h +++ /dev/null @@ -1,82 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H -#define _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/pop_heap.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __pop_heap { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __pop_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - auto __len = __last_iter - __first; - - auto&& __projected_comp = std::__make_projected(__comp, __proj); - std::__pop_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp, __len); - - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __pop_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - return __pop_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto pop_heap = __pop_heap{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_prev_permutation.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_prev_permutation.h deleted file mode 100644 index f2294b1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_prev_permutation.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H -#define _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H - -#include <__algorithm/in_found_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/prev_permutation.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using prev_permutation_result = in_found_result<_InIter>; - -struct __prev_permutation { - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result<_Iter> - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - auto __result = std::__prev_permutation<_RangeAlgPolicy>( - std::move(__first), std::move(__last), std::__make_projected(__comp, __proj)); - return {std::move(__result.first), std::move(__result.second)}; - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result> - operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { - auto __result = std::__prev_permutation<_RangeAlgPolicy>( - ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj)); - return {std::move(__result.first), std::move(__result.second)}; - } -}; - -inline namespace __cpo { -constexpr inline auto prev_permutation = __prev_permutation{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_push_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_push_heap.h deleted file mode 100644 index c5e0465..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_push_heap.h +++ /dev/null @@ -1,81 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H -#define _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/push_heap.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __push_heap { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __push_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - - auto&& __projected_comp = std::__make_projected(__comp, __proj); - std::__push_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp); - - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __push_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - return __push_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto push_heap = __push_heap{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove.h deleted file mode 100644 index 6fbc49e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_H -#define _LIBCPP___ALGORITHM_RANGES_REMOVE_H -#include <__config> - -#include <__algorithm/ranges_remove_if.h> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/permutable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __remove { - template _Sent, class _Type, class _Proj = identity> - requires indirect_binary_predicate, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> - operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const { - auto __pred = [&](auto&& __other) -> bool { return __value == __other; }; - return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj); - } - - template - requires permutable> && - indirect_binary_predicate, _Proj>, const _Type*> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const { - auto __pred = [&](auto&& __other) -> bool { return __value == __other; }; - return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto remove = __remove{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy.h deleted file mode 100644 index 764c52e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy.h +++ /dev/null @@ -1,77 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/ranges_remove_copy_if.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using remove_copy_result = in_out_result<_InIter, _OutIter>; - -struct __remove_copy { - template _Sent, - weakly_incrementable _OutIter, - class _Type, - class _Proj = identity> - requires indirectly_copyable<_InIter, _OutIter> && - indirect_binary_predicate, const _Type*> - _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result, const _Type& __value, _Proj __proj = {}) const { - auto __pred = [&](auto&& __val) -> bool { return __value == __val; }; - return ranges::__remove_copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); - } - - template - requires indirectly_copyable, _OutIter> && - indirect_binary_predicate, _Proj>, const _Type*> - _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_result, _OutIter> - operator()(_Range&& __range, _OutIter __result, const _Type& __value, _Proj __proj = {}) const { - auto __pred = [&](auto&& __val) -> bool { return __value == __val; }; - return ranges::__remove_copy_if_impl( - ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto remove_copy = __remove_copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy_if.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy_if.h deleted file mode 100644 index 87136ae..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_copy_if.h +++ /dev/null @@ -1,91 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H -#define _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/remove_copy_if.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using remove_copy_if_result = in_out_result<_InIter, _OutIter>; - -template -_LIBCPP_HIDE_FROM_ABI constexpr in_out_result<_InIter, _OutIter> -__remove_copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (!std::invoke(__pred, std::invoke(__proj, *__first))) { - *__result = *__first; - ++__result; - } - } - return {std::move(__first), std::move(__result)}; -} - -struct __remove_copy_if { - template _Sent, - weakly_incrementable _OutIter, - class _Proj = identity, - indirect_unary_predicate> _Pred> - requires indirectly_copyable<_InIter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_if_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - return ranges::__remove_copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); - } - - template , _Proj>> _Pred> - requires indirectly_copyable, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_if_result, _OutIter> - operator()(_Range&& __range, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - return ranges::__remove_copy_if_impl( - ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto remove_copy_if = __remove_copy_if{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_if.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_if.h deleted file mode 100644 index 397959b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_remove_if.h +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H -#define _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H -#include <__config> - -#include <__algorithm/find_if.h> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/iter_move.h> -#include <__iterator/permutable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -_LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> -__remove_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - auto __new_end = std::__find_if(__first, __last, __pred, __proj); - if (__new_end == __last) - return {__new_end, __new_end}; - - _Iter __i = __new_end; - while (++__i != __last) { - if (!std::invoke(__pred, std::invoke(__proj, *__i))) { - *__new_end = ranges::iter_move(__i); - ++__new_end; - } - } - return {__new_end, __i}; -} - -struct __remove_if { - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> - operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { - return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj); - } - - template , _Proj>> _Pred> - requires permutable> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto remove_if = __remove_if{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace.h deleted file mode 100644 index 15b1f38..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_H -#define _LIBCPP___ALGORITHM_RANGES_REPLACE_H - -#include <__algorithm/ranges_replace_if.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __replace { - template _Sent, class _Type1, class _Type2, class _Proj = identity> - requires indirectly_writable<_Iter, const _Type2&> && - indirect_binary_predicate, const _Type1*> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()( - _Iter __first, _Sent __last, const _Type1& __old_value, const _Type2& __new_value, _Proj __proj = {}) const { - auto __pred = [&](const auto& __val) -> bool { return __val == __old_value; }; - return ranges::__replace_if_impl(std::move(__first), std::move(__last), __pred, __new_value, __proj); - } - - template - requires indirectly_writable, const _Type2&> && - indirect_binary_predicate, _Proj>, const _Type1*> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __range, const _Type1& __old_value, const _Type2& __new_value, _Proj __proj = {}) const { - auto __pred = [&](auto&& __val) -> bool { return __val == __old_value; }; - return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto replace = __replace{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy.h deleted file mode 100644 index 7ab1c71..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy.h +++ /dev/null @@ -1,89 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/ranges_replace_copy_if.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using replace_copy_result = in_out_result<_InIter, _OutIter>; - -struct __replace_copy { - template _Sent, - class _OldType, - class _NewType, - output_iterator _OutIter, - class _Proj = identity> - requires indirectly_copyable<_InIter, _OutIter> && - indirect_binary_predicate, const _OldType*> - _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_result<_InIter, _OutIter> - operator()(_InIter __first, - _Sent __last, - _OutIter __result, - const _OldType& __old_value, - const _NewType& __new_value, - _Proj __proj = {}) const { - auto __pred = [&](const auto& __value) -> bool { return __value == __old_value; }; - return ranges::__replace_copy_if_impl( - std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj); - } - - template _OutIter, - class _Proj = identity> - requires indirectly_copyable, _OutIter> && - indirect_binary_predicate, _Proj>, const _OldType*> - _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_result, _OutIter> operator()( - _Range&& __range, _OutIter __result, const _OldType& __old_value, const _NewType& __new_value, _Proj __proj = {}) - const { - auto __pred = [&](const auto& __value) -> bool { return __value == __old_value; }; - return ranges::__replace_copy_if_impl( - ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto replace_copy = __replace_copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy_if.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy_if.h deleted file mode 100644 index 852ec45..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_copy_if.h +++ /dev/null @@ -1,94 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H -#define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H - -#include <__algorithm/in_out_result.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using replace_copy_if_result = in_out_result<_InIter, _OutIter>; - -template -_LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> __replace_copy_if_impl( - _InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, const _Type& __new_value, _Proj& __proj) { - while (__first != __last) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) - *__result = __new_value; - else - *__result = *__first; - - ++__first; - ++__result; - } - - return {std::move(__first), std::move(__result)}; -} - -struct __replace_copy_if { - template _Sent, - class _Type, - output_iterator _OutIter, - class _Proj = identity, - indirect_unary_predicate> _Pred> - requires indirectly_copyable<_InIter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> operator()( - _InIter __first, _Sent __last, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) - const { - return ranges::__replace_copy_if_impl( - std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj); - } - - template _OutIter, - class _Proj = identity, - indirect_unary_predicate, _Proj>> _Pred> - requires indirectly_copyable, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result, _OutIter> - operator()(_Range&& __range, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const { - return ranges::__replace_copy_if_impl( - ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto replace_copy_if = __replace_copy_if{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_if.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_if.h deleted file mode 100644 index baa5668..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_replace_if.h +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H -#define _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H - -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -_LIBCPP_HIDE_FROM_ABI constexpr _Iter -__replace_if_impl(_Iter __first, _Sent __last, _Pred& __pred, const _Type& __new_value, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) - *__first = __new_value; - } - return __first; -} - -struct __replace_if { - template _Sent, - class _Type, - class _Proj = identity, - indirect_unary_predicate> _Pred> - requires indirectly_writable<_Iter, const _Type&> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const { - return ranges::__replace_if_impl(std::move(__first), std::move(__last), __pred, __new_value, __proj); - } - - template , _Proj>> _Pred> - requires indirectly_writable, const _Type&> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __range, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const { - return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto replace_if = __replace_if{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse.h deleted file mode 100644 index 4e82118..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse.h +++ /dev/null @@ -1,77 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REVERSE_H -#define _LIBCPP___ALGORITHM_RANGES_REVERSE_H - -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iter_swap.h> -#include <__iterator/next.h> -#include <__iterator/permutable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __reverse { - template _Sent> - requires permutable<_Iter> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last) const { - if constexpr (random_access_iterator<_Iter>) { - if (__first == __last) - return __first; - - auto __end = ranges::next(__first, __last); - auto __ret = __end; - - while (__first < --__end) { - ranges::iter_swap(__first, __end); - ++__first; - } - return __ret; - } else { - auto __end = ranges::next(__first, __last); - auto __ret = __end; - - while (__first != __end) { - if (__first == --__end) - break; - - ranges::iter_swap(__first, __end); - ++__first; - } - return __ret; - } - } - - template - requires permutable> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range) const { - return (*this)(ranges::begin(__range), ranges::end(__range)); - } -}; - -inline namespace __cpo { -inline constexpr auto reverse = __reverse{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse_copy.h deleted file mode 100644 index 9fedab5..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_reverse_copy.h +++ /dev/null @@ -1,69 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/ranges_copy.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/next.h> -#include <__iterator/reverse_iterator.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__ranges/reverse_view.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using reverse_copy_result = in_out_result<_InIter, _OutIter>; - -struct __reverse_copy { - template _Sent, weakly_incrementable _OutIter> - requires indirectly_copyable<_InIter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result) const { - return (*this)(subrange(std::move(__first), std::move(__last)), std::move(__result)); - } - - template - requires indirectly_copyable, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result, _OutIter> - operator()(_Range&& __range, _OutIter __result) const { - auto __ret = ranges::copy(__range | views::reverse, std::move(__result)); - return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)}; - } -}; - -inline namespace __cpo { -inline constexpr auto reverse_copy = __reverse_copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate.h deleted file mode 100644 index c1affc6..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate.h +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_H -#define _LIBCPP___ALGORITHM_RANGES_ROTATE_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/ranges_iterator_concept.h> -#include <__algorithm/rotate.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/permutable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __rotate { - template - _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) { - auto __ret = std::__rotate<_RangeAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template _Sent> - _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Iter __middle, _Sent __last) const { - return __rotate_fn_impl(std::move(__first), std::move(__middle), std::move(__last)); - } - - template - requires permutable> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, iterator_t<_Range> __middle) const { - return __rotate_fn_impl(ranges::begin(__range), std::move(__middle), ranges::end(__range)); - } -}; - -inline namespace __cpo { -inline constexpr auto rotate = __rotate{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate_copy.h deleted file mode 100644 index c0b4264..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_rotate_copy.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/ranges_copy.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using rotate_copy_result = in_out_result<_InIter, _OutIter>; - -struct __rotate_copy { - template _Sent, weakly_incrementable _OutIter> - requires indirectly_copyable<_InIter, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result<_InIter, _OutIter> - operator()(_InIter __first, _InIter __middle, _Sent __last, _OutIter __result) const { - auto __res1 = ranges::copy(__middle, __last, std::move(__result)); - auto __res2 = ranges::copy(__first, __middle, std::move(__res1.out)); - return {std::move(__res1.in), std::move(__res2.out)}; - } - - template - requires indirectly_copyable, _OutIter> - _LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result, _OutIter> - operator()(_Range&& __range, iterator_t<_Range> __middle, _OutIter __result) const { - return (*this)(ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__result)); - } -}; - -inline namespace __cpo { -inline constexpr auto rotate_copy = __rotate_copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_sample.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_sample.h deleted file mode 100644 index a3b2960..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_sample.h +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SAMPLE_H -#define _LIBCPP___ALGORITHM_RANGES_SAMPLE_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/sample.h> -#include <__algorithm/uniform_random_bit_generator_adaptor.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/iterator_traits.h> -#include <__random/uniform_random_bit_generator.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__type_traits/remove_reference.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __sample { - template _Sent, weakly_incrementable _OutIter, class _Gen> - requires(forward_iterator<_Iter> || random_access_iterator<_OutIter>) && indirectly_copyable<_Iter, _OutIter> && - uniform_random_bit_generator> - _LIBCPP_HIDE_FROM_ABI _OutIter - operator()(_Iter __first, _Sent __last, _OutIter __out_first, iter_difference_t<_Iter> __n, _Gen&& __gen) const { - _ClassicGenAdaptor<_Gen> __adapted_gen(__gen); - return std::__sample<_RangeAlgPolicy>( - std::move(__first), std::move(__last), std::move(__out_first), __n, __adapted_gen); - } - - template - requires(forward_range<_Range> || random_access_iterator<_OutIter>) && - indirectly_copyable, _OutIter> && uniform_random_bit_generator> - _LIBCPP_HIDE_FROM_ABI _OutIter - operator()(_Range&& __range, _OutIter __out_first, range_difference_t<_Range> __n, _Gen&& __gen) const { - return (*this)( - ranges::begin(__range), ranges::end(__range), std::move(__out_first), __n, std::forward<_Gen>(__gen)); - } -}; - -inline namespace __cpo { -inline constexpr auto sample = __sample{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SAMPLE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_search.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_search.h deleted file mode 100644 index b711512..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_search.h +++ /dev/null @@ -1,132 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SEARCH_H -#define _LIBCPP___ALGORITHM_RANGES_SEARCH_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/search.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/advance.h> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/indirectly_comparable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/size.h> -#include <__ranges/subrange.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __search { - template - _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2) { - if constexpr (sized_sentinel_for<_Sent2, _Iter2>) { - auto __size2 = ranges::distance(__first2, __last2); - if (__size2 == 0) - return {__first1, __first1}; - - if constexpr (sized_sentinel_for<_Sent1, _Iter1>) { - auto __size1 = ranges::distance(__first1, __last1); - if (__size1 < __size2) { - ranges::advance(__first1, __last1); - return {__first1, __first1}; - } - - if constexpr (random_access_iterator<_Iter1> && random_access_iterator<_Iter2>) { - auto __ret = std::__search_random_access_impl<_RangeAlgPolicy>( - __first1, __last1, __first2, __last2, __pred, __proj1, __proj2, __size1, __size2); - return {__ret.first, __ret.second}; - } - } - } - - auto __ret = - std::__search_forward_impl<_RangeAlgPolicy>(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2); - return {__ret.first, __ret.second}; - } - - template _Sent1, - forward_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter1> operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - return __ranges_search_impl(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2); - } - - template - requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range1> operator()( - _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __first1 = ranges::begin(__range1); - if constexpr (sized_range<_Range2>) { - auto __size2 = ranges::size(__range2); - if (__size2 == 0) - return {__first1, __first1}; - if constexpr (sized_range<_Range1>) { - auto __size1 = ranges::size(__range1); - if (__size1 < __size2) { - ranges::advance(__first1, ranges::end(__range1)); - return {__first1, __first1}; - } - } - } - - return __ranges_search_impl( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __pred, - __proj1, - __proj2); - } -}; - -inline namespace __cpo { -inline constexpr auto search = __search{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_RANGES_SEARCH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_search_n.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_search_n.h deleted file mode 100644 index 746bfcc..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_search_n.h +++ /dev/null @@ -1,114 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H -#define _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/search_n.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/advance.h> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/indirectly_comparable.h> -#include <__iterator/iterator_traits.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/size.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __search_n { - template - _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_n_impl( - _Iter1 __first, _Sent1 __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { - if (__count == 0) - return {__first, __first}; - - if constexpr (sized_sentinel_for<_Sent1, _Iter1>) { - auto __size = ranges::distance(__first, __last); - if (__size < __count) { - ranges::advance(__first, __last); - return {__first, __first}; - } - - if constexpr (random_access_iterator<_Iter1>) { - auto __ret = - std::__search_n_random_access_impl<_RangeAlgPolicy>(__first, __count, __value, __pred, __proj, __size); - return {std::move(__ret.first), std::move(__ret.second)}; - } - } - - auto __ret = std::__search_n_forward_impl<_RangeAlgPolicy>(__first, __last, __count, __value, __pred, __proj); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template _Sent, - class _Type, - class _Pred = ranges::equal_to, - class _Proj = identity> - requires indirectly_comparable<_Iter, const _Type*, _Pred, _Proj> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> - operator()(_Iter __first, - _Sent __last, - iter_difference_t<_Iter> __count, - const _Type& __value, - _Pred __pred = {}, - _Proj __proj = _Proj{}) const { - return __ranges_search_n_impl(__first, __last, __count, __value, __pred, __proj); - } - - template - requires indirectly_comparable, const _Type*, _Pred, _Proj> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> operator()( - _Range&& __range, range_difference_t<_Range> __count, const _Type& __value, _Pred __pred = {}, _Proj __proj = {}) - const { - auto __first = ranges::begin(__range); - if (__count <= 0) - return {__first, __first}; - if constexpr (sized_range<_Range>) { - auto __size1 = ranges::size(__range); - if (__size1 < static_cast>(__count)) { - ranges::advance(__first, ranges::end(__range)); - return {__first, __first}; - } - } - - return __ranges_search_n_impl(ranges::begin(__range), ranges::end(__range), __count, __value, __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto search_n = __search_n{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_difference.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_difference.h deleted file mode 100644 index 1c83c7b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_difference.h +++ /dev/null @@ -1,104 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H -#define _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/set_difference.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/mergeable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/decay.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using set_difference_result = in_out_result<_InIter, _OutIter>; - -struct __set_difference { - template _Sent1, - input_iterator _InIter2, - sentinel_for<_InIter2> _Sent2, - weakly_incrementable _OutIter, - class _Comp = less, - class _Proj1 = identity, - class _Proj2 = identity> - requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_difference_result<_InIter1, _OutIter> operator()( - _InIter1 __first1, - _Sent1 __last1, - _InIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_difference( - __first1, __last1, __first2, __last2, __result, ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template - requires mergeable, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_difference_result, _OutIter> - operator()(_Range1&& __range1, - _Range2&& __range2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_difference( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __result, - ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto set_difference = __set_difference{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_intersection.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_intersection.h deleted file mode 100644 index 068794c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_intersection.h +++ /dev/null @@ -1,110 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H -#define _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H - -#include <__algorithm/in_in_out_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/set_intersection.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/mergeable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using set_intersection_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; - -struct __set_intersection { - template _Sent1, - input_iterator _InIter2, - sentinel_for<_InIter2> _Sent2, - weakly_incrementable _OutIter, - class _Comp = less, - class _Proj1 = identity, - class _Proj2 = identity> - requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_intersection_result<_InIter1, _InIter2, _OutIter> operator()( - _InIter1 __first1, - _Sent1 __last1, - _InIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_intersection<_RangeAlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)}; - } - - template - requires mergeable, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_intersection_result, - borrowed_iterator_t<_Range2>, - _OutIter> - operator()(_Range1&& __range1, - _Range2&& __range2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_intersection<_RangeAlgPolicy>( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - std::move(__result), - ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)}; - } -}; - -inline namespace __cpo { -inline constexpr auto set_intersection = __set_intersection{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_symmetric_difference.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_symmetric_difference.h deleted file mode 100644 index c0a8140..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_symmetric_difference.h +++ /dev/null @@ -1,109 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H -#define _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H - -#include <__algorithm/in_in_out_result.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/set_symmetric_difference.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/mergeable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using set_symmetric_difference_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; - -struct __set_symmetric_difference { - template _Sent1, - input_iterator _InIter2, - sentinel_for<_InIter2> _Sent2, - weakly_incrementable _OutIter, - class _Comp = ranges::less, - class _Proj1 = identity, - class _Proj2 = identity> - requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> operator()( - _InIter1 __first1, - _Sent1 __last1, - _InIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_symmetric_difference( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)}; - } - - template - requires mergeable, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_symmetric_difference_result, - borrowed_iterator_t<_Range2>, - _OutIter> - operator()(_Range1&& __range1, - _Range2&& __range2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_symmetric_difference( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - std::move(__result), - ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)}; - } -}; - -inline namespace __cpo { -inline constexpr auto set_symmetric_difference = __set_symmetric_difference{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_union.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_union.h deleted file mode 100644 index 039ffb5..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_set_union.h +++ /dev/null @@ -1,110 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SET_UNION_H -#define _LIBCPP___ALGORITHM_RANGES_SET_UNION_H - -#include <__algorithm/in_in_out_result.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/set_union.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/mergeable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using set_union_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; - -struct __set_union { - template _Sent1, - input_iterator _InIter2, - sentinel_for<_InIter2> _Sent2, - weakly_incrementable _OutIter, - class _Comp = ranges::less, - class _Proj1 = identity, - class _Proj2 = identity> - requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_union_result<_InIter1, _InIter2, _OutIter> operator()( - _InIter1 __first1, - _Sent1 __last1, - _InIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_union( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)}; - } - - template - requires mergeable, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2> - _LIBCPP_HIDE_FROM_ABI constexpr set_union_result, borrowed_iterator_t<_Range2>, _OutIter> - operator()(_Range1&& __range1, - _Range2&& __range2, - _OutIter __result, - _Comp __comp = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) const { - auto __ret = std::__set_union( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - std::move(__result), - ranges::__make_projected_comp(__comp, __proj1, __proj2)); - return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)}; - } -}; - -inline namespace __cpo { -inline constexpr auto set_union = __set_union{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SET_UNION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_left.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_left.h deleted file mode 100644 index 7d49482..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_left.h +++ /dev/null @@ -1,73 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SHIFT_LEFT_H -#define _LIBCPP___ALGORITHM_RANGES_SHIFT_LEFT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/shift_left.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/permutable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 23 - -namespace ranges { -namespace __shift_left { - -struct __fn { - template _Sent> - _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter> - operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __n) { - auto __ret = std::__shift_left<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__n)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template - requires permutable> - _LIBCPP_HIDE_FROM_ABI static constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, range_difference_t<_Range> __n) { - if constexpr (sized_range<_Range>) { - if (__n >= ranges::distance(__range)) { - return {ranges::begin(__range), ranges::begin(__range)}; - } - } - - auto __ret = std::__shift_left<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), std::move(__n)); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; -} // namespace __shift_left - -inline namespace __cpo { -inline constexpr auto shift_left = __shift_left::__fn{}; -} // namespace __cpo -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SHIFT_LEFT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_right.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_right.h deleted file mode 100644 index d3521b9..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_shift_right.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SHIFT_RIGHT_H -#define _LIBCPP___ALGORITHM_RANGES_SHIFT_RIGHT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/shift_right.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/distance.h> -#include <__iterator/incrementable_traits.h> -#include <__iterator/permutable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/subrange.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 23 - -namespace ranges { -namespace __shift_right { - -struct __fn { - template _Sent> - _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter> - operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __n) { - auto __ret = std::__shift_right<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__n)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template - requires permutable> - _LIBCPP_HIDE_FROM_ABI static constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, range_difference_t<_Range> __n) { - if constexpr (sized_range<_Range>) { - if (__n >= ranges::distance(__range)) { - auto __iter = ranges::begin(__range); - auto __end = ranges::end(__range); - ranges::advance(__iter, __end); - return {__iter, std::move(__iter)}; - } - } - - auto __ret = std::__shift_right<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), std::move(__n)); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; -} // namespace __shift_right - -inline namespace __cpo { -inline constexpr auto shift_right = __shift_right::__fn{}; -} // namespace __cpo -} // namespace ranges - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SHIFT_RIGHT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_shuffle.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_shuffle.h deleted file mode 100644 index 87cb368..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_shuffle.h +++ /dev/null @@ -1,68 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H -#define _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/shuffle.h> -#include <__algorithm/uniform_random_bit_generator_adaptor.h> -#include <__config> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/permutable.h> -#include <__random/uniform_random_bit_generator.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/remove_reference.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __shuffle { - template _Sent, class _Gen> - requires permutable<_Iter> && uniform_random_bit_generator> - _LIBCPP_HIDE_FROM_ABI _Iter operator()(_Iter __first, _Sent __last, _Gen&& __gen) const { - _ClassicGenAdaptor<_Gen> __adapted_gen(__gen); - return std::__shuffle<_RangeAlgPolicy>(std::move(__first), std::move(__last), __adapted_gen); - } - - template - requires permutable> && uniform_random_bit_generator> - _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_Range> operator()(_Range&& __range, _Gen&& __gen) const { - return (*this)(ranges::begin(__range), ranges::end(__range), std::forward<_Gen>(__gen)); - } -}; - -inline namespace __cpo { -inline constexpr auto shuffle = __shuffle{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_sort.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_sort.h deleted file mode 100644 index 2afad4c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_sort.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SORT_H -#define _LIBCPP___ALGORITHM_RANGES_SORT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/sort.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __sort { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - - auto&& __projected_comp = std::__make_projected(__comp, __proj); - std::__sort_impl<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp); - - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __sort_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - return __sort_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto sort = __sort{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_sort_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_sort_heap.h deleted file mode 100644 index d3e2087..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_sort_heap.h +++ /dev/null @@ -1,81 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H -#define _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/sort_heap.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __sort_heap { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __sort_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - - auto&& __projected_comp = std::__make_projected(__comp, __proj); - std::__sort_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp); - - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __sort_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - return __sort_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto sort_heap = __sort_heap{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_partition.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_partition.h deleted file mode 100644 index d8cfc8d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_partition.h +++ /dev/null @@ -1,89 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H -#define _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/ranges_iterator_concept.h> -#include <__algorithm/stable_partition.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/permutable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__ranges/subrange.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __stable_partition { - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX26 subrange<__remove_cvref_t<_Iter>> - __stable_partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { - auto __last_iter = ranges::next(__first, __last); - - auto&& __projected_pred = std::__make_projected(__pred, __proj); - auto __result = std::__stable_partition<_RangeAlgPolicy>( - std::move(__first), __last_iter, __projected_pred, __iterator_concept<_Iter>()); - - return {std::move(__result), std::move(__last_iter)}; - } - - template _Sent, - class _Proj = identity, - indirect_unary_predicate> _Pred> - requires permutable<_Iter> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 subrange<_Iter> - operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { - return __stable_partition_fn_impl(__first, __last, __pred, __proj); - } - - template , _Proj>> _Pred> - requires permutable> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_subrange_t<_Range> - operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return __stable_partition_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto stable_partition = __stable_partition{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_sort.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_sort.h deleted file mode 100644 index 6e17d0d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_stable_sort.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H -#define _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/stable_sort.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/projected.h> -#include <__iterator/sortable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __stable_sort { - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX26 _Iter - __stable_sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __last_iter = ranges::next(__first, __last); - - auto&& __projected_comp = std::__make_projected(__comp, __proj); - std::__stable_sort_impl<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp); - - return __last_iter; - } - - template _Sent, class _Comp = ranges::less, class _Proj = identity> - requires sortable<_Iter, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _Iter - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - return __stable_sort_fn_impl(std::move(__first), std::move(__last), __comp, __proj); - } - - template - requires sortable, _Comp, _Proj> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_iterator_t<_Range> - operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - return __stable_sort_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto stable_sort = __stable_sort{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_starts_with.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_starts_with.h deleted file mode 100644 index ae145d5..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_starts_with.h +++ /dev/null @@ -1,93 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_STARTS_WITH_H -#define _LIBCPP___ALGORITHM_RANGES_STARTS_WITH_H - -#include <__algorithm/in_in_result.h> -#include <__algorithm/ranges_mismatch.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/indirectly_comparable.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 23 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __starts_with { - template _Sent1, - input_iterator _Iter2, - sentinel_for<_Iter2> _Sent2, - class _Pred = ranges::equal_to, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr bool operator()( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred __pred = {}, - _Proj1 __proj1 = {}, - _Proj2 __proj2 = {}) { - return __mismatch::__go( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __proj1, - __proj2) - .in2 == __last2; - } - - template - requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr bool - operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) { - return __mismatch::__go( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - __pred, - __proj1, - __proj2) - .in2 == ranges::end(__range2); - } -}; -inline namespace __cpo { -inline constexpr auto starts_with = __starts_with{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_STARTS_WITH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_swap_ranges.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_swap_ranges.h deleted file mode 100644 index d24636b..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_swap_ranges.h +++ /dev/null @@ -1,95 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H -#define _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H - -#include <__algorithm/in_in_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> -#include <__algorithm/swap_ranges.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iter_swap.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__type_traits/is_same.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using swap_ranges_result = in_in_result<_I1, _I2>; - -struct __swap_ranges { - template _S1, input_iterator _I2, sentinel_for<_I2> _S2> - requires indirectly_swappable<_I1, _I2> - _LIBCPP_HIDE_FROM_ABI constexpr swap_ranges_result<_I1, _I2> - operator()(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2) const { - if constexpr (sized_sentinel_for<_I1, _S1> && sized_sentinel_for<_I2, _S2> && - (random_access_iterator<_I1> || random_access_iterator<_I2> || - (is_same_v<_I1, _S1> && is_same_v<_I2, _S2>))) { - auto __offset = std::min(__last1 - __first1, __last2 - __first2); - - auto __ret = [&] { - if constexpr (random_access_iterator<_I1>) - return std::__swap_ranges<_RangeAlgPolicy>(__first1, __first1 + __offset, std::move(__first2)); - else if constexpr (random_access_iterator<_I2>) - return std::__swap_ranges<_RangeAlgPolicy>(__first2, __first2 + __offset, std::move(__first1)); - else if (__last2 - __first2 < __last1 - __first1) { - auto __reversed = - std::__swap_ranges<_RangeAlgPolicy>(std::move(__first2), std::move(__last2), std::move(__first1)); - return std::pair<_I1, _I2>(std::move(__reversed.second), std::move(__reversed.first)); - } else - return std::__swap_ranges<_RangeAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)); - }(); - return {std::move(__ret.first), std::move(__ret.second)}; - } else { - while (__first1 != __last1 && __first2 != __last2) { - ranges::iter_swap(__first1, __first2); - ++__first1; - ++__first2; - } - - return {std::move(__first1), std::move(__first2)}; - } - } - - template - requires indirectly_swappable, iterator_t<_R2>> - _LIBCPP_HIDE_FROM_ABI constexpr swap_ranges_result, borrowed_iterator_t<_R2>> - operator()(_R1&& __r1, _R2&& __r2) const { - return operator()(ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2)); - } -}; - -inline namespace __cpo { -inline constexpr auto swap_ranges = __swap_ranges{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_transform.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_transform.h deleted file mode 100644 index 0913118..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_transform.h +++ /dev/null @@ -1,175 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H -#define _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H - -#include <__algorithm/in_in_out_result.h> -#include <__algorithm/in_out_result.h> -#include <__concepts/constructible.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using unary_transform_result = in_out_result<_Ip, _Op>; - -template -using binary_transform_result = in_in_out_result<_I1, _I2, _O1>; - -struct __transform { -private: - template - _LIBCPP_HIDE_FROM_ABI static constexpr unary_transform_result<_InIter, _OutIter> - __unary(_InIter __first, _Sent __last, _OutIter __result, _Func& __operation, _Proj& __projection) { - while (__first != __last) { - *__result = std::invoke(__operation, std::invoke(__projection, *__first)); - ++__first; - ++__result; - } - - return {std::move(__first), std::move(__result)}; - } - - template - _LIBCPP_HIDE_FROM_ABI static constexpr binary_transform_result<_InIter1, _InIter2, _OutIter> - __binary(_InIter1 __first1, - _Sent1 __last1, - _InIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Func& __binary_operation, - _Proj1& __projection1, - _Proj2& __projection2) { - while (__first1 != __last1 && __first2 != __last2) { - *__result = - std::invoke(__binary_operation, std::invoke(__projection1, *__first1), std::invoke(__projection2, *__first2)); - ++__first1; - ++__first2; - ++__result; - } - return {std::move(__first1), std::move(__first2), std::move(__result)}; - } - -public: - template _Sent, - weakly_incrementable _OutIter, - copy_constructible _Func, - class _Proj = identity> - requires indirectly_writable<_OutIter, indirect_result_t<_Func&, projected<_InIter, _Proj>>> - _LIBCPP_HIDE_FROM_ABI constexpr unary_transform_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result, _Func __operation, _Proj __proj = {}) const { - return __unary(std::move(__first), std::move(__last), std::move(__result), __operation, __proj); - } - - template - requires indirectly_writable<_OutIter, indirect_result_t<_Func, projected, _Proj>>> - _LIBCPP_HIDE_FROM_ABI constexpr unary_transform_result, _OutIter> - operator()(_Range&& __range, _OutIter __result, _Func __operation, _Proj __projection = {}) const { - return __unary(ranges::begin(__range), ranges::end(__range), std::move(__result), __operation, __projection); - } - - template _Sent1, - input_iterator _InIter2, - sentinel_for<_InIter2> _Sent2, - weakly_incrementable _OutIter, - copy_constructible _Func, - class _Proj1 = identity, - class _Proj2 = identity> - requires indirectly_writable<_OutIter, - indirect_result_t<_Func&, projected<_InIter1, _Proj1>, projected<_InIter2, _Proj2>>> - _LIBCPP_HIDE_FROM_ABI constexpr binary_transform_result<_InIter1, _InIter2, _OutIter> operator()( - _InIter1 __first1, - _Sent1 __last1, - _InIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Func __binary_operation, - _Proj1 __projection1 = {}, - _Proj2 __projection2 = {}) const { - return __binary( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __binary_operation, - __projection1, - __projection2); - } - - template - requires indirectly_writable< - _OutIter, - indirect_result_t<_Func&, projected, _Proj1>, projected, _Proj2>>> - _LIBCPP_HIDE_FROM_ABI constexpr binary_transform_result, - borrowed_iterator_t<_Range2>, - _OutIter> - operator()(_Range1&& __range1, - _Range2&& __range2, - _OutIter __result, - _Func __binary_operation, - _Proj1 __projection1 = {}, - _Proj2 __projection2 = {}) const { - return __binary( - ranges::begin(__range1), - ranges::end(__range1), - ranges::begin(__range2), - ranges::end(__range2), - std::move(__result), - __binary_operation, - __projection1, - __projection2); - } -}; - -inline namespace __cpo { -inline constexpr auto transform = __transform{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_unique.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_unique.h deleted file mode 100644 index a817359..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_unique.h +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_H -#define _LIBCPP___ALGORITHM_RANGES_UNIQUE_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/unique.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/permutable.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__ranges/subrange.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __unique { - template _Sent, - class _Proj = identity, - indirect_equivalence_relation> _Comp = ranges::equal_to> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> - operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = - std::__unique<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::__make_projected(__comp, __proj)); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template , _Proj>> _Comp = ranges::equal_to> - requires permutable> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> - operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__unique<_RangeAlgPolicy>( - ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj)); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto unique = __unique{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_unique_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_unique_copy.h deleted file mode 100644 index ee7f0a0..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_unique_copy.h +++ /dev/null @@ -1,116 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H -#define _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H - -#include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/make_projected.h> -#include <__algorithm/unique_copy.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { - -template -using unique_copy_result = in_out_result<_InIter, _OutIter>; - -template -concept __can_reread_from_output = (input_iterator<_OutIter> && same_as, iter_value_t<_OutIter>>); - -struct __unique_copy { - template - static consteval auto __get_algo_tag() { - if constexpr (forward_iterator<_InIter>) { - return __unique_copy_tags::__reread_from_input_tag{}; - } else if constexpr (__can_reread_from_output<_InIter, _OutIter>) { - return __unique_copy_tags::__reread_from_output_tag{}; - } else if constexpr (indirectly_copyable_storable<_InIter, _OutIter>) { - return __unique_copy_tags::__read_from_tmp_value_tag{}; - } - } - - template - using __algo_tag_t _LIBCPP_NODEBUG = decltype(__get_algo_tag<_InIter, _OutIter>()); - - template _Sent, - weakly_incrementable _OutIter, - class _Proj = identity, - indirect_equivalence_relation> _Comp = ranges::equal_to> - requires indirectly_copyable<_InIter, _OutIter> && - (forward_iterator<_InIter> || - (input_iterator<_OutIter> && same_as, iter_value_t<_OutIter>>) || - indirectly_copyable_storable<_InIter, _OutIter>) - _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<_InIter, _OutIter> - operator()(_InIter __first, _Sent __last, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__unique_copy<_RangeAlgPolicy>( - std::move(__first), - std::move(__last), - std::move(__result), - std::__make_projected(__comp, __proj), - __algo_tag_t<_InIter, _OutIter>()); - return {std::move(__ret.first), std::move(__ret.second)}; - } - - template , _Proj>> _Comp = ranges::equal_to> - requires indirectly_copyable, _OutIter> && - (forward_iterator> || - (input_iterator<_OutIter> && same_as, iter_value_t<_OutIter>>) || - indirectly_copyable_storable, _OutIter>) - _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result, _OutIter> - operator()(_Range&& __range, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const { - auto __ret = std::__unique_copy<_RangeAlgPolicy>( - ranges::begin(__range), - ranges::end(__range), - std::move(__result), - std::__make_projected(__comp, __proj), - __algo_tag_t, _OutIter>()); - return {std::move(__ret.first), std::move(__ret.second)}; - } -}; - -inline namespace __cpo { -inline constexpr auto unique_copy = __unique_copy{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/ranges_upper_bound.h b/third_party/libcxx/include/c++/v1/__algorithm/ranges_upper_bound.h deleted file mode 100644 index 4b2835d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/ranges_upper_bound.h +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_UPPER_BOUND_H -#define _LIBCPP___ALGORITHM_RANGES_UPPER_BOUND_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/lower_bound.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__functional/ranges_operations.h> -#include <__iterator/concepts.h> -#include <__iterator/projected.h> -#include <__ranges/access.h> -#include <__ranges/concepts.h> -#include <__ranges/dangling.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace ranges { -struct __upper_bound { - template _Sent, - class _Type, - class _Proj = identity, - indirect_strict_weak_order> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter - operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { - auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) -> bool { - return !std::invoke(__comp, __rhs, __lhs); - }; - - return std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp_lhs_rhs_swapped, __proj); - } - - template , _Proj>> _Comp = ranges::less> - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> - operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const { - auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) -> bool { - return !std::invoke(__comp, __rhs, __lhs); - }; - - return std::__lower_bound<_RangeAlgPolicy>( - ranges::begin(__r), ranges::end(__r), __value, __comp_lhs_rhs_swapped, __proj); - } -}; - -inline namespace __cpo { -inline constexpr auto upper_bound = __upper_bound{}; -} // namespace __cpo -} // namespace ranges - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_RANGES_UPPER_BOUND_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/remove.h b/third_party/libcxx/include/c++/v1/__algorithm/remove.h deleted file mode 100644 index b2d7023..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/remove.h +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REMOVE_H -#define _LIBCPP___ALGORITHM_REMOVE_H - -#include <__algorithm/find.h> -#include <__algorithm/find_if.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - __first = std::find(__first, __last, __value); - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) { - if (!(*__i == __value)) { - *__first = std::move(*__i); - ++__first; - } - } - } - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_REMOVE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/remove_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/remove_copy.h deleted file mode 100644 index 7be4c16..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/remove_copy.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REMOVE_COPY_H -#define _LIBCPP___ALGORITHM_REMOVE_COPY_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value) { - for (; __first != __last; ++__first) { - if (!(*__first == __value)) { - *__result = *__first; - ++__result; - } - } - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_REMOVE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/remove_copy_if.h b/third_party/libcxx/include/c++/v1/__algorithm/remove_copy_if.h deleted file mode 100644 index dcafed1..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/remove_copy_if.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REMOVE_COPY_IF_H -#define _LIBCPP___ALGORITHM_REMOVE_COPY_IF_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { - for (; __first != __last; ++__first) { - if (!__pred(*__first)) { - *__result = *__first; - ++__result; - } - } - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_REMOVE_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/remove_if.h b/third_party/libcxx/include/c++/v1/__algorithm/remove_if.h deleted file mode 100644 index 56fd745..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/remove_if.h +++ /dev/null @@ -1,45 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REMOVE_IF_H -#define _LIBCPP___ALGORITHM_REMOVE_IF_H - -#include <__algorithm/find_if.h> -#include <__config> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - __first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred); - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) { - if (!__pred(*__i)) { - *__first = std::move(*__i); - ++__first; - } - } - } - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_REMOVE_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/replace.h b/third_party/libcxx/include/c++/v1/__algorithm/replace.h deleted file mode 100644 index 8057c78..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/replace.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REPLACE_H -#define _LIBCPP___ALGORITHM_REPLACE_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) { - for (; __first != __last; ++__first) - if (*__first == __old_value) - *__first = __new_value; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_REPLACE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/replace_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/replace_copy.h deleted file mode 100644 index 9a2258d..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/replace_copy.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REPLACE_COPY_H -#define _LIBCPP___ALGORITHM_REPLACE_COPY_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy( - _InputIterator __first, - _InputIterator __last, - _OutputIterator __result, - const _Tp& __old_value, - const _Tp& __new_value) { - for (; __first != __last; ++__first, (void)++__result) - if (*__first == __old_value) - *__result = __new_value; - else - *__result = *__first; - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_REPLACE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/replace_copy_if.h b/third_party/libcxx/include/c++/v1/__algorithm/replace_copy_if.h deleted file mode 100644 index c2ed30f..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/replace_copy_if.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REPLACE_COPY_IF_H -#define _LIBCPP___ALGORITHM_REPLACE_COPY_IF_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy_if( - _InputIterator __first, - _InputIterator __last, - _OutputIterator __result, - _Predicate __pred, - const _Tp& __new_value) { - for (; __first != __last; ++__first, (void)++__result) - if (__pred(*__first)) - *__result = __new_value; - else - *__result = *__first; - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_REPLACE_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/replace_if.h b/third_party/libcxx/include/c++/v1/__algorithm/replace_if.h deleted file mode 100644 index 78487e3..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/replace_if.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REPLACE_IF_H -#define _LIBCPP___ALGORITHM_REPLACE_IF_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) { - for (; __first != __last; ++__first) - if (__pred(*__first)) - *__first = __new_value; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_REPLACE_IF_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/reverse.h b/third_party/libcxx/include/c++/v1/__algorithm/reverse.h deleted file mode 100644 index 4167c91..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/reverse.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REVERSE_H -#define _LIBCPP___ALGORITHM_REVERSE_H - -#include <__algorithm/iter_swap.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) { - while (__first != __last) { - if (__first == --__last) - break; - _IterOps<_AlgPolicy>::iter_swap(__first, __last); - ++__first; - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) { - if (__first != __last) - for (; __first < --__last; ++__first) - _IterOps<_AlgPolicy>::iter_swap(__first, __last); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reverse(_BidirectionalIterator __first, _Sentinel __last) { - using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>; - std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory()); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) { - std::__reverse<_ClassicAlgPolicy>(std::move(__first), std::move(__last)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_REVERSE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/reverse_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/reverse_copy.h deleted file mode 100644 index 0fcecc3..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/reverse_copy.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_REVERSE_COPY_H -#define _LIBCPP___ALGORITHM_REVERSE_COPY_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) { - for (; __first != __last; ++__result) - *__result = *--__last; - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_REVERSE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/rotate.h b/third_party/libcxx/include/c++/v1/__algorithm/rotate.h deleted file mode 100644 index b6d9eb3..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/rotate.h +++ /dev/null @@ -1,226 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_ROTATE_H -#define _LIBCPP___ALGORITHM_ROTATE_H - -#include <__algorithm/copy.h> -#include <__algorithm/copy_backward.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> -#include <__algorithm/move.h> -#include <__algorithm/move_backward.h> -#include <__algorithm/swap_ranges.h> -#include <__config> -#include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/is_trivially_assignable.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator -__rotate_left(_ForwardIterator __first, _ForwardIterator __last) { - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - using _Ops = _IterOps<_AlgPolicy>; - - value_type __tmp = _Ops::__iter_move(__first); - _ForwardIterator __lm1 = std::__move<_AlgPolicy>(_Ops::next(__first), __last, __first).second; - *__lm1 = std::move(__tmp); - return __lm1; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator -__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - using _Ops = _IterOps<_AlgPolicy>; - - _BidirectionalIterator __lm1 = _Ops::prev(__last); - value_type __tmp = _Ops::__iter_move(__lm1); - _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last)).second; - *__first = std::move(__tmp); - return __fp1; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _ForwardIterator -__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { - _ForwardIterator __i = __middle; - while (true) { - _IterOps<_AlgPolicy>::iter_swap(__first, __i); - ++__first; - if (++__i == __last) - break; - if (__first == __middle) - __middle = __i; - } - _ForwardIterator __r = __first; - if (__first != __middle) { - __i = __middle; - while (true) { - _IterOps<_AlgPolicy>::iter_swap(__first, __i); - ++__first; - if (++__i == __last) { - if (__first == __middle) - break; - __i = __middle; - } else if (__first == __middle) - __middle = __i; - } - } - return __r; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter -__rotate_random_access(_Iter __first, _Iter __middle, _Sent __sent) { - auto __left = _IterOps<_AlgPolicy>::distance(__first, __middle); - auto __right = _IterOps<_AlgPolicy>::distance(__middle, __sent); - auto __last = __first + __right; - - auto __min_len = std::min(__left, __right); - - while (__min_len > 0) { - if (__left <= __right) { - do { - std::__swap_ranges<_AlgPolicy>(__first, __first + __left, __first + __left); - __first += __left; - __right -= __left; - } while (__left <= __right); - __min_len = __right; - } else { - do { - std::__swap_ranges<_AlgPolicy>(__first + (__left - __right), __first + __left, __first + __left); - __left -= __right; - } while (__left > __right); - __min_len = __left; - } - } - return __last; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator -__rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, std::forward_iterator_tag) { - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - if (is_trivially_move_assignable::value) { - if (_IterOps<_AlgPolicy>::next(__first) == __middle) - return std::__rotate_left<_AlgPolicy>(__first, __last); - } - return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator __rotate_impl( - _BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - bidirectional_iterator_tag) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - if (is_trivially_move_assignable::value) { - if (_IterOps<_AlgPolicy>::next(__first) == __middle) - return std::__rotate_left<_AlgPolicy>(__first, __last); - if (_IterOps<_AlgPolicy>::next(__middle) == __last) - return std::__rotate_right<_AlgPolicy>(__first, __last); - } - return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __rotate_impl( - _RandomAccessIterator __first, - _RandomAccessIterator __middle, - _RandomAccessIterator __last, - random_access_iterator_tag) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - if (is_trivially_move_assignable::value) { - if (_IterOps<_AlgPolicy>::next(__first) == __middle) - return std::__rotate_left<_AlgPolicy>(__first, __last); - if (_IterOps<_AlgPolicy>::next(__middle) == __last) - return std::__rotate_right<_AlgPolicy>(__first, __last); - return std::__rotate_random_access<_AlgPolicy>(__first, __middle, __last); - } - return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iterator, _Iterator> -__rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) { - using _Ret = pair<_Iterator, _Iterator>; - _Iterator __last_iter = _IterOps<_AlgPolicy>::next(__middle, __last); - - if (__first == __middle) - return _Ret(__last_iter, __last_iter); - if (__middle == __last) - return _Ret(std::move(__first), std::move(__last_iter)); - - using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iterator>; - auto __result = std::__rotate_impl<_AlgPolicy>(std::move(__first), std::move(__middle), __last_iter, _IterCategory()); - - return _Ret(std::move(__result), std::move(__last_iter)); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, false>, __bit_iterator<_Cp, false> > -__rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) { - using _I1 = __bit_iterator<_Cp, false>; - using difference_type = typename _I1::difference_type; - difference_type __d1 = __middle - __first; - difference_type __d2 = __last - __middle; - _I1 __r = __first + __d2; - while (__d1 != 0 && __d2 != 0) { - if (__d1 <= __d2) { - if (__d1 <= __bit_array<_Cp>::capacity()) { - __bit_array<_Cp> __b(__d1); - std::copy(__first, __middle, __b.begin()); - std::copy(__b.begin(), __b.end(), std::copy(__middle, __last, __first)); - break; - } else { - __bit_iterator<_Cp, false> __mp = std::swap_ranges(__first, __middle, __middle); - __first = __middle; - __middle = __mp; - __d2 -= __d1; - } - } else { - if (__d2 <= __bit_array<_Cp>::capacity()) { - __bit_array<_Cp> __b(__d2); - std::copy(__middle, __last, __b.begin()); - std::copy_backward(__b.begin(), __b.end(), std::copy_backward(__first, __middle, __last)); - break; - } else { - __bit_iterator<_Cp, false> __mp = __first + __d2; - std::swap_ranges(__first, __mp, __middle); - __first = __mp; - __d1 -= __d2; - } - } - } - return std::make_pair(__r, __last); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { - return std::__rotate<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last)).first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_ROTATE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/rotate_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/rotate_copy.h deleted file mode 100644 index cddcadd..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/rotate_copy.h +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_ROTATE_COPY_H -#define _LIBCPP___ALGORITHM_ROTATE_COPY_H - -#include <__algorithm/copy.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) { - return std::copy(__first, __middle, std::copy(__middle, __last, __result)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_ROTATE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/sample.h b/third_party/libcxx/include/c++/v1/__algorithm/sample.h deleted file mode 100644 index ebe5180..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/sample.h +++ /dev/null @@ -1,123 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SAMPLE_H -#define _LIBCPP___ALGORITHM_SAMPLE_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min.h> -#include <__assert> -#include <__config> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__random/uniform_int_distribution.h> -#include <__type_traits/common_type.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _SampleIterator __sample( - _PopulationIterator __first, - _PopulationSentinel __last, - _SampleIterator __output_iter, - _Distance __n, - _UniformRandomNumberGenerator& __g, - input_iterator_tag) { - _Distance __k = 0; - for (; __first != __last && __k < __n; ++__first, (void)++__k) - __output_iter[__k] = *__first; - _Distance __sz = __k; - for (; __first != __last; ++__first, (void)++__k) { - _Distance __r = uniform_int_distribution<_Distance>(0, __k)(__g); - if (__r < __sz) - __output_iter[__r] = *__first; - } - return __output_iter + std::min(__n, __k); -} - -template -_LIBCPP_HIDE_FROM_ABI _SampleIterator __sample( - _PopulationIterator __first, - _PopulationSentinel __last, - _SampleIterator __output_iter, - _Distance __n, - _UniformRandomNumberGenerator& __g, - forward_iterator_tag) { - _Distance __unsampled_sz = _IterOps<_AlgPolicy>::distance(__first, __last); - for (__n = std::min(__n, __unsampled_sz); __n != 0; ++__first) { - _Distance __r = uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); - if (__r < __n) { - *__output_iter++ = *__first; - --__n; - } - } - return __output_iter; -} - -template -_LIBCPP_HIDE_FROM_ABI _SampleIterator __sample( - _PopulationIterator __first, - _PopulationSentinel __last, - _SampleIterator __output_iter, - _Distance __n, - _UniformRandomNumberGenerator& __g) { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n >= 0, "N must be a positive number."); - - using _PopIterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_PopulationIterator>; - using _Difference = typename _IterOps<_AlgPolicy>::template __difference_type<_PopulationIterator>; - using _CommonType = typename common_type<_Distance, _Difference>::type; - - return std::__sample<_AlgPolicy>( - std::move(__first), std::move(__last), std::move(__output_iter), _CommonType(__n), __g, _PopIterCategory()); -} - -#if _LIBCPP_STD_VER >= 17 -template -inline _LIBCPP_HIDE_FROM_ABI _SampleIterator -sample(_PopulationIterator __first, - _PopulationIterator __last, - _SampleIterator __output_iter, - _Distance __n, - _UniformRandomNumberGenerator&& __g) { - static_assert(__has_forward_iterator_category<_PopulationIterator>::value || - __has_random_access_iterator_category<_SampleIterator>::value, - "SampleIterator must meet the requirements of RandomAccessIterator"); - - return std::__sample<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__output_iter), __n, __g); -} - -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SAMPLE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/search.h b/third_party/libcxx/include/c++/v1/__algorithm/search.h deleted file mode 100644 index 161fd39..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/search.h +++ /dev/null @@ -1,192 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SEARCH_H -#define _LIBCPP___ALGORITHM_SEARCH_H - -#include <__algorithm/comp.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/advance.h> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_forward_impl( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - if (__first2 == __last2) - return std::make_pair(__first1, __first1); // Everything matches an empty sequence - while (true) { - // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks - while (true) { - if (__first1 == __last1) { // return __last1 if no element matches *__first2 - _IterOps<_AlgPolicy>::__advance_to(__first1, __last1); - return std::make_pair(__first1, __first1); - } - if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - } - // *__first1 matches *__first2, now match elements after here - _Iter1 __m1 = __first1; - _Iter2 __m2 = __first2; - while (true) { - if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) - return std::make_pair(__first1, ++__m1); - if (++__m1 == __last1) { // Otherwise if source exhaused, pattern not found - return std::make_pair(__m1, __m1); - } - - // if there is a mismatch, restart with a new __first1 - if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) { - ++__first1; - break; - } // else there is a match, check next elements - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_random_access_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - _DiffT1 __size1, - _DiffT2 __size2) { - const _Iter1 __s = __first1 + __size1 - _DiffT1(__size2 - 1); // Start of pattern match can't go beyond here - - while (true) { - while (true) { - if (__first1 == __s) { - _IterOps<_AlgPolicy>::__advance_to(__first1, __last1); - return std::make_pair(__first1, __first1); - } - if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - } - - _Iter1 __m1 = __first1; - _Iter2 __m2 = __first2; - while (true) { - if (++__m2 == __last2) - return std::make_pair(__first1, __first1 + _DiffT1(__size2)); - ++__m1; // no need to check range on __m1 because __s guarantees we have enough source - if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) { - ++__first1; - break; - } - } - } -} - -template ::value && - __has_random_access_iterator_category<_Iter2>::value, - int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - auto __size2 = __last2 - __first2; - if (__size2 == 0) - return std::make_pair(__first1, __first1); - - auto __size1 = __last1 - __first1; - if (__size1 < __size2) { - return std::make_pair(__last1, __last1); - } - - return std::__search_random_access_impl<_ClassicAlgPolicy>( - __first1, __last1, __first2, __last2, __pred, __proj1, __proj2, __size1, __size2); -} - -template < - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Pred, - class _Proj1, - class _Proj2, - __enable_if_t<__has_forward_iterator_category<_Iter1>::value && __has_forward_iterator_category<_Iter2>::value && - !(__has_random_access_iterator_category<_Iter1>::value && - __has_random_access_iterator_category<_Iter2>::value), - int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 -search(_ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value, - "The comparator has to be callable"); - auto __proj = __identity(); - return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 -search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::search(__first1, __last1, __first2, __last2, __equal_to()); -} - -#if _LIBCPP_STD_VER >= 17 -template -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher& __s) { - return __s(__f, __l).first; -} - -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_SEARCH_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/search_n.h b/third_party/libcxx/include/c++/v1/__algorithm/search_n.h deleted file mode 100644 index 0962542..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/search_n.h +++ /dev/null @@ -1,168 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SEARCH_N_H -#define _LIBCPP___ALGORITHM_SEARCH_N_H - -#include <__algorithm/comp.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__utility/convert_to_integral.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __search_n_forward_impl( - _Iter __first, _Sent __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { - if (__count <= 0) - return std::make_pair(__first, __first); - while (true) { - // Find first element in sequence that matchs __value, with a mininum of loop checks - while (true) { - if (__first == __last) { // return __last if no element matches __value - _IterOps<_AlgPolicy>::__advance_to(__first, __last); - return std::make_pair(__first, __first); - } - if (std::__invoke(__pred, std::__invoke(__proj, *__first), __value)) - break; - ++__first; - } - // *__first matches __value, now match elements after here - _Iter __m = __first; - _SizeT __c(0); - while (true) { - if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) - return std::make_pair(__first, ++__m); - if (++__m == __last) { // Otherwise if source exhaused, pattern not found - _IterOps<_AlgPolicy>::__advance_to(__first, __last); - return std::make_pair(__first, __first); - } - - // if there is a mismatch, restart with a new __first - if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) { - __first = __m; - ++__first; - break; - } // else there is a match, check next elements - } - } -} - -// Finds the longest suffix in [__first, __last) where each element satisfies __pred. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RAIter -__find_longest_suffix(_RAIter __first, _RAIter __last, const _ValueT& __value, _Pred& __pred, _Proj& __proj) { - while (__first != __last) { - if (!std::__invoke(__pred, std::__invoke(__proj, *--__last), __value)) { - return ++__last; - } - } - return __first; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 std::pair<_Iter, _Iter> __search_n_random_access_impl( - _Iter __first, _SizeT __count_in, const _Type& __value, _Pred& __pred, _Proj& __proj, _DiffT __size) { - auto __last = __first + __size; - auto __count = static_cast<_DiffT>(__count_in); - - if (__count == 0) - return std::make_pair(__first, __first); - if (__size < __count) - return std::make_pair(__last, __last); - - // [__match_start, __match_start + __count) is the subrange which we currently check whether it only contains matching - // elements. This subrange is returned in case all the elements match. - // [__match_start, __matched_until) is the longest subrange where all elements are known to match at any given point - // in time. - // [__matched_until, __match_start + __count) is the subrange where we don't know whether the elements match. - - // This algorithm tries to expand the subrange [__match_start, __matched_until) into a range of sufficient length. - // When we fail to do that because we find a mismatching element, we move it forward to the beginning of the next - // consecutive sequence that is not known not to match. - - const _Iter __try_match_until = __last - __count; - _Iter __match_start = __first; - _Iter __matched_until = __first; - - while (true) { - // There's no chance of expanding the subrange into a sequence of sufficient length, since we don't have enough - // elements in the haystack anymore. - if (__match_start > __try_match_until) - return std::make_pair(__last, __last); - - auto __mismatch = std::__find_longest_suffix(__matched_until, __match_start + __count, __value, __pred, __proj); - - // If all elements in [__matched_until, __match_start + __count) match, we know that - // [__match_start, __match_start + __count) is a full sequence of matching elements, so we're done. - if (__mismatch == __matched_until) - return std::make_pair(__match_start, __match_start + __count); - - // Otherwise, we have to move the [__match_start, __matched_until) subrange forward past the point where we know for - // sure a match is impossible. - __matched_until = __match_start + __count; - __match_start = __mismatch; - } -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> -__search_n_impl(_Iter __first, _Sent __last, _DiffT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { - return std::__search_n_random_access_impl<_ClassicAlgPolicy>( - __first, __count, __value, __pred, __proj, __last - __first); -} - -template ::value && - !__has_random_access_iterator_category<_Iter1>::value, - int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> -__search_n_impl(_Iter1 __first, _Sent1 __last, _DiffT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { - return std::__search_n_forward_impl<_ClassicAlgPolicy>(__first, __last, __count, __value, __pred, __proj); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n( - _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) { - static_assert( - __is_callable<_BinaryPredicate&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); - auto __proj = __identity(); - return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) { - return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_SEARCH_N_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/set_difference.h b/third_party/libcxx/include/c++/v1/__algorithm/set_difference.h deleted file mode 100644 index 0cd1bc4..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/set_difference.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SET_DIFFERENCE_H -#define _LIBCPP___ALGORITHM_SET_DIFFERENCE_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/copy.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__remove_cvref_t<_InIter1>, __remove_cvref_t<_OutIter> > -__set_difference( - _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) { - while (__first1 != __last1 && __first2 != __last2) { - if (__comp(*__first1, *__first2)) { - *__result = *__first1; - ++__first1; - ++__result; - } else if (__comp(*__first2, *__first1)) { - ++__first2; - } else { - ++__first1; - ++__first2; - } - } - return std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_difference<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::__set_difference(__first1, __last1, __first2, __last2, __result, __less<>()).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SET_DIFFERENCE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/set_intersection.h b/third_party/libcxx/include/c++/v1/__algorithm/set_intersection.h deleted file mode 100644 index 6246e24..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/set_intersection.h +++ /dev/null @@ -1,218 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SET_INTERSECTION_H -#define _LIBCPP___ALGORITHM_SET_INTERSECTION_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/lower_bound.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__type_traits/is_same.h> -#include <__utility/exchange.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/swap.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __set_intersection_result { - _InIter1 __in1_; - _InIter2 __in2_; - _OutIter __out_; - - // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - __set_intersection_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) - : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} -}; - -// Helper for __set_intersection() with one-sided binary search: populate result and advance input iterators if they -// are found to potentially contain the same value in two consecutive calls. This function is very intimately related to -// the way it is used and doesn't attempt to abstract that, it's not appropriate for general usage outside of its -// context. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_intersection_add_output_if_equal( - bool __may_be_equal, - _InForwardIter1& __first1, - _InForwardIter2& __first2, - _OutIter& __result, - bool& __prev_may_be_equal) { - if (__may_be_equal && __prev_may_be_equal) { - *__result = *__first1; - ++__result; - ++__first1; - ++__first2; - __prev_may_be_equal = false; - } else { - __prev_may_be_equal = __may_be_equal; - } -} - -// With forward iterators we can make multiple passes over the data, allowing the use of one-sided binary search to -// reduce best-case complexity to log(N). Understanding how we can use binary search and still respect complexity -// guarantees is _not_ straightforward: the guarantee is "at most 2*(N+M)-1 comparisons", and one-sided binary search -// will necessarily overshoot depending on the position of the needle in the haystack -- for instance, if we're -// searching for 3 in (1, 2, 3, 4), we'll check if 3<1, then 3<2, then 3<4, and, finally, 3<3, for a total of 4 -// comparisons, when linear search would have yielded 3. However, because we won't need to perform the intervening -// reciprocal comparisons (ie 1<3, 2<3, 4<3), that extra comparison doesn't run afoul of the guarantee. Additionally, -// this type of scenario can only happen for match distances of up to 5 elements, because 2*log2(8) is 6, and we'll -// still be worse-off at position 5 of an 8-element set. From then onwards these scenarios can't happen. TL;DR: we'll be -// 1 comparison worse-off compared to the classic linear-searching algorithm if matching position 3 of a set with 4 -// elements, or position 5 if the set has 7 or 8 elements, but we'll never exceed the complexity guarantees from the -// standard. -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InForwardIter1, _InForwardIter2, _OutIter> -__set_intersection( - _InForwardIter1 __first1, - _Sent1 __last1, - _InForwardIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Compare&& __comp, - std::forward_iterator_tag, - std::forward_iterator_tag) { - _LIBCPP_CONSTEXPR std::__identity __proj; - bool __prev_may_be_equal = false; - - while (__first2 != __last2) { - _InForwardIter1 __first1_next = - std::__lower_bound_onesided<_AlgPolicy>(__first1, __last1, *__first2, __comp, __proj); - std::swap(__first1_next, __first1); - // keeping in mind that a==b iff !(a(__first2, __last2, *__first1, __comp, __proj); - std::swap(__first2_next, __first2); - std::__set_intersection_add_output_if_equal( - __first2 == __first2_next, __first1, __first2, __result, __prev_may_be_equal); - } - return __set_intersection_result<_InForwardIter1, _InForwardIter2, _OutIter>( - _IterOps<_AlgPolicy>::next(std::move(__first1), std::move(__last1)), - _IterOps<_AlgPolicy>::next(std::move(__first2), std::move(__last2)), - std::move(__result)); -} - -// input iterators are not suitable for multipass algorithms, so we stick to the classic single-pass version -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InInputIter1, _InInputIter2, _OutIter> -__set_intersection( - _InInputIter1 __first1, - _Sent1 __last1, - _InInputIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Compare&& __comp, - std::input_iterator_tag, - std::input_iterator_tag) { - while (__first1 != __last1 && __first2 != __last2) { - if (__comp(*__first1, *__first2)) - ++__first1; - else { - if (!__comp(*__first2, *__first1)) { - *__result = *__first1; - ++__result; - ++__first1; - } - ++__first2; - } - } - - return __set_intersection_result<_InInputIter1, _InInputIter2, _OutIter>( - _IterOps<_AlgPolicy>::next(std::move(__first1), std::move(__last1)), - _IterOps<_AlgPolicy>::next(std::move(__first2), std::move(__last2)), - std::move(__result)); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InIter1, _InIter2, _OutIter> -__set_intersection( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { - return std::__set_intersection<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - std::forward<_Compare>(__comp), - typename std::_IterOps<_AlgPolicy>::template __iterator_category<_InIter1>(), - typename std::_IterOps<_AlgPolicy>::template __iterator_category<_InIter2>()); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_intersection( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_intersection<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __comp) - .__out_; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_intersection( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::__set_intersection<_ClassicAlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __less<>()) - .__out_; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SET_INTERSECTION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/set_symmetric_difference.h b/third_party/libcxx/include/c++/v1/__algorithm/set_symmetric_difference.h deleted file mode 100644 index 91ea406..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/set_symmetric_difference.h +++ /dev/null @@ -1,108 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H -#define _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/copy.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __set_symmetric_difference_result { - _InIter1 __in1_; - _InIter2 __in2_; - _OutIter __out_; - - // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - __set_symmetric_difference_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) - : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} -}; - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> -__set_symmetric_difference( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { - while (__first1 != __last1) { - if (__first2 == __last2) { - auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); - return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( - std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); - } - if (__comp(*__first1, *__first2)) { - *__result = *__first1; - ++__result; - ++__first1; - } else { - if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__result; - } else { - ++__first1; - } - ++__first2; - } - } - auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result)); - return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( - std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetric_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_symmetric_difference<__comp_ref_type<_Compare> >( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __comp) - .__out_; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetric_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::set_symmetric_difference( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/set_union.h b/third_party/libcxx/include/c++/v1/__algorithm/set_union.h deleted file mode 100644 index 393dddc..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/set_union.h +++ /dev/null @@ -1,104 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SET_UNION_H -#define _LIBCPP___ALGORITHM_SET_UNION_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/copy.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __set_union_result { - _InIter1 __in1_; - _InIter2 __in2_; - _OutIter __out_; - - // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - __set_union_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) - : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} -}; - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) { - auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); - return __set_union_result<_InIter1, _InIter2, _OutIter>( - std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); - } - if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__first2; - } else { - if (!__comp(*__first1, *__first2)) { - ++__first2; - } - *__result = *__first1; - ++__first1; - } - } - auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result)); - return __set_union_result<_InIter1, _InIter2, _OutIter>( - std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_union<__comp_ref_type<_Compare> >( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __comp) - .__out_; -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::set_union( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SET_UNION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/shift_left.h b/third_party/libcxx/include/c++/v1/__algorithm/shift_left.h deleted file mode 100644 index 42d6c23..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/shift_left.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SHIFT_LEFT_H -#define _LIBCPP___ALGORITHM_SHIFT_LEFT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/move.h> -#include <__assert> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter, _Iter> -__shift_left(_Iter __first, _Sent __last, typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __n) { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n >= 0, "n must be greater than or equal to 0"); - - if (__n == 0) { - _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); - return {std::move(__first), std::move(__end)}; - } - - _Iter __m = __first; - if constexpr (sized_sentinel_for<_Sent, _Iter>) { - auto __size = _IterOps<_AlgPolicy>::distance(__first, __last); - if (__n >= __size) { - return {__first, std::move(__first)}; - } - _IterOps<_AlgPolicy>::advance(__m, __n); - } else { - for (; __n > 0; --__n) { - if (__m == __last) { - return {__first, std::move(__first)}; - } - ++__m; - } - } - - _Iter __result = std::__move<_AlgPolicy>(__m, __last, __first).second; - return {std::move(__first), std::move(__result)}; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator -shift_left(_ForwardIterator __first, - _ForwardIterator __last, - typename iterator_traits<_ForwardIterator>::difference_type __n) { - return std::__shift_left<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __n).second; -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SHIFT_LEFT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/shift_right.h b/third_party/libcxx/include/c++/v1/__algorithm/shift_right.h deleted file mode 100644 index 917e255..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/shift_right.h +++ /dev/null @@ -1,131 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SHIFT_RIGHT_H -#define _LIBCPP___ALGORITHM_SHIFT_RIGHT_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/move.h> -#include <__algorithm/move_backward.h> -#include <__algorithm/swap_ranges.h> -#include <__assert> -#include <__concepts/derived_from.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> -#include <__utility/pair.h> -#include <__utility/swap.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter, _Iter> -__shift_right(_Iter __first, _Sent __last, typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __n) { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n >= 0, "Providing a negative shift amount to shift_right is UB"); - if (__n == 0) { - _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); - return pair<_Iter, _Iter>(std::move(__first), std::move(__end)); - } - - using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iter>; - - if constexpr (derived_from<_IterCategory, random_access_iterator_tag>) { - _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); - auto __size = __end - __first; - if (__n >= __size) { - return pair<_Iter, _Iter>(__end, std::move(__end)); - } - _Iter __m = __first; - _IterOps<_AlgPolicy>::advance(__m, (__size - __n)); - auto __ret = std::__move_backward<_AlgPolicy>(std::move(__first), std::move(__m), __end); - return pair<_Iter, _Iter>(std::move(__ret.second), std::move(__end)); - } else if constexpr (derived_from<_IterCategory, bidirectional_iterator_tag>) { - _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); - if constexpr (sized_sentinel_for<_Sent, _Iter>) { - if (__n >= ranges::distance(__first, __last)) { - return pair<_Iter, _Iter>(__end, std::move(__end)); - } - } - _Iter __m = __end; - for (; __n > 0; --__n) { - if (__m == __first) { - return pair<_Iter, _Iter>(__end, std::move(__end)); - } - --__m; - } - auto __ret = std::__move_backward<_AlgPolicy>(std::move(__first), std::move(__m), __end); - return pair<_Iter, _Iter>(std::move(__ret.second), std::move(__end)); - } else { - _Iter __ret = __first; - for (; __n > 0; --__n) { - if (__ret == __last) { - return pair<_Iter, _Iter>(__ret, std::move(__ret)); - } - ++__ret; - } - - // We have an __n-element scratch space from __first to __ret. - // Slide an __n-element window [__trail, __lead) from left to right. - // We're essentially doing swap_ranges(__first, __ret, __trail, __lead) - // over and over; but once __lead reaches __end we needn't bother - // to save the values of elements [__trail, __end). - - auto __trail = __first; - auto __lead = __ret; - while (__trail != __ret) { - if (__lead == __last) { - std::__move<_AlgPolicy>(std::move(__first), std::move(__trail), __ret); - return pair<_Iter, _Iter>(__ret, std::move(__lead)); - } - ++__trail; - ++__lead; - } - - _Iter __mid = __first; - while (true) { - if (__lead == __last) { - __trail = std::__move<_AlgPolicy>(__mid, __ret, __trail).second; - std::__move<_AlgPolicy>(std::move(__first), std::move(__mid), std::move(__trail)); - return pair<_Iter, _Iter>(__ret, std::move(__lead)); - } - _IterOps<_AlgPolicy>::iter_swap(__mid, __trail); - ++__mid; - ++__trail; - ++__lead; - if (__mid == __ret) { - __mid = __first; - } - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator -shift_right(_ForwardIterator __first, - _ForwardIterator __last, - typename iterator_traits<_ForwardIterator>::difference_type __n) { - return std::__shift_right<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __n).first; -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SHIFT_RIGHT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/shuffle.h b/third_party/libcxx/include/c++/v1/__algorithm/shuffle.h deleted file mode 100644 index 7177fbb..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/shuffle.h +++ /dev/null @@ -1,167 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SHUFFLE_H -#define _LIBCPP___ALGORITHM_SHUFFLE_H - -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__iterator/iterator_traits.h> -#include <__random/uniform_int_distribution.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/swap.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -class _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_randomizer { -public: - _LIBCPP_HIDE_FROM_ABI __libcpp_debug_randomizer() { - __state_ = __seed(); - __inc_ = __state_ + 0xda3e39cb94b95bdbULL; - __inc_ = (__inc_ << 1) | 1; - } - typedef uint_fast32_t result_type; - - static const result_type _Min = 0; - static const result_type _Max = 0xFFFFFFFF; - - _LIBCPP_HIDE_FROM_ABI result_type operator()() { - uint_fast64_t __oldstate = __state_; - __state_ = __oldstate * 6364136223846793005ULL + __inc_; - return __oldstate >> 32; - } - - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() { return _Min; } - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() { return _Max; } - -private: - uint_fast64_t __state_; - uint_fast64_t __inc_; - _LIBCPP_HIDE_FROM_ABI static uint_fast64_t __seed() { -#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED - return _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED; -#else - static char __x; - return reinterpret_cast(&__x); -#endif - } -}; - -#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) || defined(_LIBCPP_BUILDING_LIBRARY) -class _LIBCPP_EXPORTED_FROM_ABI __rs_default; - -_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); - -class _LIBCPP_EXPORTED_FROM_ABI __rs_default { - static unsigned __c_; - - __rs_default(); - -public: - typedef uint_fast32_t result_type; - - static const result_type _Min = 0; - static const result_type _Max = 0xFFFFFFFF; - - __rs_default(const __rs_default&); - ~__rs_default(); - - result_type operator()(); - - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() { return _Min; } - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() { return _Max; } - - friend _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); -}; - -_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void -random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef uniform_int_distribution _Dp; - typedef typename _Dp::param_type _Pp; - difference_type __d = __last - __first; - if (__d > 1) { - _Dp __uid; - __rs_default __g = __rs_get(); - for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) { - difference_type __i = __uid(__g, _Pp(0, __d)); - if (__i != difference_type(0)) - swap(*__first, *(__first + __i)); - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void -random_shuffle(_RandomAccessIterator __first, - _RandomAccessIterator __last, -# ifndef _LIBCPP_CXX03_LANG - _RandomNumberGenerator&& __rand) -# else - _RandomNumberGenerator& __rand) -# endif -{ - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __d = __last - __first; - if (__d > 1) { - for (--__last; __first < __last; ++__first, (void)--__d) { - difference_type __i = __rand(__d); - if (__i != difference_type(0)) - swap(*__first, *(__first + __i)); - } - } -} -#endif - -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -__shuffle(_RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef uniform_int_distribution _Dp; - typedef typename _Dp::param_type _Pp; - - auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel); - auto __last = __original_last; - difference_type __d = __last - __first; - if (__d > 1) { - _Dp __uid; - for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) { - difference_type __i = __uid(__g, _Pp(0, __d)); - if (__i != difference_type(0)) - _IterOps<_AlgPolicy>::iter_swap(__first, __first + __i); - } - } - - return __original_last; -} - -template -_LIBCPP_HIDE_FROM_ABI void -shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _UniformRandomNumberGenerator&& __g) { - (void)std::__shuffle<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), std::forward<_UniformRandomNumberGenerator>(__g)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SHUFFLE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/sift_down.h b/third_party/libcxx/include/c++/v1/__algorithm/sift_down.h deleted file mode 100644 index f827754..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/sift_down.h +++ /dev/null @@ -1,119 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SIFT_DOWN_H -#define _LIBCPP___ALGORITHM_SIFT_DOWN_H - -#include <__algorithm/iterator_operations.h> -#include <__assert> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__sift_down(_RandomAccessIterator __first, - _Compare&& __comp, - __iterator_difference_type<_RandomAccessIterator> __len, - __iterator_difference_type<_RandomAccessIterator> __start) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - // left-child of __start is at 2 * __start + 1 - // right-child of __start is at 2 * __start + 2 - difference_type __child = __start; - - if (__len < 2 || (__len - 2) / 2 < __child) - return; - - __child = 2 * __child + 1; - - if _LIBCPP_CONSTEXPR (__assume_both_children) { - // right-child exists and is greater than left-child - __child += __comp(__first[__child], __first[__child + 1]); - } else if ((__child + 1) < __len && __comp(__first[__child], __first[__child + 1])) { - // right-child exists and is greater than left-child - ++__child; - } - - // check if we are in heap-order - if (__comp(__first[__child], __first[__start])) - // we are, __start is larger than its largest child - return; - - value_type __top(_Ops::__iter_move(__first + __start)); - do { - // we are not in heap-order, swap the parent with its largest child - __first[__start] = _Ops::__iter_move(__first + __child); - __start = __child; - - if ((__len - 2) / 2 < __child) - break; - - // recompute the child based off of the updated parent - __child = 2 * __child + 1; - - if _LIBCPP_CONSTEXPR (__assume_both_children) { - __child += __comp(__first[__child], __first[__child + 1]); - } else if ((__child + 1) < __len && __comp(__first[__child], __first[__child + 1])) { - // right-child exists and is greater than left-child - ++__child; - } - - // check if we are in heap-order - } while (!__comp(__first[__child], __top)); - __first[__start] = std::move(__top); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __floyd_sift_down( - _RandomAccessIterator __first, - _Compare&& __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len) { - using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; - _LIBCPP_ASSERT_INTERNAL(__len >= 2, "shouldn't be called unless __len >= 2"); - - _RandomAccessIterator __hole = __first; - _RandomAccessIterator __child_i = __first; - difference_type __child = 0; - - while (true) { - __child_i += difference_type(__child + 1); - __child = 2 * __child + 1; - - if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) { - // right-child exists and is greater than left-child - ++__child_i; - ++__child; - } - - // swap __hole with its largest child - *__hole = _IterOps<_AlgPolicy>::__iter_move(__child_i); - __hole = __child_i; - - // if __hole is now a leaf, we're done - if (__child > (__len - 2) / 2) - return __hole; - } -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SIFT_DOWN_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/simd_utils.h b/third_party/libcxx/include/c++/v1/__algorithm/simd_utils.h deleted file mode 100644 index f73c9ea..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/simd_utils.h +++ /dev/null @@ -1,193 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SIMD_UTILS_H -#define _LIBCPP___ALGORITHM_SIMD_UTILS_H - -#include <__algorithm/min.h> -#include <__bit/bit_cast.h> -#include <__bit/countl.h> -#include <__bit/countr.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__utility/integer_sequence.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -// TODO: Find out how altivec changes things and allow vectorizations there too. -#if _LIBCPP_STD_VER >= 14 && defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(__ALTIVEC__) -# define _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS 1 -#else -# define _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS 0 -#endif - -#if _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS && !defined(__OPTIMIZE_SIZE__) -# define _LIBCPP_VECTORIZE_ALGORITHMS 1 -#else -# define _LIBCPP_VECTORIZE_ALGORITHMS 0 -#endif - -#if _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline constexpr bool __can_map_to_integer_v = - sizeof(_Tp) == alignof(_Tp) && (sizeof(_Tp) == 1 || sizeof(_Tp) == 2 || sizeof(_Tp) == 4 || sizeof(_Tp) == 8); - -template -struct __get_as_integer_type_impl; - -template <> -struct __get_as_integer_type_impl<1> { - using type _LIBCPP_NODEBUG = uint8_t; -}; - -template <> -struct __get_as_integer_type_impl<2> { - using type _LIBCPP_NODEBUG = uint16_t; -}; -template <> -struct __get_as_integer_type_impl<4> { - using type _LIBCPP_NODEBUG = uint32_t; -}; -template <> -struct __get_as_integer_type_impl<8> { - using type _LIBCPP_NODEBUG = uint64_t; -}; - -template -using __get_as_integer_type_t _LIBCPP_NODEBUG = typename __get_as_integer_type_impl::type; - -// This isn't specialized for 64 byte vectors on purpose. They have the potential to significantly reduce performance -// in mixed simd/non-simd workloads and don't provide any performance improvement for currently vectorized algorithms -// as far as benchmarks are concerned. -# if defined(__AVX__) || defined(__MVS__) -template -inline constexpr size_t __native_vector_size = 32 / sizeof(_Tp); -# elif defined(__SSE__) || defined(__ARM_NEON) -template -inline constexpr size_t __native_vector_size = 16 / sizeof(_Tp); -# elif defined(__MMX__) -template -inline constexpr size_t __native_vector_size = 8 / sizeof(_Tp); -# else -template -inline constexpr size_t __native_vector_size = 1; -# endif - -template -using __simd_vector __attribute__((__ext_vector_type__(_Np))) _LIBCPP_NODEBUG = _ArithmeticT; - -template -inline constexpr size_t __simd_vector_size_v = []() -> size_t { - static_assert(_False, "Not a vector!"); -}(); - -template -inline constexpr size_t __simd_vector_size_v<__simd_vector<_Tp, _Np>> = _Np; - -template -_LIBCPP_HIDE_FROM_ABI _Tp __simd_vector_underlying_type_impl(__simd_vector<_Tp, _Np>) { - return _Tp{}; -} - -template -using __simd_vector_underlying_type_t _LIBCPP_NODEBUG = decltype(std::__simd_vector_underlying_type_impl(_VecT{})); - -// This isn't inlined without always_inline when loading chars. -template -[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __load_vector(_Iter __iter) noexcept { - return [=](index_sequence<_Indices...>) _LIBCPP_ALWAYS_INLINE noexcept { - return _VecT{__iter[_Indices]...}; - }(make_index_sequence<__simd_vector_size_v<_VecT>>{}); -} - -// Load the first _Np elements, zero the rest -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi") -template -[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __partial_load(_Iter __iter) noexcept { - return [=]( - index_sequence<_LoadIndices...>, index_sequence<_ZeroIndices...>) _LIBCPP_ALWAYS_INLINE noexcept { - return _VecT{__iter[_LoadIndices]..., ((void)_ZeroIndices, 0)...}; - }(make_index_sequence<_Np>{}, make_index_sequence<__simd_vector_size_v<_VecT> - _Np>{}); -} - -// Create a vector where every elements is __val -template -[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT -__broadcast(__simd_vector_underlying_type_t<_VecT> __val) { - return [&](index_sequence<_Indices...>) { - return _VecT{((void)_Indices, __val)...}; - }(make_index_sequence<__simd_vector_size_v<_VecT>>()); -} -_LIBCPP_DIAGNOSTIC_POP - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __any_of(__simd_vector<_Tp, _Np> __vec) noexcept { - return __builtin_reduce_or(__builtin_convertvector(__vec, __simd_vector)); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept { - return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector)); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __none_of(__simd_vector<_Tp, _Np> __vec) noexcept { - return !__builtin_reduce_or(__builtin_convertvector(__vec, __simd_vector)); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept { - using __mask_vec = __simd_vector; - - // This has MSan disabled du to https://llvm.org/PR85876 - auto __impl = [&](_MaskT) _LIBCPP_NO_SANITIZE("memory") noexcept { -# if defined(_LIBCPP_BIG_ENDIAN) - return std::min( - _Np, std::__countl_zero(__builtin_bit_cast(_MaskT, __builtin_convertvector(__vec, __mask_vec)))); -# else - return std::min( - _Np, std::__countr_zero(__builtin_bit_cast(_MaskT, __builtin_convertvector(__vec, __mask_vec)))); -# endif - }; - - if constexpr (sizeof(__mask_vec) == sizeof(uint8_t)) { - return __impl(uint8_t{}); - } else if constexpr (sizeof(__mask_vec) == sizeof(uint16_t)) { - return __impl(uint16_t{}); - } else if constexpr (sizeof(__mask_vec) == sizeof(uint32_t)) { - return __impl(uint32_t{}); - } else if constexpr (sizeof(__mask_vec) == sizeof(uint64_t)) { - return __impl(uint64_t{}); - } else { - static_assert(sizeof(__mask_vec) == 0, "unexpected required size for mask integer type"); - return 0; - } -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_not_set(__simd_vector<_Tp, _Np> __vec) noexcept { - return std::__find_first_set(~__vec); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SIMD_UTILS_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/sort.h b/third_party/libcxx/include/c++/v1/__algorithm/sort.h deleted file mode 100644 index 8aa894e..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/sort.h +++ /dev/null @@ -1,958 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SORT_H -#define _LIBCPP___ALGORITHM_SORT_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iter_swap.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/min_element.h> -#include <__algorithm/partial_sort.h> -#include <__algorithm/unwrap_iter.h> -#include <__assert> -#include <__bit/bit_log2.h> -#include <__bit/blsr.h> -#include <__bit/countl.h> -#include <__bit/countr.h> -#include <__config> -#include <__debug_utils/randomize_range.h> -#include <__debug_utils/strict_weak_ordering_check.h> -#include <__functional/operations.h> -#include <__functional/ranges_operations.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/conditional.h> -#include <__type_traits/desugars_to.h> -#include <__type_traits/disjunction.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_arithmetic.h> -#include <__type_traits/is_constant_evaluated.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_trivially_copyable.h> -#include <__type_traits/make_unsigned.h> -#include <__utility/move.h> -#include <__utility/pair.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value_type> -inline const bool __use_branchless_sort = - __libcpp_is_contiguous_iterator<_Iter>::value && __is_cheap_to_copy<_Tp> && is_arithmetic<_Tp>::value && - (__desugars_to_v<__less_tag, _Compare, _Tp, _Tp> || __desugars_to_v<__greater_tag, _Compare, _Tp, _Tp>); - -namespace __detail { - -// Size in bits for the bitset in use. -enum { __block_size = sizeof(uint64_t) * 8 }; - -} // namespace __detail - -// Ensures that __c(*__x, *__y) is true by swapping *__x and *__y if necessary. -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -__cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) { - // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`). - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - bool __r = __c(*__x, *__y); - value_type __tmp = __r ? *__x : *__y; - *__y = __r ? *__y : *__x; - *__x = __tmp; - return !__r; -} - -// Ensures that *__x, *__y and *__z are ordered according to the comparator __c, -// under the assumption that *__y and *__z are already ordered. -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -__partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) { - // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`). - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - bool __r1 = __c(*__z, *__x); - value_type __tmp = __r1 ? *__z : *__x; - *__z = __r1 ? *__x : *__z; - bool __r2 = __c(__tmp, *__y); - *__x = __r2 ? *__x : *__y; - *__y = __r2 ? *__y : __tmp; - return !__r1 || !__r2; -} - -// stable, 2-3 compares, 0-2 swaps - -template , int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -__sort3(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) { - bool __swapped1 = std::__cond_swap<_Compare>(__x2, __x3, __c); - bool __swapped2 = std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); - return __swapped1 || __swapped2; -} - -template , int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -__sort3(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) { - using _Ops = _IterOps<_AlgPolicy>; - - if (!__c(*__y, *__x)) // if x <= y - { - if (!__c(*__z, *__y)) // if y <= z - return false; // x <= y && y <= z - // x <= y && y > z - _Ops::iter_swap(__y, __z); // x <= z && y < z - if (__c(*__y, *__x)) // if x > y - _Ops::iter_swap(__x, __y); // x < y && y <= z - return true; // x <= y && y < z - } - if (__c(*__z, *__y)) // x > y, if y > z - { - _Ops::iter_swap(__x, __z); // x < y && y < z - return true; - } - _Ops::iter_swap(__x, __y); // x > y && y <= z - // x < y && x <= z - if (__c(*__z, *__y)) // if y > z - _Ops::iter_swap(__y, __z); // x <= y && y < z - return true; -} // x <= y && y <= z - -// stable, 3-6 compares, 0-5 swaps - -template , int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void -__sort4(_RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _Compare __c) { - std::__cond_swap<_Compare>(__x1, __x3, __c); - std::__cond_swap<_Compare>(__x2, __x4, __c); - std::__cond_swap<_Compare>(__x1, __x2, __c); - std::__cond_swap<_Compare>(__x3, __x4, __c); - std::__cond_swap<_Compare>(__x2, __x3, __c); -} - -template , int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void -__sort4(_RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _Compare __c) { - using _Ops = _IterOps<_AlgPolicy>; - std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); - if (__c(*__x4, *__x3)) { - _Ops::iter_swap(__x3, __x4); - if (__c(*__x3, *__x2)) { - _Ops::iter_swap(__x2, __x3); - if (__c(*__x2, *__x1)) { - _Ops::iter_swap(__x1, __x2); - } - } - } -} - -// stable, 4-10 compares, 0-9 swaps - -template , int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void -__sort5(_RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _RandomAccessIterator __x5, - _Compare __c) { - std::__cond_swap<_Compare>(__x1, __x2, __c); - std::__cond_swap<_Compare>(__x4, __x5, __c); - std::__partially_sorted_swap<_Compare>(__x3, __x4, __x5, __c); - std::__cond_swap<_Compare>(__x2, __x5, __c); - std::__partially_sorted_swap<_Compare>(__x1, __x3, __x4, __c); - std::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c); -} - -template , int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void -__sort5(_RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _RandomAccessIterator __x5, - _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __comp); - if (__comp(*__x5, *__x4)) { - _Ops::iter_swap(__x4, __x5); - if (__comp(*__x4, *__x3)) { - _Ops::iter_swap(__x3, __x4); - if (__comp(*__x3, *__x2)) { - _Ops::iter_swap(__x2, __x3); - if (__comp(*__x2, *__x1)) { - _Ops::iter_swap(__x1, __x2); - } - } - } - } -} - -// Assumes size > 0 -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - _BidirectionalIterator __lm1 = __last; - for (--__lm1; __first != __lm1; ++__first) { - _BidirectionalIterator __i = std::__min_element<_Compare>(__first, __last, __comp); - if (__i != __first) - _IterOps<_AlgPolicy>::iter_swap(__first, __i); - } -} - -// Sort the iterator range [__first, __last) using the comparator __comp using -// the insertion sort algorithm. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void -__insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - if (__first == __last) - return; - _BidirectionalIterator __i = __first; - for (++__i; __i != __last; ++__i) { - _BidirectionalIterator __j = __i; - --__j; - if (__comp(*__i, *__j)) { - value_type __t(_Ops::__iter_move(__i)); - _BidirectionalIterator __k = __j; - __j = __i; - do { - *__j = _Ops::__iter_move(__k); - __j = __k; - } while (__j != __first && __comp(__t, *--__k)); - *__j = std::move(__t); - } - } -} - -// Sort the iterator range [__first, __last) using the comparator __comp using -// the insertion sort algorithm. Insertion sort has two loops, outer and inner. -// The implementation below has no bounds check (unguarded) for the inner loop. -// Assumes that there is an element in the position (__first - 1) and that each -// element in the input range is greater or equal to the element at __first - 1. -template -_LIBCPP_HIDE_FROM_ABI void -__insertion_sort_unguarded(_RandomAccessIterator const __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - if (__first == __last) - return; - const _RandomAccessIterator __leftmost = __first - difference_type(1); - (void)__leftmost; // can be unused when assertions are disabled - for (_RandomAccessIterator __i = __first + difference_type(1); __i != __last; ++__i) { - _RandomAccessIterator __j = __i - difference_type(1); - if (__comp(*__i, *__j)) { - value_type __t(_Ops::__iter_move(__i)); - _RandomAccessIterator __k = __j; - __j = __i; - do { - *__j = _Ops::__iter_move(__k); - __j = __k; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __k != __leftmost, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (__comp(__t, *--__k)); // No need for bounds check due to the assumption stated above. - *__j = std::move(__t); - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI bool -__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - switch (__last - __first) { - case 0: - case 1: - return true; - case 2: - if (__comp(*--__last, *__first)) - _Ops::iter_swap(__first, __last); - return true; - case 3: - std::__sort3<_AlgPolicy, _Comp>(__first, __first + difference_type(1), --__last, __comp); - return true; - case 4: - std::__sort4<_AlgPolicy, _Comp>( - __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp); - return true; - case 5: - std::__sort5<_AlgPolicy, _Comp>( - __first, - __first + difference_type(1), - __first + difference_type(2), - __first + difference_type(3), - --__last, - __comp); - return true; - } - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - _RandomAccessIterator __j = __first + difference_type(2); - std::__sort3<_AlgPolicy, _Comp>(__first, __first + difference_type(1), __j, __comp); - const unsigned __limit = 8; - unsigned __count = 0; - for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) { - if (__comp(*__i, *__j)) { - value_type __t(_Ops::__iter_move(__i)); - _RandomAccessIterator __k = __j; - __j = __i; - do { - *__j = _Ops::__iter_move(__k); - __j = __k; - } while (__j != __first && __comp(__t, *--__k)); - *__j = std::move(__t); - if (++__count == __limit) - return ++__i == __last; - } - __j = __i; - } - return true; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos( - _RandomAccessIterator __first, _RandomAccessIterator __last, uint64_t& __left_bitset, uint64_t& __right_bitset) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - // Swap one pair on each iteration as long as both bitsets have at least one - // element for swapping. - while (__left_bitset != 0 && __right_bitset != 0) { - difference_type __tz_left = std::__countr_zero(__left_bitset); - __left_bitset = std::__libcpp_blsr(__left_bitset); - difference_type __tz_right = std::__countr_zero(__right_bitset); - __right_bitset = std::__libcpp_blsr(__right_bitset); - _Ops::iter_swap(__first + __tz_left, __last - __tz_right); - } -} - -template ::value_type> -inline _LIBCPP_HIDE_FROM_ABI void -__populate_left_bitset(_RandomAccessIterator __first, _Compare __comp, _ValueType& __pivot, uint64_t& __left_bitset) { - // Possible vectorization. With a proper "-march" flag, the following loop - // will be compiled into a set of SIMD instructions. - _RandomAccessIterator __iter = __first; - for (int __j = 0; __j < __detail::__block_size;) { - bool __comp_result = !__comp(*__iter, __pivot); - __left_bitset |= (static_cast(__comp_result) << __j); - __j++; - ++__iter; - } -} - -template ::value_type> -inline _LIBCPP_HIDE_FROM_ABI void -__populate_right_bitset(_RandomAccessIterator __lm1, _Compare __comp, _ValueType& __pivot, uint64_t& __right_bitset) { - // Possible vectorization. With a proper "-march" flag, the following loop - // will be compiled into a set of SIMD instructions. - _RandomAccessIterator __iter = __lm1; - for (int __j = 0; __j < __detail::__block_size;) { - bool __comp_result = __comp(*__iter, __pivot); - __right_bitset |= (static_cast(__comp_result) << __j); - __j++; - --__iter; - } -} - -template ::value_type> -inline _LIBCPP_HIDE_FROM_ABI void __bitset_partition_partial_blocks( - _RandomAccessIterator& __first, - _RandomAccessIterator& __lm1, - _Compare __comp, - _ValueType& __pivot, - uint64_t& __left_bitset, - uint64_t& __right_bitset) { - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __remaining_len = __lm1 - __first + 1; - difference_type __l_size; - difference_type __r_size; - if (__left_bitset == 0 && __right_bitset == 0) { - __l_size = __remaining_len / 2; - __r_size = __remaining_len - __l_size; - } else if (__left_bitset == 0) { - // We know at least one side is a full block. - __l_size = __remaining_len - __detail::__block_size; - __r_size = __detail::__block_size; - } else { // if (__right_bitset == 0) - __l_size = __detail::__block_size; - __r_size = __remaining_len - __detail::__block_size; - } - // Record the comparison outcomes for the elements currently on the left side. - if (__left_bitset == 0) { - _RandomAccessIterator __iter = __first; - for (int __j = 0; __j < __l_size; __j++) { - bool __comp_result = !__comp(*__iter, __pivot); - __left_bitset |= (static_cast(__comp_result) << __j); - ++__iter; - } - } - // Record the comparison outcomes for the elements currently on the right - // side. - if (__right_bitset == 0) { - _RandomAccessIterator __iter = __lm1; - for (int __j = 0; __j < __r_size; __j++) { - bool __comp_result = __comp(*__iter, __pivot); - __right_bitset |= (static_cast(__comp_result) << __j); - --__iter; - } - } - std::__swap_bitmap_pos<_AlgPolicy, _RandomAccessIterator>(__first, __lm1, __left_bitset, __right_bitset); - __first += (__left_bitset == 0) ? __l_size : 0; - __lm1 -= (__right_bitset == 0) ? __r_size : 0; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos_within( - _RandomAccessIterator& __first, _RandomAccessIterator& __lm1, uint64_t& __left_bitset, uint64_t& __right_bitset) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - if (__left_bitset) { - // Swap within the left side. Need to find set positions in the reverse - // order. - while (__left_bitset != 0) { - difference_type __tz_left = __detail::__block_size - 1 - std::__countl_zero(__left_bitset); - __left_bitset &= (static_cast(1) << __tz_left) - 1; - _RandomAccessIterator __it = __first + __tz_left; - if (__it != __lm1) { - _Ops::iter_swap(__it, __lm1); - } - --__lm1; - } - __first = __lm1 + difference_type(1); - } else if (__right_bitset) { - // Swap within the right side. Need to find set positions in the reverse - // order. - while (__right_bitset != 0) { - difference_type __tz_right = __detail::__block_size - 1 - std::__countl_zero(__right_bitset); - __right_bitset &= (static_cast(1) << __tz_right) - 1; - _RandomAccessIterator __it = __lm1 - __tz_right; - if (__it != __first) { - _Ops::iter_swap(__it, __first); - } - ++__first; - } - } -} - -// Partition [__first, __last) using the comparator __comp. *__first has the -// chosen pivot. Elements that are equivalent are kept to the left of the -// pivot. Returns the iterator for the pivot and a bool value which is true if -// the provided range is already sorted, false otherwise. We assume that the -// length of the range is at least three elements. -// -// __bitset_partition uses bitsets for storing outcomes of the comparisons -// between the pivot and other elements. -template -_LIBCPP_HIDE_FROM_ABI std::pair<_RandomAccessIterator, bool> -__bitset_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - _LIBCPP_ASSERT_INTERNAL(__last - __first >= difference_type(3), ""); - const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around - const _RandomAccessIterator __end = __last; - (void)__end; // - - value_type __pivot(_Ops::__iter_move(__first)); - // Find the first element greater than the pivot. - if (__comp(__pivot, *(__last - difference_type(1)))) { - // Not guarded since we know the last element is greater than the pivot. - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (!__comp(__pivot, *__first)); - } else { - while (++__first < __last && !__comp(__pivot, *__first)) { - } - } - // Find the last element less than or equal to the pivot. - if (__first < __last) { - // It will be always guarded because __introsort will do the median-of-three - // before calling this. - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (__comp(__pivot, *__last)); - } - // If the first element greater than the pivot is at or after the - // last element less than or equal to the pivot, then we have covered the - // entire range without swapping elements. This implies the range is already - // partitioned. - bool __already_partitioned = __first >= __last; - if (!__already_partitioned) { - _Ops::iter_swap(__first, __last); - ++__first; - } - - // In [__first, __last) __last is not inclusive. From now on, it uses last - // minus one to be inclusive on both sides. - _RandomAccessIterator __lm1 = __last - difference_type(1); - uint64_t __left_bitset = 0; - uint64_t __right_bitset = 0; - - // Reminder: length = __lm1 - __first + 1. - while (__lm1 - __first >= 2 * __detail::__block_size - 1) { - // Record the comparison outcomes for the elements currently on the left - // side. - if (__left_bitset == 0) - std::__populate_left_bitset<_Compare>(__first, __comp, __pivot, __left_bitset); - // Record the comparison outcomes for the elements currently on the right - // side. - if (__right_bitset == 0) - std::__populate_right_bitset<_Compare>(__lm1, __comp, __pivot, __right_bitset); - // Swap the elements recorded to be the candidates for swapping in the - // bitsets. - std::__swap_bitmap_pos<_AlgPolicy, _RandomAccessIterator>(__first, __lm1, __left_bitset, __right_bitset); - // Only advance the iterator if all the elements that need to be moved to - // other side were moved. - __first += (__left_bitset == 0) ? difference_type(__detail::__block_size) : difference_type(0); - __lm1 -= (__right_bitset == 0) ? difference_type(__detail::__block_size) : difference_type(0); - } - // Now, we have a less-than a block worth of elements on at least one of the - // sides. - std::__bitset_partition_partial_blocks<_AlgPolicy, _Compare>( - __first, __lm1, __comp, __pivot, __left_bitset, __right_bitset); - // At least one the bitsets would be empty. For the non-empty one, we need to - // properly partition the elements that appear within that bitset. - std::__swap_bitmap_pos_within<_AlgPolicy>(__first, __lm1, __left_bitset, __right_bitset); - - // Move the pivot to its correct position. - _RandomAccessIterator __pivot_pos = __first - difference_type(1); - if (__begin != __pivot_pos) { - *__begin = _Ops::__iter_move(__pivot_pos); - } - *__pivot_pos = std::move(__pivot); - return std::make_pair(__pivot_pos, __already_partitioned); -} - -// Partition [__first, __last) using the comparator __comp. *__first has the -// chosen pivot. Elements that are equivalent are kept to the right of the -// pivot. Returns the iterator for the pivot and a bool value which is true if -// the provided range is already sorted, false otherwise. We assume that the -// length of the range is at least three elements. -template -_LIBCPP_HIDE_FROM_ABI std::pair<_RandomAccessIterator, bool> -__partition_with_equals_on_right(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; - _LIBCPP_ASSERT_INTERNAL(__last - __first >= difference_type(3), ""); - const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around - const _RandomAccessIterator __end = __last; - (void)__end; // - value_type __pivot(_Ops::__iter_move(__first)); - // Find the first element greater or equal to the pivot. It will be always - // guarded because __introsort will do the median-of-three before calling - // this. - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (__comp(*__first, __pivot)); - - // Find the last element less than the pivot. - if (__begin == __first - difference_type(1)) { - while (__first < __last && !__comp(*--__last, __pivot)) - ; - } else { - // Guarded. - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (!__comp(*__last, __pivot)); - } - - // If the first element greater than or equal to the pivot is at or after the - // last element less than the pivot, then we have covered the entire range - // without swapping elements. This implies the range is already partitioned. - bool __already_partitioned = __first >= __last; - // Go through the remaining elements. Swap pairs of elements (one to the - // right of the pivot and the other to left of the pivot) that are not on the - // correct side of the pivot. - while (__first < __last) { - _Ops::iter_swap(__first, __last); - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (__comp(*__first, __pivot)); - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (!__comp(*__last, __pivot)); - } - // Move the pivot to its correct position. - _RandomAccessIterator __pivot_pos = __first - difference_type(1); - if (__begin != __pivot_pos) { - *__begin = _Ops::__iter_move(__pivot_pos); - } - *__pivot_pos = std::move(__pivot); - return std::make_pair(__pivot_pos, __already_partitioned); -} - -// Similar to the above function. Elements equivalent to the pivot are put to -// the left of the pivot. Returns the iterator to the pivot element. -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -__partition_with_equals_on_left(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; - const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around - const _RandomAccessIterator __end = __last; - (void)__end; // - value_type __pivot(_Ops::__iter_move(__first)); - if (__comp(__pivot, *(__last - difference_type(1)))) { - // Guarded. - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (!__comp(__pivot, *__first)); - } else { - while (++__first < __last && !__comp(__pivot, *__first)) { - } - } - - if (__first < __last) { - // It will be always guarded because __introsort will do the - // median-of-three before calling this. - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (__comp(__pivot, *__last)); - } - while (__first < __last) { - _Ops::iter_swap(__first, __last); - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (!__comp(__pivot, *__first)); - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (__comp(__pivot, *__last)); - } - _RandomAccessIterator __pivot_pos = __first - difference_type(1); - if (__begin != __pivot_pos) { - *__begin = _Ops::__iter_move(__pivot_pos); - } - *__pivot_pos = std::move(__pivot); - return __first; -} - -// The main sorting function. Implements introsort combined with other ideas: -// - option of using block quick sort for partitioning, -// - guarded and unguarded insertion sort for small lengths, -// - Tuckey's ninther technique for computing the pivot, -// - check on whether partition was not required. -// The implementation is partly based on Orson Peters' pattern-defeating -// quicksort, published at: . -template -void __introsort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __depth, - bool __leftmost = true) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - using _Comp_ref = __comp_ref_type<_Compare>; - // Upper bound for using insertion sort for sorting. - _LIBCPP_CONSTEXPR difference_type __limit = 24; - // Lower bound for using Tuckey's ninther technique for median computation. - _LIBCPP_CONSTEXPR difference_type __ninther_threshold = 128; - while (true) { - difference_type __len = __last - __first; - switch (__len) { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - _Ops::iter_swap(__first, __last); - return; - case 3: - std::__sort3<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp); - return; - case 4: - std::__sort4<_AlgPolicy, _Compare>( - __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp); - return; - case 5: - std::__sort5<_AlgPolicy, _Compare>( - __first, - __first + difference_type(1), - __first + difference_type(2), - __first + difference_type(3), - --__last, - __comp); - return; - } - // Use insertion sort if the length of the range is below the specified limit. - if (__len < __limit) { - if (__leftmost) { - std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp); - } else { - std::__insertion_sort_unguarded<_AlgPolicy, _Compare>(__first, __last, __comp); - } - return; - } - if (__depth == 0) { - // Fallback to heap sort as Introsort suggests. - std::__partial_sort<_AlgPolicy, _Compare>(__first, __last, __last, __comp); - return; - } - --__depth; - { - difference_type __half_len = __len / 2; - // Use Tuckey's ninther technique or median of 3 for pivot selection - // depending on the length of the range being sorted. - if (__len > __ninther_threshold) { - std::__sort3<_AlgPolicy, _Compare>(__first, __first + __half_len, __last - difference_type(1), __comp); - std::__sort3<_AlgPolicy, _Compare>( - __first + difference_type(1), __first + (__half_len - 1), __last - difference_type(2), __comp); - std::__sort3<_AlgPolicy, _Compare>( - __first + difference_type(2), __first + (__half_len + 1), __last - difference_type(3), __comp); - std::__sort3<_AlgPolicy, _Compare>( - __first + (__half_len - 1), __first + __half_len, __first + (__half_len + 1), __comp); - _Ops::iter_swap(__first, __first + __half_len); - } else { - std::__sort3<_AlgPolicy, _Compare>(__first + __half_len, __first, __last - difference_type(1), __comp); - } - } - // The elements to the left of the current iterator range are already - // sorted. If the current iterator range to be sorted is not the - // leftmost part of the entire iterator range and the pivot is same as - // the highest element in the range to the left, then we know that all - // the elements in the range [first, pivot] would be equal to the pivot, - // assuming the equal elements are put on the left side when - // partitioned. This also means that we do not need to sort the left - // side of the partition. - if (!__leftmost && !__comp(*(__first - difference_type(1)), *__first)) { - __first = std::__partition_with_equals_on_left<_AlgPolicy, _RandomAccessIterator, _Comp_ref>( - __first, __last, _Comp_ref(__comp)); - continue; - } - // Use bitset partition only if asked for. - auto __ret = _UseBitSetPartition - ? std::__bitset_partition<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp) - : std::__partition_with_equals_on_right<_AlgPolicy, _RandomAccessIterator, _Compare>( - __first, __last, __comp); - _RandomAccessIterator __i = __ret.first; - // [__first, __i) < *__i and *__i <= [__i+1, __last) - // If we were given a perfect partition, see if insertion sort is quick... - if (__ret.second) { - bool __fs = std::__insertion_sort_incomplete<_AlgPolicy, _Compare>(__first, __i, __comp); - if (std::__insertion_sort_incomplete<_AlgPolicy, _Compare>(__i + difference_type(1), __last, __comp)) { - if (__fs) - return; - __last = __i; - continue; - } else { - if (__fs) { - __first = ++__i; - continue; - } - } - } - // Sort the left partiton recursively and the right partition with tail recursion elimination. - std::__introsort<_AlgPolicy, _Compare, _RandomAccessIterator, _UseBitSetPartition>( - __first, __i, __comp, __depth, __leftmost); - __leftmost = false; - __first = ++__i; - } -} - -template -void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp); - -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, char*>(char*, char*, __less&); -#if _LIBCPP_HAS_WIDE_CHARACTERS -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&); -#endif -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, signed char*>(signed char*, signed char*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, short*>(short*, short*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, int*>(int*, int*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned*>(unsigned*, unsigned*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, long*>(long*, long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, long long*>(long long*, long long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, unsigned long long*>( - unsigned long long*, unsigned long long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, float*>(float*, float*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, double*>(double*, double*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, long double*>(long double*, long double*, __less&); - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -__sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) { - if (__first == __last) // log(0) is undefined, so don't try computing the depth - return; - - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __depth_limit = 2 * std::__bit_log2(std::__to_unsigned_like(__last - __first)); - - // Only use bitset partitioning for arithmetic types. We should also check - // that the default comparator is in use so that we are sure that there are no - // branches in the comparator. - std::__introsort<_AlgPolicy, _Comp&, _RandomAccessIterator, __use_branchless_sort<_Comp, _RandomAccessIterator> >( - __first, __last, __comp, __depth_limit); -} - -template -using __is_any_of _LIBCPP_NODEBUG = _Or...>; - -template -using __sort_is_specialized_in_library _LIBCPP_NODEBUG = __is_any_of< - _Type, - char, -#if _LIBCPP_HAS_WIDE_CHARACTERS - wchar_t, -#endif - signed char, - unsigned char, - short, - unsigned short, - int, - unsigned int, - long, - unsigned long, - long long, - unsigned long long, - float, - double, - long double>; - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, __less<>&) { - __less<_Type> __comp; - std::__sort<__less<_Type>&, _Type*>(__first, __last, __comp); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, less<_Type>&) { - __less<_Type> __comp; - std::__sort<__less<_Type>&, _Type*>(__first, __last, __comp); -} - -#if _LIBCPP_STD_VER >= 14 -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, less<>&) { - __less<_Type> __comp; - std::__sort<__less<_Type>&, _Type*>(__first, __last, __comp); -} -#endif - -#if _LIBCPP_STD_VER >= 20 -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, ranges::less&) { - __less<_Type> __comp; - std::__sort<__less<_Type>&, _Type*>(__first, __last, __comp); -} -#endif - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -__sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) { - std::__debug_randomize_range<_AlgPolicy>(__first, __last); - - if (__libcpp_is_constant_evaluated()) { - std::__partial_sort<_AlgPolicy>( - std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__last), __comp); - } else { - std::__sort_dispatch<_AlgPolicy>(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __comp); - } - std::__check_strict_weak_ordering_sorted(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { - std::__sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::sort(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/sort_heap.h b/third_party/libcxx/include/c++/v1/__algorithm/sort_heap.h deleted file mode 100644 index f20b110..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/sort_heap.h +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SORT_HEAP_H -#define _LIBCPP___ALGORITHM_SORT_HEAP_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/pop_heap.h> -#include <__config> -#include <__debug_utils/strict_weak_ordering_check.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/is_assignable.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - _RandomAccessIterator __saved_last = __last; - __comp_ref_type<_Compare> __comp_ref = __comp; - - using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; - for (difference_type __n = __last - __first; __n > 1; --__last, (void)--__n) - std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n); - std::__check_strict_weak_ordering_sorted(__first, __saved_last, __comp_ref); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - std::__sort_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::sort_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SORT_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/specialized_algorithms.h b/third_party/libcxx/include/c++/v1/__algorithm/specialized_algorithms.h deleted file mode 100644 index 58b4d93..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/specialized_algorithms.h +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SPECIALIZED_ALGORITHMS_H -#define _LIBCPP___ALGORITHM_SPECIALIZED_ALGORITHMS_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace _Algorithm { -struct __copy {}; -struct __fill_n {}; -struct __for_each {}; -struct __swap_ranges {}; -} // namespace _Algorithm - -template -struct __single_iterator; - -template -struct __iterator_pair; - -template -struct __single_range; - -// This struct allows specializing algorithms for specific arguments. This is useful when we know a more efficient -// algorithm implementation for e.g. library-defined iterators. _Alg is one of tags defined inside the _Algorithm -// namespace above. _Ranges is an essentially arbitrary subset of the arguments to the algorithm that are used for -// dispatching. This set is specific to the algorithm: look at each algorithm to see which arguments they use for -// dispatching to specialized algorithms. -// -// A specialization of `__specialized_algorithm` has to define `__has_algorithm` to true for the specialized algorithm -// to be used. This is intended for cases where iterators can do generic unwrapping and forward to a different -// specialization of `__specialized_algorithm`. -// -// If __has_algorithm is true, there has to be an operator() which will get called with the actual arguments to the -// algorithm. -template -struct __specialized_algorithm { - static const bool __has_algorithm = false; -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_SPECIALIZED_ALGORITHMS_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/stable_partition.h b/third_party/libcxx/include/c++/v1/__algorithm/stable_partition.h deleted file mode 100644 index b389ae2..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/stable_partition.h +++ /dev/null @@ -1,305 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_STABLE_PARTITION_H -#define _LIBCPP___ALGORITHM_STABLE_PARTITION_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/rotate.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__iterator/advance.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__memory/construct_at.h> -#include <__memory/destruct_n.h> -#include <__memory/unique_ptr.h> -#include <__memory/unique_temporary_buffer.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __stable_partition_impl( - _ForwardIterator __first, - _ForwardIterator __last, - _Predicate __pred, - _Distance __len, - _Pair __p, - forward_iterator_tag __fit) { - using _Ops = _IterOps<_AlgPolicy>; - - // *__first is known to be false - // __len >= 1 - if (__len == 1) - return __first; - if (__len == 2) { - _ForwardIterator __m = __first; - if (__pred(*++__m)) { - _Ops::iter_swap(__first, __m); - return __m; - } - return __first; - } - if (__len <= __p.second) { // The buffer is big enough to use - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__p.first, __d); - // Move the falses into the temporary buffer, and the trues to the front of the line - // Update __first to always point to the end of the trues - value_type* __t = __p.first; - std::__construct_at(__t, _Ops::__iter_move(__first)); - __d.template __incr(); - ++__t; - _ForwardIterator __i = __first; - while (++__i != __last) { - if (__pred(*__i)) { - *__first = _Ops::__iter_move(__i); - ++__first; - } else { - std::__construct_at(__t, _Ops::__iter_move(__i)); - __d.template __incr(); - ++__t; - } - } - // All trues now at start of range, all falses in buffer - // Move falses back into range, but don't mess up __first which points to first false - __i = __first; - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i) - *__i = _Ops::__iter_move(__t2); - // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer - return __first; - } - // Else not enough buffer, do in place - // __len >= 3 - _ForwardIterator __m = __first; - _Distance __len2 = __len / 2; // __len2 >= 2 - _Ops::advance(__m, __len2); - // recurse on [__first, __m), *__first know to be false - // F????????????????? - // f m l - _ForwardIterator __first_false = - std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m, __pred, __len2, __p, __fit); - // TTTFFFFF?????????? - // f ff m l - // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true - _ForwardIterator __m1 = __m; - _ForwardIterator __second_false = __last; - _Distance __len_half = __len - __len2; - while (__pred(*__m1)) { - if (++__m1 == __last) - goto __second_half_done; - --__len_half; - } - // TTTFFFFFTTTF?????? - // f ff m m1 l - __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __fit); -__second_half_done: - // TTTFFFFFTTTTTFFFFF - // f ff m sf l - return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first; - // TTTTTTTTFFFFFFFFFF - // | -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator -__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) { - typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - - const difference_type __alloc_limit = 3; // might want to make this a function of trivial assignment - // Either prove all true and return __first or point to first false - while (true) { - if (__first == __last) - return __first; - if (!__pred(*__first)) - break; - ++__first; - } - // We now have a reduced range [__first, __last) - // *__first is known to be false - difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last); - __unique_temporary_buffer __unique_buf; - pair __p(0, 0); - if (__len >= __alloc_limit) { - __unique_buf = std::__allocate_unique_temporary_buffer(__len); - __p.first = __unique_buf.get(); - __p.second = __unique_buf.get_deleter().__count_; - } - return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( - std::move(__first), std::move(__last), __pred, __len, __p, forward_iterator_tag()); -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX26 _BidirectionalIterator __stable_partition_impl( - _BidirectionalIterator __first, - _BidirectionalIterator __last, - _Predicate __pred, - _Distance __len, - _Pair __p, - bidirectional_iterator_tag __bit) { - using _Ops = _IterOps<_AlgPolicy>; - - // *__first is known to be false - // *__last is known to be true - // __len >= 2 - if (__len == 2) { - _Ops::iter_swap(__first, __last); - return __last; - } - if (__len == 3) { - _BidirectionalIterator __m = __first; - if (__pred(*++__m)) { - _Ops::iter_swap(__first, __m); - _Ops::iter_swap(__m, __last); - return __last; - } - _Ops::iter_swap(__m, __last); - _Ops::iter_swap(__first, __m); - return __m; - } - if (__len <= __p.second) { // The buffer is big enough to use - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__p.first, __d); - // Move the falses into the temporary buffer, and the trues to the front of the line - // Update __first to always point to the end of the trues - value_type* __t = __p.first; - std::__construct_at(__t, _Ops::__iter_move(__first)); - __d.template __incr(); - ++__t; - _BidirectionalIterator __i = __first; - while (++__i != __last) { - if (__pred(*__i)) { - *__first = _Ops::__iter_move(__i); - ++__first; - } else { - std::__construct_at(__t, _Ops::__iter_move(__i)); - __d.template __incr(); - ++__t; - } - } - // move *__last, known to be true - *__first = _Ops::__iter_move(__i); - __i = ++__first; - // All trues now at start of range, all falses in buffer - // Move falses back into range, but don't mess up __first which points to first false - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i) - *__i = _Ops::__iter_move(__t2); - // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer - return __first; - } - // Else not enough buffer, do in place - // __len >= 4 - _BidirectionalIterator __m = __first; - _Distance __len2 = __len / 2; // __len2 >= 2 - _Ops::advance(__m, __len2); - // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false - // F????????????????T - // f m l - _BidirectionalIterator __m1 = __m; - _BidirectionalIterator __first_false = __first; - _Distance __len_half = __len2; - while (!__pred(*--__m1)) { - if (__m1 == __first) - goto __first_half_done; - --__len_half; - } - // F???TFFF?????????T - // f m1 m l - __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m1, __pred, __len_half, __p, __bit); -__first_half_done: - // TTTFFFFF?????????T - // f ff m l - // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true - __m1 = __m; - _BidirectionalIterator __second_false = __last; - ++__second_false; - __len_half = __len - __len2; - while (__pred(*__m1)) { - if (++__m1 == __last) - goto __second_half_done; - --__len_half; - } - // TTTFFFFFTTTF?????T - // f ff m m1 l - __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __bit); -__second_half_done: - // TTTFFFFFTTTTTFFFFF - // f ff m sf l - return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first; - // TTTTTTTTFFFFFFFFFF - // | -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _BidirectionalIterator __stable_partition_impl( - _BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) { - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment - // Either prove all true and return __first or point to first false - while (true) { - if (__first == __last) - return __first; - if (!__pred(*__first)) - break; - ++__first; - } - // __first points to first false, everything prior to __first is already set. - // Either prove [__first, __last) is all false and return __first, or point __last to last true - do { - if (__first == --__last) - return __first; - } while (!__pred(*__last)); - // We now have a reduced range [__first, __last] - // *__first is known to be false - // *__last is known to be true - // __len >= 2 - difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1; - __unique_temporary_buffer __unique_buf; - pair __p(0, 0); - if (__len >= __alloc_limit) { - __unique_buf = std::__allocate_unique_temporary_buffer(__len); - __p.first = __unique_buf.get(); - __p.second = __unique_buf.get_deleter().__count_; - } - return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( - std::move(__first), std::move(__last), __pred, __len, __p, bidirectional_iterator_tag()); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __stable_partition( - _ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category) { - return std::__stable_partition_impl<_AlgPolicy, __remove_cvref_t<_Predicate>&>( - std::move(__first), std::move(__last), __pred, __iter_category); -} - -template -_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator -stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category; - return std::__stable_partition<_ClassicAlgPolicy, _Predicate&>( - std::move(__first), std::move(__last), __pred, _IterCategory()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_STABLE_PARTITION_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/stable_sort.h b/third_party/libcxx/include/c++/v1/__algorithm/stable_sort.h deleted file mode 100644 index 64c8080..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/stable_sort.h +++ /dev/null @@ -1,323 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_STABLE_SORT_H -#define _LIBCPP___ALGORITHM_STABLE_SORT_H - -#include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> -#include <__algorithm/inplace_merge.h> -#include <__algorithm/iterator_operations.h> -#include <__algorithm/radix_sort.h> -#include <__algorithm/sort.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__debug_utils/strict_weak_ordering_check.h> -#include <__iterator/iterator_traits.h> -#include <__memory/construct_at.h> -#include <__memory/destruct_n.h> -#include <__memory/unique_ptr.h> -#include <__memory/unique_temporary_buffer.h> -#include <__type_traits/desugars_to.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_constant_evaluated.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_trivially_assignable.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __insertion_sort_move( - _BidirectionalIterator __first1, - _BidirectionalIterator __last1, - typename iterator_traits<_BidirectionalIterator>::value_type* __first2, - _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - if (__first1 != __last1) { - __destruct_n __d(0); - unique_ptr __h(__first2, __d); - value_type* __last2 = __first2; - std::__construct_at(__last2, _Ops::__iter_move(__first1)); - __d.template __incr(); - for (++__last2; ++__first1 != __last1; ++__last2) { - value_type* __j2 = __last2; - value_type* __i2 = __j2; - if (__comp(*__first1, *--__i2)) { - std::__construct_at(__j2, std::move(*__i2)); - __d.template __incr(); - for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) - *__j2 = std::move(*__i2); - *__j2 = _Ops::__iter_move(__first1); - } else { - std::__construct_at(__j2, _Ops::__iter_move(__first1)); - __d.template __incr(); - } - } - __h.release(); - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __merge_move_construct( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - typename iterator_traits<_InputIterator1>::value_type* __result, - _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_InputIterator1>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__result, __d); - for (; true; ++__result) { - if (__first1 == __last1) { - for (; __first2 != __last2; ++__first2, (void)++__result, __d.template __incr()) - std::__construct_at(__result, _Ops::__iter_move(__first2)); - __h.release(); - return; - } - if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, (void)++__result, __d.template __incr()) - std::__construct_at(__result, _Ops::__iter_move(__first1)); - __h.release(); - return; - } - if (__comp(*__first2, *__first1)) { - std::__construct_at(__result, _Ops::__iter_move(__first2)); - __d.template __incr(); - ++__first2; - } else { - std::__construct_at(__result, _Ops::__iter_move(__first1)); - __d.template __incr(); - ++__first1; - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __merge_move_assign( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, (void)++__result) - *__result = _Ops::__iter_move(__first1); - return; - } - if (__comp(*__first2, *__first1)) { - *__result = _Ops::__iter_move(__first2); - ++__first2; - } else { - *__result = _Ops::__iter_move(__first1); - ++__first1; - } - } - for (; __first2 != __last2; ++__first2, (void)++__result) - *__result = _Ops::__iter_move(__first2); -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort( - _RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, - ptrdiff_t __buff_size); - -template -_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort_move( - _RandomAccessIterator __first1, - _RandomAccessIterator __last1, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __first2) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - switch (__len) { - case 0: - return; - case 1: - std::__construct_at(__first2, _Ops::__iter_move(__first1)); - return; - case 2: - __destruct_n __d(0); - unique_ptr __h2(__first2, __d); - if (__comp(*--__last1, *__first1)) { - std::__construct_at(__first2, _Ops::__iter_move(__last1)); - __d.template __incr(); - ++__first2; - std::__construct_at(__first2, _Ops::__iter_move(__first1)); - } else { - std::__construct_at(__first2, _Ops::__iter_move(__first1)); - __d.template __incr(); - ++__first2; - std::__construct_at(__first2, _Ops::__iter_move(__last1)); - } - __h2.release(); - return; - } - if (__len <= 8) { - std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp); - return; - } - typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; - _RandomAccessIterator __m = __first1 + __l2; - std::__stable_sort<_AlgPolicy, _Compare>(__first1, __m, __comp, __l2, __first2, __l2); - std::__stable_sort<_AlgPolicy, _Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2); - std::__merge_move_construct<_AlgPolicy, _Compare>(__first1, __m, __m, __last1, __first2, __comp); -} - -template -struct __stable_sort_switch { - static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value; -}; - -#if _LIBCPP_STD_VER >= 17 -template -_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_min_bound() { - static_assert(__is_ordered_integer_representable_v<_Tp>); - if constexpr (sizeof(_Tp) == 1) { - return 1 << 8; - } - - return 1 << 10; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_max_bound() { - static_assert(__is_ordered_integer_representable_v<_Tp>); - if constexpr (sizeof(_Tp) >= 8) { - return 1 << 15; - } - - return 1 << 16; -} -#endif // _LIBCPP_STD_VER >= 17 - -template -_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort( - _RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, - ptrdiff_t __buff_size) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - switch (__len) { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - _IterOps<_AlgPolicy>::iter_swap(__first, __last); - return; - } - if (__len <= static_cast(__stable_sort_switch::value)) { - std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp); - return; - } - -#if _LIBCPP_STD_VER >= 17 - constexpr auto __default_comp = __desugars_to_v<__less_tag, _Compare, value_type, value_type >; - constexpr auto __radix_sortable = - __is_ordered_integer_representable_v && - is_same_v< value_type&, __iterator_reference<_RandomAccessIterator>>; - if constexpr (__default_comp && __radix_sortable) { - if (__len <= __buff_size && __len >= static_cast(std::__radix_sort_min_bound()) && - __len <= static_cast(std::__radix_sort_max_bound())) { - if (__libcpp_is_constant_evaluated()) { - for (auto* __p = __buff; __p < __buff + __buff_size; ++__p) { - std::__construct_at(__p); - } - } - - std::__radix_sort(__first, __last, __buff); - return; - } - } -#endif // _LIBCPP_STD_VER >= 17 - - typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; - _RandomAccessIterator __m = __first + __l2; - if (__len <= __buff_size) { - __destruct_n __d(0); - unique_ptr __h2(__buff, __d); - std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff); - __d.__set(__l2, (value_type*)nullptr); - std::__stable_sort_move<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff + __l2); - __d.__set(__len, (value_type*)nullptr); - std::__merge_move_assign<_AlgPolicy, _Compare>( - __buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); - // std::__merge<_Compare>(move_iterator(__buff), - // move_iterator(__buff + __l2), - // move_iterator<_RandomAccessIterator>(__buff + __l2), - // move_iterator<_RandomAccessIterator>(__buff + __len), - // __first, __comp); - return; - } - std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size); - std::__stable_sort<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size); - std::__inplace_merge<_AlgPolicy>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void -__stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; - - difference_type __len = __last - __first; - __unique_temporary_buffer __unique_buf; - pair __buf(0, 0); - if (__len > static_cast(__stable_sort_switch::value)) { - __unique_buf = std::__allocate_unique_temporary_buffer(__len); - __buf.first = __unique_buf.get(); - __buf.second = __unique_buf.get_deleter().__count_; - } - - std::__stable_sort<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __last, __comp, __len, __buf.first, __buf.second); - std::__check_strict_weak_ordering_sorted(__first, __last, __comp); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void -stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void -stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::stable_sort(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_STABLE_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/swap_ranges.h b/third_party/libcxx/include/c++/v1/__algorithm/swap_ranges.h deleted file mode 100644 index 3a9e841..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/swap_ranges.h +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_SWAP_RANGES_H -#define _LIBCPP___ALGORITHM_SWAP_RANGES_H - -#include <__algorithm/iterator_operations.h> -#include <__algorithm/specialized_algorithms.h> -#include <__config> -#include <__type_traits/enable_if.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template < - class _AlgPolicy, - class _Iter1, - class _Sent1, - class _Iter2, - class _SpecialAlg = - __specialized_algorithm<_Algorithm::__swap_ranges, __iterator_pair<_Iter1, _Sent1>, __single_iterator<_Iter2> >, - __enable_if_t<_SpecialAlg::__has_algorithm, int> = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> -__swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { - return _SpecialAlg()(std::move(__first1), std::move(__last1), std::move(__first2)); -} - -template < - class _AlgPolicy, - class _Iter1, - class _Sent1, - class _Iter2, - class _SpecialAlg = - __specialized_algorithm<_Algorithm::__swap_ranges, __iterator_pair<_Iter1, _Sent1>, __single_iterator<_Iter2> >, - __enable_if_t = 0> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> -__swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) { - while (__first1 != __last1) { - _IterOps<_AlgPolicy>::iter_swap(__first1, __first2); - ++__first1; - ++__first2; - } - - return pair<_Iter1, _Iter2>(std::move(__first1), std::move(__first2)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2 -swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { - return std::__swap_ranges<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/three_way_comp_ref_type.h b/third_party/libcxx/include/c++/v1/__algorithm/three_way_comp_ref_type.h deleted file mode 100644 index f6f7645..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/three_way_comp_ref_type.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_THREE_WAY_COMP_REF_TYPE_H -#define _LIBCPP___ALGORITHM_THREE_WAY_COMP_REF_TYPE_H - -#include <__assert> -#include <__compare/ordering.h> -#include <__config> -#include <__utility/declval.h> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -struct __debug_three_way_comp { - _Comp& __comp_; - _LIBCPP_HIDE_FROM_ABI constexpr __debug_three_way_comp(_Comp& __c) : __comp_(__c) {} - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(const _Tp& __x, const _Up& __y) { - auto __r = __comp_(__x, __y); - if constexpr (__comparison_category) - __do_compare_assert(__y, __x, __r); - return __r; - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp& __x, _Up& __y) { - auto __r = __comp_(__x, __y); - if constexpr (__comparison_category) - __do_compare_assert(__y, __x, __r); - return __r; - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr void __do_compare_assert(_LHS& __l, _RHS& __r, _Order __o) { - _Order __expected = __o; - if (__o == _Order::less) - __expected = _Order::greater; - if (__o == _Order::greater) - __expected = _Order::less; - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( - __comp_(__l, __r) == __expected, "Comparator does not induce a strict weak ordering"); - (void)__l; - (void)__r; - } -}; - -// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference. -# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -template -using __three_way_comp_ref_type _LIBCPP_NODEBUG = __debug_three_way_comp<_Comp>; -# else -template -using __three_way_comp_ref_type _LIBCPP_NODEBUG = _Comp&; -# endif - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_THREE_WAY_COMP_REF_TYPE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/transform.h b/third_party/libcxx/include/c++/v1/__algorithm/transform.h deleted file mode 100644 index 1b42440..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/transform.h +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_TRANSFORM_H -#define _LIBCPP___ALGORITHM_TRANSFORM_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) { - for (; __first != __last; ++__first, (void)++__result) - *__result = __op(*__first); - return __result; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator transform( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _OutputIterator __result, - _BinaryOperation __binary_op) { - for (; __first1 != __last1; ++__first1, (void)++__first2, ++__result) - *__result = __binary_op(*__first1, *__first2); - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ALGORITHM_TRANSFORM_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/uniform_random_bit_generator_adaptor.h b/third_party/libcxx/include/c++/v1/__algorithm/uniform_random_bit_generator_adaptor.h deleted file mode 100644 index bc7a892..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/uniform_random_bit_generator_adaptor.h +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H -#define _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H - -#include <__config> -#include <__type_traits/invoke.h> -#include <__type_traits/remove_cvref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Range versions of random algorithms (e.g. `std::shuffle`) are less constrained than their classic counterparts. -// Range algorithms only require the given generator to satisfy the `std::uniform_random_bit_generator` concept. -// Classic algorithms require the given generator to meet the uniform random bit generator requirements; these -// requirements include satisfying `std::uniform_random_bit_generator` and add a requirement for the generator to -// provide a nested `result_type` typedef (see `[rand.req.urng]`). -// -// To be able to reuse classic implementations, make the given generator meet the classic requirements by wrapping -// it into an adaptor type that forwards all of its interface and adds the required typedef. -template -class _ClassicGenAdaptor { -private: - // The generator is not required to be copyable or movable, so it has to be stored as a reference. - _Gen& __gen_; - -public: - using result_type = invoke_result_t<_Gen&>; - - _LIBCPP_HIDE_FROM_ABI static constexpr auto min() { return __remove_cvref_t<_Gen>::min(); } - _LIBCPP_HIDE_FROM_ABI static constexpr auto max() { return __remove_cvref_t<_Gen>::max(); } - - _LIBCPP_HIDE_FROM_ABI constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen_(__g) {} - - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()() const { return __gen_(); } -}; - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/unique.h b/third_party/libcxx/include/c++/v1/__algorithm/unique.h deleted file mode 100644 index 307c424..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/unique.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_UNIQUE_H -#define _LIBCPP___ALGORITHM_UNIQUE_H - -#include <__algorithm/adjacent_find.h> -#include <__algorithm/comp.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// unique - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter> -__unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { - __identity __proj; - __first = std::__adjacent_find(__first, __last, __pred, __proj); - if (__first != __last) { - // ... a a ? ... - // f i - _Iter __i = __first; - for (++__i; ++__i != __last;) - if (!__pred(*__first, *__i)) - *++__first = _IterOps<_AlgPolicy>::__iter_move(__i); - ++__first; - return std::pair<_Iter, _Iter>(std::move(__first), std::move(__i)); - } - return std::pair<_Iter, _Iter>(__first, __first); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { - return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -unique(_ForwardIterator __first, _ForwardIterator __last) { - return std::unique(__first, __last, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_UNIQUE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/unique_copy.h b/third_party/libcxx/include/c++/v1/__algorithm/unique_copy.h deleted file mode 100644 index 16ce80c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/unique_copy.h +++ /dev/null @@ -1,127 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_UNIQUE_COPY_H -#define _LIBCPP___ALGORITHM_UNIQUE_COPY_H - -#include <__algorithm/comp.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__type_traits/conditional.h> -#include <__type_traits/is_base_of.h> -#include <__type_traits/is_same.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __unique_copy_tags { - -struct __reread_from_input_tag {}; -struct __reread_from_output_tag {}; -struct __read_from_tmp_value_tag {}; - -} // namespace __unique_copy_tags - -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _OutputIterator> -__unique_copy(_InputIterator __first, - _Sent __last, - _OutputIterator __result, - _BinaryPredicate&& __pred, - __unique_copy_tags::__read_from_tmp_value_tag) { - if (__first != __last) { - typename _IterOps<_AlgPolicy>::template __value_type<_InputIterator> __t(*__first); - *__result = __t; - ++__result; - while (++__first != __last) { - if (!__pred(__t, *__first)) { - __t = *__first; - *__result = __t; - ++__result; - } - } - } - return pair<_InputIterator, _OutputIterator>(std::move(__first), std::move(__result)); -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _OutputIterator> -__unique_copy(_ForwardIterator __first, - _Sent __last, - _OutputIterator __result, - _BinaryPredicate&& __pred, - __unique_copy_tags::__reread_from_input_tag) { - if (__first != __last) { - _ForwardIterator __i = __first; - *__result = *__i; - ++__result; - while (++__first != __last) { - if (!__pred(*__i, *__first)) { - *__result = *__first; - ++__result; - __i = __first; - } - } - } - return pair<_ForwardIterator, _OutputIterator>(std::move(__first), std::move(__result)); -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _InputAndOutputIterator> -__unique_copy(_InputIterator __first, - _Sent __last, - _InputAndOutputIterator __result, - _BinaryPredicate&& __pred, - __unique_copy_tags::__reread_from_output_tag) { - if (__first != __last) { - *__result = *__first; - while (++__first != __last) - if (!__pred(*__result, *__first)) - *++__result = *__first; - ++__result; - } - return pair<_InputIterator, _InputAndOutputIterator>(std::move(__first), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) { - using __algo_tag = __conditional_t< - is_base_of::iterator_category>::value, - __unique_copy_tags::__reread_from_input_tag, - __conditional_t< - is_base_of::iterator_category>::value && - is_same< typename iterator_traits<_InputIterator>::value_type, - typename iterator_traits<_OutputIterator>::value_type>::value, - __unique_copy_tags::__reread_from_output_tag, - __unique_copy_tags::__read_from_tmp_value_tag> >; - return std::__unique_copy<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), std::move(__result), __pred, __algo_tag()) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::unique_copy(std::move(__first), std::move(__last), std::move(__result), __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_UNIQUE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/unwrap_iter.h b/third_party/libcxx/include/c++/v1/__algorithm/unwrap_iter.h deleted file mode 100644 index ea862cd..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/unwrap_iter.h +++ /dev/null @@ -1,83 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_UNWRAP_ITER_H -#define _LIBCPP___ALGORITHM_UNWRAP_ITER_H - -#include <__config> -#include <__iterator/iterator_traits.h> -#include <__memory/pointer_traits.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_constructible.h> -#include <__utility/declval.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// TODO: Change the name of __unwrap_iter_impl to something more appropriate -// The job of __unwrap_iter is to remove iterator wrappers (like reverse_iterator or __wrap_iter), -// to reduce the number of template instantiations and to enable pointer-based optimizations e.g. in std::copy. -// -// Some algorithms (e.g. std::copy, but not std::sort) need to convert an -// "unwrapped" result back into the original iterator type. Doing that is the job of __rewrap_iter. - -// Default case - we can't unwrap anything -template ::value> -struct __unwrap_iter_impl { - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter, _Iter __iter) { return __iter; } - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __unwrap(_Iter __i) _NOEXCEPT { return __i; } -}; - -// TODO(hardening): make sure that the following unwrapping doesn't unexpectedly turn hardened iterators into raw -// pointers. - -// It's a contiguous iterator, so we can use a raw pointer instead -template -struct __unwrap_iter_impl<_Iter, true> { - using _ToAddressT _LIBCPP_NODEBUG = decltype(std::__to_address(std::declval<_Iter>())); - - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter __orig_iter, _ToAddressT __unwrapped_iter) { - return __orig_iter + (__unwrapped_iter - std::__to_address(__orig_iter)); - } - - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToAddressT __unwrap(_Iter __i) _NOEXCEPT { - return std::__to_address(__i); - } -}; - -template > -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 decltype(_Impl::__unwrap(std::declval<_Iter>())) -__unwrap_iter(_Iter __i) _NOEXCEPT { -// Allow input_iterators to be passed to __unwrap_iter (but not __rewrap_iter) -#if _LIBCPP_STD_VER >= 20 - if constexpr (!is_copy_constructible_v<_Iter>) { - return __i; - } else -#endif - { - return _Impl::__unwrap(__i); - } -} - -template > -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _OrigIter __rewrap_iter(_OrigIter __orig_iter, _Iter __iter) _NOEXCEPT { - return _Impl::__rewrap(std::move(__orig_iter), std::move(__iter)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_UNWRAP_ITER_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/unwrap_range.h b/third_party/libcxx/include/c++/v1/__algorithm/unwrap_range.h deleted file mode 100644 index c46094f..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/unwrap_range.h +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_UNWRAP_RANGE_H -#define _LIBCPP___ALGORITHM_UNWRAP_RANGE_H - -#include <__algorithm/unwrap_iter.h> -#include <__config> -#include <__iterator/concepts.h> -#include <__type_traits/is_same.h> -#include <__utility/declval.h> -#include <__utility/move.h> -#include <__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __unwrap_range and __rewrap_range are used to unwrap ranges which may have different iterator and sentinel types. -// __unwrap_iter and __rewrap_iter don't work for this, because they assume that the iterator and sentinel have -// the same type. __unwrap_range tries to get two iterators and then forward to __unwrap_iter. - -#if _LIBCPP_STD_VER >= 20 -template -_LIBCPP_HIDE_FROM_ABI constexpr auto __unwrap_range(_Iter __first, _Sent __last) { - if constexpr (is_same_v<_Iter, _Sent>) - return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))}; - else if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) { - auto __iter_last = __first + (__last - __first); - return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__iter_last))}; - } else - return pair{std::move(__first), std::move(__last)}; -} - -template < class _Sent, class _Iter, class _Unwrapped> -_LIBCPP_HIDE_FROM_ABI constexpr _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) { - if constexpr (is_same_v<_Iter, _Sent>) - return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); - else if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) - return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); - else - return __iter; -} -#else // _LIBCPP_STD_VER >= 20 -template ()))> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR pair<_Unwrapped, _Unwrapped> __unwrap_range(_Iter __first, _Iter __last) { - return std::make_pair(std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))); -} - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) { - return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); -} -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_UNWRAP_RANGE_H diff --git a/third_party/libcxx/include/c++/v1/__algorithm/upper_bound.h b/third_party/libcxx/include/c++/v1/__algorithm/upper_bound.h deleted file mode 100644 index d77286c..0000000 --- a/third_party/libcxx/include/c++/v1/__algorithm/upper_bound.h +++ /dev/null @@ -1,71 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ALGORITHM_UPPER_BOUND_H -#define _LIBCPP___ALGORITHM_UPPER_BOUND_H - -#include <__algorithm/comp.h> -#include <__algorithm/half_positive.h> -#include <__algorithm/iterator_operations.h> -#include <__config> -#include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/advance.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__type_traits/invoke.h> -#include <__type_traits/is_callable.h> -#include <__type_traits/is_constructible.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter -__upper_bound(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) { - auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); - while (__len != 0) { - auto __half_len = std::__half_positive(__len); - auto __mid = _IterOps<_AlgPolicy>::next(__first, __half_len); - if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid))) - __len = __half_len; - else { - __first = ++__mid; - __len -= __half_len + 1; - } - } - return __first; -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(__is_callable<_Compare&, const _Tp&, decltype(*__first)>::value, "The comparator has to be callable"); - static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); - return std::__upper_bound<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), __value, std::move(__comp), std::__identity()); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator -upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::upper_bound(std::move(__first), std::move(__last), __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___ALGORITHM_UPPER_BOUND_H diff --git a/third_party/libcxx/include/c++/v1/__assert b/third_party/libcxx/include/c++/v1/__assert deleted file mode 100644 index a9451da..0000000 --- a/third_party/libcxx/include/c++/v1/__assert +++ /dev/null @@ -1,118 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ASSERT -#define _LIBCPP___ASSERT - -#include <__assertion_handler> // Note: this include is generated by CMake and is potentially vendor-provided. -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define _LIBCPP_ASSERT(expression, message) \ - (__builtin_expect(static_cast(expression), 1) \ - ? (void)0 \ - : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING( \ - __LINE__) ": libc++ Hardening assertion " _LIBCPP_TOSTRING(expression) " failed: " message "\n")) - -// WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear -// optimization intent. See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a -// discussion. -#if __has_builtin(__builtin_assume) -# define _LIBCPP_ASSUME(expression) \ - (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \ - __builtin_assume(static_cast(expression)) _LIBCPP_DIAGNOSTIC_POP) -#else -# define _LIBCPP_ASSUME(expression) ((void)0) -#endif - -// clang-format off -// Fast hardening mode checks. - -#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST - -// Enabled checks. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) -// Disabled checks. -// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access. -# define _LIBCPP_ASSERT_NON_NULL(expression, message) ((void)0) -// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security -// vulnerability. -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) ((void)0) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) ((void)0) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) ((void)0) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) ((void)0) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) ((void)0) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) ((void)0) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) ((void)0) - -// Extensive hardening mode checks. - -#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE - -// Enabled checks. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) -// Disabled checks. -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0) - -// Debug hardening mode checks. - -#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG - -// All checks enabled. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) - -// Disable all checks if hardening is not enabled. - -#else - -// All checks disabled. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) ((void)0) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) ((void)0) -# define _LIBCPP_ASSERT_NON_NULL(expression, message) ((void)0) -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) ((void)0) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) ((void)0) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) ((void)0) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) ((void)0) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) ((void)0) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) ((void)0) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) ((void)0) - -#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST -// clang-format on - -#endif // _LIBCPP___ASSERT diff --git a/third_party/libcxx/include/c++/v1/__assertion_handler b/third_party/libcxx/include/c++/v1/__assertion_handler deleted file mode 100644 index d352405..0000000 --- a/third_party/libcxx/include/c++/v1/__assertion_handler +++ /dev/null @@ -1,64 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ASSERTION_HANDLER -#define _LIBCPP___ASSERTION_HANDLER - -#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) -# include <__cxx03/__config> -# include <__cxx03/__verbose_abort> -# include <__cxx03/__verbose_trap> -#else -# include <__config> -# include <__log_hardening_failure> -# include <__verbose_abort> -# include <__verbose_trap> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) - -// Keep the old implementation that doesn't support assertion semantics for backward compatibility with the frozen C++03 -// mode. -# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_ABORT("%s", message) -# else -# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_TRAP(message) -# endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG - -#else - -# if _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_IGNORE -# define _LIBCPP_ASSERTION_HANDLER(message) ((void)0) - -# elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_OBSERVE -# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_LOG_HARDENING_FAILURE(message) - -# elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE -# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_TRAP(message) - -# elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_ENFORCE -# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_ABORT("%s", message) - -# else - -# error _LIBCPP_ASSERTION_SEMANTIC must be set to one of the following values: \ -_LIBCPP_ASSERTION_SEMANTIC_IGNORE, \ -_LIBCPP_ASSERTION_SEMANTIC_OBSERVE, \ -_LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE, \ -_LIBCPP_ASSERTION_SEMANTIC_ENFORCE - -# endif // _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_IGNORE - -#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) - -#endif // _LIBCPP___ASSERTION_HANDLER diff --git a/third_party/libcxx/include/c++/v1/__atomic/aliases.h b/third_party/libcxx/include/c++/v1/__atomic/aliases.h deleted file mode 100644 index 4fcceba..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/aliases.h +++ /dev/null @@ -1,111 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ALIASES_H -#define _LIBCPP___ATOMIC_ALIASES_H - -#include <__atomic/atomic.h> -#include <__atomic/atomic_lock_free.h> -#include <__atomic/contention_t.h> -#include <__atomic/is_always_lock_free.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__cstddef/size_t.h> -#include <__type_traits/conditional.h> -#include <__type_traits/make_unsigned.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -using atomic_bool = atomic; -using atomic_char = atomic; -using atomic_schar = atomic; -using atomic_uchar = atomic; -using atomic_short = atomic; -using atomic_ushort = atomic; -using atomic_int = atomic; -using atomic_uint = atomic; -using atomic_long = atomic; -using atomic_ulong = atomic; -using atomic_llong = atomic; -using atomic_ullong = atomic; -#if _LIBCPP_HAS_CHAR8_T -using atomic_char8_t = atomic; -#endif -using atomic_char16_t = atomic; -using atomic_char32_t = atomic; -#if _LIBCPP_HAS_WIDE_CHARACTERS -using atomic_wchar_t = atomic; -#endif - -using atomic_int_least8_t = atomic; -using atomic_uint_least8_t = atomic; -using atomic_int_least16_t = atomic; -using atomic_uint_least16_t = atomic; -using atomic_int_least32_t = atomic; -using atomic_uint_least32_t = atomic; -using atomic_int_least64_t = atomic; -using atomic_uint_least64_t = atomic; - -using atomic_int_fast8_t = atomic; -using atomic_uint_fast8_t = atomic; -using atomic_int_fast16_t = atomic; -using atomic_uint_fast16_t = atomic; -using atomic_int_fast32_t = atomic; -using atomic_uint_fast32_t = atomic; -using atomic_int_fast64_t = atomic; -using atomic_uint_fast64_t = atomic; - -using atomic_int8_t = atomic< int8_t>; -using atomic_uint8_t = atomic; -using atomic_int16_t = atomic< int16_t>; -using atomic_uint16_t = atomic; -using atomic_int32_t = atomic< int32_t>; -using atomic_uint32_t = atomic; -using atomic_int64_t = atomic< int64_t>; -using atomic_uint64_t = atomic; - -using atomic_intptr_t = atomic; -using atomic_uintptr_t = atomic; -using atomic_size_t = atomic; -using atomic_ptrdiff_t = atomic; -using atomic_intmax_t = atomic; -using atomic_uintmax_t = atomic; - -// C++20 atomic_{signed,unsigned}_lock_free: prefer the contention type most highly, then the largest lock-free type -#if _LIBCPP_STD_VER >= 20 -# if ATOMIC_LLONG_LOCK_FREE == 2 -using __largest_lock_free_type _LIBCPP_NODEBUG = long long; -# elif ATOMIC_INT_LOCK_FREE == 2 -using __largest_lock_free_type _LIBCPP_NODEBUG = int; -# elif ATOMIC_SHORT_LOCK_FREE == 2 -using __largest_lock_free_type _LIBCPP_NODEBUG = short; -# elif ATOMIC_CHAR_LOCK_FREE == 2 -using __largest_lock_free_type _LIBCPP_NODEBUG = char; -# else -# define _LIBCPP_NO_LOCK_FREE_TYPES // There are no lockfree types (this can happen on unusual platforms) -# endif - -# ifndef _LIBCPP_NO_LOCK_FREE_TYPES -using __contention_t_or_largest _LIBCPP_NODEBUG = - __conditional_t<__libcpp_is_always_lock_free<__cxx_contention_t>::__value, - __cxx_contention_t, - __largest_lock_free_type>; - -using atomic_signed_lock_free = atomic<__contention_t_or_largest>; -using atomic_unsigned_lock_free = atomic>; -# endif // !_LIBCPP_NO_LOCK_FREE_TYPES -#endif // C++20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_ALIASES_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic.h b/third_party/libcxx/include/c++/v1/__atomic/atomic.h deleted file mode 100644 index 3d0ed9c..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic.h +++ /dev/null @@ -1,804 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_H -#define _LIBCPP___ATOMIC_ATOMIC_H - -#include <__atomic/atomic_sync.h> -#include <__atomic/atomic_waitable_traits.h> -#include <__atomic/check_memory_order.h> -#include <__atomic/floating_point_helper.h> -#include <__atomic/is_always_lock_free.h> -#include <__atomic/memory_order.h> -#include <__atomic/support.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__memory/addressof.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_floating_point.h> -#include <__type_traits/is_function.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_nothrow_constructible.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_trivially_copyable.h> -#include <__type_traits/remove_pointer.h> -#include <__utility/forward.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value && !is_same<_Tp, bool>::value> -struct __atomic_base // false -{ - mutable __cxx_atomic_impl<_Tp> __a_; - - using value_type = _Tp; - -#if _LIBCPP_STD_VER >= 17 - static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value; -#endif - - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT { - return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>)); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT { - return static_cast<__atomic_base const volatile*>(this)->is_lock_free(); - } - _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - std::__cxx_atomic_store(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - std::__cxx_atomic_store(std::addressof(__a_), __d, __m); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return std::__cxx_atomic_load(std::addressof(__a_), __m); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return std::__cxx_atomic_load(std::addressof(__a_), __m); - } - _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); } - _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); } - _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { - std::__atomic_wait(*this, __v, __m); - } - _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - std::__atomic_wait(*this, __v, __m); - } - _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { std::__atomic_notify_one(*this); } - _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); } - _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT { std::__atomic_notify_all(*this); } - _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); } -#endif // _LIBCPP_STD_VER >= 20 - -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI constexpr __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {} -#else - _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default; -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} - - __atomic_base(const __atomic_base&) = delete; -}; - -// atomic - -template -struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> { - using __base _LIBCPP_NODEBUG = __atomic_base<_Tp, false>; - - using difference_type = typename __base::value_type; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; } -}; - -#if _LIBCPP_STD_VER >= 20 -// Here we need _IsIntegral because the default template argument is not enough -// e.g __atomic_base is __atomic_base, which inherits from -// __atomic_base and the caller of the wait function is -// __atomic_base. So specializing __atomic_base<_Tp> does not work -template -struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > { - using __value_type _LIBCPP_NODEBUG = _Tp; - - static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_base<_Tp, _IsIntegral>& __a, memory_order __order) { - return __a.load(__order); - } - - static _LIBCPP_HIDE_FROM_ABI _Tp - __atomic_load(const volatile __atomic_base<_Tp, _IsIntegral>& __this, memory_order __order) { - return __this.load(__order); - } - - static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_Tp>* - __atomic_contention_address(const __atomic_base<_Tp, _IsIntegral>& __a) { - return std::addressof(__a.__a_); - } - - static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_Tp>* - __atomic_contention_address(const volatile __atomic_base<_Tp, _IsIntegral>& __this) { - return std::addressof(__this.__a_); - } -}; - -#endif // _LIBCPP_STD_VER >= 20 - -template -struct __check_atomic_mandates { - using type _LIBCPP_NODEBUG = _Tp; - static_assert(is_trivially_copyable<_Tp>::value, "std::atomic requires that 'T' be a trivially copyable type"); -}; - -template -struct atomic : public __atomic_base::type> { - using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>; - -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI atomic() = default; -#else - _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default; -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} - - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile _NOEXCEPT { - __base::store(__d); - return __d; - } - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) _NOEXCEPT { - __base::store(__d); - return __d; - } - - atomic& operator=(const atomic&) = delete; - atomic& operator=(const atomic&) volatile = delete; -}; - -// atomic - -template -struct atomic<_Tp*> : public __atomic_base<_Tp*> { - using __base _LIBCPP_NODEBUG = __atomic_base<_Tp*>; - - using difference_type = ptrdiff_t; - - _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} - - _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) volatile _NOEXCEPT { - __base::store(__d); - return __d; - } - _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) _NOEXCEPT { - __base::store(__d); - return __d; - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - // __atomic_fetch_sub accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - // __atomic_fetch_sub accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) volatile _NOEXCEPT { return fetch_add(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) _NOEXCEPT { return fetch_add(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) volatile _NOEXCEPT { return fetch_sub(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) _NOEXCEPT { return fetch_sub(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator++() volatile _NOEXCEPT { return fetch_add(1) + 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator++() _NOEXCEPT { return fetch_add(1) + 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--() volatile _NOEXCEPT { return fetch_sub(1) - 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--() _NOEXCEPT { return fetch_sub(1) - 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT { return fetch_sub(__op) - __op; } - - atomic& operator=(const atomic&) = delete; - atomic& operator=(const atomic&) volatile = delete; -}; - -#if _LIBCPP_STD_VER >= 20 -template -struct __atomic_waitable_traits > : __atomic_waitable_traits<__atomic_base<_Tp> > {}; - -template - requires is_floating_point_v<_Tp> -struct atomic<_Tp> : __atomic_base<_Tp> { -private: - template - _LIBCPP_HIDE_FROM_ABI static _Tp - __rmw_op(_This&& __self, _Tp __operand, memory_order __m, _Operation __operation, _BuiltinOp __builtin_op) { - if constexpr (std::__has_rmw_builtin<_Tp>()) { - return __builtin_op(std::addressof(std::forward<_This>(__self).__a_), __operand, __m); - } else { - _Tp __old = __self.load(memory_order_relaxed); - _Tp __new = __operation(__old, __operand); - while (!__self.compare_exchange_weak(__old, __new, __m, memory_order_relaxed)) { -# ifdef _LIBCPP_COMPILER_CLANG_BASED - if constexpr (std::__is_fp80_long_double<_Tp>()) { - // https://llvm.org/PR47978 - // clang bug: __old is not updated on failure for atomic::compare_exchange_weak - // Note __old = __self.load(memory_order_relaxed) will not work - std::__cxx_atomic_load_inplace(std::addressof(__self.__a_), std::addressof(__old), memory_order_relaxed); - } -# endif - __new = __operation(__old, __operand); - } - return __old; - } - } - - template - _LIBCPP_HIDE_FROM_ABI static _Tp __fetch_add(_This&& __self, _Tp __operand, memory_order __m) { - auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) { - return std::__cxx_atomic_fetch_add(__a, __builtin_operand, __order); - }; - auto __plus = [](auto __a, auto __b) { return __a + __b; }; - return __rmw_op(std::forward<_This>(__self), __operand, __m, __plus, __builtin_op); - } - - template - _LIBCPP_HIDE_FROM_ABI static _Tp __fetch_sub(_This&& __self, _Tp __operand, memory_order __m) { - auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) { - return std::__cxx_atomic_fetch_sub(__a, __builtin_operand, __order); - }; - auto __minus = [](auto __a, auto __b) { return __a - __b; }; - return __rmw_op(std::forward<_This>(__self), __operand, __m, __minus, __builtin_op); - } - -public: - using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>; - using value_type = _Tp; - using difference_type = value_type; - - _LIBCPP_HIDE_FROM_ABI constexpr atomic() noexcept = default; - _LIBCPP_HIDE_FROM_ABI constexpr atomic(_Tp __d) noexcept : __base(__d) {} - - atomic(const atomic&) = delete; - atomic& operator=(const atomic&) = delete; - atomic& operator=(const atomic&) volatile = delete; - - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile noexcept - requires __base::is_always_lock_free - { - __base::store(__d); - return __d; - } - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) noexcept { - __base::store(__d); - return __d; - } - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile noexcept - requires __base::is_always_lock_free - { - return __fetch_add(*this, __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) noexcept { - return __fetch_add(*this, __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile noexcept - requires __base::is_always_lock_free - { - return __fetch_sub(*this, __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) noexcept { - return __fetch_sub(*this, __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile noexcept - requires __base::is_always_lock_free - { - return fetch_add(__op) + __op; - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) noexcept { return fetch_add(__op) + __op; } - - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile noexcept - requires __base::is_always_lock_free - { - return fetch_sub(__op) - __op; - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) noexcept { return fetch_sub(__op) - __op; } -}; - -#endif // _LIBCPP_STD_VER >= 20 - -// atomic_is_lock_free - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT { - return __o->is_lock_free(); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT { - return __o->is_lock_free(); -} - -// atomic_init - -template -_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void -atomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - std::__cxx_atomic_init(std::addressof(__o->__a_), __d); -} - -template -_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void -atomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - std::__cxx_atomic_init(std::addressof(__o->__a_), __d); -} - -// atomic_store - -template -_LIBCPP_HIDE_FROM_ABI void atomic_store(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - __o->store(__d); -} - -template -_LIBCPP_HIDE_FROM_ABI void atomic_store(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - __o->store(__d); -} - -// atomic_store_explicit - -template -_LIBCPP_HIDE_FROM_ABI void -atomic_store_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - __o->store(__d, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI void -atomic_store_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - __o->store(__d, __m); -} - -// atomic_load - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT { - return __o->load(); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const atomic<_Tp>* __o) _NOEXCEPT { - return __o->load(); -} - -// atomic_load_explicit - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp -atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->load(__m); -} - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->load(__m); -} - -// atomic_exchange - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->exchange(__d); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->exchange(__d); -} - -// atomic_exchange_explicit - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_exchange_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT { - return __o->exchange(__d, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_exchange_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT { - return __o->exchange(__d, __m); -} - -// atomic_compare_exchange_weak - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_weak(*__e, __d); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak( - atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_weak(*__e, __d); -} - -// atomic_compare_exchange_strong - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_strong(*__e, __d); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong( - atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_strong(*__e, __d); -} - -// atomic_compare_exchange_weak_explicit - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( - volatile atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_weak(*__e, __d, __s, __f); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( - atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_weak(*__e, __d, __s, __f); -} - -// atomic_compare_exchange_strong_explicit - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( - volatile atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_strong(*__e, __d, __s, __f); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( - atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_strong(*__e, __d, __s, __f); -} - -#if _LIBCPP_STD_VER >= 20 - -// atomic_wait - -template -_LIBCPP_HIDE_FROM_ABI void -atomic_wait(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) _NOEXCEPT { - return __o->wait(__v); -} - -template -_LIBCPP_HIDE_FROM_ABI void atomic_wait(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) _NOEXCEPT { - return __o->wait(__v); -} - -// atomic_wait_explicit - -template -_LIBCPP_HIDE_FROM_ABI void -atomic_wait_explicit(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->wait(__v, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI void -atomic_wait_explicit(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->wait(__v, __m); -} - -// atomic_notify_one - -template -_LIBCPP_HIDE_FROM_ABI void atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_one(); -} -template -_LIBCPP_HIDE_FROM_ABI void atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_one(); -} - -// atomic_notify_all - -template -_LIBCPP_HIDE_FROM_ABI void atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_all(); -} -template -_LIBCPP_HIDE_FROM_ABI void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_all(); -} - -#endif // _LIBCPP_STD_VER >= 20 - -// atomic_fetch_add - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_add(__op); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_add(__op); -} - -// atomic_fetch_add_explicit - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_add(__op, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_add(__op, __m); -} - -// atomic_fetch_sub - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_sub(__op); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_sub(__op); -} - -// atomic_fetch_sub_explicit - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_sub(__op, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_sub(__op, __m); -} - -// atomic_fetch_and - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_and(__op); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_and(__op); -} - -// atomic_fetch_and_explicit - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_and(__op, __m); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_and_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_and(__op, __m); -} - -// atomic_fetch_or - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_or(__op); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_or(__op); -} - -// atomic_fetch_or_explicit - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_or(__op, __m); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_or_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_or(__op, __m); -} - -// atomic_fetch_xor - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_xor(__op); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_xor(__op); -} - -// atomic_fetch_xor_explicit - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_xor(__op, __m); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_xor_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_xor(__op, __m); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_ATOMIC_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic_flag.h b/third_party/libcxx/include/c++/v1/__atomic/atomic_flag.h deleted file mode 100644 index 7c09870..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic_flag.h +++ /dev/null @@ -1,165 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_FLAG_H -#define _LIBCPP___ATOMIC_ATOMIC_FLAG_H - -#include <__atomic/atomic_sync.h> -#include <__atomic/atomic_waitable_traits.h> -#include <__atomic/memory_order.h> -#include <__atomic/support.h> -#include <__config> -#include <__memory/addressof.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -struct atomic_flag { - __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_; - - _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { - return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m); - } - _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m); - } - - _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m); - } - _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m); - } - _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m); - } - _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT { - __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m); - } - -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { - std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); - } - _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); - } - _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { std::__atomic_notify_one(*this); } - _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); } - _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT { std::__atomic_notify_all(*this); } - _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); } -#endif - -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI constexpr atomic_flag() _NOEXCEPT : __a_(false) {} -#else - atomic_flag() _NOEXCEPT = default; -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION - - atomic_flag(const atomic_flag&) = delete; - atomic_flag& operator=(const atomic_flag&) = delete; - atomic_flag& operator=(const atomic_flag&) volatile = delete; -}; - -#if _LIBCPP_STD_VER >= 20 -template <> -struct __atomic_waitable_traits { - using __value_type _LIBCPP_NODEBUG = _LIBCPP_ATOMIC_FLAG_TYPE; - - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATOMIC_FLAG_TYPE __atomic_load(const atomic_flag& __a, memory_order __order) { - return std::__cxx_atomic_load(&__a.__a_, __order); - } - - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATOMIC_FLAG_TYPE - __atomic_load(const volatile atomic_flag& __a, memory_order __order) { - return std::__cxx_atomic_load(&__a.__a_, __order); - } - - static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE>* - __atomic_contention_address(const atomic_flag& __a) { - return std::addressof(__a.__a_); - } - - static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE>* - __atomic_contention_address(const volatile atomic_flag& __a) { - return std::addressof(__a.__a_); - } -}; -#endif // _LIBCPP_STD_VER >= 20 - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test(const volatile atomic_flag* __o) _NOEXCEPT { return __o->test(); } - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test(const atomic_flag* __o) _NOEXCEPT { return __o->test(); } - -inline _LIBCPP_HIDE_FROM_ABI bool -atomic_flag_test_explicit(const volatile atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_explicit(const atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT { - return __o->test_and_set(); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT { return __o->test_and_set(); } - -inline _LIBCPP_HIDE_FROM_ABI bool -atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test_and_set(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test_and_set(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT { __o->clear(); } - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear(atomic_flag* __o) _NOEXCEPT { __o->clear(); } - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT { - __o->clear(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT { - __o->clear(__m); -} - -#if _LIBCPP_STD_VER >= 20 -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT { - __o->wait(__v); -} - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT { __o->wait(__v); } - -inline _LIBCPP_HIDE_FROM_ABI void -atomic_flag_wait_explicit(const volatile atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT { - __o->wait(__v, __m); -} - -inline _LIBCPP_HIDE_FROM_ABI void -atomic_flag_wait_explicit(const atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT { - __o->wait(__v, __m); -} - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT { __o->notify_one(); } -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT { __o->notify_one(); } -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT { __o->notify_all(); } -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT { __o->notify_all(); } -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_ATOMIC_FLAG_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic_init.h b/third_party/libcxx/include/c++/v1/__atomic/atomic_init.h deleted file mode 100644 index 8e86ba3..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic_init.h +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_INIT_H -#define _LIBCPP___ATOMIC_ATOMIC_INIT_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define ATOMIC_FLAG_INIT {false} -#define ATOMIC_VAR_INIT(__v) {__v} - -#if _LIBCPP_STD_VER >= 20 && defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) -# pragma clang deprecated(ATOMIC_VAR_INIT) -#endif - -#endif // _LIBCPP___ATOMIC_ATOMIC_INIT_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic_lock_free.h b/third_party/libcxx/include/c++/v1/__atomic/atomic_lock_free.h deleted file mode 100644 index 3ae9b88..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic_lock_free.h +++ /dev/null @@ -1,48 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_LOCK_FREE_H -#define _LIBCPP___ATOMIC_ATOMIC_LOCK_FREE_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) -# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE -# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE -# if _LIBCPP_HAS_CHAR8_T -# define ATOMIC_CHAR8_T_LOCK_FREE __CLANG_ATOMIC_CHAR8_T_LOCK_FREE -# endif -# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE -# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE -# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE -# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE -# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE -# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE -# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE -# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE -#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE) -# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE -# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE -# if _LIBCPP_HAS_CHAR8_T -# define ATOMIC_CHAR8_T_LOCK_FREE __GCC_ATOMIC_CHAR8_T_LOCK_FREE -# endif -# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE -# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE -# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE -# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE -# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE -# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE -# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE -# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE -#endif - -#endif // _LIBCPP___ATOMIC_ATOMIC_LOCK_FREE_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic_ref.h b/third_party/libcxx/include/c++/v1/__atomic/atomic_ref.h deleted file mode 100644 index c551f99..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic_ref.h +++ /dev/null @@ -1,398 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// Kokkos v. 4.0 -// Copyright (2022) National Technology & Engineering -// Solutions of Sandia, LLC (NTESS). -// -// Under the terms of Contract DE-NA0003525 with NTESS, -// the U.S. Government retains certain rights in this software. -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_REF_H -#define _LIBCPP___ATOMIC_ATOMIC_REF_H - -#include <__assert> -#include <__atomic/atomic_sync.h> -#include <__atomic/atomic_waitable_traits.h> -#include <__atomic/check_memory_order.h> -#include <__atomic/floating_point_helper.h> -#include <__atomic/memory_order.h> -#include <__atomic/to_gcc_order.h> -#include <__concepts/arithmetic.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__cstddef/byte.h> -#include <__cstddef/ptrdiff_t.h> -#include <__memory/addressof.h> -#include <__memory/is_sufficiently_aligned.h> -#include <__type_traits/copy_cv.h> -#include <__type_traits/has_unique_object_representation.h> -#include <__type_traits/is_trivially_copyable.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// These types are required to make __atomic_is_always_lock_free work across GCC and Clang. -// The purpose of this trick is to make sure that we provide an object with the correct alignment -// to __atomic_is_always_lock_free, since that answer depends on the alignment. -template -struct __alignment_checker_type { - alignas(_Alignment) char __data; -}; - -template -struct __get_aligner_instance { - static constexpr __alignment_checker_type<_Alignment> __instance{}; -}; - -template -struct __atomic_ref_base { -private: - _LIBCPP_HIDE_FROM_ABI static _Tp* __clear_padding(_Tp& __val) noexcept { - _Tp* __ptr = std::addressof(__val); -# if __has_builtin(__builtin_clear_padding) - __builtin_clear_padding(__ptr); -# endif - return __ptr; - } - - _LIBCPP_HIDE_FROM_ABI static bool __compare_exchange( - _Tp* __ptr, _Tp* __expected, _Tp* __desired, bool __is_weak, int __success, int __failure) noexcept { - if constexpr ( -# if __has_builtin(__builtin_clear_padding) - has_unique_object_representations_v<_Tp> || floating_point<_Tp> -# else - true // NOLINT(readability-simplify-boolean-expr) -# endif - ) { - return __atomic_compare_exchange(__ptr, __expected, __desired, __is_weak, __success, __failure); - } else { // _Tp has padding bits and __builtin_clear_padding is available - __clear_padding(*__desired); - _Tp __copy = *__expected; - __clear_padding(__copy); - // The algorithm we use here is basically to perform `__atomic_compare_exchange` on the - // values until it has either succeeded, or failed because the value representation of the - // objects involved was different. This is why we loop around __atomic_compare_exchange: - // we basically loop until its failure is caused by the value representation of the objects - // being different, not only their object representation. - while (true) { - _Tp __prev = __copy; - if (__atomic_compare_exchange(__ptr, std::addressof(__copy), __desired, __is_weak, __success, __failure)) { - return true; - } - _Tp __curr = __copy; - if (std::memcmp(__clear_padding(__prev), __clear_padding(__curr), sizeof(_Tp)) != 0) { - // Value representation without padding bits do not compare equal -> - // write the current content of *ptr into *expected - std::memcpy(__expected, std::addressof(__copy), sizeof(_Tp)); - return false; - } - } - } - } - - friend struct __atomic_waitable_traits<__atomic_ref_base<_Tp>>; - - // require types that are 1, 2, 4, 8, or 16 bytes in length to be aligned to at least their size to be potentially - // used lock-free - static constexpr size_t __min_alignment = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || (sizeof(_Tp) > 16) ? 0 : sizeof(_Tp); - -public: - using value_type = _Tp; - - static constexpr size_t required_alignment = alignof(_Tp) > __min_alignment ? alignof(_Tp) : __min_alignment; - - // The __atomic_always_lock_free builtin takes into account the alignment of the pointer if provided, - // so we create a fake pointer with a suitable alignment when querying it. Note that we are guaranteed - // that the pointer is going to be aligned properly at runtime because that is a (checked) precondition - // of atomic_ref's constructor. - static constexpr bool is_always_lock_free = - __atomic_always_lock_free(sizeof(_Tp), std::addressof(__get_aligner_instance::__instance)); - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const noexcept { - return __atomic_is_lock_free(sizeof(_Tp), __ptr_); - } - - _LIBCPP_HIDE_FROM_ABI void store(_Tp __desired, memory_order __order = memory_order::seq_cst) const noexcept - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__order) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __order == memory_order::relaxed || __order == memory_order::release || __order == memory_order::seq_cst, - "atomic_ref: memory order argument to atomic store operation is invalid"); - __atomic_store(__ptr_, __clear_padding(__desired), std::__to_gcc_order(__order)); - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { - store(__desired); - return __desired; - } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __order = memory_order::seq_cst) const noexcept - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__order) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __order == memory_order::relaxed || __order == memory_order::consume || __order == memory_order::acquire || - __order == memory_order::seq_cst, - "atomic_ref: memory order argument to atomic load operation is invalid"); - alignas(_Tp) byte __mem[sizeof(_Tp)]; - auto* __ret = reinterpret_cast<_Tp*>(__mem); - __atomic_load(__ptr_, __ret, std::__to_gcc_order(__order)); - return *__ret; - } - - _LIBCPP_HIDE_FROM_ABI operator _Tp() const noexcept { return load(); } - - _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __desired, memory_order __order = memory_order::seq_cst) const noexcept { - alignas(_Tp) byte __mem[sizeof(_Tp)]; - auto* __ret = reinterpret_cast<_Tp*>(__mem); - __atomic_exchange(__ptr_, __clear_padding(__desired), __ret, std::__to_gcc_order(__order)); - return *__ret; - } - - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __expected, _Tp __desired, memory_order __success, memory_order __failure) const noexcept - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__success, __failure) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __failure == memory_order::relaxed || __failure == memory_order::consume || - __failure == memory_order::acquire || __failure == memory_order::seq_cst, - "atomic_ref: failure memory order argument to weak atomic compare-and-exchange operation is invalid"); - return __compare_exchange( - __ptr_, - std::addressof(__expected), - std::addressof(__desired), - true, - std::__to_gcc_order(__success), - std::__to_gcc_order(__failure)); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __expected, _Tp __desired, memory_order __success, memory_order __failure) const noexcept - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__success, __failure) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __failure == memory_order::relaxed || __failure == memory_order::consume || - __failure == memory_order::acquire || __failure == memory_order::seq_cst, - "atomic_ref: failure memory order argument to strong atomic compare-and-exchange operation is invalid"); - return __compare_exchange( - __ptr_, - std::addressof(__expected), - std::addressof(__desired), - false, - std::__to_gcc_order(__success), - std::__to_gcc_order(__failure)); - } - - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __expected, _Tp __desired, memory_order __order = memory_order::seq_cst) const noexcept { - return __compare_exchange( - __ptr_, - std::addressof(__expected), - std::addressof(__desired), - true, - std::__to_gcc_order(__order), - std::__to_gcc_failure_order(__order)); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __expected, _Tp __desired, memory_order __order = memory_order::seq_cst) const noexcept { - return __compare_exchange( - __ptr_, - std::addressof(__expected), - std::addressof(__desired), - false, - std::__to_gcc_order(__order), - std::__to_gcc_failure_order(__order)); - } - - _LIBCPP_HIDE_FROM_ABI void wait(_Tp __old, memory_order __order = memory_order::seq_cst) const noexcept - _LIBCPP_CHECK_WAIT_MEMORY_ORDER(__order) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __order == memory_order::relaxed || __order == memory_order::consume || __order == memory_order::acquire || - __order == memory_order::seq_cst, - "atomic_ref: memory order argument to atomic wait operation is invalid"); - std::__atomic_wait(*this, __old, __order); - } - _LIBCPP_HIDE_FROM_ABI void notify_one() const noexcept { std::__atomic_notify_one(*this); } - _LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { std::__atomic_notify_all(*this); } -# if _LIBCPP_STD_VER >= 26 - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __copy_cv_t<_Tp, void>* address() const noexcept { return __ptr_; } -# endif - -protected: - using _Aligned_Tp [[__gnu__::__aligned__(required_alignment), __gnu__::__nodebug__]] = _Tp; - _Aligned_Tp* __ptr_; - - _LIBCPP_HIDE_FROM_ABI __atomic_ref_base(_Tp& __obj) : __ptr_(std::addressof(__obj)) {} -}; - -template -struct __atomic_waitable_traits<__atomic_ref_base<_Tp>> { - using __value_type _LIBCPP_NODEBUG = _Tp; - - static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_ref_base<_Tp>& __a, memory_order __order) { - return __a.load(__order); - } - static _LIBCPP_HIDE_FROM_ABI const _Tp* __atomic_contention_address(const __atomic_ref_base<_Tp>& __a) { - return __a.__ptr_; - } -}; - -template -struct atomic_ref : public __atomic_ref_base<_Tp> { - static_assert(is_trivially_copyable_v<_Tp>, "std::atomic_ref requires that 'T' be a trivially copyable type"); - - using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>; - - _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - std::__is_sufficiently_aligned<__base::required_alignment>(std::addressof(__obj)), - "atomic_ref ctor: referenced object must be aligned to required_alignment"); - } - - _LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default; - - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); } - - atomic_ref& operator=(const atomic_ref&) = delete; -}; - -template - requires(std::integral<_Tp> && !std::same_as) -struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { - using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>; - - using difference_type = __base::value_type; - - _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - std::__is_sufficiently_aligned<__base::required_alignment>(std::addressof(__obj)), - "atomic_ref ctor: referenced object must be aligned to required_alignment"); - } - - _LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default; - - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); } - - atomic_ref& operator=(const atomic_ref&) = delete; - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { - return __atomic_fetch_add(this->__ptr_, __arg, std::__to_gcc_order(__order)); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { - return __atomic_fetch_sub(this->__ptr_, __arg, std::__to_gcc_order(__order)); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { - return __atomic_fetch_and(this->__ptr_, __arg, std::__to_gcc_order(__order)); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { - return __atomic_fetch_or(this->__ptr_, __arg, std::__to_gcc_order(__order)); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { - return __atomic_fetch_xor(this->__ptr_, __arg, std::__to_gcc_order(__order)); - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) const noexcept { return fetch_add(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) const noexcept { return fetch_sub(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++() const noexcept { return fetch_add(_Tp(1)) + _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--() const noexcept { return fetch_sub(_Tp(1)) - _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __arg) const noexcept { return fetch_add(__arg) + __arg; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __arg) const noexcept { return fetch_sub(__arg) - __arg; } - _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __arg) const noexcept { return fetch_and(__arg) & __arg; } - _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __arg) const noexcept { return fetch_or(__arg) | __arg; } - _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __arg) const noexcept { return fetch_xor(__arg) ^ __arg; } -}; - -template - requires std::floating_point<_Tp> -struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { - using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>; - - using difference_type = __base::value_type; - - _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - std::__is_sufficiently_aligned<__base::required_alignment>(std::addressof(__obj)), - "atomic_ref ctor: referenced object must be aligned to required_alignment"); - } - - _LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default; - - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); } - - atomic_ref& operator=(const atomic_ref&) = delete; - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { - if constexpr (std::__has_rmw_builtin<_Tp>()) { - return __atomic_fetch_add(this->__ptr_, __arg, std::__to_gcc_order(__order)); - } else { - _Tp __old = this->load(memory_order_relaxed); - _Tp __new = __old + __arg; - while (!this->compare_exchange_weak(__old, __new, __order, memory_order_relaxed)) { - __new = __old + __arg; - } - return __old; - } - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept { - if constexpr (std::__has_rmw_builtin<_Tp>()) { - return __atomic_fetch_sub(this->__ptr_, __arg, std::__to_gcc_order(__order)); - } else { - _Tp __old = this->load(memory_order_relaxed); - _Tp __new = __old - __arg; - while (!this->compare_exchange_weak(__old, __new, __order, memory_order_relaxed)) { - __new = __old - __arg; - } - return __old; - } - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __arg) const noexcept { return fetch_add(__arg) + __arg; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __arg) const noexcept { return fetch_sub(__arg) - __arg; } -}; - -template -struct atomic_ref<_Tp*> : public __atomic_ref_base<_Tp*> { - using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp*>; - - using difference_type = ptrdiff_t; - - _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp*& __ptr) : __base(__ptr) {} - - _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __desired) const noexcept { return __base::operator=(__desired); } - - atomic_ref& operator=(const atomic_ref&) = delete; - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __arg, memory_order __order = memory_order_seq_cst) const noexcept { - return __atomic_fetch_add(this->__ptr_, __arg * sizeof(_Tp), std::__to_gcc_order(__order)); - } - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __arg, memory_order __order = memory_order_seq_cst) const noexcept { - return __atomic_fetch_sub(this->__ptr_, __arg * sizeof(_Tp), std::__to_gcc_order(__order)); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) const noexcept { return fetch_add(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) const noexcept { return fetch_sub(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator++() const noexcept { return fetch_add(1) + 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--() const noexcept { return fetch_sub(1) - 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __arg) const noexcept { return fetch_add(__arg) + __arg; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __arg) const noexcept { return fetch_sub(__arg) - __arg; } -}; - -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(atomic_ref); - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP__ATOMIC_ATOMIC_REF_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic_sync.h b/third_party/libcxx/include/c++/v1/__atomic/atomic_sync.h deleted file mode 100644 index 12bd1b9..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic_sync.h +++ /dev/null @@ -1,261 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_SYNC_H -#define _LIBCPP___ATOMIC_ATOMIC_SYNC_H - -#include <__atomic/atomic_waitable_traits.h> -#include <__atomic/contention_t.h> -#include <__atomic/memory_order.h> -#include <__chrono/duration.h> -#include <__config> -#include <__memory/addressof.h> -#include <__thread/poll_with_backoff.h> -#include <__type_traits/decay.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 -# if _LIBCPP_HAS_THREADS - -# if !_LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -// old dylib interface kept for backwards compatibility -_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(void const volatile*) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(void const volatile*) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(void const volatile*, __cxx_contention_t) _NOEXCEPT; - -_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile*) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile*) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t -__libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile*) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI void -__libcpp_atomic_wait(__cxx_atomic_contention_t const volatile*, __cxx_contention_t) _NOEXCEPT; -# endif // !_LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -// new dylib interface - -// return the global contention state's current value for the address -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t -__atomic_monitor_global(void const* __address) _NOEXCEPT; - -// wait on the global contention state to be changed from the given value for the address -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void -__atomic_wait_global_table(void const* __address, __cxx_contention_t __monitor_value) _NOEXCEPT; - -// notify one waiter waiting on the global contention state for the address -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_notify_one_global_table(void const*) _NOEXCEPT; - -// notify all waiters waiting on the global contention state for the address -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_notify_all_global_table(void const*) _NOEXCEPT; - -// wait on the address directly with the native platform wait -template -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void -__atomic_wait_native(void const* __address, void const* __old_value) _NOEXCEPT; - -// notify one waiter waiting on the address directly with the native platform wait -template -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_notify_one_native(const void*) _NOEXCEPT; - -// notify all waiters waiting on the address directly with the native platform wait -template -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_notify_all_native(const void*) _NOEXCEPT; - -# if _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -template -struct __atomic_wait_backoff_impl { - const _AtomicWaitable& __a_; - _Poll __poll_; - memory_order __order_; - - using __waitable_traits _LIBCPP_NODEBUG = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; - using __value_type _LIBCPP_NODEBUG = typename __waitable_traits::__value_type; - - _LIBCPP_HIDE_FROM_ABI __backoff_results operator()(chrono::nanoseconds __elapsed) const { - if (__elapsed > chrono::microseconds(4)) { - auto __contention_address = const_cast( - static_cast(__waitable_traits::__atomic_contention_address(__a_))); - - if constexpr (__has_native_atomic_wait<__value_type>) { - auto __atomic_value = __waitable_traits::__atomic_load(__a_, __order_); - if (__poll_(__atomic_value)) - return __backoff_results::__poll_success; - std::__atomic_wait_native(__contention_address, std::addressof(__atomic_value)); - } else { - __cxx_contention_t __monitor_val = std::__atomic_monitor_global(__contention_address); - auto __atomic_value = __waitable_traits::__atomic_load(__a_, __order_); - if (__poll_(__atomic_value)) - return __backoff_results::__poll_success; - std::__atomic_wait_global_table(__contention_address, __monitor_val); - } - } else { - } // poll - return __backoff_results::__continue_poll; - } -}; - -# else // _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -template -struct __atomic_wait_backoff_impl { - const _AtomicWaitable& __a_; - _Poll __poll_; - memory_order __order_; - - using __waitable_traits _LIBCPP_NODEBUG = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; - - _LIBCPP_HIDE_FROM_ABI bool - __update_monitor_val_and_poll(__cxx_atomic_contention_t const volatile*, __cxx_contention_t& __monitor_val) const { - // In case the contention type happens to be __cxx_atomic_contention_t, i.e. __cxx_atomic_impl, - // the platform wait is directly monitoring the atomic value itself. - // `__poll_` takes the current value of the atomic as an in-out argument - // to potentially modify it. After it returns, `__monitor` has a value - // which can be safely waited on by `std::__libcpp_atomic_wait` without any - // ABA style issues. - __monitor_val = __waitable_traits::__atomic_load(__a_, __order_); - return __poll_(__monitor_val); - } - - _LIBCPP_HIDE_FROM_ABI bool - __update_monitor_val_and_poll(void const volatile* __contention_address, __cxx_contention_t& __monitor_val) const { - // In case the contention type is anything else, platform wait is monitoring a __cxx_atomic_contention_t - // from the global pool, the monitor comes from __libcpp_atomic_monitor - __monitor_val = std::__libcpp_atomic_monitor(__contention_address); - auto __current_val = __waitable_traits::__atomic_load(__a_, __order_); - return __poll_(__current_val); - } - - _LIBCPP_HIDE_FROM_ABI __backoff_results operator()(chrono::nanoseconds __elapsed) const { - if (__elapsed > chrono::microseconds(4)) { - auto __contention_address = __waitable_traits::__atomic_contention_address(__a_); - __cxx_contention_t __monitor_val; - if (__update_monitor_val_and_poll(__contention_address, __monitor_val)) - return __backoff_results::__poll_success; - std::__libcpp_atomic_wait(__contention_address, __monitor_val); - } else { - } // poll - return __backoff_results::__continue_poll; - } -}; - -# endif // _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -// The semantics of this function are similar to `atomic`'s -// `.wait(T old, std::memory_order order)`, but instead of having a hardcoded -// predicate (is the loaded value unequal to `old`?), the predicate function is -// specified as an argument. The loaded value is given as an in-out argument to -// the predicate. If the predicate function returns `true`, -// `__atomic_wait_unless` will return. If the predicate function returns -// `false`, it must set the argument to its current understanding of the atomic -// value. The predicate function must not return `false` spuriously. -template -_LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, memory_order __order, _Poll&& __poll) { - static_assert(__atomic_waitable<_AtomicWaitable>); - __atomic_wait_backoff_impl<_AtomicWaitable, __decay_t<_Poll> > __backoff_fn = {__a, __poll, __order}; - std::__libcpp_thread_poll_with_backoff( - /* poll */ - [&]() { - auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order); - return __poll(__current_val); - }, - /* backoff */ __backoff_fn); -} - -# if _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable& __a) { - static_assert(__atomic_waitable<_AtomicWaitable>); - using __value_type _LIBCPP_NODEBUG = typename __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__value_type; - using __waitable_traits _LIBCPP_NODEBUG = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; - auto __contention_address = - const_cast(static_cast(__waitable_traits::__atomic_contention_address(__a))); - if constexpr (__has_native_atomic_wait<__value_type>) { - std::__atomic_notify_one_native(__contention_address); - } else { - std::__atomic_notify_one_global_table(__contention_address); - } -} - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable& __a) { - static_assert(__atomic_waitable<_AtomicWaitable>); - using __value_type _LIBCPP_NODEBUG = typename __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__value_type; - using __waitable_traits _LIBCPP_NODEBUG = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; - auto __contention_address = - const_cast(static_cast(__waitable_traits::__atomic_contention_address(__a))); - if constexpr (__has_native_atomic_wait<__value_type>) { - std::__atomic_notify_all_native(__contention_address); - } else { - std::__atomic_notify_all_global_table(__contention_address); - } -} - -# else // _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable& __a) { - static_assert(__atomic_waitable<_AtomicWaitable>); - std::__cxx_atomic_notify_one(__atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_contention_address(__a)); -} - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable& __a) { - static_assert(__atomic_waitable<_AtomicWaitable>); - std::__cxx_atomic_notify_all(__atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_contention_address(__a)); -} - -# endif - -# else // _LIBCPP_HAS_THREADS - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, memory_order __order, _Poll&& __poll) { - std::__libcpp_thread_poll_with_backoff( - /* poll */ - [&]() { - auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order); - return __poll(__current_val); - }, - /* backoff */ __spinning_backoff_policy()); -} - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable&) {} - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable&) {} - -# endif // _LIBCPP_HAS_THREADS - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) { - return std::memcmp(std::addressof(__lhs), std::addressof(__rhs), sizeof(_Tp)) == 0; -} - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_wait(_AtomicWaitable& __a, _Tp __val, memory_order __order) { - static_assert(__atomic_waitable<_AtomicWaitable>); - std::__atomic_wait_unless(__a, __order, [&](_Tp const& __current) { - return !std::__cxx_nonatomic_compare_equal(__current, __val); - }); -} - -#endif // C++20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_ATOMIC_SYNC_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic_sync_timed.h b/third_party/libcxx/include/c++/v1/__atomic/atomic_sync_timed.h deleted file mode 100644 index f3bf780..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic_sync_timed.h +++ /dev/null @@ -1,136 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_SYNC_TIMED_H -#define _LIBCPP___ATOMIC_ATOMIC_SYNC_TIMED_H - -#include <__atomic/atomic_waitable_traits.h> -#include <__atomic/contention_t.h> -#include <__atomic/memory_order.h> -#include <__chrono/duration.h> -#include <__config> -#include <__memory/addressof.h> -#include <__thread/poll_with_backoff.h> -#include <__thread/timed_backoff_policy.h> -#include <__type_traits/decay.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 -# if _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -_LIBCPP_AVAILABILITY_NEW_SYNC -_LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __atomic_monitor_global(void const* __address) _NOEXCEPT; - -// wait on the global contention state to be changed from the given value for the address -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void __atomic_wait_global_table_with_timeout( - void const* __address, __cxx_contention_t __monitor_value, uint64_t __timeout_ns) _NOEXCEPT; - -// wait on the address directly with the native platform wait -template -_LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_EXPORTED_FROM_ABI void -__atomic_wait_native_with_timeout(void const* __address, void const* __old_value, uint64_t __timeout_ns) _NOEXCEPT; - -template -struct __atomic_wait_timed_backoff_impl { - const _AtomicWaitable& __a_; - _Poll __poll_; - memory_order __order_; - chrono::duration<_Rep, _Period> __rel_time_; - - using __waitable_traits _LIBCPP_NODEBUG = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; - using __value_type _LIBCPP_NODEBUG = typename __waitable_traits::__value_type; - - _LIBCPP_HIDE_FROM_ABI __backoff_results operator()(chrono::nanoseconds __elapsed) const { - if (__elapsed > chrono::microseconds(4)) { - auto __contention_address = const_cast( - static_cast(__waitable_traits::__atomic_contention_address(__a_))); - - uint64_t __timeout_ns = - static_cast((chrono::duration_cast(__rel_time_) - __elapsed).count()); - - if constexpr (__has_native_atomic_wait<__value_type>) { - auto __atomic_value = __waitable_traits::__atomic_load(__a_, __order_); - if (__poll_(__atomic_value)) - return __backoff_results::__poll_success; - std::__atomic_wait_native_with_timeout( - __contention_address, std::addressof(__atomic_value), __timeout_ns); - } else { - __cxx_contention_t __monitor_val = std::__atomic_monitor_global(__contention_address); - auto __atomic_value = __waitable_traits::__atomic_load(__a_, __order_); - if (__poll_(__atomic_value)) - return __backoff_results::__poll_success; - std::__atomic_wait_global_table_with_timeout(__contention_address, __monitor_val, __timeout_ns); - } - } else { - } // poll - return __backoff_results::__continue_poll; - } -}; - -// The semantics of this function are similar to `atomic`'s -// `.wait(T old, std::memory_order order)` with a timeout, but instead of having a hardcoded -// predicate (is the loaded value unequal to `old`?), the predicate function is -// specified as an argument. The loaded value is given as an in-out argument to -// the predicate. If the predicate function returns `true`, -// `__atomic_wait_unless_with_timeout` will return. If the predicate function returns -// `false`, it must set the argument to its current understanding of the atomic -// value. The predicate function must not return `false` spuriously. -template -_LIBCPP_HIDE_FROM_ABI bool __atomic_wait_unless_with_timeout( - const _AtomicWaitable& __a, - memory_order __order, - _Poll&& __poll, - chrono::duration<_Rep, _Period> const& __rel_time) { - static_assert(__atomic_waitable<_AtomicWaitable>, ""); - __atomic_wait_timed_backoff_impl<_AtomicWaitable, __decay_t<_Poll>, _Rep, _Period> __backoff_fn = { - __a, __poll, __order, __rel_time}; - auto __poll_result = std::__libcpp_thread_poll_with_backoff( - /* poll */ - [&]() { - auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order); - return __poll(__current_val); - }, - /* backoff */ __backoff_fn, - __rel_time); - - return __poll_result == __poll_with_backoff_results::__poll_success; -} - -# elif _LIBCPP_HAS_THREADS // _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -template -_LIBCPP_HIDE_FROM_ABI bool __atomic_wait_unless_with_timeout( - const _AtomicWaitable& __a, - memory_order __order, - _Poll&& __poll, - chrono::duration<_Rep, _Period> const& __rel_time) { - auto __res = std::__libcpp_thread_poll_with_backoff( - /* poll */ - [&]() { - auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order); - return __poll(__current_val); - }, - /* backoff */ __libcpp_timed_backoff_policy(), - __rel_time); - return __res == __poll_with_backoff_results::__poll_success; -} - -# endif // _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_NEW_SYNC - -#endif // C++20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_ATOMIC_SYNC_TIMED_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/atomic_waitable_traits.h b/third_party/libcxx/include/c++/v1/__atomic/atomic_waitable_traits.h deleted file mode 100644 index 369cd2c..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/atomic_waitable_traits.h +++ /dev/null @@ -1,101 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_WAITABLE_TRAITS_H -#define _LIBCPP___ATOMIC_ATOMIC_WAITABLE_TRAITS_H - -#include <__atomic/contention_t.h> -#include <__atomic/memory_order.h> -#include <__config> -#include <__type_traits/decay.h> -#include <__type_traits/has_unique_object_representation.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_trivially_copyable.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// The customisation points to enable the following functions: -// - __atomic_wait -// - __atomic_wait_unless -// - __atomic_notify_one -// - __atomic_notify_all -template -struct __atomic_waitable_traits { - using __value_type _LIBCPP_NODEBUG = void; - - template - static void __atomic_load(_AtomicWaitable&&, memory_order) = delete; - - template - static void __atomic_contention_address(_AtomicWaitable&&) = delete; -}; - -template -concept __atomic_waitable = requires(const _Tp __t, memory_order __order) { - typename __atomic_waitable_traits<__decay_t<_Tp> >::__value_type; - { __atomic_waitable_traits<__decay_t<_Tp> >::__atomic_load(__t, __order) }; - { __atomic_waitable_traits<__decay_t<_Tp> >::__atomic_contention_address(__t) }; -}; - -# ifdef __linux__ -# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) _APPLY(4) -# elif defined(__APPLE__) -# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) \ - _APPLY(4) \ - _APPLY(8) -# elif defined(__FreeBSD__) && __SIZEOF_LONG__ == 8 -# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) _APPLY(8) -# elif defined(_WIN32) -# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) _APPLY(8) -# else -# define _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_APPLY) _APPLY(sizeof(__cxx_contention_t)) -# endif // __linux__ - -// concepts defines the types are supported natively by the platform's wait - -# if defined(_LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE) - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __has_native_atomic_wait_impl() { - if (alignof(_Tp) % sizeof(_Tp) != 0) - return false; - switch (sizeof(_Tp)) { -# define _LIBCPP_MAKE_CASE(n) \ - case n: \ - return true; - _LIBCPP_NATIVE_PLATFORM_WAIT_SIZES(_LIBCPP_MAKE_CASE) - default: - return false; -# undef _LIBCPP_MAKE_CASE - }; -} - -template -concept __has_native_atomic_wait = - has_unique_object_representations_v<_Tp> && is_trivially_copyable_v<_Tp> && - std::__has_native_atomic_wait_impl<_Tp>(); - -# else // _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE - -template -concept __has_native_atomic_wait = is_same_v<_Tp, __cxx_contention_t>; - -# endif // _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE - -#endif // C++20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_ATOMIC_WAITABLE_TRAITS_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/check_memory_order.h b/third_party/libcxx/include/c++/v1/__atomic/check_memory_order.h deleted file mode 100644 index 536f764..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/check_memory_order.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_CHECK_MEMORY_ORDER_H -#define _LIBCPP___ATOMIC_CHECK_MEMORY_ORDER_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ - _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \ - _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \ - _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || __f == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#define _LIBCPP_CHECK_WAIT_MEMORY_ORDER(__m) \ - _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#endif // _LIBCPP___ATOMIC_CHECK_MEMORY_ORDER_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/contention_t.h b/third_party/libcxx/include/c++/v1/__atomic/contention_t.h deleted file mode 100644 index c6d2570..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/contention_t.h +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_CONTENTION_T_H -#define _LIBCPP___ATOMIC_CONTENTION_T_H - -#include <__atomic/support.h> -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// The original definition of `__cxx_contention_t` seemed a bit arbitrary. -// When we enable the _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE ABI, -// use definitions that are based on what the underlying platform supports -// instead. -#if defined(_LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE) - -# if defined(__linux__) || defined(__Fuchsia__) -using __cxx_contention_t _LIBCPP_NODEBUG = int32_t; -# elif defined(__APPLE__) -using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; -# elif defined(__FreeBSD__) && __SIZEOF_LONG__ == 8 -using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; -# elif defined(_AIX) && !defined(__64BIT__) -using __cxx_contention_t _LIBCPP_NODEBUG = int32_t; -# elif defined(_WIN32) -using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; -# else -using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; -# endif // __linux__ || __Fuchsia__ - -#else // _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE - -# if defined(__linux__) || defined(__Fuchsia__) || (defined(_AIX) && !defined(__64BIT__)) -using __cxx_contention_t _LIBCPP_NODEBUG = int32_t; -# else -using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; -# endif // __linux__ || __Fuchsia__ || (_AIX && !__64BIT__) - -#endif // _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE - -using __cxx_atomic_contention_t _LIBCPP_NODEBUG = __cxx_atomic_impl<__cxx_contention_t>; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_CONTENTION_T_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/fence.h b/third_party/libcxx/include/c++/v1/__atomic/fence.h deleted file mode 100644 index 0a63ced..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/fence.h +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_FENCE_H -#define _LIBCPP___ATOMIC_FENCE_H - -#include <__atomic/memory_order.h> -#include <__atomic/support.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -inline _LIBCPP_HIDE_FROM_ABI void atomic_thread_fence(memory_order __m) _NOEXCEPT { __cxx_atomic_thread_fence(__m); } - -inline _LIBCPP_HIDE_FROM_ABI void atomic_signal_fence(memory_order __m) _NOEXCEPT { __cxx_atomic_signal_fence(__m); } - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_FENCE_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/floating_point_helper.h b/third_party/libcxx/include/c++/v1/__atomic/floating_point_helper.h deleted file mode 100644 index 8762ec2..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/floating_point_helper.h +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H -#define _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H - -#include <__config> -#include <__type_traits/is_floating_point.h> -#include <__type_traits/is_same.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __is_fp80_long_double() { - // Only x87-fp80 long double has 64-bit mantissa - return __LDBL_MANT_DIG__ == 64 && std::is_same_v<_Tp, long double>; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __has_rmw_builtin() { - static_assert(std::is_floating_point_v<_Tp>); -# ifndef _LIBCPP_COMPILER_CLANG_BASED - return false; -# else - // The builtin __cxx_atomic_fetch_add errors during compilation for - // long double on platforms with fp80 format. - // For more details, see - // lib/Sema/SemaChecking.cpp function IsAllowedValueType - // LLVM Parser does not allow atomicrmw with x86_fp80 type. - // if (ValType->isSpecificBuiltinType(BuiltinType::LongDouble) && - // &Context.getTargetInfo().getLongDoubleFormat() == - // &llvm::APFloat::x87DoubleExtended()) - // For more info - // https://llvm.org/PR68602 - // https://reviews.llvm.org/D53965 - return !std::__is_fp80_long_double<_Tp>(); -# endif -} - -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_FLOATING_POINT_HELPER_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/is_always_lock_free.h b/third_party/libcxx/include/c++/v1/__atomic/is_always_lock_free.h deleted file mode 100644 index f928e79..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/is_always_lock_free.h +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_IS_ALWAYS_LOCK_FREE_H -#define _LIBCPP___ATOMIC_IS_ALWAYS_LOCK_FREE_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __libcpp_is_always_lock_free { - // __atomic_always_lock_free is available in all Standard modes - static const bool __value = __atomic_always_lock_free(sizeof(_Tp), nullptr); -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_IS_ALWAYS_LOCK_FREE_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/kill_dependency.h b/third_party/libcxx/include/c++/v1/__atomic/kill_dependency.h deleted file mode 100644 index 103d52d..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/kill_dependency.h +++ /dev/null @@ -1,27 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_KILL_DEPENDENCY_H -#define _LIBCPP___ATOMIC_KILL_DEPENDENCY_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _Tp kill_dependency(_Tp __y) _NOEXCEPT { - return __y; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_KILL_DEPENDENCY_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/memory_order.h b/third_party/libcxx/include/c++/v1/__atomic/memory_order.h deleted file mode 100644 index 3558043..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/memory_order.h +++ /dev/null @@ -1,65 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_MEMORY_ORDER_H -#define _LIBCPP___ATOMIC_MEMORY_ORDER_H - -#include <__config> -#include <__type_traits/is_same.h> -#include <__type_traits/underlying_type.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Figure out what the underlying type for `memory_order` would be if it were -// declared as an unscoped enum (accounting for -fshort-enums). Use this result -// to pin the underlying type in C++20. -enum __legacy_memory_order { __mo_relaxed, __mo_consume, __mo_acquire, __mo_release, __mo_acq_rel, __mo_seq_cst }; - -using __memory_order_underlying_t _LIBCPP_NODEBUG = __underlying_type_t<__legacy_memory_order>; - -#if _LIBCPP_STD_VER >= 20 - -enum class memory_order : __memory_order_underlying_t { - relaxed = __mo_relaxed, - consume = __mo_consume, - acquire = __mo_acquire, - release = __mo_release, - acq_rel = __mo_acq_rel, - seq_cst = __mo_seq_cst -}; - -static_assert(is_same<__underlying_type_t, __memory_order_underlying_t>::value, - "unexpected underlying type for std::memory_order"); - -inline constexpr auto memory_order_relaxed = memory_order::relaxed; -inline constexpr auto memory_order_consume = memory_order::consume; -inline constexpr auto memory_order_acquire = memory_order::acquire; -inline constexpr auto memory_order_release = memory_order::release; -inline constexpr auto memory_order_acq_rel = memory_order::acq_rel; -inline constexpr auto memory_order_seq_cst = memory_order::seq_cst; - -#else - -enum memory_order { - memory_order_relaxed = __mo_relaxed, - memory_order_consume = __mo_consume, - memory_order_acquire = __mo_acquire, - memory_order_release = __mo_release, - memory_order_acq_rel = __mo_acq_rel, - memory_order_seq_cst = __mo_seq_cst, -}; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_MEMORY_ORDER_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/support.h b/third_party/libcxx/include/c++/v1/__atomic/support.h deleted file mode 100644 index 99d0f6a..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/support.h +++ /dev/null @@ -1,121 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_SUPPORT_H -#define _LIBCPP___ATOMIC_SUPPORT_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -// -// This file implements base support for atomics on the platform. -// -// The following operations and types must be implemented (where _Atmc -// is __cxx_atomic_base_impl for readability): -// -// clang-format off -// -// template -// struct __cxx_atomic_base_impl; -// -// #define __cxx_atomic_is_lock_free(__size) -// -// void __cxx_atomic_thread_fence(memory_order __order) noexcept; -// void __cxx_atomic_signal_fence(memory_order __order) noexcept; -// -// template -// void __cxx_atomic_init(_Atmc<_Tp> volatile* __a, _Tp __val) noexcept; -// template -// void __cxx_atomic_init(_Atmc<_Tp>* __a, _Tp __val) noexcept; -// -// template -// void __cxx_atomic_store(_Atmc<_Tp> volatile* __a, _Tp __val, memory_order __order) noexcept; -// template -// void __cxx_atomic_store(_Atmc<_Tp>* __a, _Tp __val, memory_order __order) noexcept; -// -// template -// _Tp __cxx_atomic_load(_Atmc<_Tp> const volatile* __a, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_load(_Atmc<_Tp> const* __a, memory_order __order) noexcept; -// -// template -// void __cxx_atomic_load_inplace(_Atmc<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) noexcept; -// template -// void __cxx_atomic_load_inplace(_Atmc<_Tp> const* __a, _Tp* __dst, memory_order __order) noexcept; -// -// template -// _Tp __cxx_atomic_exchange(_Atmc<_Tp> volatile* __a, _Tp __value, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_exchange(_Atmc<_Tp>* __a, _Tp __value, memory_order __order) noexcept; -// -// template -// bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; -// template -// bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; -// -// template -// bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; -// template -// bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; -// -// template -// _Tp __cxx_atomic_fetch_add(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_fetch_add(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept; -// -// template -// _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept; -// template -// _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept; -// -// template -// _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept; -// template -// _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept; -// template -// _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept; -// -// template -// _Tp __cxx_atomic_fetch_and(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_fetch_and(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept; -// -// template -// _Tp __cxx_atomic_fetch_or(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_fetch_or(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept; -// template -// _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept; -// -// clang-format on -// - -#if _LIBCPP_HAS_GCC_ATOMIC_IMP -# include <__atomic/support/gcc.h> -#elif _LIBCPP_HAS_C_ATOMIC_IMP -# include <__atomic/support/c11.h> -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -struct __cxx_atomic_impl : public _Base { - _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {} -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_SUPPORT_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/support/c11.h b/third_party/libcxx/include/c++/v1/__atomic/support/c11.h deleted file mode 100644 index 1ad2998..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/support/c11.h +++ /dev/null @@ -1,264 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_SUPPORT_C11_H -#define _LIBCPP___ATOMIC_SUPPORT_C11_H - -#include <__atomic/memory_order.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__memory/addressof.h> -#include <__type_traits/remove_const.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -// -// This file implements support for C11-style atomics -// - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __cxx_atomic_base_impl { - _LIBCPP_HIDE_FROM_ABI -#ifndef _LIBCPP_CXX03_LANG - __cxx_atomic_base_impl() _NOEXCEPT = default; -#else - __cxx_atomic_base_impl() _NOEXCEPT : __a_value() { - } -#endif // _LIBCPP_CXX03_LANG - _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT : __a_value(__value) {} - _Atomic(_Tp) __a_value; -}; - -#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT { - __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order)); -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT { - __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT { - __c11_atomic_init(std::addressof(__a->__a_value), __val); -} -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) _NOEXCEPT { - __c11_atomic_init(std::addressof(__a->__a_value), __val); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT { - __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) _NOEXCEPT { - __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - return __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - return __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - *__dst = __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const* __a, _Tp* __dst, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - *__dst = __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT { - return __c11_atomic_exchange( - std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) _NOEXCEPT { - return __c11_atomic_exchange( - std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order)); -} - -_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR memory_order __to_failure_order(memory_order __order) { - // Avoid switch statement to make this a constexpr. - return __order == memory_order_release - ? memory_order_relaxed - : (__order == memory_order_acq_rel ? memory_order_acquire : __order); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - __cxx_atomic_base_impl<_Tp> volatile* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) _NOEXCEPT { - return __c11_atomic_compare_exchange_strong( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) - _NOEXCEPT { - return __c11_atomic_compare_exchange_strong( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - __cxx_atomic_base_impl<_Tp> volatile* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) _NOEXCEPT { - return __c11_atomic_compare_exchange_weak( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) - _NOEXCEPT { - return __c11_atomic_compare_exchange_weak( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_and( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_and( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_or( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_or( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_xor( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_xor( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_SUPPORT_C11_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/support/gcc.h b/third_party/libcxx/include/c++/v1/__atomic/support/gcc.h deleted file mode 100644 index 73c1b1c..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/support/gcc.h +++ /dev/null @@ -1,265 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_SUPPORT_GCC_H -#define _LIBCPP___ATOMIC_SUPPORT_GCC_H - -#include <__atomic/memory_order.h> -#include <__atomic/to_gcc_order.h> -#include <__config> -#include <__memory/addressof.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_assignable.h> -#include <__type_traits/remove_const.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -// -// This file implements support for GCC-style atomics -// - -_LIBCPP_BEGIN_NAMESPACE_STD - -// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because -// the default operator= in an object is not volatile, a byte-by-byte copy -// is required. -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { - __a_value = __val; -} -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { - volatile char* __to = reinterpret_cast(std::addressof(__a_value)); - volatile char* __end = __to + sizeof(_Tp); - volatile const char* __from = reinterpret_cast(std::addressof(__val)); - while (__to != __end) - *__to++ = *__from++; -} - -template -struct __cxx_atomic_base_impl { - _LIBCPP_HIDE_FROM_ABI -#ifndef _LIBCPP_CXX03_LANG - __cxx_atomic_base_impl() _NOEXCEPT = default; -#else - __cxx_atomic_base_impl() _NOEXCEPT : __a_value() { - } -#endif // _LIBCPP_CXX03_LANG - _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {} - _Tp __a_value; -}; - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { - __cxx_atomic_assign_volatile(__a->__a_value, __val); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { - __a->__a_value = __val; -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) { - __atomic_thread_fence(__to_gcc_order(__order)); -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) { - __atomic_signal_fence(__to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { - __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { - __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { - _Tp __ret; - __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(const volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { - __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(const __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { - __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { - _Tp __ret; - __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { - _Tp __ret; - __atomic_exchange( - std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { - _Tp __ret; - __atomic_exchange( - std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - volatile __cxx_atomic_base_impl<_Tp>* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - false, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - false, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - volatile __cxx_atomic_base_impl<_Tp>* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - true, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - true, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -struct __skip_amt { - enum { value = 1 }; -}; - -template -struct __skip_amt<_Tp*> { - enum { value = sizeof(_Tp) }; -}; - -// FIXME: Haven't figured out what the spec says about using arrays with -// atomic_fetch_add. Force a failure rather than creating bad behavior. -template -struct __skip_amt<_Tp[]> {}; -template -struct __skip_amt<_Tp[n]> {}; - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_SUPPORT_GCC_H diff --git a/third_party/libcxx/include/c++/v1/__atomic/to_gcc_order.h b/third_party/libcxx/include/c++/v1/__atomic/to_gcc_order.h deleted file mode 100644 index d04c111..0000000 --- a/third_party/libcxx/include/c++/v1/__atomic/to_gcc_order.h +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_TO_GCC_ORDER_H -#define _LIBCPP___ATOMIC_TO_GCC_ORDER_H - -#include <__atomic/memory_order.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if defined(__ATOMIC_RELAXED) && defined(__ATOMIC_CONSUME) && defined(__ATOMIC_ACQUIRE) && \ - defined(__ATOMIC_RELEASE) && defined(__ATOMIC_ACQ_REL) && defined(__ATOMIC_SEQ_CST) - -_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { - // Avoid switch statement to make this a constexpr. - return __order == memory_order_relaxed - ? __ATOMIC_RELAXED - : (__order == memory_order_acquire - ? __ATOMIC_ACQUIRE - : (__order == memory_order_release - ? __ATOMIC_RELEASE - : (__order == memory_order_seq_cst - ? __ATOMIC_SEQ_CST - : (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL : __ATOMIC_CONSUME)))); -} - -_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { - // Avoid switch statement to make this a constexpr. - return __order == memory_order_relaxed - ? __ATOMIC_RELAXED - : (__order == memory_order_acquire - ? __ATOMIC_ACQUIRE - : (__order == memory_order_release - ? __ATOMIC_RELAXED - : (__order == memory_order_seq_cst - ? __ATOMIC_SEQ_CST - : (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE : __ATOMIC_CONSUME)))); -} - -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_TO_GCC_ORDER_H diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_cast.h b/third_party/libcxx/include/c++/v1/__bit/bit_cast.h deleted file mode 100644 index 7350250..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/bit_cast.h +++ /dev/null @@ -1,44 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_BIT_CAST_H -#define _LIBCPP___BIT_BIT_CAST_H - -#include <__config> -#include <__type_traits/is_trivially_copyable.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#ifndef _LIBCPP_CXX03_LANG - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept { - return __builtin_bit_cast(_ToType, __from); -} - -#endif // _LIBCPP_CXX03_LANG - -#if _LIBCPP_STD_VER >= 20 - -template - requires(sizeof(_ToType) == sizeof(_FromType) && is_trivially_copyable_v<_ToType> && - is_trivially_copyable_v<_FromType>) -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType bit_cast(const _FromType& __from) noexcept { - return __builtin_bit_cast(_ToType, __from); -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_BIT_CAST_H diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_ceil.h b/third_party/libcxx/include/c++/v1/__bit/bit_ceil.h deleted file mode 100644 index 99881a8..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/bit_ceil.h +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_BIT_CEIL_H -#define _LIBCPP___BIT_BIT_CEIL_H - -#include <__assert> -#include <__bit/countl.h> -#include <__config> -#include <__type_traits/integer_traits.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 - -template -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_ceil(_Tp __t) noexcept { - if (__t < 2) - return 1; - const unsigned __n = numeric_limits<_Tp>::digits - std::__countl_zero((_Tp)(__t - 1u)); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); - - if constexpr (sizeof(_Tp) >= sizeof(unsigned)) - return _Tp{1} << __n; - else { - const unsigned __extra = numeric_limits::digits - numeric_limits<_Tp>::digits; - const unsigned __ret_val = 1u << (__n + __extra); - return (_Tp)(__ret_val >> __extra); - } -} - -# if _LIBCPP_STD_VER >= 20 - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept { - return std::__bit_ceil(__t); -} - -# endif // _LIBCPP_STD_VER >= 20 -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_BIT_CEIL_H diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_floor.h b/third_party/libcxx/include/c++/v1/__bit/bit_floor.h deleted file mode 100644 index 799a064..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/bit_floor.h +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_BIT_FLOOR_H -#define _LIBCPP___BIT_BIT_FLOOR_H - -#include <__bit/bit_log2.h> -#include <__config> -#include <__type_traits/integer_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept { - return __t == 0 ? 0 : _Tp{1} << std::__bit_log2(__t); -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_BIT_FLOOR_H diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_log2.h b/third_party/libcxx/include/c++/v1/__bit/bit_log2.h deleted file mode 100644 index 9ceeec1..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/bit_log2.h +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_BIT_LOG2_H -#define _LIBCPP___BIT_BIT_LOG2_H - -#include <__assert> -#include <__bit/countl.h> -#include <__config> -#include <__type_traits/integer_traits.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __bit_log2(_Tp __t) _NOEXCEPT { - static_assert(__is_unsigned_integer_v<_Tp>, "__bit_log2 requires an unsigned integer type"); - _LIBCPP_ASSERT_INTERNAL(__t != 0, "logarithm of 0 is undefined"); - return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_BIT_LOG2_H diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_width.h b/third_party/libcxx/include/c++/v1/__bit/bit_width.h deleted file mode 100644 index 75050ac..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/bit_width.h +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_BIT_WIDTH_H -#define _LIBCPP___BIT_BIT_WIDTH_H - -#include <__bit/bit_log2.h> -#include <__config> -#include <__type_traits/integer_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int bit_width(_Tp __t) noexcept { - return __t == 0 ? 0 : std::__bit_log2(__t) + 1; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___BIT_BIT_WIDTH_H diff --git a/third_party/libcxx/include/c++/v1/__bit/blsr.h b/third_party/libcxx/include/c++/v1/__bit/blsr.h deleted file mode 100644 index 76bd521..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/blsr.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_BLSR_H -#define _LIBCPP___BIT_BLSR_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned __libcpp_blsr(unsigned __x) _NOEXCEPT { - return __x ^ (__x & -__x); -} - -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long __libcpp_blsr(unsigned long __x) _NOEXCEPT { - return __x ^ (__x & -__x); -} - -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long long __libcpp_blsr(unsigned long long __x) _NOEXCEPT { - return __x ^ (__x & -__x); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_BLSR_H diff --git a/third_party/libcxx/include/c++/v1/__bit/byteswap.h b/third_party/libcxx/include/c++/v1/__bit/byteswap.h deleted file mode 100644 index 7ce7e06..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/byteswap.h +++ /dev/null @@ -1,53 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_BYTESWAP_H -#define _LIBCPP___BIT_BYTESWAP_H - -#include <__concepts/arithmetic.h> -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 23 - -template -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept { - if constexpr (sizeof(_Tp) == 1) { - return __val; - } else if constexpr (sizeof(_Tp) == 2) { - return __builtin_bswap16(__val); - } else if constexpr (sizeof(_Tp) == 4) { - return __builtin_bswap32(__val); - } else if constexpr (sizeof(_Tp) == 8) { - return __builtin_bswap64(__val); -# if _LIBCPP_HAS_INT128 - } else if constexpr (sizeof(_Tp) == 16) { -# if __has_builtin(__builtin_bswap128) - return __builtin_bswap128(__val); -# else - return (static_cast<_Tp>(byteswap(static_cast(__val))) << 64) | - static_cast<_Tp>(byteswap(static_cast(__val >> 64))); -# endif // __has_builtin(__builtin_bswap128) -# endif // _LIBCPP_HAS_INT128 - } else { - static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size"); - } -} - -#endif // _LIBCPP_STD_VER >= 23 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_BYTESWAP_H diff --git a/third_party/libcxx/include/c++/v1/__bit/countl.h b/third_party/libcxx/include/c++/v1/__bit/countl.h deleted file mode 100644 index c95828f..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/countl.h +++ /dev/null @@ -1,48 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_COUNTL_H -#define _LIBCPP___BIT_COUNTL_H - -#include <__config> -#include <__type_traits/integer_traits.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _NOEXCEPT { - return __builtin_clzg(__t, numeric_limits<_Tp>::digits); -} - -#if _LIBCPP_STD_VER >= 20 - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countl_zero(_Tp __t) noexcept { - return std::__countl_zero(__t); -} - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countl_one(_Tp __t) noexcept { - return std::countl_zero(static_cast<_Tp>(~__t)); -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___BIT_COUNTL_H diff --git a/third_party/libcxx/include/c++/v1/__bit/countr.h b/third_party/libcxx/include/c++/v1/__bit/countr.h deleted file mode 100644 index 16f689d..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/countr.h +++ /dev/null @@ -1,48 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_COUNTR_H -#define _LIBCPP___BIT_COUNTR_H - -#include <__config> -#include <__type_traits/integer_traits.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __countr_zero(_Tp __t) _NOEXCEPT { - return __builtin_ctzg(__t, numeric_limits<_Tp>::digits); -} - -#if _LIBCPP_STD_VER >= 20 - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countr_zero(_Tp __t) noexcept { - return std::__countr_zero(__t); -} - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countr_one(_Tp __t) noexcept { - return std::countr_zero(static_cast<_Tp>(~__t)); -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___BIT_COUNTR_H diff --git a/third_party/libcxx/include/c++/v1/__bit/endian.h b/third_party/libcxx/include/c++/v1/__bit/endian.h deleted file mode 100644 index 2d31e5d..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/endian.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_ENDIAN_H -#define _LIBCPP___BIT_ENDIAN_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -enum class endian { - little = 0xDEAD, - big = 0xFACE, -# if defined(_LIBCPP_LITTLE_ENDIAN) - native = little -# elif defined(_LIBCPP_BIG_ENDIAN) - native = big -# else - native = 0xCAFE -# endif -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___BIT_ENDIAN_H diff --git a/third_party/libcxx/include/c++/v1/__bit/has_single_bit.h b/third_party/libcxx/include/c++/v1/__bit/has_single_bit.h deleted file mode 100644 index c49c518..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/has_single_bit.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_HAS_SINGLE_BIT_H -#define _LIBCPP___BIT_HAS_SINGLE_BIT_H - -#include <__config> -#include <__type_traits/integer_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept { - return __builtin_popcountg(__t) == 1; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___BIT_HAS_SINGLE_BIT_H diff --git a/third_party/libcxx/include/c++/v1/__bit/invert_if.h b/third_party/libcxx/include/c++/v1/__bit/invert_if.h deleted file mode 100644 index f7606ed..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/invert_if.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_INVERT_IF_H -#define _LIBCPP___BIT_INVERT_IF_H - -#include <__concepts/arithmetic.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __invert_if(_Tp __v) { - if (_Invert) - return ~__v; - return __v; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_INVERT_IF_H diff --git a/third_party/libcxx/include/c++/v1/__bit/popcount.h b/third_party/libcxx/include/c++/v1/__bit/popcount.h deleted file mode 100644 index d104c8e..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/popcount.h +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_POPCOUNT_H -#define _LIBCPP___BIT_POPCOUNT_H - -#include <__config> -#include <__type_traits/integer_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT { - return __builtin_popcountg(__t); -} - -#if _LIBCPP_STD_VER >= 20 - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int popcount(_Tp __t) noexcept { - return std::__popcount(__t); -} - -#endif - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___BIT_POPCOUNT_H diff --git a/third_party/libcxx/include/c++/v1/__bit/rotate.h b/third_party/libcxx/include/c++/v1/__bit/rotate.h deleted file mode 100644 index fde9058..0000000 --- a/third_party/libcxx/include/c++/v1/__bit/rotate.h +++ /dev/null @@ -1,60 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_ROTATE_H -#define _LIBCPP___BIT_ROTATE_H - -#include <__config> -#include <__type_traits/integer_traits.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Writing two full functions for rotl and rotr makes it easier for the compiler -// to optimize the code. On x86 this function becomes the ROL instruction and -// the rotr function becomes the ROR instruction. - -#if _LIBCPP_STD_VER >= 20 - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept { - const int __n = numeric_limits<_Tp>::digits; - int __r = __cnt % __n; - - if (__r == 0) - return __t; - - if (__r > 0) - return (__t << __r) | (__t >> (__n - __r)); - - return (__t >> -__r) | (__t << (__n + __r)); -} - -template <__unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept { - const int __n = numeric_limits<_Tp>::digits; - int __r = __cnt % __n; - - if (__r == 0) - return __t; - - if (__r > 0) - return (__t >> __r) | (__t << (__n - __r)); - - return (__t << -__r) | (__t >> (__n + __r)); -} - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___BIT_ROTATE_H diff --git a/third_party/libcxx/include/c++/v1/__bit_reference b/third_party/libcxx/include/c++/v1/__bit_reference deleted file mode 100644 index 6bbe289..0000000 --- a/third_party/libcxx/include/c++/v1/__bit_reference +++ /dev/null @@ -1,873 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___BIT_REFERENCE -#define _LIBCPP___BIT_REFERENCE - -#include <__algorithm/comp.h> -#include <__algorithm/copy.h> -#include <__algorithm/copy_backward.h> -#include <__algorithm/copy_n.h> -#include <__algorithm/equal.h> -#include <__algorithm/fill_n.h> -#include <__algorithm/min.h> -#include <__algorithm/rotate.h> -#include <__algorithm/specialized_algorithms.h> -#include <__assert> -#include <__bit/countr.h> -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__cstddef/size_t.h> -#include <__functional/identity.h> -#include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> -#include <__memory/construct_at.h> -#include <__memory/pointer_traits.h> -#include <__type_traits/conditional.h> -#include <__type_traits/desugars_to.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_constant_evaluated.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_unsigned.h> -#include <__type_traits/void_t.h> -#include <__utility/pair.h> -#include <__utility/swap.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __bit_const_reference; - -template -struct __has_storage_type { - static const bool value = false; -}; - -template -struct __size_difference_type_traits { - using difference_type = ptrdiff_t; - using size_type = size_t; -}; - -template -struct __size_difference_type_traits<_Cp, __void_t > { - using difference_type = typename _Cp::difference_type; - using size_type = typename _Cp::size_type; -}; - -// The `__x_mask` functions are designed to work exclusively with any unsigned `_StorageType`s, including small -// integral types such as unsigned char/short, `uint8_t`, and `uint16_t`. To prevent undefined behavior or -// ambiguities due to integral promotions for the small integral types, all intermediate bitwise operations are -// explicitly cast back to the unsigned `_StorageType`. - -// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz) and sets all remaining -// bits to one. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __trailing_mask(unsigned __clz) { - static_assert(is_unsigned<_StorageType>::value, "__trailing_mask only works with unsigned types"); - return static_cast<_StorageType>(~static_cast<_StorageType>(0)) >> __clz; -} - -// Creates a mask of type `_StorageType` with a specified number of trailing zeros (__ctz) and sets all remaining -// bits to one. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __leading_mask(unsigned __ctz) { - static_assert(is_unsigned<_StorageType>::value, "__leading_mask only works with unsigned types"); - return static_cast<_StorageType>(~static_cast<_StorageType>(0)) << __ctz; -} - -// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz), a specified number of -// trailing zeros (__ctz), and sets all bits in between to one. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __middle_mask(unsigned __clz, unsigned __ctz) { - static_assert(is_unsigned<_StorageType>::value, "__middle_mask only works with unsigned types"); - return std::__leading_mask<_StorageType>(__ctz) & std::__trailing_mask<_StorageType>(__clz); -} - -// This function is designed to operate correctly even for smaller integral types like `uint8_t`, `uint16_t`, -// or `unsigned short`. -// See https://github.com/llvm/llvm-project/pull/122410. -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -__fill_masked_range(_StoragePointer __word, unsigned __clz, unsigned __ctz, bool __fill_val) { - static_assert(is_unsigned::element_type>::value, - "__fill_masked_range must be called with unsigned type"); - using _StorageType = typename pointer_traits<_StoragePointer>::element_type; - _LIBCPP_ASSERT_VALID_INPUT_RANGE( - __ctz + __clz < sizeof(_StorageType) * CHAR_BIT, "__fill_masked_range called with invalid range"); - _StorageType __m = std::__middle_mask<_StorageType>(__clz, __ctz); - if (__fill_val) - *__word |= __m; - else - *__word &= ~__m; -} - -template ::value> -class __bit_reference { - using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; - using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer; - - __storage_pointer __seg_; - __storage_type __mask_; - - friend typename _Cp::__self; - - friend class __bit_const_reference<_Cp>; - friend class __bit_iterator<_Cp, false>; - -public: - using __container _LIBCPP_NODEBUG = typename _Cp::__self; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference(const __bit_reference&) = default; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 operator bool() const _NOEXCEPT { - return static_cast(*__seg_ & __mask_); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool operator~() const _NOEXCEPT { - return !static_cast(*this); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference& operator=(bool __x) _NOEXCEPT { - if (__x) - *__seg_ |= __mask_; - else - *__seg_ &= ~__mask_; - return *this; - } - -#if _LIBCPP_STD_VER >= 23 - _LIBCPP_HIDE_FROM_ABI constexpr const __bit_reference& operator=(bool __x) const noexcept { - if (__x) - *__seg_ |= __mask_; - else - *__seg_ &= ~__mask_; - return *this; - } -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT { - return operator=(static_cast(__x)); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT { *__seg_ ^= __mask_; } - -private: - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT - : __seg_(__s), - __mask_(__m) {} -}; - -template -class __bit_reference<_Cp, false> {}; - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void -swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -class __bit_const_reference { - using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; - using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__const_storage_pointer; - - __storage_pointer __seg_; - __storage_type __mask_; - - friend typename _Cp::__self; - friend class __bit_iterator<_Cp, true>; - -public: - using __container _LIBCPP_NODEBUG = typename _Cp::__self; - - _LIBCPP_HIDE_FROM_ABI __bit_const_reference(const __bit_const_reference&) = default; - __bit_const_reference& operator=(const __bit_const_reference&) = delete; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT - : __seg_(__x.__seg_), - __mask_(__x.__mask_) {} - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT { - return static_cast(*__seg_ & __mask_); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, true> operator&() const _NOEXCEPT { - return __bit_iterator<_Cp, true>(__seg_, static_cast(std::__countr_zero(__mask_))); - } - -private: - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR explicit __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT - : __seg_(__s), - __mask_(__m) {} -}; - -template -struct __bit_array { - using difference_type _LIBCPP_NODEBUG = typename __size_difference_type_traits<_Cp>::difference_type; - using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; - using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer; - using iterator _LIBCPP_NODEBUG = typename _Cp::iterator; - - static const unsigned __bits_per_word = _Cp::__bits_per_word; - static const unsigned _Np = 4; - - difference_type __size_; - __storage_type __word_[_Np]; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static difference_type capacity() { - return static_cast(_Np * __bits_per_word); - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bit_array(difference_type __s) : __size_(__s) { - if (__libcpp_is_constant_evaluated()) { - for (size_t __i = 0; __i != __bit_array<_Cp>::_Np; ++__i) - std::__construct_at(__word_ + __i, 0); - } - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() { - return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() { - return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, - static_cast(__size_ % __bits_per_word)); - } -}; - -template -class __bit_iterator { -public: - using difference_type = typename __size_difference_type_traits<_Cp>::difference_type; - using value_type = bool; - using pointer = __bit_iterator; -#ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL - using reference = __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >; -#else - using reference = __conditional_t<_IsConst, bool, __bit_reference<_Cp> >; -#endif - using iterator_category = random_access_iterator_tag; - -private: - using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; - using __storage_pointer _LIBCPP_NODEBUG = - __conditional_t<_IsConst, typename _Cp::__const_storage_pointer, typename _Cp::__storage_pointer>; - - static const unsigned __bits_per_word = _Cp::__bits_per_word; - - __storage_pointer __seg_; - unsigned __ctz_; - -public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator() _NOEXCEPT -#if _LIBCPP_STD_VER >= 14 - : __seg_(nullptr), - __ctz_(0) -#endif - { - } - -#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR - template = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT - : __seg_(__it.__seg_), - __ctz_(__it.__ctz_) {} - - _LIBCPP_HIDE_FROM_ABI __bit_iterator(const __bit_iterator&) = default; - _LIBCPP_HIDE_FROM_ABI __bit_iterator& operator=(const __bit_iterator&) = default; -#else - // When _IsConst=false, this is the copy constructor. - // It is non-trivial. Making it trivial would break ABI. - // When _IsConst=true, this is a converting constructor; - // the copy and move constructors are implicitly generated - // and trivial. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT - : __seg_(__it.__seg_), - __ctz_(__it.__ctz_) {} - - // When _IsConst=false, we have a user-provided copy constructor, - // so we must also provide a copy assignment operator because - // the implicit generation of a defaulted one is deprecated. - // When _IsConst=true, the assignment operators are - // implicitly generated and trivial. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& - operator=(const _If<_IsConst, struct __private_nat, __bit_iterator>& __it) { - __seg_ = __it.__seg_; - __ctz_ = __it.__ctz_; - return *this; - } -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator*() const _NOEXCEPT { - _LIBCPP_ASSERT_INTERNAL(__ctz_ < __bits_per_word, "Dereferencing an invalid __bit_iterator."); - return __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >( - __seg_, __storage_type(1) << __ctz_); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator++() { - if (__ctz_ != __bits_per_word - 1) - ++__ctz_; - else { - __ctz_ = 0; - ++__seg_; - } - return *this; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator++(int) { - __bit_iterator __tmp = *this; - ++(*this); - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator--() { - if (__ctz_ != 0) - --__ctz_; - else { - __ctz_ = __bits_per_word - 1; - --__seg_; - } - return *this; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator--(int) { - __bit_iterator __tmp = *this; - --(*this); - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator+=(difference_type __n) { - if (__n >= 0) - __seg_ += (__n + __ctz_) / __bits_per_word; - else - __seg_ += static_cast(__n - __bits_per_word + __ctz_ + 1) / - static_cast(__bits_per_word); - __n &= (__bits_per_word - 1); - __ctz_ = static_cast((__n + __ctz_) % __bits_per_word); - return *this; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator& operator-=(difference_type __n) { - return *this += -__n; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator+(difference_type __n) const { - __bit_iterator __t(*this); - __t += __n; - return __t; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator operator-(difference_type __n) const { - __bit_iterator __t(*this); - __t -= __n; - return __t; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator - operator+(difference_type __n, const __bit_iterator& __it) { - return __it + __n; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend difference_type - operator-(const __bit_iterator& __x, const __bit_iterator& __y) { - return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](difference_type __n) const { - return *(*this + __n); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - operator==(const __bit_iterator& __x, const __bit_iterator& __y) { - return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_; - } - -#if _LIBCPP_STD_VER <= 17 - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - operator!=(const __bit_iterator& __x, const __bit_iterator& __y) { - return !(__x == __y); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - operator<(const __bit_iterator& __x, const __bit_iterator& __y) { - return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - operator>(const __bit_iterator& __x, const __bit_iterator& __y) { - return __y < __x; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - operator<=(const __bit_iterator& __x, const __bit_iterator& __y) { - return !(__y < __x); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - operator>=(const __bit_iterator& __x, const __bit_iterator& __y) { - return !(__x < __y); - } -#else // _LIBCPP_STD_VER <= 17 - _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering - operator<=>(const __bit_iterator& __x, const __bit_iterator& __y) { - if (__x.__seg_ < __y.__seg_) - return strong_ordering::less; - - if (__x.__seg_ == __y.__seg_) - return __x.__ctz_ <=> __y.__ctz_; - - return strong_ordering::greater; - } -#endif // _LIBCPP_STD_VER <= 17 - -private: - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT - : __seg_(__s), - __ctz_(__ctz) { - _LIBCPP_ASSERT_INTERNAL( - __ctz_ < __bits_per_word, "__bit_iterator initialized with an invalid number of trailing zeros."); - } - - friend typename _Cp::__self; - - friend class __bit_reference<_Cp>; - friend class __bit_const_reference<_Cp>; - friend class __bit_iterator<_Cp, true>; - template - friend struct __bit_array; - - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_backward_aligned( - __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_backward_unaligned( - __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - friend struct __copy_backward_impl; - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend pair<__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false> > - __rotate(__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>); - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - __equal_aligned(__bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst2>); - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool - __equal_unaligned(__bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst2>); - template ::value && __is_identity<_Proj2>::value && - __desugars_to_v<__equal_tag, _BinaryPredicate, bool, bool>, - int> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool __equal_iter_impl( - __bit_iterator<_Dp, _IsConst1>, - __bit_iterator<_Dp, _IsConst1>, - __bit_iterator<_Dp, _IsConst2>, - _BinaryPredicate, - _Proj1&, - _Proj2&); - template && __is_identity<_Proj1>::value && - __is_identity<_Proj2>::value, - int> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool __equal_impl( - __bit_iterator<_Dp, _IsConst1> __first1, - __bit_iterator<_Dp, _IsConst1> __last1, - __bit_iterator<_Dp, _IsConst2> __first2, - __bit_iterator<_Dp, _IsConst2>, - _Pred&, - _Proj1&, - _Proj2&); - template - _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, _IC> - __find_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type); - template - friend typename __bit_iterator<_Dp, _IC>::difference_type _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - __count_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type); - - template - friend struct __specialized_algorithm; -}; - -template -struct __specialized_algorithm<_Algorithm::__fill_n, __single_iterator<__bit_iterator<_Cp, false> > > { - static const bool __has_algorithm = true; - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void - __impl(__bit_iterator<_Cp, false> __first, typename __size_difference_type_traits<_Cp>::size_type __n) { - using _It = __bit_iterator<_Cp, false>; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - // do first partial word - if (__first.__ctz_ != 0) { - __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); - __storage_type __dn = std::min(__clz_f, __n); - std::__fill_masked_range(std::__to_address(__first.__seg_), __clz_f - __dn, __first.__ctz_, _FillVal); - __n -= __dn; - ++__first.__seg_; - } - // do middle whole words - __storage_type __nw = __n / __bits_per_word; - std::__fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0); - __n -= __nw * __bits_per_word; - // do last partial word - if (__n > 0) { - __first.__seg_ += __nw; - std::__fill_masked_range(std::__to_address(__first.__seg_), __bits_per_word - __n, 0u, _FillVal); - } - } - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static __bit_iterator<_Cp, false> - operator()(__bit_iterator<_Cp, false> __first, _Size __n, const _Tp& __value) { - if (__n > 0) { - if (__value) - __impl(__first, __n); - else - __impl(__first, __n); - } - return __first + __n; - } -}; - -template -struct __specialized_algorithm<_Algorithm::__copy, - __iterator_pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, _IsConst> >, - __single_iterator<__bit_iterator<_Cp, false> > > { - static const bool __has_algorithm = true; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static __bit_iterator<_Cp, false> - __aligned_impl(__bit_iterator<_Cp, _IsConst> __first, - __bit_iterator<_Cp, _IsConst> __last, - __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz), __n); - __n -= __dn; - __storage_type __m = std::__middle_mask<__storage_type>(__clz - __dn, __first.__ctz_); - __storage_type __b = *__first.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - __storage_type __nw = __n / __bits_per_word; - std::copy(std::__to_address(__first.__seg_), - std::__to_address(__first.__seg_ + __nw), - std::__to_address(__result.__seg_)); - __n -= __nw * __bits_per_word; - __result.__seg_ += __nw; - // do last word - if (__n > 0) { - __first.__seg_ += __nw; - __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - __storage_type __b = *__first.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__ctz_ = static_cast(__n); - } - } - return __result; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static __bit_iterator<_Cp, false> - __unaligned_impl(__bit_iterator<_Cp, _IsConst> __first, - __bit_iterator<_Cp, _IsConst> __last, - __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz_f = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz_f), __n); - __n -= __dn; - __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first.__ctz_); - __storage_type __b = *__first.__seg_ & __m; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); - __m = std::__middle_mask<__storage_type>(__clz_r - __ddn, __result.__ctz_); - *__result.__seg_ &= ~__m; - if (__result.__ctz_ > __first.__ctz_) - *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_); - else - *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_); - __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); - __dn -= __ddn; - if (__dn > 0) { - __m = std::__trailing_mask<__storage_type>(__bits_per_word - __dn); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn); - __result.__ctz_ = static_cast(__dn); - } - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __m = std::__leading_mask<__storage_type>(__result.__ctz_); - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { - __storage_type __b = *__first.__seg_; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b << __result.__ctz_; - ++__result.__seg_; - *__result.__seg_ &= __m; - *__result.__seg_ |= __b >> __clz_r; - } - // do last word - if (__n > 0) { - __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - __storage_type __b = *__first.__seg_ & __m; - __storage_type __dn = std::min(__n, static_cast(__clz_r)); - __m = std::__middle_mask<__storage_type>(__clz_r - __dn, __result.__ctz_); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b << __result.__ctz_; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> __dn; - __result.__ctz_ = static_cast(__n); - } - } - } - return __result; - } - - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR_SINCE_CXX20 static pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> > - operator()(__bit_iterator<_Cp, _IsConst> __first, - __bit_iterator<_Cp, _IsConst> __last, - __bit_iterator<_Cp, false> __result) { - if (__first.__ctz_ == __result.__ctz_) - return std::make_pair(__last, __aligned_impl(__first, __last, __result)); - return std::make_pair(__last, __unaligned_impl(__first, __last, __result)); - } -}; - -template -struct __specialized_algorithm<_Algorithm::__swap_ranges, - __iterator_pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false> >, - __single_iterator<__bit_iterator<_Cr, false> > > { - static const bool __has_algorithm = true; - - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __aligned_impl( - __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { - using _I1 = __bit_iterator<_Cl, false>; - using difference_type = typename _I1::difference_type; - using __storage_type = typename _I1::__storage_type; - - const int __bits_per_word = _I1::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1; - *__first.__seg_ |= __b2; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) - swap(*__first.__seg_, *__result.__seg_); - // do last word - if (__n > 0) { - __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1; - *__first.__seg_ |= __b2; - __result.__ctz_ = static_cast(__n); - } - } - return __result; - } - - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __unaligned_impl( - __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { - using _I1 = __bit_iterator<_Cl, false>; - using difference_type = typename _I1::difference_type; - using __storage_type = typename _I1::__storage_type; - - const int __bits_per_word = _I1::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz_f = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz_f), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); - __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - if (__result.__ctz_ > __first.__ctz_) { - unsigned __s = __result.__ctz_ - __first.__ctz_; - *__result.__seg_ |= __b1 << __s; - *__first.__seg_ |= __b2 >> __s; - } else { - unsigned __s = __first.__ctz_ - __result.__ctz_; - *__result.__seg_ |= __b1 >> __s; - *__first.__seg_ |= __b2 << __s; - } - __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); - __dn -= __ddn; - if (__dn > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __dn); - __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - unsigned __s = __first.__ctz_ + __ddn; - *__result.__seg_ |= __b1 >> __s; - *__first.__seg_ |= __b2 << __s; - __result.__ctz_ = static_cast(__dn); - } - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - __storage_type __m = ~__storage_type(0) << __result.__ctz_; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { - __storage_type __b1 = *__first.__seg_; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 << __result.__ctz_; - *__first.__seg_ = __b2 >> __result.__ctz_; - ++__result.__seg_; - __b2 = *__result.__seg_ & ~__m; - *__result.__seg_ &= __m; - *__result.__seg_ |= __b1 >> __clz_r; - *__first.__seg_ |= __b2 << __clz_r; - } - // do last word - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __dn = std::min<__storage_type>(__n, __clz_r); - __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 << __result.__ctz_; - *__first.__seg_ |= __b2 >> __result.__ctz_; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 >> __dn; - *__first.__seg_ |= __b2 << __dn; - __result.__ctz_ = static_cast(__n); - } - } - } - return __result; - } - - _LIBCPP_HIDE_FROM_ABI static - _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> > - operator()(__bit_iterator<_Cl, false> __first1, - __bit_iterator<_Cl, false> __last1, - __bit_iterator<_Cr, false> __first2) { - if (__first1.__ctz_ == __first2.__ctz_) - return std::make_pair(__last1, __aligned_impl(__first1, __last1, __first2)); - return std::make_pair(__last1, __unaligned_impl(__first1, __last1, __first2)); - } -}; - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___BIT_REFERENCE diff --git a/third_party/libcxx/include/c++/v1/__charconv/chars_format.h b/third_party/libcxx/include/c++/v1/__charconv/chars_format.h deleted file mode 100644 index c76cebd..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/chars_format.h +++ /dev/null @@ -1,61 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_CHARS_FORMAT_H -#define _LIBCPP___CHARCONV_CHARS_FORMAT_H - -#include <__config> -#include <__utility/to_underlying.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 - -enum class chars_format { scientific = 0x1, fixed = 0x2, hex = 0x4, general = fixed | scientific }; - -inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format operator~(chars_format __x) { - return chars_format(~std::__to_underlying(__x)); -} - -inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format operator&(chars_format __x, chars_format __y) { - return chars_format(std::__to_underlying(__x) & std::__to_underlying(__y)); -} - -inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format operator|(chars_format __x, chars_format __y) { - return chars_format(std::__to_underlying(__x) | std::__to_underlying(__y)); -} - -inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format operator^(chars_format __x, chars_format __y) { - return chars_format(std::__to_underlying(__x) ^ std::__to_underlying(__y)); -} - -inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format& operator&=(chars_format& __x, chars_format __y) { - __x = __x & __y; - return __x; -} - -inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format& operator|=(chars_format& __x, chars_format __y) { - __x = __x | __y; - return __x; -} - -inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format& operator^=(chars_format& __x, chars_format __y) { - __x = __x ^ __y; - return __x; -} - -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHARCONV_CHARS_FORMAT_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/from_chars_floating_point.h b/third_party/libcxx/include/c++/v1/__charconv/from_chars_floating_point.h deleted file mode 100644 index 811e518..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/from_chars_floating_point.h +++ /dev/null @@ -1,73 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H -#define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H - -#include <__assert> -#include <__charconv/chars_format.h> -#include <__charconv/from_chars_result.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__system_error/errc.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 - -template -struct __from_chars_result { - _Fp __value; - ptrdiff_t __n; - errc __ec; -}; - -template -_LIBCPP_EXPORTED_FROM_ABI __from_chars_result<_Fp> __from_chars_floating_point( - _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); - -extern template __from_chars_result __from_chars_floating_point( - _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); - -extern template __from_chars_result __from_chars_floating_point( - _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); - -template -_LIBCPP_HIDE_FROM_ABI from_chars_result -__from_chars(const char* __first, const char* __last, _Fp& __value, chars_format __fmt) { - __from_chars_result<_Fp> __r = std::__from_chars_floating_point<_Fp>(__first, __last, __fmt); - if (__r.__ec != errc::invalid_argument) - __value = __r.__value; - return {__first + __r.__n, __r.__ec}; -} - -_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result -from_chars(const char* __first, const char* __last, float& __value, chars_format __fmt = chars_format::general) { - return std::__from_chars(__first, __last, __value, __fmt); -} - -_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result -from_chars(const char* __first, const char* __last, double& __value, chars_format __fmt = chars_format::general) { - return std::__from_chars(__first, __last, __value, __fmt); -} - -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/from_chars_integral.h b/third_party/libcxx/include/c++/v1/__charconv/from_chars_integral.h deleted file mode 100644 index 3063c09..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/from_chars_integral.h +++ /dev/null @@ -1,237 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_FROM_CHARS_INTEGRAL_H -#define _LIBCPP___CHARCONV_FROM_CHARS_INTEGRAL_H - -#include <__assert> -#include <__charconv/from_chars_result.h> -#include <__charconv/traits.h> -#include <__config> -#include <__system_error/errc.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_signed.h> -#include <__type_traits/is_unsigned.h> -#include <__type_traits/make_unsigned.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 - -from_chars_result from_chars(const char*, const char*, bool, int = 10) = delete; - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -__sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args) { - using __tl = numeric_limits<_Tp>; - decltype(std::__to_unsigned_like(__value)) __x; - - bool __neg = (__first != __last && *__first == '-'); - auto __r = __f(__neg ? __first + 1 : __first, __last, __x, __args...); - switch (__r.ec) { - case errc::invalid_argument: - return {__first, __r.ec}; - case errc::result_out_of_range: - return __r; - default: - break; - } - - if (__neg) { - if (__x <= std::__complement(std::__to_unsigned_like(__tl::min()))) { - __value = std::__complement(__x); - return __r; - } - } else { - if (__x <= std::__to_unsigned_like(__tl::max())) { - __value = __x; - return __r; - } - } - - return {__r.ptr, errc::result_out_of_range}; -} - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool __in_pattern(_Tp __c) { - return '0' <= __c && __c <= '9'; -} - -struct _LIBCPP_HIDDEN __in_pattern_result { - bool __ok; - int __val; - - explicit _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI operator bool() const { return __ok; } -}; - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __in_pattern_result __in_pattern(_Tp __c, int __base) { - if (__base <= 10) - return {'0' <= __c && __c < '0' + __base, __c - '0'}; - else if (std::__in_pattern(__c)) - return {true, __c - '0'}; - else if ('a' <= __c && __c < 'a' + __base - 10) - return {true, __c - 'a' + 10}; - else - return {'A' <= __c && __c < 'A' + __base - 10, __c - 'A' + 10}; -} - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -__subject_seq_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args) { - auto __find_non_zero = [](_It __firstit, _It __lastit) { - for (; __firstit != __lastit; ++__firstit) - if (*__firstit != '0') - break; - return __firstit; - }; - - auto __p = __find_non_zero(__first, __last); - if (__p == __last || !std::__in_pattern(*__p, __args...)) { - if (__p == __first) - return {__first, errc::invalid_argument}; - else { - __value = 0; - return {__p, {}}; - } - } - - auto __r = __f(__p, __last, __value, __args...); - if (__r.ec == errc::result_out_of_range) { - for (; __r.ptr != __last; ++__r.ptr) { - if (!std::__in_pattern(*__r.ptr, __args...)) - break; - } - } - - return __r; -} - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -__from_chars_atoi(const char* __first, const char* __last, _Tp& __value) { - using __tx = __itoa::__traits<_Tp>; - using __output_type = typename __tx::type; - - return std::__subject_seq_combinator( - __first, __last, __value, [](const char* __f, const char* __l, _Tp& __val) -> from_chars_result { - __output_type __a, __b; - auto __p = __tx::__read(__f, __l, __a, __b); - if (__p == __l || !std::__in_pattern(*__p)) { - __output_type __m = numeric_limits<_Tp>::max(); - if (__m >= __a && __m - __a >= __b) { - __val = __a + __b; - return {__p, {}}; - } - } - return {__p, errc::result_out_of_range}; - }); -} - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -__from_chars_atoi(const char* __first, const char* __last, _Tp& __value) { - using __t = decltype(std::__to_unsigned_like(__value)); - return std::__sign_combinator(__first, __last, __value, __from_chars_atoi<__t>); -} - -/* -// Code used to generate __from_chars_log2f_lut. -#include -#include -#include - -int main() { - for (int i = 2; i <= 36; ++i) - std::cout << std::format("{},\n", log2f(i)); -} -*/ -/// log2f table for bases [2, 36]. -inline constexpr float __from_chars_log2f_lut[35] = { - 1, 1.5849625, 2, 2.321928, 2.5849626, 2.807355, 3, 3.169925, 3.321928, - 3.4594316, 3.5849626, 3.7004397, 3.807355, 3.9068906, 4, 4.087463, 4.169925, 4.2479277, - 4.321928, 4.3923173, 4.4594316, 4.523562, 4.5849624, 4.643856, 4.70044, 4.7548876, 4.807355, - 4.857981, 4.9068904, 4.9541965, 5, 5.044394, 5.087463, 5.129283, 5.169925}; - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -__from_chars_integral(const char* __first, const char* __last, _Tp& __value, int __base) { - if (__base == 10) - return std::__from_chars_atoi(__first, __last, __value); - - return std::__subject_seq_combinator( - __first, - __last, - __value, - [](const char* __p, const char* __lastp, _Tp& __val, int __b) -> from_chars_result { - using __tl = numeric_limits<_Tp>; - // __base is always between 2 and 36 inclusive. - auto __digits = __tl::digits / __from_chars_log2f_lut[__b - 2]; - _Tp __x = __in_pattern(*__p++, __b).__val, __y = 0; - - for (int __i = 1; __p != __lastp; ++__i, ++__p) { - if (auto __c = __in_pattern(*__p, __b)) { - if (__i < __digits - 1) - __x = __x * __b + __c.__val; - else { - if (!__itoa::__mul_overflowed(__x, __b, __x)) - ++__p; - __y = __c.__val; - break; - } - } else - break; - } - - if (__p == __lastp || !__in_pattern(*__p, __b)) { - if (__tl::max() - __x >= __y) { - __val = __x + __y; - return {__p, {}}; - } - } - return {__p, errc::result_out_of_range}; - }, - __base); -} - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -__from_chars_integral(const char* __first, const char* __last, _Tp& __value, int __base) { - using __t = decltype(std::__to_unsigned_like(__value)); - return std::__sign_combinator(__first, __last, __value, __from_chars_integral<__t>, __base); -} - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -from_chars(const char* __first, const char* __last, _Tp& __value) { - return std::__from_chars_atoi(__first, __last, __value); -} - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result -from_chars(const char* __first, const char* __last, _Tp& __value, int __base) { - _LIBCPP_ASSERT_UNCATEGORIZED(2 <= __base && __base <= 36, "base not in [2, 36]"); - return std::__from_chars_integral(__first, __last, __value, __base); -} -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHARCONV_FROM_CHARS_INTEGRAL_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/from_chars_result.h b/third_party/libcxx/include/c++/v1/__charconv/from_chars_result.h deleted file mode 100644 index b4ecea3..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/from_chars_result.h +++ /dev/null @@ -1,39 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H -#define _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H - -#include <__config> -#include <__system_error/errc.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 - -struct from_chars_result { - const char* ptr; - errc ec; -# if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI friend bool operator==(const from_chars_result&, const from_chars_result&) = default; -# endif -# if _LIBCPP_STD_VER >= 26 - _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return ec == errc{}; } -# endif -}; - -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/tables.h b/third_party/libcxx/include/c++/v1/__charconv/tables.h deleted file mode 100644 index b8c6fd8..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/tables.h +++ /dev/null @@ -1,159 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_TABLES -#define _LIBCPP___CHARCONV_TABLES - -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __itoa { - -inline _LIBCPP_CONSTEXPR const char __base_2_lut[64] = { - '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '1', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '1', - '0', '1', '0', '1', '1', '0', '0', '1', '1', '1', '1', '0', '0', '0', '1', '0', '0', '1', '1', '0', '1', '0', - '1', '0', '1', '1', '1', '1', '0', '0', '1', '1', '0', '1', '1', '1', '1', '0', '1', '1', '1', '1'}; - -inline _LIBCPP_CONSTEXPR const char __base_8_lut[128] = { - '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '1', '0', '1', '1', '1', '2', - '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', - '2', '6', '2', '7', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '4', '0', - '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '5', '0', '5', '1', '5', '2', '5', '3', - '5', '4', '5', '5', '5', '6', '5', '7', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', - '6', '7', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7'}; - -inline _LIBCPP_CONSTEXPR const char __base_16_lut[512] = { - '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '0', 'a', '0', - 'b', '0', 'c', '0', 'd', '0', 'e', '0', 'f', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', - '1', '7', '1', '8', '1', '9', '1', 'a', '1', 'b', '1', 'c', '1', 'd', '1', 'e', '1', 'f', '2', '0', '2', '1', '2', - '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', '2', 'a', '2', 'b', '2', 'c', '2', 'd', - '2', 'e', '2', 'f', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', - '9', '3', 'a', '3', 'b', '3', 'c', '3', 'd', '3', 'e', '3', 'f', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', - '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '4', 'a', '4', 'b', '4', 'c', '4', 'd', '4', 'e', '4', 'f', '5', - '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', '5', 'a', '5', 'b', - '5', 'c', '5', 'd', '5', 'e', '5', 'f', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', - '7', '6', '8', '6', '9', '6', 'a', '6', 'b', '6', 'c', '6', 'd', '6', 'e', '6', 'f', '7', '0', '7', '1', '7', '2', - '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '7', 'a', '7', 'b', '7', 'c', '7', 'd', '7', - 'e', '7', 'f', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', - '8', 'a', '8', 'b', '8', 'c', '8', 'd', '8', 'e', '8', 'f', '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', - '5', '9', '6', '9', '7', '9', '8', '9', '9', '9', 'a', '9', 'b', '9', 'c', '9', 'd', '9', 'e', '9', 'f', 'a', '0', - 'a', '1', 'a', '2', 'a', '3', 'a', '4', 'a', '5', 'a', '6', 'a', '7', 'a', '8', 'a', '9', 'a', 'a', 'a', 'b', 'a', - 'c', 'a', 'd', 'a', 'e', 'a', 'f', 'b', '0', 'b', '1', 'b', '2', 'b', '3', 'b', '4', 'b', '5', 'b', '6', 'b', '7', - 'b', '8', 'b', '9', 'b', 'a', 'b', 'b', 'b', 'c', 'b', 'd', 'b', 'e', 'b', 'f', 'c', '0', 'c', '1', 'c', '2', 'c', - '3', 'c', '4', 'c', '5', 'c', '6', 'c', '7', 'c', '8', 'c', '9', 'c', 'a', 'c', 'b', 'c', 'c', 'c', 'd', 'c', 'e', - 'c', 'f', 'd', '0', 'd', '1', 'd', '2', 'd', '3', 'd', '4', 'd', '5', 'd', '6', 'd', '7', 'd', '8', 'd', '9', 'd', - 'a', 'd', 'b', 'd', 'c', 'd', 'd', 'd', 'e', 'd', 'f', 'e', '0', 'e', '1', 'e', '2', 'e', '3', 'e', '4', 'e', '5', - 'e', '6', 'e', '7', 'e', '8', 'e', '9', 'e', 'a', 'e', 'b', 'e', 'c', 'e', 'd', 'e', 'e', 'e', 'f', 'f', '0', 'f', - '1', 'f', '2', 'f', '3', 'f', '4', 'f', '5', 'f', '6', 'f', '7', 'f', '8', 'f', '9', 'f', 'a', 'f', 'b', 'f', 'c', - 'f', 'd', 'f', 'e', 'f', 'f'}; - -inline _LIBCPP_CONSTEXPR const uint32_t __pow10_32[10] = { - UINT32_C(0), - UINT32_C(10), - UINT32_C(100), - UINT32_C(1000), - UINT32_C(10000), - UINT32_C(100000), - UINT32_C(1000000), - UINT32_C(10000000), - UINT32_C(100000000), - UINT32_C(1000000000)}; - -inline _LIBCPP_CONSTEXPR const uint64_t __pow10_64[20] = { - UINT64_C(0), - UINT64_C(10), - UINT64_C(100), - UINT64_C(1000), - UINT64_C(10000), - UINT64_C(100000), - UINT64_C(1000000), - UINT64_C(10000000), - UINT64_C(100000000), - UINT64_C(1000000000), - UINT64_C(10000000000), - UINT64_C(100000000000), - UINT64_C(1000000000000), - UINT64_C(10000000000000), - UINT64_C(100000000000000), - UINT64_C(1000000000000000), - UINT64_C(10000000000000000), - UINT64_C(100000000000000000), - UINT64_C(1000000000000000000), - UINT64_C(10000000000000000000)}; - -# if _LIBCPP_HAS_INT128 -inline _LIBCPP_CONSTEXPR const int __pow10_128_offset = 0; -inline _LIBCPP_CONSTEXPR const __uint128_t __pow10_128[40] = { - UINT64_C(0), - UINT64_C(10), - UINT64_C(100), - UINT64_C(1000), - UINT64_C(10000), - UINT64_C(100000), - UINT64_C(1000000), - UINT64_C(10000000), - UINT64_C(100000000), - UINT64_C(1000000000), - UINT64_C(10000000000), - UINT64_C(100000000000), - UINT64_C(1000000000000), - UINT64_C(10000000000000), - UINT64_C(100000000000000), - UINT64_C(1000000000000000), - UINT64_C(10000000000000000), - UINT64_C(100000000000000000), - UINT64_C(1000000000000000000), - UINT64_C(10000000000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000000), - __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000), - (__uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000)) * 10}; -# endif - -inline _LIBCPP_CONSTEXPR const char __digits_base_10[200] = { - // clang-format off - '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', - '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', - '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', - '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', - '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', - '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', - '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', - '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', - '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', - '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'}; -// clang-format on - -} // namespace __itoa - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHARCONV_TABLES diff --git a/third_party/libcxx/include/c++/v1/__charconv/to_chars.h b/third_party/libcxx/include/c++/v1/__charconv/to_chars.h deleted file mode 100644 index 8ef09af..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/to_chars.h +++ /dev/null @@ -1,25 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_TO_CHARS -#define _LIBCPP___CHARCONV_TO_CHARS - -#include <__charconv/to_chars_floating_point.h> -#include <__charconv/to_chars_integral.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHARCONV_TO_CHARS diff --git a/third_party/libcxx/include/c++/v1/__charconv/to_chars_base_10.h b/third_party/libcxx/include/c++/v1/__charconv/to_chars_base_10.h deleted file mode 100644 index d90952e..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/to_chars_base_10.h +++ /dev/null @@ -1,184 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_TO_CHARS_BASE_10_H -#define _LIBCPP___CHARCONV_TO_CHARS_BASE_10_H - -#include <__algorithm/copy_n.h> -#include <__assert> -#include <__charconv/tables.h> -#include <__config> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __itoa { - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append1(char* __first, uint32_t __value) _NOEXCEPT { - *__first = '0' + static_cast(__value); - return __first + 1; -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append2(char* __first, uint32_t __value) _NOEXCEPT { - return std::copy_n(&__digits_base_10[__value * 2], 2, __first); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append3(char* __first, uint32_t __value) _NOEXCEPT { - return __itoa::__append2(__itoa::__append1(__first, __value / 100), __value % 100); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append4(char* __first, uint32_t __value) _NOEXCEPT { - return __itoa::__append2(__itoa::__append2(__first, __value / 100), __value % 100); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append5(char* __first, uint32_t __value) _NOEXCEPT { - return __itoa::__append4(__itoa::__append1(__first, __value / 10000), __value % 10000); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append6(char* __first, uint32_t __value) _NOEXCEPT { - return __itoa::__append4(__itoa::__append2(__first, __value / 10000), __value % 10000); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append7(char* __first, uint32_t __value) _NOEXCEPT { - return __itoa::__append6(__itoa::__append1(__first, __value / 1000000), __value % 1000000); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append8(char* __first, uint32_t __value) _NOEXCEPT { - return __itoa::__append6(__itoa::__append2(__first, __value / 1000000), __value % 1000000); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append9(char* __first, uint32_t __value) _NOEXCEPT { - return __itoa::__append8(__itoa::__append1(__first, __value / 100000000), __value % 100000000); -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char* __append10(char* __first, _Tp __value) _NOEXCEPT { - return __itoa::__append8(__itoa::__append2(__first, static_cast(__value / 100000000)), - static_cast(__value % 100000000)); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* -__base_10_u32(char* __first, uint32_t __value) _NOEXCEPT { - if (__value < 1000000) { - if (__value < 10000) { - if (__value < 100) { - // 0 <= __value < 100 - if (__value < 10) - return __itoa::__append1(__first, __value); - return __itoa::__append2(__first, __value); - } - // 100 <= __value < 10'000 - if (__value < 1000) - return __itoa::__append3(__first, __value); - return __itoa::__append4(__first, __value); - } - - // 10'000 <= __value < 1'000'000 - if (__value < 100000) - return __itoa::__append5(__first, __value); - return __itoa::__append6(__first, __value); - } - - // __value => 1'000'000 - if (__value < 100000000) { - // 1'000'000 <= __value < 100'000'000 - if (__value < 10000000) - return __itoa::__append7(__first, __value); - return __itoa::__append8(__first, __value); - } - - // 100'000'000 <= __value < max - if (__value < 1000000000) - return __itoa::__append9(__first, __value); - return __itoa::__append10(__first, __value); -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* -__base_10_u64(char* __buffer, uint64_t __value) _NOEXCEPT { - if (__value <= UINT32_MAX) - return __itoa::__base_10_u32(__buffer, static_cast(__value)); - - // Numbers in the range UINT32_MAX <= val < 10'000'000'000 always contain 10 - // digits and are outputted after this if statement. - if (__value >= 10000000000) { - // This function properly deterimines the first non-zero leading digit. - __buffer = __itoa::__base_10_u32(__buffer, static_cast(__value / 10000000000)); - __value %= 10000000000; - } - return __itoa::__append10(__buffer, __value); -} - -# if _LIBCPP_HAS_INT128 -/// \returns 10^\a exp -/// -/// \pre \a exp [19, 39] -/// -/// \note The lookup table contains a partial set of exponents limiting the -/// range that can be used. However the range is sufficient for -/// \ref __base_10_u128. -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline __uint128_t __pow_10(int __exp) _NOEXCEPT { - _LIBCPP_ASSERT_INTERNAL(__exp >= __pow10_128_offset, "Index out of bounds"); - return __pow10_128[__exp - __pow10_128_offset]; -} - -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* -__base_10_u128(char* __buffer, __uint128_t __value) _NOEXCEPT { - _LIBCPP_ASSERT_INTERNAL( - __value > numeric_limits::max(), "The optimizations for this algorithm fails when this isn't true."); - - // Unlike the 64 to 32 bit case the 128 bit case the "upper half" can't be - // stored in the "lower half". Instead we first need to handle the top most - // digits separately. - // - // Maximum unsigned values - // 64 bit 18'446'744'073'709'551'615 (20 digits) - // 128 bit 340'282'366'920'938'463'463'374'607'431'768'211'455 (39 digits) - // step 1 ^ ([0-1] digits) - // step 2 ^^^^^^^^^^^^^^^^^^^^^^^^^ ([0-19] digits) - // step 3 ^^^^^^^^^^^^^^^^^^^^^^^^^ (19 digits) - if (__value >= __itoa::__pow_10(38)) { - // step 1 - __buffer = __itoa::__append1(__buffer, static_cast(__value / __itoa::__pow_10(38))); - __value %= __itoa::__pow_10(38); - - // step 2 always 19 digits. - // They are handled here since leading zeros need to be appended to the buffer, - __buffer = __itoa::__append9(__buffer, static_cast(__value / __itoa::__pow_10(29))); - __value %= __itoa::__pow_10(29); - __buffer = __itoa::__append10(__buffer, static_cast(__value / __itoa::__pow_10(19))); - __value %= __itoa::__pow_10(19); - } else { - // step 2 - // This version needs to determine the position of the leading non-zero digit. - __buffer = __base_10_u64(__buffer, static_cast(__value / __itoa::__pow_10(19))); - __value %= __itoa::__pow_10(19); - } - - // Step 3 - __buffer = __itoa::__append9(__buffer, static_cast(__value / 10000000000)); - __buffer = __itoa::__append10(__buffer, static_cast(__value % 10000000000)); - - return __buffer; -} -# endif -} // namespace __itoa - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHARCONV_TO_CHARS_BASE_10_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/to_chars_floating_point.h b/third_party/libcxx/include/c++/v1/__charconv/to_chars_floating_point.h deleted file mode 100644 index 118f316..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/to_chars_floating_point.h +++ /dev/null @@ -1,55 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_TO_CHARS_FLOATING_POINT_H -#define _LIBCPP___CHARCONV_TO_CHARS_FLOATING_POINT_H - -#include <__charconv/chars_format.h> -#include <__charconv/to_chars_result.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, float __value); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, double __value); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, long double __value); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, float __value, chars_format __fmt); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, double __value, chars_format __fmt); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, long double __value, chars_format __fmt); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision); - -_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_EXPORTED_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision); -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHARCONV_TO_CHARS_FLOATING_POINT_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/to_chars_integral.h b/third_party/libcxx/include/c++/v1/__charconv/to_chars_integral.h deleted file mode 100644 index 6d42513..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/to_chars_integral.h +++ /dev/null @@ -1,344 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_TO_CHARS_INTEGRAL_H -#define _LIBCPP___CHARCONV_TO_CHARS_INTEGRAL_H - -#include <__algorithm/copy_n.h> -#include <__assert> -#include <__bit/countl.h> -#include <__charconv/tables.h> -#include <__charconv/to_chars_base_10.h> -#include <__charconv/to_chars_result.h> -#include <__charconv/traits.h> -#include <__config> -#include <__cstddef/ptrdiff_t.h> -#include <__system_error/errc.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/integral_constant.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_signed.h> -#include <__type_traits/make_32_64_or_128_bit.h> -#include <__type_traits/make_unsigned.h> -#include <__utility/unreachable.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type); - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_itoa(char* __first, char* __last, _Tp __value, true_type) { - auto __x = std::__to_unsigned_like(__value); - if (__value < 0 && __first != __last) { - *__first++ = '-'; - __x = std::__complement(__x); - } - - return std::__to_chars_itoa(__first, __last, __x, false_type()); -} - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type) { - using __tx = __itoa::__traits<_Tp>; - auto __diff = __last - __first; - - if (__tx::digits <= __diff || __tx::__width(__value) <= __diff) - return {__tx::__convert(__first, __value), errc(0)}; - else - return {__last, errc::value_too_large}; -} - -# if _LIBCPP_HAS_INT128 -template <> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_itoa(char* __first, char* __last, __uint128_t __value, false_type) { - // When the value fits in 64-bits use the 64-bit code path. This reduces - // the number of expensive calculations on 128-bit values. - // - // NOTE the 128-bit code path requires this optimization. - if (__value <= numeric_limits::max()) - return __to_chars_itoa(__first, __last, static_cast(__value), false_type()); - - using __tx = __itoa::__traits<__uint128_t>; - auto __diff = __last - __first; - - if (__tx::digits <= __diff || __tx::__width(__value) <= __diff) - return {__tx::__convert(__first, __value), errc(0)}; - else - return {__last, errc::value_too_large}; -} -# endif - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_integral(char* __first, char* __last, _Tp __value, int __base); - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_integral(char* __first, char* __last, _Tp __value, int __base) { - auto __x = std::__to_unsigned_like(__value); - if (__value < 0 && __first != __last) { - *__first++ = '-'; - __x = std::__complement(__x); - } - - return std::__to_chars_integral(__first, __last, __x, __base); -} - -namespace __itoa { - -template -struct _LIBCPP_HIDDEN __integral; - -template <> -struct _LIBCPP_HIDDEN __integral<2> { - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR int __width(_Tp __value) _NOEXCEPT { - // If value == 0 still need one digit. If the value != this has no - // effect since the code scans for the most significant bit set. - return numeric_limits<_Tp>::digits - std::__countl_zero(__value | 1); - } - - template - _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static __to_chars_result - __to_chars(char* __first, char* __last, _Tp __value) { - ptrdiff_t __cap = __last - __first; - int __n = __width(__value); - if (__n > __cap) - return {__last, errc::value_too_large}; - - __last = __first + __n; - char* __p = __last; - const unsigned __divisor = 16; - while (__value > __divisor) { - unsigned __c = __value % __divisor; - __value /= __divisor; - __p -= 4; - std::copy_n(&__base_2_lut[4 * __c], 4, __p); - } - do { - unsigned __c = __value % 2; - __value /= 2; - *--__p = "01"[__c]; - } while (__value != 0); - return {__last, errc(0)}; - } -}; - -template <> -struct _LIBCPP_HIDDEN __integral<8> { - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR int __width(_Tp __value) _NOEXCEPT { - // If value == 0 still need one digit. If the value != this has no - // effect since the code scans for the most significat bit set. - return ((numeric_limits<_Tp>::digits - std::__countl_zero(__value | 1)) + 2) / 3; - } - - template - _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static __to_chars_result - __to_chars(char* __first, char* __last, _Tp __value) { - ptrdiff_t __cap = __last - __first; - int __n = __width(__value); - if (__n > __cap) - return {__last, errc::value_too_large}; - - __last = __first + __n; - char* __p = __last; - unsigned __divisor = 64; - while (__value > __divisor) { - unsigned __c = __value % __divisor; - __value /= __divisor; - __p -= 2; - std::copy_n(&__base_8_lut[2 * __c], 2, __p); - } - do { - unsigned __c = __value % 8; - __value /= 8; - *--__p = "01234567"[__c]; - } while (__value != 0); - return {__last, errc(0)}; - } -}; - -template <> -struct _LIBCPP_HIDDEN __integral<16> { - template - _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR int __width(_Tp __value) _NOEXCEPT { - // If value == 0 still need one digit. If the value != this has no - // effect since the code scans for the most significat bit set. - return (numeric_limits<_Tp>::digits - std::__countl_zero(__value | 1) + 3) / 4; - } - - template - _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static __to_chars_result - __to_chars(char* __first, char* __last, _Tp __value) { - ptrdiff_t __cap = __last - __first; - int __n = __width(__value); - if (__n > __cap) - return {__last, errc::value_too_large}; - - __last = __first + __n; - char* __p = __last; - unsigned __divisor = 256; - while (__value > __divisor) { - unsigned __c = __value % __divisor; - __value /= __divisor; - __p -= 2; - std::copy_n(&__base_16_lut[2 * __c], 2, __p); - } - if (__first != __last) - do { - unsigned __c = __value % 16; - __value /= 16; - *--__p = "0123456789abcdef"[__c]; - } while (__value != 0); - return {__last, errc(0)}; - } -}; - -} // namespace __itoa - -template = sizeof(unsigned)), int> = 0> -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __to_chars_integral_width(_Tp __value) { - return __itoa::__integral<_Base>::__width(__value); -} - -template = 0> -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __to_chars_integral_width(_Tp __value) { - return std::__to_chars_integral_width<_Base>(static_cast(__value)); -} - -template = sizeof(unsigned)), int> = 0> -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_integral(char* __first, char* __last, _Tp __value) { - return __itoa::__integral<_Base>::__to_chars(__first, __last, __value); -} - -template = 0> -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_integral(char* __first, char* __last, _Tp __value) { - return std::__to_chars_integral<_Base>(__first, __last, static_cast(__value)); -} - -template -_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __to_chars_integral_width(_Tp __value, unsigned __base) { - _LIBCPP_ASSERT_INTERNAL(__value >= 0, "The function requires a non-negative value."); - - unsigned __base_2 = __base * __base; - unsigned __base_3 = __base_2 * __base; - unsigned __base_4 = __base_2 * __base_2; - - int __r = 0; - while (true) { - if (__value < __base) - return __r + 1; - if (__value < __base_2) - return __r + 2; - if (__value < __base_3) - return __r + 3; - if (__value < __base_4) - return __r + 4; - - __value /= __base_4; - __r += 4; - } - - __libcpp_unreachable(); -} - -template ::value, int> > -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result -__to_chars_integral(char* __first, char* __last, _Tp __value, int __base) { - if (__base == 10) [[likely]] - return std::__to_chars_itoa(__first, __last, __value, false_type()); - - switch (__base) { - case 2: - return std::__to_chars_integral<2>(__first, __last, __value); - case 8: - return std::__to_chars_integral<8>(__first, __last, __value); - case 16: - return std::__to_chars_integral<16>(__first, __last, __value); - } - - ptrdiff_t __cap = __last - __first; - int __n = std::__to_chars_integral_width(__value, __base); - if (__n > __cap) - return {__last, errc::value_too_large}; - - __last = __first + __n; - char* __p = __last; - do { - unsigned __c = __value % __base; - __value /= __base; - *--__p = "0123456789abcdefghijklmnopqrstuvwxyz"[__c]; - } while (__value != 0); - return {__last, errc(0)}; -} - -_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 char __hex_to_upper(char __c) { - switch (__c) { - case 'a': - return 'A'; - case 'b': - return 'B'; - case 'c': - return 'C'; - case 'd': - return 'D'; - case 'e': - return 'E'; - case 'f': - return 'F'; - } - return __c; -} - -#if _LIBCPP_STD_VER >= 17 - -to_chars_result to_chars(char*, char*, bool, int = 10) = delete; - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, _Tp __value) { - using _Type = __make_32_64_or_128_bit_t<_Tp>; - static_assert(!is_same<_Type, void>::value, "unsupported integral type used in to_chars"); - return std::__to_chars_itoa(__first, __last, static_cast<_Type>(__value), is_signed<_Tp>()); -} - -template ::value, int> = 0> -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result -to_chars(char* __first, char* __last, _Tp __value, int __base) { - _LIBCPP_ASSERT_UNCATEGORIZED(2 <= __base && __base <= 36, "base not in [2, 36]"); - - using _Type = __make_32_64_or_128_bit_t<_Tp>; - return std::__to_chars_integral(__first, __last, static_cast<_Type>(__value), __base); -} - -#endif // _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHARCONV_TO_CHARS_INTEGRAL_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/to_chars_result.h b/third_party/libcxx/include/c++/v1/__charconv/to_chars_result.h deleted file mode 100644 index a3cd4e2..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/to_chars_result.h +++ /dev/null @@ -1,48 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_TO_CHARS_RESULT_H -#define _LIBCPP___CHARCONV_TO_CHARS_RESULT_H - -#include <__config> -#include <__system_error/errc.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 17 - -struct to_chars_result { - char* ptr; - errc ec; -# if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI friend bool operator==(const to_chars_result&, const to_chars_result&) = default; -# endif -# if _LIBCPP_STD_VER >= 26 - _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return ec == errc{}; } -# endif -}; - -#endif // _LIBCPP_STD_VER >= 17 - -struct __to_chars_result { - char* __ptr; - errc __ec; - -#if _LIBCPP_STD_VER >= 17 - _LIBCPP_HIDE_FROM_ABI constexpr operator to_chars_result() { return {__ptr, __ec}; } -#endif -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHARCONV_TO_CHARS_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__charconv/traits.h b/third_party/libcxx/include/c++/v1/__charconv/traits.h deleted file mode 100644 index b8c840d..0000000 --- a/third_party/libcxx/include/c++/v1/__charconv/traits.h +++ /dev/null @@ -1,167 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHARCONV_TRAITS -#define _LIBCPP___CHARCONV_TRAITS - -#include <__assert> -#include <__bit/countl.h> -#include <__charconv/tables.h> -#include <__charconv/to_chars_base_10.h> -#include <__config> -#include <__memory/addressof.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_unsigned.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __itoa { - -template -struct _LIBCPP_HIDDEN __traits_base; - -template -struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t > { - using type = uint32_t; - - /// The width estimation using a log10 algorithm. - /// - /// The algorithm is based on - /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10 - /// Instead of using IntegerLogBase2 it uses __countl_zero. - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) { - auto __t = (32 - std::__countl_zero(static_cast(__v | 1))) * 1233 >> 12; - return __t - (__v < __itoa::__pow10_32[__t]) + 1; - } - - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char* __convert(char* __p, _Tp __v) { - return __itoa::__base_10_u32(__p, __v); - } - - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI decltype(__pow10_32)& __pow() { - return __itoa::__pow10_32; - } -}; - -template -struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t > { - using type = uint64_t; - - /// The width estimation using a log10 algorithm. - /// - /// The algorithm is based on - /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10 - /// Instead of using IntegerLogBase2 it uses __countl_zero. - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) { - auto __t = (64 - std::__countl_zero(static_cast(__v | 1))) * 1233 >> 12; - return __t - (__v < __itoa::__pow10_64[__t]) + 1; - } - - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char* __convert(char* __p, _Tp __v) { - return __itoa::__base_10_u64(__p, __v); - } - - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI decltype(__pow10_64)& __pow() { - return __itoa::__pow10_64; - } -}; - -# if _LIBCPP_HAS_INT128 -template -struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t > { - using type = __uint128_t; - - /// The width estimation using a log10 algorithm. - /// - /// The algorithm is based on - /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10 - /// Instead of using IntegerLogBase2 it uses __countl_zero. - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) { - _LIBCPP_ASSERT_INTERNAL( - __v > numeric_limits::max(), "The optimizations for this algorithm fail when this isn't true."); - // There's always a bit set in the upper 64-bits. - auto __t = (128 - std::__countl_zero(static_cast(__v >> 64))) * 1233 >> 12; - _LIBCPP_ASSERT_INTERNAL(__t >= __itoa::__pow10_128_offset, "Index out of bounds"); - // __t is adjusted since the lookup table misses the lower entries. - return __t - (__v < __itoa::__pow10_128[__t - __itoa::__pow10_128_offset]) + 1; - } - - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char* __convert(char* __p, _Tp __v) { - return __itoa::__base_10_u128(__p, __v); - } - - // TODO FMT This pow function should get an index. - // By moving this to its own header it can be reused by the pow function in to_chars_base_10. - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI decltype(__pow10_128)& __pow() { - return __itoa::__pow10_128; - } -}; -# endif - -template -_LIBCPP_HIDE_FROM_ABI bool _LIBCPP_CONSTEXPR_SINCE_CXX23 __mul_overflowed(_Tp __a, _Up __b, _Tp& __r) { - static_assert(is_unsigned<_Tp>::value); - return __builtin_mul_overflow(__a, static_cast<_Tp>(__b), std::addressof(__r)); -} - -template -struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp> { - static _LIBCPP_CONSTEXPR const int digits = numeric_limits<_Tp>::digits10 + 1; - using __traits_base<_Tp>::__pow; - using typename __traits_base<_Tp>::type; - - // precondition: at least one non-zero character available - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char const* - __read(char const* __p, char const* __ep, type& __a, type& __b) { - type __cprod[digits]; - int __j = digits - 1; - int __i = digits; - do { - if (*__p < '0' || *__p > '9') - break; - __cprod[--__i] = *__p++ - '0'; - } while (__p != __ep && __i != 0); - - __a = __inner_product(__cprod + __i + 1, __cprod + __j, __pow() + 1, __cprod[__i]); - if (__itoa::__mul_overflowed(__cprod[__j], __pow()[__j - __i], __b)) - --__p; - return __p; - } - - template - static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _Up - __inner_product(_It1 __first1, _It1 __last1, _It2 __first2, _Up __init) { - for (; __first1 < __last1; ++__first1, ++__first2) - __init = __init + *__first1 * *__first2; - return __init; - } -}; - -} // namespace __itoa - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _Tp __complement(_Tp __x) { - static_assert(is_unsigned<_Tp>::value, "cast to unsigned first"); - return _Tp(~__x + 1); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHARCONV_TRAITS diff --git a/third_party/libcxx/include/c++/v1/__chrono/calendar.h b/third_party/libcxx/include/c++/v1/__chrono/calendar.h deleted file mode 100644 index bb1c5e7..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/calendar.h +++ /dev/null @@ -1,44 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_CALENDAR_H -#define _LIBCPP___CHRONO_CALENDAR_H - -#include <__chrono/duration.h> -#include <__chrono/time_point.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -struct local_t {}; -template -using local_time = time_point; -using local_seconds = local_time; -using local_days = local_time; - -struct last_spec { - explicit last_spec() = default; -}; -inline constexpr last_spec last{}; - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_CALENDAR_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/concepts.h b/third_party/libcxx/include/c++/v1/__chrono/concepts.h deleted file mode 100644 index 61ec256..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/concepts.h +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_CONCEPTS_H -#define _LIBCPP___CHRONO_CONCEPTS_H - -#include <__chrono/hh_mm_ss.h> -#include <__chrono/time_point.h> -#include <__config> -#include <__type_traits/is_specialization.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -concept __is_hh_mm_ss = __is_specialization_v<_Tp, chrono::hh_mm_ss>; - -template -concept __is_time_point = __is_specialization_v<_Tp, chrono::time_point>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHRONO_CONCEPTS_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/convert_to_timespec.h b/third_party/libcxx/include/c++/v1/__chrono/convert_to_timespec.h deleted file mode 100644 index 11e0b82..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/convert_to_timespec.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H -#define _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H - -#include <__chrono/duration.h> -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Convert a nanoseconds duration to the given TimeSpec type, which must have -// the same properties as std::timespec. -template -_LIBCPP_HIDE_FROM_ABI inline _TimeSpec __convert_to_timespec(const chrono::nanoseconds& __ns) { - using namespace chrono; - seconds __s = duration_cast(__ns); - _TimeSpec __ts; - typedef decltype(__ts.tv_sec) __ts_sec; - const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max(); - - if (__s.count() < __ts_sec_max) { - __ts.tv_sec = static_cast<__ts_sec>(__s.count()); - __ts.tv_nsec = static_cast((__ns - __s).count()); - } else { - __ts.tv_sec = __ts_sec_max; - __ts.tv_nsec = 999999999; // (10^9 - 1) - } - - return __ts; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/convert_to_tm.h b/third_party/libcxx/include/c++/v1/__chrono/convert_to_tm.h deleted file mode 100644 index 16e1415..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/convert_to_tm.h +++ /dev/null @@ -1,241 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_CONVERT_TO_TM_H -#define _LIBCPP___CHRONO_CONVERT_TO_TM_H - -#include <__chrono/calendar.h> -#include <__chrono/concepts.h> -#include <__chrono/day.h> -#include <__chrono/duration.h> -#include <__chrono/file_clock.h> -#include <__chrono/gps_clock.h> -#include <__chrono/hh_mm_ss.h> -#include <__chrono/local_info.h> -#include <__chrono/month.h> -#include <__chrono/month_weekday.h> -#include <__chrono/monthday.h> -#include <__chrono/statically_widen.h> -#include <__chrono/sys_info.h> -#include <__chrono/system_clock.h> -#include <__chrono/tai_clock.h> -#include <__chrono/time_point.h> -#include <__chrono/utc_clock.h> -#include <__chrono/weekday.h> -#include <__chrono/year.h> -#include <__chrono/year_month.h> -#include <__chrono/year_month_day.h> -#include <__chrono/year_month_weekday.h> -#include <__chrono/zoned_time.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__format/format_error.h> -#include <__memory/addressof.h> -#include <__type_traits/common_type.h> -#include <__type_traits/is_convertible.h> -#include <__type_traits/is_specialization.h> -#include -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// Conerts a chrono date and weekday to a given _Tm type. -// -// This is an implementation detail for the function -// template -// _Tm __convert_to_tm(const _ChronoT& __value) -// -// This manually converts the two values to the proper type. It is possible to -// convert from sys_days to time_t and then to _Tm. But this leads to the Y2K -// bug when time_t is a 32-bit signed integer. Chrono considers years beyond -// the year 2038 valid, so instead do the transformation manually. -template - requires(same_as<_Date, chrono::year_month_day> || same_as<_Date, chrono::year_month_day_last>) -_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _Date& __date, chrono::weekday __weekday) { - _Tm __result = {}; -# ifdef __GLIBC__ - __result.tm_zone = "UTC"; -# endif - __result.tm_year = static_cast(__date.year()) - 1900; - __result.tm_mon = static_cast(__date.month()) - 1; - __result.tm_mday = static_cast(__date.day()); - __result.tm_wday = static_cast(__weekday.c_encoding()); - __result.tm_yday = - (static_cast(__date) - - static_cast(chrono::year_month_day{__date.year(), chrono::January, chrono::day{1}})) - .count(); - - return __result; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const chrono::sys_time<_Duration> __tp) { - chrono::sys_days __days = chrono::floor(__tp); - chrono::year_month_day __ymd{__days}; - - _Tm __result = std::__convert_to_tm<_Tm>(chrono::year_month_day{__ymd}, chrono::weekday{__days}); - - uint64_t __sec = - chrono::duration_cast(__tp - chrono::time_point_cast(__days)).count(); - __sec %= 24 * 3600; - __result.tm_hour = __sec / 3600; - __sec %= 3600; - __result.tm_min = __sec / 60; - __result.tm_sec = __sec % 60; - - return __result; -} - -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -template -_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::utc_time<_Duration> __tp) { - _Tm __result = std::__convert_to_tm<_Tm>(chrono::utc_clock::to_sys(__tp)); - - if (chrono::get_leap_second_info(__tp).is_leap_second) - ++__result.tm_sec; - - return __result; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::tai_time<_Duration> __tp) { - using _Rp = common_type_t<_Duration, chrono::seconds>; - // The time between the TAI epoch (1958-01-01) and UNIX epoch (1970-01-01). - // This avoids leap second conversion when going from TAI to UTC. - // (It also avoids issues when the date is before the UTC epoch.) - constexpr chrono::seconds __offset{4383 * 24 * 60 * 60}; - return std::__convert_to_tm<_Tm>(chrono::sys_time<_Rp>{__tp.time_since_epoch() - __offset}); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::gps_time<_Duration> __tp) { - using _Rp = common_type_t<_Duration, chrono::seconds>; - // The time between the GPS epoch (1980-01-06) and UNIX epoch (1970-01-01). - constexpr chrono::seconds __offset{3657 * 24 * 60 * 60}; - return std::__convert_to_tm<_Tm>(chrono::sys_time<_Rp>{__tp.time_since_epoch() + __offset}); -} - -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB -# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -// Convert a chrono (calendar) time point, or dururation to the given _Tm type, -// which must have the same properties as std::tm. -template -_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) { - _Tm __result = {}; -# ifdef __GLIBC__ - __result.tm_zone = "UTC"; -# endif - - if constexpr (__is_time_point<_ChronoT>) { - if constexpr (same_as) - return std::__convert_to_tm<_Tm>(_ChronoT::clock::to_sys(__value)); - else if constexpr (same_as) - return std::__convert_to_tm<_Tm>(chrono::sys_time{__value.time_since_epoch()}); - else { - // Note that some clocks have specializations __convert_to_tm for their - // time_point. These don't need to be added here. They do not trigger - // this assert. - static_assert(sizeof(_ChronoT) == 0, "TODO: Add the missing clock specialization"); - } - } else if constexpr (chrono::__is_duration_v<_ChronoT>) { - // [time.format]/6 - // ... However, if a flag refers to a "time of day" (e.g. %H, %I, %p, - // etc.), then a specialization of duration is interpreted as the time of - // day elapsed since midnight. - - // Not all values can be converted to hours, it may run into ratio - // conversion errors. In that case the conversion to seconds works. - if constexpr (is_convertible_v<_ChronoT, chrono::hours>) { - auto __hour = chrono::floor(__value); - auto __sec = chrono::duration_cast(__value - __hour); - __result.tm_hour = __hour.count() % 24; - __result.tm_min = __sec.count() / 60; - __result.tm_sec = __sec.count() % 60; - } else { - uint64_t __sec = chrono::duration_cast(__value).count(); - __sec %= 24 * 3600; - __result.tm_hour = __sec / 3600; - __sec %= 3600; - __result.tm_min = __sec / 60; - __result.tm_sec = __sec % 60; - } - } else if constexpr (same_as<_ChronoT, chrono::day>) - __result.tm_mday = static_cast(__value); - else if constexpr (same_as<_ChronoT, chrono::month>) - __result.tm_mon = static_cast(__value) - 1; - else if constexpr (same_as<_ChronoT, chrono::year>) - __result.tm_year = static_cast(__value) - 1900; - else if constexpr (same_as<_ChronoT, chrono::weekday>) - __result.tm_wday = __value.c_encoding(); - else if constexpr (same_as<_ChronoT, chrono::weekday_indexed> || same_as<_ChronoT, chrono::weekday_last>) - __result.tm_wday = __value.weekday().c_encoding(); - else if constexpr (same_as<_ChronoT, chrono::month_day>) { - __result.tm_mday = static_cast(__value.day()); - __result.tm_mon = static_cast(__value.month()) - 1; - } else if constexpr (same_as<_ChronoT, chrono::month_day_last>) { - __result.tm_mon = static_cast(__value.month()) - 1; - } else if constexpr (same_as<_ChronoT, chrono::month_weekday> || same_as<_ChronoT, chrono::month_weekday_last>) { - __result.tm_wday = __value.weekday_indexed().weekday().c_encoding(); - __result.tm_mon = static_cast(__value.month()) - 1; - } else if constexpr (same_as<_ChronoT, chrono::year_month>) { - __result.tm_year = static_cast(__value.year()) - 1900; - __result.tm_mon = static_cast(__value.month()) - 1; - } else if constexpr (same_as<_ChronoT, chrono::year_month_day> || same_as<_ChronoT, chrono::year_month_day_last>) { - return std::__convert_to_tm<_Tm>( - chrono::year_month_day{__value}, chrono::weekday{static_cast(__value)}); - } else if constexpr (same_as<_ChronoT, chrono::year_month_weekday> || - same_as<_ChronoT, chrono::year_month_weekday_last>) { - return std::__convert_to_tm<_Tm>(chrono::year_month_day{static_cast(__value)}, __value.weekday()); - } else if constexpr (__is_hh_mm_ss<_ChronoT>) { - __result.tm_sec = __value.seconds().count(); - __result.tm_min = __value.minutes().count(); - // In libc++ hours is stored as a long. The type in std::tm is an int. So - // the overflow can only occur when hour uses more bits than an int - // provides. - if constexpr (sizeof(std::chrono::hours::rep) > sizeof(__result.tm_hour)) - if (__value.hours().count() > std::numeric_limits::max()) - std::__throw_format_error("Formatting hh_mm_ss, encountered an hour overflow"); - __result.tm_hour = __value.hours().count(); -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - } else if constexpr (same_as<_ChronoT, chrono::sys_info>) { - // Has no time information. - } else if constexpr (same_as<_ChronoT, chrono::local_info>) { - // Has no time information. -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - } else if constexpr (__is_specialization_v<_ChronoT, chrono::zoned_time>) { - return std::__convert_to_tm<_Tm>( - chrono::sys_time{__value.get_local_time().time_since_epoch()}); -# endif -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - } else - static_assert(sizeof(_ChronoT) == 0, "Add the missing type specialization"); - - return __result; -} - -#endif // if _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHRONO_CONVERT_TO_TM_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/day.h b/third_party/libcxx/include/c++/v1/__chrono/day.h deleted file mode 100644 index 58fdc72..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/day.h +++ /dev/null @@ -1,112 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_DAY_H -#define _LIBCPP___CHRONO_DAY_H - -#include <__chrono/duration.h> -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class day { -private: - unsigned char __d_; - -public: - day() = default; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept - : __d_(static_cast(__val)) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { - ++__d_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { - day __tmp = *this; - ++(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { - --__d_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { - day __tmp = *this; - --(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d_ >= 1 && __d_ <= 31; } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const day& __lhs, const day& __rhs) noexcept { - return static_cast(__lhs) == static_cast(__rhs); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept { - return static_cast(__lhs) <=> static_cast(__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const day& __lhs, const days& __rhs) noexcept { - return day(static_cast(__lhs) + __rhs.count()); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const days& __lhs, const day& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr day operator-(const day& __lhs, const days& __rhs) noexcept { - return __lhs + -__rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const day& __lhs, const day& __rhs) noexcept { - return days(static_cast(static_cast(__lhs)) - static_cast(static_cast(__rhs))); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator+=(const days& __dd) noexcept { - *this = *this + __dd; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator-=(const days& __dd) noexcept { - *this = *this - __dd; - return *this; -} - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::day& __d) noexcept { - return static_cast(__d); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_DAY_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/duration.h b/third_party/libcxx/include/c++/v1/__chrono/duration.h deleted file mode 100644 index b7762bd..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/duration.h +++ /dev/null @@ -1,570 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_DURATION_H -#define _LIBCPP___CHRONO_DURATION_H - -#include <__compare/ordering.h> -#include <__compare/three_way_comparable.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> -#include <__type_traits/common_type.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_convertible.h> -#include <__type_traits/is_floating_point.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -template > -class duration; - -template -inline const bool __is_duration_v = false; - -template -inline const bool __is_duration_v > = true; - -template -inline const bool __is_duration_v > = true; - -template -inline const bool __is_duration_v > = true; - -template -inline const bool __is_duration_v > = true; - -} // namespace chrono - -template -struct common_type, chrono::duration<_Rep2, _Period2> > { - typedef chrono::duration::type, __ratio_gcd<_Period1, _Period2> > type; -}; - -namespace chrono { - -// duration_cast - -template ::type, - bool = _Period::num == 1, - bool = _Period::den == 1> -struct __duration_cast; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { - return _ToDuration(static_cast(__fd.count())); - } -}; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { - typedef typename common_type::type _Ct; - return _ToDuration( - static_cast(static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); - } -}; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { - typedef typename common_type::type _Ct; - return _ToDuration( - static_cast(static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); - } -}; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { - typedef typename common_type::type _Ct; - return _ToDuration(static_cast( - static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) / static_cast<_Ct>(_Period::den))); - } -}; - -template , int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration -duration_cast(const duration<_Rep, _Period>& __fd) { - return __duration_cast, _ToDuration>()(__fd); -} - -template -struct treat_as_floating_point : is_floating_point<_Rep> {}; - -#if _LIBCPP_STD_VER >= 17 -template -inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>::value; -#endif - -template -struct duration_values { -public: - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT { return _Rep(0); } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT { - return numeric_limits<_Rep>::max(); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT { - return numeric_limits<_Rep>::lowest(); - } -}; - -#if _LIBCPP_STD_VER >= 17 -template , int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<_Rep, _Period>& __d) { - _ToDuration __t = chrono::duration_cast<_ToDuration>(__d); - if (__t > __d) - __t = __t - _ToDuration{1}; - return __t; -} - -template , int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_Rep, _Period>& __d) { - _ToDuration __t = chrono::duration_cast<_ToDuration>(__d); - if (__t < __d) - __t = __t + _ToDuration{1}; - return __t; -} - -template , int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<_Rep, _Period>& __d) { - _ToDuration __lower = chrono::floor<_ToDuration>(__d); - _ToDuration __upper = __lower + _ToDuration{1}; - auto __lower_diff = __d - __lower; - auto __upper_diff = __upper - __d; - if (__lower_diff < __upper_diff) - return __lower; - if (__lower_diff > __upper_diff) - return __upper; - return __lower.count() & 1 ? __upper : __lower; -} -#endif - -// duration - -template -class duration { - static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration"); - static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio"); - static_assert(_Period::num > 0, "duration period must be positive"); - - template - struct __no_overflow { - private: - static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>; - static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>; - static const intmax_t __n1 = _R1::num / __gcd_n1_n2; - static const intmax_t __d1 = _R1::den / __gcd_d1_d2; - static const intmax_t __n2 = _R2::num / __gcd_n1_n2; - static const intmax_t __d2 = _R2::den / __gcd_d1_d2; - static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); - - template - struct __mul // __overflow == false - { - static const intmax_t value = _Xp * _Yp; - }; - - template - struct __mul<_Xp, _Yp, true> { - static const intmax_t value = 1; - }; - - public: - static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); - typedef ratio<__mul<__n1, __d2, !value>::value, __mul<__n2, __d1, !value>::value> type; - }; - -public: - typedef _Rep rep; - typedef typename _Period::type period; - -private: - rep __rep_; - -public: -#ifndef _LIBCPP_CXX03_LANG - constexpr duration() = default; -#else - _LIBCPP_HIDE_FROM_ABI duration() {} -#endif - - template ::value && - (treat_as_floating_point::value || !treat_as_floating_point<_Rep2>::value), - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit duration(const _Rep2& __r) : __rep_(__r) {} - - // conversions - template ::value && (treat_as_floating_point::value || - (__no_overflow<_Period2, period>::type::den == 1 && - !treat_as_floating_point<_Rep2>::value)), - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration(const duration<_Rep2, _Period2>& __d) - : __rep_(chrono::duration_cast(__d).count()) {} - - // observer - - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR rep count() const { return __rep_; } - - // arithmetic - - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type::type operator+() const { - return typename common_type::type(*this); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type::type operator-() const { - return typename common_type::type(-__rep_); - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator++() { - ++__rep_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator++(int) { return duration(__rep_++); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator--() { - --__rep_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator--(int) { return duration(__rep_--); } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator+=(const duration& __d) { - __rep_ += __d.count(); - return *this; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator-=(const duration& __d) { - __rep_ -= __d.count(); - return *this; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator*=(const rep& __rhs) { - __rep_ *= __rhs; - return *this; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator/=(const rep& __rhs) { - __rep_ /= __rhs; - return *this; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const rep& __rhs) { - __rep_ %= __rhs; - return *this; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const duration& __rhs) { - __rep_ %= __rhs.count(); - return *this; - } - - // special values - - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT { - return duration(duration_values::zero()); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT { - return duration(duration_values::min()); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT { - return duration(duration_values::max()); - } -}; - -typedef duration nanoseconds; -typedef duration microseconds; -typedef duration milliseconds; -typedef duration seconds; -typedef duration > minutes; -typedef duration > hours; -#if _LIBCPP_STD_VER >= 20 -typedef duration> days; -typedef duration> weeks; -typedef duration(365.2425 * 60 * 60 * 24)>> years; -typedef duration(365.2425 * 60 * 60 * 24) / 12>> months; -#endif -// Duration == - -template -struct __duration_eq { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() == _Ct(__rhs).count(); - } -}; - -template -struct __duration_eq<_LhsDuration, _LhsDuration> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const { - return __lhs.count() == __rhs.count(); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_eq, duration<_Rep2, _Period2> >()(__lhs, __rhs); -} - -#if _LIBCPP_STD_VER <= 17 - -// Duration != - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__lhs == __rhs); -} - -#endif // _LIBCPP_STD_VER <= 17 - -// Duration < - -template -struct __duration_lt { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() < _Ct(__rhs).count(); - } -}; - -template -struct __duration_lt<_LhsDuration, _LhsDuration> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const { - return __lhs.count() < __rhs.count(); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_lt, duration<_Rep2, _Period2> >()(__lhs, __rhs); -} - -// Duration > - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __rhs < __lhs; -} - -// Duration <= - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__rhs < __lhs); -} - -// Duration >= - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool -operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__lhs < __rhs); -} - -#if _LIBCPP_STD_VER >= 20 - -template - requires three_way_comparable> -_LIBCPP_HIDE_FROM_ABI constexpr auto -operator<=>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - using _Ct = common_type_t, duration<_Rep2, _Period2>>; - return _Ct(__lhs).count() <=> _Ct(__rhs).count(); -} - -#endif // _LIBCPP_STD_VER >= 20 - -// Duration + - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR -typename common_type, duration<_Rep2, _Period2> >::type -operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); -} - -// Duration - - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR -typename common_type, duration<_Rep2, _Period2> >::type -operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); -} - -// Duration * - -template ::type>::value, int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR duration::type, _Period> -operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); -} - -template ::type>::value, int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR duration::type, _Period> -operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) { - return __d * __s; -} - -// Duration / - -template && - is_convertible::type>::value, - int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR duration::type, _Period> -operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type<_Rep1, _Rep2>::type -operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Ct; - return _Ct(__lhs).count() / _Ct(__rhs).count(); -} - -// Duration % - -template && - is_convertible::type>::value, - int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR duration::type, _Period> -operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); -} - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR -typename common_type, duration<_Rep2, _Period2> >::type -operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); -} - -} // namespace chrono - -#if _LIBCPP_STD_VER >= 14 -// Suffixes for duration literals [time.duration.literals] -inline namespace literals { -inline namespace chrono_literals { - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::hours operator""h(unsigned long long __h) { - return chrono::hours(static_cast(__h)); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration> -operator""h(long double __h) { - return chrono::duration>(__h); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes operator""min(unsigned long long __m) { - return chrono::minutes(static_cast(__m)); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration> -operator""min(long double __m) { - return chrono::duration>(__m); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds operator""s(unsigned long long __s) { - return chrono::seconds(static_cast(__s)); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""s(long double __s) { - return chrono::duration(__s); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::milliseconds operator""ms(unsigned long long __ms) { - return chrono::milliseconds(static_cast(__ms)); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""ms(long double __ms) { - return chrono::duration(__ms); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::microseconds operator""us(unsigned long long __us) { - return chrono::microseconds(static_cast(__us)); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""us(long double __us) { - return chrono::duration(__us); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) { - return chrono::nanoseconds(static_cast(__ns)); -} - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration operator""ns(long double __ns) { - return chrono::duration(__ns); -} - -} // namespace chrono_literals -} // namespace literals - -namespace chrono { // hoist the literals into namespace std::chrono -using namespace literals::chrono_literals; -} // namespace chrono - -#endif // _LIBCPP_STD_VER >= 14 - -#if _LIBCPP_STD_VER >= 26 - -template - requires __has_enabled_hash<_Rep>::value -struct hash> { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::duration<_Rep, _Period>& __d) { - return hash<_Rep>{}(__d.count()); - } -}; - -#endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHRONO_DURATION_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/exception.h b/third_party/libcxx/include/c++/v1/__chrono/exception.h deleted file mode 100644 index 1eb5b1b..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/exception.h +++ /dev/null @@ -1,135 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_EXCEPTION_H -#define _LIBCPP___CHRONO_EXCEPTION_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/calendar.h> -# include <__chrono/local_info.h> -# include <__chrono/time_point.h> -# include <__config> -# include <__configuration/availability.h> -# include <__verbose_abort> -# include -# include -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 - -namespace chrono { - -class nonexistent_local_time : public runtime_error { -public: - template - _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& __time, const local_info& __info) - : runtime_error{__create_message(__time, __info)} { - // [time.zone.exception.nonexist]/2 - // Preconditions: i.result == local_info::nonexistent is true. - // The value of __info.result is not used. - _LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::nonexistent, - "creating an nonexistent_local_time from a local_info that is not non-existent"); - } - - _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const nonexistent_local_time&) = default; - _LIBCPP_HIDE_FROM_ABI nonexistent_local_time& operator=(const nonexistent_local_time&) = default; - - _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~nonexistent_local_time() override; // exported as key function - -private: - template - _LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) { - return std::format( - R"({} is in a gap between -{} {} and -{} {} which are both equivalent to -{} UTC)", - __time, - local_seconds{__info.first.end.time_since_epoch()} + __info.first.offset, - __info.first.abbrev, - local_seconds{__info.second.begin.time_since_epoch()} + __info.second.offset, - __info.second.abbrev, - __info.first.end); - } -}; - -template -[[noreturn]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time( - [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) { -# if _LIBCPP_HAS_EXCEPTIONS - throw nonexistent_local_time(__time, __info); -# else - _LIBCPP_VERBOSE_ABORT("nonexistent_local_time was thrown in -fno-exceptions mode"); -# endif -} - -class ambiguous_local_time : public runtime_error { -public: - template - _LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const local_time<_Duration>& __time, const local_info& __info) - : runtime_error{__create_message(__time, __info)} { - // [time.zone.exception.ambig]/2 - // Preconditions: i.result == local_info::ambiguous is true. - // The value of __info.result is not used. - _LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::ambiguous, - "creating an ambiguous_local_time from a local_info that is not ambiguous"); - } - - _LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const ambiguous_local_time&) = default; - _LIBCPP_HIDE_FROM_ABI ambiguous_local_time& operator=(const ambiguous_local_time&) = default; - - _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~ambiguous_local_time() override; // exported as key function - -private: - template - _LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) { - return std::format( - // There are two spaces after the full-stop; this has been verified - // in the sources of the Standard. - R"({0} is ambiguous. It could be -{0} {1} == {2} UTC or -{0} {3} == {4} UTC)", - __time, - __info.first.abbrev, - __time - __info.first.offset, - __info.second.abbrev, - __time - __info.second.offset); - } -}; - -template -[[noreturn]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time( - [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) { -# if _LIBCPP_HAS_EXCEPTIONS - throw ambiguous_local_time(__time, __info); -# else - _LIBCPP_VERBOSE_ABORT("ambiguous_local_time was thrown in -fno-exceptions mode"); -# endif -} - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_EXCEPTION_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/file_clock.h b/third_party/libcxx/include/c++/v1/__chrono/file_clock.h deleted file mode 100644 index 968f652..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/file_clock.h +++ /dev/null @@ -1,82 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_FILE_CLOCK_H -#define _LIBCPP___CHRONO_FILE_CLOCK_H - -#include <__chrono/duration.h> -#include <__chrono/system_clock.h> -#include <__chrono/time_point.h> -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#ifndef _LIBCPP_CXX03_LANG -_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM -struct _FilesystemClock; -_LIBCPP_END_NAMESPACE_FILESYSTEM -#endif // !_LIBCPP_CXX03_LANG - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -// [time.clock.file], type file_clock -using file_clock = filesystem::_FilesystemClock; - -template -using file_time = time_point; - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#ifndef _LIBCPP_CXX03_LANG -_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM -struct _FilesystemClock { -# if _LIBCPP_HAS_INT128 - typedef __int128_t rep; - typedef nano period; -# else - typedef long long rep; - typedef nano period; -# endif - - typedef chrono::duration duration; - typedef chrono::time_point<_FilesystemClock> time_point; - - _LIBCPP_EXPORTED_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false; - - [[__nodiscard__]] _LIBCPP_EXPORTED_FROM_ABI static time_point now() noexcept; - -# if _LIBCPP_STD_VER >= 20 - template - [[nodiscard]] - _LIBCPP_HIDE_FROM_ABI static chrono::sys_time<_Duration> to_sys(const chrono::file_time<_Duration>& __t) { - return chrono::sys_time<_Duration>(__t.time_since_epoch()); - } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static chrono::file_time<_Duration> - from_sys(const chrono::sys_time<_Duration>& __t) { - return chrono::file_time<_Duration>(__t.time_since_epoch()); - } -# endif // _LIBCPP_STD_VER >= 20 -}; -_LIBCPP_END_NAMESPACE_FILESYSTEM -#endif // !_LIBCPP_CXX03_LANG - -#endif // _LIBCPP___CHRONO_FILE_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/formatter.h b/third_party/libcxx/include/c++/v1/__chrono/formatter.h deleted file mode 100644 index 4975839..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/formatter.h +++ /dev/null @@ -1,1035 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_FORMATTER_H -#define _LIBCPP___CHRONO_FORMATTER_H - -#include <__config> - -#if _LIBCPP_HAS_LOCALIZATION - -# include <__algorithm/ranges_copy.h> -# include <__chrono/calendar.h> -# include <__chrono/concepts.h> -# include <__chrono/convert_to_tm.h> -# include <__chrono/day.h> -# include <__chrono/duration.h> -# include <__chrono/file_clock.h> -# include <__chrono/gps_clock.h> -# include <__chrono/hh_mm_ss.h> -# include <__chrono/local_info.h> -# include <__chrono/month.h> -# include <__chrono/month_weekday.h> -# include <__chrono/monthday.h> -# include <__chrono/ostream.h> -# include <__chrono/parser_std_format_spec.h> -# include <__chrono/statically_widen.h> -# include <__chrono/sys_info.h> -# include <__chrono/system_clock.h> -# include <__chrono/tai_clock.h> -# include <__chrono/time_point.h> -# include <__chrono/utc_clock.h> -# include <__chrono/weekday.h> -# include <__chrono/year.h> -# include <__chrono/year_month.h> -# include <__chrono/year_month_day.h> -# include <__chrono/year_month_weekday.h> -# include <__chrono/zoned_time.h> -# include <__concepts/arithmetic.h> -# include <__concepts/same_as.h> -# include <__format/concepts.h> -# include <__format/format_error.h> -# include <__format/format_functions.h> -# include <__format/format_parse_context.h> -# include <__format/formatter.h> -# include <__format/parser_std_format_spec.h> -# include <__format/write_escaped.h> -# include <__iterator/istreambuf_iterator.h> -# include <__iterator/ostreambuf_iterator.h> -# include <__locale_dir/time.h> -# include <__memory/addressof.h> -# include <__type_traits/is_specialization.h> -# include -# include -# include -# include -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 - -namespace __formatter { - -/// Formats a time based on a tm struct. -/// -/// This formatter passes the formatting to time_put which uses strftime. When -/// the value is outside the valid range it's unspecified what strftime will -/// output. For example weekday 8 can print 1 when the day is processed modulo -/// 7 since that handles the Sunday for 0-based weekday. It can also print 8 if -/// 7 is handled as a special case. -/// -/// The Standard doesn't specify what to do in this case so the result depends -/// on the result of the underlying code. -/// -/// \pre When the (abbreviated) weekday or month name are used, the caller -/// validates whether the value is valid. So the caller handles that -/// requirement of Table 97: Meaning of conversion specifiers -/// [tab:time.format.spec]. -/// -/// When no chrono-specs are provided it uses the stream formatter. - -// For tiny ratios it's not possible to convert a duration to a hh_mm_ss. This -// fails compile-time due to the limited precision of the ratio (64-bit is too -// small). Therefore a duration uses its own conversion. -template -_LIBCPP_HIDE_FROM_ABI void -__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::duration<_Rep, _Period>& __value) { - __sstr << std::use_facet>(__sstr.getloc()).decimal_point(); - - using __duration = chrono::duration<_Rep, _Period>; - - auto __fraction = __value - chrono::duration_cast(__value); - // Converts a negative fraction to its positive value. - if (__value < chrono::seconds{0} && __fraction != __duration{0}) - __fraction += chrono::seconds{1}; - if constexpr (chrono::treat_as_floating_point_v<_Rep>) - // When the floating-point value has digits itself they are ignored based - // on the wording in [tab:time.format.spec] - // If the precision of the input cannot be exactly represented with - // seconds, then the format is a decimal floating-point number with a - // fixed format and a precision matching that of the precision of the - // input (or to a microseconds precision if the conversion to - // floating-point decimal seconds cannot be made within 18 fractional - // digits). - // - // This matches the behaviour of MSVC STL, fmtlib interprets this - // differently and uses 3 decimals. - // https://godbolt.org/z/6dsbnW8ba - std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, - _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), - chrono::duration_cast::precision>(__fraction).count(), - chrono::hh_mm_ss<__duration>::fractional_width); - else - std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, - _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}}"), - chrono::duration_cast::precision>(__fraction).count(), - chrono::hh_mm_ss<__duration>::fractional_width); -} - -template -_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const _Tp& __value) { - __formatter::__format_sub_seconds(__sstr, __value.time_since_epoch()); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss<_Duration>& __value) { - __sstr << std::use_facet>(__sstr.getloc()).decimal_point(); - if constexpr (chrono::treat_as_floating_point_v) - std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, - _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), - __value.subseconds().count(), - __value.fractional_width); - else - std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, - _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}}"), - __value.subseconds().count(), - __value.fractional_width); -} - -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM -template -_LIBCPP_HIDE_FROM_ABI void -__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) { - __formatter::__format_sub_seconds(__sstr, __value.get_local_time().time_since_epoch()); -} -# endif - -template -consteval bool __use_fraction() { - if constexpr (__is_time_point<_Tp>) - return chrono::hh_mm_ss::fractional_width; -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) - return chrono::hh_mm_ss::fractional_width; -# endif - else if constexpr (chrono::__is_duration_v<_Tp>) - return chrono::hh_mm_ss<_Tp>::fractional_width; - else if constexpr (__is_hh_mm_ss<_Tp>) - return _Tp::fractional_width; - else - return false; -} - -template -_LIBCPP_HIDE_FROM_ABI void __format_year(basic_stringstream<_CharT>& __sstr, int __year) { - if (__year < 0) { - __sstr << _CharT('-'); - __year = -__year; - } - - // TODO FMT Write an issue - // If the result has less than four digits it is zero-padded with 0 to two digits. - // is less -> has less - // left-padded -> zero-padded, otherwise the proper value would be 000-0. - - // Note according to the wording it should be left padded, which is odd. - __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:04}"), __year); -} - -template -_LIBCPP_HIDE_FROM_ABI void __format_century(basic_stringstream<_CharT>& __sstr, int __year) { - // TODO FMT Write an issue - // [tab:time.format.spec] - // %C The year divided by 100 using floored division. If the result is a - // single decimal digit, it is prefixed with 0. - - bool __negative = __year < 0; - int __century = (__year - (99 * __negative)) / 100; // floored division - __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __century); -} - -// Implements the %z format specifier according to [tab:time.format.spec], where -// '__modifier' signals %Oz or %Ez were used. (Both modifiers behave the same, -// so there is no need to distinguish between them.) -template -_LIBCPP_HIDE_FROM_ABI void -__format_zone_offset(basic_stringstream<_CharT>& __sstr, chrono::seconds __offset, bool __modifier) { - if (__offset < 0s) { - __sstr << _CharT('-'); - __offset = -__offset; - } else { - __sstr << _CharT('+'); - } - - chrono::hh_mm_ss __hms{__offset}; - std::ostreambuf_iterator<_CharT> __out_it{__sstr}; - // Note HMS does not allow formatting hours > 23, but the offset is not limited to 24H. - std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __hms.hours().count()); - if (__modifier) - __sstr << _CharT(':'); - std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __hms.minutes().count()); -} - -// Helper to store the time zone information needed for formatting. -struct _LIBCPP_HIDE_FROM_ABI __time_zone { - // Typically these abbreviations are short and fit in the string's internal - // buffer. - string __abbrev; - chrono::seconds __offset; -}; - -template -_LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const _Tp& __value) { -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - if constexpr (same_as<_Tp, chrono::sys_info>) - return {__value.abbrev, __value.offset}; -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - else if constexpr (__is_time_point<_Tp> && requires { requires same_as; }) - return {"TAI", chrono::seconds{0}}; - else if constexpr (__is_time_point<_Tp> && requires { requires same_as; }) - return {"GPS", chrono::seconds{0}}; - else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) - return __formatter::__convert_to_time_zone(__value.get_info()); -# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - else -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - return {"UTC", chrono::seconds{0}}; -} - -template -_LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs( - basic_stringstream<_CharT>& __sstr, const _Tp& __value, basic_string_view<_CharT> __chrono_specs) { - tm __t = std::__convert_to_tm(__value); - __time_zone __z = __formatter::__convert_to_time_zone(__value); - const auto& __facet = std::use_facet>(__sstr.getloc()); - for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); ++__it) { - if (*__it == _CharT('%')) { - auto __s = __it; - ++__it; - // We only handle the types that can't be directly handled by time_put. - // (as an optimization n, t, and % are also handled directly.) - switch (*__it) { - case _CharT('n'): - __sstr << _CharT('\n'); - break; - case _CharT('t'): - __sstr << _CharT('\t'); - break; - case _CharT('%'): - __sstr << *__it; - break; - - case _CharT('C'): { - // strftime's output is only defined in the range [00, 99]. - int __year = __t.tm_year + 1900; - if (__year < 1000 || __year > 9999) - __formatter::__format_century(__sstr, __year); - else - __facet.put( - {__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1)); - } break; - - case _CharT('j'): - if constexpr (chrono::__is_duration_v<_Tp>) - // Converting a duration where the period has a small ratio to days - // may fail to compile. This due to loss of precision in the - // conversion. In order to avoid that issue convert to seconds as - // an intemediate step. - __sstr << chrono::duration_cast(chrono::duration_cast(__value)).count(); - else - __facet.put( - {__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1)); - break; - - case _CharT('q'): - if constexpr (chrono::__is_duration_v<_Tp>) { - __sstr << chrono::__units_suffix<_CharT, typename _Tp::period>(); - break; - } - __builtin_unreachable(); - - case _CharT('Q'): - // TODO FMT Determine the proper ideas - // - Should it honour the precision? - // - Shoult it honour the locale setting for the separators? - // The wording for Q doesn't use the word locale and the effect of - // precision is unspecified. - // - // MSVC STL ignores precision but uses separator - // FMT honours precision and has a bug for separator - // https://godbolt.org/z/78b7sMxns - if constexpr (chrono::__is_duration_v<_Tp>) { - __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{}"), __value.count()); - break; - } - __builtin_unreachable(); - - case _CharT('S'): - case _CharT('T'): - __facet.put( - {__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1)); - if constexpr (__formatter::__use_fraction<_Tp>()) - __formatter::__format_sub_seconds(__sstr, __value); - break; - - // Unlike time_put and strftime the formatting library requires %Y - // - // [tab:time.format.spec] - // The year as a decimal number. If the result is less than four digits - // it is left-padded with 0 to four digits. - // - // This means years in the range (-1000, 1000) need manual formatting. - // It's unclear whether %EY needs the same treatment. For example the - // Japanese EY contains the era name and year. This is zero-padded to 2 - // digits in time_put (note that older glibc versions didn't do - // padding.) However most eras won't reach 100 years, let alone 1000. - // So padding to 4 digits seems unwanted for Japanese. - // - // The same applies to %Ex since that too depends on the era. - // - // %x the locale's date representation is currently doesn't handle the - // zero-padding too. - // - // The 4 digits can be implemented better at a later time. On POSIX - // systems the required information can be extracted by nl_langinfo - // https://man7.org/linux/man-pages/man3/nl_langinfo.3.html - // - // Note since year < -1000 is expected to be rare it uses the more - // expensive year routine. - // - // TODO FMT evaluate the comment above. - -# if defined(__GLIBC__) || defined(_AIX) || defined(_WIN32) - case _CharT('y'): - // Glibc fails for negative values, AIX for positive values too. - __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), (std::abs(__t.tm_year + 1900)) % 100); - break; -# endif // defined(__GLIBC__) || defined(_AIX) || defined(_WIN32) - - case _CharT('Y'): - // Depending on the platform's libc the range of supported years is - // limited. Instead of of testing all conditions use the internal - // implementation unconditionally. - __formatter::__format_year(__sstr, __t.tm_year + 1900); - break; - - case _CharT('F'): - // Depending on the platform's libc the range of supported years is - // limited. Instead of testing all conditions use the internal - // implementation unconditionally. - __formatter::__format_year(__sstr, __t.tm_year + 1900); - __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday); - break; - - case _CharT('z'): - __formatter::__format_zone_offset(__sstr, __z.__offset, false); - break; - - case _CharT('Z'): - // __abbrev is always a char so the copy may convert. - ranges::copy(__z.__abbrev, std::ostreambuf_iterator<_CharT>{__sstr}); - break; - - case _CharT('O'): - if constexpr (__formatter::__use_fraction<_Tp>()) { - // Handle OS using the normal representation for the non-fractional - // part. There seems to be no locale information regarding how the - // fractional part should be formatted. - if (*(__it + 1) == 'S') { - ++__it; - __facet.put( - {__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1)); - __formatter::__format_sub_seconds(__sstr, __value); - break; - } - } - - // Oz produces the same output as Ez below. - [[fallthrough]]; - case _CharT('E'): - ++__it; - if (*__it == 'z') { - __formatter::__format_zone_offset(__sstr, __z.__offset, true); - break; - } - [[fallthrough]]; - default: - __facet.put( - {__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1)); - break; - } - } else { - __sstr << *__it; - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) { - if constexpr (__is_time_point<_Tp>) - return true; - else if constexpr (same_as<_Tp, chrono::day>) - return true; - else if constexpr (same_as<_Tp, chrono::month>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday_indexed>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday_last>) - return true; - else if constexpr (same_as<_Tp, chrono::month_day>) - return true; - else if constexpr (same_as<_Tp, chrono::month_day_last>) - return true; - else if constexpr (same_as<_Tp, chrono::month_weekday>) - return true; - else if constexpr (same_as<_Tp, chrono::month_weekday_last>) - return true; - else if constexpr (same_as<_Tp, chrono::year_month>) - return true; - else if constexpr (same_as<_Tp, chrono::year_month_day>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year_month_day_last>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday>) - return __value.weekday().ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) - return __value.weekday().ok(); - else if constexpr (__is_hh_mm_ss<_Tp>) - return true; -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - else if constexpr (same_as<_Tp, chrono::sys_info>) - return true; - else if constexpr (same_as<_Tp, chrono::local_info>) - return true; -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) - return true; -# endif -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - else - static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) { - if constexpr (__is_time_point<_Tp>) - return true; - else if constexpr (same_as<_Tp, chrono::day>) - return true; - else if constexpr (same_as<_Tp, chrono::month>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::weekday_indexed>) - return __value.weekday().ok(); - else if constexpr (same_as<_Tp, chrono::weekday_last>) - return __value.weekday().ok(); - else if constexpr (same_as<_Tp, chrono::month_day>) - return true; - else if constexpr (same_as<_Tp, chrono::month_day_last>) - return true; - else if constexpr (same_as<_Tp, chrono::month_weekday>) - return __value.weekday_indexed().ok(); - else if constexpr (same_as<_Tp, chrono::month_weekday_last>) - return __value.weekday_indexed().ok(); - else if constexpr (same_as<_Tp, chrono::year_month>) - return true; - else if constexpr (same_as<_Tp, chrono::year_month_day>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year_month_day_last>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday>) - return __value.weekday().ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) - return __value.weekday().ok(); - else if constexpr (__is_hh_mm_ss<_Tp>) - return true; -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - else if constexpr (same_as<_Tp, chrono::sys_info>) - return true; - else if constexpr (same_as<_Tp, chrono::local_info>) - return true; -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) - return true; -# endif -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - else - static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) { - if constexpr (__is_time_point<_Tp>) - return true; - else if constexpr (same_as<_Tp, chrono::day>) - return true; - else if constexpr (same_as<_Tp, chrono::month>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday_indexed>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday_last>) - return true; - else if constexpr (same_as<_Tp, chrono::month_day>) - return true; - else if constexpr (same_as<_Tp, chrono::month_day_last>) - return true; - else if constexpr (same_as<_Tp, chrono::month_weekday>) - return true; - else if constexpr (same_as<_Tp, chrono::month_weekday_last>) - return true; - else if constexpr (same_as<_Tp, chrono::year_month>) - return true; - else if constexpr (same_as<_Tp, chrono::year_month_day>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year_month_day_last>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) - return __value.ok(); - else if constexpr (__is_hh_mm_ss<_Tp>) - return true; -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - else if constexpr (same_as<_Tp, chrono::sys_info>) - return true; - else if constexpr (same_as<_Tp, chrono::local_info>) - return true; -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) - return true; -# endif -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - else - static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) { - if constexpr (__is_time_point<_Tp>) - return true; - else if constexpr (same_as<_Tp, chrono::day>) - return true; - else if constexpr (same_as<_Tp, chrono::month>) - return __value.ok(); - else if constexpr (same_as<_Tp, chrono::year>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday_indexed>) - return true; - else if constexpr (same_as<_Tp, chrono::weekday_last>) - return true; - else if constexpr (same_as<_Tp, chrono::month_day>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::month_day_last>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::month_weekday>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::month_weekday_last>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::year_month>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::year_month_day>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::year_month_day_last>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday>) - return __value.month().ok(); - else if constexpr (same_as<_Tp, chrono::year_month_weekday_last>) - return __value.month().ok(); - else if constexpr (__is_hh_mm_ss<_Tp>) - return true; -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - else if constexpr (same_as<_Tp, chrono::sys_info>) - return true; - else if constexpr (same_as<_Tp, chrono::local_info>) - return true; -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) - return true; -# endif -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - else - static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); -} - -template -_LIBCPP_HIDE_FROM_ABI auto -__format_chrono(const _Tp& __value, - _FormatContext& __ctx, - __format_spec::__parsed_specifications<_CharT> __specs, - basic_string_view<_CharT> __chrono_specs) { - basic_stringstream<_CharT> __sstr; - // [time.format]/2 - // 2.1 - the "C" locale if the L option is not present in chrono-format-spec, otherwise - // 2.2 - the locale passed to the formatting function if any, otherwise - // 2.3 - the global locale. - // Note that the __ctx's locale() call does 2.2 and 2.3. - if (__specs.__chrono_.__locale_specific_form_) - __sstr.imbue(__ctx.locale()); - else - __sstr.imbue(locale::classic()); - - if (__chrono_specs.empty()) - __sstr << __value; - else { - if constexpr (chrono::__is_duration_v<_Tp>) { - // A duration can be a user defined arithmetic type. Users may specialize - // numeric_limits, but they may not specialize is_signed. - if constexpr (numeric_limits::is_signed) { - if (__value < __value.zero()) { - __sstr << _CharT('-'); - __formatter::__format_chrono_using_chrono_specs(__sstr, -__value, __chrono_specs); - } else - __formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs); - } else - __formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs); - // TODO FMT When keeping the precision it will truncate the string. - // Note that the behaviour what the precision does isn't specified. - __specs.__precision_ = -1; - } else { - // Test __weekday_name_ before __weekday_ to give a better error. - if (__specs.__chrono_.__weekday_name_ && !__formatter::__weekday_name_ok(__value)) - std::__throw_format_error("Formatting a weekday name needs a valid weekday"); - - if (__specs.__chrono_.__weekday_ && !__formatter::__weekday_ok(__value)) - std::__throw_format_error("Formatting a weekday needs a valid weekday"); - - if (__specs.__chrono_.__day_of_year_ && !__formatter::__date_ok(__value)) - std::__throw_format_error("Formatting a day of year needs a valid date"); - - if (__specs.__chrono_.__week_of_year_ && !__formatter::__date_ok(__value)) - std::__throw_format_error("Formatting a week of year needs a valid date"); - - if (__specs.__chrono_.__month_name_ && !__formatter::__month_name_ok(__value)) - std::__throw_format_error("Formatting a month name from an invalid month number"); - - if constexpr (__is_hh_mm_ss<_Tp>) { - // Note this is a pedantic intepretation of the Standard. A hh_mm_ss - // is no longer a time_of_day and can store an arbitrary number of - // hours. A number of hours in a 12 or 24 hour clock can't represent - // 24 hours or more. The functions std::chrono::make12 and - // std::chrono::make24 reaffirm this view point. - // - // Interestingly this will be the only output stream function that - // throws. - // - // TODO FMT The wording probably needs to be adapted to - // - The displayed hours is hh_mm_ss.hours() % 24 - // - It should probably allow %j in the same fashion as duration. - // - The stream formatter should change its output when hours >= 24 - // - Write it as not valid, - // - or write the number of days. - if (__specs.__chrono_.__hour_ && __value.hours().count() > 23) - std::__throw_format_error("Formatting a hour needs a valid value"); - - if (__value.is_negative()) - __sstr << _CharT('-'); - } - - __formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs); - } - } - - return __formatter::__write_string(__sstr.view(), __ctx.out(), __specs); -} - -} // namespace __formatter - -template <__fmt_char_type _CharT> -struct __formatter_chrono { -public: - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator - __parse(_ParseContext& __ctx, __format_spec::__fields __fields, __format_spec::__flags __flags) { - return __parser_.__parse(__ctx, __fields, __flags); - } - - template - _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __value, _FormatContext& __ctx) const { - return __formatter::__format_chrono( - __value, __ctx, __parser_.__parser_.__get_parsed_chrono_specifications(__ctx), __parser_.__chrono_specs_); - } - - __format_spec::__parser_chrono<_CharT> __parser_; -}; - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); - } -}; - -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); - } -}; - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); - } -}; - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); - } -}; - -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB -# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); - } -}; - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - // The flags are not __clock since there is no associated time-zone. - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date_time); - } -}; - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - // [time.format]/1 - // Giving a precision specification in the chrono-format-spec is valid only - // for std::chrono::duration types where the representation type Rep is a - // floating-point type. For all other Rep types, an exception of type - // format_error is thrown if the chrono-format-spec contains a precision - // specification. - // - // Note this doesn't refer to chrono::treat_as_floating_point_v<_Rep>. - if constexpr (std::floating_point<_Rep>) - return _Base::__parse(__ctx, __format_spec::__fields_chrono_fractional, __format_spec::__flags::__duration); - else - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__duration); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__day); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__year); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__weekday); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__weekday); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__weekday); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month_day); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month_weekday); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__month_weekday); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__year_month); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__date); - } -}; - -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__time); - } -}; - -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__time_zone); - } -}; - -template <__fmt_char_type _CharT> -struct formatter : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{}); - } -}; -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM -// Note due to how libc++'s formatters are implemented there is no need to add -// the exposition only local-time-format-t abstraction. -template -struct formatter, _CharT> : public __formatter_chrono<_CharT> { -public: - using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; - - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { - return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); - } -}; -# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# endif // if _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_LOCALIZATION - -#endif // _LIBCPP___CHRONO_FORMATTER_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/gps_clock.h b/third_party/libcxx/include/c++/v1/__chrono/gps_clock.h deleted file mode 100644 index 2e220ca..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/gps_clock.h +++ /dev/null @@ -1,90 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_GPS_CLOCK_H -#define _LIBCPP___CHRONO_GPS_CLOCK_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__assert> -# include <__chrono/duration.h> -# include <__chrono/time_point.h> -# include <__chrono/utc_clock.h> -# include <__config> -# include <__type_traits/common_type.h> - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -class gps_clock; - -template -using gps_time = time_point; -using gps_seconds = gps_time; - -class gps_clock { -public: - using rep = utc_clock::rep; - using period = utc_clock::period; - using duration = chrono::duration; - using time_point = chrono::time_point; - static constexpr bool is_steady = false; // The utc_clock is not steady. - - // The static difference between UTC and GPS time as specified in the Standard. - static constexpr chrono::seconds __offset{315964809}; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_utc(utc_clock::now()); } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time> - to_utc(const gps_time<_Duration>& __time) noexcept { - using _Rp = common_type_t<_Duration, seconds>; - _Duration __time_since_epoch = __time.time_since_epoch(); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch >= utc_time<_Rp>::min().time_since_epoch() + __offset, - "the GPS to UTC conversion would underflow"); - - return utc_time<_Rp>{__time_since_epoch + __offset}; - } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static gps_time> - from_utc(const utc_time<_Duration>& __time) noexcept { - using _Rp = common_type_t<_Duration, seconds>; - _Duration __time_since_epoch = __time.time_since_epoch(); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch <= utc_time<_Rp>::max().time_since_epoch() - __offset, - "the UTC to GPS conversion would overflow"); - - return gps_time<_Rp>{__time_since_epoch - __offset}; - } -}; - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_GPS_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/hh_mm_ss.h b/third_party/libcxx/include/c++/v1/__chrono/hh_mm_ss.h deleted file mode 100644 index 746eba9..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/hh_mm_ss.h +++ /dev/null @@ -1,112 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_HH_MM_SS_H -#define _LIBCPP___CHRONO_HH_MM_SS_H - -#include <__chrono/duration.h> -#include <__chrono/time_point.h> -#include <__config> -#include <__type_traits/common_type.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -template -class hh_mm_ss { -private: - static_assert(__is_duration_v<_Duration>, "template parameter of hh_mm_ss must be a std::chrono::duration"); - using __CommonType _LIBCPP_NODEBUG = common_type_t<_Duration, chrono::seconds>; - - _LIBCPP_HIDE_FROM_ABI static constexpr uint64_t __pow10(unsigned __exp) { - uint64_t __ret = 1; - for (unsigned __i = 0; __i < __exp; ++__i) - __ret *= 10U; - return __ret; - } - - _LIBCPP_HIDE_FROM_ABI static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0) { - if (__n >= 2 && __d != 0 && __w < 19) - return 1 + __width(__n, __d % __n * 10, __w + 1); - return 0; - } - -public: - _LIBCPP_HIDE_FROM_ABI static unsigned constexpr fractional_width = - __width(__CommonType::period::den) < 19 ? __width(__CommonType::period::den) : 6u; - using precision = duration>; - - _LIBCPP_HIDE_FROM_ABI constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {} - - _LIBCPP_HIDE_FROM_ABI constexpr explicit hh_mm_ss(_Duration __d) noexcept - : __is_neg_(__d < _Duration(0)), - __h_(chrono::duration_cast(chrono::abs(__d))), - __m_(chrono::duration_cast(chrono::abs(__d) - hours())), - __s_(chrono::duration_cast(chrono::abs(__d) - hours() - minutes())), - __f_(chrono::duration_cast(chrono::abs(__d) - hours() - minutes() - seconds())) {} - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_negative() const noexcept { return __is_neg_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::hours hours() const noexcept { return __h_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes minutes() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds seconds() const noexcept { return __s_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr precision subseconds() const noexcept { return __f_; } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr precision to_duration() const noexcept { - auto __dur = __h_ + __m_ + __s_ + __f_; - return __is_neg_ ? -__dur : __dur; - } - - _LIBCPP_HIDE_FROM_ABI constexpr explicit operator precision() const noexcept { return to_duration(); } - -private: - bool __is_neg_; - chrono::hours __h_; - chrono::minutes __m_; - chrono::seconds __s_; - precision __f_; -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(hh_mm_ss); - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_am(const hours& __h) noexcept { - return __h >= hours(0) && __h < hours(12); -} -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_pm(const hours& __h) noexcept { - return __h >= hours(12) && __h < hours(24); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept { - if (__h == hours(0)) - return hours(12); - else if (__h <= hours(12)) - return __h; - else - return __h - hours(12); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr hours make24(const hours& __h, bool __is_pm) noexcept { - if (__is_pm) - return __h == hours(12) ? __h : __h + hours(12); - else - return __h == hours(12) ? hours(0) : __h; -} -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_HH_MM_SS_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/high_resolution_clock.h b/third_party/libcxx/include/c++/v1/__chrono/high_resolution_clock.h deleted file mode 100644 index d324c7f..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/high_resolution_clock.h +++ /dev/null @@ -1,35 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_HIGH_RESOLUTION_CLOCK_H -#define _LIBCPP___CHRONO_HIGH_RESOLUTION_CLOCK_H - -#include <__chrono/steady_clock.h> -#include <__chrono/system_clock.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -#if _LIBCPP_HAS_MONOTONIC_CLOCK -typedef steady_clock high_resolution_clock; -#else -typedef system_clock high_resolution_clock; -#endif - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHRONO_HIGH_RESOLUTION_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/is_clock.h b/third_party/libcxx/include/c++/v1/__chrono/is_clock.h deleted file mode 100644 index e63b848..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/is_clock.h +++ /dev/null @@ -1,72 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_IS_CLOCK_H -#define _LIBCPP___CHRONO_IS_CLOCK_H - -#include <__config> - -#include <__chrono/duration.h> -#include <__chrono/time_point.h> -#include <__concepts/same_as.h> -#include <__type_traits/integral_constant.h> -#include <__type_traits/is_arithmetic.h> -#include <__type_traits/is_class.h> -#include <__type_traits/is_union.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -// Helper to check that _Tp::time_point has the form time_point<_, typename _Tp::duration>. -template -inline constexpr bool __is_valid_clock_time_point_v = false; - -template -inline constexpr bool - __is_valid_clock_time_point_v, _ClockType> = true; - -// Check if a clock satisfies the Cpp17Clock requirements as defined in [time.clock.req] -template -_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_clock_v = requires { - typename _Tp::rep; - requires is_arithmetic_v || is_class_v || is_union_v; - - typename _Tp::period; - requires __is_ratio_v; - - typename _Tp::duration; - requires same_as>; - - typename _Tp::time_point; - requires __is_valid_clock_time_point_v; - - _Tp::is_steady; - requires same_as; - - _Tp::now(); - requires same_as; -}; - -template -struct _LIBCPP_NO_SPECIALIZATIONS is_clock : bool_constant> {}; - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER -#endif // _LIBCPP___CHRONO_IS_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/leap_second.h b/third_party/libcxx/include/c++/v1/__chrono/leap_second.h deleted file mode 100644 index 9e9df6b..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/leap_second.h +++ /dev/null @@ -1,144 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_LEAP_SECOND_H -#define _LIBCPP___CHRONO_LEAP_SECOND_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/duration.h> -# include <__chrono/system_clock.h> -# include <__chrono/time_point.h> -# include <__compare/ordering.h> -# include <__compare/three_way_comparable.h> -# include <__config> -# include <__cstddef/size_t.h> -# include <__functional/hash.h> -# include <__utility/private_constructor_tag.h> - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 - -namespace chrono { - -class leap_second { -public: - [[nodiscard]] - _LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__private_constructor_tag, sys_seconds __date, seconds __value) - : __date_(__date), __value_(__value) {} - - _LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default; - _LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; } - -private: - sys_seconds __date_; - seconds __value_; - - // The function - // template - // requires three_way_comparable_with> - // constexpr auto operator<=>(const leap_second& x, const sys_time& y) noexcept; - // - // Has constraints that are recursive (LWG4139). The proposed resolution is - // to make the funcion a hidden friend. For consistency make this change for - // all comparison functions. - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const leap_second& __x, const leap_second& __y) { - return __x.date() == __y.date(); - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) { - return __x.date() <=> __y.date(); - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) { - return __x.date() == __y; - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) { - return __x.date() < __y; - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) { - return __x < __y.date(); - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) { - return __y < __x; - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) { - return __y < __x; - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) { - return !(__y < __x); - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) { - return !(__y < __x); - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) { - return !(__x < __y); - } - - template - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) { - return !(__x < __y); - } - - template - requires three_way_comparable_with> - _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) { - return __x.date() <=> __y; - } -}; - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::leap_second& __lp) noexcept { - return std::__hash_combine(hash{}(__lp.date()), hash{}(__lp.value())); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -# endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_LEAP_SECOND_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/literals.h b/third_party/libcxx/include/c++/v1/__chrono/literals.h deleted file mode 100644 index b26acba..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/literals.h +++ /dev/null @@ -1,45 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_LITERALS_H -#define _LIBCPP___CHRONO_LITERALS_H - -#include <__chrono/day.h> -#include <__chrono/year.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -inline namespace literals { -inline namespace chrono_literals { -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator""d(unsigned long long __d) noexcept { - return chrono::day(static_cast(__d)); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::year operator""y(unsigned long long __y) noexcept { - return chrono::year(static_cast(__y)); -} -} // namespace chrono_literals -} // namespace literals - -namespace chrono { // hoist the literals into namespace std::chrono -using namespace literals::chrono_literals; -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_LITERALS_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/local_info.h b/third_party/libcxx/include/c++/v1/__chrono/local_info.h deleted file mode 100644 index 31cf777..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/local_info.h +++ /dev/null @@ -1,50 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_LOCAL_INFO_H -#define _LIBCPP___CHRONO_LOCAL_INFO_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/sys_info.h> -# include <__config> - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 - -namespace chrono { - -struct local_info { - static constexpr int unique = 0; - static constexpr int nonexistent = 1; - static constexpr int ambiguous = 2; - - int result; - sys_info first; - sys_info second; -}; - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_LOCAL_INFO_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/month.h b/third_party/libcxx/include/c++/v1/__chrono/month.h deleted file mode 100644 index abf07e8..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/month.h +++ /dev/null @@ -1,128 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_MONTH_H -#define _LIBCPP___CHRONO_MONTH_H - -#include <__chrono/duration.h> -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class month { -private: - unsigned char __m_; - -public: - month() = default; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept - : __m_(static_cast(__val)) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept { - *this += months{1}; - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept { - month __tmp = *this; - ++(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept { - *this -= months{1}; - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept { - month __tmp = *this; - --(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept { - return static_cast(__lhs) == static_cast(__rhs); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept { - return static_cast(__lhs) <=> static_cast(__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept { - auto const __mu = static_cast(static_cast(__lhs)) + (__rhs.count() - 1); - auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; - return month{static_cast(__mu - __yr * 12 + 1)}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept { - return __lhs + -__rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept { - auto const __dm = static_cast(__lhs) - static_cast(__rhs); - return months(__dm <= 11 ? __dm : __dm + 12); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator+=(const months& __dm) noexcept { - *this = *this + __dm; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator-=(const months& __dm) noexcept { - *this = *this - __dm; - return *this; -} - -inline constexpr month January{1}; -inline constexpr month February{2}; -inline constexpr month March{3}; -inline constexpr month April{4}; -inline constexpr month May{5}; -inline constexpr month June{6}; -inline constexpr month July{7}; -inline constexpr month August{8}; -inline constexpr month September{9}; -inline constexpr month October{10}; -inline constexpr month November{11}; -inline constexpr month December{12}; - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month& __m) noexcept { - return static_cast(__m); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_MONTH_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/month_weekday.h b/third_party/libcxx/include/c++/v1/__chrono/month_weekday.h deleted file mode 100644 index f149806..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/month_weekday.h +++ /dev/null @@ -1,135 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_MONTH_WEEKDAY_H -#define _LIBCPP___CHRONO_MONTH_WEEKDAY_H - -#include <__chrono/month.h> -#include <__chrono/weekday.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class month_weekday { -private: - chrono::month __m_; - chrono::weekday_indexed __wdi_; - -public: - _LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval, - const chrono::weekday_indexed& __wdival) noexcept - : __m_{__mval}, __wdi_{__wdival} {} - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { - return __wdi_; - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept { - return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday -operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept { - return month_weekday{__lhs, __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday -operator/(int __lhs, const weekday_indexed& __rhs) noexcept { - return month_weekday{month(__lhs), __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday -operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept { - return month_weekday{__rhs, __lhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday -operator/(const weekday_indexed& __lhs, int __rhs) noexcept { - return month_weekday{month(__rhs), __lhs}; -} - -class month_weekday_last { - chrono::month __m_; - chrono::weekday_last __wdl_; - -public: - _LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval, - const chrono::weekday_last& __wdlval) noexcept - : __m_{__mval}, __wdl_{__wdlval} {} - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { - return __wdl_; - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept { - return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last -operator/(const month& __lhs, const weekday_last& __rhs) noexcept { - return month_weekday_last{__lhs, __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last -operator/(int __lhs, const weekday_last& __rhs) noexcept { - return month_weekday_last{month(__lhs), __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last -operator/(const weekday_last& __lhs, const month& __rhs) noexcept { - return month_weekday_last{__rhs, __lhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last -operator/(const weekday_last& __lhs, int __rhs) noexcept { - return month_weekday_last{month(__rhs), __lhs}; -} -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday& __mw) noexcept { - return std::__hash_combine( - hash{}(__mw.month()), hash{}(__mw.weekday_indexed())); - } -}; - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday_last& __mwl) noexcept { - return std::__hash_combine( - hash{}(__mwl.month()), hash{}(__mwl.weekday_last())); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_MONTH_WEEKDAY_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/monthday.h b/third_party/libcxx/include/c++/v1/__chrono/monthday.h deleted file mode 100644 index 443d7ea..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/monthday.h +++ /dev/null @@ -1,155 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_MONTHDAY_H -#define _LIBCPP___CHRONO_MONTHDAY_H - -#include <__chrono/calendar.h> -#include <__chrono/day.h> -#include <__chrono/month.h> -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class month_day { -private: - chrono::month __m_; - chrono::day __d_; - -public: - month_day() = default; - _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept - : __m_{__mval}, __d_{__dval} {} - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool month_day::ok() const noexcept { - if (!__m_.ok()) - return false; - const unsigned __dval = static_cast(__d_); - if (__dval < 1 || __dval > 31) - return false; - if (__dval <= 29) - return true; - // Now we've got either 30 or 31 - const unsigned __mval = static_cast(__m_); - if (__mval == 2) - return false; - if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) - return __dval == 30; - return true; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept { - return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering -operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept { - if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0) - return __c; - return __lhs.day() <=> __rhs.day(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day -operator/(const month& __lhs, const day& __rhs) noexcept { - return month_day{__lhs, __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day -operator/(const day& __lhs, const month& __rhs) noexcept { - return __rhs / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept { - return __lhs / day(__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept { - return month(__lhs) / __rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept { - return month(__rhs) / __lhs; -} - -class month_day_last { -private: - chrono::month __m_; - -public: - _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept : __m_{__val} {} - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept { - return __lhs.month() == __rhs.month(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering -operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept { - return __lhs.month() <=> __rhs.month(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept { - return month_day_last{__lhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept { - return month_day_last{__rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept { - return month_day_last{month(__lhs)}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept { - return month_day_last{month(__rhs)}; -} - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_day& __md) noexcept { - return std::__hash_combine(hash{}(__md.month()), hash{}(__md.day())); - } -}; - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_day_last& __mdl) noexcept { - return hash{}(__mdl.month()); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_MONTHDAY_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/ostream.h b/third_party/libcxx/include/c++/v1/__chrono/ostream.h deleted file mode 100644 index 7a01b18..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/ostream.h +++ /dev/null @@ -1,354 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_OSTREAM_H -#define _LIBCPP___CHRONO_OSTREAM_H - -#include <__config> - -#if _LIBCPP_HAS_LOCALIZATION - -# include <__chrono/calendar.h> -# include <__chrono/day.h> -# include <__chrono/duration.h> -# include <__chrono/file_clock.h> -# include <__chrono/gps_clock.h> -# include <__chrono/hh_mm_ss.h> -# include <__chrono/local_info.h> -# include <__chrono/month.h> -# include <__chrono/month_weekday.h> -# include <__chrono/monthday.h> -# include <__chrono/statically_widen.h> -# include <__chrono/sys_info.h> -# include <__chrono/system_clock.h> -# include <__chrono/tai_clock.h> -# include <__chrono/utc_clock.h> -# include <__chrono/weekday.h> -# include <__chrono/year.h> -# include <__chrono/year_month.h> -# include <__chrono/year_month_day.h> -# include <__chrono/year_month_weekday.h> -# include <__chrono/zoned_time.h> -# include <__concepts/same_as.h> -# include <__format/format_functions.h> -# include <__fwd/ostream.h> -# include -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 - -namespace chrono { - -template - requires(!treat_as_floating_point_v && _Duration{1} < days{1}) -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_time<_Duration>& __tp) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_days& __dp) { - return __os << year_month_day{__dp}; -} - -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const utc_time<_Duration>& __tp) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const tai_time<_Duration>& __tp) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const gps_time<_Duration>& __tp) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); -} - -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB -# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const file_time<_Duration> __tp) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const local_time<_Duration> __tp) { - return __os << sys_time<_Duration>{__tp.time_since_epoch()}; -} - -// Depending on the type the return is a const _CharT* or a basic_string<_CharT> -template -_LIBCPP_HIDE_FROM_ABI auto __units_suffix() { - // TODO FMT LWG issue the suffixes are always char and not STATICALLY-WIDEN'ed. - if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "as"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "fs"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "ps"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "ns"); - else if constexpr (same_as) -# if _LIBCPP_HAS_UNICODE - return _LIBCPP_STATICALLY_WIDEN(_CharT, "\u00b5s"); -# else - return _LIBCPP_STATICALLY_WIDEN(_CharT, "us"); -# endif - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "ms"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "cs"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "ds"); - else if constexpr (same_as>) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "s"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "das"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "hs"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "ks"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ms"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "Gs"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ts"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ps"); - else if constexpr (same_as) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "Es"); - else if constexpr (same_as>) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "min"); - else if constexpr (same_as>) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "h"); - else if constexpr (same_as>) - return _LIBCPP_STATICALLY_WIDEN(_CharT, "d"); - else if constexpr (_Period::den == 1) - return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}]s"), _Period::num); - else - return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}/{}]s"), _Period::num, _Period::den); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const duration<_Rep, _Period>& __d) { - basic_ostringstream<_CharT, _Traits> __s; - __s.flags(__os.flags()); - __s.imbue(__os.getloc()); - __s.precision(__os.precision()); - __s << __d.count() << chrono::__units_suffix<_CharT, _Period>(); - return __os << __s.str(); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const day& __d) { - return __os << (__d.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%d}"), __d) - // Note this error differs from the wording of the Standard. The - // Standard wording doesn't work well on AIX or Windows. There - // the formatted day seems to be either modulo 100 or completely - // omitted. Judging by the wording this is valid. - // TODO FMT Write a paper of file an LWG issue. - : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02} is not a valid day"), - static_cast(__d))); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const month& __m) { - return __os << (__m.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%b}"), __m) - : std::format(__os.getloc(), - _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid month"), - static_cast(__m))); // TODO FMT Standard mandated locale isn't used. -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const year& __y) { - return __os << (__y.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y}"), __y) - : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y} is not a valid year"), __y)); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday& __wd) { - return __os << (__wd.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%a}"), __wd) - : std::format(__os.getloc(), // TODO FMT Standard mandated locale isn't used. - _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid weekday"), - static_cast(__wd.c_encoding()))); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday_indexed& __wdi) { - auto __i = __wdi.index(); - return __os << (__i >= 1 && __i <= 5 - ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[{}]"), __wdi.weekday(), __i) - : std::format(__os.getloc(), - _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[{} is not a valid index]"), - __wdi.weekday(), - __i)); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday_last& __wdl) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[last]"), __wdl.weekday()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const month_day& __md) { - // TODO FMT The Standard allows 30th of February to be printed. - // It would be nice to show an error message instead. - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{}"), __md.month(), __md.day()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const month_day_last& __mdl) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/last"), __mdl.month()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const month_weekday& __mwd) { - return __os << std::format( - __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), __mwd.month(), __mwd.weekday_indexed()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const month_weekday_last& __mwdl) { - return __os << std::format( - __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), __mwdl.month(), __mwdl.weekday_last()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month& __ym) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}"), __ym.year(), __ym.month()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_day& __ymd) { - return __os << (__ymd.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%F}"), __ymd) - : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%F} is not a valid date"), __ymd)); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_day_last& __ymdl) { - return __os << std::format( - __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}"), __ymdl.year(), __ymdl.month_day_last()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_weekday& __ymwd) { - return __os << std::format( - __os.getloc(), - _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}/{:L}"), - __ymwd.year(), - __ymwd.month(), - __ymwd.weekday_indexed()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_weekday_last& __ymwdl) { - return __os << std::format( - __os.getloc(), - _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}/{:L}"), - __ymwdl.year(), - __ymwdl.month(), - __ymwdl.weekday_last()); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const hh_mm_ss<_Duration> __hms) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%T}"), __hms); -} - -# if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_info& __info) { - // __info.abbrev is always std::basic_string. - // Since these strings typically are short the conversion should be cheap. - std::basic_string<_CharT> __abbrev{__info.abbrev.begin(), __info.abbrev.end()}; - return __os << std::format( - _LIBCPP_STATICALLY_WIDEN(_CharT, "[{:%F %T}, {:%F %T}) {:%T} {:%Q%q} \"{}\""), - __info.begin, - __info.end, - hh_mm_ss{__info.offset}, - __info.save, - __abbrev); -} - -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __info) { - auto __result = [&]() -> basic_string<_CharT> { - switch (__info.result) { - case local_info::unique: - return _LIBCPP_STATICALLY_WIDEN(_CharT, "unique"); - case local_info::nonexistent: - return _LIBCPP_STATICALLY_WIDEN(_CharT, "non-existent"); - case local_info::ambiguous: - return _LIBCPP_STATICALLY_WIDEN(_CharT, "ambiguous"); - - default: - return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "unspecified result ({})"), __info.result); - }; - }; - - return __os << std::format( - _LIBCPP_STATICALLY_WIDEN(_CharT, "{}: {{{}, {}}}"), __result(), __info.first, __info.second); -} - -# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM -template -_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, const zoned_time<_Duration, _TimeZonePtr>& __tp) { - return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T %Z}"), __tp); -} -# endif -# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -} // namespace chrono - -# endif // if _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_LOCALIZATION - -#endif // _LIBCPP___CHRONO_OSTREAM_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/parser_std_format_spec.h b/third_party/libcxx/include/c++/v1/__chrono/parser_std_format_spec.h deleted file mode 100644 index 8ecc19f..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/parser_std_format_spec.h +++ /dev/null @@ -1,421 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H -#define _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H - -#include <__config> - -#if _LIBCPP_HAS_LOCALIZATION - -# include <__format/concepts.h> -# include <__format/format_error.h> -# include <__format/format_parse_context.h> -# include <__format/formatter_string.h> -# include <__format/parser_std_format_spec.h> -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 - -namespace __format_spec { - -// By not placing this constant in the formatter class it's not duplicated for char and wchar_t -inline constexpr __fields __fields_chrono_fractional{ - .__precision_ = true, .__locale_specific_form_ = true, .__type_ = false}; -inline constexpr __fields __fields_chrono{.__locale_specific_form_ = true, .__type_ = false}; - -/// Flags available or required in a chrono type. -/// -/// The caller of the chrono formatter lists the types it has available and the -/// validation tests whether the requested type spec (e.g. %M) is available in -/// the formatter. -/// When the type in the chrono-format-spec isn't present in the data a -/// \ref format_error is thrown. -enum class __flags { - __second = 0x1, - __minute = 0x2, - __hour = 0x4, - __time = __hour | __minute | __second, - - __day = 0x8, - __month = 0x10, - __year = 0x20, - - __weekday = 0x40, - - __month_day = __day | __month, - __month_weekday = __weekday | __month, - __year_month = __month | __year, - __date = __day | __month | __year | __weekday, - - __date_time = __date | __time, - - __duration = 0x80 | __time, - - __time_zone = 0x100, - - __clock = __date_time | __time_zone -}; - -_LIBCPP_HIDE_FROM_ABI constexpr __flags operator&(__flags __lhs, __flags __rhs) { - return static_cast<__flags>(static_cast(__lhs) & static_cast(__rhs)); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_second(__flags __flags) { - if ((__flags & __flags::__second) != __flags::__second) - std::__throw_format_error("The supplied date time doesn't contain a second"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_minute(__flags __flags) { - if ((__flags & __flags::__minute) != __flags::__minute) - std::__throw_format_error("The supplied date time doesn't contain a minute"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_hour(__flags __flags) { - if ((__flags & __flags::__hour) != __flags::__hour) - std::__throw_format_error("The supplied date time doesn't contain an hour"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_time(__flags __flags) { - if ((__flags & __flags::__time) != __flags::__time) - std::__throw_format_error("The supplied date time doesn't contain a time"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_day(__flags __flags) { - if ((__flags & __flags::__day) != __flags::__day) - std::__throw_format_error("The supplied date time doesn't contain a day"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_month(__flags __flags) { - if ((__flags & __flags::__month) != __flags::__month) - std::__throw_format_error("The supplied date time doesn't contain a month"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_year(__flags __flags) { - if ((__flags & __flags::__year) != __flags::__year) - std::__throw_format_error("The supplied date time doesn't contain a year"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_date(__flags __flags) { - if ((__flags & __flags::__date) != __flags::__date) - std::__throw_format_error("The supplied date time doesn't contain a date"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_date_or_duration(__flags __flags) { - if (((__flags & __flags::__date) != __flags::__date) && ((__flags & __flags::__duration) != __flags::__duration)) - std::__throw_format_error("The supplied date time doesn't contain a date or duration"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_date_time(__flags __flags) { - if ((__flags & __flags::__date_time) != __flags::__date_time) - std::__throw_format_error("The supplied date time doesn't contain a date and time"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_weekday(__flags __flags) { - if ((__flags & __flags::__weekday) != __flags::__weekday) - std::__throw_format_error("The supplied date time doesn't contain a weekday"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_duration(__flags __flags) { - if ((__flags & __flags::__duration) != __flags::__duration) - std::__throw_format_error("The supplied date time doesn't contain a duration"); -} - -_LIBCPP_HIDE_FROM_ABI constexpr void __validate_time_zone(__flags __flags) { - if ((__flags & __flags::__time_zone) != __flags::__time_zone) - std::__throw_format_error("The supplied date time doesn't contain a time zone"); -} - -template -class __parser_chrono { - using _ConstIterator _LIBCPP_NODEBUG = typename basic_format_parse_context<_CharT>::const_iterator; - -public: - template - _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator - __parse(_ParseContext& __ctx, __fields __fields, __flags __flags) { - _ConstIterator __begin = __parser_.__parse(__ctx, __fields); - _ConstIterator __end = __ctx.end(); - if (__begin == __end) - return __begin; - - _ConstIterator __last = __parse_chrono_specs(__begin, __end, __flags); - __chrono_specs_ = basic_string_view<_CharT>{__begin, __last}; - - return __last; - } - - __parser<_CharT> __parser_; - basic_string_view<_CharT> __chrono_specs_; - -private: - _LIBCPP_HIDE_FROM_ABI constexpr _ConstIterator - __parse_chrono_specs(_ConstIterator __begin, _ConstIterator __end, __flags __flags) { - _LIBCPP_ASSERT_INTERNAL(__begin != __end, - "When called with an empty input the function will cause " - "undefined behavior by evaluating data not in the input"); - - if (*__begin != _CharT('%') && *__begin != _CharT('}')) - std::__throw_format_error("The format specifier expects a '%' or a '}'"); - - do { - switch (*__begin) { - case _CharT('{'): - std::__throw_format_error("The chrono specifiers contain a '{'"); - - case _CharT('}'): - return __begin; - - case _CharT('%'): - __parse_conversion_spec(__begin, __end, __flags); - [[fallthrough]]; - - default: - // All other literals - ++__begin; - } - - } while (__begin != __end && *__begin != _CharT('}')); - - return __begin; - } - - /// \pre *__begin == '%' - /// \post __begin points at the end parsed conversion-spec - _LIBCPP_HIDE_FROM_ABI constexpr void - __parse_conversion_spec(_ConstIterator& __begin, _ConstIterator __end, __flags __flags) { - ++__begin; - if (__begin == __end) - std::__throw_format_error("End of input while parsing a conversion specifier"); - - switch (*__begin) { - case _CharT('n'): - case _CharT('t'): - case _CharT('%'): - break; - - case _CharT('S'): - __format_spec::__validate_second(__flags); - break; - - case _CharT('M'): - __format_spec::__validate_minute(__flags); - break; - - case _CharT('p'): // TODO FMT does the formater require an hour or a time? - case _CharT('H'): - case _CharT('I'): - __parser_.__hour_ = true; - __validate_hour(__flags); - break; - - case _CharT('r'): - case _CharT('R'): - case _CharT('T'): - case _CharT('X'): - __parser_.__hour_ = true; - __format_spec::__validate_time(__flags); - break; - - case _CharT('d'): - case _CharT('e'): - __format_spec::__validate_day(__flags); - break; - - case _CharT('b'): - case _CharT('h'): - case _CharT('B'): - __parser_.__month_name_ = true; - [[fallthrough]]; - case _CharT('m'): - __format_spec::__validate_month(__flags); - break; - - case _CharT('y'): - case _CharT('C'): - case _CharT('Y'): - __format_spec::__validate_year(__flags); - break; - - case _CharT('j'): - __parser_.__day_of_year_ = true; - __format_spec::__validate_date_or_duration(__flags); - break; - - case _CharT('g'): - case _CharT('G'): - case _CharT('U'): - case _CharT('V'): - case _CharT('W'): - __parser_.__week_of_year_ = true; - [[fallthrough]]; - case _CharT('x'): - case _CharT('D'): - case _CharT('F'): - __format_spec::__validate_date(__flags); - break; - - case _CharT('c'): - __format_spec::__validate_date_time(__flags); - break; - - case _CharT('a'): - case _CharT('A'): - __parser_.__weekday_name_ = true; - [[fallthrough]]; - case _CharT('u'): - case _CharT('w'): - __parser_.__weekday_ = true; - __validate_weekday(__flags); - __format_spec::__validate_weekday(__flags); - break; - - case _CharT('q'): - case _CharT('Q'): - __format_spec::__validate_duration(__flags); - break; - - case _CharT('E'): - __parse_modifier_E(__begin, __end, __flags); - break; - - case _CharT('O'): - __parse_modifier_O(__begin, __end, __flags); - break; - - case _CharT('z'): - case _CharT('Z'): - // Currently there's no time zone information. However some clocks have a - // hard-coded "time zone", for these clocks the information can be used. - // TODO FMT implement time zones. - __format_spec::__validate_time_zone(__flags); - break; - - default: // unknown type; - std::__throw_format_error("The date time type specifier is invalid"); - } - } - - /// \pre *__begin == 'E' - /// \post __begin is incremented by one. - _LIBCPP_HIDE_FROM_ABI constexpr void - __parse_modifier_E(_ConstIterator& __begin, _ConstIterator __end, __flags __flags) { - ++__begin; - if (__begin == __end) - std::__throw_format_error("End of input while parsing the modifier E"); - - switch (*__begin) { - case _CharT('X'): - __parser_.__hour_ = true; - __format_spec::__validate_time(__flags); - break; - - case _CharT('y'): - case _CharT('C'): - case _CharT('Y'): - __format_spec::__validate_year(__flags); - break; - - case _CharT('x'): - __format_spec::__validate_date(__flags); - break; - - case _CharT('c'): - __format_spec::__validate_date_time(__flags); - break; - - case _CharT('z'): - // Currently there's no time zone information. However some clocks have a - // hard-coded "time zone", for these clocks the information can be used. - // TODO FMT implement time zones. - __format_spec::__validate_time_zone(__flags); - break; - - default: - std::__throw_format_error("The date time type specifier for modifier E is invalid"); - } - } - - /// \pre *__begin == 'O' - /// \post __begin is incremented by one. - _LIBCPP_HIDE_FROM_ABI constexpr void - __parse_modifier_O(_ConstIterator& __begin, _ConstIterator __end, __flags __flags) { - ++__begin; - if (__begin == __end) - std::__throw_format_error("End of input while parsing the modifier O"); - - switch (*__begin) { - case _CharT('S'): - __format_spec::__validate_second(__flags); - break; - - case _CharT('M'): - __format_spec::__validate_minute(__flags); - break; - - case _CharT('I'): - case _CharT('H'): - __parser_.__hour_ = true; - __format_spec::__validate_hour(__flags); - break; - - case _CharT('d'): - case _CharT('e'): - __format_spec::__validate_day(__flags); - break; - - case _CharT('m'): - __format_spec::__validate_month(__flags); - break; - - case _CharT('y'): - __format_spec::__validate_year(__flags); - break; - - case _CharT('U'): - case _CharT('V'): - case _CharT('W'): - __parser_.__week_of_year_ = true; - __format_spec::__validate_date(__flags); - break; - - case _CharT('u'): - case _CharT('w'): - __parser_.__weekday_ = true; - __format_spec::__validate_weekday(__flags); - break; - - case _CharT('z'): - // Currently there's no time zone information. However some clocks have a - // hard-coded "time zone", for these clocks the information can be used. - // TODO FMT implement time zones. - __format_spec::__validate_time_zone(__flags); - break; - - default: - std::__throw_format_error("The date time type specifier for modifier O is invalid"); - } - } -}; - -} // namespace __format_spec - -# endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_LOCALIZATION - -#endif // _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/statically_widen.h b/third_party/libcxx/include/c++/v1/__chrono/statically_widen.h deleted file mode 100644 index 40e0856..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/statically_widen.h +++ /dev/null @@ -1,52 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_STATICALLY_WIDEN_H -#define _LIBCPP___CHRONO_STATICALLY_WIDEN_H - -// Implements the STATICALLY-WIDEN exposition-only function. ([time.general]/2) - -#include <__concepts/same_as.h> -#include <__config> -#include <__format/concepts.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -# if _LIBCPP_HAS_WIDE_CHARACTERS -template <__fmt_char_type _CharT> -_LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) { - if constexpr (same_as<_CharT, char>) - return __str; - else - return __wstr; -} -# define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str, L##__str) -# else // _LIBCPP_HAS_WIDE_CHARACTERS - -// Without this indirection the unit test test/libcxx/modules_include.sh.cpp -// fails for the CI build "No wide characters". This seems like a bug. -// TODO FMT investigate why this is needed. -template <__fmt_char_type _CharT> -_LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str) { - return __str; -} -# define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str) -# endif // _LIBCPP_HAS_WIDE_CHARACTERS - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHRONO_STATICALLY_WIDEN_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/steady_clock.h b/third_party/libcxx/include/c++/v1/__chrono/steady_clock.h deleted file mode 100644 index 8e68c9a..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/steady_clock.h +++ /dev/null @@ -1,42 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_STEADY_CLOCK_H -#define _LIBCPP___CHRONO_STEADY_CLOCK_H - -#include <__chrono/duration.h> -#include <__chrono/time_point.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -#if _LIBCPP_HAS_MONOTONIC_CLOCK -class _LIBCPP_EXPORTED_FROM_ABI steady_clock { -public: - typedef nanoseconds duration; - typedef duration::rep rep; - typedef duration::period period; - typedef chrono::time_point time_point; - static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = true; - - [[__nodiscard__]] static time_point now() _NOEXCEPT; -}; -#endif - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHRONO_STEADY_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/sys_info.h b/third_party/libcxx/include/c++/v1/__chrono/sys_info.h deleted file mode 100644 index 81e37f2..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/sys_info.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_SYS_INFO_H -#define _LIBCPP___CHRONO_SYS_INFO_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/duration.h> -# include <__chrono/system_clock.h> -# include <__chrono/time_point.h> -# include <__config> -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 - -namespace chrono { - -struct sys_info { - sys_seconds begin; - sys_seconds end; - seconds offset; - minutes save; - string abbrev; -}; - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_SYS_INFO_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/system_clock.h b/third_party/libcxx/include/c++/v1/__chrono/system_clock.h deleted file mode 100644 index e3ef75a..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/system_clock.h +++ /dev/null @@ -1,52 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_SYSTEM_CLOCK_H -#define _LIBCPP___CHRONO_SYSTEM_CLOCK_H - -#include <__chrono/duration.h> -#include <__chrono/time_point.h> -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class _LIBCPP_EXPORTED_FROM_ABI system_clock { -public: - typedef microseconds duration; - typedef duration::rep rep; - typedef duration::period period; - typedef chrono::time_point time_point; - static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false; - - [[__nodiscard__]] static time_point now() _NOEXCEPT; - [[__nodiscard__]] static time_t to_time_t(const time_point& __t) _NOEXCEPT; - [[__nodiscard__]] static time_point from_time_t(time_t __t) _NOEXCEPT; -}; - -#if _LIBCPP_STD_VER >= 20 - -template -using sys_time = time_point; -using sys_seconds = sys_time; -using sys_days = sys_time; - -#endif - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CHRONO_SYSTEM_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/tai_clock.h b/third_party/libcxx/include/c++/v1/__chrono/tai_clock.h deleted file mode 100644 index 14c8b70..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/tai_clock.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_TAI_CLOCK_H -#define _LIBCPP___CHRONO_TAI_CLOCK_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__assert> -# include <__chrono/duration.h> -# include <__chrono/time_point.h> -# include <__chrono/utc_clock.h> -# include <__config> -# include <__type_traits/common_type.h> - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -class tai_clock; - -template -using tai_time = time_point; -using tai_seconds = tai_time; - -// [time.clock.tai.overview]/1 -// The clock tai_clock measures seconds since 1958-01-01 00:00:00 and is -// offset 10s ahead of UTC at this date. That is, 1958-01-01 00:00:00 TAI is -// equivalent to 1957-12-31 23:59:50 UTC. Leap seconds are not inserted into -// TAI. Therefore every time a leap second is inserted into UTC, UTC shifts -// another second with respect to TAI. For example by 2000-01-01 there had -// been 22 positive and 0 negative leap seconds inserted so 2000-01-01 -// 00:00:00 UTC is equivalent to 2000-01-01 00:00:32 TAI (22s plus the -// initial 10s offset). -// -// Note this does not specify what the UTC offset before 1958-01-01 00:00:00 -// TAI is, nor does it follow the "real" TAI clock between 1958-01-01 and the -// start of the UTC epoch. So while the member functions are fully specified in -// the standard, they do not technically follow the "real-world" TAI clock with -// 100% accuracy. -// -// https://koka-lang.github.io/koka/doc/std_time_utc.html contains more -// information and references. -class tai_clock { -public: - using rep = utc_clock::rep; - using period = utc_clock::period; - using duration = chrono::duration; - using time_point = chrono::time_point; - static constexpr bool is_steady = false; // The utc_clock is not steady. - - // The static difference between UTC and TAI time. - static constexpr chrono::seconds __offset{378691210}; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_utc(utc_clock::now()); } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time> - to_utc(const tai_time<_Duration>& __time) noexcept { - using _Rp = common_type_t<_Duration, seconds>; - _Duration __time_since_epoch = __time.time_since_epoch(); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch >= utc_time<_Rp>::min().time_since_epoch() + __offset, - "the TAI to UTC conversion would underflow"); - - return utc_time<_Rp>{__time_since_epoch - __offset}; - } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static tai_time> - from_utc(const utc_time<_Duration>& __time) noexcept { - using _Rp = common_type_t<_Duration, seconds>; - _Duration __time_since_epoch = __time.time_since_epoch(); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch <= utc_time<_Rp>::max().time_since_epoch() - __offset, - "the UTC to TAI conversion would overflow"); - - return tai_time<_Rp>{__time_since_epoch + __offset}; - } -}; - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_TAI_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/time_point.h b/third_party/libcxx/include/c++/v1/__chrono/time_point.h deleted file mode 100644 index d393e34..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/time_point.h +++ /dev/null @@ -1,255 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_TIME_POINT_H -#define _LIBCPP___CHRONO_TIME_POINT_H - -#include <__chrono/duration.h> -#include <__compare/ordering.h> -#include <__compare/three_way_comparable.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> -#include <__type_traits/common_type.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_convertible.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -template -class time_point { - static_assert(__is_duration_v<_Duration>, "Second template parameter of time_point must be a std::chrono::duration"); - -public: - typedef _Clock clock; - typedef _Duration duration; - typedef typename duration::rep rep; - typedef typename duration::period period; - -private: - duration __d_; - -public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point() : __d_(duration::zero()) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit time_point(const duration& __d) : __d_(__d) {} - - // conversions - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point(const time_point& __t) - : __d_(__t.time_since_epoch()) {} - - // observer - - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 duration time_since_epoch() const { - return __d_; - } - - // arithmetic - -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI constexpr time_point& operator++() { - ++__d_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI constexpr time_point operator++(int) { return time_point{__d_++}; } - _LIBCPP_HIDE_FROM_ABI constexpr time_point& operator--() { - --__d_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI constexpr time_point operator--(int) { return time_point{__d_--}; } -#endif // _LIBCPP_STD_VER >= 20 - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator+=(const duration& __d) { - __d_ += __d; - return *this; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator-=(const duration& __d) { - __d_ -= __d; - return *this; - } - - // special values - - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT { - return time_point(duration::min()); - } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT { - return time_point(duration::max()); - } -}; - -} // namespace chrono - -template -struct common_type, chrono::time_point<_Clock, _Duration2> > { - typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; -}; - -namespace chrono { - -template , int> = 0> -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, _ToDuration> -time_point_cast(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); -} - -#if _LIBCPP_STD_VER >= 17 -template , int> = 0> -[[nodiscard]] inline - _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> floor(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{chrono::floor<_ToDuration>(__t.time_since_epoch())}; -} - -template , int> = 0> -[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> -ceil(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{chrono::ceil<_ToDuration>(__t.time_since_epoch())}; -} - -template , int> = 0> -[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> -round(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{chrono::round<_ToDuration>(__t.time_since_epoch())}; -} - -template ::is_signed, int> = 0> -[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr duration<_Rep, _Period> abs(duration<_Rep, _Period> __d) { - return __d >= __d.zero() ? +__d : -__d; -} -#endif // _LIBCPP_STD_VER >= 17 - -// time_point == - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() == __rhs.time_since_epoch(); -} - -#if _LIBCPP_STD_VER <= 17 - -// time_point != - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__lhs == __rhs); -} - -#endif // _LIBCPP_STD_VER <= 17 - -// time_point < - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() < __rhs.time_since_epoch(); -} - -// time_point > - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __rhs < __lhs; -} - -// time_point <= - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__rhs < __lhs); -} - -// time_point >= - -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool -operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__lhs < __rhs); -} - -#if _LIBCPP_STD_VER >= 20 - -template _Duration2> -_LIBCPP_HIDE_FROM_ABI constexpr auto -operator<=>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() <=> __rhs.time_since_epoch(); -} - -#endif // _LIBCPP_STD_VER >= 20 - -// time_point operator+(time_point x, duration y); - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> -operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; - return _Tr(__lhs.time_since_epoch() + __rhs); -} - -// time_point operator+(duration x, time_point y); - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type, _Duration2>::type> -operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __rhs + __lhs; -} - -// time_point operator-(time_point x, duration y); - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> -operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; - return _Ret(__lhs.time_since_epoch() - __rhs); -} - -// duration operator-(time_point x, time_point y); - -template -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 -typename common_type<_Duration1, _Duration2>::type -operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() - __rhs.time_since_epoch(); -} - -} // namespace chrono - -#if _LIBCPP_STD_VER >= 26 - -template - requires __has_enabled_hash<_Duration>::value -struct hash> { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::time_point<_Clock, _Duration>& __tp) { - return hash<_Duration>{}(__tp.time_since_epoch()); - } -}; - -#endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHRONO_TIME_POINT_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/time_zone.h b/third_party/libcxx/include/c++/v1/__chrono/time_zone.h deleted file mode 100644 index d18d59d..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/time_zone.h +++ /dev/null @@ -1,185 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_TIME_ZONE_H -#define _LIBCPP___CHRONO_TIME_ZONE_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/calendar.h> -# include <__chrono/duration.h> -# include <__chrono/exception.h> -# include <__chrono/local_info.h> -# include <__chrono/sys_info.h> -# include <__chrono/system_clock.h> -# include <__compare/strong_order.h> -# include <__config> -# include <__memory/unique_ptr.h> -# include <__type_traits/common_type.h> -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -enum class choose { earliest, latest }; - -class _LIBCPP_AVAILABILITY_TZDB time_zone { - _LIBCPP_HIDE_FROM_ABI time_zone() = default; - -public: - class __impl; // public so it can be used by make_unique. - - // The "constructor". - // - // The default constructor is private to avoid the constructor from being - // part of the ABI. Instead use an __ugly_named function as an ABI interface, - // since that gives us the ability to change it in the future. - [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI static time_zone __create(unique_ptr<__impl>&& __p); - - _LIBCPP_EXPORTED_FROM_ABI ~time_zone(); - - _LIBCPP_HIDE_FROM_ABI time_zone(time_zone&&) = default; - _LIBCPP_HIDE_FROM_ABI time_zone& operator=(time_zone&&) = default; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name(); } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_info get_info(const sys_time<_Duration>& __time) const { - return __get_info(chrono::time_point_cast(__time)); - } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_info get_info(const local_time<_Duration>& __time) const { - return __get_info(chrono::time_point_cast(__time)); - } - - // We don't apply nodiscard here since this function throws on many inputs, - // so it could be used as a validation. - template - _LIBCPP_HIDE_FROM_ABI sys_time> to_sys(const local_time<_Duration>& __time) const { - local_info __info = get_info(__time); - switch (__info.result) { - case local_info::unique: - return sys_time>{__time.time_since_epoch() - __info.first.offset}; - - case local_info::nonexistent: - chrono::__throw_nonexistent_local_time(__time, __info); - - case local_info::ambiguous: - chrono::__throw_ambiguous_local_time(__time, __info); - } - - // TODO TZDB The Standard does not specify anything in these cases. - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __info.result != -1, "cannot convert the local time; it would be before the minimum system clock value"); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __info.result != -2, "cannot convert the local time; it would be after the maximum system clock value"); - - return {}; - } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time> - to_sys(const local_time<_Duration>& __time, choose __z) const { - local_info __info = get_info(__time); - switch (__info.result) { - case local_info::unique: // first and second are the same - return sys_time>{__time.time_since_epoch() - __info.first.offset}; - - case local_info::nonexistent: - // first and second are the same - // All non-existing values are converted to the same time. - return sys_time>{__info.first.end}; - - case local_info::ambiguous: - switch (__z) { - case choose::earliest: - return sys_time>{__time.time_since_epoch() - __info.first.offset}; - - case choose::latest: - return sys_time>{__time.time_since_epoch() - __info.second.offset}; - - // Note a value out of bounds is not specified. - } - } - - // TODO TZDB The standard does not specify anything in these cases. - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __info.result != -1, "cannot convert the local time; it would be before the minimum system clock value"); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __info.result != -2, "cannot convert the local time; it would be after the maximum system clock value"); - - return {}; - } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_time> - to_local(const sys_time<_Duration>& __time) const { - using _Dp = common_type_t<_Duration, seconds>; - - sys_info __info = get_info(__time); - - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __info.offset >= chrono::seconds{0} || __time.time_since_epoch() >= _Dp::min() - __info.offset, - "cannot convert the system time; it would be before the minimum local clock value"); - - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - __info.offset <= chrono::seconds{0} || __time.time_since_epoch() <= _Dp::max() - __info.offset, - "cannot convert the system time; it would be after the maximum local clock value"); - - return local_time<_Dp>{__time.time_since_epoch() + __info.offset}; - } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const noexcept { return *__impl_; } - -private: - [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI string_view __name() const noexcept; - - [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI sys_info __get_info(sys_seconds __time) const; - [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI local_info __get_info(local_seconds __time) const; - - unique_ptr<__impl> __impl_; -}; - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool -operator==(const time_zone& __x, const time_zone& __y) noexcept { - return __x.name() == __y.name(); -} - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering -operator<=>(const time_zone& __x, const time_zone& __y) noexcept { - return __x.name() <=> __y.name(); -} - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_TIME_ZONE_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/time_zone_link.h b/third_party/libcxx/include/c++/v1/__chrono/time_zone_link.h deleted file mode 100644 index cae40b0..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/time_zone_link.h +++ /dev/null @@ -1,79 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_TIME_ZONE_LINK_H -#define _LIBCPP___CHRONO_TIME_ZONE_LINK_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__compare/strong_order.h> -# include <__config> -# include <__utility/private_constructor_tag.h> -# include -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -class time_zone_link { -public: - [[nodiscard]] - _LIBCPP_HIDE_FROM_ABI explicit time_zone_link(__private_constructor_tag, string_view __name, string_view __target) - : __name_{__name}, __target_{__target} {} - - _LIBCPP_HIDE_FROM_ABI time_zone_link(time_zone_link&&) = default; - _LIBCPP_HIDE_FROM_ABI time_zone_link& operator=(time_zone_link&&) = default; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view target() const noexcept { return __target_; } - -private: - string __name_; - // TODO TZDB instead of the name we can store the pointer to a zone. These - // pointers are immutable. This makes it possible to directly return a - // pointer in the time_zone in the 'locate_zone' function. - string __target_; -}; - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool -operator==(const time_zone_link& __x, const time_zone_link& __y) noexcept { - return __x.name() == __y.name(); -} - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering -operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept { - return __x.name() <=> __y.name(); -} - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/tzdb.h b/third_party/libcxx/include/c++/v1/__chrono/tzdb.h deleted file mode 100644 index fb85f66..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/tzdb.h +++ /dev/null @@ -1,96 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_TZDB_H -#define _LIBCPP___CHRONO_TZDB_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__algorithm/ranges_lower_bound.h> -# include <__chrono/leap_second.h> -# include <__chrono/time_zone.h> -# include <__chrono/time_zone_link.h> -# include <__config> -# include <__memory/addressof.h> -# include <__vector/vector.h> -# include -# include -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -struct tzdb { - string version; - vector zones; - vector links; - - vector leap_seconds; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* __locate_zone(string_view __name) const { - if (const time_zone* __result = __find_in_zone(__name)) - return __result; - - if (auto __it = ranges::lower_bound(links, __name, {}, &time_zone_link::name); - __it != links.end() && __it->name() == __name) - if (const time_zone* __result = __find_in_zone(__it->target())) - return __result; - - return nullptr; - } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* locate_zone(string_view __name) const { - if (const time_zone* __result = __locate_zone(__name)) - return __result; - - std::__throw_runtime_error("tzdb: requested time zone not found"); - } - - [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI const time_zone* current_zone() const { - return __current_zone(); - } - -private: - _LIBCPP_HIDE_FROM_ABI const time_zone* __find_in_zone(string_view __name) const noexcept { - if (auto __it = ranges::lower_bound(zones, __name, {}, &time_zone::name); - __it != zones.end() && __it->name() == __name) - return std::addressof(*__it); - - return nullptr; - } - - [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const time_zone* __current_zone() const; -}; - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_TZDB_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/tzdb_list.h b/third_party/libcxx/include/c++/v1/__chrono/tzdb_list.h deleted file mode 100644 index 2b83a6d..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/tzdb_list.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_TZDB_LIST_H -#define _LIBCPP___CHRONO_TZDB_LIST_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/time_zone.h> -# include <__chrono/tzdb.h> -# include <__config> -# include <__fwd/string.h> -# include -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -// TODO TZDB -// Libc++ recently switched to only export __ugly_names from the dylib. -// Since the library is still experimental the functions in this header -// should be adapted to this new style. The other tzdb headers should be -// evaluated too. - -class _LIBCPP_AVAILABILITY_TZDB tzdb_list { -public: - class __impl; // public to allow construction in dylib - _LIBCPP_HIDE_FROM_ABI explicit tzdb_list(__impl* __p) : __impl_(__p) { - _LIBCPP_ASSERT_NON_NULL(__impl_ != nullptr, "initialized time_zone without a valid pimpl object"); - } - _LIBCPP_EXPORTED_FROM_ABI ~tzdb_list(); - - tzdb_list(const tzdb_list&) = delete; - tzdb_list& operator=(const tzdb_list&) = delete; - - using const_iterator = forward_list::const_iterator; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const tzdb& front() const noexcept { return __front(); } - - _LIBCPP_HIDE_FROM_ABI const_iterator erase_after(const_iterator __p) { return __erase_after(__p); } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __begin(); } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __end(); } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return __cbegin(); } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return __cend(); } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __impl& __implementation() { return *__impl_; } - -private: - [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const tzdb& __front() const noexcept; - - _LIBCPP_EXPORTED_FROM_ABI const_iterator __erase_after(const_iterator __p); - - [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __begin() const noexcept; - [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __end() const noexcept; - - [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cbegin() const noexcept; - [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cend() const noexcept; - - __impl* __impl_; -}; - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI tzdb_list& get_tzdb_list(); - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const tzdb& get_tzdb() { - return get_tzdb_list().front(); -} - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const time_zone* locate_zone(string_view __name) { - return get_tzdb().locate_zone(__name); -} - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const time_zone* current_zone() { - return get_tzdb().current_zone(); -} - -_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb(); - -[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI string remote_version(); - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_TZDB_LIST_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/utc_clock.h b/third_party/libcxx/include/c++/v1/__chrono/utc_clock.h deleted file mode 100644 index 2207b89..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/utc_clock.h +++ /dev/null @@ -1,163 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_UTC_CLOCK_H -#define _LIBCPP___CHRONO_UTC_CLOCK_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/duration.h> -# include <__chrono/leap_second.h> -# include <__chrono/system_clock.h> -# include <__chrono/time_point.h> -# include <__chrono/tzdb.h> -# include <__chrono/tzdb_list.h> -# include <__config> -# include <__type_traits/common_type.h> - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -class utc_clock; - -template -using utc_time = time_point; -using utc_seconds = utc_time; - -class utc_clock { -public: - using rep = system_clock::rep; - using period = system_clock::period; - using duration = chrono::duration; - using time_point = chrono::time_point; - static constexpr bool is_steady = false; // The system_clock is not steady. - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_sys(system_clock::now()); } - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static sys_time> - to_sys(const utc_time<_Duration>& __time); - - template - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time> - from_sys(const sys_time<_Duration>& __time) { - using _Rp = utc_time>; - // TODO TZDB investigate optimizations. - // - // The leap second database stores all transitions, this mean to calculate - // the current number of leap seconds the code needs to iterate over all - // leap seconds to accumulate the sum. Then the sum can be used to determine - // the sys_time. Accessing the database involves acquiring a mutex. - // - // The historic entries in the database are immutable. Hard-coding these - // values in a table would allow: - // - To store the sum, allowing a binary search on the data. - // - Avoid acquiring a mutex. - // The disadvantage are: - // - A slightly larger code size. - // - // There are two optimization directions - // - hard-code the database and do a linear search for future entries. This - // search can start at the back, and should probably contain very few - // entries. (Adding leap seconds is quite rare and new release of libc++ - // can add the new entries; they are announced half a year before they are - // added.) - // - During parsing the leap seconds store an additional database in the - // dylib with the list of the sum of the leap seconds. In that case there - // can be a private function __get_utc_to_sys_table that returns the - // table. - // - // Note for to_sys there are no optimizations to be done; it uses - // get_leap_second_info. The function get_leap_second_info could benefit - // from optimizations as described above; again both options apply. - - // Both UTC and the system clock use the same epoch. The Standard - // specifies from 1970-01-01 even when UTC starts at - // 1972-01-01 00:00:10 TAI. So when the sys_time is before epoch we can be - // sure there both clocks return the same value. - - const tzdb& __tzdb = chrono::get_tzdb(); - _Rp __result{__time.time_since_epoch()}; - for (const auto& __leap_second : __tzdb.leap_seconds) { - if (__leap_second > __time) - return __result; - - __result += __leap_second.value(); - } - return __result; - } -}; - -struct leap_second_info { - bool is_leap_second; - seconds elapsed; -}; - -template -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI leap_second_info get_leap_second_info(const utc_time<_Duration>& __time) { - const tzdb& __tzdb = chrono::get_tzdb(); - if (__tzdb.leap_seconds.empty()) [[unlikely]] - return {false, chrono::seconds{0}}; - - sys_seconds __sys{chrono::floor(__time).time_since_epoch()}; - seconds __elapsed{0}; - for (const auto& __leap_second : __tzdb.leap_seconds) { - if (__sys == __leap_second.date() + __elapsed) - // A time point may only be a leap second during a positive leap second - // insertion, since time points that occur during a (theoretical) - // negative leap second don't exist. - return {__leap_second.value() > 0s, __elapsed + __leap_second.value()}; - - if (__sys < __leap_second.date() + __elapsed) - return {false, __elapsed}; - - __elapsed += __leap_second.value(); - } - - return {false, __elapsed}; -} - -template -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time> -utc_clock::to_sys(const utc_time<_Duration>& __time) { - using _Dp = common_type_t<_Duration, seconds>; - leap_second_info __info = chrono::get_leap_second_info(__time); - - // [time.clock.utc.members]/2 - // Returns: A sys_time t, such that from_sys(t) == u if such a mapping - // exists. Otherwise u represents a time_point during a positive leap - // second insertion, the conversion counts that leap second as not - // inserted, and the last representable value of sys_time prior to the - // insertion of the leap second is returned. - sys_time> __result{__time.time_since_epoch() - __info.elapsed}; - if (__info.is_leap_second) - return chrono::floor(__result) + chrono::seconds{1} - _Dp{1}; - - return __result; -} - -} // namespace chrono - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_UTC_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/weekday.h b/third_party/libcxx/include/c++/v1/__chrono/weekday.h deleted file mode 100644 index 5e1065d..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/weekday.h +++ /dev/null @@ -1,202 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_WEEKDAY_H -#define _LIBCPP___CHRONO_WEEKDAY_H - -#include <__chrono/calendar.h> -#include <__chrono/duration.h> -#include <__chrono/system_clock.h> -#include <__chrono/time_point.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class weekday_indexed; -class weekday_last; - -class weekday { -private: - unsigned char __wd_; - _LIBCPP_HIDE_FROM_ABI static constexpr unsigned char __weekday_from_days(int __days) noexcept; - -public: - weekday() = default; - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(unsigned __val) noexcept - : __wd_(static_cast(__val == 7 ? 0 : __val)) {} - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday(const sys_days& __sysd) noexcept - : __wd_(__weekday_from_days(__sysd.time_since_epoch().count())) {} - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(const local_days& __locd) noexcept - : __wd_(__weekday_from_days(__locd.time_since_epoch().count())) {} - - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator++() noexcept { - __wd_ = (__wd_ == 6 ? 0 : __wd_ + 1); - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator++(int) noexcept { - weekday __tmp = *this; - ++(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator--() noexcept { - __wd_ = (__wd_ == 0 ? 6 : __wd_ - 1); - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator--(int) noexcept { - weekday __tmp = *this; - --(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI constexpr weekday& operator+=(const days& __dd) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr weekday& operator-=(const days& __dd) noexcept; - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned c_encoding() const noexcept { return __wd_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned iso_encoding() const noexcept { - return __wd_ == 0u ? 7 : __wd_; - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd_ <= 6; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr weekday_indexed operator[](unsigned __index) const noexcept; - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr weekday_last operator[](last_spec) const noexcept; -}; - -// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days -_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned char weekday::__weekday_from_days(int __days) noexcept { - return static_cast(static_cast(__days >= -4 ? (__days + 4) % 7 : (__days + 5) % 7 + 6)); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept { - return __lhs.c_encoding() == __rhs.c_encoding(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr weekday -operator+(const weekday& __lhs, const days& __rhs) noexcept { - auto const __mu = static_cast(__lhs.c_encoding()) + __rhs.count(); - auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; - return weekday{static_cast(__mu - __yr * 7)}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr weekday -operator+(const days& __lhs, const weekday& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr weekday -operator-(const weekday& __lhs, const days& __rhs) noexcept { - return __lhs + -__rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr days -operator-(const weekday& __lhs, const weekday& __rhs) noexcept { - const int __wdu = __lhs.c_encoding() - __rhs.c_encoding(); - const int __wk = (__wdu >= 0 ? __wdu : __wdu - 6) / 7; - return days{__wdu - __wk * 7}; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept { - *this = *this + __dd; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept { - *this = *this - __dd; - return *this; -} - -class weekday_indexed { -private: - chrono::weekday __wd_; - unsigned char __idx_; - -public: - weekday_indexed() = default; - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept - : __wd_{__wdval}, __idx_(__idxval) {} - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wd_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __idx_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { - return __wd_.ok() && __idx_ >= 1 && __idx_ <= 5; - } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept { - return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); -} - -class weekday_last { -private: - chrono::weekday __wd_; - -public: - _LIBCPP_HIDE_FROM_ABI explicit constexpr weekday_last(const chrono::weekday& __val) noexcept : __wd_{__val} {} - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::weekday weekday() const noexcept { return __wd_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept { return __wd_.ok(); } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept { - return __lhs.weekday() == __rhs.weekday(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr weekday_indexed weekday::operator[](unsigned __index) const noexcept { - return weekday_indexed{*this, __index}; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr weekday_last weekday::operator[](last_spec) const noexcept { - return weekday_last{*this}; -} - -inline constexpr weekday Sunday{0}; -inline constexpr weekday Monday{1}; -inline constexpr weekday Tuesday{2}; -inline constexpr weekday Wednesday{3}; -inline constexpr weekday Thursday{4}; -inline constexpr weekday Friday{5}; -inline constexpr weekday Saturday{6}; - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday& __w) noexcept { - return __w.c_encoding(); - } -}; - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday_indexed& __wi) noexcept { - return std::__hash_combine(hash{}(__wi.weekday()), __wi.index()); - } -}; - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::weekday_last& __wl) noexcept { - return hash{}(__wl.weekday()); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_WEEKDAY_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/year.h b/third_party/libcxx/include/c++/v1/__chrono/year.h deleted file mode 100644 index 208d6eb..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/year.h +++ /dev/null @@ -1,131 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_YEAR_H -#define _LIBCPP___CHRONO_YEAR_H - -#include <__chrono/duration.h> -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class year { -private: - short __y_; - -public: - year() = default; - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y_(static_cast(__val)) {} - - _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept { - ++__y_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr year operator++(int) noexcept { - year __tmp = *this; - ++(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept { - --__y_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr year operator--(int) noexcept { - year __tmp = *this; - --(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI constexpr year& operator+=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year& operator-=(const years& __dy) noexcept; - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept { - return __y_ % 4 == 0 && (__y_ % 100 != 0 || __y_ % 400 == 0); - } - _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{32767}; } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year& __lhs, const year& __rhs) noexcept { - return static_cast(__lhs) == static_cast(__rhs); -} - -_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, const year& __rhs) noexcept { - return static_cast(__lhs) <=> static_cast(__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const year& __lhs, const years& __rhs) noexcept { - return year(static_cast(__lhs) + __rhs.count()); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const years& __lhs, const year& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-(const year& __lhs, const years& __rhs) noexcept { - return __lhs + -__rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr years operator-(const year& __lhs, const year& __rhs) noexcept { - return years{static_cast(__lhs) - static_cast(__rhs)}; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator+=(const years& __dy) noexcept { - *this = *this + __dy; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator-=(const years& __dy) noexcept { - *this = *this - __dy; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept { - static_assert(static_cast(std::numeric_limits::max()) == static_cast(max())); - return static_cast(min()) <= __y_; -} - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year& __y) noexcept { - return static_cast(__y); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CHRONO_YEAR_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/year_month.h b/third_party/libcxx/include/c++/v1/__chrono/year_month.h deleted file mode 100644 index fdeeed1..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/year_month.h +++ /dev/null @@ -1,143 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_YEAR_MONTH_H -#define _LIBCPP___CHRONO_YEAR_MONTH_H - -#include <__chrono/duration.h> -#include <__chrono/month.h> -#include <__chrono/year.h> -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class year_month { - chrono::year __y_; - chrono::month __m_; - -public: - year_month() = default; - _LIBCPP_HIDE_FROM_ABI constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept - : __y_{__yval}, __m_{__mval} {} - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept; - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok(); } -}; - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, const month& __m) noexcept { - return year_month{__y, __m}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, int __m) noexcept { - return year_month{__y, month(__m)}; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept { - return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering -operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept { - if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0) - return __c; - return __lhs.month() <=> __rhs.month(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month -operator+(const year_month& __lhs, const months& __rhs) noexcept { - int __dmi = static_cast(static_cast(__lhs.month())) - 1 + __rhs.count(); - const int __dy = (__dmi >= 0 ? __dmi : __dmi - 11) / 12; - __dmi = __dmi - __dy * 12 + 1; - return (__lhs.year() + years(__dy)) / month(static_cast(__dmi)); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month -operator+(const months& __lhs, const year_month& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month -operator+(const year_month& __lhs, const years& __rhs) noexcept { - return (__lhs.year() + __rhs) / __lhs.month(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month -operator+(const years& __lhs, const year_month& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr months -operator-(const year_month& __lhs, const year_month& __rhs) noexcept { - return (__lhs.year() - __rhs.year()) + - months(static_cast(__lhs.month()) - static_cast(__rhs.month())); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month -operator-(const year_month& __lhs, const months& __rhs) noexcept { - return __lhs + -__rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month -operator-(const year_month& __lhs, const years& __rhs) noexcept { - return __lhs + -__rhs; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator+=(const months& __dm) noexcept { - *this = *this + __dm; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator-=(const months& __dm) noexcept { - *this = *this - __dm; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator+=(const years& __dy) noexcept { - *this = *this + __dy; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator-=(const years& __dy) noexcept { - *this = *this - __dy; - return *this; -} - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month& __ym) noexcept { - return std::__hash_combine(hash{}(__ym.year()), hash{}(__ym.month())); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_YEAR_MONTH_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/year_month_day.h b/third_party/libcxx/include/c++/v1/__chrono/year_month_day.h deleted file mode 100644 index b0149d3..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/year_month_day.h +++ /dev/null @@ -1,371 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_YEAR_MONTH_DAY_H -#define _LIBCPP___CHRONO_YEAR_MONTH_DAY_H - -#include <__chrono/calendar.h> -#include <__chrono/day.h> -#include <__chrono/duration.h> -#include <__chrono/month.h> -#include <__chrono/monthday.h> -#include <__chrono/system_clock.h> -#include <__chrono/time_point.h> -#include <__chrono/year.h> -#include <__chrono/year_month.h> -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class year_month_day_last; - -class year_month_day { -private: - chrono::year __y_; - chrono::month __m_; - chrono::day __d_; - -public: - year_month_day() = default; - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day( - const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept - : __y_{__yval}, __m_{__mval}, __d_{__dval} {} - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(const sys_days& __sysd) noexcept - : year_month_day(__from_days(__sysd.time_since_epoch())) {} - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_day(const local_days& __locd) noexcept - : year_month_day(__from_days(__locd.time_since_epoch())) {} - - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const months& __dm) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const months& __dm) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const years& __dy) noexcept; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } - _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { - return local_days{__to_days()}; - } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; - - _LIBCPP_HIDE_FROM_ABI static constexpr year_month_day __from_days(days __d) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept; -}; - -// https://howardhinnant.github.io/date_algorithms.html#civil_from_days -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day year_month_day::__from_days(days __d) noexcept { - static_assert(numeric_limits::digits >= 18, ""); - static_assert(numeric_limits::digits >= 20, ""); - const int __z = __d.count() + 719468; - const int __era = (__z >= 0 ? __z : __z - 146096) / 146097; - const unsigned __doe = static_cast(__z - __era * 146097); // [0, 146096] - const unsigned __yoe = (__doe - __doe / 1460 + __doe / 36524 - __doe / 146096) / 365; // [0, 399] - const int __yr = static_cast(__yoe) + __era * 400; - const unsigned __doy = __doe - (365 * __yoe + __yoe / 4 - __yoe / 100); // [0, 365] - const unsigned __mp = (5 * __doy + 2) / 153; // [0, 11] - const unsigned __dy = __doy - (153 * __mp + 2) / 5 + 1; // [1, 31] - const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12] - return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}}; -} - -// https://howardhinnant.github.io/date_algorithms.html#days_from_civil -_LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_day::__to_days() const noexcept { - static_assert(numeric_limits::digits >= 18, ""); - static_assert(numeric_limits::digits >= 20, ""); - - const int __yr = static_cast(__y_) - (__m_ <= February); - const unsigned __mth = static_cast(__m_); - const unsigned __dy = static_cast(__d_); - - const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; - const unsigned __yoe = static_cast(__yr - __era * 400); // [0, 399] - const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy - 1; // [0, 365] - const unsigned __doe = __yoe * 365 + __yoe / 4 - __yoe / 100 + __doy; // [0, 146096] - return days{__era * 146097 + static_cast(__doe) - 719468}; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept { - return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering -operator<=>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept { - if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0) - return __c; - if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0) - return __c; - return __lhs.day() <=> __rhs.day(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator/(const year_month& __lhs, const day& __rhs) noexcept { - return year_month_day{__lhs.year(), __lhs.month(), __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator/(const year_month& __lhs, int __rhs) noexcept { - return __lhs / day(__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator/(const year& __lhs, const month_day& __rhs) noexcept { - return __lhs / __rhs.month() / __rhs.day(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator/(int __lhs, const month_day& __rhs) noexcept { - return year(__lhs) / __rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator/(const month_day& __lhs, const year& __rhs) noexcept { - return __rhs / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator/(const month_day& __lhs, int __rhs) noexcept { - return year(__rhs) / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator+(const year_month_day& __lhs, const months& __rhs) noexcept { - return (__lhs.year() / __lhs.month() + __rhs) / __lhs.day(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator+(const months& __lhs, const year_month_day& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator-(const year_month_day& __lhs, const months& __rhs) noexcept { - return __lhs + -__rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator+(const year_month_day& __lhs, const years& __rhs) noexcept { - return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator+(const years& __lhs, const year_month_day& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day -operator-(const year_month_day& __lhs, const years& __rhs) noexcept { - return __lhs + -__rhs; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { - *this = *this + __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { - *this = *this - __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { - *this = *this + __dy; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { - *this = *this - __dy; - return *this; -} - -class year_month_day_last { -private: - chrono::year __y_; - chrono::month_day_last __mdl_; - -public: - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept - : __y_{__yval}, __mdl_{__mdlval} {} - - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const months& __m) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const months& __m) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const years& __y) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const years& __y) noexcept; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __mdl_.month(); } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month_day_last month_day_last() const noexcept { - return __mdl_; - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr chrono::day day() const noexcept; - _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { - return sys_days{year() / month() / day()}; - } - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { - return local_days{year() / month() / day()}; - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __mdl_.ok(); } -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day year_month_day_last::day() const noexcept { - constexpr chrono::day __d[] = { - chrono::day(31), - chrono::day(28), - chrono::day(31), - chrono::day(30), - chrono::day(31), - chrono::day(30), - chrono::day(31), - chrono::day(31), - chrono::day(30), - chrono::day(31), - chrono::day(30), - chrono::day(31)}; - return (month() != February || !__y_.is_leap()) && month().ok() - ? __d[static_cast(month()) - 1] - : chrono::day{29}; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept { - return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering -operator<=>(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept { - if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0) - return __c; - return __lhs.month_day_last() <=> __rhs.month_day_last(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator/(const year_month& __lhs, last_spec) noexcept { - return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator/(const year& __lhs, const month_day_last& __rhs) noexcept { - return year_month_day_last{__lhs, __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator/(int __lhs, const month_day_last& __rhs) noexcept { - return year_month_day_last{year{__lhs}, __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator/(const month_day_last& __lhs, const year& __rhs) noexcept { - return __rhs / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator/(const month_day_last& __lhs, int __rhs) noexcept { - return year{__rhs} / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept { - return (__lhs.year() / __lhs.month() + __rhs) / last; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept { - return __lhs + (-__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept { - return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last -operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept { - return __lhs + (-__rhs); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& -year_month_day_last::operator+=(const months& __dm) noexcept { - *this = *this + __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& -year_month_day_last::operator-=(const months& __dm) noexcept { - *this = *this - __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& -year_month_day_last::operator+=(const years& __dy) noexcept { - *this = *this + __dy; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& -year_month_day_last::operator-=(const years& __dy) noexcept { - *this = *this - __dy; - return *this; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept - : __y_{__ymdl.year()}, __m_{__ymdl.month()}, __d_{__ymdl.day()} {} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool year_month_day::ok() const noexcept { - if (!__y_.ok() || !__m_.ok()) - return false; - return chrono::day{1} <= __d_ && __d_ <= (__y_ / __m_ / last).day(); -} - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_day& __ymd) noexcept { - return std::__hash_combine( - hash{}(__ymd.year()), - std::__hash_combine(hash{}(__ymd.month()), hash{}(__ymd.day()))); - } -}; - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_day_last& __ymdl) noexcept { - return std::__hash_combine( - hash{}(__ymdl.year()), hash{}(__ymdl.month_day_last())); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_YEAR_MONTH_DAY_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/year_month_weekday.h b/third_party/libcxx/include/c++/v1/__chrono/year_month_weekday.h deleted file mode 100644 index eff472f..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/year_month_weekday.h +++ /dev/null @@ -1,325 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CHRONO_YEAR_MONTH_WEEKDAY_H -#define _LIBCPP___CHRONO_YEAR_MONTH_WEEKDAY_H - -#include <__chrono/calendar.h> -#include <__chrono/day.h> -#include <__chrono/duration.h> -#include <__chrono/month.h> -#include <__chrono/month_weekday.h> -#include <__chrono/system_clock.h> -#include <__chrono/time_point.h> -#include <__chrono/weekday.h> -#include <__chrono/year.h> -#include <__chrono/year_month.h> -#include <__chrono/year_month_day.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class year_month_weekday { - chrono::year __y_; - chrono::month __m_; - chrono::weekday_indexed __wdi_; - -public: - year_month_weekday() = default; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday( - const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept - : __y_{__yval}, __m_{__mval}, __wdi_{__wdival} {} - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const sys_days& __sysd) noexcept - : year_month_weekday(__from_days(__sysd.time_since_epoch())) {} - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept - : year_month_weekday(__from_days(__locd.time_since_epoch())) {} - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const months&) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const months&) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const years&) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const years&) noexcept; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { - return __wdi_.weekday(); - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __wdi_.index(); } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { - return __wdi_; - } - - _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { - return local_days{__to_days()}; - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { - if (!__y_.ok() || !__m_.ok() || !__wdi_.ok()) - return false; - if (__wdi_.index() <= 4) - return true; - auto __nth_weekday_day = - __wdi_.weekday() - chrono::weekday{static_cast(__y_ / __m_ / 1)} + days{(__wdi_.index() - 1) * 7 + 1}; - return static_cast(__nth_weekday_day.count()) <= static_cast((__y_ / __m_ / last).day()); - } - - _LIBCPP_HIDE_FROM_ABI static constexpr year_month_weekday __from_days(days __d) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept; -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday year_month_weekday::__from_days(days __d) noexcept { - const sys_days __sysd{__d}; - const chrono::weekday __wd = chrono::weekday(__sysd); - const year_month_day __ymd = year_month_day(__sysd); - return year_month_weekday{__ymd.year(), __ymd.month(), __wd[(static_cast(__ymd.day()) - 1) / 7 + 1]}; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_weekday::__to_days() const noexcept { - const sys_days __sysd = sys_days(__y_ / __m_ / 1); - return (__sysd + (__wdi_.weekday() - chrono::weekday(__sysd) + days{(__wdi_.index() - 1) * 7})).time_since_epoch(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept { - return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && - __lhs.weekday_indexed() == __rhs.weekday_indexed(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept { - return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator/(const year& __lhs, const month_weekday& __rhs) noexcept { - return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator/(int __lhs, const month_weekday& __rhs) noexcept { - return year(__lhs) / __rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator/(const month_weekday& __lhs, const year& __rhs) noexcept { - return __rhs / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator/(const month_weekday& __lhs, int __rhs) noexcept { - return year(__rhs) / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept { - return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept { - return __lhs + (-__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept { - return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday -operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept { - return __lhs + (-__rhs); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { - *this = *this + __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { - *this = *this - __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { - *this = *this + __dy; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { - *this = *this - __dy; - return *this; -} - -class year_month_weekday_last { -private: - chrono::year __y_; - chrono::month __m_; - chrono::weekday_last __wdl_; - -public: - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last( - const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept - : __y_{__yval}, __m_{__mval}, __wdl_{__wdlval} {} - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; - _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { - return __wdl_.weekday(); - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { - return __wdl_; - } - _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } - _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { - return local_days{__to_days()}; - } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { - return __y_.ok() && __m_.ok() && __wdl_.ok(); - } - - _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept; -}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_weekday_last::__to_days() const noexcept { - const sys_days __last = sys_days{__y_ / __m_ / last}; - return (__last - (chrono::weekday{__last} - __wdl_.weekday())).time_since_epoch(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool -operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept { - return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept { - return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept { - return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator/(int __lhs, const month_weekday_last& __rhs) noexcept { - return year(__lhs) / __rhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept { - return __rhs / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator/(const month_weekday_last& __lhs, int __rhs) noexcept { - return year(__rhs) / __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept { - return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept { - return __lhs + (-__rhs); -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept { - return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept { - return __rhs + __lhs; -} - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last -operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept { - return __lhs + (-__rhs); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& -year_month_weekday_last::operator+=(const months& __dm) noexcept { - *this = *this + __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& -year_month_weekday_last::operator-=(const months& __dm) noexcept { - *this = *this - __dm; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& -year_month_weekday_last::operator+=(const years& __dy) noexcept { - *this = *this + __dy; - return *this; -} -_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& -year_month_weekday_last::operator-=(const years& __dy) noexcept { - *this = *this - __dy; - return *this; -} - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_weekday& __ymw) noexcept { - return std::__hash_combine( - hash{}(__ymw.year()), - std::__hash_combine( - hash{}(__ymw.month()), hash{}(__ymw.weekday_indexed()))); - } -}; - -template <> -struct hash { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::year_month_weekday_last& __ymwl) noexcept { - return std::__hash_combine( - hash{}(__ymwl.year()), - std::__hash_combine( - hash{}(__ymwl.month()), hash{}(__ymwl.weekday_last()))); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___CHRONO_YEAR_MONTH_WEEKDAY_H diff --git a/third_party/libcxx/include/c++/v1/__chrono/zoned_time.h b/third_party/libcxx/include/c++/v1/__chrono/zoned_time.h deleted file mode 100644 index e63528e..0000000 --- a/third_party/libcxx/include/c++/v1/__chrono/zoned_time.h +++ /dev/null @@ -1,244 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html - -#ifndef _LIBCPP___CHRONO_ZONED_TIME_H -#define _LIBCPP___CHRONO_ZONED_TIME_H - -#include -// Enable the contents of the header only when libc++ was built with experimental features enabled. -#if _LIBCPP_HAS_EXPERIMENTAL_TZDB - -# include <__chrono/calendar.h> -# include <__chrono/duration.h> -# include <__chrono/sys_info.h> -# include <__chrono/system_clock.h> -# include <__chrono/time_zone.h> -# include <__chrono/tzdb_list.h> -# include <__concepts/constructible.h> -# include <__config> -# include <__cstddef/size_t.h> -# include <__functional/hash.h> -# include <__type_traits/common_type.h> -# include <__type_traits/conditional.h> -# include <__type_traits/remove_cvref.h> -# include <__utility/declval.h> -# include <__utility/move.h> -# include - -# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -# endif - -_LIBCPP_PUSH_MACROS -# include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION - -namespace chrono { - -template -struct zoned_traits {}; - -template <> -struct zoned_traits { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static const time_zone* default_zone() { return chrono::locate_zone("UTC"); } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static const time_zone* locate_zone(string_view __name) { - return chrono::locate_zone(__name); - } -}; - -template -class zoned_time { - // [time.zone.zonedtime.ctor]/2 - static_assert(__is_duration_v<_Duration>, - "the program is ill-formed since _Duration is not a specialization of std::chrono::duration"); - - // The wording uses the constraints like - // constructible_from - // Using these constraints in the code causes the compiler to give an - // error that the constraint depends on itself. To avoid that issue use - // the fact it is possible to create this object from a _TimeZonePtr. - using __traits _LIBCPP_NODEBUG = zoned_traits<_TimeZonePtr>; - -public: - using duration = common_type_t<_Duration, seconds>; - - _LIBCPP_HIDE_FROM_ABI zoned_time() - requires requires { __traits::default_zone(); } - : __zone_{__traits::default_zone()}, __tp_{} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time&) = default; - _LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const zoned_time&) = default; - - _LIBCPP_HIDE_FROM_ABI zoned_time(const sys_time<_Duration>& __tp) - requires requires { __traits::default_zone(); } - : __zone_{__traits::default_zone()}, __tp_{__tp} {} - - _LIBCPP_HIDE_FROM_ABI explicit zoned_time(_TimeZonePtr __zone) : __zone_{std::move(__zone)}, __tp_{} {} - - _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name) - requires(requires { __traits::locate_zone(string_view{}); } && - constructible_from<_TimeZonePtr, decltype(__traits::locate_zone(string_view{}))>) - : __zone_{__traits::locate_zone(__name)}, __tp_{} {} - - template - _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& __zt) - requires is_convertible_v, sys_time<_Duration>> - : __zone_{__zt.get_time_zone()}, __tp_{__zt.get_sys_time()} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const sys_time<_Duration>& __tp) - : __zone_{std::move(__zone)}, __tp_{__tp} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const sys_time<_Duration>& __tp) - requires requires { _TimeZonePtr{__traits::locate_zone(string_view{})}; } - : zoned_time{__traits::locate_zone(__name), __tp} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const local_time<_Duration>& __tp) - requires(is_convertible_v() -> to_sys(local_time<_Duration>{})), - sys_time>) - : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp)} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const local_time<_Duration>& __tp) - requires(requires { - _TimeZonePtr{__traits::locate_zone(string_view{})}; - } && is_convertible_v() -> to_sys(local_time<_Duration>{})), - sys_time>) - : zoned_time{__traits::locate_zone(__name), __tp} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const local_time<_Duration>& __tp, choose __c) - requires(is_convertible_v< - decltype(std::declval<_TimeZonePtr&>() -> to_sys(local_time<_Duration>{}, choose::earliest)), - sys_time>) - : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp, __c)} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const local_time<_Duration>& __tp, choose __c) - requires(requires { - _TimeZonePtr{__traits::locate_zone(string_view{})}; - } && is_convertible_v() -> to_sys(local_time<_Duration>{}, choose::earliest)), - sys_time>) - : zoned_time{__traits::locate_zone(__name), __tp, __c} {} - - template - _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const zoned_time<_Duration2, _TimeZonePtr2>& __zt) - requires is_convertible_v, sys_time<_Duration>> - : __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {} - - // per wording choose has no effect - template - _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const zoned_time<_Duration2, _TimeZonePtr2>& __zt, choose) - requires is_convertible_v, sys_time<_Duration>> - : __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {} - - template - _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const zoned_time<_Duration2, _TimeZonePtr2>& __zt) - requires(requires { - _TimeZonePtr{__traits::locate_zone(string_view{})}; - } && is_convertible_v, sys_time<_Duration>>) - : zoned_time{__traits::locate_zone(__name), __zt} {} - - template - _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const zoned_time<_Duration2, _TimeZonePtr2>& __zt, choose __c) - requires(requires { - _TimeZonePtr{__traits::locate_zone(string_view{})}; - } && is_convertible_v, sys_time<_Duration>>) - : zoned_time{__traits::locate_zone(__name), __zt, __c} {} - - _LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const sys_time<_Duration>& __tp) { - __tp_ = __tp; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const local_time<_Duration>& __tp) { - // TODO TZDB This seems wrong. - // Assigning a non-existent or ambiguous time will throw and not satisfy - // the post condition. This seems quite odd; I constructed an object with - // choose::earliest and that choice is not respected. - // what did LEWG do with this. - // MSVC STL and libstdc++ behave the same - __tp_ = __zone_->to_sys(__tp); - return *this; - } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI operator sys_time() const { return get_sys_time(); } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit operator local_time() const { return get_local_time(); } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _TimeZonePtr get_time_zone() const { return __zone_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_time get_local_time() const { return __zone_->to_local(__tp_); } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time get_sys_time() const { return __tp_; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_info get_info() const { return __zone_->get_info(__tp_); } - -private: - _TimeZonePtr __zone_; - sys_time __tp_; -}; - -zoned_time() -> zoned_time; - -template -zoned_time(sys_time<_Duration>) -> zoned_time>; - -template -using __time_zone_representation _LIBCPP_NODEBUG = - conditional_t, - const time_zone*, - remove_cvref_t<_TimeZonePtrOrName>>; - -template -zoned_time(_TimeZonePtrOrName&&) -> zoned_time>; - -template -zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>) - -> zoned_time, __time_zone_representation<_TimeZonePtrOrName>>; - -template -zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>, choose = choose::earliest) - -> zoned_time, __time_zone_representation<_TimeZonePtrOrName>>; - -template -zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>, choose = choose::earliest) - -> zoned_time, __time_zone_representation<_TimeZonePtrOrName>>; - -using zoned_seconds = zoned_time; - -template -_LIBCPP_HIDE_FROM_ABI bool -operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const zoned_time<_Duration2, _TimeZonePtr>& __rhs) { - return __lhs.get_time_zone() == __rhs.get_time_zone() && __lhs.get_sys_time() == __rhs.get_sys_time(); -} - -} // namespace chrono - -# if _LIBCPP_STD_VER >= 26 - -template - requires __has_enabled_hash<_Duration>::value && __has_enabled_hash<_TimeZonePtr>::value -struct hash> { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t - operator()(const chrono::zoned_time<_Duration, _TimeZonePtr>& __zt) { - return std::__hash_combine( - hash>{}(__zt.get_sys_time()), hash<_TimeZonePtr>{}(__zt.get_time_zone())); - } -}; - -# endif // _LIBCPP_STD_VER >= 26 - -# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && - // _LIBCPP_HAS_LOCALIZATION - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB - -#endif // _LIBCPP___CHRONO_ZONED_TIME_H diff --git a/third_party/libcxx/include/c++/v1/__compare/common_comparison_category.h b/third_party/libcxx/include/c++/v1/__compare/common_comparison_category.h deleted file mode 100644 index eae2ef0..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/common_comparison_category.h +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H -#define _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H - -#include <__compare/ordering.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__type_traits/is_same.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -namespace __comp_detail { - -enum _ClassifyCompCategory : unsigned { _None, _PartialOrd, _WeakOrd, _StrongOrd, _CCC_Size }; - -template -_LIBCPP_HIDE_FROM_ABI constexpr _ClassifyCompCategory __type_to_enum() noexcept { - if (is_same_v<_Tp, partial_ordering>) - return _PartialOrd; - if (is_same_v<_Tp, weak_ordering>) - return _WeakOrd; - if (is_same_v<_Tp, strong_ordering>) - return _StrongOrd; - return _None; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr _ClassifyCompCategory -__compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) { - int __seen[_CCC_Size] = {}; - for (auto __type : __types) - ++__seen[__type]; - if (__seen[_None]) - return _None; - if (__seen[_PartialOrd]) - return _PartialOrd; - if (__seen[_WeakOrd]) - return _WeakOrd; - return _StrongOrd; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() { - using _CCC = _ClassifyCompCategory; - constexpr _CCC __type_kinds[] = {_StrongOrd, __comp_detail::__type_to_enum<_Ts>()...}; - constexpr _CCC __cat = __comp_detail::__compute_comp_type(__type_kinds); - if constexpr (__cat == _None) - return void(); - else if constexpr (__cat == _PartialOrd) - return partial_ordering::equivalent; - else if constexpr (__cat == _WeakOrd) - return weak_ordering::equivalent; - else if constexpr (__cat == _StrongOrd) - return strong_ordering::equivalent; - else - static_assert(_False, "unhandled case"); -} -} // namespace __comp_detail - -// [cmp.common], common comparison category type -template -struct common_comparison_category { - using type _LIBCPP_NODEBUG = decltype(__comp_detail::__get_comp_type<_Ts...>()); -}; - -template -using common_comparison_category_t = typename common_comparison_category<_Ts...>::type; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H diff --git a/third_party/libcxx/include/c++/v1/__compare/compare_partial_order_fallback.h b/third_party/libcxx/include/c++/v1/__compare/compare_partial_order_fallback.h deleted file mode 100644 index 80f2aca..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/compare_partial_order_fallback.h +++ /dev/null @@ -1,75 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK -#define _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK - -#include <__compare/ordering.h> -#include <__compare/partial_order.h> -#include <__concepts/boolean_testable.h> -#include <__config> -#include <__type_traits/decay.h> -#include <__type_traits/is_same.h> -#include <__utility/forward.h> -#include <__utility/priority_tag.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [cmp.alg] -namespace __compare_partial_order_fallback { -struct __fn { - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept( - noexcept(std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) - -> decltype(std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) { - return std::partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)); - } - - template - requires is_same_v, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) { - { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable; - { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable; - { std::forward<_Up>(__u) < std::forward<_Tp>(__t) } -> __boolean_testable; - } - _LIBCPP_HIDE_FROM_ABI static constexpr partial_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( - noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less - : std::forward<_Up>(__u) < std::forward<_Tp>(__t) ? partial_ordering::greater - : partial_ordering::unordered)) { - return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less - : std::forward<_Up>(__u) < std::forward<_Tp>(__t) - ? partial_ordering::greater - : partial_ordering::unordered; - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const - noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()))) - -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) { - return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()); - } -}; -} // namespace __compare_partial_order_fallback - -inline namespace __cpo { -inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{}; -} // namespace __cpo - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK diff --git a/third_party/libcxx/include/c++/v1/__compare/compare_strong_order_fallback.h b/third_party/libcxx/include/c++/v1/__compare/compare_strong_order_fallback.h deleted file mode 100644 index c41a90c..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/compare_strong_order_fallback.h +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_COMPARE_STRONG_ORDER_FALLBACK -#define _LIBCPP___COMPARE_COMPARE_STRONG_ORDER_FALLBACK - -#include <__compare/ordering.h> -#include <__compare/strong_order.h> -#include <__concepts/boolean_testable.h> -#include <__config> -#include <__type_traits/decay.h> -#include <__type_traits/is_same.h> -#include <__utility/forward.h> -#include <__utility/priority_tag.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [cmp.alg] -namespace __compare_strong_order_fallback { -struct __fn { - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept( - noexcept(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) - -> decltype(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) { - return std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)); - } - - template - requires is_same_v, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) { - { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable; - { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable; - } - _LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( - noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? strong_ordering::less - : strong_ordering::greater)) { - return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) - ? strong_ordering::less - : strong_ordering::greater; - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const - noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()))) - -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) { - return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()); - } -}; -} // namespace __compare_strong_order_fallback - -inline namespace __cpo { -inline constexpr auto compare_strong_order_fallback = __compare_strong_order_fallback::__fn{}; -} // namespace __cpo - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_COMPARE_STRONG_ORDER_FALLBACK diff --git a/third_party/libcxx/include/c++/v1/__compare/compare_three_way.h b/third_party/libcxx/include/c++/v1/__compare/compare_three_way.h deleted file mode 100644 index 852c587..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/compare_three_way.h +++ /dev/null @@ -1,40 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_COMPARE_THREE_WAY_H -#define _LIBCPP___COMPARE_COMPARE_THREE_WAY_H - -#include <__compare/three_way_comparable.h> -#include <__config> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -struct compare_three_way { - template - requires three_way_comparable_with<_T1, _T2> - constexpr _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const - noexcept(noexcept(std::forward<_T1>(__t) <=> std::forward<_T2>(__u))) { - return std::forward<_T1>(__t) <=> std::forward<_T2>(__u); - } - - using is_transparent = void; -}; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_H diff --git a/third_party/libcxx/include/c++/v1/__compare/compare_three_way_result.h b/third_party/libcxx/include/c++/v1/__compare/compare_three_way_result.h deleted file mode 100644 index 264a4d6..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/compare_three_way_result.h +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H -#define _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H - -#include <__config> -#include <__type_traits/make_const_lvalue_ref.h> -#include <__utility/declval.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result {}; - -template -struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result< - _Tp, - _Up, - decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void())> { - using type _LIBCPP_NODEBUG = - decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>()); -}; - -template -struct _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> {}; - -template -using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H diff --git a/third_party/libcxx/include/c++/v1/__compare/compare_weak_order_fallback.h b/third_party/libcxx/include/c++/v1/__compare/compare_weak_order_fallback.h deleted file mode 100644 index 26689fb..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/compare_weak_order_fallback.h +++ /dev/null @@ -1,73 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK -#define _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK - -#include <__compare/ordering.h> -#include <__compare/weak_order.h> -#include <__concepts/boolean_testable.h> -#include <__config> -#include <__type_traits/decay.h> -#include <__type_traits/is_same.h> -#include <__utility/forward.h> -#include <__utility/priority_tag.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [cmp.alg] -namespace __compare_weak_order_fallback { -struct __fn { - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept( - noexcept(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) - -> decltype(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))) { - return std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)); - } - - template - requires is_same_v, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) { - { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable; - { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable; - } - _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept( - std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) - ? weak_ordering::less - : weak_ordering::greater)) { - return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) - ? weak_ordering::less - : weak_ordering::greater; - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const - noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()))) - -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>())) { - return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<1>()); - } -}; -} // namespace __compare_weak_order_fallback - -inline namespace __cpo { -inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{}; -} // namespace __cpo - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK diff --git a/third_party/libcxx/include/c++/v1/__compare/is_eq.h b/third_party/libcxx/include/c++/v1/__compare/is_eq.h deleted file mode 100644 index ee4d11b..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/is_eq.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_IS_EQ_H -#define _LIBCPP___COMPARE_IS_EQ_H - -#include <__compare/ordering.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_eq(partial_ordering __c) noexcept { return __c == 0; } -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_neq(partial_ordering __c) noexcept { return __c != 0; } -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_lt(partial_ordering __c) noexcept { return __c < 0; } -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_lteq(partial_ordering __c) noexcept { return __c <= 0; } -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_gt(partial_ordering __c) noexcept { return __c > 0; } -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_gteq(partial_ordering __c) noexcept { return __c >= 0; } - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_IS_EQ_H diff --git a/third_party/libcxx/include/c++/v1/__compare/ordering.h b/third_party/libcxx/include/c++/v1/__compare/ordering.h deleted file mode 100644 index 902ef53..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/ordering.h +++ /dev/null @@ -1,282 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_ORDERING_H -#define _LIBCPP___COMPARE_ORDERING_H - -#include <__config> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_same.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// exposition only -enum class _OrdResult : signed char { __less = -1, __equiv = 0, __greater = 1 }; - -enum class _PartialOrdResult : signed char { - __less = static_cast(_OrdResult::__less), - __equiv = static_cast(_OrdResult::__equiv), - __greater = static_cast(_OrdResult::__greater), - __unordered = -127, -}; - -class partial_ordering; -class weak_ordering; -class strong_ordering; - -struct _CmpUnspecifiedParam { - // If anything other than a literal 0 is provided, the behavior is undefined by the Standard. - // - // The alternative to the `__enable_if__` attribute would be to use the fact that a pointer - // can be constructed from literal 0, but this conflicts with `-Wzero-as-null-pointer-constant`. - template > > - _LIBCPP_HIDE_FROM_ABI consteval _CmpUnspecifiedParam(_Tp __zero) noexcept -# if __has_attribute(__enable_if__) - __attribute__((__enable_if__( - __zero == 0, "Only literal 0 is allowed as the operand of a comparison with one of the ordering types"))) -# endif - { - (void)__zero; - } -}; - -class partial_ordering { - _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_PartialOrdResult __v) noexcept : __value_(__v) {} - -public: - // valid values - static const partial_ordering less; - static const partial_ordering equivalent; - static const partial_ordering greater; - static const partial_ordering unordered; - - // comparisons - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default; - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ == _PartialOrdResult::__equiv; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ == _PartialOrdResult::__less; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__less; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ == _PartialOrdResult::__greater; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__greater; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__value_ == _PartialOrdResult::__greater; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__greater; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__value_ == _PartialOrdResult::__less; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__less; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering - operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering - operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v); - } - -private: - _PartialOrdResult __value_; -}; - -inline constexpr partial_ordering partial_ordering::less(_PartialOrdResult::__less); -inline constexpr partial_ordering partial_ordering::equivalent(_PartialOrdResult::__equiv); -inline constexpr partial_ordering partial_ordering::greater(_PartialOrdResult::__greater); -inline constexpr partial_ordering partial_ordering::unordered(_PartialOrdResult::__unordered); - -class weak_ordering { - using _ValueT _LIBCPP_NODEBUG = signed char; - - _LIBCPP_HIDE_FROM_ABI explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {} - -public: - static const weak_ordering less; - static const weak_ordering equivalent; - static const weak_ordering greater; - - _LIBCPP_HIDE_FROM_ABI constexpr operator partial_ordering() const noexcept { - return __value_ == 0 ? partial_ordering::equivalent - : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater); - } - - // comparisons - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default; - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ == 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(weak_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ < 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ <= 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(weak_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ > 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ >= 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, weak_ordering __v) noexcept { - return 0 < __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept { - return 0 <= __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, weak_ordering __v) noexcept { - return 0 > __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept { - return 0 >= __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept { - return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v); - } - -private: - _ValueT __value_; -}; - -inline constexpr weak_ordering weak_ordering::less(_OrdResult::__less); -inline constexpr weak_ordering weak_ordering::equivalent(_OrdResult::__equiv); -inline constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater); - -class strong_ordering { - using _ValueT _LIBCPP_NODEBUG = signed char; - - _LIBCPP_HIDE_FROM_ABI explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {} - -public: - static const strong_ordering less; - static const strong_ordering equal; - static const strong_ordering equivalent; - static const strong_ordering greater; - - // conversions - _LIBCPP_HIDE_FROM_ABI constexpr operator partial_ordering() const noexcept { - return __value_ == 0 ? partial_ordering::equivalent - : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater); - } - - _LIBCPP_HIDE_FROM_ABI constexpr operator weak_ordering() const noexcept { - return __value_ == 0 ? weak_ordering::equivalent : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater); - } - - // comparisons - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default; - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ == 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(strong_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ < 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ <= 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(strong_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ > 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__value_ >= 0; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, strong_ordering __v) noexcept { - return 0 < __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept { - return 0 <= __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, strong_ordering __v) noexcept { - return 0 > __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept { - return 0 >= __v.__value_; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering - operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v; - } - - _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering - operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept { - return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v); - } - -private: - _ValueT __value_; -}; - -inline constexpr strong_ordering strong_ordering::less(_OrdResult::__less); -inline constexpr strong_ordering strong_ordering::equal(_OrdResult::__equiv); -inline constexpr strong_ordering strong_ordering::equivalent(_OrdResult::__equiv); -inline constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater); - -/// [cmp.categories.pre]/1 -/// The types partial_ordering, weak_ordering, and strong_ordering are -/// collectively termed the comparison category types. -template -concept __comparison_category = - is_same_v<_Tp, partial_ordering> || is_same_v<_Tp, weak_ordering> || is_same_v<_Tp, strong_ordering>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_ORDERING_H diff --git a/third_party/libcxx/include/c++/v1/__compare/partial_order.h b/third_party/libcxx/include/c++/v1/__compare/partial_order.h deleted file mode 100644 index 1d2fae6..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/partial_order.h +++ /dev/null @@ -1,77 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_PARTIAL_ORDER -#define _LIBCPP___COMPARE_PARTIAL_ORDER - -#include <__compare/compare_three_way.h> -#include <__compare/ordering.h> -#include <__compare/weak_order.h> -#include <__config> -#include <__type_traits/decay.h> -#include <__type_traits/is_same.h> -#include <__utility/forward.h> -#include <__utility/priority_tag.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [cmp.alg] -namespace __partial_order { -void partial_order() = delete; - -struct __fn { - // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept( - noexcept(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return partial_ordering(partial_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - // NOLINTEND(libcpp-robust-against-adl) - - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept( - noexcept(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return partial_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( - noexcept(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return partial_ordering(std::weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const - noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>()))) - -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())) { - return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>()); - } -}; -} // namespace __partial_order - -inline namespace __cpo { -inline constexpr auto partial_order = __partial_order::__fn{}; -} // namespace __cpo - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_PARTIAL_ORDER diff --git a/third_party/libcxx/include/c++/v1/__compare/strong_order.h b/third_party/libcxx/include/c++/v1/__compare/strong_order.h deleted file mode 100644 index ba6de44..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/strong_order.h +++ /dev/null @@ -1,125 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_STRONG_ORDER -#define _LIBCPP___COMPARE_STRONG_ORDER - -#include <__bit/bit_cast.h> -#include <__compare/compare_three_way.h> -#include <__compare/ordering.h> -#include <__config> -#include <__math/traits.h> -#include <__type_traits/conditional.h> -#include <__type_traits/decay.h> -#include <__type_traits/is_floating_point.h> -#include <__type_traits/is_same.h> -#include <__utility/forward.h> -#include <__utility/priority_tag.h> -#include -#include - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [cmp.alg] -namespace __strong_order { -void strong_order() = delete; - -struct __fn { - // NOLINTBEGIN(libcpp-robust-against-adl) strong_order should use ADL, but only here - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept( - noexcept(strong_ordering(strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(strong_ordering(strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return strong_ordering(strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - // NOLINTEND(libcpp-robust-against-adl) - - template > - requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp> - _LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept { - if constexpr (numeric_limits<_Dp>::is_iec559 && - (sizeof(_Dp) == sizeof(int32_t) || sizeof(_Dp) == sizeof(int64_t))) { - using _IntT = conditional_t; - _IntT __rx = std::bit_cast<_IntT>(__t); - _IntT __ry = std::bit_cast<_IntT>(__u); - __rx = (__rx < 0) ? (numeric_limits<_IntT>::min() - __rx - 1) : __rx; - __ry = (__ry < 0) ? (numeric_limits<_IntT>::min() - __ry - 1) : __ry; - return (__rx <=> __ry); - } else if (__t < __u) { - return strong_ordering::less; - } else if (__t > __u) { - return strong_ordering::greater; - } else if (__t == __u) { - static_assert(numeric_limits<_Dp>::radix == 2, "floating point type with a radix other than 2?"); - return __math::signbit(__u) <=> __math::signbit(__t); - } else { - // They're unordered, so one of them must be a NAN. - // The order is -QNAN, -SNAN, numbers, +SNAN, +QNAN. - bool __t_is_nan = __math::isnan(__t); - bool __u_is_nan = __math::isnan(__u); - bool __t_is_negative = __math::signbit(__t); - bool __u_is_negative = __math::signbit(__u); - using _IntType = - conditional_t>; - if constexpr (is_same_v<_IntType, void>) { - static_assert(sizeof(_Dp) == 0, "std::strong_order is unimplemented for this floating-point type"); - } else if (__t_is_nan && __u_is_nan) { - // Order by sign bit, then by "payload bits" (we'll just use bit_cast). - if (__t_is_negative != __u_is_negative) { - return (__u_is_negative <=> __t_is_negative); - } else { - return std::bit_cast<_IntType>(__t) <=> std::bit_cast<_IntType>(__u); - } - } else if (__t_is_nan) { - return __t_is_negative ? strong_ordering::less : strong_ordering::greater; - } else { - return __u_is_negative ? strong_ordering::greater : strong_ordering::less; - } - } - } - - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( - noexcept(strong_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(strong_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return strong_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const - noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>()))) - -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>())) { - return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<2>()); - } -}; -} // namespace __strong_order - -inline namespace __cpo { -inline constexpr auto strong_order = __strong_order::__fn{}; -} // namespace __cpo - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___COMPARE_STRONG_ORDER diff --git a/third_party/libcxx/include/c++/v1/__compare/synth_three_way.h b/third_party/libcxx/include/c++/v1/__compare/synth_three_way.h deleted file mode 100644 index 63bf56d..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/synth_three_way.h +++ /dev/null @@ -1,53 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_SYNTH_THREE_WAY_H -#define _LIBCPP___COMPARE_SYNTH_THREE_WAY_H - -#include <__compare/ordering.h> -#include <__compare/three_way_comparable.h> -#include <__concepts/boolean_testable.h> -#include <__config> -#include <__utility/declval.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [expos.only.func] - -_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = [](const _Tp& __t, const _Up& __u) - requires requires { - { __t < __u } -> __boolean_testable; - { __u < __t } -> __boolean_testable; - } -{ - if constexpr (three_way_comparable_with<_Tp, _Up>) { - return __t <=> __u; - } else { - if (__t < __u) - return weak_ordering::less; - if (__u < __t) - return weak_ordering::greater; - return weak_ordering::equivalent; - } -}; - -template -using __synth_three_way_result _LIBCPP_NODEBUG = - decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>())); - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_SYNTH_THREE_WAY_H diff --git a/third_party/libcxx/include/c++/v1/__compare/three_way_comparable.h b/third_party/libcxx/include/c++/v1/__compare/three_way_comparable.h deleted file mode 100644 index ad6d05a..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/three_way_comparable.h +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H -#define _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H - -#include <__compare/common_comparison_category.h> -#include <__compare/ordering.h> -#include <__concepts/common_reference_with.h> -#include <__concepts/comparison_common_type.h> -#include <__concepts/equality_comparable.h> -#include <__concepts/same_as.h> -#include <__concepts/totally_ordered.h> -#include <__config> -#include <__type_traits/common_reference.h> -#include <__type_traits/make_const_lvalue_ref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -concept __compares_as = same_as, _Cat>; - -template -concept three_way_comparable = - __weakly_equality_comparable_with<_Tp, _Tp> && __partially_ordered_with<_Tp, _Tp> && - requires(__make_const_lvalue_ref<_Tp> __a, __make_const_lvalue_ref<_Tp> __b) { - { __a <=> __b } -> __compares_as<_Cat>; - }; - -template -concept three_way_comparable_with = - three_way_comparable<_Tp, _Cat> && three_way_comparable<_Up, _Cat> && __comparison_common_type_with<_Tp, _Up> && - three_way_comparable, __make_const_lvalue_ref<_Up>>, _Cat> && - __weakly_equality_comparable_with<_Tp, _Up> && __partially_ordered_with<_Tp, _Up> && - requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) { - { __t <=> __u } -> __compares_as<_Cat>; - { __u <=> __t } -> __compares_as<_Cat>; - }; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H diff --git a/third_party/libcxx/include/c++/v1/__compare/weak_order.h b/third_party/libcxx/include/c++/v1/__compare/weak_order.h deleted file mode 100644 index 1a3e85f..0000000 --- a/third_party/libcxx/include/c++/v1/__compare/weak_order.h +++ /dev/null @@ -1,105 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COMPARE_WEAK_ORDER -#define _LIBCPP___COMPARE_WEAK_ORDER - -#include <__compare/compare_three_way.h> -#include <__compare/ordering.h> -#include <__compare/strong_order.h> -#include <__config> -#include <__math/traits.h> -#include <__type_traits/decay.h> -#include <__type_traits/is_floating_point.h> -#include <__type_traits/is_same.h> -#include <__utility/forward.h> -#include <__utility/priority_tag.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [cmp.alg] -namespace __weak_order { -void weak_order() = delete; - -struct __fn { - // NOLINTBEGIN(libcpp-robust-against-adl) weak_order should use ADL, but only here - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<3>) noexcept( - noexcept(weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return weak_ordering(weak_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - // NOLINTEND(libcpp-robust-against-adl) - - template > - requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp> - _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept { - partial_ordering __po = (__t <=> __u); - if (__po == partial_ordering::less) { - return weak_ordering::less; - } else if (__po == partial_ordering::equivalent) { - return weak_ordering::equivalent; - } else if (__po == partial_ordering::greater) { - return weak_ordering::greater; - } else { - // Otherwise, at least one of them is a NaN. - bool __t_is_nan = __math::isnan(__t); - bool __u_is_nan = __math::isnan(__u); - bool __t_is_negative = __math::signbit(__t); - bool __u_is_negative = __math::signbit(__u); - if (__t_is_nan && __u_is_nan) { - return (__u_is_negative <=> __t_is_negative); - } else if (__t_is_nan) { - return __t_is_negative ? weak_ordering::less : weak_ordering::greater; - } else { - return __u_is_negative ? weak_ordering::greater : weak_ordering::less; - } - } - } - - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept( - noexcept(weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return weak_ordering(compare_three_way()(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - - template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( - noexcept(weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))))) - -> decltype(weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - return weak_ordering(std::strong_order(std::forward<_Tp>(__t), std::forward<_Up>(__u))); - } - - template - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const - noexcept(noexcept(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>()))) - -> decltype(__go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>())) { - return __go(std::forward<_Tp>(__t), std::forward<_Up>(__u), __priority_tag<3>()); - } -}; -} // namespace __weak_order - -inline namespace __cpo { -inline constexpr auto weak_order = __weak_order::__fn{}; -} // namespace __cpo - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___COMPARE_WEAK_ORDER diff --git a/third_party/libcxx/include/c++/v1/__concepts/arithmetic.h b/third_party/libcxx/include/c++/v1/__concepts/arithmetic.h deleted file mode 100644 index 64c0200..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/arithmetic.h +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_ARITHMETIC_H -#define _LIBCPP___CONCEPTS_ARITHMETIC_H - -#include <__config> -#include <__type_traits/is_floating_point.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_signed.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concepts.arithmetic], arithmetic concepts - -template -concept integral = is_integral_v<_Tp>; - -template -concept signed_integral = integral<_Tp> && is_signed_v<_Tp>; - -template -concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>; - -template -concept floating_point = is_floating_point_v<_Tp>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_ARITHMETIC_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/assignable.h b/third_party/libcxx/include/c++/v1/__concepts/assignable.h deleted file mode 100644 index 7423daa..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/assignable.h +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_ASSIGNABLE_H -#define _LIBCPP___CONCEPTS_ASSIGNABLE_H - -#include <__concepts/common_reference_with.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__type_traits/is_reference.h> -#include <__type_traits/make_const_lvalue_ref.h> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.assignable] - -template -concept assignable_from = - is_lvalue_reference_v<_Lhs> && - common_reference_with<__make_const_lvalue_ref<_Lhs>, __make_const_lvalue_ref<_Rhs>> && - requires(_Lhs __lhs, _Rhs&& __rhs) { - { __lhs = std::forward<_Rhs>(__rhs) } -> same_as<_Lhs>; - }; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_ASSIGNABLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/boolean_testable.h b/third_party/libcxx/include/c++/v1/__concepts/boolean_testable.h deleted file mode 100644 index b379fe9..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/boolean_testable.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H -#define _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H - -#include <__concepts/convertible_to.h> -#include <__config> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concepts.booleantestable] - -template -concept __boolean_testable_impl = convertible_to<_Tp, bool>; - -template -concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t) { - { !std::forward<_Tp>(__t) } -> __boolean_testable_impl; -}; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/class_or_enum.h b/third_party/libcxx/include/c++/v1/__concepts/class_or_enum.h deleted file mode 100644 index 9fceed0..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/class_or_enum.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H -#define _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H - -#include <__config> -#include <__type_traits/is_class.h> -#include <__type_traits/is_enum.h> -#include <__type_traits/is_union.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// Whether a type is a class type or enumeration type according to the Core wording. - -template -concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/common_reference_with.h b/third_party/libcxx/include/c++/v1/__concepts/common_reference_with.h deleted file mode 100644 index 4eb687e..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/common_reference_with.h +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H -#define _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H - -#include <__concepts/convertible_to.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__type_traits/common_reference.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.commonref] - -template -concept common_reference_with = - same_as, common_reference_t<_Up, _Tp>> && - convertible_to<_Tp, common_reference_t<_Tp, _Up>> && convertible_to<_Up, common_reference_t<_Tp, _Up>>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/common_with.h b/third_party/libcxx/include/c++/v1/__concepts/common_with.h deleted file mode 100644 index 09082b2..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/common_with.h +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_COMMON_WITH_H -#define _LIBCPP___CONCEPTS_COMMON_WITH_H - -#include <__concepts/common_reference_with.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__type_traits/add_reference.h> -#include <__type_traits/common_reference.h> -#include <__type_traits/common_type.h> -#include <__utility/declval.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.common] - -// clang-format off -template -concept common_with = - same_as, common_type_t<_Up, _Tp>> && - requires { - static_cast>(std::declval<_Tp>()); - static_cast>(std::declval<_Up>()); - } && - common_reference_with< - add_lvalue_reference_t, - add_lvalue_reference_t> && - common_reference_with< - add_lvalue_reference_t>, - common_reference_t< - add_lvalue_reference_t, - add_lvalue_reference_t>>; -// clang-format on - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_COMMON_WITH_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/comparison_common_type.h b/third_party/libcxx/include/c++/v1/__concepts/comparison_common_type.h deleted file mode 100644 index 3f0d770..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/comparison_common_type.h +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_COMPARISON_COMMON_TYPE_H -#define _LIBCPP___CONCEPTS_COMPARISON_COMMON_TYPE_H - -#include <__concepts/convertible_to.h> -#include <__concepts/same_as.h> -#include <__config> -#include <__type_traits/common_reference.h> -#include <__type_traits/remove_cvref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template > -concept __comparison_common_type_with_impl = - same_as, common_reference_t> && requires { - requires convertible_to || convertible_to<_Tp, const _CommonRef&>; - requires convertible_to || convertible_to<_Up, const _CommonRef&>; - }; - -template -concept __comparison_common_type_with = __comparison_common_type_with_impl, remove_cvref_t<_Up>>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_COMPARISON_COMMON_TYPE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/constructible.h b/third_party/libcxx/include/c++/v1/__concepts/constructible.h deleted file mode 100644 index 835a444..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/constructible.h +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H -#define _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H - -#include <__concepts/convertible_to.h> -#include <__concepts/destructible.h> -#include <__config> -#include <__type_traits/is_constructible.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.constructible] -template -concept constructible_from = destructible<_Tp> && is_constructible_v<_Tp, _Args...>; - -// [concept.default.init] - -template -concept __default_initializable = requires { ::new _Tp; }; - -template -concept default_initializable = constructible_from<_Tp> && requires { _Tp{}; } && __default_initializable<_Tp>; - -// [concept.moveconstructible] -template -concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>; - -// [concept.copyconstructible] -// clang-format off -template -concept copy_constructible = - move_constructible<_Tp> && - constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> && - constructible_from<_Tp, const _Tp&> && convertible_to && - constructible_from<_Tp, const _Tp> && convertible_to; -// clang-format on - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/convertible_to.h b/third_party/libcxx/include/c++/v1/__concepts/convertible_to.h deleted file mode 100644 index 6d5b6c1..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/convertible_to.h +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H -#define _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H - -#include <__config> -#include <__type_traits/is_convertible.h> -#include <__utility/declval.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.convertible] - -template -concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); }; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/copyable.h b/third_party/libcxx/include/c++/v1/__concepts/copyable.h deleted file mode 100644 index 2bf0ad4..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/copyable.h +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_COPYABLE_H -#define _LIBCPP___CONCEPTS_COPYABLE_H - -#include <__concepts/assignable.h> -#include <__concepts/constructible.h> -#include <__concepts/movable.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concepts.object] - -// clang-format off -template -concept copyable = - copy_constructible<_Tp> && - movable<_Tp> && - assignable_from<_Tp&, _Tp&> && - assignable_from<_Tp&, const _Tp&> && - assignable_from<_Tp&, const _Tp>; -// clang-format on - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_COPYABLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/derived_from.h b/third_party/libcxx/include/c++/v1/__concepts/derived_from.h deleted file mode 100644 index 9875fae..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/derived_from.h +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_DERIVED_FROM_H -#define _LIBCPP___CONCEPTS_DERIVED_FROM_H - -#include <__config> -#include <__type_traits/is_base_of.h> -#include <__type_traits/is_convertible.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.derived] - -template -concept derived_from = is_base_of_v<_Bp, _Dp> && is_convertible_v; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_DERIVED_FROM_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/destructible.h b/third_party/libcxx/include/c++/v1/__concepts/destructible.h deleted file mode 100644 index 28b4b1b..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/destructible.h +++ /dev/null @@ -1,32 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_DESTRUCTIBLE_H -#define _LIBCPP___CONCEPTS_DESTRUCTIBLE_H - -#include <__config> -#include <__type_traits/is_nothrow_destructible.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.destructible] - -template -concept destructible = is_nothrow_destructible_v<_Tp>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_DESTRUCTIBLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/different_from.h b/third_party/libcxx/include/c++/v1/__concepts/different_from.h deleted file mode 100644 index fd31f6e..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/different_from.h +++ /dev/null @@ -1,31 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_DIFFERENT_FROM_H -#define _LIBCPP___CONCEPTS_DIFFERENT_FROM_H - -#include <__concepts/same_as.h> -#include <__config> -#include <__type_traits/remove_cvref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -template -concept __different_from = !same_as, remove_cvref_t<_Up>>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_DIFFERENT_FROM_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/equality_comparable.h b/third_party/libcxx/include/c++/v1/__concepts/equality_comparable.h deleted file mode 100644 index 56fc6f8..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/equality_comparable.h +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H -#define _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H - -#include <__concepts/boolean_testable.h> -#include <__concepts/common_reference_with.h> -#include <__concepts/comparison_common_type.h> -#include <__config> -#include <__type_traits/common_reference.h> -#include <__type_traits/make_const_lvalue_ref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.equalitycomparable] - -template -concept __weakly_equality_comparable_with = - requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) { - { __t == __u } -> __boolean_testable; - { __t != __u } -> __boolean_testable; - { __u == __t } -> __boolean_testable; - { __u != __t } -> __boolean_testable; - }; - -template -concept equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>; - -// clang-format off -template -concept equality_comparable_with = - equality_comparable<_Tp> && equality_comparable<_Up> && - __comparison_common_type_with<_Tp, _Up> && - equality_comparable< - common_reference_t< - __make_const_lvalue_ref<_Tp>, - __make_const_lvalue_ref<_Up>>> && - __weakly_equality_comparable_with<_Tp, _Up>; -// clang-format on - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/invocable.h b/third_party/libcxx/include/c++/v1/__concepts/invocable.h deleted file mode 100644 index 8a29398..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/invocable.h +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_INVOCABLE_H -#define _LIBCPP___CONCEPTS_INVOCABLE_H - -#include <__config> -#include <__functional/invoke.h> -#include <__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.invocable] - -template -concept invocable = requires(_Fn&& __fn, _Args&&... __args) { - std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...); // not required to be equality preserving -}; - -// [concept.regular.invocable] - -template -concept regular_invocable = invocable<_Fn, _Args...>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_INVOCABLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/movable.h b/third_party/libcxx/include/c++/v1/__concepts/movable.h deleted file mode 100644 index bc5b9d7..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/movable.h +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_MOVABLE_H -#define _LIBCPP___CONCEPTS_MOVABLE_H - -#include <__concepts/assignable.h> -#include <__concepts/constructible.h> -#include <__concepts/swappable.h> -#include <__config> -#include <__type_traits/is_object.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concepts.object] - -template -concept movable = is_object_v<_Tp> && move_constructible<_Tp> && assignable_from<_Tp&, _Tp> && swappable<_Tp>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_MOVABLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/predicate.h b/third_party/libcxx/include/c++/v1/__concepts/predicate.h deleted file mode 100644 index e0263a8..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/predicate.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_PREDICATE_H -#define _LIBCPP___CONCEPTS_PREDICATE_H - -#include <__concepts/boolean_testable.h> -#include <__concepts/invocable.h> -#include <__config> -#include <__type_traits/invoke.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.predicate] - -template -concept predicate = regular_invocable<_Fn, _Args...> && __boolean_testable>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_PREDICATE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/regular.h b/third_party/libcxx/include/c++/v1/__concepts/regular.h deleted file mode 100644 index 9f3d8bf..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/regular.h +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_REGULAR_H -#define _LIBCPP___CONCEPTS_REGULAR_H - -#include <__concepts/equality_comparable.h> -#include <__concepts/semiregular.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.object] - -template -concept regular = semiregular<_Tp> && equality_comparable<_Tp>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_REGULAR_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/relation.h b/third_party/libcxx/include/c++/v1/__concepts/relation.h deleted file mode 100644 index 7545a7d..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/relation.h +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_RELATION_H -#define _LIBCPP___CONCEPTS_RELATION_H - -#include <__concepts/predicate.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.relation] - -template -concept relation = - predicate<_Rp, _Tp, _Tp> && predicate<_Rp, _Up, _Up> && predicate<_Rp, _Tp, _Up> && predicate<_Rp, _Up, _Tp>; - -// [concept.equiv] - -template -concept equivalence_relation = relation<_Rp, _Tp, _Up>; - -// [concept.strictweakorder] - -template -concept strict_weak_order = relation<_Rp, _Tp, _Up>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_RELATION_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/same_as.h b/third_party/libcxx/include/c++/v1/__concepts/same_as.h deleted file mode 100644 index 4241131..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/same_as.h +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_SAME_AS_H -#define _LIBCPP___CONCEPTS_SAME_AS_H - -#include <__config> -#include <__type_traits/is_same.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.same] - -template -concept __same_as_impl = _IsSame<_Tp, _Up>::value; - -template -concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_SAME_AS_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/semiregular.h b/third_party/libcxx/include/c++/v1/__concepts/semiregular.h deleted file mode 100644 index 7a159d1..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/semiregular.h +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_SEMIREGULAR_H -#define _LIBCPP___CONCEPTS_SEMIREGULAR_H - -#include <__concepts/constructible.h> -#include <__concepts/copyable.h> -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.object] - -template -concept semiregular = copyable<_Tp> && default_initializable<_Tp>; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_SEMIREGULAR_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/swappable.h b/third_party/libcxx/include/c++/v1/__concepts/swappable.h deleted file mode 100644 index c691d3a..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/swappable.h +++ /dev/null @@ -1,122 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_SWAPPABLE_H -#define _LIBCPP___CONCEPTS_SWAPPABLE_H - -#include <__concepts/assignable.h> -#include <__concepts/class_or_enum.h> -#include <__concepts/common_reference_with.h> -#include <__concepts/constructible.h> -#include <__config> -#include <__cstddef/size_t.h> -#include <__type_traits/extent.h> -#include <__type_traits/is_nothrow_assignable.h> -#include <__type_traits/is_nothrow_constructible.h> -#include <__type_traits/remove_cvref.h> -#include <__utility/exchange.h> -#include <__utility/forward.h> -#include <__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.swappable] - -namespace ranges { -namespace __swap { - -template -void swap(_Tp&, _Tp&) = delete; - -// clang-format off -template -concept __unqualified_swappable_with = - (__class_or_enum> || __class_or_enum>) && - requires(_Tp&& __t, _Up&& __u) { - swap(std::forward<_Tp>(__t), std::forward<_Up>(__u)); - }; -// clang-format on - -struct __fn; - -// clang-format off -template -concept __swappable_arrays = - !__unqualified_swappable_with<_Tp (&)[_Size], _Up (&)[_Size]> && - extent_v<_Tp> == extent_v<_Up> && - requires(_Tp (&__t)[_Size], _Up (&__u)[_Size], const __fn& __swap) { - __swap(__t[0], __u[0]); - }; -// clang-format on - -template -concept __exchangeable = - !__unqualified_swappable_with<_Tp&, _Tp&> && move_constructible<_Tp> && assignable_from<_Tp&, _Tp>; - -struct __fn { - // 2.1 `S` is `(void)swap(E1, E2)`* if `E1` or `E2` has class or enumeration type and... - // *The name `swap` is used here unqualified. - template - requires __unqualified_swappable_with<_Tp, _Up> - _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Tp&& __t, _Up&& __u) const - noexcept(noexcept(swap(std::forward<_Tp>(__t), std::forward<_Up>(__u)))) { - swap(std::forward<_Tp>(__t), std::forward<_Up>(__u)); - } - - // 2.2 Otherwise, if `E1` and `E2` are lvalues of array types with equal extent and... - template - requires __swappable_arrays<_Tp, _Up, _Size> - _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Tp (&__t)[_Size], _Up (&__u)[_Size]) const - noexcept(noexcept((*this)(*__t, *__u))) { - // TODO(cjdb): replace with `ranges::swap_ranges`. - for (size_t __i = 0; __i < _Size; ++__i) { - (*this)(__t[__i], __u[__i]); - } - } - - // 2.3 Otherwise, if `E1` and `E2` are lvalues of the same type `T` that models... - template <__exchangeable _Tp> - _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Tp& __x, _Tp& __y) const - noexcept(is_nothrow_move_constructible_v<_Tp> && is_nothrow_move_assignable_v<_Tp>) { - __y = std::exchange(__x, std::move(__y)); - } -}; -} // namespace __swap - -inline namespace __cpo { -inline constexpr auto swap = __swap::__fn{}; -} // namespace __cpo -} // namespace ranges - -template -concept swappable = requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); }; - -template -concept swappable_with = common_reference_with<_Tp, _Up> && requires(_Tp&& __t, _Up&& __u) { - ranges::swap(std::forward<_Tp>(__t), std::forward<_Tp>(__t)); - ranges::swap(std::forward<_Up>(__u), std::forward<_Up>(__u)); - ranges::swap(std::forward<_Tp>(__t), std::forward<_Up>(__u)); - ranges::swap(std::forward<_Up>(__u), std::forward<_Tp>(__t)); -}; - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CONCEPTS_SWAPPABLE_H diff --git a/third_party/libcxx/include/c++/v1/__concepts/totally_ordered.h b/third_party/libcxx/include/c++/v1/__concepts/totally_ordered.h deleted file mode 100644 index 186c3b4..0000000 --- a/third_party/libcxx/include/c++/v1/__concepts/totally_ordered.h +++ /dev/null @@ -1,59 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H -#define _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H - -#include <__concepts/boolean_testable.h> -#include <__concepts/equality_comparable.h> -#include <__config> -#include <__type_traits/common_reference.h> -#include <__type_traits/make_const_lvalue_ref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_STD_VER >= 20 - -// [concept.totallyordered] - -template -concept __partially_ordered_with = requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) { - { __t < __u } -> __boolean_testable; - { __t > __u } -> __boolean_testable; - { __t <= __u } -> __boolean_testable; - { __t >= __u } -> __boolean_testable; - { __u < __t } -> __boolean_testable; - { __u > __t } -> __boolean_testable; - { __u <= __t } -> __boolean_testable; - { __u >= __t } -> __boolean_testable; -}; - -template -concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>; - -// clang-format off -template -concept totally_ordered_with = - totally_ordered<_Tp> && totally_ordered<_Up> && - equality_comparable_with<_Tp, _Up> && - totally_ordered< - common_reference_t< - __make_const_lvalue_ref<_Tp>, - __make_const_lvalue_ref<_Up>>> && - __partially_ordered_with<_Tp, _Up>; -// clang-format on - -#endif // _LIBCPP_STD_VER >= 20 - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H diff --git a/third_party/libcxx/include/c++/v1/__condition_variable/condition_variable.h b/third_party/libcxx/include/c++/v1/__condition_variable/condition_variable.h deleted file mode 100644 index b715193..0000000 --- a/third_party/libcxx/include/c++/v1/__condition_variable/condition_variable.h +++ /dev/null @@ -1,232 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONDITION_VARIABLE_CONDITION_VARIABLE_H -#define _LIBCPP___CONDITION_VARIABLE_CONDITION_VARIABLE_H - -#include <__chrono/duration.h> -#include <__chrono/steady_clock.h> -#include <__chrono/system_clock.h> -#include <__chrono/time_point.h> -#include <__config> -#include <__mutex/mutex.h> -#include <__mutex/unique_lock.h> -#include <__system_error/throw_system_error.h> -#include <__thread/support.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_floating_point.h> -#include <__utility/move.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if _LIBCPP_HAS_THREADS - -// enum class cv_status -_LIBCPP_DECLARE_STRONG_ENUM(cv_status){no_timeout, timeout}; -_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status) - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d) { - using namespace chrono; - using __ratio = ratio_divide<_Period, nano>; - using __ns_rep = nanoseconds::rep; - _Rep __result_float = __d.count() * __ratio::num / __ratio::den; - - _Rep __result_max = numeric_limits<__ns_rep>::max(); - if (__result_float >= __result_max) { - return nanoseconds::max(); - } - - _Rep __result_min = numeric_limits<__ns_rep>::min(); - if (__result_float <= __result_min) { - return nanoseconds::min(); - } - - return nanoseconds(static_cast<__ns_rep>(__result_float)); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d) { - using namespace chrono; - if (__d.count() == 0) { - return nanoseconds(0); - } - - using __ratio = ratio_divide<_Period, nano>; - using __ns_rep = nanoseconds::rep; - __ns_rep __result_max = numeric_limits<__ns_rep>::max(); - if (__d.count() > 0 && __d.count() > __result_max / __ratio::num) { - return nanoseconds::max(); - } - - __ns_rep __result_min = numeric_limits<__ns_rep>::min(); - if (__d.count() < 0 && __d.count() < __result_min / __ratio::num) { - return nanoseconds::min(); - } - - __ns_rep __result = __d.count() * __ratio::num / __ratio::den; - if (__result == 0) { - return nanoseconds(1); - } - - return nanoseconds(__result); -} - -class _LIBCPP_EXPORTED_FROM_ABI condition_variable { - __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; - -public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default; - -# if _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION - ~condition_variable() = default; -# else - ~condition_variable(); -# endif - - condition_variable(const condition_variable&) = delete; - condition_variable& operator=(const condition_variable&) = delete; - - void notify_one() _NOEXCEPT; - void notify_all() _NOEXCEPT; - - void wait(unique_lock& __lk) _NOEXCEPT; - - template - _LIBCPP_HIDE_FROM_ABI void wait(unique_lock& __lk, _Predicate __pred) { - while (!__pred()) - wait(__lk); - } - - template - _LIBCPP_HIDE_FROM_ABI cv_status - wait_until(unique_lock& __lk, const chrono::time_point<_Clock, _Duration>& __t) { - using namespace chrono; - using __clock_tp_ns = time_point<_Clock, nanoseconds>; - - typename _Clock::time_point __now = _Clock::now(); - if (__t <= __now) - return cv_status::timeout; - - __clock_tp_ns __t_ns = __clock_tp_ns(std::__safe_nanosecond_cast(__t.time_since_epoch())); - - __do_timed_wait(__lk, __t_ns); - return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout; - } - - template - _LIBCPP_HIDE_FROM_ABI bool - wait_until(unique_lock& __lk, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred) { - while (!__pred()) { - if (wait_until(__lk, __t) == cv_status::timeout) - return __pred(); - } - return true; - } - - template - _LIBCPP_HIDE_FROM_ABI cv_status wait_for(unique_lock& __lk, const chrono::duration<_Rep, _Period>& __d) { - using namespace chrono; - if (__d <= __d.zero()) - return cv_status::timeout; - using __ns_rep = nanoseconds::rep; - steady_clock::time_point __c_now = steady_clock::now(); - -# if _LIBCPP_HAS_COND_CLOCKWAIT - using __clock_tp_ns = time_point; - __ns_rep __now_count_ns = std::__safe_nanosecond_cast(__c_now.time_since_epoch()).count(); -# else - using __clock_tp_ns = time_point; - __ns_rep __now_count_ns = std::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count(); -# endif - - __ns_rep __d_ns_count = std::__safe_nanosecond_cast(__d).count(); - - if (__now_count_ns > numeric_limits<__ns_rep>::max() - __d_ns_count) { - __do_timed_wait(__lk, __clock_tp_ns::max()); - } else { - __do_timed_wait(__lk, __clock_tp_ns(nanoseconds(__now_count_ns + __d_ns_count))); - } - - return steady_clock::now() - __c_now < __d ? cv_status::no_timeout : cv_status::timeout; - } - - template - bool _LIBCPP_HIDE_FROM_ABI - wait_for(unique_lock& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred); - - typedef __libcpp_condvar_t* native_handle_type; - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__cv_; } - -private: - void - __do_timed_wait(unique_lock& __lk, chrono::time_point) _NOEXCEPT; -# if _LIBCPP_HAS_COND_CLOCKWAIT - _LIBCPP_HIDE_FROM_ABI void - __do_timed_wait(unique_lock& __lk, chrono::time_point) _NOEXCEPT; -# endif - template - _LIBCPP_HIDE_FROM_ABI void - __do_timed_wait(unique_lock& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT; -}; -#endif // _LIBCPP_HAS_THREADS - -#if _LIBCPP_HAS_THREADS - -template -inline bool -condition_variable::wait_for(unique_lock& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred) { - return wait_until(__lk, chrono::steady_clock::now() + __d, std::move(__pred)); -} - -# if _LIBCPP_HAS_COND_CLOCKWAIT -inline void condition_variable::__do_timed_wait( - unique_lock& __lk, chrono::time_point __tp) _NOEXCEPT { - using namespace chrono; - if (!__lk.owns_lock()) - std::__throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked"); - nanoseconds __d = __tp.time_since_epoch(); - timespec __ts; - seconds __s = duration_cast(__d); - using __ts_sec = decltype(__ts.tv_sec); - const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max(); - if (__s.count() < __ts_sec_max) { - __ts.tv_sec = static_cast<__ts_sec>(__s.count()); - __ts.tv_nsec = (__d - __s).count(); - } else { - __ts.tv_sec = __ts_sec_max; - __ts.tv_nsec = giga::num - 1; - } - int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts); - if (__ec != 0 && __ec != ETIMEDOUT) - std::__throw_system_error(__ec, "condition_variable timed_wait failed"); -} -# endif // _LIBCPP_HAS_COND_CLOCKWAIT - -template -inline void condition_variable::__do_timed_wait(unique_lock& __lk, - chrono::time_point<_Clock, chrono::nanoseconds> __tp) _NOEXCEPT { - wait_for(__lk, __tp - _Clock::now()); -} - -#endif // _LIBCPP_HAS_THREADS - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CONDITION_VARIABLE_CONDITION_VARIABLE_H diff --git a/third_party/libcxx/include/c++/v1/__config b/third_party/libcxx/include/c++/v1/__config deleted file mode 100644 index 942b0a9..0000000 --- a/third_party/libcxx/include/c++/v1/__config +++ /dev/null @@ -1,612 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIG -#define _LIBCPP___CONFIG - -#include <__config_site> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#ifdef __cplusplus - -# include <__configuration/abi.h> -# include <__configuration/attributes.h> -# include <__configuration/availability.h> -# include <__configuration/compiler.h> -# include <__configuration/experimental.h> -# include <__configuration/hardening.h> -# include <__configuration/language.h> -# include <__configuration/platform.h> - -// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html - -// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. -// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is -// defined to XXYYZZ. -# define _LIBCPP_VERSION 230000 - -# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y -# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) -# define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z)) - -# define _LIBCPP_TOSTRING2(x) #x -# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) - -# ifndef __has_constexpr_builtin -# define __has_constexpr_builtin(x) 0 -# endif - -// This checks wheter a Clang module is built -# ifndef __building_module -# define __building_module(...) 0 -# endif - -// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by -// the compiler and '1' otherwise. -# ifndef __is_identifier -# define __is_identifier(__x) 1 -# endif - -# define __has_keyword(__x) !(__is_identifier(__x)) - -# ifndef __has_warning -# define __has_warning(...) 0 -# endif - -# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L -# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" -# endif - -# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) -# define _LIBCPP_ABI_VCRUNTIME -# endif - -# if defined(__MVS__) -# include // for __NATIVE_ASCII_F -# endif - -# if defined(_WIN32) -# define _LIBCPP_WIN32API -# define _LIBCPP_SHORT_WCHAR 1 -// Both MinGW and native MSVC provide a "MSVC"-like environment -# define _LIBCPP_MSVCRT_LIKE -// If mingw not explicitly detected, assume using MS C runtime only if -// a MS compatibility version is specified. -# if defined(_MSC_VER) && !defined(__MINGW32__) -# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library -# endif -# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) -# define _LIBCPP_HAS_BITSCAN64 1 -# else -# define _LIBCPP_HAS_BITSCAN64 0 -# endif -# define _LIBCPP_HAS_OPEN_WITH_WCHAR 1 -# else -# define _LIBCPP_HAS_OPEN_WITH_WCHAR 0 -# define _LIBCPP_HAS_BITSCAN64 0 -# endif // defined(_WIN32) - -# if defined(_AIX) && !defined(__64BIT__) -// The size of wchar is 2 byte on 32-bit mode on AIX. -# define _LIBCPP_SHORT_WCHAR 1 -# endif - -// Libc++ supports various implementations of std::random_device. -// -// _LIBCPP_USING_DEV_RANDOM -// Read entropy from the given file, by default `/dev/urandom`. -// If a token is provided, it is assumed to be the path to a file -// to read entropy from. This is the default behavior if nothing -// else is specified. This implementation requires storing state -// inside `std::random_device`. -// -// _LIBCPP_USING_ARC4_RANDOM -// Use arc4random(). This allows obtaining random data even when -// using sandboxing mechanisms. On some platforms like Apple, this -// is the recommended source of entropy for user-space programs. -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -// -// _LIBCPP_USING_GETENTROPY -// Use getentropy(). -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -// -// _LIBCPP_USING_FUCHSIA_CPRNG -// Use Fuchsia's zx_cprng_draw() system call, which is specified to -// deliver high-quality entropy and cannot fail. -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -// -// _LIBCPP_USING_WIN32_RANDOM -// Use rand_s(), for use on Windows. -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ - defined(__DragonFly__) -# define _LIBCPP_USING_ARC4_RANDOM -# elif defined(__wasi__) || defined(__EMSCRIPTEN__) -# define _LIBCPP_USING_GETENTROPY -# elif defined(__Fuchsia__) -# define _LIBCPP_USING_FUCHSIA_CPRNG -# elif defined(_LIBCPP_WIN32API) -# define _LIBCPP_USING_WIN32_RANDOM -# else -# define _LIBCPP_USING_DEV_RANDOM -# endif - -# ifndef _LIBCPP_CXX03_LANG - -# define _LIBCPP_ALIGNOF(...) alignof(__VA_ARGS__) -# define _ALIGNAS_TYPE(x) alignas(x) -# define _ALIGNAS(x) alignas(x) -# define _NOEXCEPT noexcept -# define _NOEXCEPT_(...) noexcept(__VA_ARGS__) -# define _LIBCPP_CONSTEXPR constexpr - -# else - -# define _LIBCPP_ALIGNOF(...) _Alignof(__VA_ARGS__) -# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) -# define _ALIGNAS(x) __attribute__((__aligned__(x))) -# define nullptr __nullptr -# define _NOEXCEPT throw() -# define _NOEXCEPT_(...) -# define static_assert(...) _Static_assert(__VA_ARGS__) -# define decltype(...) __decltype(__VA_ARGS__) -# define _LIBCPP_CONSTEXPR - -typedef __char16_t char16_t; -typedef __char32_t char32_t; - -# endif - -# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) - -# if __has_extension(blocks) && defined(__APPLE__) -# define _LIBCPP_HAS_BLOCKS_RUNTIME 1 -# else -# define _LIBCPP_HAS_BLOCKS_RUNTIME 0 -# endif - -# ifdef _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") -# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) -# elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") -# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) -# else -# define _LIBCPP_DIAGNOSTIC_PUSH -# define _LIBCPP_DIAGNOSTIC_POP -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) -# endif - -// Macros to enter and leave a state where deprecation warnings are suppressed. -# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ - _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") -# define _LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_DIAGNOSTIC_POP - -// Clang modules take a significant compile time hit when pushing and popping diagnostics. -// Since all the headers are marked as system headers unless _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER is defined, we can -// simply disable this pushing and popping when _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER isn't defined. -# ifdef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ - _LIBCPP_DIAGNOSTIC_PUSH \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") -# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP -# else -# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS -# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS -# endif - -// clang-format off - -// The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There -// are two main categories where that's the case: -// - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++ -// and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore. -// - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know -// their mangling without the appropriate declaration in some cases. -// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned -// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used. -# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \ - _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std { - -# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS - -# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE { -# define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD - -// TODO: This should really be in the versioned namespace -#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental { -#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD - -#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { -#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL - -#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { -#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL - -#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE -# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { -# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD -#else -# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ - inline namespace __fs { namespace filesystem { - -# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD -#endif - -// clang-format on - -# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) -# define _LIBCPP_HAS_INT128 0 -# else -# define _LIBCPP_HAS_INT128 1 -# endif - -# ifdef _LIBCPP_CXX03_LANG -# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ - struct _LIBCPP_EXPORTED_FROM_ABI x { \ - enum __lx -// clang-format off -# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ - __lx __v_; \ - _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ - _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ - _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ - }; -// clang-format on - -# else // _LIBCPP_CXX03_LANG -# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x -# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) -# endif // _LIBCPP_CXX03_LANG - -# ifdef __FreeBSD__ -# define _DECLARE_C99_LDBL_MATH 1 -# endif - -// If we are getting operator new from the MSVC CRT, then allocation overloads -// for align_val_t were added in 19.12, aka VS 2017 version 15.3. -# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 -# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 -# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) -// We're deferring to Microsoft's STL to provide aligned new et al. We don't -// have it unless the language feature test macro is defined. -# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 -# elif defined(__MVS__) -# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 -# else -# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1 -# endif - -# if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) -# define _LIBCPP_HAS_ALIGNED_ALLOCATION 0 -# else -# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1 -# endif - -# if defined(__APPLE__) || defined(__FreeBSD__) -# define _LIBCPP_WCTYPE_IS_MASK -# endif - -// FIXME: using `#warning` causes diagnostics from system headers which include deprecated headers. This can only be -// enabled again once https://github.com/llvm/llvm-project/pull/168041 (or a similar feature) has landed, since that -// allows suppression in system headers. -# if defined(__DEPRECATED) && __DEPRECATED && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && 0 -# define _LIBCPP_DIAGNOSE_DEPRECATED_HEADERS 1 -# else -# define _LIBCPP_DIAGNOSE_DEPRECATED_HEADERS 0 -# endif - -# if _LIBCPP_STD_VER <= 11 -# define _LIBCPP_EXPLICIT_SINCE_CXX14 -# else -# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit -# endif - -# if _LIBCPP_STD_VER >= 23 -# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit -# else -# define _LIBCPP_EXPLICIT_SINCE_CXX23 -# endif - -# if _LIBCPP_STD_VER >= 14 -# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX14 -# endif - -# if _LIBCPP_STD_VER >= 17 -# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX17 -# endif - -# if _LIBCPP_STD_VER >= 20 -# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX20 -# endif - -# if _LIBCPP_STD_VER >= 23 -# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX23 -# endif - -# if _LIBCPP_STD_VER >= 26 -# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr -# else -# define _LIBCPP_CONSTEXPR_SINCE_CXX26 -# endif - -// Thread API -// clang-format off -# if _LIBCPP_HAS_THREADS && \ - !_LIBCPP_HAS_THREAD_API_PTHREAD && \ - !_LIBCPP_HAS_THREAD_API_WIN32 && \ - !_LIBCPP_HAS_THREAD_API_EXTERNAL && \ - !_LIBCPP_HAS_THREAD_API_C11 - -# if defined(__FreeBSD__) || \ - defined(__wasi__) || \ - defined(__NetBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NuttX__) || \ - defined(__linux__) || \ - defined(__GNU__) || \ - defined(__APPLE__) || \ - defined(__MVS__) || \ - defined(_AIX) || \ - defined(__EMSCRIPTEN__) -// clang-format on -# undef _LIBCPP_HAS_THREAD_API_PTHREAD -# define _LIBCPP_HAS_THREAD_API_PTHREAD 1 -# elif defined(__Fuchsia__) -// TODO(44575): Switch to C11 thread API when possible. -# undef _LIBCPP_HAS_THREAD_API_PTHREAD -# define _LIBCPP_HAS_THREAD_API_PTHREAD 1 -# elif defined(_LIBCPP_WIN32API) -# undef _LIBCPP_HAS_THREAD_API_WIN32 -# define _LIBCPP_HAS_THREAD_API_WIN32 1 -# else -# error "No thread API" -# endif // _LIBCPP_HAS_THREAD_API -# endif // _LIBCPP_HAS_THREADS - -# if !_LIBCPP_HAS_THREAD_API_PTHREAD -# define _LIBCPP_HAS_COND_CLOCKWAIT 0 -# elif (defined(__ANDROID__) && __ANDROID_API__ >= 30) || _LIBCPP_GLIBC_PREREQ(2, 30) -# define _LIBCPP_HAS_COND_CLOCKWAIT 1 -# else -# define _LIBCPP_HAS_COND_CLOCKWAIT 0 -# endif - -# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD -# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true. -# endif - -# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL -# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true. -# endif - -# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_C11 -# error _LIBCPP_HAS_THREAD_API_C11 may only be true when _LIBCPP_HAS_THREADS is true. -# endif - -# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS -# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false. -# endif - -# if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__) -# define __STDCPP_THREADS__ 1 -# endif - -// The glibc and Bionic implementation of pthreads implements -// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 -// mutexes have no destroy mechanism. -// -// This optimization can't be performed on Apple platforms, where -// pthread_mutex_destroy can allow the kernel to release resources. -// See https://llvm.org/D64298 for details. -// -// TODO(EricWF): Enable this optimization on Bionic after speaking to their -// respective stakeholders. -// clang-format off -# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \ - (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \ - _LIBCPP_HAS_THREAD_API_WIN32 -// clang-format on -# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1 -# else -# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0 -# endif - -// Destroying a condvar is a nop on Windows. -// -// This optimization can't be performed on Apple platforms, where -// pthread_cond_destroy can allow the kernel to release resources. -// See https://llvm.org/D64298 for details. -// -// TODO(EricWF): This is potentially true for some pthread implementations -// as well. -# if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32 -# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1 -# else -# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0 -# endif - -# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ - _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC -# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE -# endif - -# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) -# define _LIBCPP_HAS_C_ATOMIC_IMP 1 -# define _LIBCPP_HAS_GCC_ATOMIC_IMP 0 -# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 -# elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_HAS_C_ATOMIC_IMP 0 -# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1 -# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 -# endif - -# if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP -# define _LIBCPP_HAS_ATOMIC_HEADER 0 -# else -# define _LIBCPP_HAS_ATOMIC_HEADER 1 -# ifndef _LIBCPP_ATOMIC_FLAG_TYPE -# define _LIBCPP_ATOMIC_FLAG_TYPE bool -# endif -# endif - -// We often repeat things just for handling wide characters in the library. -// When wide characters are disabled, it can be useful to have a quick way of -// disabling it without having to resort to #if-#endif, which has a larger -// impact on readability. -# if !_LIBCPP_HAS_WIDE_CHARACTERS -# define _LIBCPP_IF_WIDE_CHARACTERS(...) -# else -# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ -# endif - -// clang-format off -# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")") -# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")") -// clang-format on - -# ifndef _LIBCPP_NO_AUTO_LINK -# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# pragma comment(lib, "c++.lib") -# else -# pragma comment(lib, "libc++.lib") -# endif -# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) -# endif // _LIBCPP_NO_AUTO_LINK - -// Configures the fopen close-on-exec mode character, if any. This string will -// be appended to any mode string used by fstream for fopen/fdopen. -// -// Not all platforms support this, but it helps avoid fd-leaks on platforms that -// do. -# if defined(__BIONIC__) -# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" -# else -# define _LIBCPP_FOPEN_CLOEXEC_MODE -# endif - -// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these -// functions is gradually being added to existing C libraries. The conditions -// below check for known C library versions and conditions under which these -// functions are declared by the C library. -// -// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if -// __cpp_char8_t is defined or if C2X extensions are enabled. Determining -// the latter depends on internal GNU libc details that are not appropriate -// to depend on here, so any declarations present when __cpp_char8_t is not -// defined are ignored. -# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) -# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 -# else -# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 -# endif - -// There are a handful of public standard library types that are intended to -// support CTAD but don't need any explicit deduction guides to do so. This -// macro is used to mark them as such, which suppresses the -// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code -// with these classes. -# if _LIBCPP_STD_VER >= 17 -# ifdef _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ - template \ - [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> -# else -# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ - template \ - ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> -# endif -# else -# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") -# endif - -# if defined(__OBJC__) && defined(_LIBCPP_APPLE_CLANG_VER) -# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS -# endif - -# define _PSTL_PRAGMA(x) _Pragma(#x) - -// Enable SIMD for compilers that support OpenMP 4.0 -# if (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_UDR_PRESENT -# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) -# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) - -// Declaration of reduction functor, where -// NAME - the name of the functor -// OP - type of the callable object with the reduction operation -// omp_in - refers to the local partial result -// omp_out - refers to the final value of the combiner operator -// omp_priv - refers to the private copy of the initial value -// omp_orig - refers to the original variable to be reduced -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ - _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) - -# elif defined(_LIBCPP_COMPILER_CLANG_BASED) - -# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_DECLARE_SIMD -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) - -# else // (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_PRAGMA_SIMD -# define _PSTL_PRAGMA_DECLARE_SIMD -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) - -# endif // (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED - -#endif // __cplusplus - -#endif // _LIBCPP___CONFIG diff --git a/third_party/libcxx/include/c++/v1/__configuration/abi.h b/third_party/libcxx/include/c++/v1/__configuration/abi.h deleted file mode 100644 index 5ce040f..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/abi.h +++ /dev/null @@ -1,142 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_ABI_H -#define _LIBCPP___CONFIGURATION_ABI_H - -#include <__config_site> -#include <__configuration/compiler.h> -#include <__configuration/platform.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -// FIXME: ABI detection should be done via compiler builtin macros. This -// is just a placeholder until Clang implements such macros. For now assume -// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, -// and allow the user to explicitly specify the ABI to handle cases where this -// heuristic falls short. -#if _LIBCPP_ABI_FORCE_ITANIUM && _LIBCPP_ABI_FORCE_MICROSOFT -# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be true" -#elif _LIBCPP_ABI_FORCE_ITANIUM -# define _LIBCPP_ABI_ITANIUM -#elif _LIBCPP_ABI_FORCE_MICROSOFT -# define _LIBCPP_ABI_MICROSOFT -#else -// Windows uses the Microsoft ABI -# if defined(_WIN32) && defined(_MSC_VER) -# define _LIBCPP_ABI_MICROSOFT - -// 32-bit ARM uses the Itanium ABI with a few differences (array cookies, etc), -// and so does 64-bit ARM on Apple platforms. -# elif defined(__arm__) || (defined(__APPLE__) && defined(__aarch64__)) -# define _LIBCPP_ABI_ITANIUM_WITH_ARM_DIFFERENCES - -// Non-Apple 64-bit ARM uses the vanilla Itanium ABI -# elif defined(__aarch64__) -# define _LIBCPP_ABI_ITANIUM - -// We assume that other architectures also use the vanilla Itanium ABI too -# else -# define _LIBCPP_ABI_ITANIUM -# endif -#endif - -#if _LIBCPP_ABI_VERSION >= 2 -// TODO: Move the description of the remaining ABI flags to ABIGuarantees.rst or remove them. - -// Override the default return value of exception::what() for bad_function_call::what() -// with a string that is specific to bad_function_call (see http://wg21.link/LWG2233). -// This is an ABI break on platforms that sign and authenticate vtable function pointers -// because it changes the mangling of the virtual function located in the vtable, which -// changes how it gets signed. -# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE -// According to the Standard, `bitset::operator[] const` returns bool -# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL - -// These flags are documented in ABIGuarantees.rst -# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT -# define _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE -# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI -# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI -# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION -# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE -# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE -# define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE -# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING -# define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE -# define _LIBCPP_ABI_NO_ITERATOR_BASES -# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT -# define _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER -# define _LIBCPP_ABI_OPTIMIZED_FUNCTION -# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO -# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION -# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY -# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW -# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION -# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR - -#elif _LIBCPP_ABI_VERSION == 1 -// Feature macros for disabling pre ABI v1 features. All of these options -// are deprecated. -# if defined(__FreeBSD__) -# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR -# endif -#endif - -// TODO(LLVM 22): Remove this check -#if defined(_LIBCPP_ABI_NO_ITERATOR_BASES) && !defined(_LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER) -# ifndef _LIBCPP_ONLY_NO_ITERATOR_BASES -# error "You probably want to define _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER. This has been split out from" \ - " _LIBCPP_ABI_NO_ITERATOR_BASES to allow only removing the second iterator member, since they aren't really related." \ - "If you actually want this ABI configuration, please define _LIBCPP_ONLY_NO_ITERATOR_BASES instead." -# endif -#endif - -// We had some bugs where we use [[no_unique_address]] together with construct_at, -// which causes UB as the call on construct_at could write to overlapping subobjects -// -// https://llvm.org/PR70506 -// https://llvm.org/PR70494 -// -// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. -// The macro below is used for all classes whose ABI have changed as part of fixing these bugs. -#define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua"))) - -// [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work. -#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING) -# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING -#endif - -// Tracks the bounds of the array owned by std::unique_ptr, allowing it to trap when accessed out-of-bounds. -// Note that limited bounds checking is also available outside of this ABI configuration, but only some categories -// of types can be checked. -// -// ABI impact: This causes the layout of std::unique_ptr to change and its size to increase. -// This also affects the representation of a few library types that use std::unique_ptr -// internally, such as the unordered containers. -// #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR - -#if defined(_LIBCPP_COMPILER_CLANG_BASED) -# if defined(__APPLE__) -# if defined(__i386__) || defined(__x86_64__) -// use old string layout on x86_64 and i386 -# elif defined(__arm__) -// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs -# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 -# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT -# endif -# else -# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT -# endif -# endif -#endif - -#endif // _LIBCPP___CONFIGURATION_ABI_H diff --git a/third_party/libcxx/include/c++/v1/__configuration/attributes.h b/third_party/libcxx/include/c++/v1/__configuration/attributes.h deleted file mode 100644 index 39683b7..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/attributes.h +++ /dev/null @@ -1,466 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_ATTRIBUTES_H -#define _LIBCPP___CONFIGURATION_ATTRIBUTES_H - -#include <__config_site> -#include <__configuration/hardening.h> -#include <__configuration/language.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#ifndef __has_declspec_attribute -# define __has_declspec_attribute(__x) 0 -#endif - -// Attributes relevant for layout ABI -// ---------------------------------- - -#if __has_cpp_attribute(msvc::no_unique_address) -// MSVC implements [[no_unique_address]] as a silent no-op currently. -// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) -// However, MSVC implements [[msvc::no_unique_address]] which does what -// [[no_unique_address]] is supposed to do, in general. -# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -#else -# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] -#endif - -#define _LIBCPP_PACKED __attribute__((__packed__)) - -// Attributes affecting overload resolution -// ---------------------------------------- - -#if __has_attribute(__enable_if__) -# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) -#endif - -// Visibility attributes -// --------------------- - -#if defined(_LIBCPP_OBJECT_FORMAT_COFF) - -# ifdef _DLL -# define _LIBCPP_CRT_FUNC __declspec(dllimport) -# else -# define _LIBCPP_CRT_FUNC -# endif - -# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_EXPORTED_FROM_ABI -# elif defined(_LIBCPP_BUILDING_LIBRARY) -# if defined(__MINGW32__) -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport) -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# else -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport) -# endif -# define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport) -# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) -# else -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport) -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) -# endif - -# define _LIBCPP_HIDDEN -# define _LIBCPP_TEMPLATE_DATA_VIS -# define _LIBCPP_NAMESPACE_VISIBILITY - -#else - -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) -# else -# define _LIBCPP_VISIBILITY(vis) -# endif - -# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") -# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") -# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS - -// TODO: Make this a proper customization point or remove the option to override it. -# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") -# endif - -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) -# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default"))) -# elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default"))) -# else -# define _LIBCPP_NAMESPACE_VISIBILITY -# endif - -#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) - -// hide_from_abi -// ------------- - -#define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) - -#if __has_attribute(exclude_from_explicit_instantiation) -# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) -#else -// Try to approximate the effect of exclude_from_explicit_instantiation -// (which is that entities are not assumed to be provided by explicit -// template instantiations in the dylib) by always inlining those entities. -# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE -#endif - -#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST -# define _LIBCPP_HARDENING_SIG f -#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE -# define _LIBCPP_HARDENING_SIG s -#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -# define _LIBCPP_HARDENING_SIG d -#else -# define _LIBCPP_HARDENING_SIG n // "none" -#endif - -#if _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_OBSERVE -# define _LIBCPP_ASSERTION_SEMANTIC_SIG o -#elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE -# define _LIBCPP_ASSERTION_SEMANTIC_SIG q -#elif _LIBCPP_ASSERTION_SEMANTIC == _LIBCPP_ASSERTION_SEMANTIC_ENFORCE -# define _LIBCPP_ASSERTION_SEMANTIC_SIG e -#else -# define _LIBCPP_ASSERTION_SEMANTIC_SIG i // `ignore` -#endif - -#if !_LIBCPP_HAS_EXCEPTIONS -# define _LIBCPP_EXCEPTIONS_SIG n -#else -# define _LIBCPP_EXCEPTIONS_SIG e -#endif - -#define _LIBCPP_ODR_SIGNATURE \ - _LIBCPP_CONCAT( \ - _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_ASSERTION_SEMANTIC_SIG), _LIBCPP_EXCEPTIONS_SIG), \ - _LIBCPP_VERSION) - -// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved -// on two levels: -// 1. The symbol is given hidden visibility, which ensures that users won't start exporting -// symbols from their dynamic library by means of using the libc++ headers. This ensures -// that those symbols stay private to the dynamic library in which it is defined. -// -// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. -// This ensures that no ODR violation can arise from mixing two TUs compiled with different -// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the -// program contains two definitions of a function, the ODR requires them to be token-by-token -// equivalent, and the linker is allowed to pick either definition and discard the other one. -// -// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled -// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs -// compiled with different settings), the two definitions are both visible by the linker and they -// have the same name, but they have a meaningfully different implementation (one throws an exception -// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in -// practice what will happen is that the linker will pick one of the definitions at random and will -// discard the other one. This can quite clearly lead to incorrect program behavior. -// -// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any -// property that causes the code of a function to differ from the code in another configuration -// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI -// tag, but we encode the ones that we think are most important: library version, exceptions, and -// hardening mode. -// -// Note that historically, solving this problem has been achieved in various ways, including -// force-inlining all functions or giving internal linkage to all functions. Both these previous -// solutions suffer from drawbacks that lead notably to code bloat. -// -// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend -// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. -// -// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions -// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled -// name of a virtual function is part of its ABI, since some architectures like arm64e can sign -// the virtual function pointer in the vtable based on the mangled name of the function. Since -// we use an ABI tag that changes with each released version, the mangled name of the virtual -// function would change, which is incorrect. Note that it doesn't make much sense to change -// the implementation of a virtual function in an ABI-incompatible way in the first place, -// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. -// -// The macro can be applied to record and enum types. When the tagged type is nested in -// a record this "parent" record needs to have the macro too. Another use case for applying -// this macro to records and unions is to apply an ABI tag to inline constexpr variables. -// This can be useful for inline variables that are implementation details which are expected -// to change in the future. -// -// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing -// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and -// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. -#ifndef _LIBCPP_NO_ABI_TAG -# define _LIBCPP_HIDE_FROM_ABI \ - _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ - __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) -#else -# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION -#endif -#define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION - -// Optional attributes -// ------------------- - -// these are useful for a better QoI, but not required to be available - -#define _LIBCPP_NOALIAS __attribute__((__malloc__)) -#define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]] -#define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) -#define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) -#define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ - __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) - -#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) -#else -# define _LIBCPP_NO_CFI -#endif - -#if __has_attribute(__using_if_exists__) -# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) -#else -# define _LIBCPP_USING_IF_EXISTS -#endif - -#if __has_cpp_attribute(_Clang::__no_destroy__) -# define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]] -#else -# define _LIBCPP_NO_DESTROY -#endif - -#if __has_attribute(__diagnose_if__) -# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) -#else -# define _LIBCPP_DIAGNOSE_WARNING(...) -#endif - -#if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_APPLE_CLANG_VER) && \ - (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 2001) -# define _LIBCPP_DIAGNOSE_IF(...) __attribute__((__diagnose_if__(__VA_ARGS__))) -#else -# define _LIBCPP_DIAGNOSE_IF(...) -#endif - -#define _LIBCPP_DIAGNOSE_NULLPTR_IF(condition, condition_description) \ - _LIBCPP_DIAGNOSE_IF( \ - condition, \ - "null passed to callee that requires a non-null argument" condition_description, \ - "warning", \ - "nonnull") - -#if __has_cpp_attribute(_Clang::__lifetimebound__) -# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] -#else -# define _LIBCPP_LIFETIMEBOUND -#endif - -// This is to work around https://llvm.org/PR156809 -#ifndef _LIBCPP_CXX03_LANG -# define _LIBCPP_CTOR_LIFETIMEBOUND _LIBCPP_LIFETIMEBOUND -#else -# define _LIBCPP_CTOR_LIFETIMEBOUND -#endif - -#if __has_cpp_attribute(_Clang::__noescape__) -# define _LIBCPP_NOESCAPE [[_Clang::__noescape__]] -#else -# define _LIBCPP_NOESCAPE -#endif - -#if __has_cpp_attribute(_Clang::__no_specializations__) -# define _LIBCPP_NO_SPECIALIZATIONS \ - [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]] -#else -# define _LIBCPP_NO_SPECIALIZATIONS -#endif - -#if __has_cpp_attribute(_Clang::__preferred_name__) -# define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]] -#else -# define _LIBCPP_PREFERRED_NAME(x) -#endif - -#if __has_cpp_attribute(_Clang::__scoped_lockable__) -# define _LIBCPP_SCOPED_LOCKABLE [[_Clang::__scoped_lockable__]] -#else -# define _LIBCPP_SCOPED_LOCKABLE -#endif - -#if __has_cpp_attribute(_Clang::__capability__) -# define _LIBCPP_CAPABILITY(...) [[_Clang::__capability__(__VA_ARGS__)]] -#else -# define _LIBCPP_CAPABILITY(...) -#endif - -#if __has_attribute(__acquire_capability__) -# define _LIBCPP_ACQUIRE_CAPABILITY(...) __attribute__((__acquire_capability__(__VA_ARGS__))) -#else -# define _LIBCPP_ACQUIRE_CAPABILITY(...) -#endif - -#if __has_cpp_attribute(_Clang::__try_acquire_capability__) -# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) [[_Clang::__try_acquire_capability__(__VA_ARGS__)]] -#else -# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) -#endif - -#if __has_cpp_attribute(_Clang::__acquire_shared_capability__) -# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY [[_Clang::__acquire_shared_capability__]] -#else -# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY -#endif - -#if __has_cpp_attribute(_Clang::__try_acquire_shared_capability__) -# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) [[_Clang::__try_acquire_shared_capability__(__VA_ARGS__)]] -#else -# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) -#endif - -#if __has_cpp_attribute(_Clang::__release_capability__) -# define _LIBCPP_RELEASE_CAPABILITY [[_Clang::__release_capability__]] -#else -# define _LIBCPP_RELEASE_CAPABILITY -#endif - -#if __has_cpp_attribute(_Clang::__release_shared_capability__) -# define _LIBCPP_RELEASE_SHARED_CAPABILITY [[_Clang::__release_shared_capability__]] -#else -# define _LIBCPP_RELEASE_SHARED_CAPABILITY -#endif - -#if __has_attribute(__requires_capability__) -# define _LIBCPP_REQUIRES_CAPABILITY(...) __attribute__((__requires_capability__(__VA_ARGS__))) -#else -# define _LIBCPP_REQUIRES_CAPABILITY(...) -#endif - -#if __has_cpp_attribute(_Clang::__no_thread_safety_analysis__) -# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS [[_Clang::__no_thread_safety_analysis__]] -#else -# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS -#endif - -#if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) -# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) -#else -# define _LIBCPP_DECLSPEC_EMPTY_BASES -#endif - -// Allow for build-time disabling of unsigned integer sanitization -#if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) -#else -# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK -#endif - -#if __has_feature(nullability) -# define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull -#else -# define _LIBCPP_DIAGNOSE_NULLPTR -#endif - -#if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) -// The CUDA SDK contains an unfortunate definition for the __noinline__ macro, -// which breaks the regular __attribute__((__noinline__)) syntax. Therefore, -// when compiling for CUDA we use the non-underscored version of the noinline -// attribute. -// -// This is a temporary workaround and we still expect the CUDA SDK team to solve -// this issue properly in the SDK headers. -// -// See https://github.com/llvm/llvm-project/pull/73838 for more details. -# define _LIBCPP_NOINLINE __attribute__((noinline)) -#elif __has_attribute(__noinline__) -# define _LIBCPP_NOINLINE __attribute__((__noinline__)) -#else -# define _LIBCPP_NOINLINE -#endif - -// Deprecation macros -// ------------------ - -// Deprecations warnings are always enabled, except when users explicitly opt-out -// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. -#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) -# if __has_attribute(__deprecated__) -# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) -# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) -# elif _LIBCPP_STD_VER >= 14 -# define _LIBCPP_DEPRECATED [[deprecated]] -# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] -# else -# define _LIBCPP_DEPRECATED -# define _LIBCPP_DEPRECATED_(m) -# endif -#else -# define _LIBCPP_DEPRECATED -# define _LIBCPP_DEPRECATED_(m) -#endif - -#if !defined(_LIBCPP_CXX03_LANG) -# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED -#else -# define _LIBCPP_DEPRECATED_IN_CXX11 -#endif - -#if _LIBCPP_STD_VER >= 14 -# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED -#else -# define _LIBCPP_DEPRECATED_IN_CXX14 -#endif - -#if _LIBCPP_STD_VER >= 17 -# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED -#else -# define _LIBCPP_DEPRECATED_IN_CXX17 -#endif - -#if _LIBCPP_STD_VER >= 20 -# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED -#else -# define _LIBCPP_DEPRECATED_IN_CXX20 -#endif - -#if _LIBCPP_STD_VER >= 23 -# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED -#else -# define _LIBCPP_DEPRECATED_IN_CXX23 -#endif - -#if _LIBCPP_STD_VER >= 26 -# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED -# define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m) -#else -# define _LIBCPP_DEPRECATED_IN_CXX26 -# define _LIBCPP_DEPRECATED_IN_CXX26_(m) -#endif - -#if _LIBCPP_HAS_CHAR8_T -# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED -#else -# define _LIBCPP_DEPRECATED_WITH_CHAR8_T -#endif - -#if __has_cpp_attribute(_Clang::__no_field_protection__) -# define _LIBCPP_DISABLE_POINTER_FIELD_PROTECTION [[_Clang::__no_field_protection__]] -#else -# define _LIBCPP_DISABLE_POINTER_FIELD_PROTECTION -#endif - -#endif // _LIBCPP___CONFIGURATION_ATTRIBUTES_H diff --git a/third_party/libcxx/include/c++/v1/__configuration/availability.h b/third_party/libcxx/include/c++/v1/__configuration/availability.h deleted file mode 100644 index f1a598b..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/availability.h +++ /dev/null @@ -1,299 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_AVAILABILITY_H -#define _LIBCPP___CONFIGURATION_AVAILABILITY_H - -#include <__configuration/compiler.h> -#include <__configuration/language.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -// This file defines a framework that can be used by vendors to encode the version of an operating system that various -// features of libc++ has been shipped in. This is primarily intended to allow safely deploying an executable built with -// a new version of the library on a platform containing an older version of the built library. -// Detailed documentation for this can be found at https://libcxx.llvm.org/VendorDocumentation.html#availability-markup - -// Availability markup is disabled when building the library, or when a non-Clang -// compiler is used because only Clang supports the necessary attributes. -// -// We also allow users to force-disable availability markup via the `_LIBCPP_DISABLE_AVAILABILITY` -// macro because that is the only way to work around a Clang bug related to availability -// attributes: https://llvm.org/PR134151. -// Once that bug has been fixed, we should remove the macro. -#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || \ - !defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_DISABLE_AVAILABILITY) -# undef _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS -# define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0 -#endif - -// When availability annotations are disabled, we take for granted that features introduced -// in all versions of the library are available. -#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS - -# define _LIBCPP_INTRODUCED_IN_LLVM_22 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_21 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_20 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_19 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_18 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_16 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_15 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_14 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_12 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE /* nothing */ - -#elif defined(__APPLE__) - -// clang-format off - -// LLVM 22 -// TODO: Fill this in -# define _LIBCPP_INTRODUCED_IN_LLVM_22 0 -# define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE __attribute__((unavailable)) - -// LLVM 21 -// TODO: Fill this in -# define _LIBCPP_INTRODUCED_IN_LLVM_21 0 -# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE __attribute__((unavailable)) - -// LLVM 20 -// -// Note that versions for most Apple OSes were bumped forward and aligned in that release. -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 260000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 260000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 260000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 260000) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 100000) -# define _LIBCPP_INTRODUCED_IN_LLVM_20 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_20 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 26.0))) \ - __attribute__((availability(ios, strict, introduced = 26.0))) \ - __attribute__((availability(tvos, strict, introduced = 26.0))) \ - __attribute__((availability(watchos, strict, introduced = 26.0))) \ - __attribute__((availability(bridgeos, strict, introduced = 10.0))) - -// LLVM 19 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150400) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 180400) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 180400) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 110400) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90400) -# define _LIBCPP_INTRODUCED_IN_LLVM_19 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_19 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 15.4))) \ - __attribute__((availability(ios, strict, introduced = 18.4))) \ - __attribute__((availability(tvos, strict, introduced = 18.4))) \ - __attribute__((availability(watchos, strict, introduced = 11.4))) \ - __attribute__((availability(bridgeos, strict, introduced = 9.4))) - -// LLVM 18 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 180000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 180000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 110000) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90000) || \ - (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 240000) -# define _LIBCPP_INTRODUCED_IN_LLVM_18 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_18 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 15.0))) \ - __attribute__((availability(ios, strict, introduced = 18.0))) \ - __attribute__((availability(tvos, strict, introduced = 18.0))) \ - __attribute__((availability(watchos, strict, introduced = 11.0))) \ - __attribute__((availability(bridgeos, strict, introduced = 9.0))) \ - __attribute__((availability(driverkit, strict, introduced = 24.0))) - -// LLVM 16 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 80000) || \ - (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 230000) -# define _LIBCPP_INTRODUCED_IN_LLVM_16 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_16 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 14.0))) \ - __attribute__((availability(ios, strict, introduced = 17.0))) \ - __attribute__((availability(tvos, strict, introduced = 17.0))) \ - __attribute__((availability(watchos, strict, introduced = 10.0))) \ - __attribute__((availability(bridgeos, strict, introduced = 8.0))) \ - __attribute__((availability(driverkit, strict, introduced = 23.0))) - -// LLVM 15 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130300) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160300) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160300) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90300) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 70500) || \ - (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 220400) -# define _LIBCPP_INTRODUCED_IN_LLVM_15 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_15 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 13.3))) \ - __attribute__((availability(ios, strict, introduced = 16.3))) \ - __attribute__((availability(tvos, strict, introduced = 16.3))) \ - __attribute__((availability(watchos, strict, introduced = 9.3))) \ - __attribute__((availability(bridgeos, strict, introduced = 7.5))) \ - __attribute__((availability(driverkit, strict, introduced = 22.4))) - -// LLVM 14 -# define _LIBCPP_INTRODUCED_IN_LLVM_14 _LIBCPP_INTRODUCED_IN_LLVM_15 -# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE - -// LLVM 12 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120300) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150300) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150300) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80300) || \ - (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 60000) || \ - (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 210300) -# define _LIBCPP_INTRODUCED_IN_LLVM_12 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_12 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 12.3))) \ - __attribute__((availability(ios, strict, introduced = 15.3))) \ - __attribute__((availability(tvos, strict, introduced = 15.3))) \ - __attribute__((availability(watchos, strict, introduced = 8.3))) \ - __attribute__((availability(bridgeos, strict, introduced = 6.0))) \ - __attribute__((availability(driverkit, strict, introduced = 21.3))) - -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80000) || \ - (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 200000) -# warning "The selected platform is no longer supported by libc++." -# endif - -#else - -// ...New vendors can add availability markup here... - -# error \ - "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!" - -#endif - -// This controls the availability of new implementation of std::atomic's -// wait, notify_one and notify_all. The new implementation uses -// the native atomic wait/notify operations on platforms that support them -// based on the size of the atomic type, instead of the type itself. -#define _LIBCPP_AVAILABILITY_HAS_NEW_SYNC _LIBCPP_INTRODUCED_IN_LLVM_22 -#define _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE - -// This controls whether `std::__hash_memory` is available in the dylib, which -// is used for some `std::hash` specializations. -#define _LIBCPP_AVAILABILITY_HAS_HASH_MEMORY _LIBCPP_INTRODUCED_IN_LLVM_21 -// No attribute, since we've had hash in the headers before - -// This controls whether we provide a message for `bad_function_call::what()` that specific to `std::bad_function_call`. -// See https://wg21.link/LWG2233. This requires `std::bad_function_call::what()` to be available in the dylib. -#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE _LIBCPP_INTRODUCED_IN_LLVM_21 -// No attribute, since we've had bad_function_call::what() in the headers before - -// This controls the availability of floating-point std::from_chars functions. -// These overloads were added later than the integer overloads. -#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20 -#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE - -// This controls the availability of the C++20 time zone database. -// The parser code is built in the library. -#define _LIBCPP_AVAILABILITY_HAS_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19 -#define _LIBCPP_AVAILABILITY_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE - -// These macros determine whether we assume that std::bad_function_call and -// std::bad_expected_access provide a key function in the dylib. This allows -// centralizing their vtable and typeinfo instead of having all TUs provide -// a weak definition that then gets deduplicated. -#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19 -#define _LIBCPP_AVAILABILITY_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE -#define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19 -#define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE - -// These macros controls the availability of __cxa_init_primary_exception -// in the built library, which std::make_exception_ptr might use -// (see libcxx/include/__exception/exception_ptr.h). -#define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18 -#define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE - -// This controls the availability of the C++17 std::pmr library, -// which is implemented in large part in the built library. -// -// TODO: Enable std::pmr markup once https://llvm.org/PR40340 has been fixed -// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support -// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we -// use availability annotations until that bug has been fixed. -#define _LIBCPP_AVAILABILITY_HAS_PMR _LIBCPP_INTRODUCED_IN_LLVM_16 -#define _LIBCPP_AVAILABILITY_PMR - -// This controls whether the library claims to provide a default verbose -// termination function, and consequently whether the headers will try -// to use it when the mechanism isn't overriden at compile-time. -#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15 -#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE - -// This controls the availability of floating-point std::to_chars functions. -// These overloads were added later than the integer overloads. -#define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14 -#define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE - -// Enable additional explicit instantiations of iostreams components. This -// reduces the number of weak definitions generated in programs that use -// iostreams by providing a single strong definition in the shared library. -// -// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation, -// or once libc++ doesn't use the attribute anymore. -// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed. -#if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32) -# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 _LIBCPP_INTRODUCED_IN_LLVM_12 -#else -# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0 -#endif - -// Only define a bunch of symbols in the dylib if we need to be compatible with LLVM 7 headers or older -# if defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_AVAILABILITY_MINIMUM_HEADER_VERSION < 8 -# define _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 -# else -# define _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 _LIBCPP_HIDE_FROM_ABI -# endif - -#endif // _LIBCPP___CONFIGURATION_AVAILABILITY_H diff --git a/third_party/libcxx/include/c++/v1/__configuration/compiler.h b/third_party/libcxx/include/c++/v1/__configuration/compiler.h deleted file mode 100644 index 7cd81e0..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/compiler.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_COMPILER_H -#define _LIBCPP___CONFIGURATION_COMPILER_H - -#include <__config_site> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#if defined(__apple_build_version__) -// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) -# define _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) -#elif defined(__clang__) -# define _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) -#elif defined(__GNUC__) -# define _LIBCPP_COMPILER_GCC -# define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) -#endif - -#ifdef __cplusplus - -// Warn if a compiler version is used that is not supported anymore -// LLVM RELEASE Update the minimum compiler versions -# if defined(_LIBCPP_CLANG_VER) -# if _LIBCPP_CLANG_VER < 2001 -# warning "Libc++ only supports Clang 20 and later" -# endif -# elif defined(_LIBCPP_APPLE_CLANG_VER) -# if _LIBCPP_APPLE_CLANG_VER < 1700 -# warning "Libc++ only supports AppleClang 26 and later" -# endif -# elif defined(_LIBCPP_GCC_VER) -# if _LIBCPP_GCC_VER < 1500 -# warning "Libc++ only supports GCC 15 and later" -# endif -# endif - -#endif - -#endif // _LIBCPP___CONFIGURATION_COMPILER_H diff --git a/third_party/libcxx/include/c++/v1/__configuration/experimental.h b/third_party/libcxx/include/c++/v1/__configuration/experimental.h deleted file mode 100644 index bb38d82..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/experimental.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_EXPERIMENTAL_H -#define _LIBCPP___CONFIGURATION_EXPERIMENTAL_H - -#include <__config_site> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#if __has_feature(experimental_library) -# ifndef _LIBCPP_ENABLE_EXPERIMENTAL -# define _LIBCPP_ENABLE_EXPERIMENTAL -# endif -#endif - -// Incomplete features get their own specific disabling flags. This makes it -// easier to grep for target specific flags once the feature is complete. -#if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY) -# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1 -#else -# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0 -#endif - -#define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY -#define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY -#define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY -#define _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC _LIBCPP_HAS_EXPERIMENTAL_LIBRARY -#define _LIBCPP_HAS_EXPERIMENTAL_OPTIONAL_ITERATOR _LIBCPP_HAS_EXPERIMENTAL_LIBRARY - -#endif // _LIBCPP___CONFIGURATION_EXPERIMENTAL_H diff --git a/third_party/libcxx/include/c++/v1/__configuration/hardening.h b/third_party/libcxx/include/c++/v1/__configuration/hardening.h deleted file mode 100644 index 5723f5a..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/hardening.h +++ /dev/null @@ -1,215 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_HARDENING_H -#define _LIBCPP___CONFIGURATION_HARDENING_H - -#include <__config_site> -#include <__configuration/experimental.h> -#include <__configuration/language.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -// TODO(LLVM 23): Remove this. We're making these an error to catch folks who might not have migrated. -// Since hardening went through several changes (many of which impacted user-facing macros), -// we're keeping these checks around for a bit longer than usual. Failure to properly configure -// hardening results in checks being dropped silently, which is a pretty big deal. -#if defined(_LIBCPP_ENABLE_ASSERTIONS) -# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif -#if defined(_LIBCPP_ENABLE_HARDENED_MODE) -# error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif -#if defined(_LIBCPP_ENABLE_SAFE_MODE) -# error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif -#if defined(_LIBCPP_ENABLE_DEBUG_MODE) -# error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE= instead (see docs)" -#endif - -// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: -// -// - `_LIBCPP_HARDENING_MODE_NONE`; -// - `_LIBCPP_HARDENING_MODE_FAST`; -// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; -// - `_LIBCPP_HARDENING_MODE_DEBUG`. -// -// These values have the following effects: -// -// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; -// -// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks -// that can be done with relatively little runtime overhead in constant time; -// -// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of -// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors -// but are not necessarily security-critical; -// -// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive -// mode and enables all checks available in the library, including internal assertions. Checks that are part of the -// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. - -// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These -// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. -// -// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and -// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: -// - the sentinel is reachable from the begin iterator; -// - TODO(hardening): both iterators refer to the same container. -// -// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through -// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access -// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like -// `optional` and `function` are considered one-element containers for the purposes of this check. -// -// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero -// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the -// memory security of a program (however, it is still undefined behavior that can result in strange errors due to -// compiler optimizations). -// -// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the -// given ranges do not overlap. -// -// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object -// was allocated by the given allocator). Violating this category typically results in a memory leak. -// -// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in -// an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like -// attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category -// (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or -// otherwise create an immediate security issue. -// -// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure -// the containers have compatible allocators. -// -// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments -// for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the -// original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g. -// a string view where only a subset of elements is possible to access). This category is for assertions violating -// which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the -// user code. -// -// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to -// be benign in our implementation. -// -// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed -// by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied; -// thus, this would often be a heuristic check and it might be quite expensive. -// -// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on -// user input. -// -// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. - -// clang-format off -# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) -# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) -# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. -# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) -// clang-format on - -#ifndef _LIBCPP_HARDENING_MODE - -# ifndef _LIBCPP_HARDENING_MODE_DEFAULT -# error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \ -`__config_site` header, please make sure your installation of libc++ is not broken. -# endif - -# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT -#endif - -#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ - _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ - _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG -# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ -_LIBCPP_HARDENING_MODE_NONE, \ -_LIBCPP_HARDENING_MODE_FAST, \ -_LIBCPP_HARDENING_MODE_EXTENSIVE, \ -_LIBCPP_HARDENING_MODE_DEBUG -#endif - -// The library provides the macro `_LIBCPP_ASSERTION_SEMANTIC` for configuring the assertion semantic used by hardening; -// it can be set to one of the following values: -// -// - `_LIBCPP_ASSERTION_SEMANTIC_IGNORE`; -// - `_LIBCPP_ASSERTION_SEMANTIC_OBSERVE`; -// - `_LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE`; -// - `_LIBCPP_ASSERTION_SEMANTIC_ENFORCE`. -// -// libc++ assertion semantics generally mirror the evaluation semantics of C++26 Contracts: -// - `ignore` evaluates the assertion but doesn't do anything if it fails (note that it differs from the Contracts -// `ignore` semantic which wouldn't evaluate the assertion at all); -// - `observe` logs an error (indicating, if possible, that the error is fatal) and continues execution; -// - `quick-enforce` terminates the program as fast as possible (via trapping); -// - `enforce` logs an error and then terminates the program. -// -// Additionally, a special `hardening-dependent` value selects the assertion semantic based on the hardening mode in -// effect: the production-capable modes (`fast` and `extensive`) map to `quick_enforce` and the `debug` mode maps to -// `enforce`. The `hardening-dependent` semantic cannot be selected explicitly, it is only used when no assertion -// semantic is provided by the user _and_ the library's default semantic is configured to be dependent on hardening. -// -// Notes: -// - Continuing execution after a hardening check fails results in undefined behavior; the `observe` semantic is meant -// to make adopting hardening easier but should not be used outside of this scenario; -// - C++26 wording for Library Hardening precludes a conforming Hardened implementation from using the Contracts -// `ignore` semantic when evaluating hardened preconditions in the Library. Libc++ allows using this semantic for -// hardened preconditions, however, be aware that using `ignore` does not produce a conforming "Hardened" -// implementation, unlike the other semantics above. -// clang-format off -# define _LIBCPP_ASSERTION_SEMANTIC_HARDENING_DEPENDENT (1 << 1) -# define _LIBCPP_ASSERTION_SEMANTIC_IGNORE (1 << 2) -# define _LIBCPP_ASSERTION_SEMANTIC_OBSERVE (1 << 3) -# define _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE (1 << 4) -# define _LIBCPP_ASSERTION_SEMANTIC_ENFORCE (1 << 5) -// clang-format on - -// If the user attempts to configure the assertion semantic, check that it is allowed in the current environment. -#if defined(_LIBCPP_ASSERTION_SEMANTIC) -# if !_LIBCPP_HAS_EXPERIMENTAL_LIBRARY -# error "Assertion semantics are an experimental feature." -# endif -# if defined(_LIBCPP_CXX03_LANG) -# error "Assertion semantics are not available in the C++03 mode." -# endif -#endif // defined(_LIBCPP_ASSERTION_SEMANTIC) - -// User-provided semantic takes top priority -- don't override if set. -#ifndef _LIBCPP_ASSERTION_SEMANTIC - -# ifndef _LIBCPP_ASSERTION_SEMANTIC_DEFAULT -# error _LIBCPP_ASSERTION_SEMANTIC_DEFAULT is not defined. This definition should be set at configuration time in \ -the `__config_site` header, please make sure your installation of libc++ is not broken. -# endif - -# if _LIBCPP_ASSERTION_SEMANTIC_DEFAULT != _LIBCPP_ASSERTION_SEMANTIC_HARDENING_DEPENDENT -# define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_DEFAULT -# else -# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -# define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_ENFORCE -# else -# define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE -# endif -# endif // _LIBCPP_ASSERTION_SEMANTIC_DEFAULT != _LIBCPP_ASSERTION_SEMANTIC_HARDENING_DEPENDENT - -#endif // #ifndef _LIBCPP_ASSERTION_SEMANTIC - -// Finally, validate the selected semantic (in case the user tries setting it to an incorrect value): -#if _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_IGNORE && \ - _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_OBSERVE && \ - _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE && \ - _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_ENFORCE -# error _LIBCPP_ASSERTION_SEMANTIC must be set to one of the following values: \ -_LIBCPP_ASSERTION_SEMANTIC_IGNORE, \ -_LIBCPP_ASSERTION_SEMANTIC_OBSERVE, \ -_LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE, \ -_LIBCPP_ASSERTION_SEMANTIC_ENFORCE -#endif - -#endif // _LIBCPP___CONFIGURATION_HARDENING_H diff --git a/third_party/libcxx/include/c++/v1/__configuration/language.h b/third_party/libcxx/include/c++/v1/__configuration/language.h deleted file mode 100644 index 3137ba2..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/language.h +++ /dev/null @@ -1,59 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_LANGUAGE_H -#define _LIBCPP___CONFIGURATION_LANGUAGE_H - -#include <__config_site> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -// NOLINTBEGIN(libcpp-cpp-version-check) -#ifdef __cplusplus -# if __cplusplus < 201103L -# define _LIBCPP_CXX03_LANG -# endif -# if __cplusplus <= 201103L -# define _LIBCPP_STD_VER 11 -# elif __cplusplus <= 201402L -# define _LIBCPP_STD_VER 14 -# elif __cplusplus <= 201703L -# define _LIBCPP_STD_VER 17 -# elif __cplusplus <= 202002L -# define _LIBCPP_STD_VER 20 -# elif __cplusplus <= 202302L -# define _LIBCPP_STD_VER 23 -# else -// Expected release year of the next C++ standard -# define _LIBCPP_STD_VER 26 -# endif -#endif // __cplusplus -// NOLINTEND(libcpp-cpp-version-check) - -#if defined(__cpp_rtti) && __cpp_rtti >= 199711L -# define _LIBCPP_HAS_RTTI 1 -#else -# define _LIBCPP_HAS_RTTI 0 -#endif - -#if defined(__cpp_exceptions) && __cpp_exceptions >= 199711L -# define _LIBCPP_HAS_EXCEPTIONS 1 -#else -# define _LIBCPP_HAS_EXCEPTIONS 0 -#endif - -#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) -# define _LIBCPP_HAS_CHAR8_T 0 -#else -# define _LIBCPP_HAS_CHAR8_T 1 -#endif - -#endif // _LIBCPP___CONFIGURATION_LANGUAGE_H diff --git a/third_party/libcxx/include/c++/v1/__configuration/platform.h b/third_party/libcxx/include/c++/v1/__configuration/platform.h deleted file mode 100644 index 644fe17..0000000 --- a/third_party/libcxx/include/c++/v1/__configuration/platform.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CONFIGURATION_PLATFORM_H -#define _LIBCPP___CONFIGURATION_PLATFORM_H - -#include <__config_site> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#if defined(__ELF__) -# define _LIBCPP_OBJECT_FORMAT_ELF 1 -#elif defined(__MACH__) -# define _LIBCPP_OBJECT_FORMAT_MACHO 1 -#elif defined(_WIN32) -# define _LIBCPP_OBJECT_FORMAT_COFF 1 -#elif defined(__wasm__) -# define _LIBCPP_OBJECT_FORMAT_WASM 1 -#elif defined(_AIX) -# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 -#else -// ... add new file formats here ... -#endif - -// Need to detect which libc we're using if we're on Linux. -#if (defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__)) && __has_include() -# include -# if defined(__GLIBC_PREREQ) -# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) -# else -# define _LIBCPP_GLIBC_PREREQ(a, b) 0 -# endif // defined(__GLIBC_PREREQ) -#else -# define _LIBCPP_GLIBC_PREREQ(a, b) 0 -#endif - -#ifndef __BYTE_ORDER__ -# error \ - "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform" -#endif - -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# define _LIBCPP_LITTLE_ENDIAN -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define _LIBCPP_BIG_ENDIAN -#endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - -#endif // _LIBCPP___CONFIGURATION_PLATFORM_H diff --git a/third_party/libcxx/include/c++/v1/__coroutine/coroutine_handle.h b/third_party/libcxx/include/c++/v1/__coroutine/coroutine_handle.h deleted file mode 100644 index b26a650..0000000 --- a/third_party/libcxx/include/c++/v1/__coroutine/coroutine_handle.h +++ /dev/null @@ -1,177 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COROUTINE_COROUTINE_HANDLE_H -#define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H - -#include <__assert> -#include <__config> -#include <__cstddef/nullptr_t.h> -#include <__cstddef/size_t.h> -#include <__functional/hash.h> -#include <__memory/addressof.h> -#include <__type_traits/remove_cv.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -// [coroutine.handle] -template -struct coroutine_handle; - -template <> -struct coroutine_handle { -public: - // [coroutine.handle.con], construct/reset - constexpr coroutine_handle() noexcept = default; - - _LIBCPP_HIDE_FROM_ABI constexpr coroutine_handle(nullptr_t) noexcept {} - - _LIBCPP_HIDE_FROM_ABI coroutine_handle& operator=(nullptr_t) noexcept { - __handle_ = nullptr; - return *this; - } - - // [coroutine.handle.export.import], export/import - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr void* address() const noexcept { return __handle_; } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr coroutine_handle from_address(void* __addr) noexcept { - coroutine_handle __tmp; - __tmp.__handle_ = __addr; - return __tmp; - } - - // [coroutine.handle.observers], observers - _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return __handle_ != nullptr; } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool done() const { - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(__is_suspended(), "done() can be called only on suspended coroutines"); - return __builtin_coro_done(__handle_); - } - - // [coroutine.handle.resumption], resumption - _LIBCPP_HIDE_FROM_ABI void operator()() const { resume(); } - - _LIBCPP_HIDE_FROM_ABI void resume() const { - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(__is_suspended(), "resume() can be called only on suspended coroutines"); - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(!done(), "resume() has undefined behavior when the coroutine is done"); - __builtin_coro_resume(__handle_); - } - - _LIBCPP_HIDE_FROM_ABI void destroy() const { - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(__is_suspended(), "destroy() can be called only on suspended coroutines"); - __builtin_coro_destroy(__handle_); - } - -private: - _LIBCPP_HIDE_FROM_ABI bool __is_suspended() const { - // FIXME actually implement a check for if the coro is suspended. - return __handle_ != nullptr; - } - - void* __handle_ = nullptr; -}; - -// [coroutine.handle.compare] -inline _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { - return __x.address() == __y.address(); -} -inline _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering -operator<=>(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { - return compare_three_way()(__x.address(), __y.address()); -} - -template -struct coroutine_handle { -public: - // [coroutine.handle.con], construct/reset - constexpr coroutine_handle() noexcept = default; - - _LIBCPP_HIDE_FROM_ABI constexpr coroutine_handle(nullptr_t) noexcept {} - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static coroutine_handle from_promise(_Promise& __promise) { - using _RawPromise = __remove_cv_t<_Promise>; - coroutine_handle __tmp; - __tmp.__handle_ = - __builtin_coro_promise(std::addressof(const_cast<_RawPromise&>(__promise)), alignof(_Promise), true); - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI coroutine_handle& operator=(nullptr_t) noexcept { - __handle_ = nullptr; - return *this; - } - - // [coroutine.handle.export.import], export/import - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr void* address() const noexcept { return __handle_; } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr coroutine_handle from_address(void* __addr) noexcept { - coroutine_handle __tmp; - __tmp.__handle_ = __addr; - return __tmp; - } - - // [coroutine.handle.conv], conversion - _LIBCPP_HIDE_FROM_ABI constexpr operator coroutine_handle<>() const noexcept { - return coroutine_handle<>::from_address(address()); - } - - // [coroutine.handle.observers], observers - _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return __handle_ != nullptr; } - - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool done() const { - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(__is_suspended(), "done() can be called only on suspended coroutines"); - return __builtin_coro_done(__handle_); - } - - // [coroutine.handle.resumption], resumption - _LIBCPP_HIDE_FROM_ABI void operator()() const { resume(); } - - _LIBCPP_HIDE_FROM_ABI void resume() const { - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(__is_suspended(), "resume() can be called only on suspended coroutines"); - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(!done(), "resume() has undefined behavior when the coroutine is done"); - __builtin_coro_resume(__handle_); - } - - _LIBCPP_HIDE_FROM_ABI void destroy() const { - _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(__is_suspended(), "destroy() can be called only on suspended coroutines"); - __builtin_coro_destroy(__handle_); - } - - // [coroutine.handle.promise], promise access - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Promise& promise() const { - return *static_cast<_Promise*>(__builtin_coro_promise(this->__handle_, alignof(_Promise), false)); - } - -private: - _LIBCPP_HIDE_FROM_ABI bool __is_suspended() const { - // FIXME actually implement a check for if the coro is suspended. - return __handle_ != nullptr; - } - void* __handle_ = nullptr; -}; - -// [coroutine.handle.hash] -template -struct hash> { - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t operator()(const coroutine_handle<_Tp>& __v) const noexcept { - return hash()(__v.address()); - } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___COROUTINE_COROUTINE_HANDLE_H diff --git a/third_party/libcxx/include/c++/v1/__coroutine/coroutine_traits.h b/third_party/libcxx/include/c++/v1/__coroutine/coroutine_traits.h deleted file mode 100644 index 60f7ca2..0000000 --- a/third_party/libcxx/include/c++/v1/__coroutine/coroutine_traits.h +++ /dev/null @@ -1,48 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COROUTINE_COROUTINE_TRAITS_H -#define _LIBCPP___COROUTINE_COROUTINE_TRAITS_H - -#include <__config> -#include <__type_traits/void_t.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -// [coroutine.traits] -// [coroutine.traits.primary] -// The header defined the primary template coroutine_traits such that -// if ArgTypes is a parameter pack of types and if the qualified-id R::promise_type -// is valid and denotes a type ([temp.deduct]), then coroutine_traits -// has the following publicly accessible memebr: -// -// using promise_type = typename R::promise_type; -// -// Otherwise, coroutine_traits has no members. -template -struct __coroutine_traits_sfinae {}; - -template -struct __coroutine_traits_sfinae< _Tp, __void_t > { - using promise_type = typename _Tp::promise_type; -}; - -template -struct coroutine_traits : public __coroutine_traits_sfinae<_Ret> {}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___COROUTINE_COROUTINE_TRAITS_H diff --git a/third_party/libcxx/include/c++/v1/__coroutine/noop_coroutine_handle.h b/third_party/libcxx/include/c++/v1/__coroutine/noop_coroutine_handle.h deleted file mode 100644 index b9c54d3..0000000 --- a/third_party/libcxx/include/c++/v1/__coroutine/noop_coroutine_handle.h +++ /dev/null @@ -1,97 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H -#define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H - -#include <__config> -#include <__coroutine/coroutine_handle.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -// [coroutine.noop] -// [coroutine.promise.noop] -struct noop_coroutine_promise {}; - -// [coroutine.handle.noop] -template <> -struct coroutine_handle { -public: - // [coroutine.handle.noop.conv], conversion - _LIBCPP_HIDE_FROM_ABI constexpr operator coroutine_handle<>() const noexcept { - return coroutine_handle<>::from_address(address()); - } - - // [coroutine.handle.noop.observers], observers - _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return true; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool done() const noexcept { return false; } - - // [coroutine.handle.noop.resumption], resumption - _LIBCPP_HIDE_FROM_ABI constexpr void operator()() const noexcept {} - _LIBCPP_HIDE_FROM_ABI constexpr void resume() const noexcept {} - _LIBCPP_HIDE_FROM_ABI constexpr void destroy() const noexcept {} - - // [coroutine.handle.noop.promise], promise access - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI noop_coroutine_promise& promise() const noexcept { - return *static_cast( - __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false)); - } - - // [coroutine.handle.noop.address], address - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr void* address() const noexcept { return __handle_; } - -private: - _LIBCPP_HIDE_FROM_ABI friend coroutine_handle noop_coroutine() noexcept; - -# if __has_builtin(__builtin_coro_noop) - _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept { this->__handle_ = __builtin_coro_noop(); } - - void* __handle_ = nullptr; - -# elif defined(_LIBCPP_COMPILER_GCC) - // GCC doesn't implement __builtin_coro_noop(). - // Construct the coroutine frame manually instead. - struct __noop_coroutine_frame_ty_ { - static void __dummy_resume_destroy_func() {} - - void (*__resume_)() = __dummy_resume_destroy_func; - void (*__destroy_)() = __dummy_resume_destroy_func; - struct noop_coroutine_promise __promise_; - }; - - static __noop_coroutine_frame_ty_ __noop_coroutine_frame_; - - void* __handle_ = &__noop_coroutine_frame_; - - _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default; - -# endif // __has_builtin(__builtin_coro_noop) -}; - -using noop_coroutine_handle = coroutine_handle; - -# if defined(_LIBCPP_COMPILER_GCC) -inline noop_coroutine_handle::__noop_coroutine_frame_ty_ noop_coroutine_handle::__noop_coroutine_frame_{}; -# endif - -// [coroutine.noop.coroutine] -[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI noop_coroutine_handle noop_coroutine() noexcept { - return noop_coroutine_handle(); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H diff --git a/third_party/libcxx/include/c++/v1/__coroutine/trivial_awaitables.h b/third_party/libcxx/include/c++/v1/__coroutine/trivial_awaitables.h deleted file mode 100644 index 7cb7f4d..0000000 --- a/third_party/libcxx/include/c++/v1/__coroutine/trivial_awaitables.h +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H -#define __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H - -#include <__config> -#include <__coroutine/coroutine_handle.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 20 - -_LIBCPP_BEGIN_NAMESPACE_STD - -// [coroutine.trivial.awaitables] -struct suspend_never { - _LIBCPP_HIDE_FROM_ABI constexpr bool await_ready() const noexcept { return true; } - _LIBCPP_HIDE_FROM_ABI constexpr void await_suspend(coroutine_handle<>) const noexcept {} - _LIBCPP_HIDE_FROM_ABI constexpr void await_resume() const noexcept {} -}; - -struct suspend_always { - _LIBCPP_HIDE_FROM_ABI constexpr bool await_ready() const noexcept { return false; } - _LIBCPP_HIDE_FROM_ABI constexpr void await_suspend(coroutine_handle<>) const noexcept {} - _LIBCPP_HIDE_FROM_ABI constexpr void await_resume() const noexcept {} -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 20 - -#endif // __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H diff --git a/third_party/libcxx/include/c++/v1/__cstddef/byte.h b/third_party/libcxx/include/c++/v1/__cstddef/byte.h deleted file mode 100644 index 3d97db1..0000000 --- a/third_party/libcxx/include/c++/v1/__cstddef/byte.h +++ /dev/null @@ -1,85 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CSTDDEF_BYTE_H -#define _LIBCPP___CSTDDEF_BYTE_H - -#include <__config> -#include <__fwd/byte.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if _LIBCPP_STD_VER >= 17 -_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD - -enum class byte : unsigned char {}; - -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept { - return static_cast( - static_cast(static_cast(__lhs) | static_cast(__rhs))); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept { - return __lhs = __lhs | __rhs; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept { - return static_cast( - static_cast(static_cast(__lhs) & static_cast(__rhs))); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept { - return __lhs = __lhs & __rhs; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept { - return static_cast( - static_cast(static_cast(__lhs) ^ static_cast(__rhs))); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept { - return __lhs = __lhs ^ __rhs; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept { - return static_cast(static_cast(~static_cast(__b))); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept { - return __lhs = __lhs << __shift; -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept { - return static_cast(static_cast(static_cast(__lhs) << __shift)); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept { - return __lhs = __lhs >> __shift; -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept { - return static_cast(static_cast(static_cast(__lhs) >> __shift)); -} - -template ::value, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept { - return static_cast<_Integer>(__b); -} - -_LIBCPP_END_UNVERSIONED_NAMESPACE_STD -#endif // _LIBCPP_STD_VER >= 17 - -#endif // _LIBCPP___CSTDDEF_BYTE_H diff --git a/third_party/libcxx/include/c++/v1/__cstddef/max_align_t.h b/third_party/libcxx/include/c++/v1/__cstddef/max_align_t.h deleted file mode 100644 index 7c09c7e..0000000 --- a/third_party/libcxx/include/c++/v1/__cstddef/max_align_t.h +++ /dev/null @@ -1,27 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CSTDDEF_MAX_ALIGN_T_H -#define _LIBCPP___CSTDDEF_MAX_ALIGN_T_H - -#include <__config> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if !defined(_LIBCPP_CXX03_LANG) -using ::max_align_t _LIBCPP_USING_IF_EXISTS; -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CSTDDEF_MAX_ALIGN_T_H diff --git a/third_party/libcxx/include/c++/v1/__cstddef/nullptr_t.h b/third_party/libcxx/include/c++/v1/__cstddef/nullptr_t.h deleted file mode 100644 index 7eaae01..0000000 --- a/third_party/libcxx/include/c++/v1/__cstddef/nullptr_t.h +++ /dev/null @@ -1,24 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CSTDDEF_NULLPTR_T_H -#define _LIBCPP___CSTDDEF_NULLPTR_T_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -using nullptr_t = decltype(nullptr); - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CSTDDEF_NULLPTR_T_H diff --git a/third_party/libcxx/include/c++/v1/__cstddef/ptrdiff_t.h b/third_party/libcxx/include/c++/v1/__cstddef/ptrdiff_t.h deleted file mode 100644 index 146f345..0000000 --- a/third_party/libcxx/include/c++/v1/__cstddef/ptrdiff_t.h +++ /dev/null @@ -1,24 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CSTDDEF_PTRDIFF_T_H -#define _LIBCPP___CSTDDEF_PTRDIFF_T_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -using ptrdiff_t = decltype(static_cast(nullptr) - static_cast(nullptr)); - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CSTDDEF_PTRDIFF_T_H diff --git a/third_party/libcxx/include/c++/v1/__cstddef/size_t.h b/third_party/libcxx/include/c++/v1/__cstddef/size_t.h deleted file mode 100644 index 59bad93..0000000 --- a/third_party/libcxx/include/c++/v1/__cstddef/size_t.h +++ /dev/null @@ -1,24 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CSTDDEF_SIZE_T_H -#define _LIBCPP___CSTDDEF_SIZE_T_H - -#include <__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -using size_t = decltype(sizeof(int)); - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CSTDDEF_SIZE_T_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/adjacent_find.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/adjacent_find.h deleted file mode 100644 index ac23323..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/adjacent_find.h +++ /dev/null @@ -1,57 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_ADJACENT_FIND_H -#define _LIBCPP___CXX03___ALGORITHM_ADJACENT_FIND_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _Iter __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { - if (__first == __last) - return __first; - _Iter __i = __first; - while (++__i != __last) { - if (__pred(*__first, *__i)) - return __first; - __first = __i; - } - return __i; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { - return std::__adjacent_find(std::move(__first), std::move(__last), __pred); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -adjacent_find(_ForwardIterator __first, _ForwardIterator __last) { - return std::adjacent_find(std::move(__first), std::move(__last), __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_ADJACENT_FIND_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/all_of.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/all_of.h deleted file mode 100644 index 8bc39b0..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/all_of.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_ALL_OF_H -#define _LIBCPP___CXX03___ALGORITHM_ALL_OF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (!__pred(*__first)) - return false; - return true; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_ALL_OF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/any_of.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/any_of.h deleted file mode 100644 index 6b3462a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/any_of.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_ANY_OF_H -#define _LIBCPP___CXX03___ALGORITHM_ANY_OF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (__pred(*__first)) - return true; - return false; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_ANY_OF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/binary_search.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/binary_search.h deleted file mode 100644 index 37e2739..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/binary_search.h +++ /dev/null @@ -1,39 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_BINARY_SEARCH_H -#define _LIBCPP___CXX03___ALGORITHM_BINARY_SEARCH_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/lower_bound.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp); - return __first != __last && !__comp(__value, *__first); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::binary_search(__first, __last, __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_BINARY_SEARCH_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp.h deleted file mode 100644 index 420c434..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp.h +++ /dev/null @@ -1,49 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COMP_H -#define _LIBCPP___CXX03___ALGORITHM_COMP_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/desugars_to.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -struct __equal_to { - template - _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x, const _T2& __y) const { - return __x == __y; - } -}; - -template -inline const bool __desugars_to_v<__equal_tag, __equal_to, _Tp, _Up> = true; - -// The definition is required because __less is part of the ABI, but it's empty -// because all comparisons should be transparent. -template -struct __less {}; - -template <> -struct __less { - template - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __lhs, const _Up& __rhs) const { - return __lhs < __rhs; - } -}; - -template -inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_COMP_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp_ref_type.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp_ref_type.h deleted file mode 100644 index bf4d07c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/comp_ref_type.h +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COMP_REF_TYPE_H -#define _LIBCPP___CXX03___ALGORITHM_COMP_REF_TYPE_H - -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__utility/declval.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __debug_less { - _Compare& __comp_; - _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {} - - template - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Up& __y) { - bool __r = __comp_(__x, __y); - if (__r) - __do_compare_assert(0, __y, __x); - return __r; - } - - template - _LIBCPP_HIDE_FROM_ABI bool operator()(_Tp& __x, _Up& __y) { - bool __r = __comp_(__x, __y); - if (__r) - __do_compare_assert(0, __y, __x); - return __r; - } - - template - inline _LIBCPP_HIDE_FROM_ABI decltype((void)std::declval<_Compare&>()(std::declval<_LHS&>(), std::declval<_RHS&>())) - __do_compare_assert(int, _LHS& __l, _RHS& __r) { - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering"); - (void)__l; - (void)__r; - } - - template - inline _LIBCPP_HIDE_FROM_ABI void __do_compare_assert(long, _LHS&, _RHS&) {} -}; - -// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference. -#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -template -using __comp_ref_type = __debug_less<_Comp>; -#else -template -using __comp_ref_type = _Comp&; -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_COMP_REF_TYPE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy.h deleted file mode 100644 index ab164a8..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy.h +++ /dev/null @@ -1,117 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_COPY_H - -#include <__cxx03/__algorithm/copy_move_common.h> -#include <__cxx03/__algorithm/for_each_segment.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/segmented_iterator.h> -#include <__cxx03/__type_traits/common_type.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter); - -template -struct __copy_impl { - template - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - while (__first != __last) { - *__result = *__first; - ++__first; - ++__result; - } - - return std::make_pair(std::move(__first), std::move(__result)); - } - - template - struct _CopySegment { - using _Traits = __segmented_iterator_traits<_InIter>; - - _OutIter& __result_; - - _LIBCPP_HIDE_FROM_ABI explicit _CopySegment(_OutIter& __result) : __result_(__result) {} - - _LIBCPP_HIDE_FROM_ABI void - operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) { - __result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second; - } - }; - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - std::__for_each_segment(__first, __last, _CopySegment<_InIter, _OutIter>(__result)); - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; - - if (__first == __last) - return std::make_pair(std::move(__first), std::move(__result)); - - auto __local_first = _Traits::__local(__result); - auto __segment_iterator = _Traits::__segment(__result); - while (true) { - auto __local_last = _Traits::__end(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iters = std::__copy<_AlgPolicy>(__first, __first + __size, __local_first); - __first = std::move(__iters.first); - - if (__first == __last) - return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); - - __local_first = _Traits::__begin(++__segment_iterator); - } - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_trivial_impl(__first, __last, __result); - } -}; - -template -pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI __copy(_InIter __first, _Sent __last, _OutIter __result) { - return std::__copy_move_unwrap_iters<__copy_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_backward.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_backward.h deleted file mode 100644 index 0a84b6e..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_backward.h +++ /dev/null @@ -1,132 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COPY_BACKWARD_H -#define _LIBCPP___CXX03___ALGORITHM_COPY_BACKWARD_H - -#include <__cxx03/__algorithm/copy_move_common.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/segmented_iterator.h> -#include <__cxx03/__type_traits/common_type.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> __copy_backward(_InIter __first, _Sent __last, _OutIter __result); - -template -struct __copy_backward_impl { - template - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - auto __original_last_iter = __last_iter; - - while (__first != __last_iter) { - *--__result = *--__last_iter; - } - - return std::make_pair(std::move(__original_last_iter), std::move(__result)); - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_InIter>; - auto __sfirst = _Traits::__segment(__first); - auto __slast = _Traits::__segment(__last); - if (__sfirst == __slast) { - auto __iters = - std::__copy_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__local(__last), std::move(__result)); - return std::make_pair(__last, __iters.second); - } - - __result = - std::__copy_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__local(__last), std::move(__result)) - .second; - --__slast; - while (__sfirst != __slast) { - __result = - std::__copy_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__end(__slast), std::move(__result)) - .second; - --__slast; - } - __result = std::__copy_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__end(__slast), std::move(__result)) - .second; - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - auto __orig_last = __last; - auto __segment_iterator = _Traits::__segment(__result); - - // When the range contains no elements, __result might not be a valid iterator - if (__first == __last) - return std::make_pair(__first, __result); - - auto __local_last = _Traits::__local(__result); - while (true) { - using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; - - auto __local_first = _Traits::__begin(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iter = std::__copy_backward<_AlgPolicy>(__last - __size, __last, __local_last).second; - __last -= __size; - - if (__first == __last) - return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); - --__segment_iterator; - __local_last = _Traits::__end(__segment_iterator); - } - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_backward_trivial_impl(__first, __last, __result); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI pair<_BidirectionalIterator1, _BidirectionalIterator2> -__copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { - return std::__copy_move_unwrap_iters<__copy_backward_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator2 -copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && - std::is_copy_constructible<_BidirectionalIterator1>::value, - "Iterators must be copy constructible."); - - return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_COPY_BACKWARD_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_if.h deleted file mode 100644 index 53a85bc..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_if.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COPY_IF_H -#define _LIBCPP___CXX03___ALGORITHM_COPY_IF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { - for (; __first != __last; ++__first) { - if (__pred(*__first)) { - *__result = *__first; - ++__result; - } - } - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_move_common.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_move_common.h deleted file mode 100644 index 8d1ba8e..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_move_common.h +++ /dev/null @@ -1,112 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COPY_MOVE_COMMON_H -#define _LIBCPP___CXX03___ALGORITHM_COPY_MOVE_COMMON_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/unwrap_iter.h> -#include <__cxx03/__algorithm/unwrap_range.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__string/constexpr_c_functions.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_always_bitcastable.h> -#include <__cxx03/__type_traits/is_constant_evaluated.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__type_traits/is_trivially_assignable.h> -#include <__cxx03/__type_traits/is_volatile.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Type traits. - -template -struct __can_lower_copy_assignment_to_memmove { - static const bool value = - // If the types are always bitcastable, it's valid to do a bitwise copy between them. - __is_always_bitcastable<_From, _To>::value && - // Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays). - is_trivially_assignable<_To&, const _From&>::value && - // `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case. - !is_volatile<_From>::value && !is_volatile<_To>::value; -}; - -template -struct __can_lower_move_assignment_to_memmove { - static const bool value = - __is_always_bitcastable<_From, _To>::value && is_trivially_assignable<_To&, _From&&>::value && - !is_volatile<_From>::value && !is_volatile<_To>::value; -}; - -// `memmove` algorithms implementation. - -template -_LIBCPP_HIDE_FROM_ABI pair<_In*, _Out*> __copy_trivial_impl(_In* __first, _In* __last, _Out* __result) { - const size_t __n = static_cast(__last - __first); - - std::__constexpr_memmove(__result, __first, __element_count(__n)); - - return std::make_pair(__last, __result + __n); -} - -template -_LIBCPP_HIDE_FROM_ABI pair<_In*, _Out*> __copy_backward_trivial_impl(_In* __first, _In* __last, _Out* __result) { - const size_t __n = static_cast(__last - __first); - __result -= __n; - - std::__constexpr_memmove(__result, __first, __element_count(__n)); - - return std::make_pair(__last, __result); -} - -// Iterator unwrapping and dispatching to the correct overload. - -template -struct __can_rewrap - : integral_constant::value && is_copy_constructible<_OutIter>::value> {}; - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> -__copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) { - auto __range = std::__unwrap_range(__first, std::move(__last)); - auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first)); - return std::make_pair(std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.first)), - std::__rewrap_iter(std::move(__out_first), std::move(__result.second))); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> -__copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) { - return _Algorithm()(std::move(__first), std::move(__last), std::move(__out_first)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_COPY_MOVE_COMMON_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_n.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_n.h deleted file mode 100644 index b32b908..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/copy_n.h +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COPY_N_H -#define _LIBCPP___CXX03___ALGORITHM_COPY_N_H - -#include <__cxx03/__algorithm/copy.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__utility/convert_to_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value && - !__has_random_access_iterator_category<_InputIterator>::value, - int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) { - typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; - _IntegralSize __n = __orig_n; - if (__n > 0) { - *__result = *__first; - ++__result; - for (--__n; __n > 0; --__n) { - ++__first; - *__result = *__first; - ++__result; - } - } - return __result; -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) { - typedef typename iterator_traits<_InputIterator>::difference_type difference_type; - typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; - _IntegralSize __n = __orig_n; - return std::copy(__first, __first + difference_type(__n), __result); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_COPY_N_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count.h deleted file mode 100644 index 5b05b4b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count.h +++ /dev/null @@ -1,92 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COUNT_H -#define _LIBCPP___CXX03___ALGORITHM_COUNT_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__bit/invert_if.h> -#include <__cxx03/__bit/popcount.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__fwd/bit_reference.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// generic implementation -template -_LIBCPP_HIDE_FROM_ABI typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> -__count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __r(0); - for (; __first != __last; ++__first) - if (std::__invoke(__proj, *__first) == __value) - ++__r; - return __r; -} - -// __bit_iterator implementation -template -_LIBCPP_HIDE_FROM_ABI typename __bit_iterator<_Cp, _IsConst>::difference_type -__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { - using _It = __bit_iterator<_Cp, _IsConst>; - using __storage_type = typename _It::__storage_type; - using difference_type = typename _It::difference_type; - - const int __bits_per_word = _It::__bits_per_word; - difference_type __r = 0; - // do first partial word - if (__first.__ctz_ != 0) { - __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); - __storage_type __dn = std::min(__clz_f, __n); - __storage_type __m = (__storage_type(~0) << __first.__ctz_) & (__storage_type(~0) >> (__clz_f - __dn)); - __r = std::__libcpp_popcount<__storage_type>(std::__invert_if(*__first.__seg_) & __m); - __n -= __dn; - ++__first.__seg_; - } - // do middle whole words - for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) - __r += std::__libcpp_popcount<__storage_type>(std::__invert_if(*__first.__seg_)); - // do last partial word - if (__n > 0) { - __storage_type __m = __storage_type(~0) >> (__bits_per_word - __n); - __r += std::__libcpp_popcount<__storage_type>(std::__invert_if(*__first.__seg_) & __m); - } - return __r; -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI __iter_diff_t<__bit_iterator<_Cp, _IsConst> > -__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) { - if (__value) - return std::__count_bool(__first, static_cast(__last - __first)); - return std::__count_bool(__first, static_cast(__last - __first)); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI __iter_diff_t<_InputIterator> -count(_InputIterator __first, _InputIterator __last, const _Tp& __value) { - __identity __proj; - return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_COUNT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count_if.h deleted file mode 100644 index 8a31989..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/count_if.h +++ /dev/null @@ -1,34 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_COUNT_IF_H -#define _LIBCPP___CXX03___ALGORITHM_COUNT_IF_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename iterator_traits<_InputIterator>::difference_type -count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - typename iterator_traits<_InputIterator>::difference_type __r(0); - for (; __first != __last; ++__first) - if (__pred(*__first)) - ++__r; - return __r; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_COUNT_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal.h deleted file mode 100644 index 5dbc757..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal.h +++ /dev/null @@ -1,73 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_EQUAL_H -#define _LIBCPP___CXX03___ALGORITHM_EQUAL_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/unwrap_iter.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__string/constexpr_c_functions.h> -#include <__cxx03/__type_traits/desugars_to.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_equality_comparable.h> -#include <__cxx03/__type_traits/is_volatile.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool __equal_iter_impl( - _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate& __pred) { - for (; __first1 != __last1; ++__first1, (void)++__first2) - if (!__pred(*__first1, *__first2)) - return false; - return true; -} - -template && !is_volatile<_Tp>::value && - !is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value, - int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -__equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&) { - return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1)); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { - return std::__equal_iter_impl( - std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { - return std::equal(__first1, __last1, __first2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_EQUAL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal_range.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal_range.h deleted file mode 100644 index e84b536..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/equal_range.h +++ /dev/null @@ -1,85 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_EQUAL_RANGE_H -#define _LIBCPP___CXX03___ALGORITHM_EQUAL_RANGE_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/half_positive.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/lower_bound.h> -#include <__cxx03/__algorithm/upper_bound.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__iterator/next.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_Iter, _Iter> -__equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) { - auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); - _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); - while (__len != 0) { - auto __half_len = std::__half_positive(__len); - _Iter __mid = _IterOps<_AlgPolicy>::next(__first, __half_len); - if (std::__invoke(__comp, std::__invoke(__proj, *__mid), __value)) { - __first = ++__mid; - __len -= __half_len + 1; - } else if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid))) { - __end = __mid; - __len = __half_len; - } else { - _Iter __mp1 = __mid; - return pair<_Iter, _Iter>(std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj), - std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj)); - } - } - return pair<_Iter, _Iter>(__first, __first); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _ForwardIterator> -equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); - static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); - return std::__equal_range<_ClassicAlgPolicy>( - std::move(__first), - std::move(__last), - __value, - static_cast<__comp_ref_type<_Compare> >(__comp), - std::__identity()); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _ForwardIterator> -equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::equal_range(std::move(__first), std::move(__last), __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_EQUAL_RANGE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill.h deleted file mode 100644 index c1b92dd..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill.h +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FILL_H -#define _LIBCPP___CXX03___ALGORITHM_FILL_H - -#include <__cxx03/__algorithm/fill_n.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset. - -template -inline _LIBCPP_HIDE_FROM_ABI void -__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag) { - for (; __first != __last; ++__first) - *__first = __value; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag) { - std::fill_n(__first, __last - __first, __value); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - std::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FILL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill_n.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill_n.h deleted file mode 100644 index b52f650..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/fill_n.h +++ /dev/null @@ -1,94 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FILL_N_H -#define _LIBCPP___CXX03___ALGORITHM_FILL_N_H - -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__config> -#include <__cxx03/__fwd/bit_reference.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__utility/convert_to_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset. - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value); - -template -_LIBCPP_HIDE_FROM_ABI void __fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { - using _It = __bit_iterator<_Cp, false>; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - // do first partial word - if (__first.__ctz_ != 0) { - __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); - __storage_type __dn = std::min(__clz_f, __n); - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - if (_FillVal) - *__first.__seg_ |= __m; - else - *__first.__seg_ &= ~__m; - __n -= __dn; - ++__first.__seg_; - } - // do middle whole words - __storage_type __nw = __n / __bits_per_word; - std::__fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0); - __n -= __nw * __bits_per_word; - // do last partial word - if (__n > 0) { - __first.__seg_ += __nw; - __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - if (_FillVal) - *__first.__seg_ |= __m; - else - *__first.__seg_ &= ~__m; - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> -__fill_n(__bit_iterator<_Cp, false> __first, _Size __n, const bool& __value) { - if (__n > 0) { - if (__value) - std::__fill_n_bool(__first, __n); - else - std::__fill_n_bool(__first, __n); - } - return __first + __n; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) { - for (; __n > 0; ++__first, (void)--__n) - *__first = __value; - return __first; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) { - return std::__fill_n(__first, std::__convert_to_integral(__n), __value); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_FILL_N_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find.h deleted file mode 100644 index baa8e4c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find.h +++ /dev/null @@ -1,177 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FIND_H -#define _LIBCPP___CXX03___ALGORITHM_FIND_H - -#include <__cxx03/__algorithm/find_segment_if.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__algorithm/unwrap_iter.h> -#include <__cxx03/__bit/countr.h> -#include <__cxx03/__bit/invert_if.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__fwd/bit_reference.h> -#include <__cxx03/__iterator/segmented_iterator.h> -#include <__cxx03/__string/constexpr_c_functions.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/is_signed.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/limits> - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -# include <__cxx03/cwchar> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// generic implementation -template -_LIBCPP_HIDE_FROM_ABI _Iter __find(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { - for (; __first != __last; ++__first) - if (std::__invoke(__proj, *__first) == __value) - break; - return __first; -} - -// trivially equality comparable implementations -template ::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value && - sizeof(_Tp) == 1, - int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp* __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) { - if (auto __ret = std::__constexpr_memchr(__first, __value, __last - __first)) - return __ret; - return __last; -} - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template ::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value && - sizeof(_Tp) == sizeof(wchar_t) && _LIBCPP_ALIGNOF(_Tp) >= _LIBCPP_ALIGNOF(wchar_t), - int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp* __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) { - if (auto __ret = std::__constexpr_wmemchr(__first, __value, __last - __first)) - return __ret; - return __last; -} -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -// TODO: This should also be possible to get right with different signedness -// cast integral types to allow vectorization -template ::value && !__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value && - is_integral<_Tp>::value && is_integral<_Up>::value && - is_signed<_Tp>::value == is_signed<_Up>::value, - int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp* __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) { - if (__value < numeric_limits<_Tp>::min() || __value > numeric_limits<_Tp>::max()) - return __last; - return std::__find(__first, __last, _Tp(__value), __proj); -} - -// __bit_iterator implementation -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst> -__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { - using _It = __bit_iterator<_Cp, _IsConst>; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - // do first partial word - if (__first.__ctz_ != 0) { - __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); - __storage_type __dn = std::min(__clz_f, __n); - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - __storage_type __b = std::__invert_if(*__first.__seg_) & __m; - if (__b) - return _It(__first.__seg_, static_cast(std::__countr_zero(__b))); - if (__n == __dn) - return __first + __n; - __n -= __dn; - ++__first.__seg_; - } - // do middle whole words - for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) { - __storage_type __b = std::__invert_if(*__first.__seg_); - if (__b) - return _It(__first.__seg_, static_cast(std::__countr_zero(__b))); - } - // do last partial word - if (__n > 0) { - __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b = std::__invert_if(*__first.__seg_) & __m; - if (__b) - return _It(__first.__seg_, static_cast(std::__countr_zero(__b))); - } - return _It(__first.__seg_, static_cast(__n)); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst> -__find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) { - if (static_cast(__value)) - return std::__find_bool(__first, static_cast(__last - __first)); - return std::__find_bool(__first, static_cast(__last - __first)); -} - -// segmented iterator implementation - -template -struct __find_segment; - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _SegmentedIterator -__find(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj& __proj) { - return std::__find_segment_if(std::move(__first), std::move(__last), __find_segment<_Tp>(__value), __proj); -} - -template -struct __find_segment { - const _Tp& __value_; - - _LIBCPP_HIDE_FROM_ABI __find_segment(const _Tp& __value) : __value_(__value) {} - - template - _LIBCPP_HIDE_FROM_ABI _InputIterator operator()(_InputIterator __first, _InputIterator __last, _Proj& __proj) const { - return std::__find(__first, __last, __value_, __proj); - } -}; - -// public API -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _InputIterator -find(_InputIterator __first, _InputIterator __last, const _Tp& __value) { - __identity __proj; - return std::__rewrap_iter( - __first, std::__find(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __value, __proj)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_FIND_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_end.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_end.h deleted file mode 100644 index 8045021..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_end.h +++ /dev/null @@ -1,225 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FIND_END_OF_H -#define _LIBCPP___CXX03___ALGORITHM_FIND_END_OF_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/search.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__iterator/next.h> -#include <__cxx03/__iterator/reverse_iterator.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template < class _AlgPolicy, - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Pred, - class _Proj1, - class _Proj2> -_LIBCPP_HIDE_FROM_ABI inline pair<_Iter1, _Iter1> __find_end_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - forward_iterator_tag, - forward_iterator_tag) { - // modeled after search algorithm - _Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1); // __last1 is the "default" answer - _Iter1 __match_last = __match_first; - if (__first2 == __last2) - return pair<_Iter1, _Iter1>(__match_last, __match_last); - while (true) { - while (true) { - if (__first1 == __last1) // if source exhausted return last correct answer (or __last1 if never found) - return pair<_Iter1, _Iter1>(__match_first, __match_last); - if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - } - // *__first1 matches *__first2, now match elements after here - _Iter1 __m1 = __first1; - _Iter2 __m2 = __first2; - while (true) { - if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one - __match_first = __first1; - __match_last = ++__m1; - ++__first1; - break; - } - if (++__m1 == __last1) // Source exhausted, return last answer - return pair<_Iter1, _Iter1>(__match_first, __match_last); - // mismatch, restart with a new __first - if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) { - ++__first1; - break; - } // else there is a match, check next elements - } - } -} - -template < class _IterOps, - class _Pred, - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Proj1, - class _Proj2> -_LIBCPP_HIDE_FROM_ABI _Iter1 __find_end( - _Iter1 __first1, - _Sent1 __sent1, - _Iter2 __first2, - _Sent2 __sent2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - bidirectional_iterator_tag, - bidirectional_iterator_tag) { - auto __last1 = _IterOps::next(__first1, __sent1); - auto __last2 = _IterOps::next(__first2, __sent2); - // modeled after search algorithm (in reverse) - if (__first2 == __last2) - return __last1; // Everything matches an empty sequence - _Iter1 __l1 = __last1; - _Iter2 __l2 = __last2; - --__l2; - while (true) { - // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks - while (true) { - if (__first1 == __l1) // return __last1 if no element matches *__first2 - return __last1; - if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2))) - break; - } - // *__l1 matches *__l2, now match elements before here - _Iter1 __m1 = __l1; - _Iter2 __m2 = __l2; - while (true) { - if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern) - return __m1; - if (__m1 == __first1) // Otherwise if source exhaused, pattern not found - return __last1; - - // if there is a mismatch, restart with a new __l1 - if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) { - break; - } // else there is a match, check next elements - } - } -} - -template < class _AlgPolicy, - class _Pred, - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Proj1, - class _Proj2> -_LIBCPP_HIDE_FROM_ABI _Iter1 __find_end( - _Iter1 __first1, - _Sent1 __sent1, - _Iter2 __first2, - _Sent2 __sent2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - random_access_iterator_tag, - random_access_iterator_tag) { - typedef typename iterator_traits<_Iter1>::difference_type _D1; - auto __last1 = _IterOps<_AlgPolicy>::next(__first1, __sent1); - auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __sent2); - // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern - auto __len2 = __last2 - __first2; - if (__len2 == 0) - return __last1; - auto __len1 = __last1 - __first1; - if (__len1 < __len2) - return __last1; - const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here - _Iter1 __l1 = __last1; - _Iter2 __l2 = __last2; - --__l2; - while (true) { - while (true) { - if (__s == __l1) - return __last1; - if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2))) - break; - } - _Iter1 __m1 = __l1; - _Iter2 __m2 = __l2; - while (true) { - if (__m2 == __first2) - return __m1; - // no need to check range on __m1 because __s guarantees we have enough source - if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(*--__m2))) { - break; - } - } - } -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 __find_end_classic( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate& __pred) { - auto __proj = __identity(); - return std::__find_end_impl<_ClassicAlgPolicy>( - __first1, - __last1, - __first2, - __last2, - __pred, - __proj, - __proj, - typename iterator_traits<_ForwardIterator1>::iterator_category(), - typename iterator_traits<_ForwardIterator2>::iterator_category()) - .first; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 find_end( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate __pred) { - return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 -find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::find_end(__first1, __last1, __first2, __last2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FIND_END_OF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_first_of.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_first_of.h deleted file mode 100644 index dd61fb4..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_first_of.h +++ /dev/null @@ -1,55 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FIND_FIRST_OF_H -#define _LIBCPP___CXX03___ALGORITHM_FIND_FIRST_OF_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator1 __find_first_of_ce( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate&& __pred) { - for (; __first1 != __last1; ++__first1) - for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) - if (__pred(*__first1, *__j)) - return __first1; - return __last1; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 find_first_of( - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate __pred) { - return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 find_first_of( - _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FIND_FIRST_OF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if.h deleted file mode 100644 index e7cb971..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FIND_IF_H -#define _LIBCPP___CXX03___ALGORITHM_FIND_IF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _InputIterator -find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (__pred(*__first)) - break; - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FIND_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if_not.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if_not.h deleted file mode 100644 index d3a6d7b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_if_not.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FIND_IF_NOT_H -#define _LIBCPP___CXX03___ALGORITHM_FIND_IF_NOT_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _InputIterator -find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (!__pred(*__first)) - break; - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FIND_IF_NOT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_segment_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_segment_if.h deleted file mode 100644 index 9fdf8ae..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/find_segment_if.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FIND_SEGMENT_IF_H -#define _LIBCPP___CXX03___ALGORITHM_FIND_SEGMENT_IF_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/segmented_iterator.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __find_segment_if is a utility function for optimizing iteration over segmented iterators linearly. -// [__first, __last) has to be a segmented range. __pred is expected to take a range of local iterators and the __proj. -// It returns an iterator to the first element that satisfies the predicate, or a one-past-the-end iterator if there was -// no match. __proj may be anything that should be passed to __pred, but is expected to be a projection to support -// ranges algorithms, or __identity for classic algorithms. - -template -_LIBCPP_HIDE_FROM_ABI _SegmentedIterator -__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred, _Proj& __proj) { - using _Traits = __segmented_iterator_traits<_SegmentedIterator>; - - auto __sfirst = _Traits::__segment(__first); - auto __slast = _Traits::__segment(__last); - - // We are in a single segment, so we might not be at the beginning or end - if (__sfirst == __slast) - return _Traits::__compose(__sfirst, __pred(_Traits::__local(__first), _Traits::__local(__last), __proj)); - - { // We have more than one segment. Iterate over the first segment, since we might not start at the beginning - auto __llast = _Traits::__end(__sfirst); - auto __liter = __pred(_Traits::__local(__first), __llast, __proj); - if (__liter != __llast) - return _Traits::__compose(__sfirst, __liter); - } - ++__sfirst; - - // Iterate over the segments which are guaranteed to be completely in the range - while (__sfirst != __slast) { - auto __llast = _Traits::__end(__sfirst); - auto __liter = __pred(_Traits::__begin(__sfirst), _Traits::__end(__sfirst), __proj); - if (__liter != __llast) - return _Traits::__compose(__sfirst, __liter); - ++__sfirst; - } - - // Iterate over the last segment - return _Traits::__compose(__sfirst, __pred(_Traits::__begin(__sfirst), _Traits::__local(__last), __proj)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FIND_SEGMENT_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each.h deleted file mode 100644 index 1ffb013..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each.h +++ /dev/null @@ -1,33 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FOR_EACH_H -#define _LIBCPP___CXX03___ALGORITHM_FOR_EACH_H - -#include <__cxx03/__algorithm/for_each_segment.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/segmented_iterator.h> -#include <__cxx03/__type_traits/enable_if.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _Function for_each(_InputIterator __first, _InputIterator __last, _Function __f) { - for (; __first != __last; ++__first) - __f(*__first); - return __f; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FOR_EACH_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each_segment.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each_segment.h deleted file mode 100644 index b1d54ad..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/for_each_segment.h +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_FOR_EACH_SEGMENT_H -#define _LIBCPP___CXX03___ALGORITHM_FOR_EACH_SEGMENT_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/segmented_iterator.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __for_each_segment is a utility function for optimizing iterating over segmented iterators linearly. -// __first and __last are expected to be a segmented range. __func is expected to take a range of local iterators. -// Anything that is returned from __func is ignored. - -template -_LIBCPP_HIDE_FROM_ABI void __for_each_segment(_SegmentedIterator __first, _SegmentedIterator __last, _Functor __func) { - using _Traits = __segmented_iterator_traits<_SegmentedIterator>; - - auto __sfirst = _Traits::__segment(__first); - auto __slast = _Traits::__segment(__last); - - // We are in a single segment, so we might not be at the beginning or end - if (__sfirst == __slast) { - __func(_Traits::__local(__first), _Traits::__local(__last)); - return; - } - - // We have more than one segment. Iterate over the first segment, since we might not start at the beginning - __func(_Traits::__local(__first), _Traits::__end(__sfirst)); - ++__sfirst; - // iterate over the segments which are guaranteed to be completely in the range - while (__sfirst != __slast) { - __func(_Traits::__begin(__sfirst), _Traits::__end(__sfirst)); - ++__sfirst; - } - // iterate over the last segment - __func(_Traits::__begin(__sfirst), _Traits::__local(__last)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_FOR_EACH_SEGMENT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate.h deleted file mode 100644 index 2d98820..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate.h +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_GENERATE_H -#define _LIBCPP___CXX03___ALGORITHM_GENERATE_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) { - for (; __first != __last; ++__first) - *__first = __gen(); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_GENERATE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate_n.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate_n.h deleted file mode 100644 index f1ea183..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/generate_n.h +++ /dev/null @@ -1,32 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_GENERATE_N_H -#define _LIBCPP___CXX03___ALGORITHM_GENERATE_N_H - -#include <__cxx03/__config> -#include <__cxx03/__utility/convert_to_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) { - typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; - _IntegralSize __n = __orig_n; - for (; __n > 0; ++__first, (void)--__n) - *__first = __gen(); - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_GENERATE_N_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/half_positive.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/half_positive.h deleted file mode 100644 index 6e01fce..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/half_positive.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_HALF_POSITIVE_H -#define _LIBCPP___CXX03___ALGORITHM_HALF_POSITIVE_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__type_traits/make_unsigned.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Perform division by two quickly for positive integers (llvm.org/PR39129) - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Integral __half_positive(_Integral __value) { - return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp __half_positive(_Tp __value) { - return __value / 2; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_HALF_POSITIVE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/includes.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/includes.h deleted file mode 100644 index 194f508..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/includes.h +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_INCLUDES_H -#define _LIBCPP___CXX03___ALGORITHM_INCLUDES_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI bool __includes( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Comp&& __comp, - _Proj1&& __proj1, - _Proj2&& __proj2) { - for (; __first2 != __last2; ++__first1) { - if (__first1 == __last1 || - std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1))) - return false; - if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - ++__first2; - } - return true; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -includes(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _Compare __comp) { - static_assert( - __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable"); - - return std::__includes( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - static_cast<__comp_ref_type<_Compare> >(__comp), - __identity(), - __identity()); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_INCLUDES_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/inplace_merge.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/inplace_merge.h deleted file mode 100644 index 187969d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/inplace_merge.h +++ /dev/null @@ -1,240 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_INPLACE_MERGE_H -#define _LIBCPP___CXX03___ALGORITHM_INPLACE_MERGE_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/lower_bound.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__algorithm/move.h> -#include <__cxx03/__algorithm/rotate.h> -#include <__cxx03/__algorithm/upper_bound.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__iterator/reverse_iterator.h> -#include <__cxx03/__memory/destruct_n.h> -#include <__cxx03/__memory/temporary_buffer.h> -#include <__cxx03/__memory/unique_ptr.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/new> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __invert // invert the sense of a comparison -{ -private: - _Predicate __p_; - -public: - _LIBCPP_HIDE_FROM_ABI __invert() {} - - _LIBCPP_HIDE_FROM_ABI explicit __invert(_Predicate __p) : __p_(__p) {} - - template - _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x) { - return !__p_(__x); - } - - template - _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x, const _T2& __y) { - return __p_(__y, __x); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI void __half_inplace_merge( - _InputIterator1 __first1, - _Sent1 __last1, - _InputIterator2 __first2, - _Sent2 __last2, - _OutputIterator __result, - _Compare&& __comp) { - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) { - std::__move<_AlgPolicy>(__first1, __last1, __result); - return; - } - - if (__comp(*__first2, *__first1)) { - *__result = _IterOps<_AlgPolicy>::__iter_move(__first2); - ++__first2; - } else { - *__result = _IterOps<_AlgPolicy>::__iter_move(__first1); - ++__first1; - } - } - // __first2 through __last2 are already in the right spot. -} - -template -_LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge( - _BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Compare&& __comp, - typename iterator_traits<_BidirectionalIterator>::difference_type __len1, - typename iterator_traits<_BidirectionalIterator>::difference_type __len2, - typename iterator_traits<_BidirectionalIterator>::value_type* __buff) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h2(__buff, __d); - if (__len1 <= __len2) { - value_type* __p = __buff; - for (_BidirectionalIterator __i = __first; __i != __middle; - __d.template __incr(), (void)++__i, (void)++__p) - ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i)); - std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp); - } else { - value_type* __p = __buff; - for (_BidirectionalIterator __i = __middle; __i != __last; - __d.template __incr(), (void)++__i, (void)++__p) - ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i)); - typedef reverse_iterator<_BidirectionalIterator> _RBi; - typedef reverse_iterator _Rv; - typedef __invert<_Compare> _Inverted; - std::__half_inplace_merge<_AlgPolicy>( - _Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), _Inverted(__comp)); - } -} - -template -void __inplace_merge( - _BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Compare&& __comp, - typename iterator_traits<_BidirectionalIterator>::difference_type __len1, - typename iterator_traits<_BidirectionalIterator>::difference_type __len2, - typename iterator_traits<_BidirectionalIterator>::value_type* __buff, - ptrdiff_t __buff_size) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - while (true) { - // if __middle == __last, we're done - if (__len2 == 0) - return; - if (__len1 <= __buff_size || __len2 <= __buff_size) - return std::__buffered_inplace_merge<_AlgPolicy>(__first, __middle, __last, __comp, __len1, __len2, __buff); - // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 - for (; true; ++__first, (void)--__len1) { - if (__len1 == 0) - return; - if (__comp(*__middle, *__first)) - break; - } - // __first < __middle < __last - // *__first > *__middle - // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that - // all elements in: - // [__first, __m1) <= [__middle, __m2) - // [__middle, __m2) < [__m1, __middle) - // [__m1, __middle) <= [__m2, __last) - // and __m1 or __m2 is in the middle of its range - _BidirectionalIterator __m1; // "median" of [__first, __middle) - _BidirectionalIterator __m2; // "median" of [__middle, __last) - difference_type __len11; // distance(__first, __m1) - difference_type __len21; // distance(__middle, __m2) - // binary search smaller range - if (__len1 < __len2) { // __len >= 1, __len2 >= 2 - __len21 = __len2 / 2; - __m2 = __middle; - _Ops::advance(__m2, __len21); - __m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity()); - __len11 = _Ops::distance(__first, __m1); - } else { - if (__len1 == 1) { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1 - // It is known *__first > *__middle - _Ops::iter_swap(__first, __middle); - return; - } - // __len1 >= 2, __len2 >= 1 - __len11 = __len1 / 2; - __m1 = __first; - _Ops::advance(__m1, __len11); - __m2 = std::lower_bound(__middle, __last, *__m1, __comp); - __len21 = _Ops::distance(__middle, __m2); - } - difference_type __len12 = __len1 - __len11; // distance(__m1, __middle) - difference_type __len22 = __len2 - __len21; // distance(__m2, __last) - // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) - // swap middle two partitions - __middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first; - // __len12 and __len21 now have swapped meanings - // merge smaller range with recursive call and larger with tail recursion elimination - if (__len11 + __len21 < __len12 + __len22) { - std::__inplace_merge<_AlgPolicy>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); - __first = __middle; - __middle = __m2; - __len1 = __len12; - __len2 = __len22; - } else { - std::__inplace_merge<_AlgPolicy>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); - __last = __middle; - __middle = __m1; - __len1 = __len11; - __len2 = __len21; - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI void __inplace_merge( - _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle); - difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last); - difference_type __buf_size = std::min(__len1, __len2); - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - pair __buf = std::get_temporary_buffer(__buf_size); - _LIBCPP_SUPPRESS_DEPRECATED_POP - unique_ptr __h(__buf.first); - return std::__inplace_merge<_AlgPolicy>( - std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void inplace_merge( - _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) { - std::__inplace_merge<_ClassicAlgPolicy>( - std::move(__first), std::move(__middle), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) { - std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_INPLACE_MERGE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap.h deleted file mode 100644 index a29cefe..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_IS_HEAP_H -#define _LIBCPP___CXX03___ALGORITHM_IS_HEAP_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/is_heap_until.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - return std::is_heap(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_IS_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap_until.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap_until.h deleted file mode 100644 index 6625af7..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_heap_until.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_IS_HEAP_UNTIL_H -#define _LIBCPP___CXX03___ALGORITHM_IS_HEAP_UNTIL_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __len = __last - __first; - difference_type __p = 0; - difference_type __c = 1; - _RandomAccessIterator __pp = __first; - while (__c < __len) { - _RandomAccessIterator __cp = __first + __c; - if (__comp(*__pp, *__cp)) - return __cp; - ++__c; - ++__cp; - if (__c == __len) - return __last; - if (__comp(*__pp, *__cp)) - return __cp; - ++__p; - ++__pp; - __c = 2 * __p + 1; - } - return __last; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) { - return std::__is_heap_until(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_IS_HEAP_UNTIL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_partitioned.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_partitioned.h deleted file mode 100644 index c4547d3..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_partitioned.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_IS_PARTITIONED_H -#define _LIBCPP___CXX03___ALGORITHM_IS_PARTITIONED_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool -is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (!__pred(*__first)) - break; - if (__first == __last) - return true; - ++__first; - for (; __first != __last; ++__first) - if (__pred(*__first)) - return false; - return true; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_IS_PARTITIONED_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_permutation.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_permutation.h deleted file mode 100644 index 9402fdf..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_permutation.h +++ /dev/null @@ -1,254 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_IS_PERMUTATION_H -#define _LIBCPP___CXX03___ALGORITHM_IS_PERMUTATION_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__iterator/next.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _ConstTimeDistance : false_type {}; - -template -struct _ConstTimeDistance< - _Iter1, - _Iter1, - _Iter2, - _Iter2, - __enable_if_t< is_same::iterator_category, random_access_iterator_tag>::value && - is_same::iterator_category, random_access_iterator_tag>::value > > - : true_type {}; - -// Internal functions - -// For each element in [f1, l1) see if there are the same number of equal elements in [f2, l2) -template -_LIBCPP_HIDE_FROM_ABI bool __is_permutation_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2) { - using _D1 = __iter_diff_t<_Iter1>; - - for (auto __i = __first1; __i != __last1; ++__i) { - // Have we already counted the number of *__i in [f1, l1)? - auto __match = __first1; - for (; __match != __i; ++__match) { - if (std::__invoke(__pred, std::__invoke(__proj1, *__match), std::__invoke(__proj1, *__i))) - break; - } - - if (__match == __i) { - // Count number of *__i in [f2, l2) - _D1 __c2 = 0; - for (auto __j = __first2; __j != __last2; ++__j) { - if (std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj2, *__j))) - ++__c2; - } - if (__c2 == 0) - return false; - - // Count number of *__i in [__i, l1) (we can start with 1) - _D1 __c1 = 1; - for (auto __j = _IterOps<_AlgPolicy>::next(__i); __j != __last1; ++__j) { - if (std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj1, *__j))) - ++__c1; - } - if (__c1 != __c2) - return false; - } - } - - return true; -} - -// 2+1 iterators, predicate. Not used by range algorithms. -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool __is_permutation( - _ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) { - // Shorten sequences as much as possible by lopping of any equal prefix. - for (; __first1 != __last1; ++__first1, (void)++__first2) { - if (!__pred(*__first1, *__first2)) - break; - } - - if (__first1 == __last1) - return true; - - // __first1 != __last1 && *__first1 != *__first2 - using _D1 = __iter_diff_t<_ForwardIterator1>; - _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1); - if (__l1 == _D1(1)) - return false; - auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __l1); - - return std::__is_permutation_impl<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __identity(), - __identity()); -} - -// 2+2 iterators, predicate, non-constant time `distance`. -template -_LIBCPP_HIDE_FROM_ABI bool __is_permutation( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2, - /*_ConstTimeDistance=*/false_type) { - // Shorten sequences as much as possible by lopping of any equal prefix. - while (__first1 != __last1 && __first2 != __last2) { - if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - ++__first2; - } - - if (__first1 == __last1) - return __first2 == __last2; - if (__first2 == __last2) // Second range is shorter - return false; - - using _D1 = __iter_diff_t<_Iter1>; - _D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1); - - using _D2 = __iter_diff_t<_Iter2>; - _D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2); - if (__l1 != __l2) - return false; - - return std::__is_permutation_impl<_AlgPolicy>( - std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2); -} - -// 2+2 iterators, predicate, specialization for constant-time `distance` call. -template -_LIBCPP_HIDE_FROM_ABI bool __is_permutation( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2, - /*_ConstTimeDistance=*/true_type) { - if (std::distance(__first1, __last1) != std::distance(__first2, __last2)) - return false; - return std::__is_permutation<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __proj1, - __proj2, - /*_ConstTimeDistance=*/false_type()); -} - -// 2+2 iterators, predicate -template -_LIBCPP_HIDE_FROM_ABI bool __is_permutation( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred&& __pred, - _Proj1&& __proj1, - _Proj2&& __proj2) { - return std::__is_permutation<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - __pred, - __proj1, - __proj2, - _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2>()); -} - -// Public interface - -// 2+1 iterators, predicate -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool is_permutation( - _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, - "The predicate has to be callable"); - - return std::__is_permutation<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2), __pred); -} - -// 2+1 iterators -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { - return std::is_permutation(__first1, __last1, __first2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_IS_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted.h deleted file mode 100644 index 262b963..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_IS_SORTED_H -#define _LIBCPP___CXX03___ALGORITHM_IS_SORTED_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/is_sorted_until.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { - return std::is_sorted(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_IS_SORTED_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted_until.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted_until.h deleted file mode 100644 index 9bd3998..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/is_sorted_until.h +++ /dev/null @@ -1,51 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_IS_SORTED_UNTIL_H -#define _LIBCPP___CXX03___ALGORITHM_IS_SORTED_UNTIL_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator -__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) { - if (__comp(*__i, *__first)) - return __i; - __first = __i; - } - } - return __last; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) { - return std::is_sorted_until(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_IS_SORTED_UNTIL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iter_swap.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iter_swap.h deleted file mode 100644 index 896a277..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iter_swap.h +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_ITER_SWAP_H -#define _LIBCPP___CXX03___ALGORITHM_ITER_SWAP_H - -#include <__cxx03/__config> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/swap.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) { - swap(*__a, *__b); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_ITER_SWAP_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iterator_operations.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iterator_operations.h deleted file mode 100644 index b824928..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/iterator_operations.h +++ /dev/null @@ -1,192 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_ITERATOR_OPERATIONS_H -#define _LIBCPP___CXX03___ALGORITHM_ITERATOR_OPERATIONS_H - -#include <__cxx03/__algorithm/iter_swap.h> -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__iterator/next.h> -#include <__cxx03/__iterator/prev.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_reference.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/remove_cvref.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/forward.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _IterOps; - -struct _ClassicAlgPolicy {}; - -template <> -struct _IterOps<_ClassicAlgPolicy> { - template - using __value_type = typename iterator_traits<_Iter>::value_type; - - template - using __iterator_category = typename iterator_traits<_Iter>::iterator_category; - - template - using __difference_type = typename iterator_traits<_Iter>::difference_type; - - // advance - template - _LIBCPP_HIDE_FROM_ABI static void advance(_Iter& __iter, _Distance __count) { - std::advance(__iter, __count); - } - - // distance - template - _LIBCPP_HIDE_FROM_ABI static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) { - return std::distance(__first, __last); - } - - template - using __deref_t = decltype(*std::declval<_Iter&>()); - - template - using __move_t = decltype(std::move(*std::declval<_Iter&>())); - - template - _LIBCPP_HIDE_FROM_ABI static void __validate_iter_reference() { - static_assert( - is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_t<_Iter> >::reference>::value, - "It looks like your iterator's `iterator_traits::reference` does not match the return type of " - "dereferencing the iterator, i.e., calling `*it`. This is undefined behavior according to [input.iterators] " - "and can lead to dangling reference issues at runtime, so we are flagging this."); - } - - // iter_move - template >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI static - // If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it. - // Note that the C++03 mode doesn't support `decltype(auto)` as the return type. - __move_t<_Iter> - __iter_move(_Iter&& __i) { - __validate_iter_reference<_Iter>(); - - return std::move(*std::forward<_Iter>(__i)); - } - - template >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI static - // If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a - // value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to - // that temporary. Note that the C++03 mode doesn't support `auto` as the return type. - __deref_t<_Iter> - __iter_move(_Iter&& __i) { - __validate_iter_reference<_Iter>(); - - return *std::forward<_Iter>(__i); - } - - // iter_swap - template - _LIBCPP_HIDE_FROM_ABI static void iter_swap(_Iter1&& __a, _Iter2&& __b) { - std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b)); - } - - // next - template - _LIBCPP_HIDE_FROM_ABI static _Iterator next(_Iterator, _Iterator __last) { - return __last; - } - - template - _LIBCPP_HIDE_FROM_ABI static __remove_cvref_t<_Iter> - next(_Iter&& __it, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) { - return std::next(std::forward<_Iter>(__it), __n); - } - - // prev - template - _LIBCPP_HIDE_FROM_ABI static __remove_cvref_t<_Iter> - prev(_Iter&& __iter, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) { - return std::prev(std::forward<_Iter>(__iter), __n); - } - - template - _LIBCPP_HIDE_FROM_ABI static void __advance_to(_Iter& __first, _Iter __last) { - __first = __last; - } - - // advance with sentinel, a la std::ranges::advance - template - _LIBCPP_HIDE_FROM_ABI static __difference_type<_Iter> - __advance_to(_Iter& __iter, __difference_type<_Iter> __count, const _Iter& __sentinel) { - return _IterOps::__advance_to(__iter, __count, __sentinel, typename iterator_traits<_Iter>::iterator_category()); - } - -private: - // advance with sentinel, a la std::ranges::advance -- InputIterator specialization - template - _LIBCPP_HIDE_FROM_ABI static __difference_type<_InputIter> __advance_to( - _InputIter& __iter, __difference_type<_InputIter> __count, const _InputIter& __sentinel, input_iterator_tag) { - __difference_type<_InputIter> __dist = 0; - for (; __dist < __count && __iter != __sentinel; ++__dist) - ++__iter; - return __count - __dist; - } - - // advance with sentinel, a la std::ranges::advance -- BidirectionalIterator specialization - template - _LIBCPP_HIDE_FROM_ABI static __difference_type<_BiDirIter> - __advance_to(_BiDirIter& __iter, - __difference_type<_BiDirIter> __count, - const _BiDirIter& __sentinel, - bidirectional_iterator_tag) { - __difference_type<_BiDirIter> __dist = 0; - if (__count >= 0) - for (; __dist < __count && __iter != __sentinel; ++__dist) - ++__iter; - else - for (__count = -__count; __dist < __count && __iter != __sentinel; ++__dist) - --__iter; - return __count - __dist; - } - - // advance with sentinel, a la std::ranges::advance -- RandomIterator specialization - template - _LIBCPP_HIDE_FROM_ABI static __difference_type<_RandIter> - __advance_to(_RandIter& __iter, - __difference_type<_RandIter> __count, - const _RandIter& __sentinel, - random_access_iterator_tag) { - auto __dist = _IterOps::distance(__iter, __sentinel); - _LIBCPP_ASSERT_VALID_INPUT_RANGE( - __count == 0 || (__dist < 0) == (__count < 0), "__sentinel must precede __iter when __count < 0"); - if (__count < 0) - __dist = __dist > __count ? __dist : __count; - else - __dist = __dist < __count ? __dist : __count; - __iter += __dist; - return __count - __dist; - } -}; - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_ITERATOR_OPERATIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lexicographical_compare.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lexicographical_compare.h deleted file mode 100644 index 0d991c9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lexicographical_compare.h +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H -#define _LIBCPP___CXX03___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI bool __lexicographical_compare( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _Compare __comp) { - for (; __first2 != __last2; ++__first1, (void)++__first2) { - if (__first1 == __last1 || __comp(*__first1, *__first2)) - return true; - if (__comp(*__first2, *__first1)) - return false; - } - return false; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool lexicographical_compare( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _Compare __comp) { - return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool lexicographical_compare( - _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lower_bound.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lower_bound.h deleted file mode 100644 index 47ae255..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/lower_bound.h +++ /dev/null @@ -1,109 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_LOWER_BOUND_H -#define _LIBCPP___CXX03___ALGORITHM_LOWER_BOUND_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/half_positive.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__type_traits/remove_reference.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _Iter __lower_bound_bisecting( - _Iter __first, - const _Type& __value, - typename iterator_traits<_Iter>::difference_type __len, - _Comp& __comp, - _Proj& __proj) { - while (__len != 0) { - auto __l2 = std::__half_positive(__len); - _Iter __m = __first; - _IterOps<_AlgPolicy>::advance(__m, __l2); - if (std::__invoke(__comp, std::__invoke(__proj, *__m), __value)) { - __first = ++__m; - __len -= __l2 + 1; - } else { - __len = __l2; - } - } - return __first; -} - -// One-sided binary search, aka meta binary search, has been in the public domain for decades, and has the general -// advantage of being \Omega(1) rather than the classic algorithm's \Omega(log(n)), with the downside of executing at -// most 2*log(n) comparisons vs the classic algorithm's exact log(n). There are two scenarios in which it really shines: -// the first one is when operating over non-random-access iterators, because the classic algorithm requires knowing the -// container's size upfront, which adds \Omega(n) iterator increments to the complexity. The second one is when you're -// traversing the container in order, trying to fast-forward to the next value: in that case, the classic algorithm -// would yield \Omega(n*log(n)) comparisons and, for non-random-access iterators, \Omega(n^2) iterator increments, -// whereas the one-sided version will yield O(n) operations on both counts, with a \Omega(log(n)) bound on the number of -// comparisons. -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _ForwardIterator -__lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { - // step = 0, ensuring we can always short-circuit when distance is 1 later on - if (__first == __last || !std::__invoke(__comp, std::__invoke(__proj, *__first), __value)) - return __first; - - using _Distance = typename iterator_traits<_ForwardIterator>::difference_type; - for (_Distance __step = 1; __first != __last; __step <<= 1) { - auto __it = __first; - auto __dist = __step - _IterOps<_AlgPolicy>::__advance_to(__it, __step, __last); - // once we reach the last range where needle can be we must start - // looking inwards, bisecting that range - if (__it == __last || !std::__invoke(__comp, std::__invoke(__proj, *__it), __value)) { - // we've already checked the previous value and it was less, we can save - // one comparison by skipping bisection - if (__dist == 1) - return __it; - return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj); - } - // range not found, move forward! - __first = __it; - } - return __first; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -__lower_bound(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { - const auto __dist = _IterOps<_AlgPolicy>::distance(__first, __last); - return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); - auto __proj = std::__identity(); - return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::lower_bound(__first, __last, __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_LOWER_BOUND_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_heap.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_heap.h deleted file mode 100644 index faa7e9e..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_heap.h +++ /dev/null @@ -1,59 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MAKE_HEAP_H -#define _LIBCPP___CXX03___ALGORITHM_MAKE_HEAP_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/sift_down.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void -__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - __comp_ref_type<_Compare> __comp_ref = __comp; - - using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; - difference_type __n = __last - __first; - if (__n > 1) { - // start from the first parent, there is no need to consider children - for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start) { - std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::make_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_MAKE_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_projected.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_projected.h deleted file mode 100644 index 592f6d6..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/make_projected.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MAKE_PROJECTED_H -#define _LIBCPP___CXX03___ALGORITHM_MAKE_PROJECTED_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__type_traits/decay.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/integral_constant.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_member_pointer.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _ProjectedPred { - _Pred& __pred; // Can be a unary or a binary predicate. - _Proj& __proj; - - _LIBCPP_HIDE_FROM_ABI _ProjectedPred(_Pred& __pred_arg, _Proj& __proj_arg) : __pred(__pred_arg), __proj(__proj_arg) {} - - template - typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))>::type - _LIBCPP_HIDE_FROM_ABI - operator()(_Tp&& __v) const { - return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v))); - } - - template - typename __invoke_of<_Pred&, - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())), - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))>::type _LIBCPP_HIDE_FROM_ABI - operator()(_T1&& __lhs, _T2&& __rhs) const { - return std::__invoke( - __pred, std::__invoke(__proj, std::forward<_T1>(__lhs)), std::__invoke(__proj, std::forward<_T2>(__rhs))); - } -}; - -template < - class _Pred, - class _Proj, - __enable_if_t >::value && __is_identity<__decay_t<_Proj> >::value), int> = 0> -_LIBCPP_HIDE_FROM_ABI _ProjectedPred<_Pred, _Proj> __make_projected(_Pred& __pred, _Proj& __proj) { - return _ProjectedPred<_Pred, _Proj>(__pred, __proj); -} - -// Avoid creating the functor and just use the pristine comparator -- for certain algorithms, this would enable -// optimizations that rely on the type of the comparator. Additionally, this results in less layers of indirection in -// the call stack when the comparator is invoked, even in an unoptimized build. -template < - class _Pred, - class _Proj, - __enable_if_t >::value && __is_identity<__decay_t<_Proj> >::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Pred& __make_projected(_Pred& __pred, _Proj&) { - return __pred; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_MAKE_PROJECTED_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max.h deleted file mode 100644 index 0a2e435..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max.h +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MAX_H -#define _LIBCPP___CXX03___ALGORITHM_MAX_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/max_element.h> -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI const _Tp& -max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { - return __comp(__a, __b) ? __b : __a; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI const _Tp& -max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { - return std::max(__a, __b, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_MAX_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max_element.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max_element.h deleted file mode 100644 index 710df45..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/max_element.h +++ /dev/null @@ -1,51 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MAX_ELEMENT_H -#define _LIBCPP___CXX03___ALGORITHM_MAX_ELEMENT_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert( - __has_forward_iterator_category<_ForwardIterator>::value, "std::max_element requires a ForwardIterator"); - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) - if (__comp(*__first, *__i)) - __first = __i; - } - return __first; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -max_element(_ForwardIterator __first, _ForwardIterator __last) { - return std::max_element(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_MAX_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/merge.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/merge.h deleted file mode 100644 index b5a19a8..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/merge.h +++ /dev/null @@ -1,69 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MERGE_H -#define _LIBCPP___CXX03___ALGORITHM_MERGE_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/copy.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _OutputIterator __merge( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) - return std::copy(__first1, __last1, __result); - if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__first2; - } else { - *__result = *__first1; - ++__first1; - } - } - return std::copy(__first2, __last2, __result); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -merge(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -merge(_InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::merge(__first1, __last1, __first2, __last2, __result, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_MERGE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min.h deleted file mode 100644 index f42e47b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min.h +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MIN_H -#define _LIBCPP___CXX03___ALGORITHM_MIN_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/min_element.h> -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI const _Tp& -min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { - return __comp(__b, __a) ? __b : __a; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI const _Tp& -min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { - return std::min(__a, __b, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_MIN_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min_element.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min_element.h deleted file mode 100644 index 41c0416..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/min_element.h +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MIN_ELEMENT_H -#define _LIBCPP___CXX03___ALGORITHM_MIN_ELEMENT_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) { - if (__first == __last) - return __first; - - _Iter __i = __first; - while (++__i != __last) - if (std::__invoke(__comp, std::__invoke(__proj, *__i), std::__invoke(__proj, *__first))) - __first = __i; - - return __first; -} - -template -_LIBCPP_HIDE_FROM_ABI _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) { - auto __proj = __identity(); - return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert( - __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator"); - static_assert( - __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); - - return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -min_element(_ForwardIterator __first, _ForwardIterator __last) { - return std::min_element(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_MIN_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax.h deleted file mode 100644 index ce19486..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax.h +++ /dev/null @@ -1,39 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MINMAX_H -#define _LIBCPP___CXX03___ALGORITHM_MINMAX_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/minmax_element.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI pair -minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { - return __comp(__b, __a) ? pair(__b, __a) : pair(__a, __b); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI pair -minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { - return std::minmax(__a, __b, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_MINMAX_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax_element.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax_element.h deleted file mode 100644 index 8451725..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/minmax_element.h +++ /dev/null @@ -1,99 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MINMAX_ELEMENT_H -#define _LIBCPP___CXX03___ALGORITHM_MINMAX_ELEMENT_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _MinmaxElementLessFunc { - _Comp& __comp_; - _Proj& __proj_; - -public: - _LIBCPP_HIDE_FROM_ABI _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {} - - template - _LIBCPP_HIDE_FROM_ABI bool operator()(_Iter& __it1, _Iter& __it2) { - return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2)); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI pair<_Iter, _Iter> -__minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { - auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj); - - pair<_Iter, _Iter> __result(__first, __first); - if (__first == __last || ++__first == __last) - return __result; - - if (__less(__first, __result.first)) - __result.first = __first; - else - __result.second = __first; - - while (++__first != __last) { - _Iter __i = __first; - if (++__first == __last) { - if (__less(__i, __result.first)) - __result.first = __i; - else if (!__less(__i, __result.second)) - __result.second = __i; - return __result; - } - - if (__less(__first, __i)) { - if (__less(__first, __result.first)) - __result.first = __first; - if (!__less(__i, __result.second)) - __result.second = __i; - } else { - if (__less(__i, __result.first)) - __result.first = __i; - if (!__less(__first, __result.second)) - __result.second = __first; - } - } - - return __result; -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _ForwardIterator> -minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert( - __has_forward_iterator_category<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator"); - static_assert( - __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); - auto __proj = __identity(); - return std::__minmax_element_impl(__first, __last, __comp, __proj); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _ForwardIterator> -minmax_element(_ForwardIterator __first, _ForwardIterator __last) { - return std::minmax_element(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_MINMAX_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/mismatch.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/mismatch.h deleted file mode 100644 index 3c57c1b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/mismatch.h +++ /dev/null @@ -1,171 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MISMATCH_H -#define _LIBCPP___CXX03___ALGORITHM_MISMATCH_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__algorithm/simd_utils.h> -#include <__cxx03/__algorithm/unwrap_iter.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/aliasing_iterator.h> -#include <__cxx03/__type_traits/desugars_to.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_constant_evaluated.h> -#include <__cxx03/__type_traits/is_equality_comparable.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/__utility/unreachable.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_Iter1, _Iter2> -__mismatch_loop(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - while (__first1 != __last1) { - if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - ++__first2; - } - return std::make_pair(std::move(__first1), std::move(__first2)); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_Iter1, _Iter2> -__mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2); -} - -#if _LIBCPP_VECTORIZE_ALGORITHMS - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_Iter, _Iter> -__mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) { - using __value_type = __iter_value_type<_Iter>; - constexpr size_t __unroll_count = 4; - constexpr size_t __vec_size = __native_vector_size<__value_type>; - using __vec = __simd_vector<__value_type, __vec_size>; - - if (!__libcpp_is_constant_evaluated()) { - auto __orig_first1 = __first1; - auto __last2 = __first2 + (__last1 - __first1); - while (static_cast(__last1 - __first1) >= __unroll_count * __vec_size) [[__unlikely__]] { - __vec __lhs[__unroll_count]; - __vec __rhs[__unroll_count]; - - for (size_t __i = 0; __i != __unroll_count; ++__i) { - __lhs[__i] = std::__load_vector<__vec>(__first1 + __i * __vec_size); - __rhs[__i] = std::__load_vector<__vec>(__first2 + __i * __vec_size); - } - - for (size_t __i = 0; __i != __unroll_count; ++__i) { - if (auto __cmp_res = __lhs[__i] == __rhs[__i]; !std::__all_of(__cmp_res)) { - auto __offset = __i * __vec_size + std::__find_first_not_set(__cmp_res); - return {__first1 + __offset, __first2 + __offset}; - } - } - - __first1 += __unroll_count * __vec_size; - __first2 += __unroll_count * __vec_size; - } - - // check the remaining 0-3 vectors - while (static_cast(__last1 - __first1) >= __vec_size) { - if (auto __cmp_res = std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2); - !std::__all_of(__cmp_res)) { - auto __offset = std::__find_first_not_set(__cmp_res); - return {__first1 + __offset, __first2 + __offset}; - } - __first1 += __vec_size; - __first2 += __vec_size; - } - - if (__last1 - __first1 == 0) - return {__first1, __first2}; - - // Check if we can load elements in front of the current pointer. If that's the case load a vector at - // (last - vector_size) to check the remaining elements - if (static_cast(__first1 - __orig_first1) >= __vec_size) { - __first1 = __last1 - __vec_size; - __first2 = __last2 - __vec_size; - auto __offset = - std::__find_first_not_set(std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2)); - return {__first1 + __offset, __first2 + __offset}; - } // else loop over the elements individually - } - - __equal_to __pred; - __identity __proj; - return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj, __proj); -} - -template ::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> && - __is_identity<_Proj1>::value && __is_identity<_Proj2>::value, - int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_Tp*, _Tp*> -__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred&, _Proj1&, _Proj2&) { - return std::__mismatch_vectorized(__first1, __last1, __first2); -} - -template ::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> && - __is_identity<_Proj1>::value && __is_identity<_Proj2>::value && - __can_map_to_integer_v<_Tp> && __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value, - int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pair<_Tp*, _Tp*> -__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - if (__libcpp_is_constant_evaluated()) { - return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2); - } else { - using _Iter = __aliasing_iterator<_Tp*, __get_as_integer_type_t<_Tp>>; - auto __ret = std::__mismatch_vectorized(_Iter(__first1), _Iter(__last1), _Iter(__first2)); - return {__ret.first.__base(), __ret.second.__base()}; - } -} -#endif // _LIBCPP_VECTORIZE_ALGORITHMS - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator1, _InputIterator2> -mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { - __identity __proj; - auto __res = std::__mismatch( - std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred, __proj, __proj); - return std::make_pair(std::__rewrap_iter(__first1, __res.first), std::__rewrap_iter(__first2, __res.second)); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator1, _InputIterator2> -mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { - return std::mismatch(__first1, __last1, __first2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_MISMATCH_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move.h deleted file mode 100644 index 0c744bc..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move.h +++ /dev/null @@ -1,120 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MOVE_H -#define _LIBCPP___CXX03___ALGORITHM_MOVE_H - -#include <__cxx03/__algorithm/copy_move_common.h> -#include <__cxx03/__algorithm/for_each_segment.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/segmented_iterator.h> -#include <__cxx03/__type_traits/common_type.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> __move(_InIter __first, _Sent __last, _OutIter __result); - -template -struct __move_impl { - template - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - while (__first != __last) { - *__result = _IterOps<_AlgPolicy>::__iter_move(__first); - ++__first; - ++__result; - } - return std::make_pair(std::move(__first), std::move(__result)); - } - - template - struct _MoveSegment { - using _Traits = __segmented_iterator_traits<_InIter>; - - _OutIter& __result_; - - _LIBCPP_HIDE_FROM_ABI explicit _MoveSegment(_OutIter& __result) : __result_(__result) {} - - _LIBCPP_HIDE_FROM_ABI void - operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) { - __result_ = std::__move<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second; - } - }; - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - std::__for_each_segment(__first, __last, _MoveSegment<_InIter, _OutIter>(__result)); - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; - - if (__first == __last) - return std::make_pair(std::move(__first), std::move(__result)); - - auto __local_first = _Traits::__local(__result); - auto __segment_iterator = _Traits::__segment(__result); - while (true) { - auto __local_last = _Traits::__end(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iters = std::__move<_AlgPolicy>(__first, __first + __size, __local_first); - __first = std::move(__iters.first); - - if (__first == __last) - return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second))); - - __local_first = _Traits::__begin(++__segment_iterator); - } - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_trivial_impl(__first, __last, __result); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> __move(_InIter __first, _Sent __last, _OutIter __result) { - return std::__copy_move_unwrap_iters<__move_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - static_assert(is_copy_constructible<_InputIterator>::value, "Iterators has to be copy constructible."); - static_assert(is_copy_constructible<_OutputIterator>::value, "The output iterator has to be copy constructible."); - - return std::__move<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_MOVE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move_backward.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move_backward.h deleted file mode 100644 index 61e29c5..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/move_backward.h +++ /dev/null @@ -1,133 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_MOVE_BACKWARD_H -#define _LIBCPP___CXX03___ALGORITHM_MOVE_BACKWARD_H - -#include <__cxx03/__algorithm/copy_move_common.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/segmented_iterator.h> -#include <__cxx03/__type_traits/common_type.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_BidirectionalIterator1, _BidirectionalIterator2> -__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result); - -template -struct __move_backward_impl { - template - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - auto __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - auto __original_last_iter = __last_iter; - - while (__first != __last_iter) { - *--__result = _IterOps<_AlgPolicy>::__iter_move(--__last_iter); - } - - return std::make_pair(std::move(__original_last_iter), std::move(__result)); - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_InIter>; - auto __sfirst = _Traits::__segment(__first); - auto __slast = _Traits::__segment(__last); - if (__sfirst == __slast) { - auto __iters = - std::__move_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__local(__last), std::move(__result)); - return std::make_pair(__last, __iters.second); - } - - __result = - std::__move_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__local(__last), std::move(__result)) - .second; - --__slast; - while (__sfirst != __slast) { - __result = - std::__move_backward<_AlgPolicy>(_Traits::__begin(__slast), _Traits::__end(__slast), std::move(__result)) - .second; - --__slast; - } - __result = std::__move_backward<_AlgPolicy>(_Traits::__local(__first), _Traits::__end(__slast), std::move(__result)) - .second; - return std::make_pair(__last, std::move(__result)); - } - - template ::value && - !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_InIter, _OutIter> operator()(_InIter __first, _InIter __last, _OutIter __result) const { - using _Traits = __segmented_iterator_traits<_OutIter>; - using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type; - - // When the range contains no elements, __result might not be a valid iterator - if (__first == __last) - return std::make_pair(__first, __result); - - auto __orig_last = __last; - - auto __local_last = _Traits::__local(__result); - auto __segment_iterator = _Traits::__segment(__result); - while (true) { - auto __local_first = _Traits::__begin(__segment_iterator); - auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iter = std::__move_backward<_AlgPolicy>(__last - __size, __last, __local_last).second; - __last -= __size; - - if (__first == __last) - return std::make_pair(std::move(__orig_last), _Traits::__compose(__segment_iterator, std::move(__iter))); - - __local_last = _Traits::__end(--__segment_iterator); - } - } - - // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair<_In*, _Out*> operator()(_In* __first, _In* __last, _Out* __result) const { - return std::__copy_backward_trivial_impl(__first, __last, __result); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI pair<_BidirectionalIterator1, _BidirectionalIterator2> -__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { - static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && - std::is_copy_constructible<_BidirectionalIterator1>::value, - "Iterators must be copy constructible."); - - return std::__copy_move_unwrap_iters<__move_backward_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator2 -move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_MOVE_BACKWARD_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/next_permutation.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/next_permutation.h deleted file mode 100644 index 12c6c51..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/next_permutation.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_NEXT_PERMUTATION_H -#define _LIBCPP___CXX03___ALGORITHM_NEXT_PERMUTATION_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/reverse.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_BidirectionalIterator, bool> -__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) { - using _Result = pair<_BidirectionalIterator, bool>; - - _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - _BidirectionalIterator __i = __last_iter; - if (__first == __last || __first == --__i) - return _Result(std::move(__last_iter), false); - - while (true) { - _BidirectionalIterator __ip1 = __i; - if (__comp(*--__i, *__ip1)) { - _BidirectionalIterator __j = __last_iter; - while (!__comp(*__i, *--__j)) - ; - _IterOps<_AlgPolicy>::iter_swap(__i, __j); - std::__reverse<_AlgPolicy>(__ip1, __last_iter); - return _Result(std::move(__last_iter), true); - } - if (__i == __first) { - std::__reverse<_AlgPolicy>(__first, __last_iter); - return _Result(std::move(__last_iter), false); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool -next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - return std::__next_permutation<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { - return std::next_permutation(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_NEXT_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/none_of.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/none_of.h deleted file mode 100644 index 6672d5c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/none_of.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_NONE_OF_H -#define _LIBCPP___CXX03___ALGORITHM_NONE_OF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool -none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (__pred(*__first)) - return false; - return true; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_NONE_OF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/nth_element.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/nth_element.h deleted file mode 100644 index e39540f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/nth_element.h +++ /dev/null @@ -1,261 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_NTH_ELEMENT_H -#define _LIBCPP___CXX03___ALGORITHM_NTH_ELEMENT_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/sort.h> -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__debug_utils/randomize_range.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI bool __nth_element_find_guard( - _RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator __m, _Compare __comp) { - // manually guard downward moving __j against __i - while (true) { - if (__i == --__j) { - return false; - } - if (__comp(*__j, *__m)) { - return true; // found guard for downward moving __j, now use unguarded partition - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI void -// NOLINTNEXTLINE(readability-function-cognitive-complexity) -__nth_element( - _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - // _Compare is known to be a reference type - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - const difference_type __limit = 7; - while (true) { - if (__nth == __last) - return; - difference_type __len = __last - __first; - switch (__len) { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - _Ops::iter_swap(__first, __last); - return; - case 3: { - _RandomAccessIterator __m = __first; - std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp); - return; - } - } - if (__len <= __limit) { - std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp); - return; - } - // __len > __limit >= 3 - _RandomAccessIterator __m = __first + __len / 2; - _RandomAccessIterator __lm1 = __last; - unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp); - // *__m is median - // partition [__first, __m) < *__m and *__m <= [__m, __last) - // (this inhibits tossing elements equivalent to __m around unnecessarily) - _RandomAccessIterator __i = __first; - _RandomAccessIterator __j = __lm1; - // j points beyond range to be tested, *__lm1 is known to be <= *__m - // The search going up is known to be guarded but the search coming down isn't. - // Prime the downward search with a guard. - if (!__comp(*__i, *__m)) // if *__first == *__m - { - // *__first == *__m, *__first doesn't go in first part - if (std::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) { - _Ops::iter_swap(__i, __j); - ++__n_swaps; - } else { - // *__first == *__m, *__m <= all other elements - // Partition instead into [__first, __i) == *__first and *__first < [__i, __last) - ++__i; // __first + 1 - __j = __last; - if (!__comp(*__first, *--__j)) { // we need a guard if *__first == *(__last-1) - while (true) { - if (__i == __j) { - return; // [__first, __last) all equivalent elements - } else if (__comp(*__first, *__i)) { - _Ops::iter_swap(__i, __j); - ++__n_swaps; - ++__i; - break; - } - ++__i; - } - } - // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 - if (__i == __j) { - return; - } - while (true) { - while (!__comp(*__first, *__i)) { - ++__i; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __i != __last, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __j != __first, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__j; - } while (__comp(*__first, *__j)); - if (__i >= __j) - break; - _Ops::iter_swap(__i, __j); - ++__n_swaps; - ++__i; - } - // [__first, __i) == *__first and *__first < [__i, __last) - // The first part is sorted, - if (__nth < __i) { - return; - } - // __nth_element the second part - // std::__nth_element<_Compare>(__i, __nth, __last, __comp); - __first = __i; - continue; - } - } - ++__i; - // j points beyond range to be tested, *__lm1 is known to be <= *__m - // if not yet partitioned... - if (__i < __j) { - // known that *(__i - 1) < *__m - while (true) { - // __m still guards upward moving __i - while (__comp(*__i, *__m)) { - ++__i; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __i != __last, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } - // It is now known that a guard exists for downward moving __j - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __j != __first, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__j; - } while (!__comp(*__j, *__m)); - if (__i >= __j) - break; - _Ops::iter_swap(__i, __j); - ++__n_swaps; - // It is known that __m != __j - // If __m just moved, follow it - if (__m == __i) - __m = __j; - ++__i; - } - } - // [__first, __i) < *__m and *__m <= [__i, __last) - if (__i != __m && __comp(*__m, *__i)) { - _Ops::iter_swap(__i, __m); - ++__n_swaps; - } - // [__first, __i) < *__i and *__i <= [__i+1, __last) - if (__nth == __i) - return; - if (__n_swaps == 0) { - // We were given a perfectly partitioned sequence. Coincidence? - if (__nth < __i) { - // Check for [__first, __i) already sorted - __j = __m = __first; - while (true) { - if (++__j == __i) { - // [__first, __i) sorted - return; - } - if (__comp(*__j, *__m)) { - // not yet sorted, so sort - break; - } - __m = __j; - } - } else { - // Check for [__i, __last) already sorted - __j = __m = __i; - while (true) { - if (++__j == __last) { - // [__i, __last) sorted - return; - } - if (__comp(*__j, *__m)) { - // not yet sorted, so sort - break; - } - __m = __j; - } - } - } - // __nth_element on range containing __nth - if (__nth < __i) { - // std::__nth_element<_Compare>(__first, __nth, __i, __comp); - __last = __i; - } else { - // std::__nth_element<_Compare>(__i+1, __nth, __last, __comp); - __first = ++__i; - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI void __nth_element_impl( - _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare& __comp) { - if (__nth == __last) - return; - - std::__debug_randomize_range<_AlgPolicy>(__first, __last); - - std::__nth_element<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __nth, __last, __comp); - - std::__debug_randomize_range<_AlgPolicy>(__first, __nth); - if (__nth != __last) { - std::__debug_randomize_range<_AlgPolicy>(++__nth, __last); - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { - std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) { - std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_NTH_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort.h deleted file mode 100644 index 56cb9e0..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort.h +++ /dev/null @@ -1,91 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_PARTIAL_SORT_H -#define _LIBCPP___CXX03___ALGORITHM_PARTIAL_SORT_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/make_heap.h> -#include <__cxx03/__algorithm/sift_down.h> -#include <__cxx03/__algorithm/sort_heap.h> -#include <__cxx03/__config> -#include <__cxx03/__debug_utils/randomize_range.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/is_assignable.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator __partial_sort_impl( - _RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) { - if (__first == __middle) { - return _IterOps<_AlgPolicy>::next(__middle, __last); - } - - std::__make_heap<_AlgPolicy>(__first, __middle, __comp); - - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first; - _RandomAccessIterator __i = __middle; - for (; __i != __last; ++__i) { - if (__comp(*__i, *__first)) { - _IterOps<_AlgPolicy>::iter_swap(__i, __first); - std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first); - } - } - std::__sort_heap<_AlgPolicy>(std::move(__first), std::move(__middle), __comp); - - return __i; -} - -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare& __comp) { - if (__first == __middle) - return _IterOps<_AlgPolicy>::next(__middle, __last); - - std::__debug_randomize_range<_AlgPolicy>(__first, __last); - - auto __last_iter = - std::__partial_sort_impl<_AlgPolicy>(__first, __middle, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); - - std::__debug_randomize_range<_AlgPolicy>(__middle, __last); - - return __last_iter; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void partial_sort( - _RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - (void)std::__partial_sort<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) { - std::partial_sort(__first, __middle, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_PARTIAL_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort_copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort_copy.h deleted file mode 100644 index e0846dc..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partial_sort_copy.h +++ /dev/null @@ -1,106 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_PARTIAL_SORT_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_PARTIAL_SORT_COPY_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/make_heap.h> -#include <__cxx03/__algorithm/make_projected.h> -#include <__cxx03/__algorithm/sift_down.h> -#include <__cxx03/__algorithm/sort_heap.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy( - _InputIterator __first, - _Sentinel1 __last, - _RandomAccessIterator __result_first, - _Sentinel2 __result_last, - _Compare&& __comp, - _Proj1&& __proj1, - _Proj2&& __proj2) { - _RandomAccessIterator __r = __result_first; - auto&& __projected_comp = std::__make_projected(__comp, __proj2); - - if (__r != __result_last) { - for (; __first != __last && __r != __result_last; ++__first, (void)++__r) - *__r = *__first; - std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp); - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first; - for (; __first != __last; ++__first) - if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) { - *__result_first = *__first; - std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first); - } - std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp); - } - - return pair<_InputIterator, _RandomAccessIterator>( - _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _RandomAccessIterator partial_sort_copy( - _InputIterator __first, - _InputIterator __last, - _RandomAccessIterator __result_first, - _RandomAccessIterator __result_last, - _Compare __comp) { - static_assert( - __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable"); - - auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>( - __first, - __last, - __result_first, - __result_last, - static_cast<__comp_ref_type<_Compare> >(__comp), - __identity(), - __identity()); - return __result.second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _RandomAccessIterator partial_sort_copy( - _InputIterator __first, - _InputIterator __last, - _RandomAccessIterator __result_first, - _RandomAccessIterator __result_last) { - return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_PARTIAL_SORT_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition.h deleted file mode 100644 index 47fe62f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition.h +++ /dev/null @@ -1,90 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_PARTITION_H -#define _LIBCPP___CXX03___ALGORITHM_PARTITION_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _ForwardIterator> -__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) { - while (true) { - if (__first == __last) - return std::make_pair(std::move(__first), std::move(__first)); - if (!__pred(*__first)) - break; - ++__first; - } - - _ForwardIterator __p = __first; - while (++__p != __last) { - if (__pred(*__p)) { - _IterOps<_AlgPolicy>::iter_swap(__first, __p); - ++__first; - } - } - return std::make_pair(std::move(__first), std::move(__p)); -} - -template -_LIBCPP_HIDE_FROM_ABI pair<_BidirectionalIterator, _BidirectionalIterator> -__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, bidirectional_iterator_tag) { - _BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel); - _BidirectionalIterator __last = __original_last; - - while (true) { - while (true) { - if (__first == __last) - return std::make_pair(std::move(__first), std::move(__original_last)); - if (!__pred(*__first)) - break; - ++__first; - } - do { - if (__first == --__last) - return std::make_pair(std::move(__first), std::move(__original_last)); - } while (!__pred(*__last)); - _IterOps<_AlgPolicy>::iter_swap(__first, __last); - ++__first; - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _ForwardIterator> -__partition(_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) { - return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>( - std::move(__first), std::move(__last), __pred, __iter_category); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category; - auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory()); - return __result.first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_PARTITION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_copy.h deleted file mode 100644 index 3781233..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_copy.h +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_PARTITION_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_PARTITION_COPY_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_OutputIterator1, _OutputIterator2> partition_copy( - _InputIterator __first, - _InputIterator __last, - _OutputIterator1 __out_true, - _OutputIterator2 __out_false, - _Predicate __pred) { - for (; __first != __last; ++__first) { - if (__pred(*__first)) { - *__out_true = *__first; - ++__out_true; - } else { - *__out_false = *__first; - ++__out_false; - } - } - return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_PARTITION_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_point.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_point.h deleted file mode 100644 index 8dc6aea..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/partition_point.h +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_PARTITION_POINT_H -#define _LIBCPP___CXX03___ALGORITHM_PARTITION_POINT_H - -#include <__cxx03/__algorithm/half_positive.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator -partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; - difference_type __len = std::distance(__first, __last); - while (__len != 0) { - difference_type __l2 = std::__half_positive(__len); - _ForwardIterator __m = __first; - std::advance(__m, __l2); - if (__pred(*__m)) { - __first = ++__m; - __len -= __l2 + 1; - } else - __len = __l2; - } - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_PARTITION_POINT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/pop_heap.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/pop_heap.h deleted file mode 100644 index ed0d1f1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/pop_heap.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_POP_HEAP_H -#define _LIBCPP___CXX03___ALGORITHM_POP_HEAP_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/push_heap.h> -#include <__cxx03/__algorithm/sift_down.h> -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/is_assignable.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void -__pop_heap(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare& __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len) { - // Calling `pop_heap` on an empty range is undefined behavior, but in practice it will be a no-op. - _LIBCPP_ASSERT_PEDANTIC(__len > 0, "The heap given to pop_heap must be non-empty"); - - __comp_ref_type<_Compare> __comp_ref = __comp; - - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - if (__len > 1) { - value_type __top = _IterOps<_AlgPolicy>::__iter_move(__first); // create a hole at __first - _RandomAccessIterator __hole = std::__floyd_sift_down<_AlgPolicy>(__first, __comp_ref, __len); - --__last; - - if (__hole == __last) { - *__hole = std::move(__top); - } else { - *__hole = _IterOps<_AlgPolicy>::__iter_move(__last); - ++__hole; - *__last = std::move(__top); - std::__sift_up<_AlgPolicy>(__first, __hole, __comp_ref, __hole - __first); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first; - std::__pop_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp, __len); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::pop_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_POP_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/prev_permutation.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/prev_permutation.h deleted file mode 100644 index a617377..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/prev_permutation.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_PREV_PERMUTATION_H -#define _LIBCPP___CXX03___ALGORITHM_PREV_PERMUTATION_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/reverse.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_BidirectionalIterator, bool> -__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) { - using _Result = pair<_BidirectionalIterator, bool>; - - _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); - _BidirectionalIterator __i = __last_iter; - if (__first == __last || __first == --__i) - return _Result(std::move(__last_iter), false); - - while (true) { - _BidirectionalIterator __ip1 = __i; - if (__comp(*__ip1, *--__i)) { - _BidirectionalIterator __j = __last_iter; - while (!__comp(*--__j, *__i)) - ; - _IterOps<_AlgPolicy>::iter_swap(__i, __j); - std::__reverse<_AlgPolicy>(__ip1, __last_iter); - return _Result(std::move(__last_iter), true); - } - if (__i == __first) { - std::__reverse<_AlgPolicy>(__first, __last_iter); - return _Result(std::move(__last_iter), false); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool -prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - return std::__prev_permutation<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { - return std::prev_permutation(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_PREV_PERMUTATION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/push_heap.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/push_heap.h deleted file mode 100644 index eb4dc36..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/push_heap.h +++ /dev/null @@ -1,83 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_PUSH_HEAP_H -#define _LIBCPP___CXX03___ALGORITHM_PUSH_HEAP_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/is_assignable.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI void -__sift_up(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare&& __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len) { - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - - if (__len > 1) { - __len = (__len - 2) / 2; - _RandomAccessIterator __ptr = __first + __len; - - if (__comp(*__ptr, *--__last)) { - value_type __t(_IterOps<_AlgPolicy>::__iter_move(__last)); - do { - *__last = _IterOps<_AlgPolicy>::__iter_move(__ptr); - __last = __ptr; - if (__len == 0) - break; - __len = (__len - 1) / 2; - __ptr = __first + __len; - } while (__comp(*__ptr, __t)); - - *__last = std::move(__t); - } - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -__push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { - typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first; - std::__sift_up<_AlgPolicy, __comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp, __len); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - std::__push_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::push_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_PUSH_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove.h deleted file mode 100644 index c5dc7aa..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove.h +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REMOVE_H -#define _LIBCPP___CXX03___ALGORITHM_REMOVE_H - -#include <__cxx03/__algorithm/find.h> -#include <__cxx03/__algorithm/find_if.h> -#include <__cxx03/__config> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _ForwardIterator -remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - __first = std::find(__first, __last, __value); - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) { - if (!(*__i == __value)) { - *__first = std::move(*__i); - ++__first; - } - } - } - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_REMOVE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy.h deleted file mode 100644 index 7360f53..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REMOVE_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_REMOVE_COPY_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value) { - for (; __first != __last; ++__first) { - if (!(*__first == __value)) { - *__result = *__first; - ++__result; - } - } - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_REMOVE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy_if.h deleted file mode 100644 index 5993738..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_copy_if.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REMOVE_COPY_IF_H -#define _LIBCPP___CXX03___ALGORITHM_REMOVE_COPY_IF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { - for (; __first != __last; ++__first) { - if (!__pred(*__first)) { - *__result = *__first; - ++__result; - } - } - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_REMOVE_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_if.h deleted file mode 100644 index c740f45..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/remove_if.h +++ /dev/null @@ -1,45 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REMOVE_IF_H -#define _LIBCPP___CXX03___ALGORITHM_REMOVE_IF_H - -#include <__cxx03/__algorithm/find_if.h> -#include <__cxx03/__config> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _ForwardIterator -remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - __first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred); - if (__first != __last) { - _ForwardIterator __i = __first; - while (++__i != __last) { - if (!__pred(*__i)) { - *__first = std::move(*__i); - ++__first; - } - } - } - return __first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_REMOVE_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace.h deleted file mode 100644 index 975bc5f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REPLACE_H -#define _LIBCPP___CXX03___ALGORITHM_REPLACE_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void -replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) { - for (; __first != __last; ++__first) - if (*__first == __old_value) - *__first = __new_value; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_REPLACE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy.h deleted file mode 100644 index 6e786c3..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REPLACE_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_REPLACE_COPY_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator replace_copy( - _InputIterator __first, - _InputIterator __last, - _OutputIterator __result, - const _Tp& __old_value, - const _Tp& __new_value) { - for (; __first != __last; ++__first, (void)++__result) - if (*__first == __old_value) - *__result = __new_value; - else - *__result = *__first; - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_REPLACE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy_if.h deleted file mode 100644 index 43bbcc0..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_copy_if.h +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REPLACE_COPY_IF_H -#define _LIBCPP___CXX03___ALGORITHM_REPLACE_COPY_IF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator replace_copy_if( - _InputIterator __first, - _InputIterator __last, - _OutputIterator __result, - _Predicate __pred, - const _Tp& __new_value) { - for (; __first != __last; ++__first, (void)++__result) - if (__pred(*__first)) - *__result = __new_value; - else - *__result = *__first; - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_REPLACE_COPY_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_if.h deleted file mode 100644 index 5816b24..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/replace_if.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REPLACE_IF_H -#define _LIBCPP___CXX03___ALGORITHM_REPLACE_IF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void -replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) { - for (; __first != __last; ++__first) - if (__pred(*__first)) - *__first = __new_value; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_REPLACE_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse.h deleted file mode 100644 index d5298fc..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse.h +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REVERSE_H -#define _LIBCPP___CXX03___ALGORITHM_REVERSE_H - -#include <__cxx03/__algorithm/iter_swap.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void -__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) { - while (__first != __last) { - if (__first == --__last) - break; - _IterOps<_AlgPolicy>::iter_swap(__first, __last); - ++__first; - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) { - if (__first != __last) - for (; __first < --__last; ++__first) - _IterOps<_AlgPolicy>::iter_swap(__first, __last); -} - -template -_LIBCPP_HIDE_FROM_ABI void __reverse(_BidirectionalIterator __first, _Sentinel __last) { - using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>; - std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory()); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) { - std::__reverse<_ClassicAlgPolicy>(std::move(__first), std::move(__last)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_REVERSE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse_copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse_copy.h deleted file mode 100644 index a667e8a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/reverse_copy.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_REVERSE_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_REVERSE_COPY_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) { - for (; __first != __last; ++__result) - *__result = *--__last; - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_REVERSE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate.h deleted file mode 100644 index 8e5c10a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate.h +++ /dev/null @@ -1,196 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_ROTATE_H -#define _LIBCPP___CXX03___ALGORITHM_ROTATE_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/move.h> -#include <__cxx03/__algorithm/move_backward.h> -#include <__cxx03/__algorithm/swap_ranges.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/is_trivially_assignable.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator __rotate_left(_ForwardIterator __first, _ForwardIterator __last) { - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - using _Ops = _IterOps<_AlgPolicy>; - - value_type __tmp = _Ops::__iter_move(__first); - _ForwardIterator __lm1 = std::__move<_AlgPolicy>(_Ops::next(__first), __last, __first).second; - *__lm1 = std::move(__tmp); - return __lm1; -} - -template -_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator -__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - using _Ops = _IterOps<_AlgPolicy>; - - _BidirectionalIterator __lm1 = _Ops::prev(__last); - value_type __tmp = _Ops::__iter_move(__lm1); - _BidirectionalIterator __fp1 = std::__move_backward<_AlgPolicy>(__first, __lm1, std::move(__last)).second; - *__first = std::move(__tmp); - return __fp1; -} - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator -__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { - _ForwardIterator __i = __middle; - while (true) { - _IterOps<_AlgPolicy>::iter_swap(__first, __i); - ++__first; - if (++__i == __last) - break; - if (__first == __middle) - __middle = __i; - } - _ForwardIterator __r = __first; - if (__first != __middle) { - __i = __middle; - while (true) { - _IterOps<_AlgPolicy>::iter_swap(__first, __i); - ++__first; - if (++__i == __last) { - if (__first == __middle) - break; - __i = __middle; - } else if (__first == __middle) - __middle = __i; - } - } - return __r; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _Integral __algo_gcd(_Integral __x, _Integral __y) { - do { - _Integral __t = __x % __y; - __x = __y; - __y = __t; - } while (__y); - return __x; -} - -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - using _Ops = _IterOps<_AlgPolicy>; - - const difference_type __m1 = __middle - __first; - const difference_type __m2 = _Ops::distance(__middle, __last); - if (__m1 == __m2) { - std::__swap_ranges<_AlgPolicy>(__first, __middle, __middle, __last); - return __middle; - } - const difference_type __g = std::__algo_gcd(__m1, __m2); - for (_RandomAccessIterator __p = __first + __g; __p != __first;) { - value_type __t(_Ops::__iter_move(--__p)); - _RandomAccessIterator __p1 = __p; - _RandomAccessIterator __p2 = __p1 + __m1; - do { - *__p1 = _Ops::__iter_move(__p2); - __p1 = __p2; - const difference_type __d = _Ops::distance(__p2, __last); - if (__m1 < __d) - __p2 += __m1; - else - __p2 = __first + (__m1 - __d); - } while (__p2 != __p); - *__p1 = std::move(__t); - } - return __first + __m2; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -__rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, std::forward_iterator_tag) { - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - if (is_trivially_move_assignable::value) { - if (_IterOps<_AlgPolicy>::next(__first) == __middle) - return std::__rotate_left<_AlgPolicy>(__first, __last); - } - return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __rotate_impl( - _BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - bidirectional_iterator_tag) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - if (is_trivially_move_assignable::value) { - if (_IterOps<_AlgPolicy>::next(__first) == __middle) - return std::__rotate_left<_AlgPolicy>(__first, __last); - if (_IterOps<_AlgPolicy>::next(__middle) == __last) - return std::__rotate_right<_AlgPolicy>(__first, __last); - } - return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _RandomAccessIterator __rotate_impl( - _RandomAccessIterator __first, - _RandomAccessIterator __middle, - _RandomAccessIterator __last, - random_access_iterator_tag) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - if (is_trivially_move_assignable::value) { - if (_IterOps<_AlgPolicy>::next(__first) == __middle) - return std::__rotate_left<_AlgPolicy>(__first, __last); - if (_IterOps<_AlgPolicy>::next(__middle) == __last) - return std::__rotate_right<_AlgPolicy>(__first, __last); - return std::__rotate_gcd<_AlgPolicy>(__first, __middle, __last); - } - return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last); -} - -template -_LIBCPP_HIDE_FROM_ABI pair<_Iterator, _Iterator> __rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) { - using _Ret = pair<_Iterator, _Iterator>; - _Iterator __last_iter = _IterOps<_AlgPolicy>::next(__middle, __last); - - if (__first == __middle) - return _Ret(__last_iter, __last_iter); - if (__middle == __last) - return _Ret(std::move(__first), std::move(__last_iter)); - - using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iterator>; - auto __result = std::__rotate_impl<_AlgPolicy>(std::move(__first), std::move(__middle), __last_iter, _IterCategory()); - - return _Ret(std::move(__result), std::move(__last_iter)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { - return std::__rotate<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last)).first; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_ROTATE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate_copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate_copy.h deleted file mode 100644 index 06e1fb4..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/rotate_copy.h +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_ROTATE_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_ROTATE_COPY_H - -#include <__cxx03/__algorithm/copy.h> -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) { - return std::copy(__first, __middle, std::copy(__middle, __last, __result)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_ROTATE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search.h deleted file mode 100644 index f3691de..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search.h +++ /dev/null @@ -1,182 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SEARCH_H -#define _LIBCPP___CXX03___ALGORITHM_SEARCH_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_Iter1, _Iter1> __search_forward_impl( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - if (__first2 == __last2) - return std::make_pair(__first1, __first1); // Everything matches an empty sequence - while (true) { - // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks - while (true) { - if (__first1 == __last1) { // return __last1 if no element matches *__first2 - _IterOps<_AlgPolicy>::__advance_to(__first1, __last1); - return std::make_pair(__first1, __first1); - } - if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - } - // *__first1 matches *__first2, now match elements after here - _Iter1 __m1 = __first1; - _Iter2 __m2 = __first2; - while (true) { - if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) - return std::make_pair(__first1, ++__m1); - if (++__m1 == __last1) { // Otherwise if source exhaused, pattern not found - return std::make_pair(__m1, __m1); - } - - // if there is a mismatch, restart with a new __first1 - if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) { - ++__first1; - break; - } // else there is a match, check next elements - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI pair<_Iter1, _Iter1> __search_random_access_impl( - _Iter1 __first1, - _Sent1 __last1, - _Iter2 __first2, - _Sent2 __last2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - _DiffT1 __size1, - _DiffT2 __size2) { - const _Iter1 __s = __first1 + __size1 - _DiffT1(__size2 - 1); // Start of pattern match can't go beyond here - - while (true) { - while (true) { - if (__first1 == __s) { - _IterOps<_AlgPolicy>::__advance_to(__first1, __last1); - return std::make_pair(__first1, __first1); - } - if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) - break; - ++__first1; - } - - _Iter1 __m1 = __first1; - _Iter2 __m2 = __first2; - while (true) { - if (++__m2 == __last2) - return std::make_pair(__first1, __first1 + _DiffT1(__size2)); - ++__m1; // no need to check range on __m1 because __s guarantees we have enough source - if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) { - ++__first1; - break; - } - } - } -} - -template ::value && - __has_random_access_iterator_category<_Iter2>::value, - int> = 0> -_LIBCPP_HIDE_FROM_ABI pair<_Iter1, _Iter1> __search_impl( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - auto __size2 = __last2 - __first2; - if (__size2 == 0) - return std::make_pair(__first1, __first1); - - auto __size1 = __last1 - __first1; - if (__size1 < __size2) { - return std::make_pair(__last1, __last1); - } - - return std::__search_random_access_impl<_ClassicAlgPolicy>( - __first1, __last1, __first2, __last2, __pred, __proj1, __proj2, __size1, __size2); -} - -template < - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Pred, - class _Proj1, - class _Proj2, - __enable_if_t<__has_forward_iterator_category<_Iter1>::value && __has_forward_iterator_category<_Iter2>::value && - !(__has_random_access_iterator_category<_Iter1>::value && - __has_random_access_iterator_category<_Iter2>::value), - int> = 0> -_LIBCPP_HIDE_FROM_ABI pair<_Iter1, _Iter1> __search_impl( - _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { - return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 -search(_ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _ForwardIterator2 __last2, - _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, - "BinaryPredicate has to be callable"); - auto __proj = __identity(); - return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator1 -search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::search(__first1, __last1, __first2, __last2, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_SEARCH_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search_n.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search_n.h deleted file mode 100644 index 98328c6..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/search_n.h +++ /dev/null @@ -1,153 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SEARCH_N_H -#define _LIBCPP___CXX03___ALGORITHM_SEARCH_N_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_callable.h> -#include <__cxx03/__utility/convert_to_integral.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<_Iter, _Iter> __search_n_forward_impl( - _Iter __first, _Sent __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { - if (__count <= 0) - return std::make_pair(__first, __first); - while (true) { - // Find first element in sequence that matchs __value, with a mininum of loop checks - while (true) { - if (__first == __last) { // return __last if no element matches __value - _IterOps<_AlgPolicy>::__advance_to(__first, __last); - return std::make_pair(__first, __first); - } - if (std::__invoke(__pred, std::__invoke(__proj, *__first), __value)) - break; - ++__first; - } - // *__first matches __value, now match elements after here - _Iter __m = __first; - _SizeT __c(0); - while (true) { - if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) - return std::make_pair(__first, ++__m); - if (++__m == __last) { // Otherwise if source exhaused, pattern not found - _IterOps<_AlgPolicy>::__advance_to(__first, __last); - return std::make_pair(__first, __first); - } - - // if there is a mismatch, restart with a new __first - if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) { - __first = __m; - ++__first; - break; - } // else there is a match, check next elements - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI std::pair<_Iter, _Iter> __search_n_random_access_impl( - _Iter __first, _Sent __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj, _DiffT __size1) { - using difference_type = typename iterator_traits<_Iter>::difference_type; - if (__count == 0) - return std::make_pair(__first, __first); - if (__size1 < static_cast<_DiffT>(__count)) { - _IterOps<_AlgPolicy>::__advance_to(__first, __last); - return std::make_pair(__first, __first); - } - - const auto __s = __first + __size1 - difference_type(__count - 1); // Start of pattern match can't go beyond here - while (true) { - // Find first element in sequence that matchs __value, with a mininum of loop checks - while (true) { - if (__first >= __s) { // return __last if no element matches __value - _IterOps<_AlgPolicy>::__advance_to(__first, __last); - return std::make_pair(__first, __first); - } - if (std::__invoke(__pred, std::__invoke(__proj, *__first), __value)) - break; - ++__first; - } - // *__first matches __value_, now match elements after here - auto __m = __first; - _SizeT __c(0); - while (true) { - if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) - return std::make_pair(__first, __first + _DiffT(__count)); - ++__m; // no need to check range on __m because __s guarantees we have enough source - - // if there is a mismatch, restart with a new __first - if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) { - __first = __m; - ++__first; - break; - } // else there is a match, check next elements - } - } -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI pair<_Iter, _Iter> -__search_n_impl(_Iter __first, _Sent __last, _DiffT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { - return std::__search_n_random_access_impl<_ClassicAlgPolicy>( - __first, __last, __count, __value, __pred, __proj, __last - __first); -} - -template ::value && - !__has_random_access_iterator_category<_Iter1>::value, - int> = 0> -_LIBCPP_HIDE_FROM_ABI pair<_Iter1, _Iter1> -__search_n_impl(_Iter1 __first, _Sent1 __last, _DiffT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { - return std::__search_n_forward_impl<_ClassicAlgPolicy>(__first, __last, __count, __value, __pred, __proj); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator search_n( - _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) { - static_assert( - __is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value, "BinaryPredicate has to be callable"); - auto __proj = __identity(); - return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) { - return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_SEARCH_N_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_difference.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_difference.h deleted file mode 100644 index 943b458..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_difference.h +++ /dev/null @@ -1,77 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SET_DIFFERENCE_H -#define _LIBCPP___CXX03___ALGORITHM_SET_DIFFERENCE_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/copy.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/remove_cvref.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI pair<__remove_cvref_t<_InIter1>, __remove_cvref_t<_OutIter> > __set_difference( - _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) { - while (__first1 != __last1 && __first2 != __last2) { - if (__comp(*__first1, *__first2)) { - *__result = *__first1; - ++__first1; - ++__result; - } else if (__comp(*__first2, *__first1)) { - ++__first2; - } else { - ++__first1; - ++__first2; - } - } - return std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator set_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( - __first1, __last1, __first2, __last2, __result, __comp) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator set_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::__set_difference<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __result, __less<>()).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SET_DIFFERENCE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_intersection.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_intersection.h deleted file mode 100644 index d892dad..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_intersection.h +++ /dev/null @@ -1,211 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SET_INTERSECTION_H -#define _LIBCPP___CXX03___ALGORITHM_SET_INTERSECTION_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/lower_bound.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__iterator/next.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/swap.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __set_intersection_result { - _InIter1 __in1_; - _InIter2 __in2_; - _OutIter __out_; - - // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI __set_intersection_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) - : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} -}; - -// Helper for __set_intersection() with one-sided binary search: populate result and advance input iterators if they -// are found to potentially contain the same value in two consecutive calls. This function is very intimately related to -// the way it is used and doesn't attempt to abstract that, it's not appropriate for general usage outside of its -// context. -template -_LIBCPP_HIDE_FROM_ABI void __set_intersection_add_output_if_equal( - bool __may_be_equal, - _InForwardIter1& __first1, - _InForwardIter2& __first2, - _OutIter& __result, - bool& __prev_may_be_equal) { - if (__may_be_equal && __prev_may_be_equal) { - *__result = *__first1; - ++__result; - ++__first1; - ++__first2; - __prev_may_be_equal = false; - } else { - __prev_may_be_equal = __may_be_equal; - } -} - -// With forward iterators we can make multiple passes over the data, allowing the use of one-sided binary search to -// reduce best-case complexity to log(N). Understanding how we can use binary search and still respect complexity -// guarantees is _not_ straightforward: the guarantee is "at most 2*(N+M)-1 comparisons", and one-sided binary search -// will necessarily overshoot depending on the position of the needle in the haystack -- for instance, if we're -// searching for 3 in (1, 2, 3, 4), we'll check if 3<1, then 3<2, then 3<4, and, finally, 3<3, for a total of 4 -// comparisons, when linear search would have yielded 3. However, because we won't need to perform the intervening -// reciprocal comparisons (ie 1<3, 2<3, 4<3), that extra comparison doesn't run afoul of the guarantee. Additionally, -// this type of scenario can only happen for match distances of up to 5 elements, because 2*log2(8) is 6, and we'll -// still be worse-off at position 5 of an 8-element set. From then onwards these scenarios can't happen. TL;DR: we'll be -// 1 comparison worse-off compared to the classic linear-searching algorithm if matching position 3 of a set with 4 -// elements, or position 5 if the set has 7 or 8 elements, but we'll never exceed the complexity guarantees from the -// standard. -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI __set_intersection_result<_InForwardIter1, _InForwardIter2, _OutIter> -__set_intersection( - _InForwardIter1 __first1, - _Sent1 __last1, - _InForwardIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Compare&& __comp, - std::forward_iterator_tag, - std::forward_iterator_tag) { - std::__identity __proj; - bool __prev_may_be_equal = false; - - while (__first2 != __last2) { - _InForwardIter1 __first1_next = - std::__lower_bound_onesided<_AlgPolicy>(__first1, __last1, *__first2, __comp, __proj); - std::swap(__first1_next, __first1); - // keeping in mind that a==b iff !(a(__first2, __last2, *__first1, __comp, __proj); - std::swap(__first2_next, __first2); - std::__set_intersection_add_output_if_equal( - __first2 == __first2_next, __first1, __first2, __result, __prev_may_be_equal); - } - return __set_intersection_result<_InForwardIter1, _InForwardIter2, _OutIter>( - _IterOps<_AlgPolicy>::next(std::move(__first1), std::move(__last1)), - _IterOps<_AlgPolicy>::next(std::move(__first2), std::move(__last2)), - std::move(__result)); -} - -// input iterators are not suitable for multipass algorithms, so we stick to the classic single-pass version -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI __set_intersection_result<_InInputIter1, _InInputIter2, _OutIter> -__set_intersection( - _InInputIter1 __first1, - _Sent1 __last1, - _InInputIter2 __first2, - _Sent2 __last2, - _OutIter __result, - _Compare&& __comp, - std::input_iterator_tag, - std::input_iterator_tag) { - while (__first1 != __last1 && __first2 != __last2) { - if (__comp(*__first1, *__first2)) - ++__first1; - else { - if (!__comp(*__first2, *__first1)) { - *__result = *__first1; - ++__result; - ++__first1; - } - ++__first2; - } - } - - return __set_intersection_result<_InInputIter1, _InInputIter2, _OutIter>( - _IterOps<_AlgPolicy>::next(std::move(__first1), std::move(__last1)), - _IterOps<_AlgPolicy>::next(std::move(__first2), std::move(__last2)), - std::move(__result)); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI __set_intersection_result<_InIter1, _InIter2, _OutIter> __set_intersection( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { - return std::__set_intersection<_AlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - std::forward<_Compare>(__comp), - typename std::_IterOps<_AlgPolicy>::template __iterator_category<_InIter1>(), - typename std::_IterOps<_AlgPolicy>::template __iterator_category<_InIter2>()); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator set_intersection( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_intersection<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __comp) - .__out_; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator set_intersection( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::__set_intersection<_ClassicAlgPolicy>( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __less<>()) - .__out_; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SET_INTERSECTION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_symmetric_difference.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_symmetric_difference.h deleted file mode 100644 index 82a1c46..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_symmetric_difference.h +++ /dev/null @@ -1,108 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H -#define _LIBCPP___CXX03___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/copy.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __set_symmetric_difference_result { - _InIter1 __in1_; - _InIter2 __in2_; - _OutIter __out_; - - // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI - __set_symmetric_difference_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) - : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} -}; - -template -_LIBCPP_HIDE_FROM_ABI __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> __set_symmetric_difference( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { - while (__first1 != __last1) { - if (__first2 == __last2) { - auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result)); - return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( - std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); - } - if (__comp(*__first1, *__first2)) { - *__result = *__first1; - ++__result; - ++__first1; - } else { - if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__result; - } else { - ++__first1; - } - ++__first2; - } - } - auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result)); - return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( - std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); -} - -template -_LIBCPP_HIDE_FROM_ABI _OutputIterator set_symmetric_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_symmetric_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __comp) - .__out_; -} - -template -_LIBCPP_HIDE_FROM_ABI _OutputIterator set_symmetric_difference( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::set_symmetric_difference( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_union.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_union.h deleted file mode 100644 index 3effd78..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/set_union.h +++ /dev/null @@ -1,104 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SET_UNION_H -#define _LIBCPP___CXX03___ALGORITHM_SET_UNION_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/copy.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __set_union_result { - _InIter1 __in1_; - _InIter2 __in2_; - _OutIter __out_; - - // need a constructor as C++03 aggregate init is hard - _LIBCPP_HIDE_FROM_ABI __set_union_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter) - : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} -}; - -template -_LIBCPP_HIDE_FROM_ABI __set_union_result<_InIter1, _InIter2, _OutIter> __set_union( - _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) { - auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result)); - return __set_union_result<_InIter1, _InIter2, _OutIter>( - std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); - } - if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__first2; - } else { - if (!__comp(*__first1, *__first2)) { - ++__first2; - } - *__result = *__first1; - ++__first1; - } - } - auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result)); - return __set_union_result<_InIter1, _InIter2, _OutIter>( - std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); -} - -template -_LIBCPP_HIDE_FROM_ABI _OutputIterator set_union( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - return std::__set_union<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __comp) - .__out_; -} - -template -_LIBCPP_HIDE_FROM_ABI _OutputIterator set_union( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result) { - return std::set_union( - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__last2), - std::move(__result), - __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SET_UNION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/shuffle.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/shuffle.h deleted file mode 100644 index 24cd71c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/shuffle.h +++ /dev/null @@ -1,157 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SHUFFLE_H -#define _LIBCPP___CXX03___ALGORITHM_SHUFFLE_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__random/uniform_int_distribution.h> -#include <__cxx03/__utility/forward.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/swap.h> -#include <__cxx03/cstddef> -#include <__cxx03/cstdint> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -class _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_randomizer { -public: - _LIBCPP_HIDE_FROM_ABI __libcpp_debug_randomizer() { - __state_ = __seed(); - __inc_ = __state_ + 0xda3e39cb94b95bdbULL; - __inc_ = (__inc_ << 1) | 1; - } - typedef uint_fast32_t result_type; - - static const result_type _Min = 0; - static const result_type _Max = 0xFFFFFFFF; - - _LIBCPP_HIDE_FROM_ABI result_type operator()() { - uint_fast64_t __oldstate = __state_; - __state_ = __oldstate * 6364136223846793005ULL + __inc_; - return __oldstate >> 32; - } - - static _LIBCPP_HIDE_FROM_ABI result_type min() { return _Min; } - static _LIBCPP_HIDE_FROM_ABI result_type max() { return _Max; } - -private: - uint_fast64_t __state_; - uint_fast64_t __inc_; - _LIBCPP_HIDE_FROM_ABI static uint_fast64_t __seed() { -#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED - return _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED; -#else - static char __x; - return reinterpret_cast(&__x); -#endif - } -}; - -class _LIBCPP_EXPORTED_FROM_ABI __rs_default; - -_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); - -class _LIBCPP_EXPORTED_FROM_ABI __rs_default { - static unsigned __c_; - - __rs_default(); - -public: - typedef uint_fast32_t result_type; - - static const result_type _Min = 0; - static const result_type _Max = 0xFFFFFFFF; - - __rs_default(const __rs_default&); - ~__rs_default(); - - result_type operator()(); - - static _LIBCPP_HIDE_FROM_ABI result_type min() { return _Min; } - static _LIBCPP_HIDE_FROM_ABI result_type max() { return _Max; } - - friend _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); -}; - -_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); - -template -_LIBCPP_HIDE_FROM_ABI void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef uniform_int_distribution _Dp; - typedef typename _Dp::param_type _Pp; - difference_type __d = __last - __first; - if (__d > 1) { - _Dp __uid; - __rs_default __g = __rs_get(); - for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) { - difference_type __i = __uid(__g, _Pp(0, __d)); - if (__i != difference_type(0)) - swap(*__first, *(__first + __i)); - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI void -random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomNumberGenerator& __rand) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __d = __last - __first; - if (__d > 1) { - for (--__last; __first < __last; ++__first, (void)--__d) { - difference_type __i = __rand(__d); - if (__i != difference_type(0)) - swap(*__first, *(__first + __i)); - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -__shuffle(_RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef uniform_int_distribution _Dp; - typedef typename _Dp::param_type _Pp; - - auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel); - auto __last = __original_last; - difference_type __d = __last - __first; - if (__d > 1) { - _Dp __uid; - for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) { - difference_type __i = __uid(__g, _Pp(0, __d)); - if (__i != difference_type(0)) - _IterOps<_AlgPolicy>::iter_swap(__first, __first + __i); - } - } - - return __original_last; -} - -template -_LIBCPP_HIDE_FROM_ABI void -shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _UniformRandomNumberGenerator&& __g) { - (void)std::__shuffle<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), std::forward<_UniformRandomNumberGenerator>(__g)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SHUFFLE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sift_down.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sift_down.h deleted file mode 100644 index d299b71..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sift_down.h +++ /dev/null @@ -1,118 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SIFT_DOWN_H -#define _LIBCPP___CXX03___ALGORITHM_SIFT_DOWN_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI void -__sift_down(_RandomAccessIterator __first, - _Compare&& __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - _RandomAccessIterator __start) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - // left-child of __start is at 2 * __start + 1 - // right-child of __start is at 2 * __start + 2 - difference_type __child = __start - __first; - - if (__len < 2 || (__len - 2) / 2 < __child) - return; - - __child = 2 * __child + 1; - _RandomAccessIterator __child_i = __first + __child; - - if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) { - // right-child exists and is greater than left-child - ++__child_i; - ++__child; - } - - // check if we are in heap-order - if (__comp(*__child_i, *__start)) - // we are, __start is larger than its largest child - return; - - value_type __top(_Ops::__iter_move(__start)); - do { - // we are not in heap-order, swap the parent with its largest child - *__start = _Ops::__iter_move(__child_i); - __start = __child_i; - - if ((__len - 2) / 2 < __child) - break; - - // recompute the child based off of the updated parent - __child = 2 * __child + 1; - __child_i = __first + __child; - - if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) { - // right-child exists and is greater than left-child - ++__child_i; - ++__child; - } - - // check if we are in heap-order - } while (!__comp(*__child_i, __top)); - *__start = std::move(__top); -} - -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator __floyd_sift_down( - _RandomAccessIterator __first, - _Compare&& __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len) { - using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; - _LIBCPP_ASSERT_INTERNAL(__len >= 2, "shouldn't be called unless __len >= 2"); - - _RandomAccessIterator __hole = __first; - _RandomAccessIterator __child_i = __first; - difference_type __child = 0; - - while (true) { - __child_i += difference_type(__child + 1); - __child = 2 * __child + 1; - - if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) { - // right-child exists and is greater than left-child - ++__child_i; - ++__child; - } - - // swap __hole with its largest child - *__hole = _IterOps<_AlgPolicy>::__iter_move(__child_i); - __hole = __child_i; - - // if __hole is now a leaf, we're done - if (__child > (__len - 2) / 2) - return __hole; - } -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SIFT_DOWN_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/simd_utils.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/simd_utils.h deleted file mode 100644 index 7b0e825..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/simd_utils.h +++ /dev/null @@ -1,159 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SIMD_UTILS_H -#define _LIBCPP___CXX03___ALGORITHM_SIMD_UTILS_H - -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__bit/countl.h> -#include <__cxx03/__bit/countr.h> -#include <__cxx03/__config> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__utility/integer_sequence.h> -#include <__cxx03/cstddef> -#include <__cxx03/cstdint> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -// TODO: Find out how altivec changes things and allow vectorizations there too. -#define _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS 0 - -#if _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS && !defined(__OPTIMIZE_SIZE__) -# define _LIBCPP_VECTORIZE_ALGORITHMS 1 -#else -# define _LIBCPP_VECTORIZE_ALGORITHMS 0 -#endif - -#if _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline constexpr bool __can_map_to_integer_v = - sizeof(_Tp) == alignof(_Tp) && (sizeof(_Tp) == 1 || sizeof(_Tp) == 2 || sizeof(_Tp) == 4 || sizeof(_Tp) == 8); - -template -struct __get_as_integer_type_impl; - -template <> -struct __get_as_integer_type_impl<1> { - using type = uint8_t; -}; - -template <> -struct __get_as_integer_type_impl<2> { - using type = uint16_t; -}; -template <> -struct __get_as_integer_type_impl<4> { - using type = uint32_t; -}; -template <> -struct __get_as_integer_type_impl<8> { - using type = uint64_t; -}; - -template -using __get_as_integer_type_t = typename __get_as_integer_type_impl::type; - -// This isn't specialized for 64 byte vectors on purpose. They have the potential to significantly reduce performance -// in mixed simd/non-simd workloads and don't provide any performance improvement for currently vectorized algorithms -// as far as benchmarks are concerned. -# if defined(__AVX__) || defined(__MVS__) -template -inline constexpr size_t __native_vector_size = 32 / sizeof(_Tp); -# elif defined(__SSE__) || defined(__ARM_NEON__) -template -inline constexpr size_t __native_vector_size = 16 / sizeof(_Tp); -# elif defined(__MMX__) -template -inline constexpr size_t __native_vector_size = 8 / sizeof(_Tp); -# else -template -inline constexpr size_t __native_vector_size = 1; -# endif - -template -using __simd_vector __attribute__((__ext_vector_type__(_Np))) = _ArithmeticT; - -template -inline constexpr size_t __simd_vector_size_v = []() -> size_t { - static_assert(_False, "Not a vector!"); -}(); - -template -inline constexpr size_t __simd_vector_size_v<__simd_vector<_Tp, _Np>> = _Np; - -template -_LIBCPP_HIDE_FROM_ABI _Tp __simd_vector_underlying_type_impl(__simd_vector<_Tp, _Np>) { - return _Tp{}; -} - -template -using __simd_vector_underlying_type_t = decltype(std::__simd_vector_underlying_type_impl(_VecT{})); - -// This isn't inlined without always_inline when loading chars. -template -_LIBCPP_NODISCARD _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __load_vector(_Iter __iter) noexcept { - return [=](index_sequence<_Indices...>) _LIBCPP_ALWAYS_INLINE noexcept { - return _VecT{__iter[_Indices]...}; - }(make_index_sequence<__simd_vector_size_v<_VecT>>{}); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept { - return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector)); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept { - using __mask_vec = __simd_vector; - - // This has MSan disabled du to https://github.com/llvm/llvm-project/issues/85876 - auto __impl = [&](_MaskT) _LIBCPP_NO_SANITIZE("memory") noexcept { -# if defined(_LIBCPP_BIG_ENDIAN) - return std::min( - _Np, std::__countl_zero(__builtin_bit_cast(_MaskT, __builtin_convertvector(__vec, __mask_vec)))); -# else - return std::min( - _Np, std::__countr_zero(__builtin_bit_cast(_MaskT, __builtin_convertvector(__vec, __mask_vec)))); -# endif - }; - - if constexpr (sizeof(__mask_vec) == sizeof(uint8_t)) { - return __impl(uint8_t{}); - } else if constexpr (sizeof(__mask_vec) == sizeof(uint16_t)) { - return __impl(uint16_t{}); - } else if constexpr (sizeof(__mask_vec) == sizeof(uint32_t)) { - return __impl(uint32_t{}); - } else if constexpr (sizeof(__mask_vec) == sizeof(uint64_t)) { - return __impl(uint64_t{}); - } else { - static_assert(sizeof(__mask_vec) == 0, "unexpected required size for mask integer type"); - return 0; - } -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI size_t __find_first_not_set(__simd_vector<_Tp, _Np> __vec) noexcept { - return std::__find_first_set(~__vec); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SIMD_UTILS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort.h deleted file mode 100644 index 41df4d9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort.h +++ /dev/null @@ -1,989 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SORT_H -#define _LIBCPP___CXX03___ALGORITHM_SORT_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iter_swap.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/min_element.h> -#include <__cxx03/__algorithm/partial_sort.h> -#include <__cxx03/__algorithm/unwrap_iter.h> -#include <__cxx03/__assert> -#include <__cxx03/__bit/blsr.h> -#include <__cxx03/__bit/countl.h> -#include <__cxx03/__bit/countr.h> -#include <__cxx03/__config> -#include <__cxx03/__debug_utils/randomize_range.h> -#include <__cxx03/__debug_utils/strict_weak_ordering_check.h> -#include <__cxx03/__functional/operations.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__type_traits/disjunction.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_constant_evaluated.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/climits> -#include <__cxx03/cstdint> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// stable, 2-3 compares, 0-2 swaps - -template -_LIBCPP_HIDE_FROM_ABI unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) { - using _Ops = _IterOps<_AlgPolicy>; - - unsigned __r = 0; - if (!__c(*__y, *__x)) // if x <= y - { - if (!__c(*__z, *__y)) // if y <= z - return __r; // x <= y && y <= z - // x <= y && y > z - _Ops::iter_swap(__y, __z); // x <= z && y < z - __r = 1; - if (__c(*__y, *__x)) // if x > y - { - _Ops::iter_swap(__x, __y); // x < y && y <= z - __r = 2; - } - return __r; // x <= y && y < z - } - if (__c(*__z, *__y)) // x > y, if y > z - { - _Ops::iter_swap(__x, __z); // x < y && y < z - __r = 1; - return __r; - } - _Ops::iter_swap(__x, __y); // x > y && y <= z - __r = 1; // x < y && x <= z - if (__c(*__z, *__y)) // if y > z - { - _Ops::iter_swap(__y, __z); // x <= y && y < z - __r = 2; - } - return __r; -} // x <= y && y <= z - -// stable, 3-6 compares, 0-5 swaps - -template -_LIBCPP_HIDE_FROM_ABI void -__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) { - using _Ops = _IterOps<_AlgPolicy>; - std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); - if (__c(*__x4, *__x3)) { - _Ops::iter_swap(__x3, __x4); - if (__c(*__x3, *__x2)) { - _Ops::iter_swap(__x2, __x3); - if (__c(*__x2, *__x1)) { - _Ops::iter_swap(__x1, __x2); - } - } - } -} - -// stable, 4-10 compares, 0-9 swaps - -template -_LIBCPP_HIDE_FROM_ABI void -__sort5(_ForwardIterator __x1, - _ForwardIterator __x2, - _ForwardIterator __x3, - _ForwardIterator __x4, - _ForwardIterator __x5, - _Comp __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - std::__sort4<_AlgPolicy, _Comp>(__x1, __x2, __x3, __x4, __comp); - if (__comp(*__x5, *__x4)) { - _Ops::iter_swap(__x4, __x5); - if (__comp(*__x4, *__x3)) { - _Ops::iter_swap(__x3, __x4); - if (__comp(*__x3, *__x2)) { - _Ops::iter_swap(__x2, __x3); - if (__comp(*__x2, *__x1)) { - _Ops::iter_swap(__x1, __x2); - } - } - } - } -} - -// The comparator being simple is a prerequisite for using the branchless optimization. -template -struct __is_simple_comparator : false_type {}; -template <> -struct __is_simple_comparator<__less<>&> : true_type {}; -template -struct __is_simple_comparator&> : true_type {}; -template -struct __is_simple_comparator&> : true_type {}; - -template ::value_type> -using __use_branchless_sort = - integral_constant::value && sizeof(_Tp) <= sizeof(void*) && - is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>; - -namespace __detail { - -// Size in bits for the bitset in use. -enum { __block_size = sizeof(uint64_t) * 8 }; - -} // namespace __detail - -// Ensures that __c(*__x, *__y) is true by swapping *__x and *__y if necessary. -template -inline _LIBCPP_HIDE_FROM_ABI void __cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) { - // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`). - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - bool __r = __c(*__x, *__y); - value_type __tmp = __r ? *__x : *__y; - *__y = __r ? *__y : *__x; - *__x = __tmp; -} - -// Ensures that *__x, *__y and *__z are ordered according to the comparator __c, -// under the assumption that *__y and *__z are already ordered. -template -inline _LIBCPP_HIDE_FROM_ABI void -__partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) { - // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`). - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - bool __r = __c(*__z, *__x); - value_type __tmp = __r ? *__z : *__x; - *__z = __r ? *__x : *__z; - __r = __c(__tmp, *__y); - *__x = __r ? *__x : *__y; - *__y = __r ? *__y : __tmp; -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless( - _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) { - std::__cond_swap<_Compare>(__x2, __x3, __c); - std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless( - _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) { - std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _Compare __c) { - std::__cond_swap<_Compare>(__x1, __x3, __c); - std::__cond_swap<_Compare>(__x2, __x4, __c); - std::__cond_swap<_Compare>(__x1, __x2, __c); - std::__cond_swap<_Compare>(__x3, __x4, __c); - std::__cond_swap<_Compare>(__x2, __x3, __c); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _Compare __c) { - std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _RandomAccessIterator __x5, - _Compare __c) { - std::__cond_swap<_Compare>(__x1, __x2, __c); - std::__cond_swap<_Compare>(__x4, __x5, __c); - std::__partially_sorted_swap<_Compare>(__x3, __x4, __x5, __c); - std::__cond_swap<_Compare>(__x2, __x5, __c); - std::__partially_sorted_swap<_Compare>(__x1, __x3, __x4, __c); - std::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _RandomAccessIterator __x5, - _Compare __c) { - std::__sort5<_AlgPolicy, _Compare, _RandomAccessIterator>( - std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __c); -} - -// Assumes size > 0 -template -_LIBCPP_HIDE_FROM_ABI void -__selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - _BidirectionalIterator __lm1 = __last; - for (--__lm1; __first != __lm1; ++__first) { - _BidirectionalIterator __i = std::__min_element<_Compare>(__first, __last, __comp); - if (__i != __first) - _IterOps<_AlgPolicy>::iter_swap(__first, __i); - } -} - -// Sort the iterator range [__first, __last) using the comparator __comp using -// the insertion sort algorithm. -template -_LIBCPP_HIDE_FROM_ABI void -__insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - if (__first == __last) - return; - _BidirectionalIterator __i = __first; - for (++__i; __i != __last; ++__i) { - _BidirectionalIterator __j = __i; - --__j; - if (__comp(*__i, *__j)) { - value_type __t(_Ops::__iter_move(__i)); - _BidirectionalIterator __k = __j; - __j = __i; - do { - *__j = _Ops::__iter_move(__k); - __j = __k; - } while (__j != __first && __comp(__t, *--__k)); - *__j = std::move(__t); - } - } -} - -// Sort the iterator range [__first, __last) using the comparator __comp using -// the insertion sort algorithm. Insertion sort has two loops, outer and inner. -// The implementation below has no bounds check (unguarded) for the inner loop. -// Assumes that there is an element in the position (__first - 1) and that each -// element in the input range is greater or equal to the element at __first - 1. -template -_LIBCPP_HIDE_FROM_ABI void -__insertion_sort_unguarded(_RandomAccessIterator const __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - if (__first == __last) - return; - const _RandomAccessIterator __leftmost = __first - difference_type(1); - (void)__leftmost; // can be unused when assertions are disabled - for (_RandomAccessIterator __i = __first + difference_type(1); __i != __last; ++__i) { - _RandomAccessIterator __j = __i - difference_type(1); - if (__comp(*__i, *__j)) { - value_type __t(_Ops::__iter_move(__i)); - _RandomAccessIterator __k = __j; - __j = __i; - do { - *__j = _Ops::__iter_move(__k); - __j = __k; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __k != __leftmost, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (__comp(__t, *--__k)); // No need for bounds check due to the assumption stated above. - *__j = std::move(__t); - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI bool -__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - switch (__last - __first) { - case 0: - case 1: - return true; - case 2: - if (__comp(*--__last, *__first)) - _Ops::iter_swap(__first, __last); - return true; - case 3: - std::__sort3_maybe_branchless<_AlgPolicy, _Comp>(__first, __first + difference_type(1), --__last, __comp); - return true; - case 4: - std::__sort4_maybe_branchless<_AlgPolicy, _Comp>( - __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp); - return true; - case 5: - std::__sort5_maybe_branchless<_AlgPolicy, _Comp>( - __first, - __first + difference_type(1), - __first + difference_type(2), - __first + difference_type(3), - --__last, - __comp); - return true; - } - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - _RandomAccessIterator __j = __first + difference_type(2); - std::__sort3_maybe_branchless<_AlgPolicy, _Comp>(__first, __first + difference_type(1), __j, __comp); - const unsigned __limit = 8; - unsigned __count = 0; - for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) { - if (__comp(*__i, *__j)) { - value_type __t(_Ops::__iter_move(__i)); - _RandomAccessIterator __k = __j; - __j = __i; - do { - *__j = _Ops::__iter_move(__k); - __j = __k; - } while (__j != __first && __comp(__t, *--__k)); - *__j = std::move(__t); - if (++__count == __limit) - return ++__i == __last; - } - __j = __i; - } - return true; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos( - _RandomAccessIterator __first, _RandomAccessIterator __last, uint64_t& __left_bitset, uint64_t& __right_bitset) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - // Swap one pair on each iteration as long as both bitsets have at least one - // element for swapping. - while (__left_bitset != 0 && __right_bitset != 0) { - difference_type __tz_left = __libcpp_ctz(__left_bitset); - __left_bitset = __libcpp_blsr(__left_bitset); - difference_type __tz_right = __libcpp_ctz(__right_bitset); - __right_bitset = __libcpp_blsr(__right_bitset); - _Ops::iter_swap(__first + __tz_left, __last - __tz_right); - } -} - -template ::value_type> -inline _LIBCPP_HIDE_FROM_ABI void -__populate_left_bitset(_RandomAccessIterator __first, _Compare __comp, _ValueType& __pivot, uint64_t& __left_bitset) { - // Possible vectorization. With a proper "-march" flag, the following loop - // will be compiled into a set of SIMD instructions. - _RandomAccessIterator __iter = __first; - for (int __j = 0; __j < __detail::__block_size;) { - bool __comp_result = !__comp(*__iter, __pivot); - __left_bitset |= (static_cast(__comp_result) << __j); - __j++; - ++__iter; - } -} - -template ::value_type> -inline _LIBCPP_HIDE_FROM_ABI void -__populate_right_bitset(_RandomAccessIterator __lm1, _Compare __comp, _ValueType& __pivot, uint64_t& __right_bitset) { - // Possible vectorization. With a proper "-march" flag, the following loop - // will be compiled into a set of SIMD instructions. - _RandomAccessIterator __iter = __lm1; - for (int __j = 0; __j < __detail::__block_size;) { - bool __comp_result = __comp(*__iter, __pivot); - __right_bitset |= (static_cast(__comp_result) << __j); - __j++; - --__iter; - } -} - -template ::value_type> -inline _LIBCPP_HIDE_FROM_ABI void __bitset_partition_partial_blocks( - _RandomAccessIterator& __first, - _RandomAccessIterator& __lm1, - _Compare __comp, - _ValueType& __pivot, - uint64_t& __left_bitset, - uint64_t& __right_bitset) { - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __remaining_len = __lm1 - __first + 1; - difference_type __l_size; - difference_type __r_size; - if (__left_bitset == 0 && __right_bitset == 0) { - __l_size = __remaining_len / 2; - __r_size = __remaining_len - __l_size; - } else if (__left_bitset == 0) { - // We know at least one side is a full block. - __l_size = __remaining_len - __detail::__block_size; - __r_size = __detail::__block_size; - } else { // if (__right_bitset == 0) - __l_size = __detail::__block_size; - __r_size = __remaining_len - __detail::__block_size; - } - // Record the comparison outcomes for the elements currently on the left side. - if (__left_bitset == 0) { - _RandomAccessIterator __iter = __first; - for (int __j = 0; __j < __l_size; __j++) { - bool __comp_result = !__comp(*__iter, __pivot); - __left_bitset |= (static_cast(__comp_result) << __j); - ++__iter; - } - } - // Record the comparison outcomes for the elements currently on the right - // side. - if (__right_bitset == 0) { - _RandomAccessIterator __iter = __lm1; - for (int __j = 0; __j < __r_size; __j++) { - bool __comp_result = __comp(*__iter, __pivot); - __right_bitset |= (static_cast(__comp_result) << __j); - --__iter; - } - } - std::__swap_bitmap_pos<_AlgPolicy, _RandomAccessIterator>(__first, __lm1, __left_bitset, __right_bitset); - __first += (__left_bitset == 0) ? __l_size : 0; - __lm1 -= (__right_bitset == 0) ? __r_size : 0; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos_within( - _RandomAccessIterator& __first, _RandomAccessIterator& __lm1, uint64_t& __left_bitset, uint64_t& __right_bitset) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - if (__left_bitset) { - // Swap within the left side. Need to find set positions in the reverse - // order. - while (__left_bitset != 0) { - difference_type __tz_left = __detail::__block_size - 1 - __libcpp_clz(__left_bitset); - __left_bitset &= (static_cast(1) << __tz_left) - 1; - _RandomAccessIterator __it = __first + __tz_left; - if (__it != __lm1) { - _Ops::iter_swap(__it, __lm1); - } - --__lm1; - } - __first = __lm1 + difference_type(1); - } else if (__right_bitset) { - // Swap within the right side. Need to find set positions in the reverse - // order. - while (__right_bitset != 0) { - difference_type __tz_right = __detail::__block_size - 1 - __libcpp_clz(__right_bitset); - __right_bitset &= (static_cast(1) << __tz_right) - 1; - _RandomAccessIterator __it = __lm1 - __tz_right; - if (__it != __first) { - _Ops::iter_swap(__it, __first); - } - ++__first; - } - } -} - -// Partition [__first, __last) using the comparator __comp. *__first has the -// chosen pivot. Elements that are equivalent are kept to the left of the -// pivot. Returns the iterator for the pivot and a bool value which is true if -// the provided range is already sorted, false otherwise. We assume that the -// length of the range is at least three elements. -// -// __bitset_partition uses bitsets for storing outcomes of the comparisons -// between the pivot and other elements. -template -_LIBCPP_HIDE_FROM_ABI std::pair<_RandomAccessIterator, bool> -__bitset_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; - typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; - _LIBCPP_ASSERT_INTERNAL(__last - __first >= difference_type(3), ""); - const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around - const _RandomAccessIterator __end = __last; - (void)__end; // - - value_type __pivot(_Ops::__iter_move(__first)); - // Find the first element greater than the pivot. - if (__comp(__pivot, *(__last - difference_type(1)))) { - // Not guarded since we know the last element is greater than the pivot. - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (!__comp(__pivot, *__first)); - } else { - while (++__first < __last && !__comp(__pivot, *__first)) { - } - } - // Find the last element less than or equal to the pivot. - if (__first < __last) { - // It will be always guarded because __introsort will do the median-of-three - // before calling this. - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (__comp(__pivot, *__last)); - } - // If the first element greater than the pivot is at or after the - // last element less than or equal to the pivot, then we have covered the - // entire range without swapping elements. This implies the range is already - // partitioned. - bool __already_partitioned = __first >= __last; - if (!__already_partitioned) { - _Ops::iter_swap(__first, __last); - ++__first; - } - - // In [__first, __last) __last is not inclusive. From now on, it uses last - // minus one to be inclusive on both sides. - _RandomAccessIterator __lm1 = __last - difference_type(1); - uint64_t __left_bitset = 0; - uint64_t __right_bitset = 0; - - // Reminder: length = __lm1 - __first + 1. - while (__lm1 - __first >= 2 * __detail::__block_size - 1) { - // Record the comparison outcomes for the elements currently on the left - // side. - if (__left_bitset == 0) - std::__populate_left_bitset<_Compare>(__first, __comp, __pivot, __left_bitset); - // Record the comparison outcomes for the elements currently on the right - // side. - if (__right_bitset == 0) - std::__populate_right_bitset<_Compare>(__lm1, __comp, __pivot, __right_bitset); - // Swap the elements recorded to be the candidates for swapping in the - // bitsets. - std::__swap_bitmap_pos<_AlgPolicy, _RandomAccessIterator>(__first, __lm1, __left_bitset, __right_bitset); - // Only advance the iterator if all the elements that need to be moved to - // other side were moved. - __first += (__left_bitset == 0) ? difference_type(__detail::__block_size) : difference_type(0); - __lm1 -= (__right_bitset == 0) ? difference_type(__detail::__block_size) : difference_type(0); - } - // Now, we have a less-than a block worth of elements on at least one of the - // sides. - std::__bitset_partition_partial_blocks<_AlgPolicy, _Compare>( - __first, __lm1, __comp, __pivot, __left_bitset, __right_bitset); - // At least one the bitsets would be empty. For the non-empty one, we need to - // properly partition the elements that appear within that bitset. - std::__swap_bitmap_pos_within<_AlgPolicy>(__first, __lm1, __left_bitset, __right_bitset); - - // Move the pivot to its correct position. - _RandomAccessIterator __pivot_pos = __first - difference_type(1); - if (__begin != __pivot_pos) { - *__begin = _Ops::__iter_move(__pivot_pos); - } - *__pivot_pos = std::move(__pivot); - return std::make_pair(__pivot_pos, __already_partitioned); -} - -// Partition [__first, __last) using the comparator __comp. *__first has the -// chosen pivot. Elements that are equivalent are kept to the right of the -// pivot. Returns the iterator for the pivot and a bool value which is true if -// the provided range is already sorted, false otherwise. We assume that the -// length of the range is at least three elements. -template -_LIBCPP_HIDE_FROM_ABI std::pair<_RandomAccessIterator, bool> -__partition_with_equals_on_right(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; - _LIBCPP_ASSERT_INTERNAL(__last - __first >= difference_type(3), ""); - const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around - const _RandomAccessIterator __end = __last; - (void)__end; // - value_type __pivot(_Ops::__iter_move(__first)); - // Find the first element greater or equal to the pivot. It will be always - // guarded because __introsort will do the median-of-three before calling - // this. - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (__comp(*__first, __pivot)); - - // Find the last element less than the pivot. - if (__begin == __first - difference_type(1)) { - while (__first < __last && !__comp(*--__last, __pivot)) - ; - } else { - // Guarded. - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (!__comp(*__last, __pivot)); - } - - // If the first element greater than or equal to the pivot is at or after the - // last element less than the pivot, then we have covered the entire range - // without swapping elements. This implies the range is already partitioned. - bool __already_partitioned = __first >= __last; - // Go through the remaining elements. Swap pairs of elements (one to the - // right of the pivot and the other to left of the pivot) that are not on the - // correct side of the pivot. - while (__first < __last) { - _Ops::iter_swap(__first, __last); - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (__comp(*__first, __pivot)); - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (!__comp(*__last, __pivot)); - } - // Move the pivot to its correct position. - _RandomAccessIterator __pivot_pos = __first - difference_type(1); - if (__begin != __pivot_pos) { - *__begin = _Ops::__iter_move(__pivot_pos); - } - *__pivot_pos = std::move(__pivot); - return std::make_pair(__pivot_pos, __already_partitioned); -} - -// Similar to the above function. Elements equivalent to the pivot are put to -// the left of the pivot. Returns the iterator to the pivot element. -template -_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator -__partition_with_equals_on_left(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; - const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around - const _RandomAccessIterator __end = __last; - (void)__end; // - value_type __pivot(_Ops::__iter_move(__first)); - if (__comp(__pivot, *(__last - difference_type(1)))) { - // Guarded. - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (!__comp(__pivot, *__first)); - } else { - while (++__first < __last && !__comp(__pivot, *__first)) { - } - } - - if (__first < __last) { - // It will be always guarded because __introsort will do the - // median-of-three before calling this. - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (__comp(__pivot, *__last)); - } - while (__first < __last) { - _Ops::iter_swap(__first, __last); - do { - ++__first; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __first != __end, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - } while (!__comp(__pivot, *__first)); - do { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __last != __begin, - "Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?"); - --__last; - } while (__comp(__pivot, *__last)); - } - _RandomAccessIterator __pivot_pos = __first - difference_type(1); - if (__begin != __pivot_pos) { - *__begin = _Ops::__iter_move(__pivot_pos); - } - *__pivot_pos = std::move(__pivot); - return __first; -} - -// The main sorting function. Implements introsort combined with other ideas: -// - option of using block quick sort for partitioning, -// - guarded and unguarded insertion sort for small lengths, -// - Tuckey's ninther technique for computing the pivot, -// - check on whether partition was not required. -// The implementation is partly based on Orson Peters' pattern-defeating -// quicksort, published at: . -template -void __introsort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __depth, - bool __leftmost = true) { - using _Ops = _IterOps<_AlgPolicy>; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - using _Comp_ref = __comp_ref_type<_Compare>; - // Upper bound for using insertion sort for sorting. - difference_type __limit = 24; - // Lower bound for using Tuckey's ninther technique for median computation. - difference_type __ninther_threshold = 128; - while (true) { - difference_type __len = __last - __first; - switch (__len) { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - _Ops::iter_swap(__first, __last); - return; - case 3: - std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp); - return; - case 4: - std::__sort4_maybe_branchless<_AlgPolicy, _Compare>( - __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp); - return; - case 5: - std::__sort5_maybe_branchless<_AlgPolicy, _Compare>( - __first, - __first + difference_type(1), - __first + difference_type(2), - __first + difference_type(3), - --__last, - __comp); - return; - } - // Use insertion sort if the length of the range is below the specified limit. - if (__len < __limit) { - if (__leftmost) { - std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp); - } else { - std::__insertion_sort_unguarded<_AlgPolicy, _Compare>(__first, __last, __comp); - } - return; - } - if (__depth == 0) { - // Fallback to heap sort as Introsort suggests. - std::__partial_sort<_AlgPolicy, _Compare>(__first, __last, __last, __comp); - return; - } - --__depth; - { - difference_type __half_len = __len / 2; - // Use Tuckey's ninther technique or median of 3 for pivot selection - // depending on the length of the range being sorted. - if (__len > __ninther_threshold) { - std::__sort3<_AlgPolicy, _Compare>(__first, __first + __half_len, __last - difference_type(1), __comp); - std::__sort3<_AlgPolicy, _Compare>( - __first + difference_type(1), __first + (__half_len - 1), __last - difference_type(2), __comp); - std::__sort3<_AlgPolicy, _Compare>( - __first + difference_type(2), __first + (__half_len + 1), __last - difference_type(3), __comp); - std::__sort3<_AlgPolicy, _Compare>( - __first + (__half_len - 1), __first + __half_len, __first + (__half_len + 1), __comp); - _Ops::iter_swap(__first, __first + __half_len); - } else { - std::__sort3<_AlgPolicy, _Compare>(__first + __half_len, __first, __last - difference_type(1), __comp); - } - } - // The elements to the left of the current iterator range are already - // sorted. If the current iterator range to be sorted is not the - // leftmost part of the entire iterator range and the pivot is same as - // the highest element in the range to the left, then we know that all - // the elements in the range [first, pivot] would be equal to the pivot, - // assuming the equal elements are put on the left side when - // partitioned. This also means that we do not need to sort the left - // side of the partition. - if (!__leftmost && !__comp(*(__first - difference_type(1)), *__first)) { - __first = std::__partition_with_equals_on_left<_AlgPolicy, _RandomAccessIterator, _Comp_ref>( - __first, __last, _Comp_ref(__comp)); - continue; - } - // Use bitset partition only if asked for. - auto __ret = _UseBitSetPartition - ? std::__bitset_partition<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp) - : std::__partition_with_equals_on_right<_AlgPolicy, _RandomAccessIterator, _Compare>( - __first, __last, __comp); - _RandomAccessIterator __i = __ret.first; - // [__first, __i) < *__i and *__i <= [__i+1, __last) - // If we were given a perfect partition, see if insertion sort is quick... - if (__ret.second) { - bool __fs = std::__insertion_sort_incomplete<_AlgPolicy, _Compare>(__first, __i, __comp); - if (std::__insertion_sort_incomplete<_AlgPolicy, _Compare>(__i + difference_type(1), __last, __comp)) { - if (__fs) - return; - __last = __i; - continue; - } else { - if (__fs) { - __first = ++__i; - continue; - } - } - } - // Sort the left partiton recursively and the right partition with tail recursion elimination. - std::__introsort<_AlgPolicy, _Compare, _RandomAccessIterator, _UseBitSetPartition>( - __first, __i, __comp, __depth, __leftmost); - __leftmost = false; - __first = ++__i; - } -} - -template -inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) { - if (__n == 0) - return 0; - if (sizeof(__n) <= sizeof(unsigned)) - return sizeof(unsigned) * CHAR_BIT - 1 - __libcpp_clz(static_cast(__n)); - if (sizeof(__n) <= sizeof(unsigned long)) - return sizeof(unsigned long) * CHAR_BIT - 1 - __libcpp_clz(static_cast(__n)); - if (sizeof(__n) <= sizeof(unsigned long long)) - return sizeof(unsigned long long) * CHAR_BIT - 1 - __libcpp_clz(static_cast(__n)); - - _Number __log2 = 0; - while (__n > 1) { - __log2++; - __n >>= 1; - } - return __log2; -} - -template -void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp); - -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, char*>(char*, char*, __less&); -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&); -#endif -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, signed char*>(signed char*, signed char*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, short*>(short*, short*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, int*>(int*, int*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned*>(unsigned*, unsigned*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, long*>(long*, long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, long long*>(long long*, long long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, unsigned long long*>( - unsigned long long*, unsigned long long*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, float*>(float*, float*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, double*>(double*, double*, __less&); -extern template _LIBCPP_EXPORTED_FROM_ABI void -__sort<__less&, long double*>(long double*, long double*, __less&); - -template -_LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __depth_limit = 2 * std::__log2i(__last - __first); - - // Only use bitset partitioning for arithmetic types. We should also check - // that the default comparator is in use so that we are sure that there are no - // branches in the comparator. - std::__introsort<_AlgPolicy, - _Comp&, - _RandomAccessIterator, - __use_branchless_sort<_Comp, _RandomAccessIterator>::value>(__first, __last, __comp, __depth_limit); -} - -template -using __is_any_of = _Or...>; - -template -using __sort_is_specialized_in_library = __is_any_of< - _Type, - char, -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS - wchar_t, -#endif - signed char, - unsigned char, - short, - unsigned short, - int, - unsigned int, - long, - unsigned long, - long long, - unsigned long long, - float, - double, - long double>; - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, __less<>&) { - __less<_Type> __comp; - std::__sort<__less<_Type>&, _Type*>(__first, __last, __comp); -} - -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, less<_Type>&) { - __less<_Type> __comp; - std::__sort<__less<_Type>&, _Type*>(__first, __last, __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -__sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) { - std::__debug_randomize_range<_AlgPolicy>(__first, __last); - - if (__libcpp_is_constant_evaluated()) { - std::__partial_sort<_AlgPolicy>( - std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__last), __comp); - } else { - std::__sort_dispatch<_AlgPolicy>(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __comp); - } - std::__check_strict_weak_ordering_sorted(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { - std::__sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::sort(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort_heap.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort_heap.h deleted file mode 100644 index 1a7cad1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/sort_heap.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SORT_HEAP_H -#define _LIBCPP___CXX03___ALGORITHM_SORT_HEAP_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/pop_heap.h> -#include <__cxx03/__config> -#include <__cxx03/__debug_utils/strict_weak_ordering_check.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/is_assignable.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI void -__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { - _RandomAccessIterator __saved_last = __last; - __comp_ref_type<_Compare> __comp_ref = __comp; - - using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; - for (difference_type __n = __last - __first; __n > 1; --__last, (void)--__n) - std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n); - std::__check_strict_weak_ordering_sorted(__first, __saved_last, __comp_ref); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible."); - static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); - - std::__sort_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::sort_heap(std::move(__first), std::move(__last), __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SORT_HEAP_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_partition.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_partition.h deleted file mode 100644 index c804498..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_partition.h +++ /dev/null @@ -1,307 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_STABLE_PARTITION_H -#define _LIBCPP___CXX03___ALGORITHM_STABLE_PARTITION_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/rotate.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/destruct_n.h> -#include <__cxx03/__memory/temporary_buffer.h> -#include <__cxx03/__memory/unique_ptr.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/new> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl( - _ForwardIterator __first, - _ForwardIterator __last, - _Predicate __pred, - _Distance __len, - _Pair __p, - forward_iterator_tag __fit) { - using _Ops = _IterOps<_AlgPolicy>; - - // *__first is known to be false - // __len >= 1 - if (__len == 1) - return __first; - if (__len == 2) { - _ForwardIterator __m = __first; - if (__pred(*++__m)) { - _Ops::iter_swap(__first, __m); - return __m; - } - return __first; - } - if (__len <= __p.second) { // The buffer is big enough to use - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__p.first, __d); - // Move the falses into the temporary buffer, and the trues to the front of the line - // Update __first to always point to the end of the trues - value_type* __t = __p.first; - ::new ((void*)__t) value_type(_Ops::__iter_move(__first)); - __d.template __incr(); - ++__t; - _ForwardIterator __i = __first; - while (++__i != __last) { - if (__pred(*__i)) { - *__first = _Ops::__iter_move(__i); - ++__first; - } else { - ::new ((void*)__t) value_type(_Ops::__iter_move(__i)); - __d.template __incr(); - ++__t; - } - } - // All trues now at start of range, all falses in buffer - // Move falses back into range, but don't mess up __first which points to first false - __i = __first; - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i) - *__i = _Ops::__iter_move(__t2); - // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer - return __first; - } - // Else not enough buffer, do in place - // __len >= 3 - _ForwardIterator __m = __first; - _Distance __len2 = __len / 2; // __len2 >= 2 - _Ops::advance(__m, __len2); - // recurse on [__first, __m), *__first know to be false - // F????????????????? - // f m l - _ForwardIterator __first_false = - std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m, __pred, __len2, __p, __fit); - // TTTFFFFF?????????? - // f ff m l - // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true - _ForwardIterator __m1 = __m; - _ForwardIterator __second_false = __last; - _Distance __len_half = __len - __len2; - while (__pred(*__m1)) { - if (++__m1 == __last) - goto __second_half_done; - --__len_half; - } - // TTTFFFFFTTTF?????? - // f ff m m1 l - __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __fit); -__second_half_done: - // TTTFFFFFTTTTTFFFFF - // f ff m sf l - return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first; - // TTTTTTTTFFFFFFFFFF - // | -} - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator -__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) { - typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - - const difference_type __alloc_limit = 3; // might want to make this a function of trivial assignment - // Either prove all true and return __first or point to first false - while (true) { - if (__first == __last) - return __first; - if (!__pred(*__first)) - break; - ++__first; - } - // We now have a reduced range [__first, __last) - // *__first is known to be false - difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last); - pair __p(0, 0); - unique_ptr __h; - if (__len >= __alloc_limit) { - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __p = std::get_temporary_buffer(__len); - _LIBCPP_SUPPRESS_DEPRECATED_POP - __h.reset(__p.first); - } - return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( - std::move(__first), std::move(__last), __pred, __len, __p, forward_iterator_tag()); -} - -template -_BidirectionalIterator __stable_partition_impl( - _BidirectionalIterator __first, - _BidirectionalIterator __last, - _Predicate __pred, - _Distance __len, - _Pair __p, - bidirectional_iterator_tag __bit) { - using _Ops = _IterOps<_AlgPolicy>; - - // *__first is known to be false - // *__last is known to be true - // __len >= 2 - if (__len == 2) { - _Ops::iter_swap(__first, __last); - return __last; - } - if (__len == 3) { - _BidirectionalIterator __m = __first; - if (__pred(*++__m)) { - _Ops::iter_swap(__first, __m); - _Ops::iter_swap(__m, __last); - return __last; - } - _Ops::iter_swap(__m, __last); - _Ops::iter_swap(__first, __m); - return __m; - } - if (__len <= __p.second) { // The buffer is big enough to use - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__p.first, __d); - // Move the falses into the temporary buffer, and the trues to the front of the line - // Update __first to always point to the end of the trues - value_type* __t = __p.first; - ::new ((void*)__t) value_type(_Ops::__iter_move(__first)); - __d.template __incr(); - ++__t; - _BidirectionalIterator __i = __first; - while (++__i != __last) { - if (__pred(*__i)) { - *__first = _Ops::__iter_move(__i); - ++__first; - } else { - ::new ((void*)__t) value_type(_Ops::__iter_move(__i)); - __d.template __incr(); - ++__t; - } - } - // move *__last, known to be true - *__first = _Ops::__iter_move(__i); - __i = ++__first; - // All trues now at start of range, all falses in buffer - // Move falses back into range, but don't mess up __first which points to first false - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i) - *__i = _Ops::__iter_move(__t2); - // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer - return __first; - } - // Else not enough buffer, do in place - // __len >= 4 - _BidirectionalIterator __m = __first; - _Distance __len2 = __len / 2; // __len2 >= 2 - _Ops::advance(__m, __len2); - // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false - // F????????????????T - // f m l - _BidirectionalIterator __m1 = __m; - _BidirectionalIterator __first_false = __first; - _Distance __len_half = __len2; - while (!__pred(*--__m1)) { - if (__m1 == __first) - goto __first_half_done; - --__len_half; - } - // F???TFFF?????????T - // f m1 m l - __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m1, __pred, __len_half, __p, __bit); -__first_half_done: - // TTTFFFFF?????????T - // f ff m l - // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true - __m1 = __m; - _BidirectionalIterator __second_false = __last; - ++__second_false; - __len_half = __len - __len2; - while (__pred(*__m1)) { - if (++__m1 == __last) - goto __second_half_done; - --__len_half; - } - // TTTFFFFFTTTF?????T - // f ff m m1 l - __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __bit); -__second_half_done: - // TTTFFFFFTTTTTFFFFF - // f ff m sf l - return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first; - // TTTTTTTTFFFFFFFFFF - // | -} - -template -_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl( - _BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) { - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment - // Either prove all true and return __first or point to first false - while (true) { - if (__first == __last) - return __first; - if (!__pred(*__first)) - break; - ++__first; - } - // __first points to first false, everything prior to __first is already set. - // Either prove [__first, __last) is all false and return __first, or point __last to last true - do { - if (__first == --__last) - return __first; - } while (!__pred(*__last)); - // We now have a reduced range [__first, __last] - // *__first is known to be false - // *__last is known to be true - // __len >= 2 - difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1; - pair __p(0, 0); - unique_ptr __h; - if (__len >= __alloc_limit) { - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __p = std::get_temporary_buffer(__len); - _LIBCPP_SUPPRESS_DEPRECATED_POP - __h.reset(__p.first); - } - return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( - std::move(__first), std::move(__last), __pred, __len, __p, bidirectional_iterator_tag()); -} - -template -_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition( - _ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category) { - return std::__stable_partition_impl<_AlgPolicy, __remove_cvref_t<_Predicate>&>( - std::move(__first), std::move(__last), __pred, __iter_category); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category; - return std::__stable_partition<_ClassicAlgPolicy, _Predicate&>( - std::move(__first), std::move(__last), __pred, _IterCategory()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_STABLE_PARTITION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_sort.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_sort.h deleted file mode 100644 index e1f89f6..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/stable_sort.h +++ /dev/null @@ -1,273 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_STABLE_SORT_H -#define _LIBCPP___CXX03___ALGORITHM_STABLE_SORT_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/inplace_merge.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__algorithm/sort.h> -#include <__cxx03/__config> -#include <__cxx03/__debug_utils/strict_weak_ordering_check.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/destruct_n.h> -#include <__cxx03/__memory/temporary_buffer.h> -#include <__cxx03/__memory/unique_ptr.h> -#include <__cxx03/__type_traits/is_trivially_assignable.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/new> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI void __insertion_sort_move( - _BidirectionalIterator __first1, - _BidirectionalIterator __last1, - typename iterator_traits<_BidirectionalIterator>::value_type* __first2, - _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - if (__first1 != __last1) { - __destruct_n __d(0); - unique_ptr __h(__first2, __d); - value_type* __last2 = __first2; - ::new ((void*)__last2) value_type(_Ops::__iter_move(__first1)); - __d.template __incr(); - for (++__last2; ++__first1 != __last1; ++__last2) { - value_type* __j2 = __last2; - value_type* __i2 = __j2; - if (__comp(*__first1, *--__i2)) { - ::new ((void*)__j2) value_type(std::move(*__i2)); - __d.template __incr(); - for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) - *__j2 = std::move(*__i2); - *__j2 = _Ops::__iter_move(__first1); - } else { - ::new ((void*)__j2) value_type(_Ops::__iter_move(__first1)); - __d.template __incr(); - } - } - __h.release(); - } -} - -template -_LIBCPP_HIDE_FROM_ABI void __merge_move_construct( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - typename iterator_traits<_InputIterator1>::value_type* __result, - _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_InputIterator1>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__result, __d); - for (; true; ++__result) { - if (__first1 == __last1) { - for (; __first2 != __last2; ++__first2, (void)++__result, __d.template __incr()) - ::new ((void*)__result) value_type(_Ops::__iter_move(__first2)); - __h.release(); - return; - } - if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, (void)++__result, __d.template __incr()) - ::new ((void*)__result) value_type(_Ops::__iter_move(__first1)); - __h.release(); - return; - } - if (__comp(*__first2, *__first1)) { - ::new ((void*)__result) value_type(_Ops::__iter_move(__first2)); - __d.template __incr(); - ++__first2; - } else { - ::new ((void*)__result) value_type(_Ops::__iter_move(__first1)); - __d.template __incr(); - ++__first1; - } - } -} - -template -_LIBCPP_HIDE_FROM_ABI void __merge_move_assign( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - for (; __first1 != __last1; ++__result) { - if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, (void)++__result) - *__result = _Ops::__iter_move(__first1); - return; - } - if (__comp(*__first2, *__first1)) { - *__result = _Ops::__iter_move(__first2); - ++__first2; - } else { - *__result = _Ops::__iter_move(__first1); - ++__first1; - } - } - for (; __first2 != __last2; ++__first2, (void)++__result) - *__result = _Ops::__iter_move(__first2); -} - -template -void __stable_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, - ptrdiff_t __buff_size); - -template -void __stable_sort_move(_RandomAccessIterator __first1, - _RandomAccessIterator __last1, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __first2) { - using _Ops = _IterOps<_AlgPolicy>; - - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - switch (__len) { - case 0: - return; - case 1: - ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); - return; - case 2: - __destruct_n __d(0); - unique_ptr __h2(__first2, __d); - if (__comp(*--__last1, *__first1)) { - ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1)); - __d.template __incr(); - ++__first2; - ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); - } else { - ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); - __d.template __incr(); - ++__first2; - ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1)); - } - __h2.release(); - return; - } - if (__len <= 8) { - std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp); - return; - } - typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; - _RandomAccessIterator __m = __first1 + __l2; - std::__stable_sort<_AlgPolicy, _Compare>(__first1, __m, __comp, __l2, __first2, __l2); - std::__stable_sort<_AlgPolicy, _Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2); - std::__merge_move_construct<_AlgPolicy, _Compare>(__first1, __m, __m, __last1, __first2, __comp); -} - -template -struct __stable_sort_switch { - static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value; -}; - -template -void __stable_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, - ptrdiff_t __buff_size) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - switch (__len) { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - _IterOps<_AlgPolicy>::iter_swap(__first, __last); - return; - } - if (__len <= static_cast(__stable_sort_switch::value)) { - std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp); - return; - } - typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; - _RandomAccessIterator __m = __first + __l2; - if (__len <= __buff_size) { - __destruct_n __d(0); - unique_ptr __h2(__buff, __d); - std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff); - __d.__set(__l2, (value_type*)nullptr); - std::__stable_sort_move<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff + __l2); - __d.__set(__len, (value_type*)nullptr); - std::__merge_move_assign<_AlgPolicy, _Compare>( - __buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); - // std::__merge<_Compare>(move_iterator(__buff), - // move_iterator(__buff + __l2), - // move_iterator<_RandomAccessIterator>(__buff + __l2), - // move_iterator<_RandomAccessIterator>(__buff + __len), - // __first, __comp); - return; - } - std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size); - std::__stable_sort<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size); - std::__inplace_merge<_AlgPolicy>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -__stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; - - difference_type __len = __last - __first; - pair __buf(0, 0); - unique_ptr __h; - if (__len > static_cast(__stable_sort_switch::value)) { - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __buf = std::get_temporary_buffer(__len); - _LIBCPP_SUPPRESS_DEPRECATED_POP - __h.reset(__buf.first); - } - - std::__stable_sort<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __last, __comp, __len, __buf.first, __buf.second); - std::__check_strict_weak_ordering_sorted(__first, __last, __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); -} - -template -inline _LIBCPP_HIDE_FROM_ABI void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { - std::stable_sort(__first, __last, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_STABLE_SORT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/swap_ranges.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/swap_ranges.h deleted file mode 100644 index d1f50c1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/swap_ranges.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_SWAP_RANGES_H -#define _LIBCPP___CXX03___ALGORITHM_SWAP_RANGES_H - -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// 2+2 iterators: the shorter size will be used. -template -_LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator1, _ForwardIterator2> -__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _Sentinel2 __last2) { - while (__first1 != __last1 && __first2 != __last2) { - _IterOps<_AlgPolicy>::iter_swap(__first1, __first2); - ++__first1; - ++__first2; - } - - return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2)); -} - -// 2+1 iterators: size2 >= size1. -template -_LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator1, _ForwardIterator2> -__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) { - while (__first1 != __last1) { - _IterOps<_AlgPolicy>::iter_swap(__first1, __first2); - ++__first1; - ++__first2; - } - - return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator2 -swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { - return std::__swap_ranges<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)).second; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_SWAP_RANGES_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/three_way_comp_ref_type.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/three_way_comp_ref_type.h deleted file mode 100644 index 7e978b8..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/three_way_comp_ref_type.h +++ /dev/null @@ -1,26 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_THREE_WAY_COMP_REF_TYPE_H -#define _LIBCPP___CXX03___ALGORITHM_THREE_WAY_COMP_REF_TYPE_H - -#include <__cxx03/__assert> -#include <__cxx03/__compare/ordering.h> -#include <__cxx03/__config> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_THREE_WAY_COMP_REF_TYPE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/transform.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/transform.h deleted file mode 100644 index abdf2cc..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/transform.h +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_TRANSFORM_H -#define _LIBCPP___CXX03___ALGORITHM_TRANSFORM_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) { - for (; __first != __last; ++__first, (void)++__result) - *__result = __op(*__first); - return __result; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator transform( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _OutputIterator __result, - _BinaryOperation __binary_op) { - for (; __first1 != __last1; ++__first1, (void)++__first2, ++__result) - *__result = __binary_op(*__first1, *__first2); - return __result; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ALGORITHM_TRANSFORM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/uniform_random_bit_generator_adaptor.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/uniform_random_bit_generator_adaptor.h deleted file mode 100644 index ef789bf..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/uniform_random_bit_generator_adaptor.h +++ /dev/null @@ -1,20 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H -#define _LIBCPP___CXX03___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/invoke.h> -#include <__cxx03/__type_traits/remove_cvref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#endif // _LIBCPP___CXX03___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique.h deleted file mode 100644 index 15980b9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique.h +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_UNIQUE_H -#define _LIBCPP___CXX03___ALGORITHM_UNIQUE_H - -#include <__cxx03/__algorithm/adjacent_find.h> -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// unique - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI std::pair<_Iter, _Iter> -__unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { - __first = std::__adjacent_find(__first, __last, __pred); - if (__first != __last) { - // ... a a ? ... - // f i - _Iter __i = __first; - for (++__i; ++__i != __last;) - if (!__pred(*__first, *__i)) - *++__first = _IterOps<_AlgPolicy>::__iter_move(__i); - ++__first; - return std::pair<_Iter, _Iter>(std::move(__first), std::move(__i)); - } - return std::pair<_Iter, _Iter>(__first, __first); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _ForwardIterator -unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { - return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -unique(_ForwardIterator __first, _ForwardIterator __last) { - return std::unique(__first, __last, __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_UNIQUE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique_copy.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique_copy.h deleted file mode 100644 index 5bed5b5..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unique_copy.h +++ /dev/null @@ -1,127 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_UNIQUE_COPY_H -#define _LIBCPP___CXX03___ALGORITHM_UNIQUE_COPY_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__type_traits/is_base_of.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __unique_copy_tags { - -struct __reread_from_input_tag {}; -struct __reread_from_output_tag {}; -struct __read_from_tmp_value_tag {}; - -} // namespace __unique_copy_tags - -template -_LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _OutputIterator> -__unique_copy(_InputIterator __first, - _Sent __last, - _OutputIterator __result, - _BinaryPredicate&& __pred, - __unique_copy_tags::__read_from_tmp_value_tag) { - if (__first != __last) { - typename _IterOps<_AlgPolicy>::template __value_type<_InputIterator> __t(*__first); - *__result = __t; - ++__result; - while (++__first != __last) { - if (!__pred(__t, *__first)) { - __t = *__first; - *__result = __t; - ++__result; - } - } - } - return pair<_InputIterator, _OutputIterator>(std::move(__first), std::move(__result)); -} - -template -_LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _OutputIterator> -__unique_copy(_ForwardIterator __first, - _Sent __last, - _OutputIterator __result, - _BinaryPredicate&& __pred, - __unique_copy_tags::__reread_from_input_tag) { - if (__first != __last) { - _ForwardIterator __i = __first; - *__result = *__i; - ++__result; - while (++__first != __last) { - if (!__pred(*__i, *__first)) { - *__result = *__first; - ++__result; - __i = __first; - } - } - } - return pair<_ForwardIterator, _OutputIterator>(std::move(__first), std::move(__result)); -} - -template -_LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _InputAndOutputIterator> -__unique_copy(_InputIterator __first, - _Sent __last, - _InputAndOutputIterator __result, - _BinaryPredicate&& __pred, - __unique_copy_tags::__reread_from_output_tag) { - if (__first != __last) { - *__result = *__first; - while (++__first != __last) - if (!__pred(*__result, *__first)) - *++__result = *__first; - ++__result; - } - return pair<_InputIterator, _InputAndOutputIterator>(std::move(__first), std::move(__result)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) { - using __algo_tag = __conditional_t< - is_base_of::iterator_category>::value, - __unique_copy_tags::__reread_from_input_tag, - __conditional_t< - is_base_of::iterator_category>::value && - is_same< typename iterator_traits<_InputIterator>::value_type, - typename iterator_traits<_OutputIterator>::value_type>::value, - __unique_copy_tags::__reread_from_output_tag, - __unique_copy_tags::__read_from_tmp_value_tag> >; - return std::__unique_copy<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), std::move(__result), __pred, __algo_tag()) - .second; -} - -template -inline _LIBCPP_HIDE_FROM_ABI _OutputIterator -unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::unique_copy(std::move(__first), std::move(__last), std::move(__result), __equal_to()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_UNIQUE_COPY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_iter.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_iter.h deleted file mode 100644 index d8daa54..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_iter.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_UNWRAP_ITER_H -#define _LIBCPP___CXX03___ALGORITHM_UNWRAP_ITER_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// TODO: Change the name of __unwrap_iter_impl to something more appropriate -// The job of __unwrap_iter is to remove iterator wrappers (like reverse_iterator or __wrap_iter), -// to reduce the number of template instantiations and to enable pointer-based optimizations e.g. in std::copy. -// -// Some algorithms (e.g. std::copy, but not std::sort) need to convert an -// "unwrapped" result back into the original iterator type. Doing that is the job of __rewrap_iter. - -// Default case - we can't unwrap anything -template ::value> -struct __unwrap_iter_impl { - static _LIBCPP_HIDE_FROM_ABI _Iter __rewrap(_Iter, _Iter __iter) { return __iter; } - static _LIBCPP_HIDE_FROM_ABI _Iter __unwrap(_Iter __i) _NOEXCEPT { return __i; } -}; - -// TODO(hardening): make sure that the following unwrapping doesn't unexpectedly turn hardened iterators into raw -// pointers. - -// It's a contiguous iterator, so we can use a raw pointer instead -template -struct __unwrap_iter_impl<_Iter, true> { - using _ToAddressT = decltype(std::__to_address(std::declval<_Iter>())); - - static _LIBCPP_HIDE_FROM_ABI _Iter __rewrap(_Iter __orig_iter, _ToAddressT __unwrapped_iter) { - return __orig_iter + (__unwrapped_iter - std::__to_address(__orig_iter)); - } - - static _LIBCPP_HIDE_FROM_ABI _ToAddressT __unwrap(_Iter __i) _NOEXCEPT { return std::__to_address(__i); } -}; - -template , - __enable_if_t::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI decltype(_Impl::__unwrap(std::declval<_Iter>())) __unwrap_iter(_Iter __i) _NOEXCEPT { - return _Impl::__unwrap(__i); -} - -template > -_LIBCPP_HIDE_FROM_ABI _OrigIter __rewrap_iter(_OrigIter __orig_iter, _Iter __iter) _NOEXCEPT { - return _Impl::__rewrap(std::move(__orig_iter), std::move(__iter)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_UNWRAP_ITER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_range.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_range.h deleted file mode 100644 index 1926676..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/unwrap_range.h +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_UNWRAP_RANGE_H -#define _LIBCPP___CXX03___ALGORITHM_UNWRAP_RANGE_H - -#include <__cxx03/__algorithm/unwrap_iter.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/next.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __unwrap_range and __rewrap_range are used to unwrap ranges which may have different iterator and sentinel types. -// __unwrap_iter and __rewrap_iter don't work for this, because they assume that the iterator and sentinel have -// the same type. __unwrap_range tries to get two iterators and then forward to __unwrap_iter. - -template ()))> -_LIBCPP_HIDE_FROM_ABI pair<_Unwrapped, _Unwrapped> __unwrap_range(_Iter __first, _Iter __last) { - return std::make_pair(std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))); -} - -template -_LIBCPP_HIDE_FROM_ABI _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) { - return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_UNWRAP_RANGE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/upper_bound.h b/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/upper_bound.h deleted file mode 100644 index 6c7cc37..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__algorithm/upper_bound.h +++ /dev/null @@ -1,68 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ALGORITHM_UPPER_BOUND_H -#define _LIBCPP___CXX03___ALGORITHM_UPPER_BOUND_H - -#include <__cxx03/__algorithm/comp.h> -#include <__cxx03/__algorithm/half_positive.h> -#include <__cxx03/__algorithm/iterator_operations.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/identity.h> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/distance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _Iter -__upper_bound(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) { - auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); - while (__len != 0) { - auto __half_len = std::__half_positive(__len); - auto __mid = _IterOps<_AlgPolicy>::next(__first, __half_len); - if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid))) - __len = __half_len; - else { - __first = ++__mid; - __len -= __half_len + 1; - } - } - return __first; -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); - return std::__upper_bound<_ClassicAlgPolicy>( - std::move(__first), std::move(__last), __value, std::move(__comp), std::__identity()); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator -upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { - return std::upper_bound(std::move(__first), std::move(__last), __value, __less<>()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ALGORITHM_UPPER_BOUND_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__assert b/third_party/libcxx/include/c++/v1/__cxx03/__assert deleted file mode 100644 index f6c4d8e..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__assert +++ /dev/null @@ -1,118 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ASSERT -#define _LIBCPP___CXX03___ASSERT - -#include <__assertion_handler> // Note: this include is generated by CMake and is potentially vendor-provided. -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define _LIBCPP_ASSERT(expression, message) \ - (__builtin_expect(static_cast(expression), 1) \ - ? (void)0 \ - : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \ - expression) " failed: " message "\n")) - -// TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add -// assumptions without a clear optimization intent, disable that to avoid worsening the code generation. -// See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a discussion. -#if 0 && __has_builtin(__builtin_assume) -# define _LIBCPP_ASSUME(expression) \ - (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \ - __builtin_assume(static_cast(expression)) _LIBCPP_DIAGNOSTIC_POP) -#else -# define _LIBCPP_ASSUME(expression) ((void)0) -#endif - -// clang-format off -// Fast hardening mode checks. - -#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST - -// Enabled checks. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) -// Disabled checks. -// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access. -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) -// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security -// vulnerability. -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) - -// Extensive hardening mode checks. - -#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE - -// Enabled checks. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) -// Disabled checks. -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) - -// Debug hardening mode checks. - -#elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG - -// All checks enabled. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) - -// Disable all checks if hardening is not enabled. - -#else - -// All checks disabled. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) - -#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST -// clang-format on - -#endif // _LIBCPP___CXX03___ASSERT diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/aliases.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/aliases.h deleted file mode 100644 index 4cb75ee..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/aliases.h +++ /dev/null @@ -1,85 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_ALIASES_H -#define _LIBCPP___CXX03___ATOMIC_ALIASES_H - -#include <__cxx03/__atomic/atomic.h> -#include <__cxx03/__atomic/atomic_lock_free.h> -#include <__cxx03/__atomic/contention_t.h> -#include <__cxx03/__atomic/is_always_lock_free.h> -#include <__cxx03/__config> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__type_traits/make_unsigned.h> -#include <__cxx03/cstddef> -#include <__cxx03/cstdint> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -using atomic_bool = atomic; -using atomic_char = atomic; -using atomic_schar = atomic; -using atomic_uchar = atomic; -using atomic_short = atomic; -using atomic_ushort = atomic; -using atomic_int = atomic; -using atomic_uint = atomic; -using atomic_long = atomic; -using atomic_ulong = atomic; -using atomic_llong = atomic; -using atomic_ullong = atomic; -#ifndef _LIBCPP_HAS_NO_CHAR8_T -using atomic_char8_t = atomic; -#endif -using atomic_char16_t = atomic; -using atomic_char32_t = atomic; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using atomic_wchar_t = atomic; -#endif - -using atomic_int_least8_t = atomic; -using atomic_uint_least8_t = atomic; -using atomic_int_least16_t = atomic; -using atomic_uint_least16_t = atomic; -using atomic_int_least32_t = atomic; -using atomic_uint_least32_t = atomic; -using atomic_int_least64_t = atomic; -using atomic_uint_least64_t = atomic; - -using atomic_int_fast8_t = atomic; -using atomic_uint_fast8_t = atomic; -using atomic_int_fast16_t = atomic; -using atomic_uint_fast16_t = atomic; -using atomic_int_fast32_t = atomic; -using atomic_uint_fast32_t = atomic; -using atomic_int_fast64_t = atomic; -using atomic_uint_fast64_t = atomic; - -using atomic_int8_t = atomic< int8_t>; -using atomic_uint8_t = atomic; -using atomic_int16_t = atomic< int16_t>; -using atomic_uint16_t = atomic; -using atomic_int32_t = atomic< int32_t>; -using atomic_uint32_t = atomic; -using atomic_int64_t = atomic< int64_t>; -using atomic_uint64_t = atomic; - -using atomic_intptr_t = atomic; -using atomic_uintptr_t = atomic; -using atomic_size_t = atomic; -using atomic_ptrdiff_t = atomic; -using atomic_intmax_t = atomic; -using atomic_uintmax_t = atomic; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_ALIASES_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic.h deleted file mode 100644 index f2e8493..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic.h +++ /dev/null @@ -1,484 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_ATOMIC_H -#define _LIBCPP___CXX03___ATOMIC_ATOMIC_H - -#include <__cxx03/__atomic/atomic_base.h> -#include <__cxx03/__atomic/check_memory_order.h> -#include <__cxx03/__atomic/cxx_atomic_impl.h> -#include <__cxx03/__atomic/memory_order.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/operations.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__type_traits/is_floating_point.h> -#include <__cxx03/__type_traits/is_function.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/remove_const.h> -#include <__cxx03/__type_traits/remove_pointer.h> -#include <__cxx03/__type_traits/remove_volatile.h> -#include <__cxx03/__utility/forward.h> -#include <__cxx03/cstddef> -#include <__cxx03/cstring> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct atomic : public __atomic_base<_Tp> { - using __base = __atomic_base<_Tp>; - - _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI atomic(_Tp __d) _NOEXCEPT : __base(__d) {} - - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile _NOEXCEPT { - __base::store(__d); - return __d; - } - _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) _NOEXCEPT { - __base::store(__d); - return __d; - } - - atomic& operator=(const atomic&) = delete; - atomic& operator=(const atomic&) volatile = delete; -}; - -// atomic - -template -struct atomic<_Tp*> : public __atomic_base<_Tp*> { - using __base = __atomic_base<_Tp*>; - - using difference_type = ptrdiff_t; - - _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} - - _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) volatile _NOEXCEPT { - __base::store(__d); - return __d; - } - _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) _NOEXCEPT { - __base::store(__d); - return __d; - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - // __atomic_fetch_add accepts function pointers, guard against them. - static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) volatile _NOEXCEPT { return fetch_add(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) _NOEXCEPT { return fetch_add(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) volatile _NOEXCEPT { return fetch_sub(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) _NOEXCEPT { return fetch_sub(1); } - _LIBCPP_HIDE_FROM_ABI _Tp* operator++() volatile _NOEXCEPT { return fetch_add(1) + 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator++() _NOEXCEPT { return fetch_add(1) + 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--() volatile _NOEXCEPT { return fetch_sub(1) - 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator--() _NOEXCEPT { return fetch_sub(1) - 1; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT { return fetch_sub(__op) - __op; } - - atomic& operator=(const atomic&) = delete; - atomic& operator=(const atomic&) volatile = delete; -}; - -// atomic_is_lock_free - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT { - return __o->is_lock_free(); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT { - return __o->is_lock_free(); -} - -// atomic_init - -template -_LIBCPP_HIDE_FROM_ABI void atomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - std::__cxx_atomic_init(std::addressof(__o->__a_), __d); -} - -template -_LIBCPP_HIDE_FROM_ABI void atomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - std::__cxx_atomic_init(std::addressof(__o->__a_), __d); -} - -// atomic_store - -template -_LIBCPP_HIDE_FROM_ABI void atomic_store(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - __o->store(__d); -} - -template -_LIBCPP_HIDE_FROM_ABI void atomic_store(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - __o->store(__d); -} - -// atomic_store_explicit - -template -_LIBCPP_HIDE_FROM_ABI void -atomic_store_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - __o->store(__d, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI void -atomic_store_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - __o->store(__d, __m); -} - -// atomic_load - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT { - return __o->load(); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const atomic<_Tp>* __o) _NOEXCEPT { - return __o->load(); -} - -// atomic_load_explicit - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->load(__m); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->load(__m); -} - -// atomic_exchange - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->exchange(__d); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->exchange(__d); -} - -// atomic_exchange_explicit - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_exchange_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT { - return __o->exchange(__d, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_exchange_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT { - return __o->exchange(__d, __m); -} - -// atomic_compare_exchange_weak - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_weak(*__e, __d); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak( - atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_weak(*__e, __d); -} - -// atomic_compare_exchange_strong - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_strong(*__e, __d); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong( - atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { - return __o->compare_exchange_strong(*__e, __d); -} - -// atomic_compare_exchange_weak_explicit - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( - volatile atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_weak(*__e, __d, __s, __f); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( - atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_weak(*__e, __d, __s, __f); -} - -// atomic_compare_exchange_strong_explicit - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( - volatile atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_strong(*__e, __d, __s, __f); -} - -template -_LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( - atomic<_Tp>* __o, - typename atomic<_Tp>::value_type* __e, - typename atomic<_Tp>::value_type __d, - memory_order __s, - memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return __o->compare_exchange_strong(*__e, __d, __s, __f); -} - -// atomic_wait - -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_wait(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) _NOEXCEPT { - return __o->wait(__v); -} - -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_wait(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) _NOEXCEPT { - return __o->wait(__v); -} - -// atomic_wait_explicit - -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_wait_explicit(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->wait(__v, __m); -} - -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_wait_explicit(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return __o->wait(__v, __m); -} - -// atomic_notify_one - -template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_one(); -} -template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_one(); -} - -// atomic_notify_all - -template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_all(); -} -template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT { - __o->notify_all(); -} - -// atomic_fetch_add - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_add(__op); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_add(__op); -} - -// atomic_fetch_add_explicit - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_add(__op, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_add(__op, __m); -} - -// atomic_fetch_sub - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_sub(__op); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { - return __o->fetch_sub(__op); -} - -// atomic_fetch_sub_explicit - -template -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_sub(__op, __m); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_sub(__op, __m); -} - -// atomic_fetch_and - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_and(__op); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_and(__op); -} - -// atomic_fetch_and_explicit - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_and(__op, __m); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_and_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_and(__op, __m); -} - -// atomic_fetch_or - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_or(__op); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_or(__op); -} - -// atomic_fetch_or_explicit - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_or(__op, __m); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_or_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_or(__op, __m); -} - -// atomic_fetch_xor - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_xor(__op); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { - return __o->fetch_xor(__op); -} - -// atomic_fetch_xor_explicit - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor_explicit( - volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_xor(__op, __m); -} - -template ::value && !is_same<_Tp, bool>::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -atomic_fetch_xor_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { - return __o->fetch_xor(__op, __m); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_ATOMIC_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_base.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_base.h deleted file mode 100644 index d79ef7d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_base.h +++ /dev/null @@ -1,217 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_ATOMIC_BASE_H -#define _LIBCPP___CXX03___ATOMIC_ATOMIC_BASE_H - -#include <__cxx03/__atomic/atomic_sync.h> -#include <__cxx03/__atomic/check_memory_order.h> -#include <__cxx03/__atomic/cxx_atomic_impl.h> -#include <__cxx03/__atomic/is_always_lock_free.h> -#include <__cxx03/__atomic/memory_order.h> -#include <__cxx03/__config> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__type_traits/is_nothrow_constructible.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/version> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value && !is_same<_Tp, bool>::value> -struct __atomic_base // false -{ - mutable __cxx_atomic_impl<_Tp> __a_; - - using value_type = _Tp; - - _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT { - return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>)); - } - _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT { - return static_cast<__atomic_base const volatile*>(this)->is_lock_free(); - } - _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - std::__cxx_atomic_store(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - std::__cxx_atomic_store(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return std::__cxx_atomic_load(std::addressof(__a_), __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return std::__cxx_atomic_load(std::addressof(__a_), __m); - } - _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); } - _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); } - _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const - volatile _NOEXCEPT { - std::__atomic_wait(*this, __v, __m); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void - wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - std::__atomic_wait(*this, __v, __m); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { - std::__atomic_notify_one(*this); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT { - std::__atomic_notify_all(*this); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); } - - _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} - - __atomic_base(const __atomic_base&) = delete; -}; - -// atomic - -template -struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> { - using __base = __atomic_base<_Tp, false>; - - using difference_type = typename __base::value_type; - - _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; } -}; - -// Here we need _IsIntegral because the default template argument is not enough -// e.g __atomic_base is __atomic_base, which inherits from -// __atomic_base and the caller of the wait function is -// __atomic_base. So specializing __atomic_base<_Tp> does not work -template -struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > { - static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_base<_Tp, _IsIntegral>& __a, memory_order __order) { - return __a.load(__order); - } - - static _LIBCPP_HIDE_FROM_ABI _Tp - __atomic_load(const volatile __atomic_base<_Tp, _IsIntegral>& __this, memory_order __order) { - return __this.load(__order); - } - - static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_Tp>* - __atomic_contention_address(const __atomic_base<_Tp, _IsIntegral>& __a) { - return std::addressof(__a.__a_); - } - - static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_Tp>* - __atomic_contention_address(const volatile __atomic_base<_Tp, _IsIntegral>& __this) { - return std::addressof(__this.__a_); - } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_ATOMIC_BASE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_flag.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_flag.h deleted file mode 100644 index 316e014..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_flag.h +++ /dev/null @@ -1,184 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_ATOMIC_FLAG_H -#define _LIBCPP___CXX03___ATOMIC_ATOMIC_FLAG_H - -#include <__cxx03/__atomic/atomic_sync.h> -#include <__cxx03/__atomic/contention_t.h> -#include <__cxx03/__atomic/cxx_atomic_impl.h> -#include <__cxx03/__atomic/memory_order.h> -#include <__cxx03/__chrono/duration.h> -#include <__cxx03/__config> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__thread/support.h> -#include <__cxx03/cstdint> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -struct atomic_flag { - __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_; - - _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { - return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m); - } - _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m); - } - - _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m); - } - _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m); - } - _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m); - } - _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT { - __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m); - } - - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void - wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { - std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); - } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void - wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); - } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { - std::__atomic_notify_one(*this); - } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { - std::__atomic_notify_one(*this); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT { - std::__atomic_notify_all(*this); - } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { - std::__atomic_notify_all(*this); - } - atomic_flag() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION - - atomic_flag(const atomic_flag&) = delete; - atomic_flag& operator=(const atomic_flag&) = delete; - atomic_flag& operator=(const atomic_flag&) volatile = delete; -}; - -template <> -struct __atomic_waitable_traits { - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATOMIC_FLAG_TYPE __atomic_load(const atomic_flag& __a, memory_order __order) { - return std::__cxx_atomic_load(&__a.__a_, __order); - } - - static _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATOMIC_FLAG_TYPE - __atomic_load(const volatile atomic_flag& __a, memory_order __order) { - return std::__cxx_atomic_load(&__a.__a_, __order); - } - - static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE>* - __atomic_contention_address(const atomic_flag& __a) { - return std::addressof(__a.__a_); - } - - static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE>* - __atomic_contention_address(const volatile atomic_flag& __a) { - return std::addressof(__a.__a_); - } -}; - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test(const volatile atomic_flag* __o) _NOEXCEPT { return __o->test(); } - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test(const atomic_flag* __o) _NOEXCEPT { return __o->test(); } - -inline _LIBCPP_HIDE_FROM_ABI bool -atomic_flag_test_explicit(const volatile atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_explicit(const atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT { - return __o->test_and_set(); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT { return __o->test_and_set(); } - -inline _LIBCPP_HIDE_FROM_ABI bool -atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test_and_set(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT { - return __o->test_and_set(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT { __o->clear(); } - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear(atomic_flag* __o) _NOEXCEPT { __o->clear(); } - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT { - __o->clear(__m); -} - -inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT { - __o->clear(__m); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT { - __o->wait(__v); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT { - __o->wait(__v); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_wait_explicit(const volatile atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT { - __o->wait(__v, __m); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_wait_explicit(const atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT { - __o->wait(__v, __m); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT { - __o->notify_one(); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT { - __o->notify_one(); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT { - __o->notify_all(); -} - -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT { - __o->notify_all(); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_ATOMIC_FLAG_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_init.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_init.h deleted file mode 100644 index 16b2752..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_init.h +++ /dev/null @@ -1,21 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_ATOMIC_INIT_H -#define _LIBCPP___CXX03___ATOMIC_ATOMIC_INIT_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define ATOMIC_FLAG_INIT {false} -#define ATOMIC_VAR_INIT(__v) {__v} - -#endif // _LIBCPP___CXX03___ATOMIC_ATOMIC_INIT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_lock_free.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_lock_free.h deleted file mode 100644 index 297d148..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_lock_free.h +++ /dev/null @@ -1,48 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_ATOMIC_LOCK_FREE_H -#define _LIBCPP___CXX03___ATOMIC_ATOMIC_LOCK_FREE_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) -# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE -# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE -# ifndef _LIBCPP_HAS_NO_CHAR8_T -# define ATOMIC_CHAR8_T_LOCK_FREE __CLANG_ATOMIC_CHAR8_T_LOCK_FREE -# endif -# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE -# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE -# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE -# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE -# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE -# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE -# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE -# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE -#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE) -# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE -# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE -# ifndef _LIBCPP_HAS_NO_CHAR8_T -# define ATOMIC_CHAR8_T_LOCK_FREE __GCC_ATOMIC_CHAR8_T_LOCK_FREE -# endif -# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE -# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE -# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE -# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE -# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE -# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE -# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE -# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE -#endif - -#endif // _LIBCPP___CXX03___ATOMIC_ATOMIC_LOCK_FREE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_sync.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_sync.h deleted file mode 100644 index ca029f0..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/atomic_sync.h +++ /dev/null @@ -1,205 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_ATOMIC_SYNC_H -#define _LIBCPP___CXX03___ATOMIC_ATOMIC_SYNC_H - -#include <__cxx03/__atomic/contention_t.h> -#include <__cxx03/__atomic/cxx_atomic_impl.h> -#include <__cxx03/__atomic/memory_order.h> -#include <__cxx03/__atomic/to_gcc_order.h> -#include <__cxx03/__chrono/duration.h> -#include <__cxx03/__config> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__thread/poll_with_backoff.h> -#include <__cxx03/__thread/support.h> -#include <__cxx03/__type_traits/conjunction.h> -#include <__cxx03/__type_traits/decay.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/void_t.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/cstring> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// The customisation points to enable the following functions: -// - __atomic_wait -// - __atomic_wait_unless -// - __atomic_notify_one -// - __atomic_notify_all -// Note that std::atomic::wait was back-ported to C++03 -// The below implementations look ugly to support C++03 -template -struct __atomic_waitable_traits { - template - static void __atomic_load(_AtomicWaitable&&, memory_order) = delete; - - template - static void __atomic_contention_address(_AtomicWaitable&&) = delete; -}; - -template -struct __atomic_waitable : false_type {}; - -template -struct __atomic_waitable< _Tp, - __void_t >::__atomic_load( - std::declval(), std::declval())), - decltype(__atomic_waitable_traits<__decay_t<_Tp> >::__atomic_contention_address( - std::declval()))> > : true_type {}; - -template -struct __atomic_wait_poll_impl { - const _AtomicWaitable& __a_; - _Poll __poll_; - memory_order __order_; - - _LIBCPP_HIDE_FROM_ABI bool operator()() const { - auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a_, __order_); - return __poll_(__current_val); - } -}; - -#ifndef _LIBCPP_HAS_NO_THREADS - -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*) _NOEXCEPT; -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(void const volatile*) _NOEXCEPT; -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t -__libcpp_atomic_monitor(void const volatile*) _NOEXCEPT; -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void -__libcpp_atomic_wait(void const volatile*, __cxx_contention_t) _NOEXCEPT; - -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void -__cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile*) _NOEXCEPT; -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void -__cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile*) _NOEXCEPT; -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t -__libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile*) _NOEXCEPT; -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void -__libcpp_atomic_wait(__cxx_atomic_contention_t const volatile*, __cxx_contention_t) _NOEXCEPT; - -template -struct __atomic_wait_backoff_impl { - const _AtomicWaitable& __a_; - _Poll __poll_; - memory_order __order_; - - using __waitable_traits = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; - - _LIBCPP_AVAILABILITY_SYNC - _LIBCPP_HIDE_FROM_ABI bool - __update_monitor_val_and_poll(__cxx_atomic_contention_t const volatile*, __cxx_contention_t& __monitor_val) const { - // In case the contention type happens to be __cxx_atomic_contention_t, i.e. __cxx_atomic_impl, - // the platform wait is directly monitoring the atomic value itself. - // `__poll_` takes the current value of the atomic as an in-out argument - // to potentially modify it. After it returns, `__monitor` has a value - // which can be safely waited on by `std::__libcpp_atomic_wait` without any - // ABA style issues. - __monitor_val = __waitable_traits::__atomic_load(__a_, __order_); - return __poll_(__monitor_val); - } - - _LIBCPP_AVAILABILITY_SYNC - _LIBCPP_HIDE_FROM_ABI bool - __update_monitor_val_and_poll(void const volatile* __contention_address, __cxx_contention_t& __monitor_val) const { - // In case the contention type is anything else, platform wait is monitoring a __cxx_atomic_contention_t - // from the global pool, the monitor comes from __libcpp_atomic_monitor - __monitor_val = std::__libcpp_atomic_monitor(__contention_address); - auto __current_val = __waitable_traits::__atomic_load(__a_, __order_); - return __poll_(__current_val); - } - - _LIBCPP_AVAILABILITY_SYNC - _LIBCPP_HIDE_FROM_ABI bool operator()(chrono::nanoseconds __elapsed) const { - if (__elapsed > chrono::microseconds(64)) { - auto __contention_address = __waitable_traits::__atomic_contention_address(__a_); - __cxx_contention_t __monitor_val; - if (__update_monitor_val_and_poll(__contention_address, __monitor_val)) - return true; - std::__libcpp_atomic_wait(__contention_address, __monitor_val); - } else if (__elapsed > chrono::microseconds(4)) - __libcpp_thread_yield(); - else { - } // poll - return false; - } -}; - -// The semantics of this function are similar to `atomic`'s -// `.wait(T old, std::memory_order order)`, but instead of having a hardcoded -// predicate (is the loaded value unequal to `old`?), the predicate function is -// specified as an argument. The loaded value is given as an in-out argument to -// the predicate. If the predicate function returns `true`, -// `__atomic_wait_unless` will return. If the predicate function returns -// `false`, it must set the argument to its current understanding of the atomic -// value. The predicate function must not return `false` spuriously. -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -__atomic_wait_unless(const _AtomicWaitable& __a, _Poll&& __poll, memory_order __order) { - static_assert(__atomic_waitable<_AtomicWaitable>::value, ""); - __atomic_wait_poll_impl<_AtomicWaitable, __decay_t<_Poll> > __poll_impl = {__a, __poll, __order}; - __atomic_wait_backoff_impl<_AtomicWaitable, __decay_t<_Poll> > __backoff_fn = {__a, __poll, __order}; - std::__libcpp_thread_poll_with_backoff(__poll_impl, __backoff_fn); -} - -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable& __a) { - static_assert(__atomic_waitable<_AtomicWaitable>::value, ""); - std::__cxx_atomic_notify_one(__atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_contention_address(__a)); -} - -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable& __a) { - static_assert(__atomic_waitable<_AtomicWaitable>::value, ""); - std::__cxx_atomic_notify_all(__atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_contention_address(__a)); -} - -#else // _LIBCPP_HAS_NO_THREADS - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, _Poll&& __poll, memory_order __order) { - __atomic_wait_poll_impl<_AtomicWaitable, __decay_t<_Poll> > __poll_fn = {__a, __poll, __order}; - std::__libcpp_thread_poll_with_backoff(__poll_fn, __spinning_backoff_policy()); -} - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable&) {} - -template -_LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable&) {} - -#endif // _LIBCPP_HAS_NO_THREADS - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) { - return std::memcmp(std::addressof(__lhs), std::addressof(__rhs), sizeof(_Tp)) == 0; -} - -template -struct __atomic_compare_unequal_to { - _Tp __val_; - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __arg) const { - return !std::__cxx_nonatomic_compare_equal(__arg, __val_); - } -}; - -template -_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -__atomic_wait(_AtomicWaitable& __a, _Up __val, memory_order __order) { - static_assert(__atomic_waitable<_AtomicWaitable>::value, ""); - __atomic_compare_unequal_to<_Up> __nonatomic_equal = {__val}; - std::__atomic_wait_unless(__a, __nonatomic_equal, __order); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_ATOMIC_SYNC_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/check_memory_order.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/check_memory_order.h deleted file mode 100644 index 5661efd..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/check_memory_order.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_CHECK_MEMORY_ORDER_H -#define _LIBCPP___CXX03___ATOMIC_CHECK_MEMORY_ORDER_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ - _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \ - _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \ - _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || __f == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#define _LIBCPP_CHECK_WAIT_MEMORY_ORDER(__m) \ - _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \ - "memory order argument to atomic operation is invalid") - -#endif // _LIBCPP___CXX03___ATOMIC_CHECK_MEMORY_ORDER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/contention_t.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/contention_t.h deleted file mode 100644 index c7ecf9d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/contention_t.h +++ /dev/null @@ -1,32 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_CONTENTION_T_H -#define _LIBCPP___CXX03___ATOMIC_CONTENTION_T_H - -#include <__cxx03/__atomic/cxx_atomic_impl.h> -#include <__cxx03/__config> -#include <__cxx03/cstdint> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if defined(__linux__) || defined(__Fuchsia__) || (defined(_AIX) && !defined(__64BIT__)) -using __cxx_contention_t = int32_t; -#else -using __cxx_contention_t = int64_t; -#endif // __linux__ || __Fuchsia__ || (_AIX && !__64BIT__) - -using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_CONTENTION_T_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/cxx_atomic_impl.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/cxx_atomic_impl.h deleted file mode 100644 index 4ec516b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/cxx_atomic_impl.h +++ /dev/null @@ -1,498 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_CXX_ATOMIC_IMPL_H -#define _LIBCPP___CXX03___ATOMIC_CXX_ATOMIC_IMPL_H - -#include <__cxx03/__atomic/memory_order.h> -#include <__cxx03/__atomic/to_gcc_order.h> -#include <__cxx03/__config> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__type_traits/is_assignable.h> -#include <__cxx03/__type_traits/is_trivially_copyable.h> -#include <__cxx03/__type_traits/remove_const.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) - -// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because -// the default operator= in an object is not volatile, a byte-by-byte copy -// is required. -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { - __a_value = __val; -} -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { - volatile char* __to = reinterpret_cast(std::addressof(__a_value)); - volatile char* __end = __to + sizeof(_Tp); - volatile const char* __from = reinterpret_cast(std::addressof(__val)); - while (__to != __end) - *__to++ = *__from++; -} - -template -struct __cxx_atomic_base_impl { - _LIBCPP_HIDE_FROM_ABI __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} - explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {} - _Tp __a_value; -}; - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { - __cxx_atomic_assign_volatile(__a->__a_value, __val); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { - __a->__a_value = __val; -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) { - __atomic_thread_fence(__to_gcc_order(__order)); -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) { - __atomic_signal_fence(__to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { - __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { - __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { - _Tp __ret; - __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(const volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { - __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(const __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { - __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { - _Tp __ret; - __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { - _Tp __ret; - __atomic_exchange( - std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { - _Tp __ret; - __atomic_exchange( - std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - volatile __cxx_atomic_base_impl<_Tp>* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - false, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - false, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - volatile __cxx_atomic_base_impl<_Tp>* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - true, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - true, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -struct __skip_amt { - enum { value = 1 }; -}; - -template -struct __skip_amt<_Tp*> { - enum { value = sizeof(_Tp) }; -}; - -// FIXME: Haven't figured out what the spec says about using arrays with -// atomic_fetch_add. Force a failure rather than creating bad behavior. -template -struct __skip_amt<_Tp[]> {}; -template -struct __skip_amt<_Tp[n]> {}; - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -# define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) - -#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP) - -template -struct __cxx_atomic_base_impl { - _LIBCPP_HIDE_FROM_ABI __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} - explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT : __a_value(__value) {} - _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value; -}; - -# define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT { - __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order)); -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT { - __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT { - __c11_atomic_init(std::addressof(__a->__a_value), __val); -} -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) _NOEXCEPT { - __c11_atomic_init(std::addressof(__a->__a_value), __val); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT { - __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) _NOEXCEPT { - __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - return __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - return __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - *__dst = __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const* __a, _Tp* __dst, memory_order __order) _NOEXCEPT { - using __ptr_type = __remove_const_t__a_value)>*; - *__dst = __c11_atomic_load( - const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT { - return __c11_atomic_exchange( - std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) _NOEXCEPT { - return __c11_atomic_exchange( - std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order)); -} - -_LIBCPP_HIDE_FROM_ABI inline memory_order __to_failure_order(memory_order __order) { - // Avoid switch statement to make this a constexpr. - return __order == memory_order_release - ? memory_order_relaxed - : (__order == memory_order_acq_rel ? memory_order_acquire : __order); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - __cxx_atomic_base_impl<_Tp> volatile* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) _NOEXCEPT { - return __c11_atomic_compare_exchange_strong( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) - _NOEXCEPT { - return __c11_atomic_compare_exchange_strong( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - __cxx_atomic_base_impl<_Tp> volatile* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) _NOEXCEPT { - return __c11_atomic_compare_exchange_weak( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) - _NOEXCEPT { - return __c11_atomic_compare_exchange_weak( - std::addressof(__a->__a_value), - __expected, - __value, - static_cast<__memory_order_underlying_t>(__success), - static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_add( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp* -__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_sub( - std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_and( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_and( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_or( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_or( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_xor( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { - return __c11_atomic_fetch_xor( - std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); -} - -#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP - -template > -struct __cxx_atomic_impl : public _Base { - static_assert(is_trivially_copyable<_Tp>::value, "std::atomic requires that 'T' be a trivially copyable type"); - - _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default; - _LIBCPP_HIDE_FROM_ABI explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {} -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_CXX_ATOMIC_IMPL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/fence.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/fence.h deleted file mode 100644 index 05eaa83..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/fence.h +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_FENCE_H -#define _LIBCPP___CXX03___ATOMIC_FENCE_H - -#include <__cxx03/__atomic/cxx_atomic_impl.h> -#include <__cxx03/__atomic/memory_order.h> -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -inline _LIBCPP_HIDE_FROM_ABI void atomic_thread_fence(memory_order __m) _NOEXCEPT { __cxx_atomic_thread_fence(__m); } - -inline _LIBCPP_HIDE_FROM_ABI void atomic_signal_fence(memory_order __m) _NOEXCEPT { __cxx_atomic_signal_fence(__m); } - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_FENCE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/is_always_lock_free.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/is_always_lock_free.h deleted file mode 100644 index 45628ae..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/is_always_lock_free.h +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_IS_ALWAYS_LOCK_FREE_H -#define _LIBCPP___CXX03___ATOMIC_IS_ALWAYS_LOCK_FREE_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __libcpp_is_always_lock_free { - // __atomic_always_lock_free is available in all Standard modes - static const bool __value = __atomic_always_lock_free(sizeof(_Tp), nullptr); -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_IS_ALWAYS_LOCK_FREE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/kill_dependency.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/kill_dependency.h deleted file mode 100644 index 1e0dfc8..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/kill_dependency.h +++ /dev/null @@ -1,27 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_KILL_DEPENDENCY_H -#define _LIBCPP___CXX03___ATOMIC_KILL_DEPENDENCY_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _Tp kill_dependency(_Tp __y) _NOEXCEPT { - return __y; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_KILL_DEPENDENCY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/memory_order.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/memory_order.h deleted file mode 100644 index d610c86..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/memory_order.h +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_MEMORY_ORDER_H -#define _LIBCPP___CXX03___ATOMIC_MEMORY_ORDER_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/underlying_type.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Figure out what the underlying type for `memory_order` would be if it were -// declared as an unscoped enum (accounting for -fshort-enums). Use this result -// to pin the underlying type in C++20. -enum __legacy_memory_order { __mo_relaxed, __mo_consume, __mo_acquire, __mo_release, __mo_acq_rel, __mo_seq_cst }; - -using __memory_order_underlying_t = underlying_type<__legacy_memory_order>::type; - -enum memory_order { - memory_order_relaxed = __mo_relaxed, - memory_order_consume = __mo_consume, - memory_order_acquire = __mo_acquire, - memory_order_release = __mo_release, - memory_order_acq_rel = __mo_acq_rel, - memory_order_seq_cst = __mo_seq_cst, -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_MEMORY_ORDER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/to_gcc_order.h b/third_party/libcxx/include/c++/v1/__cxx03/__atomic/to_gcc_order.h deleted file mode 100644 index aa510c1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__atomic/to_gcc_order.h +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ATOMIC_TO_GCC_ORDER_H -#define _LIBCPP___CXX03___ATOMIC_TO_GCC_ORDER_H - -#include <__cxx03/__atomic/memory_order.h> -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if defined(__ATOMIC_RELAXED) && defined(__ATOMIC_CONSUME) && defined(__ATOMIC_ACQUIRE) && \ - defined(__ATOMIC_RELEASE) && defined(__ATOMIC_ACQ_REL) && defined(__ATOMIC_SEQ_CST) - -_LIBCPP_HIDE_FROM_ABI inline int __to_gcc_order(memory_order __order) { - // Avoid switch statement to make this a constexpr. - return __order == memory_order_relaxed - ? __ATOMIC_RELAXED - : (__order == memory_order_acquire - ? __ATOMIC_ACQUIRE - : (__order == memory_order_release - ? __ATOMIC_RELEASE - : (__order == memory_order_seq_cst - ? __ATOMIC_SEQ_CST - : (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL : __ATOMIC_CONSUME)))); -} - -_LIBCPP_HIDE_FROM_ABI inline int __to_gcc_failure_order(memory_order __order) { - // Avoid switch statement to make this a constexpr. - return __order == memory_order_relaxed - ? __ATOMIC_RELAXED - : (__order == memory_order_acquire - ? __ATOMIC_ACQUIRE - : (__order == memory_order_release - ? __ATOMIC_RELAXED - : (__order == memory_order_seq_cst - ? __ATOMIC_SEQ_CST - : (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE : __ATOMIC_CONSUME)))); -} - -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ATOMIC_TO_GCC_ORDER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__bit/blsr.h b/third_party/libcxx/include/c++/v1/__cxx03/__bit/blsr.h deleted file mode 100644 index b8027d9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__bit/blsr.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___BIT_BLSR_H -#define _LIBCPP___CXX03___BIT_BLSR_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -inline _LIBCPP_HIDE_FROM_ABI unsigned __libcpp_blsr(unsigned __x) _NOEXCEPT { return __x ^ (__x & -__x); } - -inline _LIBCPP_HIDE_FROM_ABI unsigned long __libcpp_blsr(unsigned long __x) _NOEXCEPT { return __x ^ (__x & -__x); } - -inline _LIBCPP_HIDE_FROM_ABI unsigned long long __libcpp_blsr(unsigned long long __x) _NOEXCEPT { - return __x ^ (__x & -__x); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___BIT_BLSR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__bit/countl.h b/third_party/libcxx/include/c++/v1/__cxx03/__bit/countl.h deleted file mode 100644 index 3f0161a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__bit/countl.h +++ /dev/null @@ -1,96 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// TODO: __builtin_clzg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can -// refactor this code to exclusively use __builtin_clzg. - -#ifndef _LIBCPP___CXX03___BIT_COUNTL_H -#define _LIBCPP___CXX03___BIT_COUNTL_H - -#include <__cxx03/__bit/rotate.h> -#include <__cxx03/__config> -#include <__cxx03/__type_traits/is_unsigned_integer.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int __libcpp_clz(unsigned long __x) _NOEXCEPT { - return __builtin_clzl(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int __libcpp_clz(unsigned long long __x) _NOEXCEPT { - return __builtin_clzll(__x); -} - -#ifndef _LIBCPP_HAS_NO_INT128 -inline _LIBCPP_HIDE_FROM_ABI int __libcpp_clz(__uint128_t __x) _NOEXCEPT { -# if __has_builtin(__builtin_clzg) - return __builtin_clzg(__x); -# else - // The function is written in this form due to C++ constexpr limitations. - // The algorithm: - // - Test whether any bit in the high 64-bits is set - // - No bits set: - // - The high 64-bits contain 64 leading zeros, - // - Add the result of the low 64-bits. - // - Any bits set: - // - The number of leading zeros of the input is the number of leading - // zeros in the high 64-bits. - return ((__x >> 64) == 0) ? (64 + __builtin_clzll(static_cast(__x))) - : __builtin_clzll(static_cast(__x >> 64)); -# endif -} -#endif // _LIBCPP_HAS_NO_INT128 - -template -_LIBCPP_HIDE_FROM_ABI int __countl_zero(_Tp __t) _NOEXCEPT { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires an unsigned integer type"); -#if __has_builtin(__builtin_clzg) - return __builtin_clzg(__t, numeric_limits<_Tp>::digits); -#else // __has_builtin(__builtin_clzg) - if (__t == 0) - return numeric_limits<_Tp>::digits; - - if (sizeof(_Tp) <= sizeof(unsigned int)) - return std::__libcpp_clz(static_cast(__t)) - - (numeric_limits::digits - numeric_limits<_Tp>::digits); - else if (sizeof(_Tp) <= sizeof(unsigned long)) - return std::__libcpp_clz(static_cast(__t)) - - (numeric_limits::digits - numeric_limits<_Tp>::digits); - else if (sizeof(_Tp) <= sizeof(unsigned long long)) - return std::__libcpp_clz(static_cast(__t)) - - (numeric_limits::digits - numeric_limits<_Tp>::digits); - else { - int __ret = 0; - int __iter = 0; - const unsigned int __ulldigits = numeric_limits::digits; - while (true) { - __t = std::__rotl(__t, __ulldigits); - if ((__iter = std::__countl_zero(static_cast(__t))) != __ulldigits) - break; - __ret += __iter; - } - return __ret + __iter; - } -#endif // __has_builtin(__builtin_clzg) -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___BIT_COUNTL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__bit/countr.h b/third_party/libcxx/include/c++/v1/__cxx03/__bit/countr.h deleted file mode 100644 index 2f5b559..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__bit/countr.h +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// TODO: __builtin_ctzg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can -// refactor this code to exclusively use __builtin_ctzg. - -#ifndef _LIBCPP___CXX03___BIT_COUNTR_H -#define _LIBCPP___CXX03___BIT_COUNTR_H - -#include <__cxx03/__bit/rotate.h> -#include <__cxx03/__config> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int __libcpp_ctz(unsigned long __x) _NOEXCEPT { - return __builtin_ctzl(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { - return __builtin_ctzll(__x); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI int __countr_zero(_Tp __t) _NOEXCEPT { -#if __has_builtin(__builtin_ctzg) - return __builtin_ctzg(__t, numeric_limits<_Tp>::digits); -#else // __has_builtin(__builtin_ctzg) - if (__t == 0) - return numeric_limits<_Tp>::digits; - if (sizeof(_Tp) <= sizeof(unsigned int)) - return std::__libcpp_ctz(static_cast(__t)); - else if (sizeof(_Tp) <= sizeof(unsigned long)) - return std::__libcpp_ctz(static_cast(__t)); - else if (sizeof(_Tp) <= sizeof(unsigned long long)) - return std::__libcpp_ctz(static_cast(__t)); - else { - int __ret = 0; - const unsigned int __ulldigits = numeric_limits::digits; - while (static_cast(__t) == 0uLL) { - __ret += __ulldigits; - __t >>= __ulldigits; - } - return __ret + std::__libcpp_ctz(static_cast(__t)); - } -#endif // __has_builtin(__builtin_ctzg) -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___BIT_COUNTR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__bit/invert_if.h b/third_party/libcxx/include/c++/v1/__cxx03/__bit/invert_if.h deleted file mode 100644 index cc2815e..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__bit/invert_if.h +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___BIT_INVERT_IF_H -#define _LIBCPP___CXX03___BIT_INVERT_IF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _Tp __invert_if(_Tp __v) { - if (_Invert) - return ~__v; - return __v; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___BIT_INVERT_IF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__bit/popcount.h b/third_party/libcxx/include/c++/v1/__cxx03/__bit/popcount.h deleted file mode 100644 index a61a921..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__bit/popcount.h +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___BIT_POPCOUNT_H -#define _LIBCPP___CXX03___BIT_POPCOUNT_H - -#include <__cxx03/__bit/rotate.h> -#include <__cxx03/__config> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(_Tp __v) { - return __builtin_popcountg(__v); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___BIT_POPCOUNT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__bit/rotate.h b/third_party/libcxx/include/c++/v1/__cxx03/__bit/rotate.h deleted file mode 100644 index fbe121f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__bit/rotate.h +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___BIT_ROTATE_H -#define _LIBCPP___CXX03___BIT_ROTATE_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/is_unsigned_integer.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Writing two full functions for rotl and rotr makes it easier for the compiler -// to optimize the code. On x86 this function becomes the ROL instruction and -// the rotr function becomes the ROR instruction. -template -_LIBCPP_HIDE_FROM_ABI _Tp __rotl(_Tp __x, int __s) _NOEXCEPT { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires an unsigned integer type"); - const int __N = numeric_limits<_Tp>::digits; - int __r = __s % __N; - - if (__r == 0) - return __x; - - if (__r > 0) - return (__x << __r) | (__x >> (__N - __r)); - - return (__x >> -__r) | (__x << (__N + __r)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __rotr(_Tp __x, int __s) _NOEXCEPT { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type"); - const int __N = numeric_limits<_Tp>::digits; - int __r = __s % __N; - - if (__r == 0) - return __x; - - if (__r > 0) - return (__x >> __r) | (__x << (__N - __r)); - - return (__x << -__r) | (__x >> (__N + __r)); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___BIT_ROTATE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__bit_reference b/third_party/libcxx/include/c++/v1/__cxx03/__bit_reference deleted file mode 100644 index ac0005f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__bit_reference +++ /dev/null @@ -1,965 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___BIT_REFERENCE -#define _LIBCPP___CXX03___BIT_REFERENCE - -#include <__cxx03/__algorithm/copy_n.h> -#include <__cxx03/__algorithm/fill_n.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__bit/countr.h> -#include <__cxx03/__bit/invert_if.h> -#include <__cxx03/__bit/popcount.h> -#include <__cxx03/__config> -#include <__cxx03/__fwd/bit_reference.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/construct_at.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__utility/swap.h> -#include <__cxx03/cstring> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __bit_const_reference; - -template -struct __has_storage_type { - static const bool value = false; -}; - -template ::value> -class __bit_reference { - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = typename _Cp::__storage_pointer; - - __storage_pointer __seg_; - __storage_type __mask_; - - friend typename _Cp::__self; - - friend class __bit_const_reference<_Cp>; - friend class __bit_iterator<_Cp, false>; - -public: - using __container = typename _Cp::__self; - - _LIBCPP_HIDE_FROM_ABI __bit_reference(const __bit_reference&) = default; - - _LIBCPP_HIDE_FROM_ABI operator bool() const _NOEXCEPT { return static_cast(*__seg_ & __mask_); } - _LIBCPP_HIDE_FROM_ABI bool operator~() const _NOEXCEPT { return !static_cast(*this); } - - _LIBCPP_HIDE_FROM_ABI __bit_reference& operator=(bool __x) _NOEXCEPT { - if (__x) - *__seg_ |= __mask_; - else - *__seg_ &= ~__mask_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT { - return operator=(static_cast(__x)); - } - - _LIBCPP_HIDE_FROM_ABI void flip() _NOEXCEPT { *__seg_ ^= __mask_; } - _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> operator&() const _NOEXCEPT { - return __bit_iterator<_Cp, false>(__seg_, static_cast(std::__libcpp_ctz(__mask_))); - } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT - : __seg_(__s), - __mask_(__m) {} -}; - -template -class __bit_reference<_Cp, false> {}; - -template -inline _LIBCPP_HIDE_FROM_ABI void swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT { - bool __t = __x; - __x = __y; - __y = __t; -} - -template -class __bit_const_reference { - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = typename _Cp::__const_storage_pointer; - - __storage_pointer __seg_; - __storage_type __mask_; - - friend typename _Cp::__self; - friend class __bit_iterator<_Cp, true>; - -public: - using __container = typename _Cp::__self; - - _LIBCPP_HIDE_FROM_ABI __bit_const_reference(const __bit_const_reference&) = default; - __bit_const_reference& operator=(const __bit_const_reference&) = delete; - - _LIBCPP_HIDE_FROM_ABI __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT - : __seg_(__x.__seg_), - __mask_(__x.__mask_) {} - - _LIBCPP_HIDE_FROM_ABI operator bool() const _NOEXCEPT { return static_cast(*__seg_ & __mask_); } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, true> operator&() const _NOEXCEPT { - return __bit_iterator<_Cp, true>(__seg_, static_cast(std::__libcpp_ctz(__mask_))); - } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT - : __seg_(__s), - __mask_(__m) {} -}; - -// copy - -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_aligned( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz), __n); - __n -= __dn; - __storage_type __m = (__storage_type(~0) << __first.__ctz_) & (__storage_type(~0) >> (__clz - __dn)); - __storage_type __b = *__first.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - __storage_type __nw = __n / __bits_per_word; - std::copy_n(std::__to_address(__first.__seg_), __nw, std::__to_address(__result.__seg_)); - __n -= __nw * __bits_per_word; - __result.__seg_ += __nw; - // do last word - if (__n > 0) { - __first.__seg_ += __nw; - __storage_type __m = __storage_type(~0) >> (__bits_per_word - __n); - __storage_type __b = *__first.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__ctz_ = static_cast(__n); - } - } - return __result; -} - -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_unaligned( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz_f = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz_f), __n); - __n -= __dn; - __storage_type __m = (__storage_type(~0) << __first.__ctz_) & (__storage_type(~0) >> (__clz_f - __dn)); - __storage_type __b = *__first.__seg_ & __m; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); - __m = (__storage_type(~0) << __result.__ctz_) & (__storage_type(~0) >> (__clz_r - __ddn)); - *__result.__seg_ &= ~__m; - if (__result.__ctz_ > __first.__ctz_) - *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_); - else - *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_); - __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); - __dn -= __ddn; - if (__dn > 0) { - __m = __storage_type(~0) >> (__bits_per_word - __dn); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn); - __result.__ctz_ = static_cast(__dn); - } - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __m = __storage_type(~0) << __result.__ctz_; - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { - __storage_type __b = *__first.__seg_; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b << __result.__ctz_; - ++__result.__seg_; - *__result.__seg_ &= __m; - *__result.__seg_ |= __b >> __clz_r; - } - // do last word - if (__n > 0) { - __m = __storage_type(~0) >> (__bits_per_word - __n); - __storage_type __b = *__first.__seg_ & __m; - __storage_type __dn = std::min(__n, static_cast(__clz_r)); - __m = (__storage_type(~0) << __result.__ctz_) & (__storage_type(~0) >> (__clz_r - __dn)); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b << __result.__ctz_; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - __m = __storage_type(~0) >> (__bits_per_word - __n); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> __dn; - __result.__ctz_ = static_cast(__n); - } - } - } - return __result; -} - -template -inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> -copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - if (__first.__ctz_ == __result.__ctz_) - return std::__copy_aligned(__first, __last, __result); - return std::__copy_unaligned(__first, __last, __result); -} - -// copy_backward - -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_aligned( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__last.__ctz_ != 0) { - difference_type __dn = std::min(static_cast(__last.__ctz_), __n); - __n -= __dn; - unsigned __clz = __bits_per_word - __last.__ctz_; - __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz); - __storage_type __b = *__last.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); - // __last.__ctz_ = 0 - } - // __last.__ctz_ == 0 || __n == 0 - // __result.__ctz_ == 0 || __n == 0 - // do middle words - __storage_type __nw = __n / __bits_per_word; - __result.__seg_ -= __nw; - __last.__seg_ -= __nw; - std::copy_n(std::__to_address(__last.__seg_), __nw, std::__to_address(__result.__seg_)); - __n -= __nw * __bits_per_word; - // do last word - if (__n > 0) { - __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n); - __storage_type __b = *--__last.__seg_ & __m; - *--__result.__seg_ &= ~__m; - *__result.__seg_ |= __b; - __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); - } - } - return __result; -} - -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_unaligned( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - using _In = __bit_iterator<_Cp, _IsConst>; - using difference_type = typename _In::difference_type; - using __storage_type = typename _In::__storage_type; - - const int __bits_per_word = _In::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__last.__ctz_ != 0) { - difference_type __dn = std::min(static_cast(__last.__ctz_), __n); - __n -= __dn; - unsigned __clz_l = __bits_per_word - __last.__ctz_; - __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l); - __storage_type __b = *__last.__seg_ & __m; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __ddn = std::min(__dn, static_cast(__result.__ctz_)); - if (__ddn > 0) { - __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r); - *__result.__seg_ &= ~__m; - if (__result.__ctz_ > __last.__ctz_) - *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); - else - *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_); - __result.__ctz_ = static_cast(((-__ddn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); - __dn -= __ddn; - } - if (__dn > 0) { - // __result.__ctz_ == 0 - --__result.__seg_; - __result.__ctz_ = static_cast(-__dn & (__bits_per_word - 1)); - __m = ~__storage_type(0) << __result.__ctz_; - *__result.__seg_ &= ~__m; - __last.__ctz_ -= __dn + __ddn; - *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); - } - // __last.__ctz_ = 0 - } - // __last.__ctz_ == 0 || __n == 0 - // __result.__ctz_ != 0 || __n == 0 - // do middle words - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __m = ~__storage_type(0) >> __clz_r; - for (; __n >= __bits_per_word; __n -= __bits_per_word) { - __storage_type __b = *--__last.__seg_; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> __clz_r; - *--__result.__seg_ &= __m; - *__result.__seg_ |= __b << __result.__ctz_; - } - // do last word - if (__n > 0) { - __m = ~__storage_type(0) << (__bits_per_word - __n); - __storage_type __b = *--__last.__seg_ & __m; - __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __dn = std::min(__n, static_cast(__result.__ctz_)); - __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r); - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_); - __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - // __result.__ctz_ == 0 - --__result.__seg_; - __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); - __m = ~__storage_type(0) << __result.__ctz_; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn)); - } - } - } - return __result; -} - -template -inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> copy_backward( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - if (__last.__ctz_ == __result.__ctz_) - return std::__copy_backward_aligned(__first, __last, __result); - return std::__copy_backward_unaligned(__first, __last, __result); -} - -// move - -template -inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> -move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - return std::copy(__first, __last, __result); -} - -// move_backward - -template -inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> move_backward( - __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { - return std::copy_backward(__first, __last, __result); -} - -// swap_ranges - -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> __swap_ranges_aligned( - __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { - using _I1 = __bit_iterator<_Cl, false>; - using difference_type = typename _I1::difference_type; - using __storage_type = typename _I1::__storage_type; - - const int __bits_per_word = _I1::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1; - *__first.__seg_ |= __b2; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) - swap(*__first.__seg_, *__result.__seg_); - // do last word - if (__n > 0) { - __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1; - *__first.__seg_ |= __b2; - __result.__ctz_ = static_cast(__n); - } - } - return __result; -} - -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> __swap_ranges_unaligned( - __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) { - using _I1 = __bit_iterator<_Cl, false>; - using difference_type = typename _I1::difference_type; - using __storage_type = typename _I1::__storage_type; - - const int __bits_per_word = _I1::__bits_per_word; - difference_type __n = __last - __first; - if (__n > 0) { - // do first word - if (__first.__ctz_ != 0) { - unsigned __clz_f = __bits_per_word - __first.__ctz_; - difference_type __dn = std::min(static_cast(__clz_f), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); - __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - if (__result.__ctz_ > __first.__ctz_) { - unsigned __s = __result.__ctz_ - __first.__ctz_; - *__result.__seg_ |= __b1 << __s; - *__first.__seg_ |= __b2 >> __s; - } else { - unsigned __s = __first.__ctz_ - __result.__ctz_; - *__result.__seg_ |= __b1 >> __s; - *__first.__seg_ |= __b2 << __s; - } - __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); - __dn -= __ddn; - if (__dn > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __dn); - __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - unsigned __s = __first.__ctz_ + __ddn; - *__result.__seg_ |= __b1 >> __s; - *__first.__seg_ |= __b2 << __s; - __result.__ctz_ = static_cast(__dn); - } - ++__first.__seg_; - // __first.__ctz_ = 0; - } - // __first.__ctz_ == 0; - // do middle words - __storage_type __m = ~__storage_type(0) << __result.__ctz_; - unsigned __clz_r = __bits_per_word - __result.__ctz_; - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { - __storage_type __b1 = *__first.__seg_; - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 << __result.__ctz_; - *__first.__seg_ = __b2 >> __result.__ctz_; - ++__result.__seg_; - __b2 = *__result.__seg_ & ~__m; - *__result.__seg_ &= __m; - *__result.__seg_ |= __b1 >> __clz_r; - *__first.__seg_ |= __b2 << __clz_r; - } - // do last word - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b1 = *__first.__seg_ & __m; - *__first.__seg_ &= ~__m; - __storage_type __dn = std::min<__storage_type>(__n, __clz_r); - __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); - __storage_type __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 << __result.__ctz_; - *__first.__seg_ |= __b2 >> __result.__ctz_; - __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; - __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - __b2 = *__result.__seg_ & __m; - *__result.__seg_ &= ~__m; - *__result.__seg_ |= __b1 >> __dn; - *__first.__seg_ |= __b2 << __dn; - __result.__ctz_ = static_cast(__n); - } - } - } - return __result; -} - -template -inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> swap_ranges( - __bit_iterator<_Cl, false> __first1, __bit_iterator<_Cl, false> __last1, __bit_iterator<_Cr, false> __first2) { - if (__first1.__ctz_ == __first2.__ctz_) - return std::__swap_ranges_aligned(__first1, __last1, __first2); - return std::__swap_ranges_unaligned(__first1, __last1, __first2); -} - -// rotate - -template -struct __bit_array { - using difference_type = typename _Cp::difference_type; - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = typename _Cp::__storage_pointer; - using iterator = typename _Cp::iterator; - - static const unsigned __bits_per_word = _Cp::__bits_per_word; - static const unsigned _Np = 4; - - difference_type __size_; - __storage_type __word_[_Np]; - - _LIBCPP_HIDE_FROM_ABI static difference_type capacity() { - return static_cast(_Np * __bits_per_word); - } - _LIBCPP_HIDE_FROM_ABI explicit __bit_array(difference_type __s) : __size_(__s) { - if (__libcpp_is_constant_evaluated()) { - for (size_t __i = 0; __i != __bit_array<_Cp>::_Np; ++__i) - std::__construct_at(__word_ + __i, 0); - } - } - _LIBCPP_HIDE_FROM_ABI iterator begin() { - return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); - } - _LIBCPP_HIDE_FROM_ABI iterator end() { - return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, - static_cast(__size_ % __bits_per_word)); - } -}; - -template -_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> -rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) { - using _I1 = __bit_iterator<_Cp, false>; - using difference_type = typename _I1::difference_type; - - difference_type __d1 = __middle - __first; - difference_type __d2 = __last - __middle; - _I1 __r = __first + __d2; - while (__d1 != 0 && __d2 != 0) { - if (__d1 <= __d2) { - if (__d1 <= __bit_array<_Cp>::capacity()) { - __bit_array<_Cp> __b(__d1); - std::copy(__first, __middle, __b.begin()); - std::copy(__b.begin(), __b.end(), std::copy(__middle, __last, __first)); - break; - } else { - __bit_iterator<_Cp, false> __mp = std::swap_ranges(__first, __middle, __middle); - __first = __middle; - __middle = __mp; - __d2 -= __d1; - } - } else { - if (__d2 <= __bit_array<_Cp>::capacity()) { - __bit_array<_Cp> __b(__d2); - std::copy(__middle, __last, __b.begin()); - std::copy_backward(__b.begin(), __b.end(), std::copy_backward(__first, __middle, __last)); - break; - } else { - __bit_iterator<_Cp, false> __mp = __first + __d2; - std::swap_ranges(__first, __mp, __middle); - __first = __mp; - __d1 -= __d2; - } - } - } - return __r; -} - -// equal - -template -_LIBCPP_HIDE_FROM_ABI bool __equal_unaligned( - __bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { - using _It = __bit_iterator<_Cp, _IC1>; - using difference_type = typename _It::difference_type; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - difference_type __n = __last1 - __first1; - if (__n > 0) { - // do first word - if (__first1.__ctz_ != 0) { - unsigned __clz_f = __bits_per_word - __first1.__ctz_; - difference_type __dn = std::min(static_cast(__clz_f), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - __storage_type __b = *__first1.__seg_ & __m; - unsigned __clz_r = __bits_per_word - __first2.__ctz_; - __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r); - __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); - if (__first2.__ctz_ > __first1.__ctz_) { - if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_))) - return false; - } else { - if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_))) - return false; - } - __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word; - __first2.__ctz_ = static_cast((__ddn + __first2.__ctz_) % __bits_per_word); - __dn -= __ddn; - if (__dn > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __dn); - if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn))) - return false; - __first2.__ctz_ = static_cast(__dn); - } - ++__first1.__seg_; - // __first1.__ctz_ = 0; - } - // __first1.__ctz_ == 0; - // do middle words - unsigned __clz_r = __bits_per_word - __first2.__ctz_; - __storage_type __m = ~__storage_type(0) << __first2.__ctz_; - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) { - __storage_type __b = *__first1.__seg_; - if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) - return false; - ++__first2.__seg_; - if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r)) - return false; - } - // do last word - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - __storage_type __b = *__first1.__seg_ & __m; - __storage_type __dn = std::min(__n, static_cast(__clz_r)); - __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); - if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) - return false; - __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word; - __first2.__ctz_ = static_cast((__dn + __first2.__ctz_) % __bits_per_word); - __n -= __dn; - if (__n > 0) { - __m = ~__storage_type(0) >> (__bits_per_word - __n); - if ((*__first2.__seg_ & __m) != (__b >> __dn)) - return false; - } - } - } - return true; -} - -template -_LIBCPP_HIDE_FROM_ABI bool __equal_aligned( - __bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { - using _It = __bit_iterator<_Cp, _IC1>; - using difference_type = typename _It::difference_type; - using __storage_type = typename _It::__storage_type; - - const int __bits_per_word = _It::__bits_per_word; - difference_type __n = __last1 - __first1; - if (__n > 0) { - // do first word - if (__first1.__ctz_ != 0) { - unsigned __clz = __bits_per_word - __first1.__ctz_; - difference_type __dn = std::min(static_cast(__clz), __n); - __n -= __dn; - __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); - if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) - return false; - ++__first2.__seg_; - ++__first1.__seg_; - // __first1.__ctz_ = 0; - // __first2.__ctz_ = 0; - } - // __first1.__ctz_ == 0; - // __first2.__ctz_ == 0; - // do middle words - for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_) - if (*__first2.__seg_ != *__first1.__seg_) - return false; - // do last word - if (__n > 0) { - __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) - return false; - } - } - return true; -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool -equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { - if (__first1.__ctz_ == __first2.__ctz_) - return std::__equal_aligned(__first1, __last1, __first2); - return std::__equal_unaligned(__first1, __last1, __first2); -} - -template -class __bit_iterator { -public: - using difference_type = typename _Cp::difference_type; - using value_type = bool; - using pointer = __bit_iterator; -#ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL - using reference = __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >; -#else - using reference = __conditional_t<_IsConst, bool, __bit_reference<_Cp> >; -#endif - using iterator_category = random_access_iterator_tag; - -private: - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = - __conditional_t<_IsConst, typename _Cp::__const_storage_pointer, typename _Cp::__storage_pointer>; - - static const unsigned __bits_per_word = _Cp::__bits_per_word; - - __storage_pointer __seg_; - unsigned __ctz_; - -public: - _LIBCPP_HIDE_FROM_ABI __bit_iterator() _NOEXCEPT {} - - // When _IsConst=false, this is the copy constructor. - // It is non-trivial. Making it trivial would break ABI. - // When _IsConst=true, this is a converting constructor; - // the copy and move constructors are implicitly generated - // and trivial. - _LIBCPP_HIDE_FROM_ABI __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT - : __seg_(__it.__seg_), - __ctz_(__it.__ctz_) {} - - // When _IsConst=false, we have a user-provided copy constructor, - // so we must also provide a copy assignment operator because - // the implicit generation of a defaulted one is deprecated. - // When _IsConst=true, the assignment operators are - // implicitly generated and trivial. - _LIBCPP_HIDE_FROM_ABI __bit_iterator& operator=(const _If<_IsConst, struct __private_nat, __bit_iterator>& __it) { - __seg_ = __it.__seg_; - __ctz_ = __it.__ctz_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI reference operator*() const _NOEXCEPT { - return __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >( - __seg_, __storage_type(1) << __ctz_); - } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator& operator++() { - if (__ctz_ != __bits_per_word - 1) - ++__ctz_; - else { - __ctz_ = 0; - ++__seg_; - } - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator operator++(int) { - __bit_iterator __tmp = *this; - ++(*this); - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator& operator--() { - if (__ctz_ != 0) - --__ctz_; - else { - __ctz_ = __bits_per_word - 1; - --__seg_; - } - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator operator--(int) { - __bit_iterator __tmp = *this; - --(*this); - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator& operator+=(difference_type __n) { - if (__n >= 0) - __seg_ += (__n + __ctz_) / __bits_per_word; - else - __seg_ += static_cast(__n - __bits_per_word + __ctz_ + 1) / - static_cast(__bits_per_word); - __n &= (__bits_per_word - 1); - __ctz_ = static_cast((__n + __ctz_) % __bits_per_word); - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator& operator-=(difference_type __n) { return *this += -__n; } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator operator+(difference_type __n) const { - __bit_iterator __t(*this); - __t += __n; - return __t; - } - - _LIBCPP_HIDE_FROM_ABI __bit_iterator operator-(difference_type __n) const { - __bit_iterator __t(*this); - __t -= __n; - return __t; - } - - _LIBCPP_HIDE_FROM_ABI friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) { - return __it + __n; - } - - _LIBCPP_HIDE_FROM_ABI friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y) { - return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_; - } - - _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const { return *(*this + __n); } - - _LIBCPP_HIDE_FROM_ABI friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) { - return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_; - } - - _LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) { - return !(__x == __y); - } - - _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) { - return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_); - } - - _LIBCPP_HIDE_FROM_ABI friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) { - return __y < __x; - } - - _LIBCPP_HIDE_FROM_ABI friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) { - return !(__y < __x); - } - - _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) { - return !(__x < __y); - } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT - : __seg_(__s), - __ctz_(__ctz) {} - - friend typename _Cp::__self; - - friend class __bit_reference<_Cp>; - friend class __bit_const_reference<_Cp>; - friend class __bit_iterator<_Cp, true>; - template - friend struct __bit_array; - - template - friend void __fill_n_bool(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); - - template - friend __bit_iterator<_Dp, false> __copy_aligned( - __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - friend __bit_iterator<_Dp, false> __copy_unaligned( - __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - friend __bit_iterator<_Dp, false> - copy(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - friend __bit_iterator<_Dp, false> __copy_backward_aligned( - __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - friend __bit_iterator<_Dp, false> __copy_backward_unaligned( - __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - friend __bit_iterator<_Dp, false> - copy_backward(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); - template - friend __bit_iterator<_Cr, false> - __swap_ranges_aligned(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>); - template - friend __bit_iterator<_Cr, false> - __swap_ranges_unaligned(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>); - template - friend __bit_iterator<_Cr, false> - swap_ranges(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>); - template - friend __bit_iterator<_Dp, false> - rotate(__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>); - template - friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); - template - friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); - template - friend bool equal(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); - template - friend __bit_iterator<_Dp, _IC> __find_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); - template - friend typename __bit_iterator<_Dp, _IC>::difference_type - _LIBCPP_HIDE_FROM_ABI __count_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); -}; - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___BIT_REFERENCE diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/convert_to_timespec.h b/third_party/libcxx/include/c++/v1/__cxx03/__chrono/convert_to_timespec.h deleted file mode 100644 index 24d77c2..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/convert_to_timespec.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CHRONO_CONVERT_TO_TIMESPEC_H -#define _LIBCPP___CXX03___CHRONO_CONVERT_TO_TIMESPEC_H - -#include <__cxx03/__chrono/duration.h> -#include <__cxx03/__config> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Convert a nanoseconds duration to the given TimeSpec type, which must have -// the same properties as std::timespec. -template -_LIBCPP_HIDE_FROM_ABI inline _TimeSpec __convert_to_timespec(const chrono::nanoseconds& __ns) { - using namespace chrono; - seconds __s = duration_cast(__ns); - _TimeSpec __ts; - typedef decltype(__ts.tv_sec) __ts_sec; - const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max(); - - if (__s.count() < __ts_sec_max) { - __ts.tv_sec = static_cast<__ts_sec>(__s.count()); - __ts.tv_nsec = static_cast((__ns - __s).count()); - } else { - __ts.tv_sec = __ts_sec_max; - __ts.tv_nsec = 999999999; // (10^9 - 1) - } - - return __ts; -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___CHRONO_CONVERT_TO_TIMESPEC_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/duration.h b/third_party/libcxx/include/c++/v1/__cxx03/__chrono/duration.h deleted file mode 100644 index 3a96df7..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/duration.h +++ /dev/null @@ -1,418 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CHRONO_DURATION_H -#define _LIBCPP___CXX03___CHRONO_DURATION_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/common_type.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/__type_traits/is_floating_point.h> -#include <__cxx03/limits> -#include <__cxx03/ratio> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -template > -class _LIBCPP_TEMPLATE_VIS duration; - -template -struct __is_duration : false_type {}; - -template -struct __is_duration > : true_type {}; - -template -struct __is_duration > : true_type {}; - -template -struct __is_duration > : true_type {}; - -template -struct __is_duration > : true_type {}; - -} // namespace chrono - -template -struct _LIBCPP_TEMPLATE_VIS common_type, chrono::duration<_Rep2, _Period2> > { - typedef chrono::duration::type, typename __ratio_gcd<_Period1, _Period2>::type> - type; -}; - -namespace chrono { - -// duration_cast - -template ::type, - bool = _Period::num == 1, - bool = _Period::den == 1> -struct __duration_cast; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> { - _LIBCPP_HIDE_FROM_ABI _ToDuration operator()(const _FromDuration& __fd) const { - return _ToDuration(static_cast(__fd.count())); - } -}; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> { - _LIBCPP_HIDE_FROM_ABI _ToDuration operator()(const _FromDuration& __fd) const { - typedef typename common_type::type _Ct; - return _ToDuration( - static_cast(static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); - } -}; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> { - _LIBCPP_HIDE_FROM_ABI _ToDuration operator()(const _FromDuration& __fd) const { - typedef typename common_type::type _Ct; - return _ToDuration( - static_cast(static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); - } -}; - -template -struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> { - _LIBCPP_HIDE_FROM_ABI _ToDuration operator()(const _FromDuration& __fd) const { - typedef typename common_type::type _Ct; - return _ToDuration(static_cast( - static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) / static_cast<_Ct>(_Period::den))); - } -}; - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _ToDuration duration_cast(const duration<_Rep, _Period>& __fd) { - return __duration_cast, _ToDuration>()(__fd); -} - -template -struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; - -// clang-format off -template -struct _LIBCPP_TEMPLATE_VIS duration_values { -public: - _LIBCPP_HIDE_FROM_ABI static _Rep zero() _NOEXCEPT { return _Rep(0); } - _LIBCPP_HIDE_FROM_ABI static _Rep max() _NOEXCEPT { return numeric_limits<_Rep>::max(); } - _LIBCPP_HIDE_FROM_ABI static _Rep min() _NOEXCEPT { return numeric_limits<_Rep>::lowest(); } -}; -// clang-format on - -// duration - -template -class _LIBCPP_TEMPLATE_VIS duration { - static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); - static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); - static_assert(_Period::num > 0, "duration period must be positive"); - - template - struct __no_overflow { - private: - static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; - static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; - static const intmax_t __n1 = _R1::num / __gcd_n1_n2; - static const intmax_t __d1 = _R1::den / __gcd_d1_d2; - static const intmax_t __n2 = _R2::num / __gcd_n1_n2; - static const intmax_t __d2 = _R2::den / __gcd_d1_d2; - static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); - - template - struct __mul // __overflow == false - { - static const intmax_t value = _Xp * _Yp; - }; - - template - struct __mul<_Xp, _Yp, true> { - static const intmax_t value = 1; - }; - - public: - static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); - typedef ratio<__mul<__n1, __d2, !value>::value, __mul<__n2, __d1, !value>::value> type; - }; - -public: - typedef _Rep rep; - typedef typename _Period::type period; - -private: - rep __rep_; - -public: - _LIBCPP_HIDE_FROM_ABI duration() {} - - template ::value && - (treat_as_floating_point::value || !treat_as_floating_point<_Rep2>::value), - int> = 0> - _LIBCPP_HIDE_FROM_ABI explicit duration(const _Rep2& __r) : __rep_(__r) {} - - // conversions - template ::value && (treat_as_floating_point::value || - (__no_overflow<_Period2, period>::type::den == 1 && - !treat_as_floating_point<_Rep2>::value)), - int> = 0> - _LIBCPP_HIDE_FROM_ABI duration(const duration<_Rep2, _Period2>& __d) - : __rep_(chrono::duration_cast(__d).count()) {} - - // observer - - _LIBCPP_HIDE_FROM_ABI rep count() const { return __rep_; } - - // arithmetic - - _LIBCPP_HIDE_FROM_ABI typename common_type::type operator+() const { - return typename common_type::type(*this); - } - _LIBCPP_HIDE_FROM_ABI typename common_type::type operator-() const { - return typename common_type::type(-__rep_); - } - _LIBCPP_HIDE_FROM_ABI duration& operator++() { - ++__rep_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI duration operator++(int) { return duration(__rep_++); } - _LIBCPP_HIDE_FROM_ABI duration& operator--() { - --__rep_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI duration operator--(int) { return duration(__rep_--); } - - _LIBCPP_HIDE_FROM_ABI duration& operator+=(const duration& __d) { - __rep_ += __d.count(); - return *this; - } - _LIBCPP_HIDE_FROM_ABI duration& operator-=(const duration& __d) { - __rep_ -= __d.count(); - return *this; - } - - _LIBCPP_HIDE_FROM_ABI duration& operator*=(const rep& __rhs) { - __rep_ *= __rhs; - return *this; - } - _LIBCPP_HIDE_FROM_ABI duration& operator/=(const rep& __rhs) { - __rep_ /= __rhs; - return *this; - } - _LIBCPP_HIDE_FROM_ABI duration& operator%=(const rep& __rhs) { - __rep_ %= __rhs; - return *this; - } - _LIBCPP_HIDE_FROM_ABI duration& operator%=(const duration& __rhs) { - __rep_ %= __rhs.count(); - return *this; - } - - // special values - - _LIBCPP_HIDE_FROM_ABI static duration zero() _NOEXCEPT { return duration(duration_values::zero()); } - _LIBCPP_HIDE_FROM_ABI static duration min() _NOEXCEPT { return duration(duration_values::min()); } - _LIBCPP_HIDE_FROM_ABI static duration max() _NOEXCEPT { return duration(duration_values::max()); } -}; - -typedef duration nanoseconds; -typedef duration microseconds; -typedef duration milliseconds; -typedef duration seconds; -typedef duration< long, ratio< 60> > minutes; -typedef duration< long, ratio<3600> > hours; - -// Duration == - -template -struct __duration_eq { - _LIBCPP_HIDE_FROM_ABI bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() == _Ct(__rhs).count(); - } -}; - -template -struct __duration_eq<_LhsDuration, _LhsDuration> { - _LIBCPP_HIDE_FROM_ABI bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const { - return __lhs.count() == __rhs.count(); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_eq, duration<_Rep2, _Period2> >()(__lhs, __rhs); -} - -// Duration != - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__lhs == __rhs); -} - -// Duration < - -template -struct __duration_lt { - _LIBCPP_HIDE_FROM_ABI bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() < _Ct(__rhs).count(); - } -}; - -template -struct __duration_lt<_LhsDuration, _LhsDuration> { - _LIBCPP_HIDE_FROM_ABI bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const { - return __lhs.count() < __rhs.count(); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_lt, duration<_Rep2, _Period2> >()(__lhs, __rhs); -} - -// Duration > - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __rhs < __lhs; -} - -// Duration <= - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__rhs < __lhs); -} - -// Duration >= - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__lhs < __rhs); -} - -// Duration + - -template -inline _LIBCPP_HIDE_FROM_ABI typename common_type, duration<_Rep2, _Period2> >::type -operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); -} - -// Duration - - -template -inline _LIBCPP_HIDE_FROM_ABI typename common_type, duration<_Rep2, _Period2> >::type -operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); -} - -// Duration * - -template ::type>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI duration::type, _Period> -operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); -} - -template ::type>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI duration::type, _Period> -operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) { - return __d * __s; -} - -// Duration / - -template ::value && - is_convertible::type>::value, - int> = 0> -inline _LIBCPP_HIDE_FROM_ABI duration::type, _Period> -operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI typename common_type<_Rep1, _Rep2>::type -operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Ct; - return _Ct(__lhs).count() / _Ct(__rhs).count(); -} - -// Duration % - -template ::value && - is_convertible::type>::value, - int> = 0> -inline _LIBCPP_HIDE_FROM_ABI duration::type, _Period> -operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); -} - -template -inline _LIBCPP_HIDE_FROM_ABI typename common_type, duration<_Rep2, _Period2> >::type -operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); -} - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) -# include <__cxx03/type_traits> -#endif - -#endif // _LIBCPP___CXX03___CHRONO_DURATION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/high_resolution_clock.h b/third_party/libcxx/include/c++/v1/__cxx03/__chrono/high_resolution_clock.h deleted file mode 100644 index 3371d16..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/high_resolution_clock.h +++ /dev/null @@ -1,35 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CHRONO_HIGH_RESOLUTION_CLOCK_H -#define _LIBCPP___CXX03___CHRONO_HIGH_RESOLUTION_CLOCK_H - -#include <__cxx03/__chrono/steady_clock.h> -#include <__cxx03/__chrono/system_clock.h> -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK -typedef steady_clock high_resolution_clock; -#else -typedef system_clock high_resolution_clock; -#endif - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___CHRONO_HIGH_RESOLUTION_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/steady_clock.h b/third_party/libcxx/include/c++/v1/__cxx03/__chrono/steady_clock.h deleted file mode 100644 index 5a8fa4f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/steady_clock.h +++ /dev/null @@ -1,42 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CHRONO_STEADY_CLOCK_H -#define _LIBCPP___CXX03___CHRONO_STEADY_CLOCK_H - -#include <__cxx03/__chrono/duration.h> -#include <__cxx03/__chrono/time_point.h> -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK -class _LIBCPP_EXPORTED_FROM_ABI steady_clock { -public: - typedef nanoseconds duration; - typedef duration::rep rep; - typedef duration::period period; - typedef chrono::time_point time_point; - static const bool is_steady = true; - - static time_point now() _NOEXCEPT; -}; -#endif - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___CHRONO_STEADY_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/system_clock.h b/third_party/libcxx/include/c++/v1/__cxx03/__chrono/system_clock.h deleted file mode 100644 index 09d2d69..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/system_clock.h +++ /dev/null @@ -1,43 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CHRONO_SYSTEM_CLOCK_H -#define _LIBCPP___CXX03___CHRONO_SYSTEM_CLOCK_H - -#include <__cxx03/__chrono/duration.h> -#include <__cxx03/__chrono/time_point.h> -#include <__cxx03/__config> -#include <__cxx03/ctime> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -class _LIBCPP_EXPORTED_FROM_ABI system_clock { -public: - typedef microseconds duration; - typedef duration::rep rep; - typedef duration::period period; - typedef chrono::time_point time_point; - static const bool is_steady = false; - - static time_point now() _NOEXCEPT; - static time_t to_time_t(const time_point& __t) _NOEXCEPT; - static time_point from_time_t(time_t __t) _NOEXCEPT; -}; - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___CHRONO_SYSTEM_CLOCK_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/time_point.h b/third_party/libcxx/include/c++/v1/__cxx03/__chrono/time_point.h deleted file mode 100644 index 7f2a73a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__chrono/time_point.h +++ /dev/null @@ -1,177 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CHRONO_TIME_POINT_H -#define _LIBCPP___CXX03___CHRONO_TIME_POINT_H - -#include <__cxx03/__chrono/duration.h> -#include <__cxx03/__config> -#include <__cxx03/__type_traits/common_type.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace chrono { - -template -class _LIBCPP_TEMPLATE_VIS time_point { - static_assert(__is_duration<_Duration>::value, - "Second template parameter of time_point must be a std::chrono::duration"); - -public: - typedef _Clock clock; - typedef _Duration duration; - typedef typename duration::rep rep; - typedef typename duration::period period; - -private: - duration __d_; - -public: - _LIBCPP_HIDE_FROM_ABI time_point() : __d_(duration::zero()) {} - _LIBCPP_HIDE_FROM_ABI explicit time_point(const duration& __d) : __d_(__d) {} - - // conversions - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI time_point(const time_point& __t) : __d_(__t.time_since_epoch()) {} - - // observer - - _LIBCPP_HIDE_FROM_ABI duration time_since_epoch() const { return __d_; } - - // arithmetic - - _LIBCPP_HIDE_FROM_ABI time_point& operator+=(const duration& __d) { - __d_ += __d; - return *this; - } - _LIBCPP_HIDE_FROM_ABI time_point& operator-=(const duration& __d) { - __d_ -= __d; - return *this; - } - - // special values - - _LIBCPP_HIDE_FROM_ABI static time_point min() _NOEXCEPT { return time_point(duration::min()); } - _LIBCPP_HIDE_FROM_ABI static time_point max() _NOEXCEPT { return time_point(duration::max()); } -}; - -} // namespace chrono - -template -struct _LIBCPP_TEMPLATE_VIS -common_type, chrono::time_point<_Clock, _Duration2> > { - typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; -}; - -namespace chrono { - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI time_point<_Clock, _ToDuration> time_point_cast(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); -} - -// time_point == - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() == __rhs.time_since_epoch(); -} - -// time_point != - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__lhs == __rhs); -} - -// time_point < - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() < __rhs.time_since_epoch(); -} - -// time_point > - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __rhs < __lhs; -} - -// time_point <= - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__rhs < __lhs); -} - -// time_point >= - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__lhs < __rhs); -} - -// time_point operator+(time_point x, duration y); - -template -inline _LIBCPP_HIDE_FROM_ABI time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> -operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; - return _Tr(__lhs.time_since_epoch() + __rhs); -} - -// time_point operator+(duration x, time_point y); - -template -inline _LIBCPP_HIDE_FROM_ABI time_point<_Clock, typename common_type, _Duration2>::type> -operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __rhs + __lhs; -} - -// time_point operator-(time_point x, duration y); - -template -inline _LIBCPP_HIDE_FROM_ABI time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> -operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; - return _Ret(__lhs.time_since_epoch() - __rhs); -} - -// duration operator-(time_point x, time_point y); - -template -inline _LIBCPP_HIDE_FROM_ABI typename common_type<_Duration1, _Duration2>::type -operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() - __rhs.time_since_epoch(); -} - -} // namespace chrono - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___CHRONO_TIME_POINT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__condition_variable/condition_variable.h b/third_party/libcxx/include/c++/v1/__cxx03/__condition_variable/condition_variable.h deleted file mode 100644 index af03250..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__condition_variable/condition_variable.h +++ /dev/null @@ -1,244 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONDITION_VARIABLE_CONDITION_VARIABLE_H -#define _LIBCPP___CXX03___CONDITION_VARIABLE_CONDITION_VARIABLE_H - -#include <__cxx03/__chrono/duration.h> -#include <__cxx03/__chrono/steady_clock.h> -#include <__cxx03/__chrono/system_clock.h> -#include <__cxx03/__chrono/time_point.h> -#include <__cxx03/__config> -#include <__cxx03/__mutex/mutex.h> -#include <__cxx03/__mutex/unique_lock.h> -#include <__cxx03/__system_error/system_error.h> -#include <__cxx03/__thread/support.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_floating_point.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/limits> -#include <__cxx03/ratio> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#ifndef _LIBCPP_HAS_NO_THREADS - -// enum class cv_status -_LIBCPP_DECLARE_STRONG_ENUM(cv_status){no_timeout, timeout}; -_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status) - -class _LIBCPP_EXPORTED_FROM_ABI condition_variable { - __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; - -public: - _LIBCPP_HIDE_FROM_ABI condition_variable() _NOEXCEPT = default; - -# ifdef _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION - ~condition_variable() = default; -# else - ~condition_variable(); -# endif - - condition_variable(const condition_variable&) = delete; - condition_variable& operator=(const condition_variable&) = delete; - - void notify_one() _NOEXCEPT; - void notify_all() _NOEXCEPT; - - void wait(unique_lock& __lk) _NOEXCEPT; - template - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS void wait(unique_lock& __lk, _Predicate __pred); - - template - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status - wait_until(unique_lock& __lk, const chrono::time_point<_Clock, _Duration>& __t); - - template - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool - wait_until(unique_lock& __lk, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred); - - template - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status - wait_for(unique_lock& __lk, const chrono::duration<_Rep, _Period>& __d); - - template - bool _LIBCPP_HIDE_FROM_ABI - wait_for(unique_lock& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred); - - typedef __libcpp_condvar_t* native_handle_type; - _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__cv_; } - -private: - void - __do_timed_wait(unique_lock& __lk, chrono::time_point) _NOEXCEPT; -# if defined(_LIBCPP_HAS_COND_CLOCKWAIT) - _LIBCPP_HIDE_FROM_ABI void - __do_timed_wait(unique_lock& __lk, chrono::time_point) _NOEXCEPT; -# endif - template - _LIBCPP_HIDE_FROM_ABI void - __do_timed_wait(unique_lock& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT; -}; -#endif // !_LIBCPP_HAS_NO_THREADS - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d) { - using namespace chrono; - using __ratio = ratio_divide<_Period, nano>; - using __ns_rep = nanoseconds::rep; - _Rep __result_float = __d.count() * __ratio::num / __ratio::den; - - _Rep __result_max = numeric_limits<__ns_rep>::max(); - if (__result_float >= __result_max) { - return nanoseconds::max(); - } - - _Rep __result_min = numeric_limits<__ns_rep>::min(); - if (__result_float <= __result_min) { - return nanoseconds::min(); - } - - return nanoseconds(static_cast<__ns_rep>(__result_float)); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d) { - using namespace chrono; - if (__d.count() == 0) { - return nanoseconds(0); - } - - using __ratio = ratio_divide<_Period, nano>; - using __ns_rep = nanoseconds::rep; - __ns_rep __result_max = numeric_limits<__ns_rep>::max(); - if (__d.count() > 0 && __d.count() > __result_max / __ratio::num) { - return nanoseconds::max(); - } - - __ns_rep __result_min = numeric_limits<__ns_rep>::min(); - if (__d.count() < 0 && __d.count() < __result_min / __ratio::num) { - return nanoseconds::min(); - } - - __ns_rep __result = __d.count() * __ratio::num / __ratio::den; - if (__result == 0) { - return nanoseconds(1); - } - - return nanoseconds(__result); -} - -#ifndef _LIBCPP_HAS_NO_THREADS -template -void condition_variable::wait(unique_lock& __lk, _Predicate __pred) { - while (!__pred()) - wait(__lk); -} - -template -cv_status condition_variable::wait_until(unique_lock& __lk, const chrono::time_point<_Clock, _Duration>& __t) { - using namespace chrono; - using __clock_tp_ns = time_point<_Clock, nanoseconds>; - - typename _Clock::time_point __now = _Clock::now(); - if (__t <= __now) - return cv_status::timeout; - - __clock_tp_ns __t_ns = __clock_tp_ns(std::__safe_nanosecond_cast(__t.time_since_epoch())); - - __do_timed_wait(__lk, __t_ns); - return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout; -} - -template -bool condition_variable::wait_until( - unique_lock& __lk, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred) { - while (!__pred()) { - if (wait_until(__lk, __t) == cv_status::timeout) - return __pred(); - } - return true; -} - -template -cv_status condition_variable::wait_for(unique_lock& __lk, const chrono::duration<_Rep, _Period>& __d) { - using namespace chrono; - if (__d <= __d.zero()) - return cv_status::timeout; - using __ns_rep = nanoseconds::rep; - steady_clock::time_point __c_now = steady_clock::now(); - -# if defined(_LIBCPP_HAS_COND_CLOCKWAIT) - using __clock_tp_ns = time_point; - __ns_rep __now_count_ns = std::__safe_nanosecond_cast(__c_now.time_since_epoch()).count(); -# else - using __clock_tp_ns = time_point; - __ns_rep __now_count_ns = std::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count(); -# endif - - __ns_rep __d_ns_count = std::__safe_nanosecond_cast(__d).count(); - - if (__now_count_ns > numeric_limits<__ns_rep>::max() - __d_ns_count) { - __do_timed_wait(__lk, __clock_tp_ns::max()); - } else { - __do_timed_wait(__lk, __clock_tp_ns(nanoseconds(__now_count_ns + __d_ns_count))); - } - - return steady_clock::now() - __c_now < __d ? cv_status::no_timeout : cv_status::timeout; -} - -template -inline bool -condition_variable::wait_for(unique_lock& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred) { - return wait_until(__lk, chrono::steady_clock::now() + __d, std::move(__pred)); -} - -# if defined(_LIBCPP_HAS_COND_CLOCKWAIT) -inline void condition_variable::__do_timed_wait( - unique_lock& __lk, chrono::time_point __tp) _NOEXCEPT { - using namespace chrono; - if (!__lk.owns_lock()) - __throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked"); - nanoseconds __d = __tp.time_since_epoch(); - timespec __ts; - seconds __s = duration_cast(__d); - using __ts_sec = decltype(__ts.tv_sec); - const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max(); - if (__s.count() < __ts_sec_max) { - __ts.tv_sec = static_cast<__ts_sec>(__s.count()); - __ts.tv_nsec = (__d - __s).count(); - } else { - __ts.tv_sec = __ts_sec_max; - __ts.tv_nsec = giga::num - 1; - } - int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts); - if (__ec != 0 && __ec != ETIMEDOUT) - __throw_system_error(__ec, "condition_variable timed_wait failed"); -} -# endif // _LIBCPP_HAS_COND_CLOCKWAIT - -template -inline void condition_variable::__do_timed_wait(unique_lock& __lk, - chrono::time_point<_Clock, chrono::nanoseconds> __tp) _NOEXCEPT { - wait_for(__lk, __tp - _Clock::now()); -} - -#endif // _LIBCPP_HAS_NO_THREADS - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___CONDITION_VARIABLE_CONDITION_VARIABLE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__config b/third_party/libcxx/include/c++/v1/__cxx03/__config deleted file mode 100644 index d955429..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__config +++ /dev/null @@ -1,1077 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONFIG -#define _LIBCPP___CXX03___CONFIG - -#include <__cxx03/__configuration/abi.h> -#include <__cxx03/__configuration/availability.h> -#include <__cxx03/__configuration/compiler.h> -#include <__cxx03/__configuration/config_site_shim.h> -#include <__cxx03/__configuration/platform.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#ifdef __cplusplus - -// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html - -// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. -// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is -// defined to XXYYZZ. -# define _LIBCPP_VERSION 190100 - -# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y -# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) - -// HARDENING { - -// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) -// equivalent to setting the extensive mode. This is deprecated and will be removed in LLVM 20. -# ifdef _LIBCPP_ENABLE_ASSERTIONS -# warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_HARDENING_MODE instead" -# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 -# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" -# endif -# if _LIBCPP_ENABLE_ASSERTIONS -# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE -# endif -# endif - -// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: -// -// - `_LIBCPP_HARDENING_MODE_NONE`; -// - `_LIBCPP_HARDENING_MODE_FAST`; -// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; -// - `_LIBCPP_HARDENING_MODE_DEBUG`. -// -// These values have the following effects: -// -// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; -// -// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks -// that can be done with relatively little runtime overhead in constant time; -// -// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of -// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors -// but are not necessarily security-critical; -// -// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive -// mode and enables all checks available in the library, including internal assertions. Checks that are part of the -// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. - -// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These -// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. -// -// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and -// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: -// - the sentinel is reachable from the begin iterator; -// - TODO(hardening): both iterators refer to the same container. -// -// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through -// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access -// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like -// `optional` and `function` are considered one-element containers for the purposes of this check. -// -// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero -// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the -// memory security of a program (however, it is still undefined behavior that can result in strange errors due to -// compiler optimizations). -// -// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the -// given ranges do not overlap. -// -// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object -// was allocated by the given allocator). Violating this category typically results in a memory leak. -// -// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in -// an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like -// attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category -// (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or -// otherwise create an immediate security issue. -// -// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure -// the containers have compatible allocators. -// -// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments -// for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the -// original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g. -// a string view where only a subset of elements is possible to access). This category is for assertions violating -// which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the -// user code. -// -// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to -// be benign in our implementation. -// -// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed -// by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied; -// thus, this would often be a heuristic check and it might be quite expensive. -// -// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on -// user input. -// -// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. - -// clang-format off -# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) -# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) -# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. -# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) -// clang-format on - -# ifndef _LIBCPP_HARDENING_MODE - -# ifndef _LIBCPP_HARDENING_MODE_DEFAULT -# error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \ -`__config_site` header, please make sure your installation of libc++ is not broken. -# endif - -# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT -# endif - -# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ - _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ - _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ - _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG -# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ -_LIBCPP_HARDENING_MODE_NONE, \ -_LIBCPP_HARDENING_MODE_FAST, \ -_LIBCPP_HARDENING_MODE_EXTENSIVE, \ -_LIBCPP_HARDENING_MODE_DEBUG -# endif - -# ifdef _LIBCPP_ASSERTION_SEMANTIC -# error "Assertion semantics are not available in the C++03 mode." -# endif - -// } HARDENING - -# define _LIBCPP_TOSTRING2(x) #x -# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) - -# ifndef __has_constexpr_builtin -# define __has_constexpr_builtin(x) 0 -# endif - -// This checks wheter a Clang module is built -# ifndef __building_module -# define __building_module(...) 0 -# endif - -// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by -// the compiler and '1' otherwise. -# ifndef __is_identifier -# define __is_identifier(__x) 1 -# endif - -# ifndef __has_declspec_attribute -# define __has_declspec_attribute(__x) 0 -# endif - -# define __has_keyword(__x) !(__is_identifier(__x)) - -# ifndef __has_warning -# define __has_warning(...) 0 -# endif - -# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L -# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" -# endif - -// FIXME: ABI detection should be done via compiler builtin macros. This -// is just a placeholder until Clang implements such macros. For now assume -// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, -// and allow the user to explicitly specify the ABI to handle cases where this -// heuristic falls short. -# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) -# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" -# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) -# define _LIBCPP_ABI_ITANIUM -# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) -# define _LIBCPP_ABI_MICROSOFT -# else -# if defined(_WIN32) && defined(_MSC_VER) -# define _LIBCPP_ABI_MICROSOFT -# else -# define _LIBCPP_ABI_ITANIUM -# endif -# endif - -# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) -# define _LIBCPP_ABI_VCRUNTIME -# endif - -# if __has_feature(experimental_library) -# ifndef _LIBCPP_ENABLE_EXPERIMENTAL -# define _LIBCPP_ENABLE_EXPERIMENTAL -# endif -# endif - -# if defined(__MVS__) -# include // for __NATIVE_ASCII_F -# endif - -# if defined(_WIN32) -# define _LIBCPP_WIN32API -# define _LIBCPP_SHORT_WCHAR 1 -// Both MinGW and native MSVC provide a "MSVC"-like environment -# define _LIBCPP_MSVCRT_LIKE -// If mingw not explicitly detected, assume using MS C runtime only if -// a MS compatibility version is specified. -# if defined(_MSC_VER) && !defined(__MINGW32__) -# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library -# endif -# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) -# define _LIBCPP_HAS_BITSCAN64 -# endif -# define _LIBCPP_HAS_OPEN_WITH_WCHAR -# endif // defined(_WIN32) - -# if defined(_AIX) && !defined(__64BIT__) -// The size of wchar is 2 byte on 32-bit mode on AIX. -# define _LIBCPP_SHORT_WCHAR 1 -# endif - -// Libc++ supports various implementations of std::random_device. -// -// _LIBCPP_USING_DEV_RANDOM -// Read entropy from the given file, by default `/dev/urandom`. -// If a token is provided, it is assumed to be the path to a file -// to read entropy from. This is the default behavior if nothing -// else is specified. This implementation requires storing state -// inside `std::random_device`. -// -// _LIBCPP_USING_ARC4_RANDOM -// Use arc4random(). This allows obtaining random data even when -// using sandboxing mechanisms. On some platforms like Apple, this -// is the recommended source of entropy for user-space programs. -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -// -// _LIBCPP_USING_GETENTROPY -// Use getentropy(). -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -// -// _LIBCPP_USING_FUCHSIA_CPRNG -// Use Fuchsia's zx_cprng_draw() system call, which is specified to -// deliver high-quality entropy and cannot fail. -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -// -// _LIBCPP_USING_NACL_RANDOM -// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, -// including accesses to the special files under `/dev`. This implementation -// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -// -// _LIBCPP_USING_WIN32_RANDOM -// Use rand_s(), for use on Windows. -// When this option is used, the token passed to `std::random_device`'s -// constructor *must* be "/dev/urandom" -- anything else is an error. -# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ - defined(__DragonFly__) -# define _LIBCPP_USING_ARC4_RANDOM -# elif defined(__wasi__) || defined(__EMSCRIPTEN__) -# define _LIBCPP_USING_GETENTROPY -# elif defined(__Fuchsia__) -# define _LIBCPP_USING_FUCHSIA_CPRNG -# elif defined(__native_client__) -# define _LIBCPP_USING_NACL_RANDOM -# elif defined(_LIBCPP_WIN32API) -# define _LIBCPP_USING_WIN32_RANDOM -# else -# define _LIBCPP_USING_DEV_RANDOM -# endif - -# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) -# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) -# define _ALIGNAS(x) __attribute__((__aligned__(x))) -# define _LIBCPP_NORETURN __attribute__((__noreturn__)) -# define nullptr __nullptr -# define _NOEXCEPT throw() -# define static_assert(...) _Static_assert(__VA_ARGS__) -# define decltype(...) __decltype(__VA_ARGS__) - -typedef __char16_t char16_t; -typedef __char32_t char32_t; - -# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) - -// Objective-C++ features (opt-in) -# if __has_feature(objc_arc) -# define _LIBCPP_HAS_OBJC_ARC -# endif - -# if __has_feature(objc_arc_weak) -# define _LIBCPP_HAS_OBJC_ARC_WEAK -# endif - -# if __has_extension(blocks) -# define _LIBCPP_HAS_EXTENSION_BLOCKS -# endif - -# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) -# define _LIBCPP_HAS_BLOCKS_RUNTIME -# endif - -# if !__has_feature(address_sanitizer) -# define _LIBCPP_HAS_NO_ASAN -# endif - -# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) - -# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ - -# if defined(_LIBCPP_OBJECT_FORMAT_COFF) - -# ifdef _DLL -# define _LIBCPP_CRT_FUNC __declspec(dllimport) -# else -# define _LIBCPP_CRT_FUNC -# endif - -# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) -# define _LIBCPP_DLL_VIS -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_EXPORTED_FROM_ABI -# elif defined(_LIBCPP_BUILDING_LIBRARY) -# define _LIBCPP_DLL_VIS __declspec(dllexport) -# if defined(__MINGW32__) -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# else -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS -# endif -# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS -# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) -# else -# define _LIBCPP_DLL_VIS __declspec(dllimport) -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) -# endif - -# define _LIBCPP_HIDDEN -# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS -# define _LIBCPP_TEMPLATE_VIS -# define _LIBCPP_TEMPLATE_DATA_VIS -# define _LIBCPP_TYPE_VISIBILITY_DEFAULT - -# else - -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) -# else -# define _LIBCPP_VISIBILITY(vis) -# endif - -# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") -# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") -# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS - -// TODO: Make this a proper customization point or remove the option to override it. -# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS -# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") -# endif - -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -// The inline should be removed once PR32114 is resolved -# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN -# else -# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS -# endif - -// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) -# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) -# else -# define _LIBCPP_TEMPLATE_VIS -# endif - -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) -# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) -# else -# define _LIBCPP_TYPE_VISIBILITY_DEFAULT -# endif - -# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) - -# if __has_attribute(exclude_from_explicit_instantiation) -# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) -# else -// Try to approximate the effect of exclude_from_explicit_instantiation -// (which is that entities are not assumed to be provided by explicit -// template instantiations in the dylib) by always inlining those entities. -# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE -# endif - -# ifdef _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") -# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) -# elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") -# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) -# else -# define _LIBCPP_DIAGNOSTIC_PUSH -# define _LIBCPP_DIAGNOSTIC_POP -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) -# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) -# endif - -# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST -# define _LIBCPP_HARDENING_SIG f -# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE -# define _LIBCPP_HARDENING_SIG s -# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -# define _LIBCPP_HARDENING_SIG d -# else -# define _LIBCPP_HARDENING_SIG n // "none" -# endif - -# ifdef _LIBCPP_HAS_NO_EXCEPTIONS -# define _LIBCPP_EXCEPTIONS_SIG n -# else -# define _LIBCPP_EXCEPTIONS_SIG e -# endif - -# define _LIBCPP_ODR_SIGNATURE \ - _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) - -// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved -// on two levels: -// 1. The symbol is given hidden visibility, which ensures that users won't start exporting -// symbols from their dynamic library by means of using the libc++ headers. This ensures -// that those symbols stay private to the dynamic library in which it is defined. -// -// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. -// This ensures that no ODR violation can arise from mixing two TUs compiled with different -// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the -// program contains two definitions of a function, the ODR requires them to be token-by-token -// equivalent, and the linker is allowed to pick either definition and discard the other one. -// -// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled -// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs -// compiled with different settings), the two definitions are both visible by the linker and they -// have the same name, but they have a meaningfully different implementation (one throws an exception -// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in -// practice what will happen is that the linker will pick one of the definitions at random and will -// discard the other one. This can quite clearly lead to incorrect program behavior. -// -// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any -// property that causes the code of a function to differ from the code in another configuration -// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI -// tag, but we encode the ones that we think are most important: library version, exceptions, and -// hardening mode. -// -// Note that historically, solving this problem has been achieved in various ways, including -// force-inlining all functions or giving internal linkage to all functions. Both these previous -// solutions suffer from drawbacks that lead notably to code bloat. -// -// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend -// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. -// -// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions -// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled -// name of a virtual function is part of its ABI, since some architectures like arm64e can sign -// the virtual function pointer in the vtable based on the mangled name of the function. Since -// we use an ABI tag that changes with each released version, the mangled name of the virtual -// function would change, which is incorrect. Note that it doesn't make much sense to change -// the implementation of a virtual function in an ABI-incompatible way in the first place, -// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. -// -// The macro can be applied to record and enum types. When the tagged type is nested in -// a record this "parent" record needs to have the macro too. Another use case for applying -// this macro to records and unions is to apply an ABI tag to inline constexpr variables. -// This can be useful for inline variables that are implementation details which are expected -// to change in the future. -// -// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing -// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and -// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. -# ifndef _LIBCPP_NO_ABI_TAG -# define _LIBCPP_HIDE_FROM_ABI \ - _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ - __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) -# else -# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION -# endif -# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION - -# ifdef _LIBCPP_BUILDING_LIBRARY -# if _LIBCPP_ABI_VERSION > 1 -# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI -# else -# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 -# endif -# else -# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI -# endif - -// TODO: Remove this workaround once we drop support for Clang 16 -# if __has_warning("-Wc++23-extensions") -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") -# else -# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions") -# endif - -// Clang modules take a significant compile time hit when pushing and popping diagnostics. -// Since all the headers are marked as system headers in the modulemap, we can simply disable this -// pushing and popping when building with clang modules. -# if !__has_feature(modules) -# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ - _LIBCPP_DIAGNOSTIC_PUSH \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ - _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") -# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP -# else -# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS -# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS -# endif - -// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. -// clang-format off -# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ - namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ - inline namespace _LIBCPP_ABI_NAMESPACE { -# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS - -#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE -# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { -# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD -#else -# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ - inline namespace __fs { namespace filesystem { - -# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD -#endif - -// clang-format on - -# if __has_attribute(__enable_if__) -# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) -# endif - -# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) -# define _LIBCPP_HAS_NO_INT128 -# endif - -# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ - struct _LIBCPP_EXPORTED_FROM_ABI x { \ - enum __lx -// clang-format off -# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ - __lx __v_; \ - _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ - _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ - _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ - }; -// clang-format on - -# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) -# define _LIBCPP_LOCALE__L_EXTENSIONS 1 -# endif - -# ifdef __FreeBSD__ -# define _DECLARE_C99_LDBL_MATH 1 -# endif - -// If we are getting operator new from the MSVC CRT, then allocation overloads -// for align_val_t were added in 19.12, aka VS 2017 version 15.3. -# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 -# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION -# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) -// We're deferring to Microsoft's STL to provide aligned new et al. We don't -// have it unless the language feature test macro is defined. -# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION -# elif defined(__MVS__) -# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION -# endif - -# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) -# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION -# endif - -# if defined(__APPLE__) || defined(__FreeBSD__) -# define _LIBCPP_HAS_DEFAULTRUNELOCALE -# endif - -# if defined(__APPLE__) || defined(__FreeBSD__) -# define _LIBCPP_WCTYPE_IS_MASK -# endif - -# define _LIBCPP_HAS_NO_CHAR8_T - -// Deprecation macros. -// -// Deprecations warnings are always enabled, except when users explicitly opt-out -// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. -# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) -# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) -# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) -# else -# define _LIBCPP_DEPRECATED -# define _LIBCPP_DEPRECATED_(m) -# endif - -# define _LIBCPP_DEPRECATED_ATOMIC_SYNC /* nothing */ - -# if !defined(_LIBCPP_HAS_NO_CHAR8_T) -# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED -# else -# define _LIBCPP_DEPRECATED_WITH_CHAR8_T -# endif - -// Macros to enter and leave a state where deprecation warnings are suppressed. -# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ - _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ - _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") -# else -# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH -# define _LIBCPP_SUPPRESS_DEPRECATED_POP -# endif - -# ifndef _LIBCPP_WEAK -# define _LIBCPP_WEAK __attribute__((__weak__)) -# endif - -// Thread API -// clang-format off -# if !defined(_LIBCPP_HAS_NO_THREADS) && \ - !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ - !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ - !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) - -# if defined(__FreeBSD__) || \ - defined(__wasi__) || \ - defined(__NetBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NuttX__) || \ - defined(__linux__) || \ - defined(__GNU__) || \ - defined(__APPLE__) || \ - defined(__MVS__) || \ - defined(_AIX) || \ - defined(__EMSCRIPTEN__) -// clang-format on -# define _LIBCPP_HAS_THREAD_API_PTHREAD -# elif defined(__Fuchsia__) -// TODO(44575): Switch to C11 thread API when possible. -# define _LIBCPP_HAS_THREAD_API_PTHREAD -# elif defined(_LIBCPP_WIN32API) -# define _LIBCPP_HAS_THREAD_API_WIN32 -# else -# error "No thread API" -# endif // _LIBCPP_HAS_THREAD_API -# endif // _LIBCPP_HAS_NO_THREADS - -# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) -# if defined(__ANDROID__) && __ANDROID_API__ >= 30 -# define _LIBCPP_HAS_COND_CLOCKWAIT -# elif defined(_LIBCPP_GLIBC_PREREQ) -# if _LIBCPP_GLIBC_PREREQ(2, 30) -# define _LIBCPP_HAS_COND_CLOCKWAIT -# endif -# endif -# endif - -# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) -# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ - _LIBCPP_HAS_NO_THREADS is not defined. -# endif - -# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) -# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ - _LIBCPP_HAS_NO_THREADS is defined. -# endif - -# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) -# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ - _LIBCPP_HAS_NO_THREADS is defined. -# endif - -# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) -# define __STDCPP_THREADS__ 1 -# endif - -// The glibc and Bionic implementation of pthreads implements -// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 -// mutexes have no destroy mechanism. -// -// This optimization can't be performed on Apple platforms, where -// pthread_mutex_destroy can allow the kernel to release resources. -// See https://llvm.org/D64298 for details. -// -// TODO(EricWF): Enable this optimization on Bionic after speaking to their -// respective stakeholders. -// clang-format off -# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ - (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ - defined(_LIBCPP_HAS_THREAD_API_WIN32) -// clang-format on -# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION -# endif - -// Destroying a condvar is a nop on Windows. -// -// This optimization can't be performed on Apple platforms, where -// pthread_cond_destroy can allow the kernel to release resources. -// See https://llvm.org/D64298 for details. -// -// TODO(EricWF): This is potentially true for some pthread implementations -// as well. -# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) -# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION -# endif - -# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ - defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) -# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE -# endif - -# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) -# define _LIBCPP_HAS_C_ATOMIC_IMP -# elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_HAS_GCC_ATOMIC_IMP -# endif - -# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ - !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) -# define _LIBCPP_HAS_NO_ATOMIC_HEADER -# else -# ifndef _LIBCPP_ATOMIC_FLAG_TYPE -# define _LIBCPP_ATOMIC_FLAG_TYPE bool -# endif -# endif - -# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) -# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) -# else -# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS -# endif - -# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) -# if defined(__clang__) && __has_attribute(acquire_capability) -// Work around the attribute handling in clang. When both __declspec and -// __attribute__ are present, the processing goes awry preventing the definition -// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus -// combining the two does work. -# if !defined(_MSC_VER) -# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS -# endif -# endif -# endif - -# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS -# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) -# else -# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) -# endif - -# if __has_attribute(__require_constant_initialization__) -# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) -# else -# define _LIBCPP_CONSTINIT -# endif - -# if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) -// The CUDA SDK contains an unfortunate definition for the __noinline__ macro, -// which breaks the regular __attribute__((__noinline__)) syntax. Therefore, -// when compiling for CUDA we use the non-underscored version of the noinline -// attribute. -// -// This is a temporary workaround and we still expect the CUDA SDK team to solve -// this issue properly in the SDK headers. -// -// See https://github.com/llvm/llvm-project/pull/73838 for more details. -# define _LIBCPP_NOINLINE __attribute__((noinline)) -# elif __has_attribute(__noinline__) -# define _LIBCPP_NOINLINE __attribute__((__noinline__)) -# else -# define _LIBCPP_NOINLINE -# endif - -// We often repeat things just for handling wide characters in the library. -// When wide characters are disabled, it can be useful to have a quick way of -// disabling it without having to resort to #if-#endif, which has a larger -// impact on readability. -# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) -# define _LIBCPP_IF_WIDE_CHARACTERS(...) -# else -# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ -# endif - -// clang-format off -# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")") -# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")") -// clang-format on - -# ifndef _LIBCPP_NO_AUTO_LINK -# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# pragma comment(lib, "c++.lib") -# else -# pragma comment(lib, "libc++.lib") -# endif -# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) -# endif // _LIBCPP_NO_AUTO_LINK - -// Configures the fopen close-on-exec mode character, if any. This string will -// be appended to any mode string used by fstream for fopen/fdopen. -// -// Not all platforms support this, but it helps avoid fd-leaks on platforms that -// do. -# if defined(__BIONIC__) -# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" -# else -# define _LIBCPP_FOPEN_CLOEXEC_MODE -# endif - -# if __has_cpp_attribute(msvc::no_unique_address) -// MSVC implements [[no_unique_address]] as a silent no-op currently. -// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) -// However, MSVC implements [[msvc::no_unique_address]] which does what -// [[no_unique_address]] is supposed to do, in general. - -// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or -// [[msvc::no_unique_address]] though. If/when it does implement -// [[msvc::no_unique_address]], this should be preferred though. -# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -# elif __has_cpp_attribute(no_unique_address) -# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] -# else -# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ -// Note that this can be replaced by #error as soon as clang-cl -// implements msvc::no_unique_address, since there should be no C++20 -// compiler that doesn't support one of the two attributes at that point. -// We generally don't want to use this macro outside of C++20-only code, -// because using it conditionally in one language version only would make -// the ABI inconsistent. -# endif - -// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these -// functions is gradually being added to existing C libraries. The conditions -// below check for known C library versions and conditions under which these -// functions are declared by the C library. -# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 -// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if -// __cpp_char8_t is defined or if C2X extensions are enabled. Determining -// the latter depends on internal GNU libc details that are not appropriate -// to depend on here, so any declarations present when __cpp_char8_t is not -// defined are ignored. -# if defined(_LIBCPP_GLIBC_PREREQ) -# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) -# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 -# endif -# endif - -// There are a handful of public standard library types that are intended to -// support CTAD but don't need any explicit deduction guides to do so. This -// macro is used to mark them as such, which suppresses the -// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code -// with these classes. -# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") - -// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use -// compiler intrinsics in the Objective-C++ mode. -# ifdef __OBJC__ -# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS -# endif - -# define _PSTL_PRAGMA(x) _Pragma(#x) - -// Enable SIMD for compilers that support OpenMP 4.0 -# if (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_UDR_PRESENT -# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) -# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) - -// Declaration of reduction functor, where -// NAME - the name of the functor -// OP - type of the callable object with the reduction operation -// omp_in - refers to the local partial result -// omp_out - refers to the final value of the combiner operator -// omp_priv - refers to the private copy of the initial value -// omp_orig - refers to the original variable to be reduced -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ - _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) - -# elif defined(_LIBCPP_COMPILER_CLANG_BASED) - -# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_DECLARE_SIMD -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) - -# else // (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_PRAGMA_SIMD -# define _PSTL_PRAGMA_DECLARE_SIMD -# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) -# define _PSTL_PRAGMA_SIMD_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) -# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) - -# endif // (defined(_OPENMP) && _OPENMP >= 201307) - -# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED - -// Optional attributes - these are useful for a better QoI, but not required to be available - -# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) -# else -# define _LIBCPP_NO_CFI -# endif - -# if __has_attribute(__malloc__) -# define _LIBCPP_NOALIAS __attribute__((__malloc__)) -# else -# define _LIBCPP_NOALIAS -# endif - -# if __has_attribute(__using_if_exists__) -# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) -# else -# define _LIBCPP_USING_IF_EXISTS -# endif - -# if __has_cpp_attribute(__nodiscard__) -# define _LIBCPP_NODISCARD [[__nodiscard__]] -# else -// We can't use GCC's [[gnu::warn_unused_result]] and -// __attribute__((warn_unused_result)), because GCC does not silence them via -// (void) cast. -# define _LIBCPP_NODISCARD -# endif - -# if __has_attribute(__no_destroy__) -# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) -# else -# define _LIBCPP_NO_DESTROY -# endif - -# if __has_attribute(__diagnose_if__) -# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) -# else -# define _LIBCPP_DIAGNOSE_WARNING(...) -# endif - -// Use a function like macro to imply that it must be followed by a semicolon -# if __has_cpp_attribute(fallthrough) -# define _LIBCPP_FALLTHROUGH() [[fallthrough]] -# elif __has_attribute(__fallthrough__) -# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) -# else -# define _LIBCPP_FALLTHROUGH() ((void)0) -# endif - -# if __has_cpp_attribute(_Clang::__lifetimebound__) -# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] -# else -# define _LIBCPP_LIFETIMEBOUND -# endif - -# if __has_attribute(__nodebug__) -# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) -# else -# define _LIBCPP_NODEBUG -# endif - -# if __has_attribute(__standalone_debug__) -# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) -# else -# define _LIBCPP_STANDALONE_DEBUG -# endif - -# if __has_attribute(__preferred_name__) -# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) -# else -# define _LIBCPP_PREFERRED_NAME(x) -# endif - -# if __has_attribute(__no_sanitize__) -# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) -# else -# define _LIBCPP_NO_SANITIZE(...) -# endif - -# if __has_attribute(__init_priority__) -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) -# else -# define _LIBCPP_INIT_PRIORITY_MAX -# endif - -# if __has_attribute(__format__) -// The attribute uses 1-based indices for ordinary and static member functions. -// The attribute uses 2-based indices for non-static member functions. -# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ - __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) -# else -# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ -# endif - -# if __has_attribute(__packed__) -# define _LIBCPP_PACKED __attribute__((__packed__)) -# else -# define _LIBCPP_PACKED -# endif - -# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) -# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) -# else -# define _LIBCPP_DECLSPEC_EMPTY_BASES -# endif - -// Allow for build-time disabling of unsigned integer sanitization -# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) -# else -# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK -# endif - -// Clang-18 has support for deducing this, but it does not set the FTM. -# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800) -# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER -# endif - -#endif // __cplusplus - -#endif // _LIBCPP___CXX03___CONFIG diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/abi.h b/third_party/libcxx/include/c++/v1/__cxx03/__configuration/abi.h deleted file mode 100644 index 81dd5b1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/abi.h +++ /dev/null @@ -1,172 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONFIGURATION_ABI_H -#define _LIBCPP___CXX03___CONFIGURATION_ABI_H - -#include <__cxx03/__configuration/compiler.h> -#include <__cxx03/__configuration/config_site_shim.h> -#include <__cxx03/__configuration/platform.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#if _LIBCPP_ABI_VERSION >= 2 -// Change short string representation so that string data starts at offset 0, -// improving its alignment in some cases. -# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT -// Fix deque iterator type in order to support incomplete types. -# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE -// Fix undefined behavior in how std::list stores its linked nodes. -# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB -// Fix undefined behavior in how __tree stores its end and parent nodes. -# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB -// Fix undefined behavior in how __hash_table stores its pointer types. -# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB -# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB -# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE -// Override the default return value of exception::what() for bad_function_call::what() -// with a string that is specific to bad_function_call (see http://wg21.link/LWG2233). -// This is an ABI break on platforms that sign and authenticate vtable function pointers -// because it changes the mangling of the virtual function located in the vtable, which -// changes how it gets signed. -# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE -// Enable optimized version of __do_get_(un)signed which avoids redundant copies. -# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET -// Give reverse_iterator one data member of type T, not two. -// Also, in C++17 and later, don't derive iterator types from std::iterator. -# define _LIBCPP_ABI_NO_ITERATOR_BASES -// Use the smallest possible integer type to represent the index of the variant. -// Previously libc++ used "unsigned int" exclusively. -# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION -// Unstable attempt to provide a more optimized std::function -# define _LIBCPP_ABI_OPTIMIZED_FUNCTION -// All the regex constants must be distinct and nonzero. -# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO -// Re-worked external template instantiations for std::string with a focus on -// performance and fast-path inlining. -# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION -// Enable clang::trivial_abi on std::unique_ptr. -# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI -// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr -# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI -// std::random_device holds some state when it uses an implementation that gets -// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this -// implementation to another one on a platform that has already shipped -// std::random_device, one needs to retain the same object layout to remain ABI -// compatible. This switch removes these workarounds for platforms that don't care -// about ABI compatibility. -# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT -// Don't export the legacy __basic_string_common class and its methods from the built library. -# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON -// Don't export the legacy __vector_base_common class and its methods from the built library. -# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON -// According to the Standard, `bitset::operator[] const` returns bool -# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL -// Fix the implementation of CityHash used for std::hash. -// This is an ABI break because `std::hash` will return a different result, -// which means that hashing the same object in translation units built against -// different versions of libc++ can return inconsistent results. This is especially -// tricky since std::hash is used in the implementation of unordered containers. -// -// The incorrect implementation of CityHash has the problem that it drops some -// bits on the floor. -# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION -// Remove the base 10 implementation of std::to_chars from the dylib. -// The implementation moved to the header, but we still export the symbols from -// the dylib for backwards compatibility. -# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 -// Define std::array/std::string_view iterators to be __wrap_iters instead of raw -// pointers, which prevents people from relying on a non-portable implementation -// detail. This is especially useful because enabling bounded iterators hardening -// requires code not to make these assumptions. -# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY -# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW -// Dont' add an inline namespace for `std::filesystem` -# define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE -// std::basic_ios uses WEOF to indicate that the fill value is -// uninitialized. However, on platforms where the size of char_type is -// equal to or greater than the size of int_type and char_type is unsigned, -// std::char_traits::eq_int_type() cannot distinguish between WEOF -// and WCHAR_MAX. This ABI setting determines whether we should instead track whether the fill -// value has been initialized using a separate boolean, which changes the ABI. -# define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE -// Make a std::pair of trivially copyable types trivially copyable. -// While this technically doesn't change the layout of pair itself, other types may decide to programatically change -// their representation based on whether something is trivially copyable. -# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR -#elif _LIBCPP_ABI_VERSION == 1 -# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) -// Enable compiling copies of now inline methods into the dylib to support -// applications compiled against older libraries. This is unnecessary with -// COFF dllexport semantics, since dllexport forces a non-inline definition -// of inline functions to be emitted anyway. Our own non-inline copy would -// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, -// the linker will take issue with the symbols in the shared object if the -// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), -// so disable it. -# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS -# endif -// Feature macros for disabling pre ABI v1 features. All of these options -// are deprecated. -# if defined(__FreeBSD__) -# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR -# endif -#endif - -// We had some bugs where we use [[no_unique_address]] together with construct_at, -// which causes UB as the call on construct_at could write to overlapping subobjects -// -// https://github.com/llvm/llvm-project/issues/70506 -// https://github.com/llvm/llvm-project/issues/70494 -// -// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. -// The macro below is used for all classes whose ABI have changed as part of fixing these bugs. -#define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua"))) - -// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's -// within the bounds of the original container and asserts it on every dereference. -// -// ABI impact: changes the iterator type of the relevant containers. -// -// Supported containers: -// - `span`; -// - `string_view`. -// #define _LIBCPP_ABI_BOUNDED_ITERATORS - -// Changes the iterator type of `basic_string` to a bounded iterator that keeps track of whether it's within the bounds -// of the original container and asserts it on every dereference and when performing iterator arithmetics. -// -// ABI impact: changes the iterator type of `basic_string` and its specializations, such as `string` and `wstring`. -// #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING - -// Changes the iterator type of `vector` to a bounded iterator that keeps track of whether it's within the bounds of the -// original container and asserts it on every dereference and when performing iterator arithmetics. Note: this doesn't -// yet affect `vector`. -// -// ABI impact: changes the iterator type of `vector` (except `vector`). -// #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR - -#if defined(_LIBCPP_COMPILER_CLANG_BASED) -# if defined(__APPLE__) -# if defined(__i386__) || defined(__x86_64__) -// use old string layout on x86_64 and i386 -# elif defined(__arm__) -// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs -# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 -# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT -# endif -# else -# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT -# endif -# endif -#endif - -#endif // _LIBCPP___CXX03___CONFIGURATION_ABI_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/availability.h b/third_party/libcxx/include/c++/v1/__cxx03/__configuration/availability.h deleted file mode 100644 index ad45ce0..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/availability.h +++ /dev/null @@ -1,400 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONFIGURATION_AVAILABILITY_H -#define _LIBCPP___CXX03___CONFIGURATION_AVAILABILITY_H - -#include <__cxx03/__configuration/compiler.h> -#include <__cxx03/__configuration/language.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -// Libc++ is shipped by various vendors. In particular, it is used as a system -// library on macOS, iOS and other Apple platforms. In order for users to be -// able to compile a binary that is intended to be deployed to an older version -// of a platform, Clang provides availability attributes [1]. These attributes -// can be placed on declarations and are used to describe the life cycle of a -// symbol in the library. -// -// The main goal is to ensure a compile-time error if a symbol that hasn't been -// introduced in a previously released library is used in a program that targets -// that previously released library. Normally, this would be a load-time error -// when one tries to launch the program against the older library. -// -// For example, the filesystem library was introduced in the dylib in LLVM 9. -// On Apple platforms, this corresponds to macOS 10.15. If a user compiles on -// a macOS 10.15 host but targets macOS 10.13 with their program, the compiler -// would normally not complain (because the required declarations are in the -// headers), but the dynamic loader would fail to find the symbols when actually -// trying to launch the program on macOS 10.13. To turn this into a compile-time -// issue instead, declarations are annotated with when they were introduced, and -// the compiler can produce a diagnostic if the program references something that -// isn't available on the deployment target. -// -// This mechanism is general in nature, and any vendor can add their markup to -// the library (see below). Whenever a new feature is added that requires support -// in the shared library, two macros are added below to allow marking the feature -// as unavailable: -// 1. A macro named `_LIBCPP_AVAILABILITY_HAS_` which must be defined -// to `_LIBCPP_INTRODUCED_IN_` for the appropriate LLVM version. -// 2. A macro named `_LIBCPP_AVAILABILITY_`, which must be defined to -// `_LIBCPP_INTRODUCED_IN__MARKUP` for the appropriate LLVM version. -// -// When vendors decide to ship the feature as part of their shared library, they -// can update the `_LIBCPP_INTRODUCED_IN_` macro (and the markup counterpart) -// based on the platform version they shipped that version of LLVM in. The library -// will then use this markup to provide an optimal user experience on these platforms. -// -// Furthermore, many features in the standard library have corresponding -// feature-test macros. The `_LIBCPP_AVAILABILITY_HAS_` macros -// are checked by the corresponding feature-test macros generated by -// generate_feature_test_macro_components.py to ensure that the library -// doesn't announce a feature as being implemented if it is unavailable on -// the deployment target. -// -// Note that this mechanism is disabled by default in the "upstream" libc++. -// Availability annotations are only meaningful when shipping libc++ inside -// a platform (i.e. as a system library), and so vendors that want them should -// turn those annotations on at CMake configuration time. -// -// [1]: https://clang.llvm.org/docs/AttributeReference.html#availability - -// For backwards compatibility, allow users to define _LIBCPP_DISABLE_AVAILABILITY -// for a while. -#if defined(_LIBCPP_DISABLE_AVAILABILITY) -# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) -# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -# endif -#endif - -// Availability markup is disabled when building the library, or when a non-Clang -// compiler is used because only Clang supports the necessary attributes. -#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED) -# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) -# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -# endif -#endif - -// When availability annotations are disabled, we take for granted that features introduced -// in all versions of the library are available. -#if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) - -# define _LIBCPP_INTRODUCED_IN_LLVM_19 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_18 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_17 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_17_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_16 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_15 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_14 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_13 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_13_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_12 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_11 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_10 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_10_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_9 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE /* nothing */ -# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_PUSH /* nothing */ -# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_POP /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_8 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_8_ATTRIBUTE /* nothing */ - -# define _LIBCPP_INTRODUCED_IN_LLVM_4 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE /* nothing */ - -#elif defined(__APPLE__) - -// clang-format off - -// LLVM 19 -// TODO: Fill this in -# define _LIBCPP_INTRODUCED_IN_LLVM_19 0 -# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE __attribute__((unavailable)) - -// LLVM 18 -// TODO: Fill this in -# define _LIBCPP_INTRODUCED_IN_LLVM_18 0 -# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE __attribute__((unavailable)) - -// LLVM 17 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140400) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170400) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170400) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100400) -# define _LIBCPP_INTRODUCED_IN_LLVM_17 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_17 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_17_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 14.4))) \ - __attribute__((availability(ios, strict, introduced = 17.4))) \ - __attribute__((availability(tvos, strict, introduced = 17.4))) \ - __attribute__((availability(watchos, strict, introduced = 10.4))) - -// LLVM 16 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000) -# define _LIBCPP_INTRODUCED_IN_LLVM_16 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_16 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 14.0))) \ - __attribute__((availability(ios, strict, introduced = 17.0))) \ - __attribute__((availability(tvos, strict, introduced = 17.0))) \ - __attribute__((availability(watchos, strict, introduced = 10.0))) - -// LLVM 15 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130400) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160500) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160500) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90500) -# define _LIBCPP_INTRODUCED_IN_LLVM_15 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_15 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 13.4))) \ - __attribute__((availability(ios, strict, introduced = 16.5))) \ - __attribute__((availability(tvos, strict, introduced = 16.5))) \ - __attribute__((availability(watchos, strict, introduced = 9.5))) - -// LLVM 14 -# define _LIBCPP_INTRODUCED_IN_LLVM_14 _LIBCPP_INTRODUCED_IN_LLVM_15 -# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE - -// LLVM 13 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90000) -# define _LIBCPP_INTRODUCED_IN_LLVM_13 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_13 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_13_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 13.0))) \ - __attribute__((availability(ios, strict, introduced = 16.0))) \ - __attribute__((availability(tvos, strict, introduced = 16.0))) \ - __attribute__((availability(watchos, strict, introduced = 9.0))) - -// LLVM 12 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120300) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150300) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150300) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80300) -# define _LIBCPP_INTRODUCED_IN_LLVM_12 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_12 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 12.3))) \ - __attribute__((availability(ios, strict, introduced = 15.3))) \ - __attribute__((availability(tvos, strict, introduced = 15.3))) \ - __attribute__((availability(watchos, strict, introduced = 8.3))) - -// LLVM 11 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000) -# define _LIBCPP_INTRODUCED_IN_LLVM_11 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_11 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 11.0))) \ - __attribute__((availability(ios, strict, introduced = 14.0))) \ - __attribute__((availability(tvos, strict, introduced = 14.0))) \ - __attribute__((availability(watchos, strict, introduced = 7.0))) - -// LLVM 10 -# define _LIBCPP_INTRODUCED_IN_LLVM_10 _LIBCPP_INTRODUCED_IN_LLVM_11 -# define _LIBCPP_INTRODUCED_IN_LLVM_10_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE - -// LLVM 9 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) -# define _LIBCPP_INTRODUCED_IN_LLVM_9 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_9 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 10.15))) \ - __attribute__((availability(ios, strict, introduced = 13.0))) \ - __attribute__((availability(tvos, strict, introduced = 13.0))) \ - __attribute__((availability(watchos, strict, introduced = 6.0))) -# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_PUSH \ - _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \ - _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \ - _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \ - _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))") -# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_POP \ - _Pragma("clang attribute pop") \ - _Pragma("clang attribute pop") \ - _Pragma("clang attribute pop") \ - _Pragma("clang attribute pop") - -// LLVM 4 -# if defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000 -# define _LIBCPP_INTRODUCED_IN_LLVM_4 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_4 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE __attribute__((availability(watchos, strict, introduced = 5.0))) - -// clang-format on - -#else - -// ...New vendors can add availability markup here... - -# error \ - "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!" - -#endif - -// These macros control the availability of std::bad_optional_access and -// other exception types. These were put in the shared library to prevent -// code bloat from every user program defining the vtable for these exception -// types. -// -// Note that when exceptions are disabled, the methods that normally throw -// these exceptions can be used even on older deployment targets, but those -// methods will abort instead of throwing. -#define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4 -#define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE - -#define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4 -#define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE - -#define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4 -#define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE - -// These macros control the availability of all parts of that -// depend on something in the dylib. -#define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY _LIBCPP_INTRODUCED_IN_LLVM_9 -#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE -#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_PUSH -#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_POP - -// This controls the availability of the C++20 synchronization library, -// which requires shared library support for various operations -// (see libcxx/src/atomic.cpp). This includes , , -// , and notification functions on std::atomic. -#define _LIBCPP_AVAILABILITY_HAS_SYNC _LIBCPP_INTRODUCED_IN_LLVM_11 -#define _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE - -// Enable additional explicit instantiations of iostreams components. This -// reduces the number of weak definitions generated in programs that use -// iostreams by providing a single strong definition in the shared library. -// -// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation, -// or once libc++ doesn't use the attribute anymore. -// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed. -#if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32) -# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 _LIBCPP_INTRODUCED_IN_LLVM_12 -#else -# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0 -#endif - -// This controls the availability of floating-point std::to_chars functions. -// These overloads were added later than the integer overloads. -#define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14 -#define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE - -// This controls whether the library claims to provide a default verbose -// termination function, and consequently whether the headers will try -// to use it when the mechanism isn't overriden at compile-time. -#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15 -#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE - -// This controls the availability of the C++17 std::pmr library, -// which is implemented in large part in the built library. -// -// TODO: Enable std::pmr markup once https://github.com/llvm/llvm-project/issues/40340 has been fixed -// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support -// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we -// use availability annotations until that bug has been fixed. -#define _LIBCPP_AVAILABILITY_HAS_PMR _LIBCPP_INTRODUCED_IN_LLVM_16 -#define _LIBCPP_AVAILABILITY_PMR - -// These macros controls the availability of __cxa_init_primary_exception -// in the built library, which std::make_exception_ptr might use -// (see libcxx/include/__exception/exception_ptr.h). -#define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18 -#define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE - -// This controls the availability of C++23 , which -// has a dependency on the built library (it needs access to -// the underlying buffer types of std::cout, std::cerr, and std::clog. -#define _LIBCPP_AVAILABILITY_HAS_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18 -#define _LIBCPP_AVAILABILITY_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE - -// This controls the availability of the C++20 time zone database. -// The parser code is built in the library. -#define _LIBCPP_AVAILABILITY_HAS_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19 -#define _LIBCPP_AVAILABILITY_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE - -// These macros determine whether we assume that std::bad_function_call and -// std::bad_expected_access provide a key function in the dylib. This allows -// centralizing their vtable and typeinfo instead of having all TUs provide -// a weak definition that then gets deduplicated. -#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19 -#define _LIBCPP_AVAILABILITY_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE -#define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19 -#define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE - -// Define availability attributes that depend on _LIBCPP_HAS_NO_EXCEPTIONS. -// Those are defined in terms of the availability attributes above, and -// should not be vendor-specific. -#if defined(_LIBCPP_HAS_NO_EXCEPTIONS) -# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST -# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS -# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS -#else -# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_ANY_CAST -# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS -# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS -#endif - -// Define availability attributes that depend on both -// _LIBCPP_HAS_NO_EXCEPTIONS and _LIBCPP_HAS_NO_RTTI. -#if defined(_LIBCPP_HAS_NO_EXCEPTIONS) || defined(_LIBCPP_HAS_NO_RTTI) -# undef _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION -# undef _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION -# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 0 -# define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION -#endif - -#endif // _LIBCPP___CXX03___CONFIGURATION_AVAILABILITY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/compiler.h b/third_party/libcxx/include/c++/v1/__cxx03/__configuration/compiler.h deleted file mode 100644 index 4d53a21..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/compiler.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONFIGURATION_COMPILER_H -#define _LIBCPP___CXX03___CONFIGURATION_COMPILER_H - -#include <__cxx03/__configuration/config_site_shim.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#if defined(__apple_build_version__) -// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) -# define _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) -#elif defined(__clang__) -# define _LIBCPP_COMPILER_CLANG_BASED -# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) -#elif defined(__GNUC__) -# define _LIBCPP_COMPILER_GCC -# define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) -#endif - -#ifdef __cplusplus - -// Warn if a compiler version is used that is not supported anymore -// LLVM RELEASE Update the minimum compiler versions -# if defined(_LIBCPP_CLANG_VER) -# if _LIBCPP_CLANG_VER < 1700 -# warning "Libc++ only supports Clang 17 and later" -# endif -# elif defined(_LIBCPP_APPLE_CLANG_VER) -# if _LIBCPP_APPLE_CLANG_VER < 1500 -# warning "Libc++ only supports AppleClang 15 and later" -# endif -# elif defined(_LIBCPP_GCC_VER) -# if _LIBCPP_GCC_VER < 1400 -# warning "Libc++ only supports GCC 14 and later" -# endif -# endif - -#endif - -#endif // _LIBCPP___CXX03___CONFIGURATION_COMPILER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/config_site_shim.h b/third_party/libcxx/include/c++/v1/__cxx03/__configuration/config_site_shim.h deleted file mode 100644 index 974a17a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/config_site_shim.h +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONFIGURATION_CONFIG_SITE_SHIM_H -#define _LIBCPP___CXX03___CONFIGURATION_CONFIG_SITE_SHIM_H - -#include <__config_site> - -#if !_LIBCPP_ABI_FORCE_ITANIUM -# undef _LIBCPP_ABI_FORCE_ITANIUM -#endif - -#if !_LIBCPP_ABI_FORCE_MICROSOFT -# undef _LIBCPP_ABI_FORCE_MICROSOFT -#endif - -#if !_LIBCPP_HAS_THREADS -# define _LIBCPP_HAS_NO_THREADS -#endif - -#if !_LIBCPP_HAS_MONOTONIC_CLOCK -# define _LIBCPP_HAS_NO_MONOTONIC_CLOCK -#endif - -#if !_LIBCPP_HAS_MUSL_LIBC -# undef _LIBCPP_HAS_MUSL_LIBC -#endif - -#if !_LIBCPP_HAS_THREAD_API_PTHREAD -# undef _LIBCPP_HAS_THREAD_API_PTHREAD -#endif - -#if !_LIBCPP_HAS_THREAD_API_EXTERNAL -# undef _LIBCPP_HAS_THREAD_API_EXTERNAL -#endif - -#if !_LIBCPP_HAS_THREAD_API_WIN32 -# undef _LIBCPP_HAS_THREAD_API_WIN32 -#endif - -#undef _LIBCPP_HAS_THREAD_API_C11 - -#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS -# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -#endif - -#if !_LIBCPP_HAS_FILESYSTEM -# define _LIBCPP_HAS_NO_FILESYSTEM -#endif - -#if !_LIBCPP_HAS_RANDOM_DEVICE -# define _LIBCPP_HAS_NO_RANDOM_DEVICE -#endif - -#if !_LIBCPP_HAS_LOCALIZATION -# define _LIBCPP_HAS_NO_LOCALIZATION -#endif - -#if !_LIBCPP_HAS_UNICODE -# define _LIBCPP_HAS_NO_UNICODE -#endif - -#if !_LIBCPP_HAS_WIDE_CHARACTERS -# define _LIBCPP_HAS_NO_WIDE_CHARACTERS -#endif - -#if !_LIBCPP_HAS_TIME_ZONE_DATABASE -# define _LIBCPP_HAS_NO_TIME_ZONE_DATABASE -#endif - -#if !_LIBCPP_INSTRUMENTED_WITH_ASAN -# undef _LIBCPP_INSTRUMENTED_WITH_ASAN -#endif - -#endif // _LIBCPP___CXX03___CONFIGURATION_CONFIG_SITE_SHIM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/language.h b/third_party/libcxx/include/c++/v1/__cxx03/__configuration/language.h deleted file mode 100644 index adc98a8..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/language.h +++ /dev/null @@ -1,27 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONFIGURATION_LANGUAGE_H -#define _LIBCPP___CXX03___CONFIGURATION_LANGUAGE_H - -#include <__cxx03/__configuration/config_site_shim.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#if !defined(__cpp_rtti) || __cpp_rtti < 199711L -# define _LIBCPP_HAS_NO_RTTI -#endif - -#if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L -# define _LIBCPP_HAS_NO_EXCEPTIONS -#endif - -#endif // _LIBCPP___CXX03___CONFIGURATION_LANGUAGE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/platform.h b/third_party/libcxx/include/c++/v1/__cxx03/__configuration/platform.h deleted file mode 100644 index 2459050..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__configuration/platform.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___CONFIGURATION_PLATFORM_H -#define _LIBCPP___CXX03___CONFIGURATION_PLATFORM_H - -#include <__cxx03/__configuration/config_site_shim.h> - -#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -# pragma GCC system_header -#endif - -#if defined(__ELF__) -# define _LIBCPP_OBJECT_FORMAT_ELF 1 -#elif defined(__MACH__) -# define _LIBCPP_OBJECT_FORMAT_MACHO 1 -#elif defined(_WIN32) -# define _LIBCPP_OBJECT_FORMAT_COFF 1 -#elif defined(__wasm__) -# define _LIBCPP_OBJECT_FORMAT_WASM 1 -#elif defined(_AIX) -# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 -#else -// ... add new file formats here ... -#endif - -// Need to detect which libc we're using if we're on Linux. -#if defined(__linux__) -# include -# if defined(__GLIBC_PREREQ) -# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) -# else -# define _LIBCPP_GLIBC_PREREQ(a, b) 0 -# endif // defined(__GLIBC_PREREQ) -#endif // defined(__linux__) - -#ifndef __BYTE_ORDER__ -# error \ - "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform" -#endif - -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# define _LIBCPP_LITTLE_ENDIAN -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define _LIBCPP_BIG_ENDIAN -#endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - -#endif // _LIBCPP___CXX03___CONFIGURATION_PLATFORM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/randomize_range.h b/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/randomize_range.h deleted file mode 100644 index 577a6be..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/randomize_range.h +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LIBCXX_DEBUG_RANDOMIZE_RANGE_H -#define _LIBCPP___CXX03___LIBCXX_DEBUG_RANDOMIZE_RANGE_H - -#include <__cxx03/__config> - -#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY -# include <__cxx03/__algorithm/shuffle.h> -# include <__cxx03/__type_traits/is_constant_evaluated.h> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI void __debug_randomize_range(_Iterator __first, _Sentinel __last) { -#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY -# error Support for unspecified stability is only for C++11 and higher - - if (!__libcpp_is_constant_evaluated()) - std::__shuffle<_AlgPolicy>(__first, __last, __libcpp_debug_randomizer()); -#else - (void)__first; - (void)__last; -#endif -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___LIBCXX_DEBUG_RANDOMIZE_RANGE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/sanitizers.h b/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/sanitizers.h deleted file mode 100644 index 32c4399..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/sanitizers.h +++ /dev/null @@ -1,104 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LIBCXX_DEBUG_UTILS_SANITIZERS_H -#define _LIBCPP___CXX03___LIBCXX_DEBUG_UTILS_SANITIZERS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/integral_constant.h> -#include <__cxx03/__type_traits/is_constant_evaluated.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#ifndef _LIBCPP_HAS_NO_ASAN - -extern "C" { -_LIBCPP_EXPORTED_FROM_ABI void -__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); -_LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container( - const void*, const void*, const void*, const void*, const void*, const void*); -_LIBCPP_EXPORTED_FROM_ABI int -__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); -} - -#endif // _LIBCPP_HAS_NO_ASAN - -_LIBCPP_BEGIN_NAMESPACE_STD - -// ASan choices -#ifndef _LIBCPP_HAS_NO_ASAN -# define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1 -#endif - -#ifdef _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS -// __asan_annotate_container_with_allocator determines whether containers with custom allocators are annotated. This is -// a public customization point to disable annotations if the custom allocator assumes that the memory isn't poisoned. -// See the https://libcxx.llvm.org/UsingLibcxx.html#turning-off-asan-annotation-in-containers for more information. -template -struct __asan_annotate_container_with_allocator : true_type {}; -#endif - -// Annotate a double-ended contiguous range. -// - [__first_storage, __last_storage) is the allocated memory region, -// - [__first_old_contained, __last_old_contained) is the previously allowed (unpoisoned) range, and -// - [__first_new_contained, __last_new_contained) is the new allowed (unpoisoned) range. -template -_LIBCPP_HIDE_FROM_ABI void __annotate_double_ended_contiguous_container( - const void* __first_storage, - const void* __last_storage, - const void* __first_old_contained, - const void* __last_old_contained, - const void* __first_new_contained, - const void* __last_new_contained) { -#ifdef _LIBCPP_HAS_NO_ASAN - (void)__first_storage; - (void)__last_storage; - (void)__first_old_contained; - (void)__last_old_contained; - (void)__first_new_contained; - (void)__last_new_contained; -#else - if (__asan_annotate_container_with_allocator<_Allocator>::value && __first_storage != nullptr) - __sanitizer_annotate_double_ended_contiguous_container( - __first_storage, - __last_storage, - __first_old_contained, - __last_old_contained, - __first_new_contained, - __last_new_contained); -#endif -} - -// Annotate a contiguous range. -// [__first_storage, __last_storage) is the allocated memory region, -// __old_last_contained is the previously last allowed (unpoisoned) element, and -// __new_last_contained is the new last allowed (unpoisoned) element. -template -_LIBCPP_HIDE_FROM_ABI void __annotate_contiguous_container( - const void* __first_storage, - const void* __last_storage, - const void* __old_last_contained, - const void* __new_last_contained) { -#ifdef _LIBCPP_HAS_NO_ASAN - (void)__first_storage; - (void)__last_storage; - (void)__old_last_contained; - (void)__new_last_contained; -#else - if (!__libcpp_is_constant_evaluated() && __asan_annotate_container_with_allocator<_Allocator>::value && - __first_storage != nullptr) - __sanitizer_annotate_contiguous_container( - __first_storage, __last_storage, __old_last_contained, __new_last_contained); -#endif -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___LIBCXX_DEBUG_UTILS_SANITIZERS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/strict_weak_ordering_check.h b/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/strict_weak_ordering_check.h deleted file mode 100644 index 9897652..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__debug_utils/strict_weak_ordering_check.h +++ /dev/null @@ -1,77 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LIBCXX_DEBUG_STRICT_WEAK_ORDERING_CHECK -#define _LIBCPP___CXX03___LIBCXX_DEBUG_STRICT_WEAK_ORDERING_CHECK - -#include <__cxx03/__config> - -#include <__cxx03/__algorithm/comp_ref_type.h> -#include <__cxx03/__algorithm/is_sorted.h> -#include <__cxx03/__assert> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/is_constant_evaluated.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI void -__check_strict_weak_ordering_sorted(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) { -#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG - using __diff_t = __iter_diff_t<_RandomAccessIterator>; - using _Comp_ref = __comp_ref_type<_Comp>; - if (!__libcpp_is_constant_evaluated()) { - // Check if the range is actually sorted. - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( - (std::is_sorted<_RandomAccessIterator, _Comp_ref>(__first, __last, _Comp_ref(__comp))), - "The range is not sorted after the sort, your comparator is not a valid strict-weak ordering"); - // Limit the number of elements we need to check. - __diff_t __size = __last - __first > __diff_t(100) ? __diff_t(100) : __last - __first; - __diff_t __p = 0; - while (__p < __size) { - __diff_t __q = __p + __diff_t(1); - // Find first element that is greater than *(__first+__p). - while (__q < __size && !__comp(*(__first + __p), *(__first + __q))) { - ++__q; - } - // Check that the elements from __p to __q are equal between each other. - for (__diff_t __b = __p; __b < __q; ++__b) { - for (__diff_t __a = __p; __a <= __b; ++__a) { - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( - !__comp(*(__first + __a), *(__first + __b)), "Your comparator is not a valid strict-weak ordering"); - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( - !__comp(*(__first + __b), *(__first + __a)), "Your comparator is not a valid strict-weak ordering"); - } - } - // Check that elements between __p and __q are less than between __q and __size. - for (__diff_t __a = __p; __a < __q; ++__a) { - for (__diff_t __b = __q; __b < __size; ++__b) { - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( - __comp(*(__first + __a), *(__first + __b)), "Your comparator is not a valid strict-weak ordering"); - _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( - !__comp(*(__first + __b), *(__first + __a)), "Your comparator is not a valid strict-weak ordering"); - } - } - // Skip these equal elements. - __p = __q; - } - } -#else - (void)__first; - (void)__last; - (void)__comp; -#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___LIBCXX_DEBUG_STRICT_WEAK_ORDERING_CHECK diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__exception/exception.h b/third_party/libcxx/include/c++/v1/__cxx03/__exception/exception.h deleted file mode 100644 index 27b1e43..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__exception/exception.h +++ /dev/null @@ -1,94 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___EXCEPTION_EXCEPTION_H -#define _LIBCPP___CXX03___EXCEPTION_EXCEPTION_H - -#include <__cxx03/__config> - -// defines its own std::exception and std::bad_exception types, -// which we use in order to be ABI-compatible with other STLs on Windows. -#if defined(_LIBCPP_ABI_VCRUNTIME) -# include <__cxx03/vcruntime_exception.h> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -namespace std { // purposefully not using versioning namespace - -#if defined(_LIBCPP_ABI_VCRUNTIME) && (!defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS != 0) -// The std::exception class was already included above, but we're explicit about this condition here for clarity. - -#elif defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0 -// However, does not define std::exception and std::bad_exception -// when _HAS_EXCEPTIONS == 0. -// -// Since libc++ still wants to provide the std::exception hierarchy even when _HAS_EXCEPTIONS == 0 -// (after all those are simply types like any other), we define an ABI-compatible version -// of the VCRuntime std::exception and std::bad_exception types in that mode. - -struct __std_exception_data { - char const* _What; - bool _DoFree; -}; - -class exception { // base of all library exceptions -public: - exception() _NOEXCEPT : __data_() {} - - explicit exception(char const* __message) _NOEXCEPT : __data_() { - __data_._What = __message; - __data_._DoFree = true; - } - - exception(exception const&) _NOEXCEPT {} - - exception& operator=(exception const&) _NOEXCEPT { return *this; } - - virtual ~exception() _NOEXCEPT {} - - virtual char const* what() const _NOEXCEPT { return __data_._What ? __data_._What : "Unknown exception"; } - -private: - __std_exception_data __data_; -}; - -class bad_exception : public exception { -public: - bad_exception() _NOEXCEPT : exception("bad exception") {} -}; - -#else // !defined(_LIBCPP_ABI_VCRUNTIME) -// On all other platforms, we define our own std::exception and std::bad_exception types -// regardless of whether exceptions are turned on as a language feature. - -class _LIBCPP_EXPORTED_FROM_ABI exception { -public: - _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {} - _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT = default; - _LIBCPP_HIDE_FROM_ABI exception& operator=(const exception&) _NOEXCEPT = default; - - virtual ~exception() _NOEXCEPT; - virtual const char* what() const _NOEXCEPT; -}; - -class _LIBCPP_EXPORTED_FROM_ABI bad_exception : public exception { -public: - _LIBCPP_HIDE_FROM_ABI bad_exception() _NOEXCEPT {} - _LIBCPP_HIDE_FROM_ABI bad_exception(const bad_exception&) _NOEXCEPT = default; - _LIBCPP_HIDE_FROM_ABI bad_exception& operator=(const bad_exception&) _NOEXCEPT = default; - ~bad_exception() _NOEXCEPT override; - const char* what() const _NOEXCEPT override; -}; -#endif // !_LIBCPP_ABI_VCRUNTIME - -} // namespace std - -#endif // _LIBCPP___CXX03___EXCEPTION_EXCEPTION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__exception/exception_ptr.h b/third_party/libcxx/include/c++/v1/__cxx03/__exception/exception_ptr.h deleted file mode 100644 index 33dbd40..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__exception/exception_ptr.h +++ /dev/null @@ -1,177 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___EXCEPTION_EXCEPTION_PTR_H -#define _LIBCPP___CXX03___EXCEPTION_EXCEPTION_PTR_H - -#include <__cxx03/__config> -#include <__cxx03/__exception/operations.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__memory/construct_at.h> -#include <__cxx03/__type_traits/decay.h> -#include <__cxx03/cstddef> -#include <__cxx03/cstdlib> -#include <__cxx03/new> -#include <__cxx03/typeinfo> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#ifndef _LIBCPP_ABI_MICROSOFT - -# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION - -namespace __cxxabiv1 { - -extern "C" { -_LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw(); -_LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw(); - -struct __cxa_exception; -_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception( - void*, - std::type_info*, -# if defined(_WIN32) - void(__thiscall*)(void*)) throw(); -# elif defined(__wasm__) - // In Wasm, a destructor returns its argument - void* (*)(void*)) throw(); -# else - void (*)(void*)) throw(); -# endif -} - -} // namespace __cxxabiv1 - -# endif - -#endif - -namespace std { // purposefully not using versioning namespace - -#ifndef _LIBCPP_ABI_MICROSOFT - -class _LIBCPP_EXPORTED_FROM_ABI exception_ptr { - void* __ptr_; - - static exception_ptr __from_native_exception_pointer(void*) _NOEXCEPT; - - template - friend _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep) _NOEXCEPT; - -public: - // exception_ptr is basically a COW string. - using __trivially_relocatable = exception_ptr; - - _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {} - _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {} - - exception_ptr(const exception_ptr&) _NOEXCEPT; - exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; - ~exception_ptr() _NOEXCEPT; - - _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __ptr_ != nullptr; } - - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT { - return __x.__ptr_ == __y.__ptr_; - } - - friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT { - return !(__x == __y); - } - - friend _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT; - friend _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); -}; - -template -_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS -# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L - using _Ep2 = __decay_t<_Ep>; - - void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep)); -# ifdef __wasm__ - // In Wasm, a destructor returns its argument - (void)__cxxabiv1::__cxa_init_primary_exception( - __ex, const_cast(&typeid(_Ep)), [](void* __p) -> void* { -# else - (void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast(&typeid(_Ep)), [](void* __p) { -# endif - std::__destroy_at(static_cast<_Ep2*>(__p)); -# ifdef __wasm__ - return __p; -# endif - }); - - try { - ::new (__ex) _Ep2(__e); - return exception_ptr::__from_native_exception_pointer(__ex); - } catch (...) { - __cxxabiv1::__cxa_free_exception(__ex); - return current_exception(); - } -# else - try { - throw __e; - } catch (...) { - return current_exception(); - } -# endif -# else - ((void)__e); - std::abort(); -# endif -} - -#else // _LIBCPP_ABI_MICROSOFT - -class _LIBCPP_EXPORTED_FROM_ABI exception_ptr { - _LIBCPP_DIAGNOSTIC_PUSH - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field") - void* __ptr1_; - void* __ptr2_; - _LIBCPP_DIAGNOSTIC_POP - -public: - exception_ptr() _NOEXCEPT; - exception_ptr(nullptr_t) _NOEXCEPT; - exception_ptr(const exception_ptr& __other) _NOEXCEPT; - exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT; - exception_ptr& operator=(nullptr_t) _NOEXCEPT; - ~exception_ptr() _NOEXCEPT; - explicit operator bool() const _NOEXCEPT; -}; - -_LIBCPP_EXPORTED_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT; - -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT { - return !(__x == __y); -} - -_LIBCPP_EXPORTED_FROM_ABI void swap(exception_ptr&, exception_ptr&) _NOEXCEPT; - -_LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void* __except, const void* __ptr); -_LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT; -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); - -// This is a built-in template function which automagically extracts the required -// information. -template -void* __GetExceptionInfo(_E); - -template -_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT { - return __copy_exception_ptr(std::addressof(__e), __GetExceptionInfo(__e)); -} - -#endif // _LIBCPP_ABI_MICROSOFT -} // namespace std - -#endif // _LIBCPP___CXX03___EXCEPTION_EXCEPTION_PTR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__exception/nested_exception.h b/third_party/libcxx/include/c++/v1/__cxx03/__exception/nested_exception.h deleted file mode 100644 index 6079994..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__exception/nested_exception.h +++ /dev/null @@ -1,99 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___EXCEPTION_NESTED_EXCEPTION_H -#define _LIBCPP___CXX03___EXCEPTION_NESTED_EXCEPTION_H - -#include <__cxx03/__config> -#include <__cxx03/__exception/exception_ptr.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__type_traits/decay.h> -#include <__cxx03/__type_traits/is_base_of.h> -#include <__cxx03/__type_traits/is_class.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/__type_traits/is_final.h> -#include <__cxx03/__type_traits/is_polymorphic.h> -#include <__cxx03/__utility/forward.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -namespace std { // purposefully not using versioning namespace - -class _LIBCPP_EXPORTED_FROM_ABI nested_exception { - exception_ptr __ptr_; - -public: - nested_exception() _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI nested_exception(const nested_exception&) _NOEXCEPT = default; - _LIBCPP_HIDE_FROM_ABI nested_exception& operator=(const nested_exception&) _NOEXCEPT = default; - virtual ~nested_exception() _NOEXCEPT; - - // access functions - _LIBCPP_NORETURN void rethrow_nested() const; - _LIBCPP_HIDE_FROM_ABI exception_ptr nested_ptr() const _NOEXCEPT { return __ptr_; } -}; - -template -struct __nested : public _Tp, public nested_exception { - _LIBCPP_HIDE_FROM_ABI explicit __nested(const _Tp& __t) : _Tp(__t) {} -}; - -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS -template -struct __throw_with_nested; - -template -struct __throw_with_nested<_Tp, _Up, true> { - _LIBCPP_NORETURN static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { - throw __nested<_Up>(std::forward<_Tp>(__t)); - } -}; - -template -struct __throw_with_nested<_Tp, _Up, false> { - _LIBCPP_NORETURN static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { throw std::forward<_Tp>(__t); } -}; -#endif - -template -_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void throw_with_nested(_Tp&& __t) { -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - using _Up = __decay_t<_Tp>; - static_assert(is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible"); - __throw_with_nested<_Tp, - _Up, - is_class<_Up>::value && !is_base_of::value && - !__libcpp_is_final<_Up>::value>::__do_throw(std::forward<_Tp>(__t)); -#else - ((void)__t); - // FIXME: Make this abort -#endif -} - -template -struct __can_dynamic_cast - : _BoolConstant< is_polymorphic<_From>::value && - (!is_base_of<_To, _From>::value || is_convertible::value)> {}; - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep& __e) { - const nested_exception* __nep = dynamic_cast(std::addressof(__e)); - if (__nep) - __nep->rethrow_nested(); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep&) {} - -} // namespace std - -#endif // _LIBCPP___CXX03___EXCEPTION_NESTED_EXCEPTION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__exception/operations.h b/third_party/libcxx/include/c++/v1/__cxx03/__exception/operations.h deleted file mode 100644 index da8abba..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__exception/operations.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___EXCEPTION_OPERATIONS_H -#define _LIBCPP___CXX03___EXCEPTION_OPERATIONS_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -namespace std { // purposefully not using versioning namespace -using unexpected_handler = void (*)(); -_LIBCPP_EXPORTED_FROM_ABI unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI unexpected_handler get_unexpected() _NOEXCEPT; -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void unexpected(); - -using terminate_handler = void (*)(); -_LIBCPP_EXPORTED_FROM_ABI terminate_handler set_terminate(terminate_handler) _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI terminate_handler get_terminate() _NOEXCEPT; - -_LIBCPP_EXPORTED_FROM_ABI bool uncaught_exception() _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI int uncaught_exceptions() _NOEXCEPT; - -class _LIBCPP_EXPORTED_FROM_ABI exception_ptr; - -_LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT; -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); -} // namespace std - -#endif // _LIBCPP___CXX03___EXCEPTION_OPERATIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__exception/terminate.h b/third_party/libcxx/include/c++/v1/__cxx03/__exception/terminate.h deleted file mode 100644 index 5f0cfa9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__exception/terminate.h +++ /dev/null @@ -1,22 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___EXCEPTION_TERMINATE_H -#define _LIBCPP___CXX03___EXCEPTION_TERMINATE_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -namespace std { // purposefully not using versioning namespace -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void terminate() _NOEXCEPT; -} // namespace std - -#endif // _LIBCPP___CXX03___EXCEPTION_TERMINATE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_function.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_function.h deleted file mode 100644 index 06613bd..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_function.h +++ /dev/null @@ -1,43 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_BINARY_FUNCTION_H -#define _LIBCPP___CXX03___FUNCTIONAL_BINARY_FUNCTION_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS binary_function { - typedef _Arg1 first_argument_type; - typedef _Arg2 second_argument_type; - typedef _Result result_type; -}; - -template -struct __binary_function_keep_layout_base { - using first_argument_type = _Arg1; - using second_argument_type = _Arg2; - using result_type = _Result; -}; - -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") -template -using __binary_function = binary_function<_Arg1, _Arg2, _Result>; -_LIBCPP_DIAGNOSTIC_POP - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_BINARY_FUNCTION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_negate.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_negate.h deleted file mode 100644 index f59506c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binary_negate.h +++ /dev/null @@ -1,45 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_BINARY_NEGATE_H -#define _LIBCPP___CXX03___FUNCTIONAL_BINARY_NEGATE_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/binary_function.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS binary_negate - : public __binary_function { - _Predicate __pred_; - -public: - _LIBCPP_HIDE_FROM_ABI explicit binary_negate(const _Predicate& __pred) : __pred_(__pred) {} - - _LIBCPP_HIDE_FROM_ABI bool operator()(const typename _Predicate::first_argument_type& __x, - const typename _Predicate::second_argument_type& __y) const { - return !__pred_(__x, __y); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI binary_negate<_Predicate> not2(const _Predicate& __pred) { - return binary_negate<_Predicate>(__pred); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_BINARY_NEGATE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/bind.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/bind.h deleted file mode 100644 index 1722844..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/bind.h +++ /dev/null @@ -1,70 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_BIND_H -#define _LIBCPP___CXX03___FUNCTIONAL_BIND_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/weak_result_type.h> -#include <__cxx03/__fwd/functional.h> -#include <__cxx03/__type_traits/decay.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_reference_wrapper.h> -#include <__cxx03/__type_traits/is_void.h> -#include <__cxx03/__type_traits/remove_cvref.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct is_bind_expression - : _If< _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, false_type, is_bind_expression<__remove_cvref_t<_Tp> > > {}; - -template -struct is_placeholder - : _If< _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, - integral_constant, - is_placeholder<__remove_cvref_t<_Tp> > > {}; - -namespace placeholders { - -template -struct __ph {}; - -// C++17 recommends that we implement placeholders as `inline constexpr`, but allows -// implementing them as `extern `. Libc++ implements them as -// `extern const` in all standard modes to avoid an ABI break in C++03: making them -// `inline constexpr` requires removing their definition in the shared library to -// avoid ODR violations, which is an ABI break. -// -// In practice, since placeholders are empty, `extern const` is almost impossible -// to distinguish from `inline constexpr` from a usage stand point. -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<1> _1; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<2> _2; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<3> _3; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<4> _4; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<5> _5; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<6> _6; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<7> _7; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<8> _8; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<9> _9; -_LIBCPP_EXPORTED_FROM_ABI extern const __ph<10> _10; - -} // namespace placeholders - -template -struct is_placeholder > : public integral_constant {}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_BIND_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binder1st.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/binder1st.h deleted file mode 100644 index aacb024..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binder1st.h +++ /dev/null @@ -1,49 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_BINDER1ST_H -#define _LIBCPP___CXX03___FUNCTIONAL_BINDER1ST_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/unary_function.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS binder1st - : public __unary_function { -protected: - _Operation op; - typename _Operation::first_argument_type value; - -public: - _LIBCPP_HIDE_FROM_ABI binder1st(const _Operation& __x, const typename _Operation::first_argument_type __y) - : op(__x), value(__y) {} - _LIBCPP_HIDE_FROM_ABI typename _Operation::result_type - operator()(typename _Operation::second_argument_type& __x) const { - return op(value, __x); - } - _LIBCPP_HIDE_FROM_ABI typename _Operation::result_type - operator()(const typename _Operation::second_argument_type& __x) const { - return op(value, __x); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI binder1st<_Operation> bind1st(const _Operation& __op, const _Tp& __x) { - return binder1st<_Operation>(__op, __x); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_BINDER1ST_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binder2nd.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/binder2nd.h deleted file mode 100644 index b45a1fe..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/binder2nd.h +++ /dev/null @@ -1,49 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_BINDER2ND_H -#define _LIBCPP___CXX03___FUNCTIONAL_BINDER2ND_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/unary_function.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS binder2nd - : public __unary_function { -protected: - _Operation op; - typename _Operation::second_argument_type value; - -public: - _LIBCPP_HIDE_FROM_ABI binder2nd(const _Operation& __x, const typename _Operation::second_argument_type __y) - : op(__x), value(__y) {} - _LIBCPP_HIDE_FROM_ABI typename _Operation::result_type - operator()(typename _Operation::first_argument_type& __x) const { - return op(__x, value); - } - _LIBCPP_HIDE_FROM_ABI typename _Operation::result_type - operator()(const typename _Operation::first_argument_type& __x) const { - return op(__x, value); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI binder2nd<_Operation> bind2nd(const _Operation& __op, const _Tp& __x) { - return binder2nd<_Operation>(__op, __x); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_BINDER2ND_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/hash.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/hash.h deleted file mode 100644 index b2c3bee..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/hash.h +++ /dev/null @@ -1,509 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_HASH_H -#define _LIBCPP___CXX03___FUNCTIONAL_HASH_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/unary_function.h> -#include <__cxx03/__fwd/functional.h> -#include <__cxx03/__type_traits/conjunction.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__type_traits/is_enum.h> -#include <__cxx03/__type_traits/underlying_type.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/__utility/swap.h> -#include <__cxx03/cstddef> -#include <__cxx03/cstdint> -#include <__cxx03/cstring> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI _Size __loadword(const void* __p) { - _Size __r; - std::memcpy(&__r, __p, sizeof(__r)); - return __r; -} - -// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t -// is 64 bits. This is because cityhash64 uses 64bit x 64bit -// multiplication, which can be very slow on 32-bit systems. -template -struct __murmur2_or_cityhash; - -template -struct __murmur2_or_cityhash<_Size, 32> { - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK _Size - operator()(const void* __key, _Size __len) const { - // murmur2 - const _Size __m = 0x5bd1e995; - const _Size __r = 24; - _Size __h = __len; - const unsigned char* __data = static_cast(__key); - for (; __len >= 4; __data += 4, __len -= 4) { - _Size __k = std::__loadword<_Size>(__data); - __k *= __m; - __k ^= __k >> __r; - __k *= __m; - __h *= __m; - __h ^= __k; - } - switch (__len) { - case 3: - __h ^= static_cast<_Size>(__data[2] << 16); - _LIBCPP_FALLTHROUGH(); - case 2: - __h ^= static_cast<_Size>(__data[1] << 8); - _LIBCPP_FALLTHROUGH(); - case 1: - __h ^= __data[0]; - __h *= __m; - } - __h ^= __h >> 13; - __h *= __m; - __h ^= __h >> 15; - return __h; - } -}; - -template -struct __murmur2_or_cityhash<_Size, 64> { - // cityhash64 - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK _Size - operator()(const void* __key, _Size __len) const { - const char* __s = static_cast(__key); - if (__len <= 32) { - if (__len <= 16) { - return __hash_len_0_to_16(__s, __len); - } else { - return __hash_len_17_to_32(__s, __len); - } - } else if (__len <= 64) { - return __hash_len_33_to_64(__s, __len); - } - - // For strings over 64 bytes we hash the end first, and then as we - // loop we keep 56 bytes of state: v, w, x, y, and z. - _Size __x = std::__loadword<_Size>(__s + __len - 40); - _Size __y = std::__loadword<_Size>(__s + __len - 16) + std::__loadword<_Size>(__s + __len - 56); - _Size __z = - __hash_len_16(std::__loadword<_Size>(__s + __len - 48) + __len, std::__loadword<_Size>(__s + __len - 24)); - pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); - pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); - __x = __x * __k1 + std::__loadword<_Size>(__s); - - // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. - __len = (__len - 1) & ~static_cast<_Size>(63); - do { - __x = __rotate(__x + __y + __v.first + std::__loadword<_Size>(__s + 8), 37) * __k1; - __y = __rotate(__y + __v.second + std::__loadword<_Size>(__s + 48), 42) * __k1; - __x ^= __w.second; - __y += __v.first + std::__loadword<_Size>(__s + 40); - __z = __rotate(__z + __w.first, 33) * __k1; - __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); - __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, __y + std::__loadword<_Size>(__s + 16)); - std::swap(__z, __x); - __s += 64; - __len -= 64; - } while (__len != 0); - return __hash_len_16(__hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, - __hash_len_16(__v.second, __w.second) + __x); - } - -private: - // Some primes between 2^63 and 2^64. - static const _Size __k0 = 0xc3a5c85c97cb3127ULL; - static const _Size __k1 = 0xb492b66fbe98f273ULL; - static const _Size __k2 = 0x9ae16a3b2f90404fULL; - static const _Size __k3 = 0xc949d7c7509e6557ULL; - - _LIBCPP_HIDE_FROM_ABI static _Size __rotate(_Size __val, int __shift) { - return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); - } - - _LIBCPP_HIDE_FROM_ABI static _Size __rotate_by_at_least_1(_Size __val, int __shift) { - return (__val >> __shift) | (__val << (64 - __shift)); - } - - _LIBCPP_HIDE_FROM_ABI static _Size __shift_mix(_Size __val) { return __val ^ (__val >> 47); } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static _Size __hash_len_16(_Size __u, _Size __v) { - const _Size __mul = 0x9ddfea08eb382d69ULL; - _Size __a = (__u ^ __v) * __mul; - __a ^= (__a >> 47); - _Size __b = (__v ^ __a) * __mul; - __b ^= (__b >> 47); - __b *= __mul; - return __b; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static _Size - __hash_len_0_to_16(const char* __s, _Size __len) { - if (__len > 8) { - const _Size __a = std::__loadword<_Size>(__s); - const _Size __b = std::__loadword<_Size>(__s + __len - 8); - return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; - } - if (__len >= 4) { - const uint32_t __a = std::__loadword(__s); - const uint32_t __b = std::__loadword(__s + __len - 4); -#ifdef _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION - return __hash_len_16(__len + (static_cast<_Size>(__a) << 3), __b); -#else - return __hash_len_16(__len + (__a << 3), __b); -#endif - } - if (__len > 0) { - const unsigned char __a = static_cast(__s[0]); - const unsigned char __b = static_cast(__s[__len >> 1]); - const unsigned char __c = static_cast(__s[__len - 1]); - const uint32_t __y = static_cast(__a) + (static_cast(__b) << 8); - const uint32_t __z = __len + (static_cast(__c) << 2); - return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; - } - return __k2; - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static _Size - __hash_len_17_to_32(const char* __s, _Size __len) { - const _Size __a = std::__loadword<_Size>(__s) * __k1; - const _Size __b = std::__loadword<_Size>(__s + 8); - const _Size __c = std::__loadword<_Size>(__s + __len - 8) * __k2; - const _Size __d = std::__loadword<_Size>(__s + __len - 16) * __k0; - return __hash_len_16( - __rotate(__a - __b, 43) + __rotate(__c, 30) + __d, __a + __rotate(__b ^ __k3, 20) - __c + __len); - } - - // Return a 16-byte hash for 48 bytes. Quick and dirty. - // Callers do best to use "random-looking" values for a and b. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static pair<_Size, _Size> - __weak_hash_len_32_with_seeds(_Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) { - __a += __w; - __b = __rotate(__b + __a + __z, 21); - const _Size __c = __a; - __a += __x; - __a += __y; - __b += __rotate(__a, 44); - return pair<_Size, _Size>(__a + __z, __b + __c); - } - - // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static pair<_Size, _Size> - __weak_hash_len_32_with_seeds(const char* __s, _Size __a, _Size __b) { - return __weak_hash_len_32_with_seeds( - std::__loadword<_Size>(__s), - std::__loadword<_Size>(__s + 8), - std::__loadword<_Size>(__s + 16), - std::__loadword<_Size>(__s + 24), - __a, - __b); - } - - // Return an 8-byte hash for 33 to 64 bytes. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK static _Size - __hash_len_33_to_64(const char* __s, size_t __len) { - _Size __z = std::__loadword<_Size>(__s + 24); - _Size __a = std::__loadword<_Size>(__s) + (__len + std::__loadword<_Size>(__s + __len - 16)) * __k0; - _Size __b = __rotate(__a + __z, 52); - _Size __c = __rotate(__a, 37); - __a += std::__loadword<_Size>(__s + 8); - __c += __rotate(__a, 7); - __a += std::__loadword<_Size>(__s + 16); - _Size __vf = __a + __z; - _Size __vs = __b + __rotate(__a, 31) + __c; - __a = std::__loadword<_Size>(__s + 16) + std::__loadword<_Size>(__s + __len - 32); - __z += std::__loadword<_Size>(__s + __len - 8); - __b = __rotate(__a + __z, 52); - __c = __rotate(__a, 37); - __a += std::__loadword<_Size>(__s + __len - 24); - __c += __rotate(__a, 7); - __a += std::__loadword<_Size>(__s + __len - 16); - _Size __wf = __a + __z; - _Size __ws = __b + __rotate(__a, 31) + __c; - _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); - return __shift_mix(__r * __k0 + __vs) * __k2; - } -}; - -template -struct __scalar_hash; - -template -struct __scalar_hash<_Tp, 0> : public __unary_function<_Tp, size_t> { - _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { - union { - _Tp __t; - size_t __a; - } __u; - __u.__a = 0; - __u.__t = __v; - return __u.__a; - } -}; - -template -struct __scalar_hash<_Tp, 1> : public __unary_function<_Tp, size_t> { - _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { - union { - _Tp __t; - size_t __a; - } __u; - __u.__t = __v; - return __u.__a; - } -}; - -template -struct __scalar_hash<_Tp, 2> : public __unary_function<_Tp, size_t> { - _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { - union { - _Tp __t; - struct { - size_t __a; - size_t __b; - } __s; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash()(&__u, sizeof(__u)); - } -}; - -template -struct __scalar_hash<_Tp, 3> : public __unary_function<_Tp, size_t> { - _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { - union { - _Tp __t; - struct { - size_t __a; - size_t __b; - size_t __c; - } __s; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash()(&__u, sizeof(__u)); - } -}; - -template -struct __scalar_hash<_Tp, 4> : public __unary_function<_Tp, size_t> { - _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { - union { - _Tp __t; - struct { - size_t __a; - size_t __b; - size_t __c; - size_t __d; - } __s; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash()(&__u, sizeof(__u)); - } -}; - -struct _PairT { - size_t first; - size_t second; -}; - -_LIBCPP_HIDE_FROM_ABI inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT { - typedef __scalar_hash<_PairT> _HashT; - const _PairT __p = {__lhs, __rhs}; - return _HashT()(__p); -} - -template -struct _LIBCPP_TEMPLATE_VIS hash<_Tp*> : public __unary_function<_Tp*, size_t> { - _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp* __v) const _NOEXCEPT { - union { - _Tp* __t; - size_t __a; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash()(&__u, sizeof(__u)); - } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(bool __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(char __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(signed char __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned char __v) const _NOEXCEPT { return static_cast(__v); } -}; - -#ifndef _LIBCPP_HAS_NO_CHAR8_T -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(char8_t __v) const _NOEXCEPT { return static_cast(__v); } -}; -#endif // !_LIBCPP_HAS_NO_CHAR8_T - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(char16_t __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(char32_t __v) const _NOEXCEPT { return static_cast(__v); } -}; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(wchar_t __v) const _NOEXCEPT { return static_cast(__v); } -}; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(short __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned short __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(int __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned int __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(long __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned long __v) const _NOEXCEPT { return static_cast(__v); } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __scalar_hash {}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __scalar_hash {}; - -#ifndef _LIBCPP_HAS_NO_INT128 - -template <> -struct _LIBCPP_TEMPLATE_VIS hash<__int128_t> : public __scalar_hash<__int128_t> {}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t> : public __scalar_hash<__uint128_t> {}; - -#endif - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __scalar_hash { - _LIBCPP_HIDE_FROM_ABI size_t operator()(float __v) const _NOEXCEPT { - // -0.0 and 0.0 should return same hash - if (__v == 0.0f) - return 0; - return __scalar_hash::operator()(__v); - } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __scalar_hash { - _LIBCPP_HIDE_FROM_ABI size_t operator()(double __v) const _NOEXCEPT { - // -0.0 and 0.0 should return same hash - if (__v == 0.0) - return 0; - return __scalar_hash::operator()(__v); - } -}; - -template <> -struct _LIBCPP_TEMPLATE_VIS hash : public __scalar_hash { - _LIBCPP_HIDE_FROM_ABI size_t operator()(long double __v) const _NOEXCEPT { - // -0.0 and 0.0 should return same hash - if (__v == 0.0L) - return 0; -#if defined(__i386__) || (defined(__x86_64__) && defined(__ILP32__)) - // Zero out padding bits - union { - long double __t; - struct { - size_t __a; - size_t __b; - size_t __c; - size_t __d; - } __s; - } __u; - __u.__s.__a = 0; - __u.__s.__b = 0; - __u.__s.__c = 0; - __u.__s.__d = 0; - __u.__t = __v; - return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; -#elif defined(__x86_64__) - // Zero out padding bits - union { - long double __t; - struct { - size_t __a; - size_t __b; - } __s; - } __u; - __u.__s.__a = 0; - __u.__s.__b = 0; - __u.__t = __v; - return __u.__s.__a ^ __u.__s.__b; -#else - return __scalar_hash::operator()(__v); -#endif - } -}; - -template ::value> -struct _LIBCPP_TEMPLATE_VIS __enum_hash : public __unary_function<_Tp, size_t> { - _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { - typedef typename underlying_type<_Tp>::type type; - return hash()(static_cast(__v)); - } -}; -template -struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> { - __enum_hash() = delete; - __enum_hash(__enum_hash const&) = delete; - __enum_hash& operator=(__enum_hash const&) = delete; -}; - -template -struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp> {}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_HASH_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/identity.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/identity.h deleted file mode 100644 index b5b8683..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/identity.h +++ /dev/null @@ -1,45 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_IDENTITY_H -#define _LIBCPP___CXX03___FUNCTIONAL_IDENTITY_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/functional.h> -#include <__cxx03/__type_traits/integral_constant.h> -#include <__cxx03/__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __is_identity : false_type {}; - -struct __identity { - template - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _Tp&& operator()(_Tp&& __t) const _NOEXCEPT { - return std::forward<_Tp>(__t); - } - - using is_transparent = void; -}; - -template <> -struct __is_identity<__identity> : true_type {}; -template <> -struct __is_identity > : true_type {}; -template <> -struct __is_identity > : true_type {}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_IDENTITY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fn.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fn.h deleted file mode 100644 index fb9ffcf..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fn.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_MEM_FN_H -#define _LIBCPP___CXX03___FUNCTIONAL_MEM_FN_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/binary_function.h> -#include <__cxx03/__functional/weak_result_type.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __mem_fn : public __weak_result_type<_Tp> { -public: - // types - typedef _Tp type; - -private: - type __f_; - -public: - _LIBCPP_HIDE_FROM_ABI __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} - - // invoke - template - _LIBCPP_HIDE_FROM_ABI typename __invoke_return::type operator()(_ArgTypes&&... __args) const { - return std::__invoke(__f_, std::forward<_ArgTypes>(__args)...); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI __mem_fn<_Rp _Tp::*> mem_fn(_Rp _Tp::* __pm) _NOEXCEPT { - return __mem_fn<_Rp _Tp::*>(__pm); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_MEM_FN_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fun_ref.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fun_ref.h deleted file mode 100644 index 81497e9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/mem_fun_ref.h +++ /dev/null @@ -1,137 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_MEM_FUN_REF_H -#define _LIBCPP___CXX03___FUNCTIONAL_MEM_FUN_REF_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/binary_function.h> -#include <__cxx03/__functional/unary_function.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS mem_fun_t : public __unary_function<_Tp*, _Sp> { - _Sp (_Tp::*__p_)(); - -public: - _LIBCPP_HIDE_FROM_ABI explicit mem_fun_t(_Sp (_Tp::*__p)()) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp* __p) const { return (__p->*__p_)(); } -}; - -template -class _LIBCPP_TEMPLATE_VIS mem_fun1_t : public __binary_function<_Tp*, _Ap, _Sp> { - _Sp (_Tp::*__p_)(_Ap); - -public: - _LIBCPP_HIDE_FROM_ABI explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp* __p, _Ap __x) const { return (__p->*__p_)(__x); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI mem_fun_t<_Sp, _Tp> mem_fun(_Sp (_Tp::*__f)()) { - return mem_fun_t<_Sp, _Tp>(__f); -} - -template -inline _LIBCPP_HIDE_FROM_ABI mem_fun1_t<_Sp, _Tp, _Ap> mem_fun(_Sp (_Tp::*__f)(_Ap)) { - return mem_fun1_t<_Sp, _Tp, _Ap>(__f); -} - -template -class _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public __unary_function<_Tp, _Sp> { - _Sp (_Tp::*__p_)(); - -public: - _LIBCPP_HIDE_FROM_ABI explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp& __p) const { return (__p.*__p_)(); } -}; - -template -class _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> { - _Sp (_Tp::*__p_)(_Ap); - -public: - _LIBCPP_HIDE_FROM_ABI explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(_Tp& __p, _Ap __x) const { return (__p.*__p_)(__x); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI mem_fun_ref_t<_Sp, _Tp> mem_fun_ref(_Sp (_Tp::*__f)()) { - return mem_fun_ref_t<_Sp, _Tp>(__f); -} - -template -inline _LIBCPP_HIDE_FROM_ABI mem_fun1_ref_t<_Sp, _Tp, _Ap> mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) { - return mem_fun1_ref_t<_Sp, _Tp, _Ap>(__f); -} - -template -class _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public __unary_function { - _Sp (_Tp::*__p_)() const; - -public: - _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp* __p) const { return (__p->*__p_)(); } -}; - -template -class _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public __binary_function { - _Sp (_Tp::*__p_)(_Ap) const; - -public: - _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp* __p, _Ap __x) const { return (__p->*__p_)(__x); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI const_mem_fun_t<_Sp, _Tp> mem_fun(_Sp (_Tp::*__f)() const) { - return const_mem_fun_t<_Sp, _Tp>(__f); -} - -template -inline _LIBCPP_HIDE_FROM_ABI const_mem_fun1_t<_Sp, _Tp, _Ap> mem_fun(_Sp (_Tp::*__f)(_Ap) const) { - return const_mem_fun1_t<_Sp, _Tp, _Ap>(__f); -} - -template -class _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public __unary_function<_Tp, _Sp> { - _Sp (_Tp::*__p_)() const; - -public: - _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp& __p) const { return (__p.*__p_)(); } -}; - -template -class _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> { - _Sp (_Tp::*__p_)(_Ap) const; - -public: - _LIBCPP_HIDE_FROM_ABI explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) : __p_(__p) {} - _LIBCPP_HIDE_FROM_ABI _Sp operator()(const _Tp& __p, _Ap __x) const { return (__p.*__p_)(__x); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI const_mem_fun_ref_t<_Sp, _Tp> mem_fun_ref(_Sp (_Tp::*__f)() const) { - return const_mem_fun_ref_t<_Sp, _Tp>(__f); -} - -template -inline _LIBCPP_HIDE_FROM_ABI const_mem_fun1_ref_t<_Sp, _Tp, _Ap> mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) { - return const_mem_fun1_ref_t<_Sp, _Tp, _Ap>(__f); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_MEM_FUN_REF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/operations.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/operations.h deleted file mode 100644 index 83840a2..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/operations.h +++ /dev/null @@ -1,181 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H -#define _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/binary_function.h> -#include <__cxx03/__functional/unary_function.h> -#include <__cxx03/__type_traits/desugars_to.h> -#include <__cxx03/__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Arithmetic operations - -template -struct _LIBCPP_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus); - -// The non-transparent std::plus specialization is only equivalent to a raw plus -// operator when we don't perform an implicit conversion when calling it. -template -inline const bool __desugars_to_v<__plus_tag, plus<_Tp>, _Tp, _Tp> = true; - -template -inline const bool __desugars_to_v<__plus_tag, plus, _Tp, _Up> = true; - -template -struct _LIBCPP_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus); - -template -struct _LIBCPP_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies); - -template -struct _LIBCPP_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides); - -template -struct _LIBCPP_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus); - -template -struct _LIBCPP_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return -__x; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate); - -// Bitwise operations - -template -struct _LIBCPP_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x & __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and); - -template -struct _LIBCPP_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x | __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or); - -template -struct _LIBCPP_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp> { - typedef _Tp __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x ^ __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor); - -// Comparison operations - -template -struct _LIBCPP_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to); - -// The non-transparent std::equal_to specialization is only equivalent to a raw equality -// comparison when we don't perform an implicit conversion when calling it. -template -inline const bool __desugars_to_v<__equal_tag, equal_to<_Tp>, _Tp, _Tp> = true; - -// In the transparent case, we do not enforce that -template -inline const bool __desugars_to_v<__equal_tag, equal_to, _Tp, _Up> = true; - -template -struct _LIBCPP_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to); - -template -struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less); - -template -inline const bool __desugars_to_v<__less_tag, less<_Tp>, _Tp, _Tp> = true; - -template -struct _LIBCPP_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal); - -template -struct _LIBCPP_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal); - -template -struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater); - -// Logical operations - -template -struct _LIBCPP_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and); - -template -struct _LIBCPP_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x) const { return !__x; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not); - -template -struct _LIBCPP_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool> { - typedef bool __result_type; // used by valarray - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or); - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_binary_function.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_binary_function.h deleted file mode 100644 index 3fe2f4c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_binary_function.h +++ /dev/null @@ -1,38 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H -#define _LIBCPP___CXX03___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/binary_function.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS pointer_to_binary_function : public __binary_function<_Arg1, _Arg2, _Result> { - _Result (*__f_)(_Arg1, _Arg2); - -public: - _LIBCPP_HIDE_FROM_ABI explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) : __f_(__f) {} - _LIBCPP_HIDE_FROM_ABI _Result operator()(_Arg1 __x, _Arg2 __y) const { return __f_(__x, __y); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI pointer_to_binary_function<_Arg1, _Arg2, _Result> ptr_fun(_Result (*__f)(_Arg1, _Arg2)) { - return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__f); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_unary_function.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_unary_function.h deleted file mode 100644 index cf429b9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/pointer_to_unary_function.h +++ /dev/null @@ -1,38 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H -#define _LIBCPP___CXX03___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/unary_function.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS pointer_to_unary_function : public __unary_function<_Arg, _Result> { - _Result (*__f_)(_Arg); - -public: - _LIBCPP_HIDE_FROM_ABI explicit pointer_to_unary_function(_Result (*__f)(_Arg)) : __f_(__f) {} - _LIBCPP_HIDE_FROM_ABI _Result operator()(_Arg __x) const { return __f_(__x); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__f)(_Arg)) { - return pointer_to_unary_function<_Arg, _Result>(__f); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/reference_wrapper.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/reference_wrapper.h deleted file mode 100644 index bbe8544..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/reference_wrapper.h +++ /dev/null @@ -1,89 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_REFERENCE_WRAPPER_H -#define _LIBCPP___CXX03___FUNCTIONAL_REFERENCE_WRAPPER_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/weak_result_type.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_const.h> -#include <__cxx03/__type_traits/remove_cvref.h> -#include <__cxx03/__type_traits/void_t.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> { -public: - // types - typedef _Tp type; - -private: - type* __f_; - - static void __fun(_Tp&) _NOEXCEPT; - static void __fun(_Tp&&) = delete; // NOLINT(modernize-use-equals-delete) ; This is llvm.org/PR54276 - -public: - template ()))>, - __enable_if_t::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI reference_wrapper(_Up&& __u) { - type& __f = static_cast<_Up&&>(__u); - __f_ = std::addressof(__f); - } - - // access - _LIBCPP_HIDE_FROM_ABI operator type&() const _NOEXCEPT { return *__f_; } - _LIBCPP_HIDE_FROM_ABI type& get() const _NOEXCEPT { return *__f_; } - - // invoke - template - _LIBCPP_HIDE_FROM_ABI typename __invoke_of::type operator()(_ArgTypes&&... __args) const { - return std::__invoke(get(), std::forward<_ArgTypes>(__args)...); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI reference_wrapper<_Tp> ref(_Tp& __t) _NOEXCEPT { - return reference_wrapper<_Tp>(__t); -} - -template -inline _LIBCPP_HIDE_FROM_ABI reference_wrapper<_Tp> ref(reference_wrapper<_Tp> __t) _NOEXCEPT { - return __t; -} - -template -inline _LIBCPP_HIDE_FROM_ABI reference_wrapper cref(const _Tp& __t) _NOEXCEPT { - return reference_wrapper(__t); -} - -template -inline _LIBCPP_HIDE_FROM_ABI reference_wrapper cref(reference_wrapper<_Tp> __t) _NOEXCEPT { - return __t; -} - -template -void ref(const _Tp&&) = delete; -template -void cref(const _Tp&&) = delete; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_REFERENCE_WRAPPER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_function.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_function.h deleted file mode 100644 index 72193c8..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_function.h +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_UNARY_FUNCTION_H -#define _LIBCPP___CXX03___FUNCTIONAL_UNARY_FUNCTION_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS unary_function { - typedef _Arg argument_type; - typedef _Result result_type; -}; - -template -struct __unary_function_keep_layout_base { - using argument_type = _Arg; - using result_type = _Result; -}; - -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") -template -using __unary_function = unary_function<_Arg, _Result>; -_LIBCPP_DIAGNOSTIC_POP - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_UNARY_FUNCTION_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_negate.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_negate.h deleted file mode 100644 index 3591b8e..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/unary_negate.h +++ /dev/null @@ -1,38 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_UNARY_NEGATE_H -#define _LIBCPP___CXX03___FUNCTIONAL_UNARY_NEGATE_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/unary_function.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS unary_negate : public __unary_function { - _Predicate __pred_; - -public: - _LIBCPP_HIDE_FROM_ABI explicit unary_negate(const _Predicate& __pred) : __pred_(__pred) {} - _LIBCPP_HIDE_FROM_ABI bool operator()(const typename _Predicate::argument_type& __x) const { return !__pred_(__x); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI unary_negate<_Predicate> not1(const _Predicate& __pred) { - return unary_negate<_Predicate>(__pred); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_UNARY_NEGATE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__functional/weak_result_type.h b/third_party/libcxx/include/c++/v1/__cxx03/__functional/weak_result_type.h deleted file mode 100644 index e8c2c4d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__functional/weak_result_type.h +++ /dev/null @@ -1,209 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_WEAK_RESULT_TYPE_H -#define _LIBCPP___CXX03___FUNCTIONAL_WEAK_RESULT_TYPE_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/binary_function.h> -#include <__cxx03/__functional/unary_function.h> -#include <__cxx03/__type_traits/integral_constant.h> -#include <__cxx03/__type_traits/invoke.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__utility/declval.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __has_result_type { -private: - template - static false_type __test(...); - template - static true_type __test(typename _Up::result_type* = 0); - -public: - static const bool value = decltype(__test<_Tp>(0))::value; -}; - -// __weak_result_type - -template -struct __derives_from_unary_function { -private: - struct __two { - char __lx; - char __lxx; - }; - static __two __test(...); - template - static __unary_function<_Ap, _Rp> __test(const volatile __unary_function<_Ap, _Rp>*); - -public: - static const bool value = !is_same::value; - typedef decltype(__test((_Tp*)0)) type; -}; - -template -struct __derives_from_binary_function { -private: - struct __two { - char __lx; - char __lxx; - }; - static __two __test(...); - template - static __binary_function<_A1, _A2, _Rp> __test(const volatile __binary_function<_A1, _A2, _Rp>*); - -public: - static const bool value = !is_same::value; - typedef decltype(__test((_Tp*)0)) type; -}; - -template ::value> -struct __maybe_derive_from_unary_function // bool is true - : public __derives_from_unary_function<_Tp>::type {}; - -template -struct __maybe_derive_from_unary_function<_Tp, false> {}; - -template ::value> -struct __maybe_derive_from_binary_function // bool is true - : public __derives_from_binary_function<_Tp>::type {}; - -template -struct __maybe_derive_from_binary_function<_Tp, false> {}; - -template ::value> -struct __weak_result_type_imp // bool is true - : public __maybe_derive_from_unary_function<_Tp>, - public __maybe_derive_from_binary_function<_Tp> { - using result_type _LIBCPP_NODEBUG = typename _Tp::result_type; -}; - -template -struct __weak_result_type_imp<_Tp, false> - : public __maybe_derive_from_unary_function<_Tp>, public __maybe_derive_from_binary_function<_Tp> {}; - -template -struct __weak_result_type : public __weak_result_type_imp<_Tp> {}; - -// 0 argument case - -template -struct __weak_result_type<_Rp()> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (&)()> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (*)()> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -// 1 argument case - -template -struct __weak_result_type<_Rp(_A1)> : public __unary_function<_A1, _Rp> {}; - -template -struct __weak_result_type<_Rp (&)(_A1)> : public __unary_function<_A1, _Rp> {}; - -template -struct __weak_result_type<_Rp (*)(_A1)> : public __unary_function<_A1, _Rp> {}; - -template -struct __weak_result_type<_Rp (_Cp::*)()> : public __unary_function<_Cp*, _Rp> {}; - -template -struct __weak_result_type<_Rp (_Cp::*)() const> : public __unary_function {}; - -template -struct __weak_result_type<_Rp (_Cp::*)() volatile> : public __unary_function {}; - -template -struct __weak_result_type<_Rp (_Cp::*)() const volatile> : public __unary_function {}; - -// 2 argument case - -template -struct __weak_result_type<_Rp(_A1, _A2)> : public __binary_function<_A1, _A2, _Rp> {}; - -template -struct __weak_result_type<_Rp (*)(_A1, _A2)> : public __binary_function<_A1, _A2, _Rp> {}; - -template -struct __weak_result_type<_Rp (&)(_A1, _A2)> : public __binary_function<_A1, _A2, _Rp> {}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1)> : public __binary_function<_Cp*, _A1, _Rp> {}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1) const> : public __binary_function {}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile> : public __binary_function {}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> : public __binary_function { -}; - -// 3 or more arguments - -template -struct __weak_result_type<_Rp(_A1, _A2, _A3, _A4...)> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> { - using result_type _LIBCPP_NODEBUG = _Rp; -}; - -template -struct __invoke_return { - typedef decltype(std::__invoke(std::declval<_Tp>(), std::declval<_Args>()...)) type; -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_WEAK_RESULT_TYPE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/array.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/array.h deleted file mode 100644 index 101faf8..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/array.h +++ /dev/null @@ -1,38 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_ARRAY_H -#define _LIBCPP___CXX03___FWD_ARRAY_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS array; - -template -_LIBCPP_HIDE_FROM_ABI _Tp& get(array<_Tp, _Size>&) _NOEXCEPT; - -template -_LIBCPP_HIDE_FROM_ABI const _Tp& get(const array<_Tp, _Size>&) _NOEXCEPT; - -template -struct __is_std_array : false_type {}; - -template -struct __is_std_array > : true_type {}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_ARRAY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/bit_reference.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/bit_reference.h deleted file mode 100644 index e04a47f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/bit_reference.h +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_BIT_REFERENCE_H -#define _LIBCPP___CXX03___FWD_BIT_REFERENCE_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __bit_iterator; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_BIT_REFERENCE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/complex.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/complex.h deleted file mode 100644 index 0959f94..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/complex.h +++ /dev/null @@ -1,26 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_COMPLEX_H -#define _LIBCPP___CXX03___FWD_COMPLEX_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS complex; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_COMPLEX_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/deque.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/deque.h deleted file mode 100644 index 7d1c6f7..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/deque.h +++ /dev/null @@ -1,26 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_DEQUE_H -#define _LIBCPP___CXX03___FWD_DEQUE_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/memory.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS deque; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_DEQUE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/fstream.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/fstream.h deleted file mode 100644 index 8cc5d2b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/fstream.h +++ /dev/null @@ -1,53 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_FSTREAM_H -#define _LIBCPP___CXX03___FWD_FSTREAM_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/string.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS basic_filebuf; -template > -class _LIBCPP_TEMPLATE_VIS basic_ifstream; -template > -class _LIBCPP_TEMPLATE_VIS basic_ofstream; -template > -class _LIBCPP_TEMPLATE_VIS basic_fstream; - -using filebuf = basic_filebuf; -using ifstream = basic_ifstream; -using ofstream = basic_ofstream; -using fstream = basic_fstream; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wfilebuf = basic_filebuf; -using wifstream = basic_ifstream; -using wofstream = basic_ofstream; -using wfstream = basic_fstream; -#endif - -template -class _LIBCPP_PREFERRED_NAME(filebuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfilebuf)) basic_filebuf; -template -class _LIBCPP_PREFERRED_NAME(ifstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wifstream)) basic_ifstream; -template -class _LIBCPP_PREFERRED_NAME(ofstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wofstream)) basic_ofstream; -template -class _LIBCPP_PREFERRED_NAME(fstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfstream)) basic_fstream; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_FSTREAM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/functional.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/functional.h deleted file mode 100644 index 924874c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/functional.h +++ /dev/null @@ -1,28 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_FUNCTIONAL_H -#define _LIBCPP___CXX03___FWD_FUNCTIONAL_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS hash; - -template -class _LIBCPP_TEMPLATE_VIS reference_wrapper; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_FUNCTIONAL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/ios.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/ios.h deleted file mode 100644 index 3b33b25..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/ios.h +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_IOS_H -#define _LIBCPP___CXX03___FWD_IOS_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/string.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -class _LIBCPP_EXPORTED_FROM_ABI ios_base; - -template > -class _LIBCPP_TEMPLATE_VIS basic_ios; - -using ios = basic_ios; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wios = basic_ios; -#endif - -template -class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wios)) basic_ios; - -#if _LIBCPP_LIBC_NEWLIB -// On newlib, off_t is 'long int' -using streamoff = long int; // for char_traits in -#else -using streamoff = long long; // for char_traits in -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_IOS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/istream.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/istream.h deleted file mode 100644 index f3edc78..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/istream.h +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_ISTREAM_H -#define _LIBCPP___CXX03___FWD_ISTREAM_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/string.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS basic_istream; - -template > -class _LIBCPP_TEMPLATE_VIS basic_iostream; - -using istream = basic_istream; -using iostream = basic_iostream; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wistream = basic_istream; -using wiostream = basic_iostream; -#endif - -template -class _LIBCPP_PREFERRED_NAME(istream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistream)) basic_istream; - -template -class _LIBCPP_PREFERRED_NAME(iostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wiostream)) basic_iostream; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_ISTREAM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/memory.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/memory.h deleted file mode 100644 index df76b17..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/memory.h +++ /dev/null @@ -1,25 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_MEMORY_H -#define _LIBCPP___CXX03___FWD_MEMORY_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS allocator; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_MEMORY_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/ostream.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/ostream.h deleted file mode 100644 index b5061e6..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/ostream.h +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_OSTREAM_H -#define _LIBCPP___CXX03___FWD_OSTREAM_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/string.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS basic_ostream; - -using ostream = basic_ostream; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wostream = basic_ostream; -#endif - -template -class _LIBCPP_PREFERRED_NAME(ostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostream)) basic_ostream; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_OSTREAM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/pair.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/pair.h deleted file mode 100644 index be2c862..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/pair.h +++ /dev/null @@ -1,33 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_PAIR_H -#define _LIBCPP___CXX03___FWD_PAIR_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/tuple.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS pair; - -template -_LIBCPP_HIDE_FROM_ABI typename tuple_element<_Ip, pair<_T1, _T2> >::type& get(pair<_T1, _T2>&) _NOEXCEPT; - -template -_LIBCPP_HIDE_FROM_ABI const typename tuple_element<_Ip, pair<_T1, _T2> >::type& get(const pair<_T1, _T2>&) _NOEXCEPT; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_PAIR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/queue.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/queue.h deleted file mode 100644 index c2f6808..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/queue.h +++ /dev/null @@ -1,31 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_QUEUE_H -#define _LIBCPP___CXX03___FWD_QUEUE_H - -#include <__cxx03/__config> -#include <__cxx03/__functional/operations.h> -#include <__cxx03/__fwd/deque.h> -#include <__cxx03/__fwd/vector.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS queue; - -template , class _Compare = less > -class _LIBCPP_TEMPLATE_VIS priority_queue; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_QUEUE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/sstream.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/sstream.h deleted file mode 100644 index 32ae42c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/sstream.h +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_SSTREAM_H -#define _LIBCPP___CXX03___FWD_SSTREAM_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/memory.h> -#include <__cxx03/__fwd/string.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template , class _Allocator = allocator<_CharT> > -class _LIBCPP_TEMPLATE_VIS basic_stringbuf; - -template , class _Allocator = allocator<_CharT> > -class _LIBCPP_TEMPLATE_VIS basic_istringstream; -template , class _Allocator = allocator<_CharT> > -class _LIBCPP_TEMPLATE_VIS basic_ostringstream; -template , class _Allocator = allocator<_CharT> > -class _LIBCPP_TEMPLATE_VIS basic_stringstream; - -using stringbuf = basic_stringbuf; -using istringstream = basic_istringstream; -using ostringstream = basic_ostringstream; -using stringstream = basic_stringstream; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wstringbuf = basic_stringbuf; -using wistringstream = basic_istringstream; -using wostringstream = basic_ostringstream; -using wstringstream = basic_stringstream; -#endif - -template -class _LIBCPP_PREFERRED_NAME(stringbuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringbuf)) basic_stringbuf; -template -class _LIBCPP_PREFERRED_NAME(istringstream) - _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistringstream)) basic_istringstream; -template -class _LIBCPP_PREFERRED_NAME(ostringstream) - _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostringstream)) basic_ostringstream; -template -class _LIBCPP_PREFERRED_NAME(stringstream) - _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringstream)) basic_stringstream; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_SSTREAM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/stack.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/stack.h deleted file mode 100644 index 715356e..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/stack.h +++ /dev/null @@ -1,26 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_STACK_H -#define _LIBCPP___CXX03___FWD_STACK_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/deque.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS stack; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_STACK_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/streambuf.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/streambuf.h deleted file mode 100644 index d22be50..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/streambuf.h +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_STREAMBUF_H -#define _LIBCPP___CXX03___FWD_STREAMBUF_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/string.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS basic_streambuf; - -using streambuf = basic_streambuf; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wstreambuf = basic_streambuf; -#endif - -template -class _LIBCPP_PREFERRED_NAME(streambuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstreambuf)) basic_streambuf; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_STREAMBUF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/string.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/string.h deleted file mode 100644 index c0da201..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/string.h +++ /dev/null @@ -1,73 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_STRING_H -#define _LIBCPP___CXX03___FWD_STRING_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/memory.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS char_traits; -template <> -struct char_traits; - -#ifndef _LIBCPP_HAS_NO_CHAR8_T -template <> -struct char_traits; -#endif - -template <> -struct char_traits; -template <> -struct char_traits; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -struct char_traits; -#endif - -template , class _Allocator = allocator<_CharT> > -class _LIBCPP_TEMPLATE_VIS basic_string; - -using string = basic_string; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wstring = basic_string; -#endif - -#ifndef _LIBCPP_HAS_NO_CHAR8_T -using u8string = basic_string; -#endif - -using u16string = basic_string; -using u32string = basic_string; - -// clang-format off -template -class _LIBCPP_PREFERRED_NAME(string) -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS - _LIBCPP_PREFERRED_NAME(wstring) -#endif -#ifndef _LIBCPP_HAS_NO_CHAR8_T - _LIBCPP_PREFERRED_NAME(u8string) -#endif - _LIBCPP_PREFERRED_NAME(u16string) - _LIBCPP_PREFERRED_NAME(u32string) - basic_string; -// clang-format on - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_STRING_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/string_view.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/string_view.h deleted file mode 100644 index 76c608b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/string_view.h +++ /dev/null @@ -1,50 +0,0 @@ -// -*- C++ -*- -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_STRING_VIEW_H -#define _LIBCPP___CXX03___FWD_STRING_VIEW_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/string.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS basic_string_view; - -typedef basic_string_view string_view; -#ifndef _LIBCPP_HAS_NO_CHAR8_T -typedef basic_string_view u8string_view; -#endif -typedef basic_string_view u16string_view; -typedef basic_string_view u32string_view; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -typedef basic_string_view wstring_view; -#endif - -// clang-format off -template -class _LIBCPP_PREFERRED_NAME(string_view) -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS - _LIBCPP_PREFERRED_NAME(wstring_view) -#endif -#ifndef _LIBCPP_HAS_NO_CHAR8_T - _LIBCPP_PREFERRED_NAME(u8string_view) -#endif - _LIBCPP_PREFERRED_NAME(u16string_view) - _LIBCPP_PREFERRED_NAME(u32string_view) - basic_string_view; -// clang-format on -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_STRING_VIEW_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/tuple.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/tuple.h deleted file mode 100644 index 55b46ee..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/tuple.h +++ /dev/null @@ -1,26 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_TUPLE_H -#define _LIBCPP___CXX03___FWD_TUPLE_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS tuple_element; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_TUPLE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/vector.h b/third_party/libcxx/include/c++/v1/__cxx03/__fwd/vector.h deleted file mode 100644 index 4133173..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__fwd/vector.h +++ /dev/null @@ -1,26 +0,0 @@ -//===---------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===---------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FWD_VECTOR_H -#define _LIBCPP___CXX03___FWD_VECTOR_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/memory.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template > -class _LIBCPP_TEMPLATE_VIS vector; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FWD_VECTOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__hash_table b/third_party/libcxx/include/c++/v1/__cxx03/__hash_table deleted file mode 100644 index 30c0fbf..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__hash_table +++ /dev/null @@ -1,1842 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___HASH_TABLE -#define _LIBCPP___CXX03___HASH_TABLE - -#include <__cxx03/__algorithm/max.h> -#include <__cxx03/__algorithm/min.h> -#include <__cxx03/__assert> -#include <__cxx03/__bit/countl.h> -#include <__cxx03/__config> -#include <__cxx03/__functional/hash.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__memory/allocator_traits.h> -#include <__cxx03/__memory/compressed_pair.h> -#include <__cxx03/__memory/construct_at.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__memory/swap_allocator.h> -#include <__cxx03/__memory/unique_ptr.h> -#include <__cxx03/__type_traits/can_extract_key.h> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__type_traits/is_const.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__type_traits/is_nothrow_assignable.h> -#include <__cxx03/__type_traits/is_nothrow_constructible.h> -#include <__cxx03/__type_traits/is_pointer.h> -#include <__cxx03/__type_traits/is_reference.h> -#include <__cxx03/__type_traits/is_swappable.h> -#include <__cxx03/__type_traits/remove_const.h> -#include <__cxx03/__type_traits/remove_cvref.h> -#include <__cxx03/__utility/forward.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/__utility/swap.h> -#include <__cxx03/cmath> -#include <__cxx03/cstring> -#include <__cxx03/new> // __launder - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __hash_value_type; - -template -struct __is_hash_value_type_imp : false_type {}; - -template -struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value> > : true_type {}; - -template -struct __is_hash_value_type : false_type {}; - -template -struct __is_hash_value_type<_One> : __is_hash_value_type_imp<__remove_cvref_t<_One> > {}; - -_LIBCPP_EXPORTED_FROM_ABI size_t __next_prime(size_t __n); - -template -struct __hash_node_base { - typedef typename pointer_traits<_NodePtr>::element_type __node_type; - typedef __hash_node_base __first_node; - typedef __rebind_pointer_t<_NodePtr, __first_node> __node_base_pointer; - typedef _NodePtr __node_pointer; - -#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) - typedef __node_base_pointer __next_pointer; -#else - typedef __conditional_t::value, __node_base_pointer, __node_pointer> __next_pointer; -#endif - - __next_pointer __next_; - - _LIBCPP_HIDE_FROM_ABI __next_pointer __ptr() _NOEXCEPT { - return static_cast<__next_pointer>(pointer_traits<__node_base_pointer>::pointer_to(*this)); - } - - _LIBCPP_HIDE_FROM_ABI __node_pointer __upcast() _NOEXCEPT { - return static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(*this)); - } - - _LIBCPP_HIDE_FROM_ABI size_t __hash() const _NOEXCEPT { return static_cast<__node_type const&>(*this).__hash_; } - - _LIBCPP_HIDE_FROM_ABI __hash_node_base() _NOEXCEPT : __next_(nullptr) {} - _LIBCPP_HIDE_FROM_ABI explicit __hash_node_base(__next_pointer __next) _NOEXCEPT : __next_(__next) {} -}; - -template -struct __hash_node : public __hash_node_base< __rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > > { - typedef _Tp __node_value_type; - using _Base = __hash_node_base<__rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > >; - using __next_pointer = typename _Base::__next_pointer; - - size_t __hash_; - - // We allow starting the lifetime of nodes without initializing the value held by the node, - // since that is handled by the hash table itself in order to be allocator-aware. - -private: - _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)]; - -public: - _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); } - - _LIBCPP_HIDE_FROM_ABI explicit __hash_node(__next_pointer __next, size_t __hash) : _Base(__next), __hash_(__hash) {} - _LIBCPP_HIDE_FROM_ABI ~__hash_node() {} -}; - -inline _LIBCPP_HIDE_FROM_ABI bool __is_hash_power2(size_t __bc) { return __bc > 2 && !(__bc & (__bc - 1)); } - -inline _LIBCPP_HIDE_FROM_ABI size_t __constrain_hash(size_t __h, size_t __bc) { - return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : (__h < __bc ? __h : __h % __bc); -} - -inline _LIBCPP_HIDE_FROM_ABI size_t __next_hash_pow2(size_t __n) { - return __n < 2 ? __n : (size_t(1) << (numeric_limits::digits - __libcpp_clz(__n - 1))); -} - -template -class __hash_table; - -template -class _LIBCPP_TEMPLATE_VIS __hash_iterator; -template -class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; -template -class _LIBCPP_TEMPLATE_VIS __hash_local_iterator; -template -class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; -template -class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; -template -class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; - -template -struct __hash_key_value_types { - static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, ""); - typedef _Tp key_type; - typedef _Tp __node_value_type; - typedef _Tp __container_value_type; - static const bool __is_map = false; - - _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(_Tp const& __v) { return __v; } - _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; } - _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) { return std::addressof(__n); } - _LIBCPP_HIDE_FROM_ABI static __container_value_type&& __move(__node_value_type& __v) { return std::move(__v); } -}; - -template -struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { - typedef _Key key_type; - typedef _Tp mapped_type; - typedef __hash_value_type<_Key, _Tp> __node_value_type; - typedef pair __container_value_type; - typedef __container_value_type __map_value_type; - static const bool __is_map = true; - - _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(__container_value_type const& __v) { return __v.first; } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) { - return __t.__get_value(); - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) { - return __t; - } - - _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) { - return std::addressof(__n.__get_value()); - } - _LIBCPP_HIDE_FROM_ABI static pair __move(__node_value_type& __v) { return __v.__move(); } -}; - -template , bool = _KVTypes::__is_map> -struct __hash_map_pointer_types {}; - -template -struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { - typedef typename _KVTypes::__map_value_type _Mv; - typedef __rebind_pointer_t<_AllocPtr, _Mv> __map_value_type_pointer; - typedef __rebind_pointer_t<_AllocPtr, const _Mv> __const_map_value_type_pointer; -}; - -template ::element_type> -struct __hash_node_types; - -template -struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> > - : public __hash_key_value_types<_Tp>, - __hash_map_pointer_types<_Tp, _VoidPtr> - -{ - typedef __hash_key_value_types<_Tp> __base; - -public: - typedef ptrdiff_t difference_type; - typedef size_t size_type; - - typedef __rebind_pointer_t<_NodePtr, void> __void_pointer; - - typedef typename pointer_traits<_NodePtr>::element_type __node_type; - typedef _NodePtr __node_pointer; - - typedef __hash_node_base<__node_pointer> __node_base_type; - typedef __rebind_pointer_t<_NodePtr, __node_base_type> __node_base_pointer; - - typedef typename __node_base_type::__next_pointer __next_pointer; - - typedef _Tp __node_value_type; - typedef __rebind_pointer_t<_VoidPtr, __node_value_type> __node_value_type_pointer; - typedef __rebind_pointer_t<_VoidPtr, const __node_value_type> __const_node_value_type_pointer; - -private: - static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const"); - static_assert(is_same::element_type, void>::value, - "_VoidPtr does not point to unqualified void type"); - static_assert(is_same<__rebind_pointer_t<_VoidPtr, __node_type>, _NodePtr>::value, - "_VoidPtr does not rebind to _NodePtr."); -}; - -template -struct __hash_node_types_from_iterator; -template -struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; -template -struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; -template -struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; -template -struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; - -template -struct __make_hash_node_types { - typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; - typedef __rebind_pointer_t<_VoidPtr, _NodeTp> _NodePtr; - typedef __hash_node_types<_NodePtr> type; -}; - -template -class _LIBCPP_TEMPLATE_VIS __hash_iterator { - typedef __hash_node_types<_NodePtr> _NodeTypes; - typedef _NodePtr __node_pointer; - typedef typename _NodeTypes::__next_pointer __next_pointer; - - __next_pointer __node_; - -public: - typedef forward_iterator_tag iterator_category; - typedef typename _NodeTypes::__node_value_type value_type; - typedef typename _NodeTypes::difference_type difference_type; - typedef value_type& reference; - typedef typename _NodeTypes::__node_value_type_pointer pointer; - - _LIBCPP_HIDE_FROM_ABI __hash_iterator() _NOEXCEPT : __node_(nullptr) {} - - _LIBCPP_HIDE_FROM_ABI reference operator*() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container iterator"); - return __node_->__upcast()->__get_value(); - } - - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container iterator"); - return pointer_traits::pointer_to(__node_->__upcast()->__get_value()); - } - - _LIBCPP_HIDE_FROM_ABI __hash_iterator& operator++() { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to increment a non-incrementable unordered container iterator"); - __node_ = __node_->__next_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __hash_iterator operator++(int) { - __hash_iterator __t(*this); - ++(*this); - return __t; - } - - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) { - return __x.__node_ == __y.__node_; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) { - return !(__x == __y); - } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __hash_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} - - template - friend class __hash_table; - template - friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; - template - friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; - template - friend class _LIBCPP_TEMPLATE_VIS unordered_map; - template - friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; -}; - -template -class _LIBCPP_TEMPLATE_VIS __hash_const_iterator { - static_assert(!is_const::element_type>::value, ""); - typedef __hash_node_types<_NodePtr> _NodeTypes; - typedef _NodePtr __node_pointer; - typedef typename _NodeTypes::__next_pointer __next_pointer; - - __next_pointer __node_; - -public: - typedef __hash_iterator<_NodePtr> __non_const_iterator; - - typedef forward_iterator_tag iterator_category; - typedef typename _NodeTypes::__node_value_type value_type; - typedef typename _NodeTypes::difference_type difference_type; - typedef const value_type& reference; - typedef typename _NodeTypes::__const_node_value_type_pointer pointer; - - _LIBCPP_HIDE_FROM_ABI __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {} - - _LIBCPP_HIDE_FROM_ABI __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT : __node_(__x.__node_) {} - - _LIBCPP_HIDE_FROM_ABI reference operator*() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_iterator"); - return __node_->__upcast()->__get_value(); - } - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_iterator"); - return pointer_traits::pointer_to(__node_->__upcast()->__get_value()); - } - - _LIBCPP_HIDE_FROM_ABI __hash_const_iterator& operator++() { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to increment a non-incrementable unordered container const_iterator"); - __node_ = __node_->__next_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __hash_const_iterator operator++(int) { - __hash_const_iterator __t(*this); - ++(*this); - return __t; - } - - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) { - return __x.__node_ == __y.__node_; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) { - return !(__x == __y); - } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __hash_const_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} - - template - friend class __hash_table; - template - friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; - template - friend class _LIBCPP_TEMPLATE_VIS unordered_map; - template - friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; -}; - -template -class _LIBCPP_TEMPLATE_VIS __hash_local_iterator { - typedef __hash_node_types<_NodePtr> _NodeTypes; - typedef _NodePtr __node_pointer; - typedef typename _NodeTypes::__next_pointer __next_pointer; - - __next_pointer __node_; - size_t __bucket_; - size_t __bucket_count_; - -public: - typedef forward_iterator_tag iterator_category; - typedef typename _NodeTypes::__node_value_type value_type; - typedef typename _NodeTypes::difference_type difference_type; - typedef value_type& reference; - typedef typename _NodeTypes::__node_value_type_pointer pointer; - - _LIBCPP_HIDE_FROM_ABI __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {} - - _LIBCPP_HIDE_FROM_ABI reference operator*() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container local_iterator"); - return __node_->__upcast()->__get_value(); - } - - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container local_iterator"); - return pointer_traits::pointer_to(__node_->__upcast()->__get_value()); - } - - _LIBCPP_HIDE_FROM_ABI __hash_local_iterator& operator++() { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to increment a non-incrementable unordered container local_iterator"); - __node_ = __node_->__next_; - if (__node_ != nullptr && std::__constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) - __node_ = nullptr; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __hash_local_iterator operator++(int) { - __hash_local_iterator __t(*this); - ++(*this); - return __t; - } - - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) { - return __x.__node_ == __y.__node_; - } - friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) { - return !(__x == __y); - } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __hash_local_iterator( - __next_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT - : __node_(__node), - __bucket_(__bucket), - __bucket_count_(__bucket_count) { - if (__node_ != nullptr) - __node_ = __node_->__next_; - } - - template - friend class __hash_table; - template - friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; - template - friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; -}; - -template -class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator { - typedef __hash_node_types<_ConstNodePtr> _NodeTypes; - typedef _ConstNodePtr __node_pointer; - typedef typename _NodeTypes::__next_pointer __next_pointer; - - __next_pointer __node_; - size_t __bucket_; - size_t __bucket_count_; - - typedef pointer_traits<__node_pointer> __pointer_traits; - typedef typename __pointer_traits::element_type __node; - typedef __remove_const_t<__node> __non_const_node; - typedef __rebind_pointer_t<__node_pointer, __non_const_node> __non_const_node_pointer; - -public: - typedef __hash_local_iterator<__non_const_node_pointer> __non_const_iterator; - - typedef forward_iterator_tag iterator_category; - typedef typename _NodeTypes::__node_value_type value_type; - typedef typename _NodeTypes::difference_type difference_type; - typedef const value_type& reference; - typedef typename _NodeTypes::__const_node_value_type_pointer pointer; - - _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {} - - _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT - : __node_(__x.__node_), - __bucket_(__x.__bucket_), - __bucket_count_(__x.__bucket_count_) {} - - _LIBCPP_HIDE_FROM_ABI reference operator*() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); - return __node_->__upcast()->__get_value(); - } - - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); - return pointer_traits::pointer_to(__node_->__upcast()->__get_value()); - } - - _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator& operator++() { - _LIBCPP_ASSERT_NON_NULL( - __node_ != nullptr, "Attempted to increment a non-incrementable unordered container const_local_iterator"); - __node_ = __node_->__next_; - if (__node_ != nullptr && std::__constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) - __node_ = nullptr; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator operator++(int) { - __hash_const_local_iterator __t(*this); - ++(*this); - return __t; - } - - friend _LIBCPP_HIDE_FROM_ABI bool - operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) { - return __x.__node_ == __y.__node_; - } - friend _LIBCPP_HIDE_FROM_ABI bool - operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) { - return !(__x == __y); - } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __hash_const_local_iterator( - __next_pointer __node_ptr, size_t __bucket, size_t __bucket_count) _NOEXCEPT - : __node_(__node_ptr), - __bucket_(__bucket), - __bucket_count_(__bucket_count) { - if (__node_ != nullptr) - __node_ = __node_->__next_; - } - - template - friend class __hash_table; - template - friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; -}; - -template -class __bucket_list_deallocator { - typedef _Alloc allocator_type; - typedef allocator_traits __alloc_traits; - typedef typename __alloc_traits::size_type size_type; - - __compressed_pair __data_; - -public: - typedef typename __alloc_traits::pointer pointer; - - _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator() : __data_(0, __default_init_tag()) {} - - _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(const allocator_type& __a, size_type __size) : __data_(__size, __a) {} - - _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(__bucket_list_deallocator&& __x) : __data_(std::move(__x.__data_)) { - __x.size() = 0; - } - - _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __data_.first(); } - _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __data_.first(); } - - _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __data_.second(); } - _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __data_.second(); } - - _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc(), __p, size()); } -}; - -template -class __hash_map_node_destructor; - -template -class __hash_node_destructor { - typedef _Alloc allocator_type; - typedef allocator_traits __alloc_traits; - -public: - typedef typename __alloc_traits::pointer pointer; - -private: - typedef __hash_node_types _NodeTypes; - - allocator_type& __na_; - -public: - bool __value_constructed; - - _LIBCPP_HIDE_FROM_ABI __hash_node_destructor(__hash_node_destructor const&) = default; - _LIBCPP_HIDE_FROM_ABI __hash_node_destructor& operator=(const __hash_node_destructor&) = delete; - - _LIBCPP_HIDE_FROM_ABI explicit __hash_node_destructor(allocator_type& __na, bool __constructed = false) _NOEXCEPT - : __na_(__na), - __value_constructed(__constructed) {} - - _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { - if (__value_constructed) { - __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__get_value())); - std::__destroy_at(std::addressof(*__p)); - } - if (__p) - __alloc_traits::deallocate(__na_, __p, 1); - } - - template - friend class __hash_map_node_destructor; -}; - -template -struct __enforce_unordered_container_requirements { - typedef int type; -}; - -template -typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type -__diagnose_unordered_container_requirements(int); - -// This dummy overload is used so that the compiler won't emit a spurious -// "no matching function for call to __diagnose_unordered_xxx" diagnostic -// when the overload above causes a hard error. -template -int __diagnose_unordered_container_requirements(void*); - -template -class __hash_table { -public: - typedef _Tp value_type; - typedef _Hash hasher; - typedef _Equal key_equal; - typedef _Alloc allocator_type; - -private: - typedef allocator_traits __alloc_traits; - typedef typename __make_hash_node_types::type _NodeTypes; - -public: - typedef typename _NodeTypes::__node_value_type __node_value_type; - typedef typename _NodeTypes::__container_value_type __container_value_type; - typedef typename _NodeTypes::key_type key_type; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef typename __alloc_traits::pointer pointer; - typedef typename __alloc_traits::const_pointer const_pointer; -#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE - typedef typename __alloc_traits::size_type size_type; -#else - typedef typename _NodeTypes::size_type size_type; -#endif - typedef typename _NodeTypes::difference_type difference_type; - -public: - // Create __node - - typedef typename _NodeTypes::__node_type __node; - typedef __rebind_alloc<__alloc_traits, __node> __node_allocator; - typedef allocator_traits<__node_allocator> __node_traits; - typedef typename _NodeTypes::__void_pointer __void_pointer; - typedef typename _NodeTypes::__node_pointer __node_pointer; - typedef typename _NodeTypes::__node_pointer __node_const_pointer; - typedef typename _NodeTypes::__node_base_type __first_node; - typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; - typedef typename _NodeTypes::__next_pointer __next_pointer; - -private: - // check for sane allocator pointer rebinding semantics. Rebinding the - // allocator for a new pointer type should be exactly the same as rebinding - // the pointer using 'pointer_traits'. - static_assert(is_same<__node_pointer, typename __node_traits::pointer>::value, - "Allocator does not rebind pointers in a sane manner."); - typedef __rebind_alloc<__node_traits, __first_node> __node_base_allocator; - typedef allocator_traits<__node_base_allocator> __node_base_traits; - static_assert(is_same<__node_base_pointer, typename __node_base_traits::pointer>::value, - "Allocator does not rebind pointers in a sane manner."); - -private: - typedef __rebind_alloc<__node_traits, __next_pointer> __pointer_allocator; - typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; - typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; - typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; - typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; - - // --- Member data begin --- - __bucket_list __bucket_list_; - __compressed_pair<__first_node, __node_allocator> __p1_; - __compressed_pair __p2_; - __compressed_pair __p3_; - // --- Member data end --- - - _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __p2_.first(); } - -public: - _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __p2_.first(); } - - _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __p2_.second(); } - _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __p2_.second(); } - - _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __p3_.first(); } - _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __p3_.first(); } - - _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __p3_.second(); } - _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __p3_.second(); } - - _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __p1_.second(); } - _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __p1_.second(); } - -public: - typedef __hash_iterator<__node_pointer> iterator; - typedef __hash_const_iterator<__node_pointer> const_iterator; - typedef __hash_local_iterator<__node_pointer> local_iterator; - typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; - - _LIBCPP_HIDE_FROM_ABI __hash_table(); - _LIBCPP_HIDE_FROM_ABI __hash_table(const hasher& __hf, const key_equal& __eql); - _LIBCPP_HIDE_FROM_ABI __hash_table(const hasher& __hf, const key_equal& __eql, const allocator_type& __a); - _LIBCPP_HIDE_FROM_ABI explicit __hash_table(const allocator_type& __a); - _LIBCPP_HIDE_FROM_ABI __hash_table(const __hash_table& __u); - _LIBCPP_HIDE_FROM_ABI __hash_table(const __hash_table& __u, const allocator_type& __a); - _LIBCPP_HIDE_FROM_ABI __hash_table(__hash_table&& __u); - _LIBCPP_HIDE_FROM_ABI __hash_table(__hash_table&& __u, const allocator_type& __a); - _LIBCPP_HIDE_FROM_ABI ~__hash_table(); - - _LIBCPP_HIDE_FROM_ABI __hash_table& operator=(const __hash_table& __u); - _LIBCPP_HIDE_FROM_ABI __hash_table& operator=(__hash_table&& __u); - template - _LIBCPP_HIDE_FROM_ABI void __assign_unique(_InputIterator __first, _InputIterator __last); - template - _LIBCPP_HIDE_FROM_ABI void __assign_multi(_InputIterator __first, _InputIterator __last); - - _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { - return std::min(__node_traits::max_size(__node_alloc()), numeric_limits::max()); - } - -private: - _LIBCPP_HIDE_FROM_ABI __next_pointer __node_insert_multi_prepare(size_t __cp_hash, value_type& __cp_val); - _LIBCPP_HIDE_FROM_ABI void __node_insert_multi_perform(__node_pointer __cp, __next_pointer __pn) _NOEXCEPT; - - _LIBCPP_HIDE_FROM_ABI __next_pointer __node_insert_unique_prepare(size_t __nd_hash, value_type& __nd_val); - _LIBCPP_HIDE_FROM_ABI void __node_insert_unique_perform(__node_pointer __ptr) _NOEXCEPT; - -public: - _LIBCPP_HIDE_FROM_ABI pair __node_insert_unique(__node_pointer __nd); - _LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(__node_pointer __nd); - _LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); - - template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique_key_args(_Key const& __k, _Args&&... __args); - - template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique_impl(_Args&&... __args); - - template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique(_Pp&& __x) { - return __emplace_unique_extract_key(std::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>()); - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique(_First&& __f, _Second&& __s) { - return __emplace_unique_key_args(__f, std::forward<_First>(__f), std::forward<_Second>(__s)); - } - - template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique(_Args&&... __args) { - return __emplace_unique_impl(std::forward<_Args>(__args)...); - } - - template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { - return __emplace_unique_impl(std::forward<_Pp>(__x)); - } - template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { - return __emplace_unique_key_args(__x, std::forward<_Pp>(__x)); - } - template - _LIBCPP_HIDE_FROM_ABI pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { - return __emplace_unique_key_args(__x.first, std::forward<_Pp>(__x)); - } - - template - _LIBCPP_HIDE_FROM_ABI iterator __emplace_multi(_Args&&... __args); - template - _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); - - _LIBCPP_HIDE_FROM_ABI pair __insert_unique(__container_value_type&& __x) { - return __emplace_unique_key_args(_NodeTypes::__get_key(__x), std::move(__x)); - } - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI pair __insert_unique(_Pp&& __x) { - return __emplace_unique(std::forward<_Pp>(__x)); - } - - template - _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(_Pp&& __x) { - return __emplace_multi(std::forward<_Pp>(__x)); - } - - template - _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, _Pp&& __x) { - return __emplace_hint_multi(__p, std::forward<_Pp>(__x)); - } - - _LIBCPP_HIDE_FROM_ABI pair __insert_unique(const __container_value_type& __x) { - return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); - } - - _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI void __rehash_unique(size_type __n) { __rehash(__n); } - _LIBCPP_HIDE_FROM_ABI void __rehash_multi(size_type __n) { __rehash(__n); } - _LIBCPP_HIDE_FROM_ABI void __reserve_unique(size_type __n) { - __rehash_unique(static_cast(std::ceil(__n / max_load_factor()))); - } - _LIBCPP_HIDE_FROM_ABI void __reserve_multi(size_type __n) { - __rehash_multi(static_cast(std::ceil(__n / max_load_factor()))); - } - - _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __bucket_list_.get_deleter().size(); } - - _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT; - - template - _LIBCPP_HIDE_FROM_ABI size_type bucket(const _Key& __k) const { - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( - bucket_count() > 0, "unordered container::bucket(key) called when bucket_count() == 0"); - return std::__constrain_hash(hash_function()(__k), bucket_count()); - } - - template - _LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __x); - template - _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Key& __x) const; - - typedef __hash_node_destructor<__node_allocator> _Dp; - typedef unique_ptr<__node, _Dp> __node_holder; - - _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p); - _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last); - template - _LIBCPP_HIDE_FROM_ABI size_type __erase_unique(const _Key& __k); - template - _LIBCPP_HIDE_FROM_ABI size_type __erase_multi(const _Key& __k); - _LIBCPP_HIDE_FROM_ABI __node_holder remove(const_iterator __p) _NOEXCEPT; - - template - _LIBCPP_HIDE_FROM_ABI size_type __count_unique(const _Key& __k) const; - template - _LIBCPP_HIDE_FROM_ABI size_type __count_multi(const _Key& __k) const; - - template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_unique(const _Key& __k); - template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_unique(const _Key& __k) const; - - template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_multi(const _Key& __k); - template - _LIBCPP_HIDE_FROM_ABI pair __equal_range_multi(const _Key& __k) const; - - _LIBCPP_HIDE_FROM_ABI void swap(__hash_table& __u); - - _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const _NOEXCEPT { return max_size(); } - _LIBCPP_HIDE_FROM_ABI size_type bucket_size(size_type __n) const; - _LIBCPP_HIDE_FROM_ABI float load_factor() const _NOEXCEPT { - size_type __bc = bucket_count(); - return __bc != 0 ? (float)size() / __bc : 0.f; - } - _LIBCPP_HIDE_FROM_ABI void max_load_factor(float __mlf) _NOEXCEPT { - // While passing a non-positive load factor is undefined behavior, in practice the result will be benign (the - // call will be equivalent to `max_load_factor(load_factor())`, which is also the case for passing a valid value - // less than the current `load_factor`). - _LIBCPP_ASSERT_PEDANTIC(__mlf > 0, "unordered container::max_load_factor(lf) called with lf <= 0"); - max_load_factor() = std::max(__mlf, load_factor()); - } - - _LIBCPP_HIDE_FROM_ABI local_iterator begin(size_type __n) { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n < bucket_count(), "unordered container::begin(n) called with n >= bucket_count()"); - return local_iterator(__bucket_list_[__n], __n, bucket_count()); - } - - _LIBCPP_HIDE_FROM_ABI local_iterator end(size_type __n) { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n < bucket_count(), "unordered container::end(n) called with n >= bucket_count()"); - return local_iterator(nullptr, __n, bucket_count()); - } - - _LIBCPP_HIDE_FROM_ABI const_local_iterator cbegin(size_type __n) const { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n < bucket_count(), "unordered container::cbegin(n) called with n >= bucket_count()"); - return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); - } - - _LIBCPP_HIDE_FROM_ABI const_local_iterator cend(size_type __n) const { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n < bucket_count(), "unordered container::cend(n) called with n >= bucket_count()"); - return const_local_iterator(nullptr, __n, bucket_count()); - } - -private: - template - _LIBCPP_HIDE_FROM_ABI void __rehash(size_type __n); - template - _LIBCPP_HIDE_FROM_ABI void __do_rehash(size_type __n); - - template - _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node(_Args&&... __args); - - template - _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); - - _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __hash_table& __u) { - __copy_assign_alloc(__u, integral_constant()); - } - _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __hash_table& __u, true_type); - _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __hash_table&, false_type) {} - - _LIBCPP_HIDE_FROM_ABI void __move_assign(__hash_table& __u, false_type); - _LIBCPP_HIDE_FROM_ABI void __move_assign(__hash_table& __u, true_type); - _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__hash_table& __u) { - __move_assign_alloc(__u, integral_constant()); - } - _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__hash_table& __u, true_type) { - __bucket_list_.get_deleter().__alloc() = std::move(__u.__bucket_list_.get_deleter().__alloc()); - __node_alloc() = std::move(__u.__node_alloc()); - } - _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} - - _LIBCPP_HIDE_FROM_ABI void __deallocate_node(__next_pointer __np) _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI __next_pointer __detach() _NOEXCEPT; - - template - friend class _LIBCPP_TEMPLATE_VIS unordered_map; - template - friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; -}; - -template -inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() - : __p2_(0, __default_init_tag()), __p3_(1.0f, __default_init_tag()) {} - -template -inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql) - : __bucket_list_(nullptr, __bucket_list_deleter()), __p1_(), __p2_(0, __hf), __p3_(1.0f, __eql) {} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table( - const hasher& __hf, const key_equal& __eql, const allocator_type& __a) - : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __hf), - __p3_(1.0f, __eql) {} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) - : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __default_init_tag()), - __p3_(1.0f, __default_init_tag()) {} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) - : __bucket_list_(nullptr, - __bucket_list_deleter(allocator_traits<__pointer_allocator>::select_on_container_copy_construction( - __u.__bucket_list_.get_deleter().__alloc()), - 0)), - __p1_(__default_init_tag(), - allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())), - __p2_(0, __u.hash_function()), - __p3_(__u.__p3_) {} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, const allocator_type& __a) - : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __u.hash_function()), - __p3_(__u.__p3_) {} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) - : __bucket_list_(std::move(__u.__bucket_list_)), - __p1_(std::move(__u.__p1_)), - __p2_(std::move(__u.__p2_)), - __p3_(std::move(__u.__p3_)) { - if (size() > 0) { - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - __u.__p1_.first().__next_ = nullptr; - __u.size() = 0; - } -} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, const allocator_type& __a) - : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, std::move(__u.hash_function())), - __p3_(std::move(__u.__p3_)) { - if (__a == allocator_type(__u.__node_alloc())) { - __bucket_list_.reset(__u.__bucket_list_.release()); - __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); - __u.__bucket_list_.get_deleter().size() = 0; - if (__u.size() > 0) { - __p1_.first().__next_ = __u.__p1_.first().__next_; - __u.__p1_.first().__next_ = nullptr; - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - size() = __u.size(); - __u.size() = 0; - } - } -} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() { - static_assert(is_copy_constructible::value, "Predicate must be copy-constructible."); - static_assert(is_copy_constructible::value, "Hasher must be copy-constructible."); - - __deallocate_node(__p1_.first().__next_); -} - -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(const __hash_table& __u, true_type) { - if (__node_alloc() != __u.__node_alloc()) { - clear(); - __bucket_list_.reset(); - __bucket_list_.get_deleter().size() = 0; - } - __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); - __node_alloc() = __u.__node_alloc(); -} - -template -__hash_table<_Tp, _Hash, _Equal, _Alloc>& __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) { - if (this != std::addressof(__u)) { - __copy_assign_alloc(__u); - hash_function() = __u.hash_function(); - key_eq() = __u.key_eq(); - max_load_factor() = __u.max_load_factor(); - __assign_multi(__u.begin(), __u.end()); - } - return *this; -} - -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) _NOEXCEPT { - __node_allocator& __na = __node_alloc(); - while (__np != nullptr) { - __next_pointer __next = __np->__next_; - __node_pointer __real_np = __np->__upcast(); - __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__get_value())); - std::__destroy_at(std::addressof(*__real_np)); - __node_traits::deallocate(__na, __real_np, 1); - __np = __next; - } -} - -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT { - size_type __bc = bucket_count(); - for (size_type __i = 0; __i < __bc; ++__i) - __bucket_list_[__i] = nullptr; - size() = 0; - __next_pointer __cache = __p1_.first().__next_; - __p1_.first().__next_ = nullptr; - return __cache; -} - -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, true_type) { - clear(); - __bucket_list_.reset(__u.__bucket_list_.release()); - __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); - __u.__bucket_list_.get_deleter().size() = 0; - __move_assign_alloc(__u); - size() = __u.size(); - hash_function() = std::move(__u.hash_function()); - max_load_factor() = __u.max_load_factor(); - key_eq() = std::move(__u.key_eq()); - __p1_.first().__next_ = __u.__p1_.first().__next_; - if (size() > 0) { - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - __u.__p1_.first().__next_ = nullptr; - __u.size() = 0; - } -} - -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, false_type) { - if (__node_alloc() == __u.__node_alloc()) - __move_assign(__u, true_type()); - else { - hash_function() = std::move(__u.hash_function()); - key_eq() = std::move(__u.key_eq()); - max_load_factor() = __u.max_load_factor(); - if (bucket_count() != 0) { - __next_pointer __cache = __detach(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - const_iterator __i = __u.begin(); - while (__cache != nullptr && __u.size() != 0) { - __cache->__upcast()->__get_value() = std::move(__u.remove(__i++)->__get_value()); - __next_pointer __next = __cache->__next_; - __node_insert_multi(__cache->__upcast()); - __cache = __next; - } -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } catch (...) { - __deallocate_node(__cache); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - __deallocate_node(__cache); - } - const_iterator __i = __u.begin(); - while (__u.size() != 0) { - __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__get_value())); - __node_insert_multi(__h.get()); - __h.release(); - } - } -} - -template -inline __hash_table<_Tp, _Hash, _Equal, _Alloc>& -__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) { - __move_assign(__u, integral_constant()); - return *this; -} - -template -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, _InputIterator __last) { - typedef iterator_traits<_InputIterator> _ITraits; - typedef typename _ITraits::value_type _ItValueType; - static_assert(is_same<_ItValueType, __container_value_type>::value, - "__assign_unique may only be called with the containers value type"); - - if (bucket_count() != 0) { - __next_pointer __cache = __detach(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - for (; __cache != nullptr && __first != __last; ++__first) { - __cache->__upcast()->__get_value() = *__first; - __next_pointer __next = __cache->__next_; - __node_insert_unique(__cache->__upcast()); - __cache = __next; - } -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } catch (...) { - __deallocate_node(__cache); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - __deallocate_node(__cache); - } - for (; __first != __last; ++__first) - __insert_unique(*__first); -} - -template -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, _InputIterator __last) { - typedef iterator_traits<_InputIterator> _ITraits; - typedef typename _ITraits::value_type _ItValueType; - static_assert( - (is_same<_ItValueType, __container_value_type>::value || is_same<_ItValueType, __node_value_type>::value), - "__assign_multi may only be called with the containers value type" - " or the nodes value type"); - if (bucket_count() != 0) { - __next_pointer __cache = __detach(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - for (; __cache != nullptr && __first != __last; ++__first) { - __cache->__upcast()->__get_value() = *__first; - __next_pointer __next = __cache->__next_; - __node_insert_multi(__cache->__upcast()); - __cache = __next; - } -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } catch (...) { - __deallocate_node(__cache); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - __deallocate_node(__cache); - } - for (; __first != __last; ++__first) - __insert_multi(_NodeTypes::__get_value(*__first)); -} - -template -inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT { - return iterator(__p1_.first().__next_); -} - -template -inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT { - return iterator(nullptr); -} - -template -inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT { - return const_iterator(__p1_.first().__next_); -} - -template -inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT { - return const_iterator(nullptr); -} - -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT { - if (size() > 0) { - __deallocate_node(__p1_.first().__next_); - __p1_.first().__next_ = nullptr; - size_type __bc = bucket_count(); - for (size_type __i = 0; __i < __bc; ++__i) - __bucket_list_[__i] = nullptr; - size() = 0; - } -} - -// Prepare the container for an insertion of the value __value with the hash -// __hash. This does a lookup into the container to see if __value is already -// present, and performs a rehash if necessary. Returns a pointer to the -// existing element if it exists, otherwise nullptr. -// -// Note that this function does forward exceptions if key_eq() throws, and never -// mutates __value or actually inserts into the map. -template -_LIBCPP_HIDE_FROM_ABI typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare(size_t __hash, value_type& __value) { - size_type __bc = bucket_count(); - - if (__bc != 0) { - size_t __chash = std::__constrain_hash(__hash, __bc); - __next_pointer __ndptr = __bucket_list_[__chash]; - if (__ndptr != nullptr) { - for (__ndptr = __ndptr->__next_; - __ndptr != nullptr && - (__ndptr->__hash() == __hash || std::__constrain_hash(__ndptr->__hash(), __bc) == __chash); - __ndptr = __ndptr->__next_) { - if ((__ndptr->__hash() == __hash) && key_eq()(__ndptr->__upcast()->__get_value(), __value)) - return __ndptr; - } - } - } - if (size() + 1 > __bc * max_load_factor() || __bc == 0) { - __rehash_unique(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); - } - return nullptr; -} - -// Insert the node __nd into the container by pushing it into the right bucket, -// and updating size(). Assumes that __nd->__hash is up-to-date, and that -// rehashing has already occurred and that no element with the same key exists -// in the map. -template -_LIBCPP_HIDE_FROM_ABI void -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform(__node_pointer __nd) _NOEXCEPT { - size_type __bc = bucket_count(); - size_t __chash = std::__constrain_hash(__nd->__hash(), __bc); - // insert_after __bucket_list_[__chash], or __first_node if bucket is null - __next_pointer __pn = __bucket_list_[__chash]; - if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); - __nd->__next_ = __pn->__next_; - __pn->__next_ = __nd->__ptr(); - // fix up __bucket_list_ - __bucket_list_[__chash] = __pn; - if (__nd->__next_ != nullptr) - __bucket_list_[std::__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); - } else { - __nd->__next_ = __pn->__next_; - __pn->__next_ = __nd->__ptr(); - } - ++size(); -} - -template -pair::iterator, bool> -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) { - __nd->__hash_ = hash_function()(__nd->__get_value()); - __next_pointer __existing_node = __node_insert_unique_prepare(__nd->__hash(), __nd->__get_value()); - - // Insert the node, unless it already exists in the container. - bool __inserted = false; - if (__existing_node == nullptr) { - __node_insert_unique_perform(__nd); - __existing_node = __nd->__ptr(); - __inserted = true; - } - return pair(iterator(__existing_node), __inserted); -} - -// Prepare the container for an insertion of the value __cp_val with the hash -// __cp_hash. This does a lookup into the container to see if __cp_value is -// already present, and performs a rehash if necessary. Returns a pointer to the -// last occurrence of __cp_val in the map. -// -// Note that this function does forward exceptions if key_eq() throws, and never -// mutates __value or actually inserts into the map. -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare(size_t __cp_hash, value_type& __cp_val) { - size_type __bc = bucket_count(); - if (size() + 1 > __bc * max_load_factor() || __bc == 0) { - __rehash_multi(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); - __bc = bucket_count(); - } - size_t __chash = std::__constrain_hash(__cp_hash, __bc); - __next_pointer __pn = __bucket_list_[__chash]; - if (__pn != nullptr) { - for (bool __found = false; - __pn->__next_ != nullptr && std::__constrain_hash(__pn->__next_->__hash(), __bc) == __chash; - __pn = __pn->__next_) { - // __found key_eq() action - // false false loop - // true true loop - // false true set __found to true - // true false break - if (__found != - (__pn->__next_->__hash() == __cp_hash && key_eq()(__pn->__next_->__upcast()->__get_value(), __cp_val))) { - if (!__found) - __found = true; - else - break; - } - } - } - return __pn; -} - -// Insert the node __cp into the container after __pn (which is the last node in -// the bucket that compares equal to __cp). Rehashing, and checking for -// uniqueness has already been performed (in __node_insert_multi_prepare), so -// all we need to do is update the bucket and size(). Assumes that __cp->__hash -// is up-to-date. -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( - __node_pointer __cp, __next_pointer __pn) _NOEXCEPT { - size_type __bc = bucket_count(); - size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); - if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); - __cp->__next_ = __pn->__next_; - __pn->__next_ = __cp->__ptr(); - // fix up __bucket_list_ - __bucket_list_[__chash] = __pn; - if (__cp->__next_ != nullptr) - __bucket_list_[std::__constrain_hash(__cp->__next_->__hash(), __bc)] = __cp->__ptr(); - } else { - __cp->__next_ = __pn->__next_; - __pn->__next_ = __cp->__ptr(); - if (__cp->__next_ != nullptr) { - size_t __nhash = std::__constrain_hash(__cp->__next_->__hash(), __bc); - if (__nhash != __chash) - __bucket_list_[__nhash] = __cp->__ptr(); - } - } - ++size(); -} - -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) { - __cp->__hash_ = hash_function()(__cp->__get_value()); - __next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__get_value()); - __node_insert_multi_perform(__cp, __pn); - - return iterator(__cp->__ptr()); -} - -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(const_iterator __p, __node_pointer __cp) { - if (__p != end() && key_eq()(*__p, __cp->__get_value())) { - __next_pointer __np = __p.__node_; - __cp->__hash_ = __np->__hash(); - size_type __bc = bucket_count(); - if (size() + 1 > __bc * max_load_factor() || __bc == 0) { - __rehash_multi(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); - __bc = bucket_count(); - } - size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); - __next_pointer __pp = __bucket_list_[__chash]; - while (__pp->__next_ != __np) - __pp = __pp->__next_; - __cp->__next_ = __np; - __pp->__next_ = static_cast<__next_pointer>(__cp); - ++size(); - return iterator(static_cast<__next_pointer>(__cp)); - } - return __node_insert_multi(__cp); -} - -template -template -pair::iterator, bool> -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) { - size_t __hash = hash_function()(__k); - size_type __bc = bucket_count(); - bool __inserted = false; - __next_pointer __nd; - size_t __chash; - if (__bc != 0) { - __chash = std::__constrain_hash(__hash, __bc); - __nd = __bucket_list_[__chash]; - if (__nd != nullptr) { - for (__nd = __nd->__next_; - __nd != nullptr && (__nd->__hash() == __hash || std::__constrain_hash(__nd->__hash(), __bc) == __chash); - __nd = __nd->__next_) { - if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__get_value(), __k)) - goto __done; - } - } - } - { - __node_holder __h = __construct_node_hash(__hash, std::forward<_Args>(__args)...); - if (size() + 1 > __bc * max_load_factor() || __bc == 0) { - __rehash_unique(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); - __bc = bucket_count(); - __chash = std::__constrain_hash(__hash, __bc); - } - // insert_after __bucket_list_[__chash], or __first_node if bucket is null - __next_pointer __pn = __bucket_list_[__chash]; - if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); - __h->__next_ = __pn->__next_; - __pn->__next_ = __h.get()->__ptr(); - // fix up __bucket_list_ - __bucket_list_[__chash] = __pn; - if (__h->__next_ != nullptr) - __bucket_list_[std::__constrain_hash(__h->__next_->__hash(), __bc)] = __h.get()->__ptr(); - } else { - __h->__next_ = __pn->__next_; - __pn->__next_ = static_cast<__next_pointer>(__h.get()); - } - __nd = static_cast<__next_pointer>(__h.release()); - // increment size - ++size(); - __inserted = true; - } -__done: - return pair(iterator(__nd), __inserted); -} - -template -template -pair::iterator, bool> -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) { - __node_holder __h = __construct_node(std::forward<_Args>(__args)...); - pair __r = __node_insert_unique(__h.get()); - if (__r.second) - __h.release(); - return __r; -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) { - __node_holder __h = __construct_node(std::forward<_Args>(__args)...); - iterator __r = __node_insert_multi(__h.get()); - __h.release(); - return __r; -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) { - __node_holder __h = __construct_node(std::forward<_Args>(__args)...); - iterator __r = __node_insert_multi(__p, __h.get()); - __h.release(); - return __r; -} - -template -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __n) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { - if (__n == 1) - __n = 2; - else if (__n & (__n - 1)) - __n = std::__next_prime(__n); - size_type __bc = bucket_count(); - if (__n > __bc) - __do_rehash<_UniqueKeys>(__n); - else if (__n < __bc) { - __n = std::max( - __n, - std::__is_hash_power2(__bc) ? std::__next_hash_pow2(size_t(std::ceil(float(size()) / max_load_factor()))) - : std::__next_prime(size_t(std::ceil(float(size()) / max_load_factor())))); - if (__n < __bc) - __do_rehash<_UniqueKeys>(__n); - } -} - -template -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc) { - __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); - __bucket_list_.reset(__nbc > 0 ? __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); - __bucket_list_.get_deleter().size() = __nbc; - if (__nbc > 0) { - for (size_type __i = 0; __i < __nbc; ++__i) - __bucket_list_[__i] = nullptr; - __next_pointer __pp = __p1_.first().__ptr(); - __next_pointer __cp = __pp->__next_; - if (__cp != nullptr) { - size_type __chash = std::__constrain_hash(__cp->__hash(), __nbc); - __bucket_list_[__chash] = __pp; - size_type __phash = __chash; - for (__pp = __cp, void(), __cp = __cp->__next_; __cp != nullptr; __cp = __pp->__next_) { - __chash = std::__constrain_hash(__cp->__hash(), __nbc); - if (__chash == __phash) - __pp = __cp; - else { - if (__bucket_list_[__chash] == nullptr) { - __bucket_list_[__chash] = __pp; - __pp = __cp; - __phash = __chash; - } else { - __next_pointer __np = __cp; - if (!_UniqueKeys) { - for (; __np->__next_ != nullptr && - key_eq()(__cp->__upcast()->__get_value(), __np->__next_->__upcast()->__get_value()); - __np = __np->__next_) - ; - } - __pp->__next_ = __np->__next_; - __np->__next_ = __bucket_list_[__chash]->__next_; - __bucket_list_[__chash]->__next_ = __cp; - } - } - } - } - } -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) { - size_t __hash = hash_function()(__k); - size_type __bc = bucket_count(); - if (__bc != 0) { - size_t __chash = std::__constrain_hash(__hash, __bc); - __next_pointer __nd = __bucket_list_[__chash]; - if (__nd != nullptr) { - for (__nd = __nd->__next_; - __nd != nullptr && (__nd->__hash() == __hash || std::__constrain_hash(__nd->__hash(), __bc) == __chash); - __nd = __nd->__next_) { - if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__get_value(), __k)) - return iterator(__nd); - } - } - } - return end(); -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const { - size_t __hash = hash_function()(__k); - size_type __bc = bucket_count(); - if (__bc != 0) { - size_t __chash = std::__constrain_hash(__hash, __bc); - __next_pointer __nd = __bucket_list_[__chash]; - if (__nd != nullptr) { - for (__nd = __nd->__next_; - __nd != nullptr && (__hash == __nd->__hash() || std::__constrain_hash(__nd->__hash(), __bc) == __chash); - __nd = __nd->__next_) { - if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__get_value(), __k)) - return const_iterator(__nd); - } - } - } - return end(); -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&&... __args) { - static_assert(!__is_hash_value_type<_Args...>::value, "Construct cannot be called with a hash value type"); - __node_allocator& __na = __node_alloc(); - __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - - // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value - // held inside the node, since we need to use the allocator's construct() method for that. - // - // We don't use the allocator's construct() method to construct the node itself since the - // Cpp17FooInsertable named requirements don't require the allocator's construct() method - // to work on anything other than the value_type. - std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ 0); - - // Now construct the value_type using the allocator's construct() method. - __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__get_value()), std::forward<_Args>(__args)...); - __h.get_deleter().__value_constructed = true; - - __h->__hash_ = hash_function()(__h->__get_value()); - return __h; -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest) { - static_assert(!__is_hash_value_type<_First, _Rest...>::value, "Construct cannot be called with a hash value type"); - __node_allocator& __na = __node_alloc(); - __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ __hash); - __node_traits::construct( - __na, _NodeTypes::__get_ptr(__h->__get_value()), std::forward<_First>(__f), std::forward<_Rest>(__rest)...); - __h.get_deleter().__value_constructed = true; - return __h; -} - -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) { - __next_pointer __np = __p.__node_; - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __p != end(), "unordered container::erase(iterator) called with a non-dereferenceable iterator"); - iterator __r(__np); - ++__r; - remove(__p); - return __r; -} - -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator -__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, const_iterator __last) { - for (const_iterator __p = __first; __first != __last; __p = __first) { - ++__first; - erase(__p); - } - __next_pointer __np = __last.__node_; - return iterator(__np); -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) { - iterator __i = find(__k); - if (__i == end()) - return 0; - erase(__i); - return 1; -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) { - size_type __r = 0; - iterator __i = find(__k); - if (__i != end()) { - iterator __e = end(); - do { - erase(__i++); - ++__r; - } while (__i != __e && key_eq()(*__i, __k)); - } - return __r; -} - -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder -__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT { - // current node - __next_pointer __cn = __p.__node_; - size_type __bc = bucket_count(); - size_t __chash = std::__constrain_hash(__cn->__hash(), __bc); - // find previous node - __next_pointer __pn = __bucket_list_[__chash]; - for (; __pn->__next_ != __cn; __pn = __pn->__next_) - ; - // Fix up __bucket_list_ - // if __pn is not in same bucket (before begin is not in same bucket) && - // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) - if (__pn == __p1_.first().__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) { - if (__cn->__next_ == nullptr || std::__constrain_hash(__cn->__next_->__hash(), __bc) != __chash) - __bucket_list_[__chash] = nullptr; - } - // if __cn->__next_ is not in same bucket (nullptr is in same bucket) - if (__cn->__next_ != nullptr) { - size_t __nhash = std::__constrain_hash(__cn->__next_->__hash(), __bc); - if (__nhash != __chash) - __bucket_list_[__nhash] = __pn; - } - // remove __cn - __pn->__next_ = __cn->__next_; - __cn->__next_ = nullptr; - --size(); - return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); -} - -template -template -inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const { - return static_cast(find(__k) != end()); -} - -template -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const { - size_type __r = 0; - const_iterator __i = find(__k); - if (__i != end()) { - const_iterator __e = end(); - do { - ++__i; - ++__r; - } while (__i != __e && key_eq()(*__i, __k)); - } - return __r; -} - -template -template -pair::iterator, - typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(const _Key& __k) { - iterator __i = find(__k); - iterator __j = __i; - if (__i != end()) - ++__j; - return pair(__i, __j); -} - -template -template -pair::const_iterator, - typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(const _Key& __k) const { - const_iterator __i = find(__k); - const_iterator __j = __i; - if (__i != end()) - ++__j; - return pair(__i, __j); -} - -template -template -pair::iterator, - typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(const _Key& __k) { - iterator __i = find(__k); - iterator __j = __i; - if (__i != end()) { - iterator __e = end(); - do { - ++__j; - } while (__j != __e && key_eq()(*__j, __k)); - } - return pair(__i, __j); -} - -template -template -pair::const_iterator, - typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(const _Key& __k) const { - const_iterator __i = find(__k); - const_iterator __j = __i; - if (__i != end()) { - const_iterator __e = end(); - do { - ++__j; - } while (__j != __e && key_eq()(*__j, __k)); - } - return pair(__i, __j); -} - -template -void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) { - _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR( - __node_traits::propagate_on_container_swap::value || this->__node_alloc() == __u.__node_alloc(), - "unordered container::swap: Either propagate_on_container_swap " - "must be true or the allocators must compare equal"); - { - __node_pointer_pointer __npp = __bucket_list_.release(); - __bucket_list_.reset(__u.__bucket_list_.release()); - __u.__bucket_list_.reset(__npp); - } - std::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); - std::__swap_allocator(__bucket_list_.get_deleter().__alloc(), __u.__bucket_list_.get_deleter().__alloc()); - std::__swap_allocator(__node_alloc(), __u.__node_alloc()); - std::swap(__p1_.first().__next_, __u.__p1_.first().__next_); - __p2_.swap(__u.__p2_); - __p3_.swap(__u.__p3_); - if (size() > 0) - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - if (__u.size() > 0) - __u.__bucket_list_[std::__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = - __u.__p1_.first().__ptr(); -} - -template -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type -__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n < bucket_count(), "unordered container::bucket_size(n) called with n >= bucket_count()"); - __next_pointer __np = __bucket_list_[__n]; - size_type __bc = bucket_count(); - size_type __r = 0; - if (__np != nullptr) { - for (__np = __np->__next_; __np != nullptr && std::__constrain_hash(__np->__hash(), __bc) == __n; - __np = __np->__next_, (void)++__r) - ; - } - return __r; -} - -template -inline _LIBCPP_HIDE_FROM_ABI void -swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) { - __x.swap(__y); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___HASH_TABLE diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__ios/fpos.h b/third_party/libcxx/include/c++/v1/__cxx03/__ios/fpos.h deleted file mode 100644 index 5f16bfd..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__ios/fpos.h +++ /dev/null @@ -1,76 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___IOS_FPOS_H -#define _LIBCPP___CXX03___IOS_FPOS_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/ios.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS fpos { -private: - _StateT __st_; - streamoff __off_; - -public: - _LIBCPP_HIDE_FROM_ABI fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {} - - _LIBCPP_HIDE_FROM_ABI operator streamoff() const { return __off_; } - - _LIBCPP_HIDE_FROM_ABI _StateT state() const { return __st_; } - _LIBCPP_HIDE_FROM_ABI void state(_StateT __st) { __st_ = __st; } - - _LIBCPP_HIDE_FROM_ABI fpos& operator+=(streamoff __off) { - __off_ += __off; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI fpos operator+(streamoff __off) const { - fpos __t(*this); - __t += __off; - return __t; - } - - _LIBCPP_HIDE_FROM_ABI fpos& operator-=(streamoff __off) { - __off_ -= __off; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI fpos operator-(streamoff __off) const { - fpos __t(*this); - __t -= __off; - return __t; - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) { - return streamoff(__x) - streamoff(__y); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) { - return streamoff(__x) == streamoff(__y); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) { - return streamoff(__x) != streamoff(__y); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___IOS_FPOS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/access.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/access.h deleted file mode 100644 index 52220a1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/access.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ACCESS_H -#define _LIBCPP___CXX03___ITERATOR_ACCESS_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI _Tp* begin(_Tp (&__array)[_Np]) _NOEXCEPT { - return __array; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp* end(_Tp (&__array)[_Np]) _NOEXCEPT { - return __array + _Np; -} - -template -_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) { - return __c.begin(); -} - -template -_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) { - return __c.begin(); -} - -template -_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) { - return __c.end(); -} - -template -_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) { - return __c.end(); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_ACCESS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/advance.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/advance.h deleted file mode 100644 index d49556a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/advance.h +++ /dev/null @@ -1,74 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ADVANCE_H -#define _LIBCPP___CXX03___ITERATOR_ADVANCE_H - -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__utility/convert_to_integral.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/__utility/unreachable.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI void -__advance(_InputIter& __i, typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) { - for (; __n > 0; --__n) - ++__i; -} - -template -_LIBCPP_HIDE_FROM_ABI void -__advance(_BiDirIter& __i, typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) { - if (__n >= 0) - for (; __n > 0; --__n) - ++__i; - else - for (; __n < 0; ++__n) - --__i; -} - -template -_LIBCPP_HIDE_FROM_ABI void -__advance(_RandIter& __i, typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) { - __i += __n; -} - -template < class _InputIter, - class _Distance, - class _IntegralDistance = decltype(std::__convert_to_integral(std::declval<_Distance>())), - __enable_if_t::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void advance(_InputIter& __i, _Distance __orig_n) { - typedef typename iterator_traits<_InputIter>::difference_type _Difference; - _Difference __n = static_cast<_Difference>(std::__convert_to_integral(__orig_n)); - // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation. - _LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value, - "Attempt to advance(it, n) with negative n on a non-bidirectional iterator"); - std::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ITERATOR_ADVANCE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/aliasing_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/aliasing_iterator.h deleted file mode 100644 index 93da1d2..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/aliasing_iterator.h +++ /dev/null @@ -1,127 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ALIASING_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_ALIASING_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__type_traits/is_trivial.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -// This iterator wrapper is used to type-pun an iterator to return a different type. This is done without UB by not -// actually punning the type, but instead inspecting the object representation of the base type and copying that into -// an instance of the alias type. For that reason the alias type has to be trivial. The alias is returned as a prvalue -// when derferencing the iterator, since it is temporary storage. This wrapper is used to vectorize some algorithms. - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __aliasing_iterator_wrapper { - class __iterator { - _BaseIter __base_ = nullptr; - - using __iter_traits = iterator_traits<_BaseIter>; - using __base_value_type = typename __iter_traits::value_type; - - static_assert(__has_random_access_iterator_category<_BaseIter>::value, - "The base iterator has to be a random access iterator!"); - - public: - using iterator_category = random_access_iterator_tag; - using value_type = _Alias; - using difference_type = ptrdiff_t; - using reference = value_type&; - using pointer = value_type*; - - static_assert(is_trivial::value); - static_assert(sizeof(__base_value_type) == sizeof(value_type)); - - _LIBCPP_HIDE_FROM_ABI __iterator() = default; - _LIBCPP_HIDE_FROM_ABI __iterator(_BaseIter __base) _NOEXCEPT : __base_(__base) {} - - _LIBCPP_HIDE_FROM_ABI __iterator& operator++() _NOEXCEPT { - ++__base_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __iterator operator++(int) _NOEXCEPT { - __iterator __tmp(*this); - ++__base_; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI __iterator& operator--() _NOEXCEPT { - --__base_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI __iterator operator--(int) _NOEXCEPT { - __iterator __tmp(*this); - --__base_; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI friend __iterator operator+(__iterator __iter, difference_type __n) _NOEXCEPT { - return __iterator(__iter.__base_ + __n); - } - - _LIBCPP_HIDE_FROM_ABI friend __iterator operator+(difference_type __n, __iterator __iter) _NOEXCEPT { - return __iterator(__n + __iter.__base_); - } - - _LIBCPP_HIDE_FROM_ABI __iterator& operator+=(difference_type __n) _NOEXCEPT { - __base_ += __n; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI friend __iterator operator-(__iterator __iter, difference_type __n) _NOEXCEPT { - return __iterator(__iter.__base_ - __n); - } - - _LIBCPP_HIDE_FROM_ABI friend difference_type operator-(__iterator __lhs, __iterator __rhs) _NOEXCEPT { - return __lhs.__base_ - __rhs.__base_; - } - - _LIBCPP_HIDE_FROM_ABI __iterator& operator-=(difference_type __n) _NOEXCEPT { - __base_ -= __n; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI _BaseIter __base() const _NOEXCEPT { return __base_; } - - _LIBCPP_HIDE_FROM_ABI _Alias operator*() const _NOEXCEPT { - _Alias __val; - __builtin_memcpy(&__val, std::__to_address(__base_), sizeof(value_type)); - return __val; - } - - _LIBCPP_HIDE_FROM_ABI value_type operator[](difference_type __n) const _NOEXCEPT { return *(*this + __n); } - - _LIBCPP_HIDE_FROM_ABI friend bool operator==(const __iterator& __lhs, const __iterator& __rhs) _NOEXCEPT { - return __lhs.__base_ == __rhs.__base_; - } - - _LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __iterator& __lhs, const __iterator& __rhs) _NOEXCEPT { - return __lhs.__base_ != __rhs.__base_; - } - }; -}; - -// This is required to avoid ADL instantiations on _BaseT -template -using __aliasing_iterator = typename __aliasing_iterator_wrapper<_BaseT, _Alias>::__iterator; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_ALIASING_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/back_insert_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/back_insert_iterator.h deleted file mode 100644 index e9390a6..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/back_insert_iterator.h +++ /dev/null @@ -1,67 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_BACK_INSERT_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_BACK_INSERT_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -class _LIBCPP_TEMPLATE_VIS back_insert_iterator : public iterator { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -protected: - _Container* container; - -public: - typedef output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - typedef _Container container_type; - - _LIBCPP_HIDE_FROM_ABI explicit back_insert_iterator(_Container& __x) : container(std::addressof(__x)) {} - _LIBCPP_HIDE_FROM_ABI back_insert_iterator& operator=(const typename _Container::value_type& __value) { - container->push_back(__value); - return *this; - } - _LIBCPP_HIDE_FROM_ABI back_insert_iterator& operator*() { return *this; } - _LIBCPP_HIDE_FROM_ABI back_insert_iterator& operator++() { return *this; } - _LIBCPP_HIDE_FROM_ABI back_insert_iterator operator++(int) { return *this; } - - _LIBCPP_HIDE_FROM_ABI _Container* __get_container() const { return container; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(back_insert_iterator); - -template -inline _LIBCPP_HIDE_FROM_ABI back_insert_iterator<_Container> back_inserter(_Container& __x) { - return back_insert_iterator<_Container>(__x); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ITERATOR_BACK_INSERT_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/bounded_iter.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/bounded_iter.h deleted file mode 100644 index 83296a4..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/bounded_iter.h +++ /dev/null @@ -1,247 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_BOUNDED_ITER_H -#define _LIBCPP___CXX03___ITERATOR_BOUNDED_ITER_H - -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/integral_constant.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Iterator wrapper that carries the valid range it is allowed to access. -// -// This is a simple iterator wrapper for contiguous iterators that points -// within a [begin, end] range and carries these bounds with it. The iterator -// ensures that it is pointing within [begin, end) range when it is -// dereferenced. It also ensures that it is never iterated outside of -// [begin, end]. This is important for two reasons: -// -// 1. It allows `operator*` and `operator++` bounds checks to be `iter != end`. -// This is both less for the optimizer to prove, and aligns with how callers -// typically use iterators. -// -// 2. Advancing an iterator out of bounds is undefined behavior (see the table -// in [input.iterators]). In particular, when the underlying iterator is a -// pointer, it is undefined at the language level (see [expr.add]). If -// bounded iterators exhibited this undefined behavior, we risk compiler -// optimizations deleting non-redundant bounds checks. -template ::value > > -struct __bounded_iter { - using value_type = typename iterator_traits<_Iterator>::value_type; - using difference_type = typename iterator_traits<_Iterator>::difference_type; - using pointer = typename iterator_traits<_Iterator>::pointer; - using reference = typename iterator_traits<_Iterator>::reference; - using iterator_category = typename iterator_traits<_Iterator>::iterator_category; - - // Create a singular iterator. - // - // Such an iterator points past the end of an empty span, so it is not dereferenceable. - // Observing operations like comparison and assignment are valid. - _LIBCPP_HIDE_FROM_ABI __bounded_iter() = default; - - _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter const&) = default; - _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter&&) = default; - - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter<_OtherIterator> const& __other) _NOEXCEPT - : __current_(__other.__current_), - __begin_(__other.__begin_), - __end_(__other.__end_) {} - - // Assign a bounded iterator to another one, rebinding the bounds of the iterator as well. - _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator=(__bounded_iter const&) = default; - _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator=(__bounded_iter&&) = default; - -private: - // Create an iterator wrapping the given iterator, and whose bounds are described - // by the provided [begin, end] range. - // - // The constructor does not check whether the resulting iterator is within its bounds. It is a - // responsibility of the container to ensure that the given bounds are valid. - // - // Since it is non-standard for iterators to have this constructor, __bounded_iter must - // be created via `std::__make_bounded_iter`. - _LIBCPP_HIDE_FROM_ABI explicit __bounded_iter(_Iterator __current, _Iterator __begin, _Iterator __end) - : __current_(__current), __begin_(__begin), __end_(__end) { - _LIBCPP_ASSERT_INTERNAL( - __begin <= __current, "__bounded_iter(current, begin, end): current and begin are inconsistent"); - _LIBCPP_ASSERT_INTERNAL( - __current <= __end, "__bounded_iter(current, begin, end): current and end are inconsistent"); - } - - template - friend __bounded_iter<_It> __make_bounded_iter(_It, _It, _It); - -public: - // Dereference and indexing operations. - // - // These operations check that the iterator is dereferenceable. Since the class invariant is - // that the iterator is always within `[begin, end]`, we only need to check it's not pointing to - // `end`. This is easier for the optimizer because it aligns with the `iter != container.end()` - // checks that typical callers already use (see - // https://github.com/llvm/llvm-project/issues/78829). - _LIBCPP_HIDE_FROM_ABI reference operator*() const _NOEXCEPT { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __current_ != __end_, "__bounded_iter::operator*: Attempt to dereference an iterator at the end"); - return *__current_; - } - - _LIBCPP_HIDE_FROM_ABI pointer operator->() const _NOEXCEPT { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __current_ != __end_, "__bounded_iter::operator->: Attempt to dereference an iterator at the end"); - return std::__to_address(__current_); - } - - _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n >= __begin_ - __current_, "__bounded_iter::operator[]: Attempt to index an iterator past the start"); - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n < __end_ - __current_, "__bounded_iter::operator[]: Attempt to index an iterator at or past the end"); - return __current_[__n]; - } - - // Arithmetic operations. - // - // These operations check that the iterator remains within `[begin, end]`. - _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator++() _NOEXCEPT { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __current_ != __end_, "__bounded_iter::operator++: Attempt to advance an iterator past the end"); - ++__current_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI __bounded_iter operator++(int) _NOEXCEPT { - __bounded_iter __tmp(*this); - ++*this; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator--() _NOEXCEPT { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __current_ != __begin_, "__bounded_iter::operator--: Attempt to rewind an iterator past the start"); - --__current_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI __bounded_iter operator--(int) _NOEXCEPT { - __bounded_iter __tmp(*this); - --*this; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator+=(difference_type __n) _NOEXCEPT { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n >= __begin_ - __current_, "__bounded_iter::operator+=: Attempt to rewind an iterator past the start"); - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n <= __end_ - __current_, "__bounded_iter::operator+=: Attempt to advance an iterator past the end"); - __current_ += __n; - return *this; - } - _LIBCPP_HIDE_FROM_ABI friend __bounded_iter operator+(__bounded_iter const& __self, difference_type __n) _NOEXCEPT { - __bounded_iter __tmp(__self); - __tmp += __n; - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI friend __bounded_iter operator+(difference_type __n, __bounded_iter const& __self) _NOEXCEPT { - __bounded_iter __tmp(__self); - __tmp += __n; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator-=(difference_type __n) _NOEXCEPT { - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n <= __current_ - __begin_, "__bounded_iter::operator-=: Attempt to rewind an iterator past the start"); - _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( - __n >= __current_ - __end_, "__bounded_iter::operator-=: Attempt to advance an iterator past the end"); - __current_ -= __n; - return *this; - } - _LIBCPP_HIDE_FROM_ABI friend __bounded_iter operator-(__bounded_iter const& __self, difference_type __n) _NOEXCEPT { - __bounded_iter __tmp(__self); - __tmp -= __n; - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI friend difference_type - operator-(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { - return __x.__current_ - __y.__current_; - } - - // Comparison operations. - // - // These operations do not check whether the iterators are within their bounds. - // The valid range for each iterator is also not considered as part of the comparison, - // i.e. two iterators pointing to the same location will be considered equal even - // if they have different validity ranges. - _LIBCPP_HIDE_FROM_ABI friend bool operator==(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { - return __x.__current_ == __y.__current_; - } - - _LIBCPP_HIDE_FROM_ABI friend bool operator!=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { - return __x.__current_ != __y.__current_; - } - - // TODO(mordante) disable these overloads in the LLVM 20 release. - _LIBCPP_HIDE_FROM_ABI friend bool operator<(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { - return __x.__current_ < __y.__current_; - } - _LIBCPP_HIDE_FROM_ABI friend bool operator>(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { - return __x.__current_ > __y.__current_; - } - _LIBCPP_HIDE_FROM_ABI friend bool operator<=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { - return __x.__current_ <= __y.__current_; - } - _LIBCPP_HIDE_FROM_ABI friend bool operator>=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { - return __x.__current_ >= __y.__current_; - } - -private: - template - friend struct pointer_traits; - template - friend struct __bounded_iter; - _Iterator __current_; // current iterator - _Iterator __begin_, __end_; // valid range represented as [begin, end] -}; - -template -_LIBCPP_HIDE_FROM_ABI __bounded_iter<_It> __make_bounded_iter(_It __it, _It __begin, _It __end) { - return __bounded_iter<_It>(std::move(__it), std::move(__begin), std::move(__end)); -} - -template -struct __libcpp_is_contiguous_iterator<__bounded_iter<_Iterator> > : true_type {}; - -template -struct pointer_traits<__bounded_iter<_Iterator> > { - using pointer = __bounded_iter<_Iterator>; - using element_type = typename pointer_traits<_Iterator>::element_type; - using difference_type = typename pointer_traits<_Iterator>::difference_type; - - _LIBCPP_HIDE_FROM_ABI static element_type* to_address(pointer __it) _NOEXCEPT { - return std::__to_address(__it.__current_); - } -}; - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ITERATOR_BOUNDED_ITER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/distance.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/distance.h deleted file mode 100644 index 656b960..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/distance.h +++ /dev/null @@ -1,47 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_DISTANCE_H -#define _LIBCPP___CXX03___ITERATOR_DISTANCE_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/decay.h> -#include <__cxx03/__type_traits/remove_cvref.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_HIDE_FROM_ABI typename iterator_traits<_InputIter>::difference_type -__distance(_InputIter __first, _InputIter __last, input_iterator_tag) { - typename iterator_traits<_InputIter>::difference_type __r(0); - for (; __first != __last; ++__first) - ++__r; - return __r; -} - -template -inline _LIBCPP_HIDE_FROM_ABI typename iterator_traits<_RandIter>::difference_type -__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) { - return __last - __first; -} - -template -inline _LIBCPP_HIDE_FROM_ABI typename iterator_traits<_InputIter>::difference_type -distance(_InputIter __first, _InputIter __last) { - return std::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_DISTANCE_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/erase_if_container.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/erase_if_container.h deleted file mode 100644 index c83eccd..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/erase_if_container.h +++ /dev/null @@ -1,43 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ERASE_IF_CONTAINER_H -#define _LIBCPP___CXX03___ITERATOR_ERASE_IF_CONTAINER_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -_LIBCPP_HIDE_FROM_ABI typename _Container::size_type __libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { - typename _Container::size_type __old_size = __c.size(); - - const typename _Container::iterator __last = __c.end(); - for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { - if (__pred(*__iter)) - __iter = __c.erase(__iter); - else - ++__iter; - } - - return __old_size - __c.size(); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ITERATOR_ERASE_IF_CONTAINER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/front_insert_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/front_insert_iterator.h deleted file mode 100644 index 347858f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/front_insert_iterator.h +++ /dev/null @@ -1,65 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_FRONT_INSERT_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_FRONT_INSERT_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -class _LIBCPP_TEMPLATE_VIS front_insert_iterator : public iterator { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -protected: - _Container* container; - -public: - typedef output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - typedef _Container container_type; - - _LIBCPP_HIDE_FROM_ABI explicit front_insert_iterator(_Container& __x) : container(std::addressof(__x)) {} - _LIBCPP_HIDE_FROM_ABI front_insert_iterator& operator=(const typename _Container::value_type& __value) { - container->push_front(__value); - return *this; - } - _LIBCPP_HIDE_FROM_ABI front_insert_iterator& operator*() { return *this; } - _LIBCPP_HIDE_FROM_ABI front_insert_iterator& operator++() { return *this; } - _LIBCPP_HIDE_FROM_ABI front_insert_iterator operator++(int) { return *this; } -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(front_insert_iterator); - -template -inline _LIBCPP_HIDE_FROM_ABI front_insert_iterator<_Container> front_inserter(_Container& __x) { - return front_insert_iterator<_Container>(__x); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ITERATOR_FRONT_INSERT_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/insert_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/insert_iterator.h deleted file mode 100644 index afb1f98..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/insert_iterator.h +++ /dev/null @@ -1,71 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_INSERT_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_INSERT_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -using __insert_iterator_iter_t = typename _Container::iterator; - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -class _LIBCPP_TEMPLATE_VIS insert_iterator : public iterator { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -protected: - _Container* container; - __insert_iterator_iter_t<_Container> iter; - -public: - typedef output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - typedef _Container container_type; - - _LIBCPP_HIDE_FROM_ABI insert_iterator(_Container& __x, __insert_iterator_iter_t<_Container> __i) - : container(std::addressof(__x)), iter(__i) {} - _LIBCPP_HIDE_FROM_ABI insert_iterator& operator=(const typename _Container::value_type& __value) { - iter = container->insert(iter, __value); - ++iter; - return *this; - } - _LIBCPP_HIDE_FROM_ABI insert_iterator& operator*() { return *this; } - _LIBCPP_HIDE_FROM_ABI insert_iterator& operator++() { return *this; } - _LIBCPP_HIDE_FROM_ABI insert_iterator& operator++(int) { return *this; } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI insert_iterator<_Container> -inserter(_Container& __x, __insert_iterator_iter_t<_Container> __i) { - return insert_iterator<_Container>(__x, __i); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ITERATOR_INSERT_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/istream_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/istream_iterator.h deleted file mode 100644 index fb77c67..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/istream_iterator.h +++ /dev/null @@ -1,86 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ISTREAM_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_ISTREAM_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/istream.h> -#include <__cxx03/__fwd/string.h> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template , class _Distance = ptrdiff_t> -class _LIBCPP_TEMPLATE_VIS istream_iterator - : public iterator { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -public: - typedef input_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Distance difference_type; - typedef const _Tp* pointer; - typedef const _Tp& reference; - typedef _CharT char_type; - typedef _Traits traits_type; - typedef basic_istream<_CharT, _Traits> istream_type; - -private: - istream_type* __in_stream_; - _Tp __value_; - -public: - _LIBCPP_HIDE_FROM_ABI istream_iterator() : __in_stream_(nullptr), __value_() {} - _LIBCPP_HIDE_FROM_ABI istream_iterator(istream_type& __s) : __in_stream_(std::addressof(__s)) { - if (!(*__in_stream_ >> __value_)) - __in_stream_ = nullptr; - } - - _LIBCPP_HIDE_FROM_ABI const _Tp& operator*() const { return __value_; } - _LIBCPP_HIDE_FROM_ABI const _Tp* operator->() const { return std::addressof((operator*())); } - _LIBCPP_HIDE_FROM_ABI istream_iterator& operator++() { - if (!(*__in_stream_ >> __value_)) - __in_stream_ = nullptr; - return *this; - } - _LIBCPP_HIDE_FROM_ABI istream_iterator operator++(int) { - istream_iterator __t(*this); - ++(*this); - return __t; - } - - template - friend _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, - const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); -}; - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, - const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) { - return __x.__in_stream_ == __y.__in_stream_; -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, - const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) { - return !(__x == __y); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_ISTREAM_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/istreambuf_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/istreambuf_iterator.h deleted file mode 100644 index 37c81bb..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/istreambuf_iterator.h +++ /dev/null @@ -1,94 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ISTREAMBUF_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_ISTREAMBUF_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/istream.h> -#include <__cxx03/__fwd/streambuf.h> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -class _LIBCPP_TEMPLATE_VIS istreambuf_iterator - : public iterator { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -public: - typedef input_iterator_tag iterator_category; - typedef _CharT value_type; - typedef typename _Traits::off_type difference_type; - typedef _CharT* pointer; - typedef _CharT reference; - typedef _CharT char_type; - typedef _Traits traits_type; - typedef typename _Traits::int_type int_type; - typedef basic_streambuf<_CharT, _Traits> streambuf_type; - typedef basic_istream<_CharT, _Traits> istream_type; - -private: - mutable streambuf_type* __sbuf_; - - class __proxy { - char_type __keep_; - streambuf_type* __sbuf_; - _LIBCPP_HIDE_FROM_ABI explicit __proxy(char_type __c, streambuf_type* __s) : __keep_(__c), __sbuf_(__s) {} - friend class istreambuf_iterator; - - public: - _LIBCPP_HIDE_FROM_ABI char_type operator*() const { return __keep_; } - }; - - _LIBCPP_HIDE_FROM_ABI bool __test_for_eof() const { - if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) - __sbuf_ = nullptr; - return __sbuf_ == nullptr; - } - -public: - _LIBCPP_HIDE_FROM_ABI istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {} - _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(istream_type& __s) _NOEXCEPT : __sbuf_(__s.rdbuf()) {} - _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(streambuf_type* __s) _NOEXCEPT : __sbuf_(__s) {} - _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(const __proxy& __p) _NOEXCEPT : __sbuf_(__p.__sbuf_) {} - - _LIBCPP_HIDE_FROM_ABI char_type operator*() const { return static_cast(__sbuf_->sgetc()); } - _LIBCPP_HIDE_FROM_ABI istreambuf_iterator& operator++() { - __sbuf_->sbumpc(); - return *this; - } - _LIBCPP_HIDE_FROM_ABI __proxy operator++(int) { return __proxy(__sbuf_->sbumpc(), __sbuf_); } - - _LIBCPP_HIDE_FROM_ABI bool equal(const istreambuf_iterator& __b) const { - return __test_for_eof() == __b.__test_for_eof(); - } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator==(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) { - return __a.equal(__b); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool -operator!=(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) { - return !__a.equal(__b); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_ISTREAMBUF_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator.h deleted file mode 100644 index 8fbe973..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator.h +++ /dev/null @@ -1,33 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS iterator { - typedef _Tp value_type; - typedef _Distance difference_type; - typedef _Pointer pointer; - typedef _Reference reference; - typedef _Category iterator_category; -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator_traits.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator_traits.h deleted file mode 100644 index 9b27911..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/iterator_traits.h +++ /dev/null @@ -1,246 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_ITERATOR_TRAITS_H -#define _LIBCPP___CXX03___ITERATOR_ITERATOR_TRAITS_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/pair.h> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__type_traits/disjunction.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/__type_traits/is_object.h> -#include <__cxx03/__type_traits/is_primary_template.h> -#include <__cxx03/__type_traits/is_reference.h> -#include <__cxx03/__type_traits/is_valid_expansion.h> -#include <__cxx03/__type_traits/remove_const.h> -#include <__cxx03/__type_traits/remove_cv.h> -#include <__cxx03/__type_traits/remove_cvref.h> -#include <__cxx03/__type_traits/void_t.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct _LIBCPP_TEMPLATE_VIS iterator_traits; - -struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; -struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; -struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; -struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; -struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; - -template -struct __iter_traits_cache { - using type = _If< __is_primary_template >::value, _Iter, iterator_traits<_Iter> >; -}; -template -using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; - -struct __iter_concept_concept_test { - template - using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept; -}; -struct __iter_concept_category_test { - template - using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category; -}; -struct __iter_concept_random_fallback { - template - using _Apply = __enable_if_t< __is_primary_template >::value, random_access_iterator_tag >; -}; - -template -struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {}; - -template -struct __iter_concept_cache { - using type = _Or< __test_iter_concept<_Iter, __iter_concept_concept_test>, - __test_iter_concept<_Iter, __iter_concept_category_test>, - __test_iter_concept<_Iter, __iter_concept_random_fallback> >; -}; - -template -using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; - -template -struct __has_iterator_typedefs { -private: - template - static false_type __test(...); - template - static true_type - __test(__void_t* = nullptr, - __void_t* = nullptr, - __void_t* = nullptr, - __void_t* = nullptr, - __void_t* = nullptr); - -public: - static const bool value = decltype(__test<_Tp>(nullptr, nullptr, nullptr, nullptr, nullptr))::value; -}; - -template -struct __has_iterator_category { -private: - template - static false_type __test(...); - template - static true_type __test(typename _Up::iterator_category* = nullptr); - -public: - static const bool value = decltype(__test<_Tp>(nullptr))::value; -}; - -template -struct __has_iterator_concept { -private: - template - static false_type __test(...); - template - static true_type __test(typename _Up::iterator_concept* = nullptr); - -public: - static const bool value = decltype(__test<_Tp>(nullptr))::value; -}; - -template -struct __iterator_traits {}; - -template -struct __iterator_traits_impl {}; - -template -struct __iterator_traits_impl<_Iter, true> { - typedef typename _Iter::difference_type difference_type; - typedef typename _Iter::value_type value_type; - typedef typename _Iter::pointer pointer; - typedef typename _Iter::reference reference; - typedef typename _Iter::iterator_category iterator_category; -}; - -template -struct __iterator_traits<_Iter, true> - : __iterator_traits_impl< _Iter, - is_convertible::value || - is_convertible::value > {}; - -// iterator_traits will only have the nested types if Iterator::iterator_category -// exists. Else iterator_traits will be an empty class. This is a -// conforming extension which allows some programs to compile and behave as -// the client expects instead of failing at compile time. - -template -struct _LIBCPP_TEMPLATE_VIS iterator_traits : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> { - using __primary_template = iterator_traits; -}; - -template -struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> { - typedef ptrdiff_t difference_type; - typedef __remove_cv_t<_Tp> value_type; - typedef _Tp* pointer; - typedef _Tp& reference; - typedef random_access_iterator_tag iterator_category; -}; - -template >::value> -struct __has_iterator_category_convertible_to : is_convertible::iterator_category, _Up> { -}; - -template -struct __has_iterator_category_convertible_to<_Tp, _Up, false> : false_type {}; - -template ::value> -struct __has_iterator_concept_convertible_to : is_convertible {}; - -template -struct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {}; - -template -using __has_input_iterator_category = __has_iterator_category_convertible_to<_Tp, input_iterator_tag>; - -template -using __has_forward_iterator_category = __has_iterator_category_convertible_to<_Tp, forward_iterator_tag>; - -template -using __has_bidirectional_iterator_category = __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>; - -template -using __has_random_access_iterator_category = __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>; - -// __libcpp_is_contiguous_iterator determines if an iterator is known by -// libc++ to be contiguous, either because it advertises itself as such -// (in C++20) or because it is a pointer type or a known trivial wrapper -// around a (possibly fancy) pointer type, such as __wrap_iter. -// Such iterators receive special "contiguous" optimizations in -// std::copy and std::sort. -// -template -struct __libcpp_is_contiguous_iterator : false_type {}; - -// Any native pointer which is an iterator is also a contiguous iterator. -template -struct __libcpp_is_contiguous_iterator<_Up*> : true_type {}; - -template -class __wrap_iter; - -template -using __has_exactly_input_iterator_category = - integral_constant::value && - !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value>; - -template -using __has_exactly_forward_iterator_category = - integral_constant::value && - !__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value>; - -template -using __has_exactly_bidirectional_iterator_category = - integral_constant::value && - !__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>::value>; - -template -using __iter_value_type = typename iterator_traits<_InputIterator>::value_type; - -template -using __iter_key_type = __remove_const_t::value_type::first_type>; - -template -using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; - -template -using __iter_to_alloc_type = - pair::value_type::first_type, - typename iterator_traits<_InputIterator>::value_type::second_type>; - -template -using __iterator_category_type = typename iterator_traits<_Iter>::iterator_category; - -template -using __iterator_pointer_type = typename iterator_traits<_Iter>::pointer; - -template -using __iter_diff_t = typename iterator_traits<_Iter>::difference_type; - -template -using __iter_reference = typename iterator_traits<_Iter>::reference; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_ITERATOR_TRAITS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/move_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/move_iterator.h deleted file mode 100644 index c778bb3..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/move_iterator.h +++ /dev/null @@ -1,166 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_MOVE_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_MOVE_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_assignable.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/__type_traits/is_reference.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/remove_reference.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class _LIBCPP_TEMPLATE_VIS move_iterator { -public: - typedef _Iter iterator_type; - typedef _If< __has_random_access_iterator_category<_Iter>::value, - random_access_iterator_tag, - typename iterator_traits<_Iter>::iterator_category > - iterator_category; - typedef typename iterator_traits::value_type value_type; - typedef typename iterator_traits::difference_type difference_type; - typedef iterator_type pointer; - - typedef typename iterator_traits::reference __reference; - typedef __conditional_t::value, __libcpp_remove_reference_t<__reference>&&, __reference> - reference; - - _LIBCPP_HIDE_FROM_ABI explicit move_iterator(_Iter __i) : __current_(std::move(__i)) {} - - _LIBCPP_HIDE_FROM_ABI move_iterator& operator++() { - ++__current_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return __current_; } - - _LIBCPP_HIDE_FROM_ABI move_iterator() : __current_() {} - - template ::value && is_convertible::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI move_iterator(const move_iterator<_Up>& __u) : __current_(__u.base()) {} - - template ::value && is_convertible::value && - is_assignable<_Iter&, const _Up&>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI move_iterator& operator=(const move_iterator<_Up>& __u) { - __current_ = __u.base(); - return *this; - } - - _LIBCPP_HIDE_FROM_ABI _Iter base() const { return __current_; } - - _LIBCPP_HIDE_FROM_ABI reference operator*() const { return static_cast(*__current_); } - _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const { - return static_cast(__current_[__n]); - } - - _LIBCPP_HIDE_FROM_ABI move_iterator operator++(int) { - move_iterator __tmp(*this); - ++__current_; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI move_iterator& operator--() { - --__current_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI move_iterator operator--(int) { - move_iterator __tmp(*this); - --__current_; - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI move_iterator operator+(difference_type __n) const { return move_iterator(__current_ + __n); } - _LIBCPP_HIDE_FROM_ABI move_iterator& operator+=(difference_type __n) { - __current_ += __n; - return *this; - } - _LIBCPP_HIDE_FROM_ABI move_iterator operator-(difference_type __n) const { return move_iterator(__current_ - __n); } - _LIBCPP_HIDE_FROM_ABI move_iterator& operator-=(difference_type __n) { - __current_ -= __n; - return *this; - } - -private: - template - friend class move_iterator; - - _Iter __current_; -}; -_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_iterator); - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { - return __x.base() == __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { - return __x.base() != __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { - return __x.base() < __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { - return __x.base() > __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { - return __x.base() <= __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { - return __x.base() >= __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI typename move_iterator<_Iter1>::difference_type -operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { - return __x.base() - __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI move_iterator<_Iter> -operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) { - return move_iterator<_Iter>(__x.base() + __n); -} - -template -inline _LIBCPP_HIDE_FROM_ABI move_iterator<_Iter> make_move_iterator(_Iter __i) { - return move_iterator<_Iter>(std::move(__i)); -} - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___ITERATOR_MOVE_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/next.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/next.h deleted file mode 100644 index 16ebaed..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/next.h +++ /dev/null @@ -1,39 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_NEXT_H -#define _LIBCPP___CXX03___ITERATOR_NEXT_H - -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/enable_if.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _InputIter -next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) { - // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation. - // Note that this check duplicates the similar check in `std::advance`. - _LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value, - "Attempt to next(it, n) with negative n on a non-bidirectional iterator"); - - std::advance(__x, __n); - return __x; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_NEXT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostream_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostream_iterator.h deleted file mode 100644 index 3e00ce2..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostream_iterator.h +++ /dev/null @@ -1,67 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_OSTREAM_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_OSTREAM_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__fwd/ostream.h> -#include <__cxx03/__fwd/string.h> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template > -class _LIBCPP_TEMPLATE_VIS ostream_iterator : public iterator { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -public: - typedef output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - typedef _CharT char_type; - typedef _Traits traits_type; - typedef basic_ostream<_CharT, _Traits> ostream_type; - -private: - ostream_type* __out_stream_; - const char_type* __delim_; - -public: - _LIBCPP_HIDE_FROM_ABI ostream_iterator(ostream_type& __s) _NOEXCEPT - : __out_stream_(std::addressof(__s)), - __delim_(nullptr) {} - _LIBCPP_HIDE_FROM_ABI ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT - : __out_stream_(std::addressof(__s)), - __delim_(__delimiter) {} - _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator=(const _Tp& __value) { - *__out_stream_ << __value; - if (__delim_) - *__out_stream_ << __delim_; - return *this; - } - - _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator*() { return *this; } - _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator++() { return *this; } - _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator++(int) { return *this; } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_OSTREAM_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostreambuf_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostreambuf_iterator.h deleted file mode 100644 index 27c8152..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/ostreambuf_iterator.h +++ /dev/null @@ -1,64 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_OSTREAMBUF_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_OSTREAMBUF_ITERATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/cstddef> -#include <__cxx03/iosfwd> // for forward declaration of basic_streambuf - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator : public iterator { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -public: - typedef output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - typedef _CharT char_type; - typedef _Traits traits_type; - typedef basic_streambuf<_CharT, _Traits> streambuf_type; - typedef basic_ostream<_CharT, _Traits> ostream_type; - -private: - streambuf_type* __sbuf_; - -public: - _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator(ostream_type& __s) _NOEXCEPT : __sbuf_(__s.rdbuf()) {} - _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT : __sbuf_(__s) {} - _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator=(_CharT __c) { - if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) - __sbuf_ = nullptr; - return *this; - } - _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator*() { return *this; } - _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++() { return *this; } - _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++(int) { return *this; } - _LIBCPP_HIDE_FROM_ABI bool failed() const _NOEXCEPT { return __sbuf_ == nullptr; } - - template - friend _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_Ch, _Tr> __pad_and_output( - ostreambuf_iterator<_Ch, _Tr> __s, const _Ch* __ob, const _Ch* __op, const _Ch* __oe, ios_base& __iob, _Ch __fl); -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_OSTREAMBUF_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/prev.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/prev.h deleted file mode 100644 index 32f6e66..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/prev.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_PREV_H -#define _LIBCPP___CXX03___ITERATOR_PREV_H - -#include <__cxx03/__assert> -#include <__cxx03/__config> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _InputIter -prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n) { - // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation. - // Note that this check duplicates the similar check in `std::advance`. - _LIBCPP_ASSERT_PEDANTIC(__n <= 0 || __has_bidirectional_iterator_category<_InputIter>::value, - "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator"); - std::advance(__x, -__n); - return __x; -} - -// LWG 3197 -// It is unclear what the implications of "BidirectionalIterator" in the standard are. -// However, calling std::prev(non-bidi-iterator) is obviously an error and we should catch it at compile time. -template ::value, int> = 0> -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _InputIter prev(_InputIter __it) { - static_assert(__has_bidirectional_iterator_category<_InputIter>::value, - "Attempt to prev(it) with a non-bidirectional iterator"); - return std::prev(std::move(__it), 1); -} - -_LIBCPP_POP_MACROS - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_PREV_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/reverse_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/reverse_iterator.h deleted file mode 100644 index b06dad1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/reverse_iterator.h +++ /dev/null @@ -1,203 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_REVERSE_ITERATOR_H -#define _LIBCPP___CXX03___ITERATOR_REVERSE_ITERATOR_H - -#include <__cxx03/__algorithm/unwrap_iter.h> -#include <__cxx03/__config> -#include <__cxx03/__iterator/advance.h> -#include <__cxx03/__iterator/iterator.h> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__iterator/next.h> -#include <__cxx03/__iterator/prev.h> -#include <__cxx03/__iterator/segmented_iterator.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__type_traits/conditional.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_assignable.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/__type_traits/is_nothrow_constructible.h> -#include <__cxx03/__type_traits/is_pointer.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/move.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -class _LIBCPP_TEMPLATE_VIS reverse_iterator - : public iterator::iterator_category, - typename iterator_traits<_Iter>::value_type, - typename iterator_traits<_Iter>::difference_type, - typename iterator_traits<_Iter>::pointer, - typename iterator_traits<_Iter>::reference> { - _LIBCPP_SUPPRESS_DEPRECATED_POP - -private: -#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES - _Iter __t_; // no longer used as of LWG #2360, not removed due to ABI break -#endif - -protected: - _Iter current; - -public: - using iterator_type = _Iter; - - using iterator_category = - _If<__has_random_access_iterator_category<_Iter>::value, - random_access_iterator_tag, - typename iterator_traits<_Iter>::iterator_category>; - using pointer = typename iterator_traits<_Iter>::pointer; - using value_type = typename iterator_traits<_Iter>::value_type; - using difference_type = typename iterator_traits<_Iter>::difference_type; - using reference = typename iterator_traits<_Iter>::reference; - -#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES - _LIBCPP_HIDE_FROM_ABI reverse_iterator() : __t_(), current() {} - - _LIBCPP_HIDE_FROM_ABI explicit reverse_iterator(_Iter __x) : __t_(__x), current(__x) {} - - template ::value && is_convertible<_Up const&, _Iter>::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI reverse_iterator(const reverse_iterator<_Up>& __u) : __t_(__u.base()), current(__u.base()) {} - - template ::value && is_convertible<_Up const&, _Iter>::value && - is_assignable<_Iter&, _Up const&>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI reverse_iterator& operator=(const reverse_iterator<_Up>& __u) { - __t_ = current = __u.base(); - return *this; - } -#else - _LIBCPP_HIDE_FROM_ABI reverse_iterator() : current() {} - - _LIBCPP_HIDE_FROM_ABI explicit reverse_iterator(_Iter __x) : current(__x) {} - - template ::value && is_convertible<_Up const&, _Iter>::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI reverse_iterator(const reverse_iterator<_Up>& __u) : current(__u.base()) {} - - template ::value && is_convertible<_Up const&, _Iter>::value && - is_assignable<_Iter&, _Up const&>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI reverse_iterator& operator=(const reverse_iterator<_Up>& __u) { - current = __u.base(); - return *this; - } -#endif - _LIBCPP_HIDE_FROM_ABI _Iter base() const { return current; } - _LIBCPP_HIDE_FROM_ABI reference operator*() const { - _Iter __tmp = current; - return *--__tmp; - } - - _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return std::addressof(operator*()); } - - _LIBCPP_HIDE_FROM_ABI reverse_iterator& operator++() { - --current; - return *this; - } - _LIBCPP_HIDE_FROM_ABI reverse_iterator operator++(int) { - reverse_iterator __tmp(*this); - --current; - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI reverse_iterator& operator--() { - ++current; - return *this; - } - _LIBCPP_HIDE_FROM_ABI reverse_iterator operator--(int) { - reverse_iterator __tmp(*this); - ++current; - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI reverse_iterator operator+(difference_type __n) const { - return reverse_iterator(current - __n); - } - _LIBCPP_HIDE_FROM_ABI reverse_iterator& operator+=(difference_type __n) { - current -= __n; - return *this; - } - _LIBCPP_HIDE_FROM_ABI reverse_iterator operator-(difference_type __n) const { - return reverse_iterator(current + __n); - } - _LIBCPP_HIDE_FROM_ABI reverse_iterator& operator-=(difference_type __n) { - current += __n; - return *this; - } - _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const { return *(*this + __n); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { - return __x.base() == __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { - return __x.base() > __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { - return __x.base() != __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { - return __x.base() < __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { - return __x.base() <= __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { - return __x.base() >= __y.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI typename reverse_iterator<_Iter1>::difference_type -operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { - return __y.base() - __x.base(); -} - -template -inline _LIBCPP_HIDE_FROM_ABI reverse_iterator<_Iter> -operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) { - return reverse_iterator<_Iter>(__x.base() - __n); -} - -template -struct __unwrap_iter_impl >, __b> { - using _UnwrappedIter = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>())); - using _ReverseWrapper = reverse_iterator >; - - static _LIBCPP_HIDE_FROM_ABI _ReverseWrapper __rewrap(_ReverseWrapper __orig_iter, _UnwrappedIter __unwrapped_iter) { - return _ReverseWrapper( - reverse_iterator<_Iter>(__unwrap_iter_impl<_Iter>::__rewrap(__orig_iter.base().base(), __unwrapped_iter))); - } - - static _LIBCPP_HIDE_FROM_ABI _UnwrappedIter __unwrap(_ReverseWrapper __i) _NOEXCEPT { - return __unwrap_iter_impl<_Iter>::__unwrap(__i.base().base()); - } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_REVERSE_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/segmented_iterator.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/segmented_iterator.h deleted file mode 100644 index 7e353d6..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/segmented_iterator.h +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___SEGMENTED_ITERATOR_H -#define _LIBCPP___CXX03___SEGMENTED_ITERATOR_H - -// Segmented iterators are iterators over (not necessarily contiguous) sub-ranges. -// -// For example, std::deque stores its data into multiple blocks of contiguous memory, -// which are not stored contiguously themselves. The concept of segmented iterators -// allows algorithms to operate over these multi-level iterators natively, opening the -// door to various optimizations. See http://lafstern.org/matt/segmented.pdf for details. -// -// If __segmented_iterator_traits can be instantiated, the following functions and associated types must be provided: -// - Traits::__local_iterator -// The type of iterators used to iterate inside a segment. -// -// - Traits::__segment_iterator -// The type of iterators used to iterate over segments. -// Segment iterators can be forward iterators or bidirectional iterators, depending on the -// underlying data structure. -// -// - static __segment_iterator Traits::__segment(It __it) -// Returns an iterator to the segment that the provided iterator is in. -// -// - static __local_iterator Traits::__local(It __it) -// Returns the local iterator pointing to the element that the provided iterator points to. -// -// - static __local_iterator Traits::__begin(__segment_iterator __it) -// Returns the local iterator to the beginning of the segment that the provided iterator is pointing into. -// -// - static __local_iterator Traits::__end(__segment_iterator __it) -// Returns the one-past-the-end local iterator to the segment that the provided iterator is pointing into. -// -// - static It Traits::__compose(__segment_iterator, __local_iterator) -// Returns the iterator composed of the segment iterator and local iterator. - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/integral_constant.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __segmented_iterator_traits; -/* exposition-only: -{ - using __segment_iterator = ...; - using __local_iterator = ...; - - static __segment_iterator __segment(_Iterator); - static __local_iterator __local(_Iterator); - static __local_iterator __begin(__segment_iterator); - static __local_iterator __end(__segment_iterator); - static _Iterator __compose(__segment_iterator, __local_iterator); -}; -*/ - -template -struct __has_specialization : false_type {}; - -template -struct __has_specialization<_Tp, sizeof(_Tp) * 0> : true_type {}; - -template -using __is_segmented_iterator = __has_specialization<__segmented_iterator_traits<_Iterator> >; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___SEGMENTED_ITERATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/wrap_iter.h b/third_party/libcxx/include/c++/v1/__cxx03/__iterator/wrap_iter.h deleted file mode 100644 index 22c9e2d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__iterator/wrap_iter.h +++ /dev/null @@ -1,188 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H -#define _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H - -#include <__cxx03/__config> -#include <__cxx03/__iterator/iterator_traits.h> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_convertible.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __wrap_iter { -public: - typedef _Iter iterator_type; - typedef typename iterator_traits::value_type value_type; - typedef typename iterator_traits::difference_type difference_type; - typedef typename iterator_traits::pointer pointer; - typedef typename iterator_traits::reference reference; - typedef typename iterator_traits::iterator_category iterator_category; - -private: - iterator_type __i_; - -public: - _LIBCPP_HIDE_FROM_ABI __wrap_iter() _NOEXCEPT : __i_() {} - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI __wrap_iter(const __wrap_iter<_Up>& __u) _NOEXCEPT : __i_(__u.base()) {} - _LIBCPP_HIDE_FROM_ABI reference operator*() const _NOEXCEPT { return *__i_; } - _LIBCPP_HIDE_FROM_ABI pointer operator->() const _NOEXCEPT { return std::__to_address(__i_); } - _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator++() _NOEXCEPT { - ++__i_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI __wrap_iter operator++(int) _NOEXCEPT { - __wrap_iter __tmp(*this); - ++(*this); - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator--() _NOEXCEPT { - --__i_; - return *this; - } - _LIBCPP_HIDE_FROM_ABI __wrap_iter operator--(int) _NOEXCEPT { - __wrap_iter __tmp(*this); - --(*this); - return __tmp; - } - _LIBCPP_HIDE_FROM_ABI __wrap_iter operator+(difference_type __n) const _NOEXCEPT { - __wrap_iter __w(*this); - __w += __n; - return __w; - } - _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator+=(difference_type __n) _NOEXCEPT { - __i_ += __n; - return *this; - } - _LIBCPP_HIDE_FROM_ABI __wrap_iter operator-(difference_type __n) const _NOEXCEPT { return *this + (-__n); } - _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator-=(difference_type __n) _NOEXCEPT { - *this += -__n; - return *this; - } - _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const _NOEXCEPT { return __i_[__n]; } - - _LIBCPP_HIDE_FROM_ABI iterator_type base() const _NOEXCEPT { return __i_; } - -private: - _LIBCPP_HIDE_FROM_ABI explicit __wrap_iter(iterator_type __x) _NOEXCEPT : __i_(__x) {} - - template - friend class __wrap_iter; - template - friend class basic_string; - template - friend class basic_string_view; - template - friend class _LIBCPP_TEMPLATE_VIS vector; - template - friend class _LIBCPP_TEMPLATE_VIS span; - template - friend struct array; -}; - -template -_LIBCPP_HIDE_FROM_ABI bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return __x.base() == __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return __x.base() == __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return __x.base() < __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return __x.base() < __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return !(__x == __y); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return !(__x == __y); -} - -// TODO(mordante) disable these overloads in the LLVM 20 release. -template -_LIBCPP_HIDE_FROM_ABI bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return __y < __x; -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return __y < __x; -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return !(__x < __y); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return !(__x < __y); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { - return !(__y < __x); -} - -template -_LIBCPP_HIDE_FROM_ABI bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return !(__y < __x); -} - -template -_LIBCPP_HIDE_FROM_ABI typename __wrap_iter<_Iter1>::difference_type -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { - return __x.base() - __y.base(); -} - -template -_LIBCPP_HIDE_FROM_ABI __wrap_iter<_Iter1> -operator+(typename __wrap_iter<_Iter1>::difference_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT { - __x += __n; - return __x; -} - -template -struct __libcpp_is_contiguous_iterator<__wrap_iter<_It> > : true_type {}; - -template -struct _LIBCPP_TEMPLATE_VIS pointer_traits<__wrap_iter<_It> > { - typedef __wrap_iter<_It> pointer; - typedef typename pointer_traits<_It>::element_type element_type; - typedef typename pointer_traits<_It>::difference_type difference_type; - - _LIBCPP_HIDE_FROM_ABI static element_type* to_address(pointer __w) _NOEXCEPT { return std::__to_address(__w.base()); } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale b/third_party/libcxx/include/c++/v1/__cxx03/__locale deleted file mode 100644 index e9cbc1f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale +++ /dev/null @@ -1,1495 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE -#define _LIBCPP___CXX03___LOCALE - -#include <__cxx03/__config> -#include <__cxx03/__locale_dir/locale_base_api.h> -#include <__cxx03/__memory/shared_ptr.h> // __shared_count -#include <__cxx03/__mutex/once_flag.h> -#include <__cxx03/__type_traits/make_unsigned.h> -#include <__cxx03/__utility/no_destroy.h> -#include <__cxx03/__utility/private_constructor_tag.h> -#include <__cxx03/cctype> -#include <__cxx03/clocale> -#include <__cxx03/cstdint> -#include <__cxx03/cstdlib> -#include <__cxx03/string> - -// Some platforms require more includes than others. Keep the includes on all plaforms for now. -#include <__cxx03/cstddef> -#include <__cxx03/cstring> - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -# include <__cxx03/cwchar> -#else -# include <__cxx03/__std_mbstate_t.h> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -class _LIBCPP_EXPORTED_FROM_ABI locale; - -template -_LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT; - -template -_LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&); - -class _LIBCPP_EXPORTED_FROM_ABI locale { -public: - // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor. - using __trivially_relocatable = locale; - - // types: - class _LIBCPP_EXPORTED_FROM_ABI facet; - class _LIBCPP_EXPORTED_FROM_ABI id; - - typedef int category; - - static const category // values assigned here are for exposition only - none = 0, - collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK, - time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages; - - // construct/copy/destroy: - locale() _NOEXCEPT; - locale(const locale&) _NOEXCEPT; - explicit locale(const char*); - explicit locale(const string&); - locale(const locale&, const char*, category); - locale(const locale&, const string&, category); - template - _LIBCPP_HIDE_FROM_ABI locale(const locale&, _Facet*); - locale(const locale&, const locale&, category); - - ~locale(); - - const locale& operator=(const locale&) _NOEXCEPT; - - template - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS locale combine(const locale&) const; - - // locale operations: - string name() const; - bool operator==(const locale&) const; - _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); } - template - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool - operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const; - - // global locale objects: - static locale global(const locale&); - static const locale& classic(); - -private: - class __imp; - __imp* __locale_; - - template - friend struct __no_destroy; - _LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* __loc) : __locale_(__loc) {} - - void __install_ctor(const locale&, facet*, long); - static locale& __global(); - bool has_facet(id&) const; - const facet* use_facet(id&) const; - - template - friend bool has_facet(const locale&) _NOEXCEPT; - template - friend const _Facet& use_facet(const locale&); -}; - -class _LIBCPP_EXPORTED_FROM_ABI locale::facet : public __shared_count { -protected: - _LIBCPP_HIDE_FROM_ABI explicit facet(size_t __refs = 0) : __shared_count(static_cast(__refs) - 1) {} - - ~facet() override; - - // facet(const facet&) = delete; // effectively done in __shared_count - // void operator=(const facet&) = delete; - -private: - void __on_zero_shared() _NOEXCEPT override; -}; - -class _LIBCPP_EXPORTED_FROM_ABI locale::id { - once_flag __flag_; - int32_t __id_; - - static int32_t __next_id; - -public: - _LIBCPP_HIDE_FROM_ABI id() : __id_(0) {} - void operator=(const id&) = delete; - id(const id&) = delete; - -public: // only needed for tests - long __get(); - - friend class locale; - friend class locale::__imp; -}; - -template -inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f) { - __install_ctor(__other, __f, __f ? __f->id.__get() : 0); -} - -template -locale locale::combine(const locale& __other) const { - if (!std::has_facet<_Facet>(__other)) - __throw_runtime_error("locale::combine: locale missing facet"); - - return locale(*this, &const_cast<_Facet&>(std::use_facet<_Facet>(__other))); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT { - return __l.has_facet(_Facet::id); -} - -template -inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) { - return static_cast(*__l.use_facet(_Facet::id)); -} - -// template class collate; - -template -class _LIBCPP_TEMPLATE_VIS collate : public locale::facet { -public: - typedef _CharT char_type; - typedef basic_string string_type; - - _LIBCPP_HIDE_FROM_ABI explicit collate(size_t __refs = 0) : locale::facet(__refs) {} - - _LIBCPP_HIDE_FROM_ABI int - compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const { - return do_compare(__lo1, __hi1, __lo2, __hi2); - } - - // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work - // around a dllimport bug that expects an external instantiation. - _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type - transform(const char_type* __lo, const char_type* __hi) const { - return do_transform(__lo, __hi); - } - - _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); } - - static locale::id id; - -protected: - ~collate() override; - virtual int - do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const; - virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const { - return string_type(__lo, __hi); - } - virtual long do_hash(const char_type* __lo, const char_type* __hi) const; -}; - -template -locale::id collate<_CharT>::id; - -template -collate<_CharT>::~collate() {} - -template -int collate<_CharT>::do_compare( - const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const { - for (; __lo2 != __hi2; ++__lo1, ++__lo2) { - if (__lo1 == __hi1 || *__lo1 < *__lo2) - return -1; - if (*__lo2 < *__lo1) - return 1; - } - return __lo1 != __hi1; -} - -template -long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const { - size_t __h = 0; - const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8; - const size_t __mask = size_t(0xF) << (__sr + 4); - for (const char_type* __p = __lo; __p != __hi; ++__p) { - __h = (__h << 4) + static_cast(*__p); - size_t __g = __h & __mask; - __h ^= __g | (__g >> __sr); - } - return static_cast(__h); -} - -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate; -#endif - -// template class collate_byname; - -template -class _LIBCPP_TEMPLATE_VIS collate_byname; - -template <> -class _LIBCPP_EXPORTED_FROM_ABI collate_byname : public collate { - locale_t __l_; - -public: - typedef char char_type; - typedef basic_string string_type; - - explicit collate_byname(const char* __n, size_t __refs = 0); - explicit collate_byname(const string& __n, size_t __refs = 0); - -protected: - ~collate_byname() override; - int do_compare( - const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override; - string_type do_transform(const char_type* __lo, const char_type* __hi) const override; -}; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -class _LIBCPP_EXPORTED_FROM_ABI collate_byname : public collate { - locale_t __l_; - -public: - typedef wchar_t char_type; - typedef basic_string string_type; - - explicit collate_byname(const char* __n, size_t __refs = 0); - explicit collate_byname(const string& __n, size_t __refs = 0); - -protected: - ~collate_byname() override; - - int do_compare( - const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override; - string_type do_transform(const char_type* __lo, const char_type* __hi) const override; -}; -#endif - -template -bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, - const basic_string<_CharT, _Traits, _Allocator>& __y) const { - return std::use_facet >(*this).compare( - __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0; -} - -// template class ctype - -class _LIBCPP_EXPORTED_FROM_ABI ctype_base { -public: -#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE) - typedef unsigned long mask; - static const mask space = 1 << 0; - static const mask print = 1 << 1; - static const mask cntrl = 1 << 2; - static const mask upper = 1 << 3; - static const mask lower = 1 << 4; - static const mask alpha = 1 << 5; - static const mask digit = 1 << 6; - static const mask punct = 1 << 7; - static const mask xdigit = 1 << 8; - static const mask blank = 1 << 9; -# if defined(__BIONIC__) - // Historically this was a part of regex_traits rather than ctype_base. The - // historical value of the constant is preserved for ABI compatibility. - static const mask __regex_word = 0x8000; -# else - static const mask __regex_word = 1 << 10; -# endif // defined(__BIONIC__) -#elif defined(__GLIBC__) - typedef unsigned short mask; - static const mask space = _ISspace; - static const mask print = _ISprint; - static const mask cntrl = _IScntrl; - static const mask upper = _ISupper; - static const mask lower = _ISlower; - static const mask alpha = _ISalpha; - static const mask digit = _ISdigit; - static const mask punct = _ISpunct; - static const mask xdigit = _ISxdigit; - static const mask blank = _ISblank; -# if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN) - static const mask __regex_word = static_cast(_ISbit(15)); -# else - static const mask __regex_word = 0x80; -# endif -#elif defined(_LIBCPP_MSVCRT_LIKE) - typedef unsigned short mask; - static const mask space = _SPACE; - static const mask print = _BLANK | _PUNCT | _ALPHA | _DIGIT; - static const mask cntrl = _CONTROL; - static const mask upper = _UPPER; - static const mask lower = _LOWER; - static const mask alpha = _ALPHA; - static const mask digit = _DIGIT; - static const mask punct = _PUNCT; - static const mask xdigit = _HEX; - static const mask blank = _BLANK; - static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA -#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) -# ifdef __APPLE__ - typedef __uint32_t mask; -# elif defined(__FreeBSD__) - typedef unsigned long mask; -# elif defined(__NetBSD__) - typedef unsigned short mask; -# endif - static const mask space = _CTYPE_S; - static const mask print = _CTYPE_R; - static const mask cntrl = _CTYPE_C; - static const mask upper = _CTYPE_U; - static const mask lower = _CTYPE_L; - static const mask alpha = _CTYPE_A; - static const mask digit = _CTYPE_D; - static const mask punct = _CTYPE_P; - static const mask xdigit = _CTYPE_X; - -# if defined(__NetBSD__) - static const mask blank = _CTYPE_BL; - // NetBSD defines classes up to 0x2000 - // see sys/ctype_bits.h, _CTYPE_Q - static const mask __regex_word = 0x8000; -# else - static const mask blank = _CTYPE_B; - static const mask __regex_word = 0x80; -# endif -#elif defined(_AIX) - typedef unsigned int mask; - static const mask space = _ISSPACE; - static const mask print = _ISPRINT; - static const mask cntrl = _ISCNTRL; - static const mask upper = _ISUPPER; - static const mask lower = _ISLOWER; - static const mask alpha = _ISALPHA; - static const mask digit = _ISDIGIT; - static const mask punct = _ISPUNCT; - static const mask xdigit = _ISXDIGIT; - static const mask blank = _ISBLANK; - static const mask __regex_word = 0x8000; -#elif _LIBCPP_LIBC_NEWLIB - // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. - typedef char mask; - // In case char is signed, static_cast is needed to avoid warning on - // positive value becomming negative. - static const mask space = static_cast(_S); - static const mask print = static_cast(_P | _U | _L | _N | _B); - static const mask cntrl = static_cast(_C); - static const mask upper = static_cast(_U); - static const mask lower = static_cast(_L); - static const mask alpha = static_cast(_U | _L); - static const mask digit = static_cast(_N); - static const mask punct = static_cast(_P); - static const mask xdigit = static_cast(_X | _N); - static const mask blank = static_cast(_B); - // mask is already fully saturated, use a different type in regex_type_traits. - static const unsigned short __regex_word = 0x100; -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT -#elif defined(__MVS__) -# if defined(__NATIVE_ASCII_F) - typedef unsigned int mask; - static const mask space = _ISSPACE_A; - static const mask print = _ISPRINT_A; - static const mask cntrl = _ISCNTRL_A; - static const mask upper = _ISUPPER_A; - static const mask lower = _ISLOWER_A; - static const mask alpha = _ISALPHA_A; - static const mask digit = _ISDIGIT_A; - static const mask punct = _ISPUNCT_A; - static const mask xdigit = _ISXDIGIT_A; - static const mask blank = _ISBLANK_A; -# else - typedef unsigned short mask; - static const mask space = __ISSPACE; - static const mask print = __ISPRINT; - static const mask cntrl = __ISCNTRL; - static const mask upper = __ISUPPER; - static const mask lower = __ISLOWER; - static const mask alpha = __ISALPHA; - static const mask digit = __ISDIGIT; - static const mask punct = __ISPUNCT; - static const mask xdigit = __ISXDIGIT; - static const mask blank = __ISBLANK; -# endif - static const mask __regex_word = 0x8000; -#else -# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE? -#endif - static const mask alnum = alpha | digit; - static const mask graph = alnum | punct; - - _LIBCPP_HIDE_FROM_ABI ctype_base() {} - - static_assert((__regex_word & ~(std::make_unsigned::type)(space | print | cntrl | upper | lower | alpha | - digit | punct | xdigit | blank)) == __regex_word, - "__regex_word can't overlap other bits"); -}; - -template -class _LIBCPP_TEMPLATE_VIS ctype; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -class _LIBCPP_EXPORTED_FROM_ABI ctype : public locale::facet, public ctype_base { -public: - typedef wchar_t char_type; - - _LIBCPP_HIDE_FROM_ABI explicit ctype(size_t __refs = 0) : locale::facet(__refs) {} - - _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); } - - _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { - return do_is(__low, __high, __vec); - } - - _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { - return do_scan_is(__m, __low, __high); - } - - _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { - return do_scan_not(__m, __low, __high); - } - - _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } - - _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const { - return do_toupper(__low, __high); - } - - _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } - - _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const { - return do_tolower(__low, __high); - } - - _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } - - _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const { - return do_widen(__low, __high, __to); - } - - _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } - - _LIBCPP_HIDE_FROM_ABI const char_type* - narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { - return do_narrow(__low, __high, __dfault, __to); - } - - static locale::id id; - -protected: - ~ctype() override; - virtual bool do_is(mask __m, char_type __c) const; - virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; - virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; - virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; - virtual char_type do_toupper(char_type) const; - virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; - virtual char_type do_tolower(char_type) const; - virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; - virtual char_type do_widen(char) const; - virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; - virtual char do_narrow(char_type, char __dfault) const; - virtual const char_type* - do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; -}; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -template <> -class _LIBCPP_EXPORTED_FROM_ABI ctype : public locale::facet, public ctype_base { - const mask* __tab_; - bool __del_; - -public: - typedef char char_type; - - explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0); - - _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { - return isascii(__c) ? (__tab_[static_cast(__c)] & __m) != 0 : false; - } - - _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { - for (; __low != __high; ++__low, ++__vec) - *__vec = isascii(*__low) ? __tab_[static_cast(*__low)] : 0; - return __low; - } - - _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { - for (; __low != __high; ++__low) - if (isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) - break; - return __low; - } - - _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { - for (; __low != __high; ++__low) - if (!isascii(*__low) || !(__tab_[static_cast(*__low)] & __m)) - break; - return __low; - } - - _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } - - _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const { - return do_toupper(__low, __high); - } - - _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } - - _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const { - return do_tolower(__low, __high); - } - - _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } - - _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const { - return do_widen(__low, __high, __to); - } - - _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } - - _LIBCPP_HIDE_FROM_ABI const char* - narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { - return do_narrow(__low, __high, __dfault, __to); - } - - static locale::id id; - -#ifdef _CACHED_RUNES - static const size_t table_size = _CACHED_RUNES; -#else - static const size_t table_size = 256; -#endif - _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; } - static const mask* classic_table() _NOEXCEPT; - -protected: - ~ctype() override; - virtual char_type do_toupper(char_type __c) const; - virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; - virtual char_type do_tolower(char_type __c) const; - virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; - virtual char_type do_widen(char __c) const; - virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; - virtual char do_narrow(char_type __c, char __dfault) const; - virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; -}; - -// template class ctype_byname; - -template -class _LIBCPP_TEMPLATE_VIS ctype_byname; - -template <> -class _LIBCPP_EXPORTED_FROM_ABI ctype_byname : public ctype { - locale_t __l_; - -public: - explicit ctype_byname(const char*, size_t = 0); - explicit ctype_byname(const string&, size_t = 0); - -protected: - ~ctype_byname() override; - char_type do_toupper(char_type) const override; - const char_type* do_toupper(char_type* __low, const char_type* __high) const override; - char_type do_tolower(char_type) const override; - const char_type* do_tolower(char_type* __low, const char_type* __high) const override; -}; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -class _LIBCPP_EXPORTED_FROM_ABI ctype_byname : public ctype { - locale_t __l_; - -public: - explicit ctype_byname(const char*, size_t = 0); - explicit ctype_byname(const string&, size_t = 0); - -protected: - ~ctype_byname() override; - bool do_is(mask __m, char_type __c) const override; - const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override; - const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override; - const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override; - char_type do_toupper(char_type) const override; - const char_type* do_toupper(char_type* __low, const char_type* __high) const override; - char_type do_tolower(char_type) const override; - const char_type* do_tolower(char_type* __low, const char_type* __high) const override; - char_type do_widen(char) const override; - const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override; - char do_narrow(char_type, char __dfault) const override; - const char_type* - do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override; -}; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -template -inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::space, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::print, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::cntrl, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::upper, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::lower, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::alpha, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::digit, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::punct, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::xdigit, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::alnum, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::graph, __c); -} - -template -_LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).is(ctype_base::blank, __c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).toupper(__c); -} - -template -inline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) { - return std::use_facet >(__loc).tolower(__c); -} - -// codecvt_base - -class _LIBCPP_EXPORTED_FROM_ABI codecvt_base { -public: - _LIBCPP_HIDE_FROM_ABI codecvt_base() {} - enum result { ok, partial, error, noconv }; -}; - -// template class codecvt; - -template -class _LIBCPP_TEMPLATE_VIS codecvt; - -// template <> class codecvt - -template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { -public: - typedef char intern_type; - typedef char extern_type; - typedef mbstate_t state_type; - - _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} - - _LIBCPP_HIDE_FROM_ABI result - out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const { - return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { - return do_unshift(__st, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const { - return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } - - _LIBCPP_HIDE_FROM_ABI int - length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { - return do_length(__st, __frm, __end, __mx); - } - - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } - - static locale::id id; - -protected: - _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} - - ~codecvt() override; - - virtual result - do_out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const; - virtual result - do_in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const; - virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; - virtual int do_encoding() const _NOEXCEPT; - virtual bool do_always_noconv() const _NOEXCEPT; - virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; - virtual int do_max_length() const _NOEXCEPT; -}; - -// template <> class codecvt - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { - locale_t __l_; - -public: - typedef wchar_t intern_type; - typedef char extern_type; - typedef mbstate_t state_type; - - explicit codecvt(size_t __refs = 0); - - _LIBCPP_HIDE_FROM_ABI result - out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const { - return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { - return do_unshift(__st, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const { - return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } - - _LIBCPP_HIDE_FROM_ABI int - length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { - return do_length(__st, __frm, __end, __mx); - } - - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } - - static locale::id id; - -protected: - explicit codecvt(const char*, size_t __refs = 0); - - ~codecvt() override; - - virtual result - do_out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const; - virtual result - do_in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const; - virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; - virtual int do_encoding() const _NOEXCEPT; - virtual bool do_always_noconv() const _NOEXCEPT; - virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; - virtual int do_max_length() const _NOEXCEPT; -}; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -// template <> class codecvt // deprecated in C++20 - -template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { -public: - typedef char16_t intern_type; - typedef char extern_type; - typedef mbstate_t state_type; - - _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} - - _LIBCPP_HIDE_FROM_ABI result - out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const { - return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { - return do_unshift(__st, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const { - return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } - - _LIBCPP_HIDE_FROM_ABI int - length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { - return do_length(__st, __frm, __end, __mx); - } - - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } - - static locale::id id; - -protected: - _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} - - ~codecvt() override; - - virtual result - do_out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const; - virtual result - do_in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const; - virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; - virtual int do_encoding() const _NOEXCEPT; - virtual bool do_always_noconv() const _NOEXCEPT; - virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; - virtual int do_max_length() const _NOEXCEPT; -}; - -#ifndef _LIBCPP_HAS_NO_CHAR8_T - -// template <> class codecvt // C++20 - -template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { -public: - typedef char16_t intern_type; - typedef char8_t extern_type; - typedef mbstate_t state_type; - - _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} - - _LIBCPP_HIDE_FROM_ABI result - out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const { - return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { - return do_unshift(__st, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const { - return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } - - _LIBCPP_HIDE_FROM_ABI int - length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { - return do_length(__st, __frm, __end, __mx); - } - - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } - - static locale::id id; - -protected: - _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} - - ~codecvt() override; - - virtual result - do_out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const; - virtual result - do_in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const; - virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; - virtual int do_encoding() const _NOEXCEPT; - virtual bool do_always_noconv() const _NOEXCEPT; - virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; - virtual int do_max_length() const _NOEXCEPT; -}; - -#endif - -// template <> class codecvt // deprecated in C++20 - -template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { -public: - typedef char32_t intern_type; - typedef char extern_type; - typedef mbstate_t state_type; - - _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} - - _LIBCPP_HIDE_FROM_ABI result - out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const { - return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { - return do_unshift(__st, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const { - return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } - - _LIBCPP_HIDE_FROM_ABI int - length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { - return do_length(__st, __frm, __end, __mx); - } - - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } - - static locale::id id; - -protected: - _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} - - ~codecvt() override; - - virtual result - do_out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const; - virtual result - do_in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const; - virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; - virtual int do_encoding() const _NOEXCEPT; - virtual bool do_always_noconv() const _NOEXCEPT; - virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; - virtual int do_max_length() const _NOEXCEPT; -}; - -#ifndef _LIBCPP_HAS_NO_CHAR8_T - -// template <> class codecvt // C++20 - -template <> -class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { -public: - typedef char32_t intern_type; - typedef char8_t extern_type; - typedef mbstate_t state_type; - - _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} - - _LIBCPP_HIDE_FROM_ABI result - out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const { - return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { - return do_unshift(__st, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI result - in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const { - return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); - } - - _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } - - _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } - - _LIBCPP_HIDE_FROM_ABI int - length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { - return do_length(__st, __frm, __end, __mx); - } - - _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } - - static locale::id id; - -protected: - _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} - - ~codecvt() override; - - virtual result - do_out(state_type& __st, - const intern_type* __frm, - const intern_type* __frm_end, - const intern_type*& __frm_nxt, - extern_type* __to, - extern_type* __to_end, - extern_type*& __to_nxt) const; - virtual result - do_in(state_type& __st, - const extern_type* __frm, - const extern_type* __frm_end, - const extern_type*& __frm_nxt, - intern_type* __to, - intern_type* __to_end, - intern_type*& __to_nxt) const; - virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; - virtual int do_encoding() const _NOEXCEPT; - virtual bool do_always_noconv() const _NOEXCEPT; - virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; - virtual int do_max_length() const _NOEXCEPT; -}; - -#endif - -// template class codecvt_byname - -template -class _LIBCPP_TEMPLATE_VIS codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> { -public: - _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const char* __nm, size_t __refs = 0) - : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} - _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const string& __nm, size_t __refs = 0) - : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} - -protected: - ~codecvt_byname() override; -}; - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {} -_LIBCPP_SUPPRESS_DEPRECATED_POP - -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; -#endif -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // deprecated in C++20 -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // deprecated in C++20 -#ifndef _LIBCPP_HAS_NO_CHAR8_T -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20 -extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20 -#endif - -template -struct __narrow_to_utf8 { - template - _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; -}; - -template <> -struct __narrow_to_utf8<8> { - template - _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { - for (; __wb < __we; ++__wb, ++__s) - *__s = *__wb; - return __s; - } -}; - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template <> -struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt { - _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt(1) {} - _LIBCPP_SUPPRESS_DEPRECATED_POP - - ~__narrow_to_utf8() override; - - template - _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { - result __r = ok; - mbstate_t __mb; - while (__wb < __we && __r != error) { - const int __sz = 32; - char __buf[__sz]; - char* __bn; - const char16_t* __wn = (const char16_t*)__wb; - __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn); - if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) - __throw_runtime_error("locale not supported"); - for (const char* __p = __buf; __p < __bn; ++__p, ++__s) - *__s = *__p; - __wb = (const _CharT*)__wn; - } - return __s; - } -}; - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template <> -struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt { - _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt(1) {} - _LIBCPP_SUPPRESS_DEPRECATED_POP - - ~__narrow_to_utf8() override; - - template - _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { - result __r = ok; - mbstate_t __mb; - while (__wb < __we && __r != error) { - const int __sz = 32; - char __buf[__sz]; - char* __bn; - const char32_t* __wn = (const char32_t*)__wb; - __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn); - if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) - __throw_runtime_error("locale not supported"); - for (const char* __p = __buf; __p < __bn; ++__p, ++__s) - *__s = *__p; - __wb = (const _CharT*)__wn; - } - return __s; - } -}; - -template -struct __widen_from_utf8 { - template - _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; -}; - -template <> -struct __widen_from_utf8<8> { - template - _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { - for (; __nb < __ne; ++__nb, ++__s) - *__s = *__nb; - return __s; - } -}; - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template <> -struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt { - _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt(1) {} - _LIBCPP_SUPPRESS_DEPRECATED_POP - - ~__widen_from_utf8() override; - - template - _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { - result __r = ok; - mbstate_t __mb; - while (__nb < __ne && __r != error) { - const int __sz = 32; - char16_t __buf[__sz]; - char16_t* __bn; - const char* __nn = __nb; - __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn); - if (__r == codecvt_base::error || __nn == __nb) - __throw_runtime_error("locale not supported"); - for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) - *__s = *__p; - __nb = __nn; - } - return __s; - } -}; - -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template <> -struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt { - _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt(1) {} - _LIBCPP_SUPPRESS_DEPRECATED_POP - - ~__widen_from_utf8() override; - - template - _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { - result __r = ok; - mbstate_t __mb; - while (__nb < __ne && __r != error) { - const int __sz = 32; - char32_t __buf[__sz]; - char32_t* __bn; - const char* __nn = __nb; - __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn); - if (__r == codecvt_base::error || __nn == __nb) - __throw_runtime_error("locale not supported"); - for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) - *__s = *__p; - __nb = __nn; - } - return __s; - } -}; - -// template class numpunct - -template -class _LIBCPP_TEMPLATE_VIS numpunct; - -template <> -class _LIBCPP_EXPORTED_FROM_ABI numpunct : public locale::facet { -public: - typedef char char_type; - typedef basic_string string_type; - - explicit numpunct(size_t __refs = 0); - - _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } - _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } - _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } - _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } - _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } - - static locale::id id; - -protected: - ~numpunct() override; - virtual char_type do_decimal_point() const; - virtual char_type do_thousands_sep() const; - virtual string do_grouping() const; - virtual string_type do_truename() const; - virtual string_type do_falsename() const; - - char_type __decimal_point_; - char_type __thousands_sep_; - string __grouping_; -}; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -class _LIBCPP_EXPORTED_FROM_ABI numpunct : public locale::facet { -public: - typedef wchar_t char_type; - typedef basic_string string_type; - - explicit numpunct(size_t __refs = 0); - - _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } - _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } - _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } - _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } - _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } - - static locale::id id; - -protected: - ~numpunct() override; - virtual char_type do_decimal_point() const; - virtual char_type do_thousands_sep() const; - virtual string do_grouping() const; - virtual string_type do_truename() const; - virtual string_type do_falsename() const; - - char_type __decimal_point_; - char_type __thousands_sep_; - string __grouping_; -}; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -// template class numpunct_byname - -template -class _LIBCPP_TEMPLATE_VIS numpunct_byname; - -template <> -class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname : public numpunct { -public: - typedef char char_type; - typedef basic_string string_type; - - explicit numpunct_byname(const char* __nm, size_t __refs = 0); - explicit numpunct_byname(const string& __nm, size_t __refs = 0); - -protected: - ~numpunct_byname() override; - -private: - void __init(const char*); -}; - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -template <> -class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname : public numpunct { -public: - typedef wchar_t char_type; - typedef basic_string string_type; - - explicit numpunct_byname(const char* __nm, size_t __refs = 0); - explicit numpunct_byname(const string& __nm, size_t __refs = 0); - -protected: - ~numpunct_byname() override; - -private: - void __init(const char*); -}; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___LOCALE diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api.h deleted file mode 100644 index 3dbce82..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api.h +++ /dev/null @@ -1,98 +0,0 @@ -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_DIR_LOCALE_BASE_API_H -#define _LIBCPP___CXX03___LOCALE_DIR_LOCALE_BASE_API_H - -#if defined(_LIBCPP_MSVCRT_LIKE) -# include <__cxx03/__locale_dir/locale_base_api/win32.h> -#elif defined(_AIX) || defined(__MVS__) -# include <__cxx03/__locale_dir/locale_base_api/ibm.h> -#elif defined(__ANDROID__) -# include <__cxx03/__locale_dir/locale_base_api/android.h> -#elif defined(__sun__) -# include <__cxx03/__locale_dir/locale_base_api/solaris.h> -#elif _LIBCPP_LIBC_NEWLIB -# include <__cxx03/__locale_dir/locale_base_api/newlib.h> -#elif defined(__OpenBSD__) -# include <__cxx03/__locale_dir/locale_base_api/openbsd.h> -#elif defined(__Fuchsia__) -# include <__cxx03/__locale_dir/locale_base_api/fuchsia.h> -#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) -# include <__cxx03/__locale_dir/locale_base_api/musl.h> -#elif defined(__APPLE__) || defined(__FreeBSD__) -# include <__cxx03/xlocale.h> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -/* -The platform-specific headers have to provide the following interface: - -// TODO: rename this to __libcpp_locale_t -using locale_t = implementation-defined; - -implementation-defined __libcpp_mb_cur_max_l(locale_t); -wint_t __libcpp_btowc_l(int, locale_t); -int __libcpp_wctob_l(wint_t, locale_t); -size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, locale_t); -size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, locale_t); -size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, locale_t); -size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, locale_t); -int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, locale_t); -size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, locale_t); -lconv* __libcpp_localeconv_l(locale_t); -size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, locale_t); -int __libcpp_snprintf_l(char* dest, size_t buff_size, locale_t, const char* format, ...); -int __libcpp_asprintf_l(char** dest, locale_t, const char* format, ...); -int __libcpp_sscanf_l(const char* dest, locale_t, const char* format, ...); - -// TODO: change these to reserved names -float strtof_l(const char* str, char** str_end, locale_t); -double strtod_l(const char* str, char** str_end, locale_t); -long double strtold_l(const char* str, char** str_end, locale_t); -long long strtoll_l(const char* str, char** str_end, locale_t); -unsigned long long strtoull_l(const char* str, char** str_end, locale_t); - -locale_t newlocale(int category_mask, const char* locale, locale_t base); -void freelocale(locale_t); - -int islower_l(int ch, locale_t); -int isupper_l(int ch, locale_t); -int isdigit_l(int ch, locale_t); -int isxdigit_l(int ch, locale_t); -int strcoll_l(const char* lhs, const char* rhs, locale_t); -size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t); -int wcscoll_l(const char* lhs, const char* rhs, locale_t); -size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t); -int toupper_l(int ch, locale_t); -int tolower_l(int ch, locale_t); -int iswspace_l(wint_t ch, locale_t); -int iswprint_l(wint_t ch, locale_t); -int iswcntrl_l(wint_t ch, locale_t); -int iswupper_l(wint_t ch, locale_t); -int iswlower_l(wint_t ch, locale_t); -int iswalpha_l(wint_t ch, locale_t); -int iswblank_l(wint_t ch, locale_t); -int iswdigit_l(wint_t ch, locale_t); -int iswpunct_l(wint_t ch, locale_t); -int iswxdigit_l(wint_t ch, locale_t); -wint_t towupper_l(wint_t ch, locale_t); -wint_t towlower_l(wint_t ch, locale_t); -size_t strftime_l(char* str, size_t len, const char* format, const tm*, locale_t); - - -These functions are equivalent to their C counterparts, -except that locale_t is used instead of the current global locale. - -The variadic functions may be implemented as templates with a parameter pack instead of variadic functions. -*/ - -#endif // _LIBCPP___CXX03___LOCALE_DIR_LOCALE_BASE_API_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/android.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/android.h deleted file mode 100644 index e96e64d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/android.h +++ /dev/null @@ -1,45 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_ANDROID_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_ANDROID_H - -#include <__cxx03/stdlib.h> - -// FIXME: Is this actually required? -extern "C" { -#include -} - -#include <__cxx03/android/api-level.h> - -// If we do not have this header, we are in a platform build rather than an NDK -// build, which will always be at least as new as the ToT NDK, in which case we -// don't need any of the inlines below since libc provides them. -#if __has_include() -# include -// In NDK versions later than 16, locale-aware functions are provided by -// legacy_stdlib_inlines.h -# if __NDK_MAJOR__ <= 16 -# if __ANDROID_API__ < 26 - -inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) { - return ::strtof(__nptr, __endptr); -} - -inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t) { - return ::strtod(__nptr, __endptr); -} - -# endif // __ANDROID_API__ < 26 - -# endif // __NDK_MAJOR__ <= 16 -#endif // __has_include() - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_ANDROID_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_defaults.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_defaults.h deleted file mode 100644 index 35bf30c..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_defaults.h +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// The BSDs have lots of *_l functions. We don't want to define those symbols -// on other platforms though, for fear of conflicts with user code. So here, -// we will define the mapping from an internal macro to the real BSD symbol. -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc) -#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc) -#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc) -#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc) -#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc) -#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc) -#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l) -#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l) -#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l) -#define __libcpp_localeconv_l(l) localeconv_l(l) -#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l) -#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__) -#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__) -#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_fallbacks.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_fallbacks.h deleted file mode 100644 index a73b724..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/bsd_locale_fallbacks.h +++ /dev/null @@ -1,126 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// The BSDs have lots of *_l functions. This file provides reimplementations -// of those functions for non-BSD platforms. -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H - -#include <__cxx03/__locale_dir/locale_base_api/locale_guard.h> -#include <__cxx03/cstdio> -#include <__cxx03/stdlib.h> -#include - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -# include <__cxx03/cwchar> -#endif - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) { - __libcpp_locale_guard __current(__l); - return MB_CUR_MAX; -} - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, locale_t __l) { - __libcpp_locale_guard __current(__l); - return btowc(__c); -} - -inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, locale_t __l) { - __libcpp_locale_guard __current(__l); - return wctob(__c); -} - -inline _LIBCPP_HIDE_FROM_ABI size_t -__libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); - return wcsnrtombs(__dest, __src, __nwc, __len, __ps); -} - -inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); - return wcrtomb(__s, __wc, __ps); -} - -inline _LIBCPP_HIDE_FROM_ABI size_t -__libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); - return mbsnrtowcs(__dest, __src, __nms, __len, __ps); -} - -inline _LIBCPP_HIDE_FROM_ABI size_t -__libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); - return mbrtowc(__pwc, __s, __n, __ps); -} - -inline _LIBCPP_HIDE_FROM_ABI int __libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, locale_t __l) { - __libcpp_locale_guard __current(__l); - return mbtowc(__pwc, __pmb, __max); -} - -inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); - return mbrlen(__s, __n, __ps); -} -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS - -inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t __l) { - __libcpp_locale_guard __current(__l); - return localeconv(); -} - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -inline _LIBCPP_HIDE_FROM_ABI size_t -__libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); - return mbsrtowcs(__dest, __src, __len, __ps); -} -#endif - -inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l( - char* __s, size_t __n, locale_t __l, const char* __format, ...) { - va_list __va; - va_start(__va, __format); - __libcpp_locale_guard __current(__l); - int __res = vsnprintf(__s, __n, __format, __va); - va_end(__va); - return __res; -} - -inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l( - char** __s, locale_t __l, const char* __format, ...) { - va_list __va; - va_start(__va, __format); - __libcpp_locale_guard __current(__l); - int __res = vasprintf(__s, __format, __va); - va_end(__va); - return __res; -} - -inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l( - const char* __s, locale_t __l, const char* __format, ...) { - va_list __va; - va_start(__va, __format); - __libcpp_locale_guard __current(__l); - int __res = vsscanf(__s, __format, __va); - va_end(__va); - return __res; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/fuchsia.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/fuchsia.h deleted file mode 100644 index 6ee6a3a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/fuchsia.h +++ /dev/null @@ -1,18 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_FUCHSIA_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_FUCHSIA_H - -#include <__cxx03/__support/xlocale/__posix_l_fallback.h> -#include <__cxx03/__support/xlocale/__strtonum_fallback.h> -#include <__cxx03/cstdlib> -#include <__cxx03/cwchar> - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_FUCHSIA_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/ibm.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/ibm.h deleted file mode 100644 index a24d994..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/ibm.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_IBM_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_IBM_H - -#if defined(__MVS__) -# include <__cxx03/__support/ibm/locale_mgmt_zos.h> -#endif // defined(__MVS__) - -#include <__cxx03/locale.h> -#include <__cxx03/stdarg.h> -#include <__cxx03/stdio.h> - -#include "cstdlib" - -#if defined(__MVS__) -# include <__cxx03/wctype.h> -// POSIX routines -# include <__cxx03/__support/xlocale/__posix_l_fallback.h> -#endif // defined(__MVS__) - -namespace { - -struct __setAndRestore { - explicit __setAndRestore(locale_t locale) { - if (locale == (locale_t)0) { - __cloc = newlocale(LC_ALL_MASK, "C", /* base */ (locale_t)0); - __stored = uselocale(__cloc); - } else { - __stored = uselocale(locale); - } - } - - ~__setAndRestore() { - uselocale(__stored); - if (__cloc) - freelocale(__cloc); - } - -private: - locale_t __stored = (locale_t)0; - locale_t __cloc = (locale_t)0; -}; - -} // namespace - -// The following are not POSIX routines. These are quick-and-dirty hacks -// to make things pretend to work -inline _LIBCPP_HIDE_FROM_ABI long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t locale) { - __setAndRestore __newloc(locale); - return ::strtoll(__nptr, __endptr, __base); -} - -inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t locale) { - __setAndRestore __newloc(locale); - return ::strtod(__nptr, __endptr); -} - -inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t locale) { - __setAndRestore __newloc(locale); - return ::strtof(__nptr, __endptr); -} - -inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __endptr, locale_t locale) { - __setAndRestore __newloc(locale); - return ::strtold(__nptr, __endptr); -} - -inline _LIBCPP_HIDE_FROM_ABI unsigned long long -strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t locale) { - __setAndRestore __newloc(locale); - return ::strtoull(__nptr, __endptr, __base); -} - -inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) { - const size_t buff_size = 256; - if ((*strp = (char*)malloc(buff_size)) == NULL) { - return -1; - } - - va_list ap_copy; - // va_copy may not be provided by the C library in C++03 mode. -#if __has_builtin(__builtin_va_copy) - __builtin_va_copy(ap_copy, ap); -#else - va_copy(ap_copy, ap); -#endif - int str_size = vsnprintf(*strp, buff_size, fmt, ap_copy); - va_end(ap_copy); - - if ((size_t)str_size >= buff_size) { - if ((*strp = (char*)realloc(*strp, str_size + 1)) == NULL) { - return -1; - } - str_size = vsnprintf(*strp, str_size + 1, fmt, ap); - } - return str_size; -} - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_IBM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/locale_guard.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/locale_guard.h deleted file mode 100644 index e358363..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/locale_guard.h +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H - -#include <__cxx03/__config> -#include <__cxx03/__locale> // for locale_t -#include <__cxx03/clocale> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) -struct __libcpp_locale_guard { - _LIBCPP_HIDE_FROM_ABI __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} - - _LIBCPP_HIDE_FROM_ABI ~__libcpp_locale_guard() { - if (__old_loc_) - uselocale(__old_loc_); - } - - locale_t __old_loc_; - - __libcpp_locale_guard(__libcpp_locale_guard const&) = delete; - __libcpp_locale_guard& operator=(__libcpp_locale_guard const&) = delete; -}; -#elif defined(_LIBCPP_MSVCRT_LIKE) -struct __libcpp_locale_guard { - __libcpp_locale_guard(locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { - // Setting the locale can be expensive even when the locale given is - // already the current locale, so do an explicit check to see if the - // current locale is already the one we want. - const char* __lc = __setlocale(nullptr); - // If every category is the same, the locale string will simply be the - // locale name, otherwise it will be a semicolon-separated string listing - // each category. In the second case, we know at least one category won't - // be what we want, so we only have to check the first case. - if (std::strcmp(__l.__get_locale(), __lc) != 0) { - __locale_all = _strdup(__lc); - if (__locale_all == nullptr) - __throw_bad_alloc(); - __setlocale(__l.__get_locale()); - } - } - ~__libcpp_locale_guard() { - // The CRT documentation doesn't explicitly say, but setlocale() does the - // right thing when given a semicolon-separated list of locale settings - // for the different categories in the same format as returned by - // setlocale(LC_ALL, nullptr). - if (__locale_all != nullptr) { - __setlocale(__locale_all); - free(__locale_all); - } - _configthreadlocale(__status); - } - static const char* __setlocale(const char* __locale) { - const char* __new_locale = setlocale(LC_ALL, __locale); - if (__new_locale == nullptr) - __throw_bad_alloc(); - return __new_locale; - } - int __status; - char* __locale_all = nullptr; -}; -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/musl.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/musl.h deleted file mode 100644 index e2d23d4..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/musl.h +++ /dev/null @@ -1,31 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// This adds support for the extended locale functions that are currently -// missing from the Musl C library. -// -// This only works when the specified locale is "C" or "POSIX", but that's -// about as good as we can do without implementing full xlocale support -// in Musl. -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_MUSL_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_MUSL_H - -#include <__cxx03/cstdlib> -#include <__cxx03/cwchar> - -inline _LIBCPP_HIDE_FROM_ABI long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t) { - return ::strtoll(__nptr, __endptr, __base); -} - -inline _LIBCPP_HIDE_FROM_ABI unsigned long long strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t) { - return ::strtoull(__nptr, __endptr, __base); -} - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_MUSL_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/newlib.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/newlib.h deleted file mode 100644 index e52d907..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/newlib.h +++ /dev/null @@ -1,12 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_NEWLIB_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_NEWLIB_H - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_NEWLIB_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/openbsd.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/openbsd.h deleted file mode 100644 index 6b64607..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/openbsd.h +++ /dev/null @@ -1,19 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_OPENBSD_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_OPENBSD_H - -#include <__cxx03/__support/xlocale/__strtonum_fallback.h> -#include <__cxx03/clocale> -#include <__cxx03/cstdlib> -#include <__cxx03/ctype.h> -#include <__cxx03/cwctype> - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_OPENBSD_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/win32.h b/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/win32.h deleted file mode 100644 index 5f85acf..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__locale_dir/locale_base_api/win32.h +++ /dev/null @@ -1,235 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_WIN32_H -#define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_WIN32_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> -#include <__cxx03/locale.h> // _locale_t -#include <__cxx03/stdio.h> -#include <__cxx03/string> - -#define _X_ALL LC_ALL -#define _X_COLLATE LC_COLLATE -#define _X_CTYPE LC_CTYPE -#define _X_MONETARY LC_MONETARY -#define _X_NUMERIC LC_NUMERIC -#define _X_TIME LC_TIME -#define _X_MAX LC_MAX -#define _X_MESSAGES 6 -#define _NCAT (_X_MESSAGES + 1) - -#define _CATMASK(n) ((1 << (n)) >> 1) -#define _M_COLLATE _CATMASK(_X_COLLATE) -#define _M_CTYPE _CATMASK(_X_CTYPE) -#define _M_MONETARY _CATMASK(_X_MONETARY) -#define _M_NUMERIC _CATMASK(_X_NUMERIC) -#define _M_TIME _CATMASK(_X_TIME) -#define _M_MESSAGES _CATMASK(_X_MESSAGES) -#define _M_ALL (_CATMASK(_NCAT) - 1) - -#define LC_COLLATE_MASK _M_COLLATE -#define LC_CTYPE_MASK _M_CTYPE -#define LC_MONETARY_MASK _M_MONETARY -#define LC_NUMERIC_MASK _M_NUMERIC -#define LC_TIME_MASK _M_TIME -#define LC_MESSAGES_MASK _M_MESSAGES -#define LC_ALL_MASK \ - (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK) - -class __lconv_storage { -public: - __lconv_storage(const lconv* __lc_input) { - __lc_ = *__lc_input; - - __decimal_point_ = __lc_input->decimal_point; - __thousands_sep_ = __lc_input->thousands_sep; - __grouping_ = __lc_input->grouping; - __int_curr_symbol_ = __lc_input->int_curr_symbol; - __currency_symbol_ = __lc_input->currency_symbol; - __mon_decimal_point_ = __lc_input->mon_decimal_point; - __mon_thousands_sep_ = __lc_input->mon_thousands_sep; - __mon_grouping_ = __lc_input->mon_grouping; - __positive_sign_ = __lc_input->positive_sign; - __negative_sign_ = __lc_input->negative_sign; - - __lc_.decimal_point = const_cast(__decimal_point_.c_str()); - __lc_.thousands_sep = const_cast(__thousands_sep_.c_str()); - __lc_.grouping = const_cast(__grouping_.c_str()); - __lc_.int_curr_symbol = const_cast(__int_curr_symbol_.c_str()); - __lc_.currency_symbol = const_cast(__currency_symbol_.c_str()); - __lc_.mon_decimal_point = const_cast(__mon_decimal_point_.c_str()); - __lc_.mon_thousands_sep = const_cast(__mon_thousands_sep_.c_str()); - __lc_.mon_grouping = const_cast(__mon_grouping_.c_str()); - __lc_.positive_sign = const_cast(__positive_sign_.c_str()); - __lc_.negative_sign = const_cast(__negative_sign_.c_str()); - } - - lconv* __get() { return &__lc_; } - -private: - lconv __lc_; - std::string __decimal_point_; - std::string __thousands_sep_; - std::string __grouping_; - std::string __int_curr_symbol_; - std::string __currency_symbol_; - std::string __mon_decimal_point_; - std::string __mon_thousands_sep_; - std::string __mon_grouping_; - std::string __positive_sign_; - std::string __negative_sign_; -}; - -class locale_t { -public: - locale_t() : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {} - locale_t(std::nullptr_t) : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {} - locale_t(_locale_t __xlocale, const char* __xlocale_str) - : __locale_(__xlocale), __locale_str_(__xlocale_str), __lc_(nullptr) {} - locale_t(const locale_t& __l) : __locale_(__l.__locale_), __locale_str_(__l.__locale_str_), __lc_(nullptr) {} - - ~locale_t() { delete __lc_; } - - locale_t& operator=(const locale_t& __l) { - __locale_ = __l.__locale_; - __locale_str_ = __l.__locale_str_; - // __lc_ not copied - return *this; - } - - friend bool operator==(const locale_t& __left, const locale_t& __right) { - return __left.__locale_ == __right.__locale_; - } - - friend bool operator==(const locale_t& __left, int __right) { return __left.__locale_ == nullptr && __right == 0; } - - friend bool operator==(const locale_t& __left, long long __right) { - return __left.__locale_ == nullptr && __right == 0; - } - - friend bool operator==(const locale_t& __left, std::nullptr_t) { return __left.__locale_ == nullptr; } - - friend bool operator==(int __left, const locale_t& __right) { return __left == 0 && nullptr == __right.__locale_; } - - friend bool operator==(std::nullptr_t, const locale_t& __right) { return nullptr == __right.__locale_; } - - friend bool operator!=(const locale_t& __left, const locale_t& __right) { return !(__left == __right); } - - friend bool operator!=(const locale_t& __left, int __right) { return !(__left == __right); } - - friend bool operator!=(const locale_t& __left, long long __right) { return !(__left == __right); } - - friend bool operator!=(const locale_t& __left, std::nullptr_t __right) { return !(__left == __right); } - - friend bool operator!=(int __left, const locale_t& __right) { return !(__left == __right); } - - friend bool operator!=(std::nullptr_t __left, const locale_t& __right) { return !(__left == __right); } - - operator bool() const { return __locale_ != nullptr; } - - const char* __get_locale() const { return __locale_str_; } - - operator _locale_t() const { return __locale_; } - - lconv* __store_lconv(const lconv* __input_lc) { - delete __lc_; - __lc_ = new __lconv_storage(__input_lc); - return __lc_->__get(); - } - -private: - _locale_t __locale_; - const char* __locale_str_; - __lconv_storage* __lc_ = nullptr; -}; - -// Locale management functions -#define freelocale _free_locale -// FIXME: base currently unused. Needs manual work to construct the new locale -locale_t newlocale(int __mask, const char* __locale, locale_t __base); -// uselocale can't be implemented on Windows because Windows allows partial modification -// of thread-local locale and so _get_current_locale() returns a copy while uselocale does -// not create any copies. -// We can still implement raii even without uselocale though. - -lconv* localeconv_l(locale_t& __loc); -size_t mbrlen_l(const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc); -size_t mbsrtowcs_l( - wchar_t* __restrict __dst, const char** __restrict __src, size_t __len, mbstate_t* __restrict __ps, locale_t __loc); -size_t wcrtomb_l(char* __restrict __s, wchar_t __wc, mbstate_t* __restrict __ps, locale_t __loc); -size_t mbrtowc_l( - wchar_t* __restrict __pwc, const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc); -size_t mbsnrtowcs_l(wchar_t* __restrict __dst, - const char** __restrict __src, - size_t __nms, - size_t __len, - mbstate_t* __restrict __ps, - locale_t __loc); -size_t wcsnrtombs_l(char* __restrict __dst, - const wchar_t** __restrict __src, - size_t __nwc, - size_t __len, - mbstate_t* __restrict __ps, - locale_t __loc); -wint_t btowc_l(int __c, locale_t __loc); -int wctob_l(wint_t __c, locale_t __loc); - -decltype(MB_CUR_MAX) MB_CUR_MAX_L(locale_t __l); - -// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ -#define mbtowc_l _mbtowc_l -#define strtoll_l _strtoi64_l -#define strtoull_l _strtoui64_l -#define strtod_l _strtod_l -#if defined(_LIBCPP_MSVCRT) -# define strtof_l _strtof_l -# define strtold_l _strtold_l -#else -_LIBCPP_EXPORTED_FROM_ABI float strtof_l(const char*, char**, locale_t); -_LIBCPP_EXPORTED_FROM_ABI long double strtold_l(const char*, char**, locale_t); -#endif -inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, _locale_t __loc) { return _islower_l((int)__c, __loc); } - -inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, _locale_t __loc) { return _isupper_l((int)__c, __loc); } - -#define isdigit_l _isdigit_l -#define isxdigit_l _isxdigit_l -#define strcoll_l _strcoll_l -#define strxfrm_l _strxfrm_l -#define wcscoll_l _wcscoll_l -#define wcsxfrm_l _wcsxfrm_l -#define toupper_l _toupper_l -#define tolower_l _tolower_l -#define iswspace_l _iswspace_l -#define iswprint_l _iswprint_l -#define iswcntrl_l _iswcntrl_l -#define iswupper_l _iswupper_l -#define iswlower_l _iswlower_l -#define iswalpha_l _iswalpha_l -#define iswdigit_l _iswdigit_l -#define iswpunct_l _iswpunct_l -#define iswxdigit_l _iswxdigit_l -#define towupper_l _towupper_l -#define towlower_l _towlower_l -#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 -_LIBCPP_EXPORTED_FROM_ABI size_t strftime_l(char* ret, size_t n, const char* format, const struct tm* tm, locale_t loc); -#else -# define strftime_l _strftime_l -#endif -#define sscanf_l(__s, __l, __f, ...) _sscanf_l(__s, __f, __l, __VA_ARGS__) -_LIBCPP_EXPORTED_FROM_ABI int snprintf_l(char* __ret, size_t __n, locale_t __loc, const char* __format, ...); -_LIBCPP_EXPORTED_FROM_ABI int asprintf_l(char** __ret, locale_t __loc, const char* __format, ...); -_LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const char* __format, va_list __ap); - -// not-so-pressing FIXME: use locale to determine blank characters -inline int iswblank_l(wint_t __c, locale_t /*loc*/) { return (__c == L' ' || __c == L'\t'); } - -#endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_WIN32_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/abs.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/abs.h deleted file mode 100644 index 61fc58a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/abs.h +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_ABS_H -#define _LIBCPP___CXX03___MATH_ABS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// fabs - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); } - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT { - return __builtin_fabs(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT { - return __builtin_fabsl(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double fabs(_A1 __x) _NOEXCEPT { - return __builtin_fabs((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_ABS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/copysign.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/copysign.h deleted file mode 100644 index d209406..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/copysign.h +++ /dev/null @@ -1,45 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_COPYSIGN_H -#define _LIBCPP___CXX03___MATH_COPYSIGN_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/promote.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// copysign - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT { - return ::__builtin_copysignf(__x, __y); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT { - return ::__builtin_copysignl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type copysign(_A1 __x, _A2 __y) _NOEXCEPT { - return ::__builtin_copysign(__x, __y); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_COPYSIGN_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/error_functions.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/error_functions.h deleted file mode 100644 index 25cf059..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/error_functions.h +++ /dev/null @@ -1,60 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_ERROR_FUNCTIONS_H -#define _LIBCPP___CXX03___MATH_ERROR_FUNCTIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// erf - -inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT { return __builtin_erff(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double erf(double __x) _NOEXCEPT { - return __builtin_erf(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __x) _NOEXCEPT { return __builtin_erfl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double erf(_A1 __x) _NOEXCEPT { - return __builtin_erf((double)__x); -} - -// erfc - -inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT { return __builtin_erfcf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double erfc(double __x) _NOEXCEPT { - return __builtin_erfc(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __x) _NOEXCEPT { return __builtin_erfcl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double erfc(_A1 __x) _NOEXCEPT { - return __builtin_erfc((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_ERROR_FUNCTIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/exponential_functions.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/exponential_functions.h deleted file mode 100644 index 452d5d2..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/exponential_functions.h +++ /dev/null @@ -1,171 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_EXPONENTIAL_FUNCTIONS_H -#define _LIBCPP___CXX03___MATH_EXPONENTIAL_FUNCTIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// exp - -inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return __builtin_expf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT { - return __builtin_exp(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT { return __builtin_expl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT { - return __builtin_exp((double)__x); -} - -// frexp - -inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT { return __builtin_frexpf(__x, __e); } - -template -_LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT { - return __builtin_frexp(__x, __e); -} - -inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT { - return __builtin_frexpl(__x, __e); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double frexp(_A1 __x, int* __e) _NOEXCEPT { - return __builtin_frexp((double)__x, __e); -} - -// ldexp - -inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT { return __builtin_ldexpf(__x, __e); } - -template -_LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT { - return __builtin_ldexp(__x, __e); -} - -inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT { - return __builtin_ldexpl(__x, __e); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double ldexp(_A1 __x, int __e) _NOEXCEPT { - return __builtin_ldexp((double)__x, __e); -} - -// exp2 - -inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT { return __builtin_exp2f(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT { - return __builtin_exp2(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT { return __builtin_exp2l(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double exp2(_A1 __x) _NOEXCEPT { - return __builtin_exp2((double)__x); -} - -// expm1 - -inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT { return __builtin_expm1f(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT { - return __builtin_expm1(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT { return __builtin_expm1l(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double expm1(_A1 __x) _NOEXCEPT { - return __builtin_expm1((double)__x); -} - -// scalbln - -inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT { return __builtin_scalblnf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT { - return __builtin_scalbln(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double scalbln(long double __x, long __y) _NOEXCEPT { - return __builtin_scalblnl(__x, __y); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double scalbln(_A1 __x, long __y) _NOEXCEPT { - return __builtin_scalbln((double)__x, __y); -} - -// scalbn - -inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT { return __builtin_scalbnf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT { - return __builtin_scalbn(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double scalbn(long double __x, int __y) _NOEXCEPT { - return __builtin_scalbnl(__x, __y); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double scalbn(_A1 __x, int __y) _NOEXCEPT { - return __builtin_scalbn((double)__x, __y); -} - -// pow - -inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT { - return __builtin_pow(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT { - return __builtin_powl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type pow(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::pow((__result_type)__x, (__result_type)__y); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_EXPONENTIAL_FUNCTIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/fdim.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/fdim.h deleted file mode 100644 index ac6fec4..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/fdim.h +++ /dev/null @@ -1,48 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_FDIM_H -#define _LIBCPP___CXX03___MATH_FDIM_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT { return __builtin_fdimf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double fdim(double __x, double __y) _NOEXCEPT { - return __builtin_fdim(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double fdim(long double __x, long double __y) _NOEXCEPT { - return __builtin_fdiml(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fdim(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::fdim((__result_type)__x, (__result_type)__y); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_FDIM_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/fma.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/fma.h deleted file mode 100644 index ce7e92a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/fma.h +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_FMA_H -#define _LIBCPP___CXX03___MATH_FMA_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT { - return __builtin_fmaf(__x, __y, __z); -} - -template -_LIBCPP_HIDE_FROM_ABI double fma(double __x, double __y, double __z) _NOEXCEPT { - return __builtin_fma(__x, __y, __z); -} - -inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT { - return __builtin_fmal(__x, __y, __z); -} - -template ::value && is_arithmetic<_A2>::value && is_arithmetic<_A3>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2, _A3>::type fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2, _A3>::type; - static_assert( - !(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value && _IsSame<_A3, __result_type>::value), - ""); - return __builtin_fma((__result_type)__x, (__result_type)__y, (__result_type)__z); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_FMA_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/gamma.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/gamma.h deleted file mode 100644 index 4d10498..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/gamma.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_GAMMA_H -#define _LIBCPP___CXX03___MATH_GAMMA_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// lgamma - -inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT { return __builtin_lgammaf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double lgamma(double __x) _NOEXCEPT { - return __builtin_lgamma(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double lgamma(long double __x) _NOEXCEPT { return __builtin_lgammal(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double lgamma(_A1 __x) _NOEXCEPT { - return __builtin_lgamma((double)__x); -} - -// nan - -// tgamma - -inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT { return __builtin_tgammaf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double tgamma(double __x) _NOEXCEPT { - return __builtin_tgamma(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double tgamma(long double __x) _NOEXCEPT { return __builtin_tgammal(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double tgamma(_A1 __x) _NOEXCEPT { - return __builtin_tgamma((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_GAMMA_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/hyperbolic_functions.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/hyperbolic_functions.h deleted file mode 100644 index 2b765ca..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/hyperbolic_functions.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_HYPERBOLIC_FUNCTIONS_H -#define _LIBCPP___CXX03___MATH_HYPERBOLIC_FUNCTIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// cosh - -inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT { return __builtin_coshf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double cosh(double __x) _NOEXCEPT { - return __builtin_cosh(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double cosh(long double __x) _NOEXCEPT { return __builtin_coshl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double cosh(_A1 __x) _NOEXCEPT { - return __builtin_cosh((double)__x); -} - -// sinh - -inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT { return __builtin_sinhf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double sinh(double __x) _NOEXCEPT { - return __builtin_sinh(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double sinh(long double __x) _NOEXCEPT { return __builtin_sinhl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double sinh(_A1 __x) _NOEXCEPT { - return __builtin_sinh((double)__x); -} - -// tanh - -inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT { return __builtin_tanhf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double tanh(double __x) _NOEXCEPT { - return __builtin_tanh(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double tanh(long double __x) _NOEXCEPT { return __builtin_tanhl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double tanh(_A1 __x) _NOEXCEPT { - return __builtin_tanh((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_HYPERBOLIC_FUNCTIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/hypot.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/hypot.h deleted file mode 100644 index 20b00f3..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/hypot.h +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_HYPOT_H -#define _LIBCPP___CXX03___MATH_HYPOT_H - -#include <__cxx03/__algorithm/max.h> -#include <__cxx03/__config> -#include <__cxx03/__math/abs.h> -#include <__cxx03/__math/exponential_functions.h> -#include <__cxx03/__math/roots.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> -#include <__cxx03/__utility/pair.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT { return __builtin_hypotf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT { - return __builtin_hypot(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y) _NOEXCEPT { - return __builtin_hypotl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type hypot(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::hypot((__result_type)__x, (__result_type)__y); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___MATH_HYPOT_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_hyperbolic_functions.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_hyperbolic_functions.h deleted file mode 100644 index b48689d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_hyperbolic_functions.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_INVERSE_HYPERBOLIC_FUNCTIONS_H -#define _LIBCPP___CXX03___MATH_INVERSE_HYPERBOLIC_FUNCTIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// acosh - -inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT { return __builtin_acoshf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double acosh(double __x) _NOEXCEPT { - return __builtin_acosh(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double acosh(long double __x) _NOEXCEPT { return __builtin_acoshl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double acosh(_A1 __x) _NOEXCEPT { - return __builtin_acosh((double)__x); -} - -// asinh - -inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT { return __builtin_asinhf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double asinh(double __x) _NOEXCEPT { - return __builtin_asinh(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double asinh(long double __x) _NOEXCEPT { return __builtin_asinhl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double asinh(_A1 __x) _NOEXCEPT { - return __builtin_asinh((double)__x); -} - -// atanh - -inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT { return __builtin_atanhf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double atanh(double __x) _NOEXCEPT { - return __builtin_atanh(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double atanh(long double __x) _NOEXCEPT { return __builtin_atanhl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double atanh(_A1 __x) _NOEXCEPT { - return __builtin_atanh((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_INVERSE_HYPERBOLIC_FUNCTIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_trigonometric_functions.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_trigonometric_functions.h deleted file mode 100644 index 573c9b1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/inverse_trigonometric_functions.h +++ /dev/null @@ -1,99 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_INVERSE_TRIGONOMETRIC_FUNCTIONS_H -#define _LIBCPP___CXX03___MATH_INVERSE_TRIGONOMETRIC_FUNCTIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// acos - -inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT { return __builtin_acosf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT { - return __builtin_acos(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT { return __builtin_acosl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double acos(_A1 __x) _NOEXCEPT { - return __builtin_acos((double)__x); -} - -// asin - -inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT { return __builtin_asinf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double asin(double __x) _NOEXCEPT { - return __builtin_asin(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT { return __builtin_asinl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double asin(_A1 __x) _NOEXCEPT { - return __builtin_asin((double)__x); -} - -// atan - -inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT { return __builtin_atanf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double atan(double __x) _NOEXCEPT { - return __builtin_atan(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT { return __builtin_atanl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double atan(_A1 __x) _NOEXCEPT { - return __builtin_atan((double)__x); -} - -// atan2 - -inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT { return __builtin_atan2f(__y, __x); } - -template -_LIBCPP_HIDE_FROM_ABI double atan2(double __x, double __y) _NOEXCEPT { - return __builtin_atan2(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x) _NOEXCEPT { - return __builtin_atan2l(__y, __x); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type atan2(_A1 __y, _A2 __x) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::atan2((__result_type)__y, (__result_type)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_INVERSE_TRIGONOMETRIC_FUNCTIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/logarithms.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/logarithms.h deleted file mode 100644 index 9b9e59a..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/logarithms.h +++ /dev/null @@ -1,124 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_LOGARITHMS_H -#define _LIBCPP___CXX03___MATH_LOGARITHMS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// log - -inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT { return __builtin_logf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT { - return __builtin_log(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT { return __builtin_logl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double log(_A1 __x) _NOEXCEPT { - return __builtin_log((double)__x); -} - -// log10 - -inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT { return __builtin_log10f(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT { - return __builtin_log10(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT { return __builtin_log10l(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double log10(_A1 __x) _NOEXCEPT { - return __builtin_log10((double)__x); -} - -// ilogb - -inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT { return __builtin_ilogbf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI int ilogb(double __x) _NOEXCEPT { - return __builtin_ilogb(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT { return __builtin_ilogbl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI int ilogb(_A1 __x) _NOEXCEPT { - return __builtin_ilogb((double)__x); -} - -// log1p - -inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT { return __builtin_log1pf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT { - return __builtin_log1p(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT { return __builtin_log1pl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double log1p(_A1 __x) _NOEXCEPT { - return __builtin_log1p((double)__x); -} - -// log2 - -inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT { return __builtin_log2f(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT { - return __builtin_log2(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT { return __builtin_log2l(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double log2(_A1 __x) _NOEXCEPT { - return __builtin_log2((double)__x); -} - -// logb - -inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT { return __builtin_logbf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT { - return __builtin_logb(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT { return __builtin_logbl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double logb(_A1 __x) _NOEXCEPT { - return __builtin_logb((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_LOGARITHMS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/min_max.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/min_max.h deleted file mode 100644 index 4df5bc1..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/min_max.h +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_MIN_MAX_H -#define _LIBCPP___CXX03___MATH_MIN_MAX_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// fmax - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT { - return __builtin_fmaxf(__x, __y); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT { - return __builtin_fmax(__x, __y); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT { - return __builtin_fmaxl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmax(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::fmax((__result_type)__x, (__result_type)__y); -} - -// fmin - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT { - return __builtin_fminf(__x, __y); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT { - return __builtin_fmin(__x, __y); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT { - return __builtin_fminl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmin(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::fmin((__result_type)__x, (__result_type)__y); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_MIN_MAX_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/modulo.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/modulo.h deleted file mode 100644 index 5a61241..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/modulo.h +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_MODULO_H -#define _LIBCPP___CXX03___MATH_MODULO_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// fmod - -inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT { return __builtin_fmodf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double fmod(double __x, double __y) _NOEXCEPT { - return __builtin_fmod(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y) _NOEXCEPT { - return __builtin_fmodl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmod(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::fmod((__result_type)__x, (__result_type)__y); -} - -// modf - -inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT { return __builtin_modff(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double modf(double __x, double* __y) _NOEXCEPT { - return __builtin_modf(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double modf(long double __x, long double* __y) _NOEXCEPT { - return __builtin_modfl(__x, __y); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_MODULO_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/remainder.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/remainder.h deleted file mode 100644 index a9f750b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/remainder.h +++ /dev/null @@ -1,73 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_REMAINDER_H -#define _LIBCPP___CXX03___MATH_REMAINDER_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// remainder - -inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT { return __builtin_remainderf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double remainder(double __x, double __y) _NOEXCEPT { - return __builtin_remainder(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double remainder(long double __x, long double __y) _NOEXCEPT { - return __builtin_remainderl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remainder(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::remainder((__result_type)__x, (__result_type)__y); -} - -// remquo - -inline _LIBCPP_HIDE_FROM_ABI float remquo(float __x, float __y, int* __z) _NOEXCEPT { - return __builtin_remquof(__x, __y, __z); -} - -template -_LIBCPP_HIDE_FROM_ABI double remquo(double __x, double __y, int* __z) _NOEXCEPT { - return __builtin_remquo(__x, __y, __z); -} - -inline _LIBCPP_HIDE_FROM_ABI long double remquo(long double __x, long double __y, int* __z) _NOEXCEPT { - return __builtin_remquol(__x, __y, __z); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::remquo((__result_type)__x, (__result_type)__y, __z); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_REMAINDER_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/roots.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/roots.h deleted file mode 100644 index 77d9eea..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/roots.h +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_ROOTS_H -#define _LIBCPP___CXX03___MATH_ROOTS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// sqrt - -inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT { return __builtin_sqrtf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double sqrt(double __x) _NOEXCEPT { - return __builtin_sqrt(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT { return __builtin_sqrtl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double sqrt(_A1 __x) _NOEXCEPT { - return __builtin_sqrt((double)__x); -} - -// cbrt - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); } - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT { - return __builtin_cbrt(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT { - return __builtin_cbrtl(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double cbrt(_A1 __x) _NOEXCEPT { - return __builtin_cbrt((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_ROOTS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/rounding_functions.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/rounding_functions.h deleted file mode 100644 index e146d74..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/rounding_functions.h +++ /dev/null @@ -1,245 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_ROUNDING_FUNCTIONS_H -#define _LIBCPP___CXX03___MATH_ROUNDING_FUNCTIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/promote.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// ceil - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); } - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT { - return __builtin_ceil(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT { - return __builtin_ceill(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT { - return __builtin_ceil((double)__x); -} - -// floor - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); } - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT { - return __builtin_floor(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT { - return __builtin_floorl(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT { - return __builtin_floor((double)__x); -} - -// llrint - -inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT { return __builtin_llrintf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI long long llrint(double __x) _NOEXCEPT { - return __builtin_llrint(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT { return __builtin_llrintl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI long long llrint(_A1 __x) _NOEXCEPT { - return __builtin_llrint((double)__x); -} - -// llround - -inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT { return __builtin_llroundf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI long long llround(double __x) _NOEXCEPT { - return __builtin_llround(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT { return __builtin_llroundl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI long long llround(_A1 __x) _NOEXCEPT { - return __builtin_llround((double)__x); -} - -// lrint - -inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT { return __builtin_lrintf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI long lrint(double __x) _NOEXCEPT { - return __builtin_lrint(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT { return __builtin_lrintl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI long lrint(_A1 __x) _NOEXCEPT { - return __builtin_lrint((double)__x); -} - -// lround - -inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT { return __builtin_lroundf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI long lround(double __x) _NOEXCEPT { - return __builtin_lround(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT { return __builtin_lroundl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI long lround(_A1 __x) _NOEXCEPT { - return __builtin_lround((double)__x); -} - -// nearbyint - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT { - return __builtin_nearbyintf(__x); -} - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT { - return __builtin_nearbyint(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT { - return __builtin_nearbyintl(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCEPT { - return __builtin_nearbyint((double)__x); -} - -// nextafter - -inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT { return __builtin_nextafterf(__x, __y); } - -template -_LIBCPP_HIDE_FROM_ABI double nextafter(double __x, double __y) _NOEXCEPT { - return __builtin_nextafter(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double nextafter(long double __x, long double __y) _NOEXCEPT { - return __builtin_nextafterl(__x, __y); -} - -template ::value && is_arithmetic<_A2>::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type nextafter(_A1 __x, _A2 __y) _NOEXCEPT { - using __result_type = typename __promote<_A1, _A2>::type; - static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); - return __math::nextafter((__result_type)__x, (__result_type)__y); -} - -// nexttoward - -inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT { - return __builtin_nexttowardf(__x, __y); -} - -template -_LIBCPP_HIDE_FROM_ABI double nexttoward(double __x, long double __y) _NOEXCEPT { - return __builtin_nexttoward(__x, __y); -} - -inline _LIBCPP_HIDE_FROM_ABI long double nexttoward(long double __x, long double __y) _NOEXCEPT { - return __builtin_nexttowardl(__x, __y); -} - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double nexttoward(_A1 __x, long double __y) _NOEXCEPT { - return __builtin_nexttoward((double)__x, __y); -} - -// rint - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); } - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT { - return __builtin_rint(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT { - return __builtin_rintl(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT { - return __builtin_rint((double)__x); -} - -// round - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); } - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT { - return __builtin_round(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT { - return __builtin_roundl(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT { - return __builtin_round((double)__x); -} - -// trunc - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); } - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT { - return __builtin_trunc(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT { - return __builtin_truncl(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double trunc(_A1 __x) _NOEXCEPT { - return __builtin_trunc((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_ROUNDING_FUNCTIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/traits.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/traits.h deleted file mode 100644 index 250e88b..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/traits.h +++ /dev/null @@ -1,189 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_TRAITS_H -#define _LIBCPP___CXX03___MATH_TRAITS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_arithmetic.h> -#include <__cxx03/__type_traits/is_integral.h> -#include <__cxx03/__type_traits/is_signed.h> -#include <__cxx03/__type_traits/promote.h> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// signbit - -// The universal C runtime (UCRT) in the WinSDK provides floating point overloads -// for std::signbit(). By defining our overloads as templates, we can work around -// this issue as templates are less preferred than non-template functions. -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(float __x) _NOEXCEPT { - return __builtin_signbit(__x); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(double __x) _NOEXCEPT { - return __builtin_signbit(__x); -} - -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(long double __x) _NOEXCEPT { - return __builtin_signbit(__x); -} - -template ::value && is_signed<_A1>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { - return __x < 0; -} - -template ::value && !is_signed<_A1>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT { - return false; -} - -// isfinite - -template ::value && numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT { - return __builtin_isfinite((typename __promote<_A1>::type)__x); -} - -template ::value && !numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT { - return true; -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT { return __builtin_isfinite(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT { return __builtin_isfinite(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT { - return __builtin_isfinite(__x); -} - -// isinf - -template ::value && numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT { - return __builtin_isinf((typename __promote<_A1>::type)__x); -} - -template ::value && !numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) _NOEXCEPT { - return false; -} - -#ifdef _LIBCPP_PREFERRED_OVERLOAD -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT { return __builtin_isinf(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT { - return __builtin_isinf(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { return __builtin_isinf(__x); } -#endif - -// isnan - -template ::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT { - return __builtin_isnan(__x); -} - -template ::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT { - return false; -} - -#ifdef _LIBCPP_PREFERRED_OVERLOAD -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT { return __builtin_isnan(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT { - return __builtin_isnan(__x); -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { return __builtin_isnan(__x); } -#endif - -// isnormal - -template ::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { - return __x != 0; -} - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isnormal(float __x) _NOEXCEPT { return __builtin_isnormal(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isnormal(double __x) _NOEXCEPT { return __builtin_isnormal(__x); } - -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isnormal(long double __x) _NOEXCEPT { - return __builtin_isnormal(__x); -} - -// isgreater - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT { - using type = typename __promote<_A1, _A2>::type; - return __builtin_isgreater((type)__x, (type)__y); -} - -// isgreaterequal - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT { - using type = typename __promote<_A1, _A2>::type; - return __builtin_isgreaterequal((type)__x, (type)__y); -} - -// isless - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT { - using type = typename __promote<_A1, _A2>::type; - return __builtin_isless((type)__x, (type)__y); -} - -// islessequal - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT { - using type = typename __promote<_A1, _A2>::type; - return __builtin_islessequal((type)__x, (type)__y); -} - -// islessgreater - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT { - using type = typename __promote<_A1, _A2>::type; - return __builtin_islessgreater((type)__x, (type)__y); -} - -// isunordered - -template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT { - using type = typename __promote<_A1, _A2>::type; - return __builtin_isunordered((type)__x, (type)__y); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_TRAITS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__math/trigonometric_functions.h b/third_party/libcxx/include/c++/v1/__cxx03/__math/trigonometric_functions.h deleted file mode 100644 index 6c23ae6..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__math/trigonometric_functions.h +++ /dev/null @@ -1,76 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MATH_TRIGONOMETRIC_FUNCTIONS_H -#define _LIBCPP___CXX03___MATH_TRIGONOMETRIC_FUNCTIONS_H - -#include <__cxx03/__config> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_integral.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __math { - -// cos - -inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT { return __builtin_cosf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double cos(double __x) _NOEXCEPT { - return __builtin_cos(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT { return __builtin_cosl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double cos(_A1 __x) _NOEXCEPT { - return __builtin_cos((double)__x); -} - -// sin - -inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT { return __builtin_sinf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double sin(double __x) _NOEXCEPT { - return __builtin_sin(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT { return __builtin_sinl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double sin(_A1 __x) _NOEXCEPT { - return __builtin_sin((double)__x); -} - -// tan - -inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT { return __builtin_tanf(__x); } - -template -_LIBCPP_HIDE_FROM_ABI double tan(double __x) _NOEXCEPT { - return __builtin_tan(__x); -} - -inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT { return __builtin_tanl(__x); } - -template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI double tan(_A1 __x) _NOEXCEPT { - return __builtin_tan((double)__x); -} - -} // namespace __math - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MATH_TRIGONOMETRIC_FUNCTIONS_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__mbstate_t.h b/third_party/libcxx/include/c++/v1/__cxx03/__mbstate_t.h deleted file mode 100644 index 6c7cfaa..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__mbstate_t.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MBSTATE_T_H -#define _LIBCPP___CXX03___MBSTATE_T_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -// The goal of this header is to provide mbstate_t without requiring all of -// or . It's also used by the libc++ versions of -// and to get mbstate_t when the C library doesn't provide -// or , hence the #include_next of those headers instead of #include. -// (e.g. if isn't present in the C library, the libc++ -// will include this header. This header needs to not turn around and cyclically -// include <__cxx03/wchar.h>, but fall through to .) -// -// This does not define std::mbstate_t -- this only brings in the declaration -// in the global namespace. - -// We define this here to support older versions of glibc that do -// not define this for clang. This is also set in libc++'s header, -// and we need to do so here too to avoid a different function signature given -// a different include order. -#ifdef __cplusplus -# define __CORRECT_ISO_CPP_WCHAR_H_PROTO -#endif - -#if defined(_LIBCPP_HAS_MUSL_LIBC) -# define __NEED_mbstate_t -# include -# undef __NEED_mbstate_t -#elif __has_include() -# include // works on most Unixes -#elif __has_include() -# include // works on Darwin -#elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && __has_include_next() -# include_next // fall back to the C standard provider of mbstate_t -#elif __has_include_next() -# include_next // is also required to make mbstate_t visible -#else -# error "We don't know how to get the definition of mbstate_t without on your platform." -#endif - -#endif // _LIBCPP___CXX03___MBSTATE_T_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/addressof.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/addressof.h deleted file mode 100644 index 9bb49ba..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/addressof.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ADDRESSOF_H -#define _LIBCPP___CXX03___MEMORY_ADDRESSOF_H - -#include <__cxx03/__config> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* addressof(_Tp& __x) _NOEXCEPT { - return __builtin_addressof(__x); -} - -#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) -// Objective-C++ Automatic Reference Counting uses qualified pointers -// that require special addressof() signatures. When -// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler -// itself is providing these definitions. Otherwise, we provide them. -template -inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEPT { - return &__x; -} - -# ifdef _LIBCPP_HAS_OBJC_ARC_WEAK -template -inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT { - return &__x; -} -# endif - -template -inline _LIBCPP_HIDE_FROM_ABI __autoreleasing _Tp* addressof(__autoreleasing _Tp& __x) _NOEXCEPT { - return &__x; -} - -template -inline _LIBCPP_HIDE_FROM_ABI __unsafe_unretained _Tp* addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT { - return &__x; -} -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MEMORY_ADDRESSOF_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/align.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/align.h deleted file mode 100644 index 2b2085f..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/align.h +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ALIGN_H -#define _LIBCPP___CXX03___MEMORY_ALIGN_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -_LIBCPP_EXPORTED_FROM_ABI void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MEMORY_ALIGN_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/aligned_alloc.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/aligned_alloc.h deleted file mode 100644 index 1efffcc..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/aligned_alloc.h +++ /dev/null @@ -1,53 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ALIGNED_ALLOC_H -#define _LIBCPP___CXX03___MEMORY_ALIGNED_ALLOC_H - -#include <__cxx03/__config> -#include <__cxx03/cstddef> -#include <__cxx03/cstdlib> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION - -// Low-level helpers to call the aligned allocation and deallocation functions -// on the target platform. This is used to implement libc++'s own memory -// allocation routines -- if you need to allocate memory inside the library, -// chances are that you want to use `__libcpp_allocate` instead. -// -// Returns the allocated memory, or `nullptr` on failure. -inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) { -# if defined(_LIBCPP_MSVCRT_LIKE) - return ::_aligned_malloc(__size, __alignment); -# else - void* __result = nullptr; - (void)::posix_memalign(&__result, __alignment, __size); - // If posix_memalign fails, __result is unmodified so we still return `nullptr`. - return __result; -# endif -} - -inline _LIBCPP_HIDE_FROM_ABI void __libcpp_aligned_free(void* __ptr) { -# if defined(_LIBCPP_MSVCRT_LIKE) - ::_aligned_free(__ptr); -# else - ::free(__ptr); -# endif -} - -#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MEMORY_ALIGNED_ALLOC_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocate_at_least.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocate_at_least.h deleted file mode 100644 index 3a906c7..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocate_at_least.h +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ALLOCATE_AT_LEAST_H -#define _LIBCPP___CXX03___MEMORY_ALLOCATE_AT_LEAST_H - -#include <__cxx03/__config> -#include <__cxx03/__memory/allocator_traits.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -struct __allocation_result { - _Pointer ptr; - size_t count; -}; - -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI __allocation_result::pointer> -__allocate_at_least(_Alloc& __alloc, size_t __n) { - return {__alloc.allocate(__n), __n}; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MEMORY_ALLOCATE_AT_LEAST_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocation_guard.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocation_guard.h deleted file mode 100644 index 0a2712d..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocation_guard.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ALLOCATION_GUARD_H -#define _LIBCPP___CXX03___MEMORY_ALLOCATION_GUARD_H - -#include <__cxx03/__config> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__memory/allocator_traits.h> -#include <__cxx03/__utility/move.h> -#include <__cxx03/cstddef> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -// Helper class to allocate memory using an Allocator in an exception safe -// manner. -// -// The intended usage of this class is as follows: -// -// 0 -// 1 __allocation_guard guard(alloc, 10); -// 2 do_some_initialization_that_may_throw(guard.__get()); -// 3 save_allocated_pointer_in_a_noexcept_operation(guard.__release_ptr()); -// 4 -// -// If line (2) throws an exception during initialization of the memory, the -// guard's destructor will be called, and the memory will be released using -// Allocator deallocation. Otherwise, we release the memory from the guard on -// line (3) in an operation that can't throw -- after that, the guard is not -// responsible for the memory anymore. -// -// This is similar to a unique_ptr, except it's easier to use with a -// custom allocator. -template -struct __allocation_guard { - using _Pointer = typename allocator_traits<_Alloc>::pointer; - using _Size = typename allocator_traits<_Alloc>::size_type; - - template // we perform the allocator conversion inside the constructor - _LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n) - : __alloc_(std::move(__alloc)), - __n_(__n), - __ptr_(allocator_traits<_Alloc>::allocate(__alloc_, __n_)) // initialization order is important - {} - - _LIBCPP_HIDE_FROM_ABI ~__allocation_guard() _NOEXCEPT { __destroy(); } - - _LIBCPP_HIDE_FROM_ABI __allocation_guard(const __allocation_guard&) = delete; - _LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT - : __alloc_(std::move(__other.__alloc_)), - __n_(__other.__n_), - __ptr_(__other.__ptr_) { - __other.__ptr_ = nullptr; - } - - _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(const __allocation_guard& __other) = delete; - _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(__allocation_guard&& __other) _NOEXCEPT { - if (std::addressof(__other) != this) { - __destroy(); - - __alloc_ = std::move(__other.__alloc_); - __n_ = __other.__n_; - __ptr_ = __other.__ptr_; - __other.__ptr_ = nullptr; - } - - return *this; - } - - _LIBCPP_HIDE_FROM_ABI _Pointer - __release_ptr() _NOEXCEPT { // not called __release() because it's a keyword in objective-c++ - _Pointer __tmp = __ptr_; - __ptr_ = nullptr; - return __tmp; - } - - _LIBCPP_HIDE_FROM_ABI _Pointer __get() const _NOEXCEPT { return __ptr_; } - -private: - _LIBCPP_HIDE_FROM_ABI void __destroy() _NOEXCEPT { - if (__ptr_ != nullptr) { - allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_); - } - } - - _Alloc __alloc_; - _Size __n_; - _Pointer __ptr_; -}; - -_LIBCPP_END_NAMESPACE_STD - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___CXX03___MEMORY_ALLOCATION_GUARD_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator.h deleted file mode 100644 index cd6f7d9..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator.h +++ /dev/null @@ -1,162 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ALLOCATOR_H -#define _LIBCPP___CXX03___MEMORY_ALLOCATOR_H - -#include <__cxx03/__config> -#include <__cxx03/__memory/addressof.h> -#include <__cxx03/__memory/allocate_at_least.h> -#include <__cxx03/__memory/allocator_traits.h> -#include <__cxx03/__type_traits/is_const.h> -#include <__cxx03/__type_traits/is_constant_evaluated.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/is_void.h> -#include <__cxx03/__type_traits/is_volatile.h> -#include <__cxx03/__utility/forward.h> -#include <__cxx03/cstddef> -#include <__cxx03/new> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class allocator; - -template <> -class _LIBCPP_TEMPLATE_VIS allocator { -public: - typedef void* pointer; - typedef const void* const_pointer; - typedef void value_type; - - template - struct rebind { - typedef allocator<_Up> other; - }; -}; - -// TODO(LLVM 20): Remove the escape hatch -#ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST -template <> -class _LIBCPP_TEMPLATE_VIS allocator { -public: - typedef const void* pointer; - typedef const void* const_pointer; - typedef const void value_type; - - template - struct rebind { - typedef allocator<_Up> other; - }; -}; -#endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST - -// This class provides a non-trivial default constructor to the class that derives from it -// if the condition is satisfied. -// -// The second template parameter exists to allow giving a unique type to __non_trivial_if, -// which makes it possible to avoid breaking the ABI when making this a base class of an -// existing class. Without that, imagine we have classes D1 and D2, both of which used to -// have no base classes, but which now derive from __non_trivial_if. The layout of a class -// that inherits from both D1 and D2 will change because the two __non_trivial_if base -// classes are not allowed to share the same address. -// -// By making those __non_trivial_if base classes unique, we work around this problem and -// it is safe to start deriving from __non_trivial_if in existing classes. -template -struct __non_trivial_if {}; - -template -struct __non_trivial_if { - _LIBCPP_HIDE_FROM_ABI __non_trivial_if() _NOEXCEPT {} -}; - -// allocator -// -// Note: For ABI compatibility between C++20 and previous standards, we make -// allocator trivial in C++20. - -template -class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::value, allocator<_Tp> > { - static_assert(!is_const<_Tp>::value, "std::allocator does not support const types"); - static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); - -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp value_type; - typedef true_type propagate_on_container_move_assignment; - typedef true_type is_always_equal; - - _LIBCPP_HIDE_FROM_ABI allocator() _NOEXCEPT = default; - - template - _LIBCPP_HIDE_FROM_ABI allocator(const allocator<_Up>&) _NOEXCEPT {} - - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _Tp* allocate(size_t __n) { - if (__n > allocator_traits::max_size(*this)) - __throw_bad_array_new_length(); - if (__libcpp_is_constant_evaluated()) { - return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); - } else { - return static_cast<_Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); - } - } - - _LIBCPP_HIDE_FROM_ABI void deallocate(_Tp* __p, size_t __n) _NOEXCEPT { - if (__libcpp_is_constant_evaluated()) { - ::operator delete(__p); - } else { - std::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } - } - - // C++20 Removed members - typedef _Tp* pointer; - typedef const _Tp* const_pointer; - typedef _Tp& reference; - typedef const _Tp& const_reference; - - template - struct rebind { - typedef allocator<_Up> other; - }; - - _LIBCPP_HIDE_FROM_ABI pointer address(reference __x) const _NOEXCEPT { return std::addressof(__x); } - _LIBCPP_HIDE_FROM_ABI const_pointer address(const_reference __x) const _NOEXCEPT { return std::addressof(__x); } - - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _Tp* allocate(size_t __n, const void*) { return allocate(__n); } - - _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return size_type(~0) / sizeof(_Tp); } - - template - _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) { - ::new ((void*)__p) _Up(std::forward<_Args>(__args)...); - } - - _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); } -}; - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT { - return true; -} - -template -inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT { - return false; -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MEMORY_ALLOCATOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_arg_t.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_arg_t.h deleted file mode 100644 index 1dbea06..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_arg_t.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___FUNCTIONAL_ALLOCATOR_ARG_T_H -#define _LIBCPP___CXX03___FUNCTIONAL_ALLOCATOR_ARG_T_H - -#include <__cxx03/__config> -#include <__cxx03/__memory/uses_allocator.h> -#include <__cxx03/__type_traits/integral_constant.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__type_traits/remove_cvref.h> -#include <__cxx03/__utility/forward.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { - explicit allocator_arg_t() = default; -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___FUNCTIONAL_ALLOCATOR_ARG_T_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_destructor.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_destructor.h deleted file mode 100644 index 2c69c91..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_destructor.h +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ALLOCATOR_DESTRUCTOR_H -#define _LIBCPP___CXX03___MEMORY_ALLOCATOR_DESTRUCTOR_H - -#include <__cxx03/__config> -#include <__cxx03/__memory/allocator_traits.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template -class __allocator_destructor { - typedef _LIBCPP_NODEBUG allocator_traits<_Alloc> __alloc_traits; - -public: - typedef _LIBCPP_NODEBUG typename __alloc_traits::pointer pointer; - typedef _LIBCPP_NODEBUG typename __alloc_traits::size_type size_type; - -private: - _Alloc& __alloc_; - size_type __s_; - -public: - _LIBCPP_HIDE_FROM_ABI __allocator_destructor(_Alloc& __a, size_type __s) _NOEXCEPT : __alloc_(__a), __s_(__s) {} - _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc_, __p, __s_); } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___CXX03___MEMORY_ALLOCATOR_DESTRUCTOR_H diff --git a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_traits.h b/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_traits.h deleted file mode 100644 index 6e7b8ca..0000000 --- a/third_party/libcxx/include/c++/v1/__cxx03/__memory/allocator_traits.h +++ /dev/null @@ -1,371 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___CXX03___MEMORY_ALLOCATOR_TRAITS_H -#define _LIBCPP___CXX03___MEMORY_ALLOCATOR_TRAITS_H - -#include <__cxx03/__config> -#include <__cxx03/__memory/construct_at.h> -#include <__cxx03/__memory/pointer_traits.h> -#include <__cxx03/__type_traits/enable_if.h> -#include <__cxx03/__type_traits/is_constructible.h> -#include <__cxx03/__type_traits/is_empty.h> -#include <__cxx03/__type_traits/is_same.h> -#include <__cxx03/__type_traits/make_unsigned.h> -#include <__cxx03/__type_traits/remove_reference.h> -#include <__cxx03/__type_traits/void_t.h> -#include <__cxx03/__utility/declval.h> -#include <__cxx03/__utility/forward.h> -#include <__cxx03/cstddef> -#include <__cxx03/limits> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__cxx03/__undef_macros> - -_LIBCPP_BEGIN_NAMESPACE_STD - -#define _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \ - template \ - struct NAME : false_type {}; \ - template \ - struct NAME<_Tp, __void_t > : true_type {} - -// __pointer -template , - bool = __has_pointer<_RawAlloc>::value> -struct __pointer { - using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer; -}; -template -struct __pointer<_Tp, _Alloc, _RawAlloc, false> { - using type _LIBCPP_NODEBUG = _Tp*; -}; - -// __const_pointer -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer); -template ::value> -struct __const_pointer { - using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer; -}; -template -struct __const_pointer<_Tp, _Ptr, _Alloc, false> { - using type = typename pointer_traits<_Ptr>::template rebind::other; -}; - -// __void_pointer -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer); -template ::value> -struct __void_pointer { - using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer; -}; -template -struct __void_pointer<_Ptr, _Alloc, false> { - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind::other; -}; - -// __const_void_pointer -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer); -template ::value> -struct __const_void_pointer { - using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer; -}; -template -struct __const_void_pointer<_Ptr, _Alloc, false> { - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind::other; -}; - -// __size_type -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_size_type, size_type); -template ::value> -struct __size_type : make_unsigned<_DiffType> {}; -template -struct __size_type<_Alloc, _DiffType, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::size_type; -}; - -// __alloc_traits_difference_type -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type); -template ::value> -struct __alloc_traits_difference_type { - using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type; -}; -template -struct __alloc_traits_difference_type<_Alloc, _Ptr, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::difference_type; -}; - -// __propagate_on_container_copy_assignment -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_copy_assignment, propagate_on_container_copy_assignment); -template ::value> -struct __propagate_on_container_copy_assignment : false_type {}; -template -struct __propagate_on_container_copy_assignment<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_copy_assignment; -}; - -// __propagate_on_container_move_assignment -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_move_assignment, propagate_on_container_move_assignment); -template ::value> -struct __propagate_on_container_move_assignment : false_type {}; -template -struct __propagate_on_container_move_assignment<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_move_assignment; -}; - -// __propagate_on_container_swap -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_swap, propagate_on_container_swap); -template ::value> -struct __propagate_on_container_swap : false_type {}; -template -struct __propagate_on_container_swap<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_swap; -}; - -// __is_always_equal -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_is_always_equal, is_always_equal); -template ::value> -struct __is_always_equal : is_empty<_Alloc> {}; -template -struct __is_always_equal<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::is_always_equal; -}; - -// __allocator_traits_rebind -_LIBCPP_SUPPRESS_DEPRECATED_PUSH -template -struct __has_rebind_other : false_type {}; -template -struct __has_rebind_other<_Tp, _Up, __void_t::other> > : true_type {}; - -template ::value> -struct __allocator_traits_rebind { - static_assert(__has_rebind_other<_Tp, _Up>::value, "This allocator has to implement rebind"); - using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other; -}; -template