From 5c77c9a754ff1796f728e214dbd0de312eb687d6 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 15 Mar 2025 15:21:55 +0100 Subject: [PATCH] - Change `distinct` -> `typedef`. - Order of attribute declaration is changed for `alias`. - Added `LANGUAGE_DEV_VERSION` env constant. - Rename `anyfault` -> `fault`. - Changed `fault` -> `faultdef`. - Added `attrdef` instead of `alias` for attribute aliases. --- .github/workflows/main.yml | 14 +-- lib/std/collections/enumset.c3 | 4 +- lib/std/collections/hashmap.c3 | 4 +- lib/std/collections/object.c3 | 6 +- lib/std/collections/priorityqueue.c3 | 4 +- lib/std/compression/qoi.c3 | 5 +- lib/std/core/allocators/libc_allocator.c3 | 2 +- lib/std/core/builtin.c3 | 10 +- lib/std/core/dstring.c3 | 4 +- lib/std/core/env.c3 | 1 + lib/std/core/mem.c3 | 2 +- lib/std/core/mem_allocator.c3 | 4 +- lib/std/core/sanitizer/tsan.c3 | 2 +- lib/std/core/string.c3 | 15 +-- lib/std/core/test.c3 | 7 +- lib/std/core/types.c3 | 4 +- lib/std/encoding/base32.c3 | 2 +- lib/std/encoding/encoding.c3 | 2 +- lib/std/encoding/json.c3 | 2 +- lib/std/hash/fnv32a.c3 | 2 +- lib/std/hash/fnv64a.c3 | 2 +- lib/std/io/formatter.c3 | 10 +- lib/std/io/formatter_private.c3 | 4 +- lib/std/io/io.c3 | 2 +- lib/std/io/os/file_libc.c3 | 4 +- lib/std/io/path.c3 | 2 +- lib/std/libc/libc.c3 | 12 +-- lib/std/libc/os/posix.c3 | 31 +++--- lib/std/libc/termios.c3 | 52 +++++----- lib/std/math/math.c3 | 66 +++++++------ lib/std/math/random/math.lcg.c3 | 8 +- lib/std/math/random/math.mcg.c3 | 8 +- lib/std/math/random/math.pcg.c3 | 8 +- lib/std/math/random/math.sfc.c3 | 12 +-- lib/std/math/random/math.simple_random.c3 | 2 +- lib/std/math/uuid.c3 | 2 +- lib/std/net/net.c3 | 2 +- lib/std/net/os/common.c3 | 14 +-- lib/std/net/os/posix.c3 | 6 +- lib/std/net/os/win32.c3 | 6 +- lib/std/net/socket.c3 | 4 +- lib/std/net/tcp.c3 | 4 +- lib/std/net/udp.c3 | 2 +- lib/std/net/url.c3 | 2 +- lib/std/net/url_encoding.c3 | 2 +- lib/std/os/backtrace.c3 | 9 +- lib/std/os/macos/cf_allocator.c3 | 4 +- lib/std/os/macos/cf_array.c3 | 6 +- lib/std/os/macos/core_foundation.c3 | 3 +- lib/std/os/macos/objc.c3 | 10 +- lib/std/os/posix/files.c3 | 2 +- lib/std/os/posix/threads.c3 | 42 ++++---- lib/std/os/subprocess.c3 | 2 +- lib/std/os/win32/types.c3 | 2 +- lib/std/os/win32/wsa.c3 | 2 +- lib/std/sort/countingsort.c3 | 18 ++-- lib/std/sort/quicksort.c3 | 2 +- lib/std/text/i18n.c3 | 2 +- lib/std/threads/buffered_channel.c3 | 6 +- lib/std/threads/event/event_thread.c3 | 6 +- lib/std/threads/fixed_pool.c3 | 2 +- lib/std/threads/os/thread_none.c3 | 8 +- lib/std/threads/os/thread_win32.c3 | 2 +- lib/std/threads/thread.c3 | 18 ++-- lib/std/threads/unbuffered_channel.c3 | 6 +- lib/std/time/time.c3 | 8 +- releasenotes.md | 8 +- resources/examples/base64.c3 | 2 +- resources/examples/brainfk.c3 | 2 +- resources/examples/contextfree/boolerr.c3 | 3 +- resources/examples/contextfree/cleanup.c3 | 2 +- .../examples/contextfree/guess_number.c3 | 2 +- resources/examples/map.c3 | 2 +- resources/examples/opengl/src/glfw/glfw.c3 | 8 +- resources/examples/plus_minus.c3 | 2 +- resources/examples/retry.c3 | 4 +- src/compiler/c_codegen.c | 7 +- src/compiler/compiler.c | 1 + src/compiler/compiler_internal.h | 5 +- src/compiler/copying.c | 1 - src/compiler/enums.h | 18 ++-- src/compiler/expr.c | 4 - src/compiler/headers.c | 4 +- src/compiler/json_output.c | 2 +- src/compiler/llvm_codegen.c | 14 +-- src/compiler/llvm_codegen_debug_info.c | 2 +- src/compiler/llvm_codegen_expr.c | 42 ++++---- src/compiler/llvm_codegen_function.c | 4 +- src/compiler/llvm_codegen_stmt.c | 16 ++-- src/compiler/llvm_codegen_value.c | 4 +- src/compiler/parse_expr.c | 6 +- src/compiler/parse_global.c | 95 ++++++++++--------- src/compiler/parse_stmt.c | 8 +- src/compiler/sema_casts.c | 15 --- src/compiler/sema_decls.c | 51 ++++------ src/compiler/sema_expr.c | 19 ++-- src/compiler/sema_liveness.c | 1 - src/compiler/sema_stmts.c | 13 ++- src/compiler/sema_types.c | 2 +- src/compiler/tokens.c | 17 ++-- src/compiler/types.c | 12 +-- test/test_suite/arrays/slice_array.c3 | 2 +- .../assert/unreachable_in_macro.c3t | 2 +- .../attributes/attr_not_imported.c3 | 2 +- .../test_suite/attributes/attribute_params.c3 | 4 +- .../attributes/attribute_visibility.c3t | 2 +- .../attributes/attributes_repeat_param.c3t | 2 +- .../attributes/recursive_attributes.c3 | 6 +- .../attributes/user_defined_attributes.c3t | 10 +- test/test_suite/bitstruct/bitstruct_init.c3 | 2 +- .../invalid_bitstruct_member_types.c3 | 4 +- test/test_suite/cast/cast_rcast.c3 | 2 +- test/test_suite/cast/cast_subarray.c3t | 2 +- test/test_suite/cast/cast_to_failable.c3 | 2 +- .../compile_time_access_subscript.c3t | 4 +- .../compile_time/comptime_array_folding.c3t | 4 +- .../recursive_tag.c3 | 2 +- test/test_suite/debug_symbols/defer_macro.c3t | 4 +- .../defer/defer_catch_direct_error.c3t | 2 +- test/test_suite/defer/defer_catch_err.c3t | 10 +- test/test_suite/defer/defer_catch_mix.c3t | 2 +- test/test_suite/defer/defer_catch_try.c3t | 2 +- test/test_suite/define/common2.c3 | 2 +- test/test_suite/define/forbidden_defines.c3 | 2 +- test/test_suite/define/test_at.c3 | 2 +- test/test_suite/define/weak_alias_fails.c3 | 4 +- test/test_suite/define/weak_aliases.c3 | 6 +- .../test_suite/distinct/distinct_function.c3t | 4 +- .../distinct/distinct_function_call.c3 | 2 +- .../distinct/distinct_inline_access.c3 | 2 +- test/test_suite/distinct/distinct_invalid.c3 | 10 +- test/test_suite/distinct/distinct_max.c3t | 2 +- test/test_suite/distinct/distinct_shift.c3t | 2 +- test/test_suite/distinct/distinct_slicing.c3 | 2 +- test/test_suite/distinct/distinct_struct.c3 | 2 +- .../distinct/distinct_struct_array.c3 | 6 +- test/test_suite/distinct/distinct_sub.c3t | 2 +- test/test_suite/distinct/distinct_union.c3 | 6 +- test/test_suite/distinct/test_errors.c3 | 2 +- test/test_suite/distinct/test_ops_on_int.c3 | 2 +- .../test_suite/distinct/test_ops_on_struct.c3 | 2 +- test/test_suite/dynamic/inline_protocol.c3 | 2 +- test/test_suite/enumerations/enum_add_sub.c3t | 4 +- test/test_suite/enumerations/inc_assign.c3t | 2 +- .../enumerations/inc_assign_fail.c3 | 2 +- test/test_suite/errors/anyfault_void.c3t | 4 +- test/test_suite/errors/empty_fault.c3 | 2 +- test/test_suite/errors/error_decl_ok.c3 | 6 +- test/test_suite/errors/error_else.c3t | 2 +- test/test_suite/errors/error_regression_2.c3t | 6 +- .../test_suite/errors/error_semantic_fails.c3 | 2 +- test/test_suite/errors/error_throw.c3 | 2 +- test/test_suite/errors/error_union.c3 | 4 +- test/test_suite/errors/failable_catch.c3t | 2 +- test/test_suite/errors/fault_conv.c3t | 4 +- .../errors/general_error_regression.c3t | 12 +-- test/test_suite/errors/macro_err2.c3t | 2 +- test/test_suite/errors/macro_err3.c3t | 2 +- test/test_suite/errors/missing_bang.c3 | 2 +- test/test_suite/errors/more_optional_tests.c3 | 2 +- test/test_suite/errors/multiple_catch.c3t | 10 +- .../errors/optional_chained_init.c3t | 14 +-- test/test_suite/errors/optional_contracts.c3 | 4 +- test/test_suite/errors/optional_inits.c3t | 2 +- .../errors/optional_taddr_and_access.c3t | 2 +- .../errors/optional_untyped_list.c3 | 2 +- .../errors/optional_with_optional.c3t | 8 +- test/test_suite/errors/or_and_rethrow.c3t | 10 +- .../errors/or_and_rethrow_missing_question.c3 | 2 +- test/test_suite/errors/printing_errors.c3t | 4 +- .../errors/simple_static_failable.c3t | 2 +- test/test_suite/errors/try_assign.c3t | 2 +- test/test_suite/errors/try_catch_if.c3t | 2 +- .../errors/try_catch_unwrapping_while_if.c3 | 2 +- test/test_suite/errors/try_with_unwrapper.c3t | 2 +- test/test_suite/expressions/addr_of_fails.c3 | 4 +- .../expressions/assign_optional.c3t | 2 +- .../casts/cast_enum_const_to_distinct.c3 | 2 +- .../expressions/casts/cast_failable.c3 | 2 +- .../casts/cast_implicit_inline_distinct.c3 | 4 +- .../expressions/casts/explicit_cast.c3 | 2 +- .../failed_distinct_float_conversions.c3 | 4 +- .../casts/struct_cast_and_distinct.c3 | 2 +- .../expressions/casts/void_casting.c3t | 2 +- .../expressions/chained_ternary.c3t | 2 +- test/test_suite/expressions/enum_ct_sub.c3t | 2 +- .../expressions/optional_ternary.c3t | 2 +- .../from_docs/examples_if_catch.c3t | 2 +- .../functions/c_vararg_expansion.c3t | 2 +- .../functions/default_param_fail.c3 | 2 +- .../functions/distinct_fn_ptr_and_lambda.c3t | 2 +- test/test_suite/functions/test_regression.c3t | 2 +- .../functions/test_regression_mingw.c3t | 2 +- .../generic/generic_lambda_complex.c3t | 6 +- test/test_suite/generic/generic_local.c3 | 2 +- test/test_suite/generic/nested_typedef.c3t | 2 +- test/test_suite/globals/init_with_err.c3t | 2 +- .../macros/macro_failable_return_rethrow.c3t | 2 +- .../macros/unifying_implicit_void.c3t | 2 +- .../methods/distinct_arr_method_resolution.c3 | 4 +- .../methods/enum_distinct_err_methods.c3t | 4 +- .../methods/methods_with_inferred_type.c3t | 2 +- .../methods/operator_defined_twice.c3 | 2 +- test/test_suite/methods/self_methods_null.c3t | 2 +- .../statements/for_with_optional.c3t | 2 +- .../statements/foreach_custom_errors.c3 | 2 +- .../statements/foreach_distinct_iterable.c3t | 2 +- .../foreach_distinct_pointer_1506.c3 | 2 +- .../statements/foreach_r_custom_errors.c3 | 2 +- test/test_suite/statements/if_only_throw.c3t | 2 +- test/test_suite/statements/switch_errors.c3 | 2 +- .../statements/various_switching.c3t | 4 +- test/test_suite/struct/struct_bad_member.c3 | 2 +- test/test_suite/switch/failable_switch.c3 | 2 +- .../switch/switch_in_defer_macro.c3t | 8 +- test/unit/regression/catch_err.c3 | 8 +- test/unit/regression/distinct_inline.c3 | 18 ++-- test/unit/stdlib/core/test_test.c3 | 2 +- test/unit/stdlib/math/math_complex.c3 | 10 +- test/unit/stdlib/net/url_encoding.c3 | 2 +- test/unit/stdlib/threads/channel.c3 | 4 +- 221 files changed, 649 insertions(+), 684 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e1bec7a97..07e74d7ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,15 +77,15 @@ jobs: - name: Vendor-fetch run: | - build\${{ matrix.build_type }}\c3c.exe vendor-fetch raylib5 + build\${{ matrix.build_type }}\c3c.exe vendor-fetch raylib55_v7 - name: Try raylib5 run: | cd resources - ..\build\${{ matrix.build_type }}\c3c.exe vendor-fetch raylib5 - ..\build\${{ matrix.build_type }}\c3c.exe compile --lib raylib5 --print-linking examples\raylib\raylib_arkanoid.c3 - ..\build\${{ matrix.build_type }}\c3c.exe compile --lib raylib5 --print-linking examples\raylib\raylib_snake.c3 - ..\build\${{ matrix.build_type }}\c3c.exe compile --lib raylib5 --print-linking examples\raylib\raylib_tetris.c3 + ..\build\${{ matrix.build_type }}\c3c.exe vendor-fetch raylib55_v7 + ..\build\${{ matrix.build_type }}\c3c.exe compile --lib raylib55_v7 --print-linking examples\raylib\raylib_arkanoid.c3 + ..\build\${{ matrix.build_type }}\c3c.exe compile --lib raylib55_v7 --print-linking examples\raylib\raylib_snake.c3 + ..\build\${{ matrix.build_type }}\c3c.exe compile --lib raylib55_v7 --print-linking examples\raylib\raylib_tetris.c3 - name: Compile run unit tests run: | @@ -158,7 +158,7 @@ jobs: - name: Vendor-fetch run: | - ./build/c3c vendor-fetch raylib5 + ./build/c3c vendor-fetch raylib55_v7 - name: Build testproject lib run: | @@ -640,7 +640,7 @@ jobs: - name: Vendor-fetch run: | - ./build/c3c vendor-fetch raylib5 + ./build/c3c vendor-fetch raylib55_v7 - name: Compile and run some examples run: | diff --git a/lib/std/collections/enumset.c3 b/lib/std/collections/enumset.c3 index 110eafec7..416927e19 100644 --- a/lib/std/collections/enumset.c3 +++ b/lib/std/collections/enumset.c3 @@ -8,10 +8,10 @@ module std::collections::enumset{Enum}; import std::io; -alias EnumSetType = $typefrom(type_for_enum_elements(Enum.elements)) @private; +alias EnumSetType @private = $typefrom(type_for_enum_elements(Enum.elements)); const IS_CHAR_ARRAY = Enum.elements > 128; -distinct EnumSet (Printable) = EnumSetType; +typedef EnumSet (Printable) = EnumSetType; fn void EnumSet.add(&self, Enum v) { diff --git a/lib/std/collections/hashmap.c3 b/lib/std/collections/hashmap.c3 index 356eb8367..94943c02c 100644 --- a/lib/std/collections/hashmap.c3 +++ b/lib/std/collections/hashmap.c3 @@ -535,8 +535,8 @@ struct HashMapIterator Entry* current_entry; } -distinct HashMapValueIterator = HashMapIterator; -distinct HashMapKeyIterator = HashMapIterator; +typedef HashMapValueIterator = HashMapIterator; +typedef HashMapKeyIterator = HashMapIterator; <* diff --git a/lib/std/collections/object.c3 b/lib/std/collections/object.c3 index 90a79d625..a3e610d68 100644 --- a/lib/std/collections/object.c3 +++ b/lib/std/collections/object.c3 @@ -462,7 +462,7 @@ fn Object* Object.get_or_create_obj(&self, String key) return container; } -alias ObjectInternalMap = HashMap{String, Object*} @private; -alias ObjectInternalList = List{Object*} @private; -alias ObjectInternalMapEntry = Entry{String, Object*} @private; +alias ObjectInternalMap @private = HashMap {String, Object*}; +alias ObjectInternalList @private = List {Object*}; +alias ObjectInternalMapEntry @private = Entry {String, Object*}; diff --git a/lib/std/collections/priorityqueue.c3 b/lib/std/collections/priorityqueue.c3 index bce7fd1da..64d9a595d 100644 --- a/lib/std/collections/priorityqueue.c3 +++ b/lib/std/collections/priorityqueue.c3 @@ -23,8 +23,8 @@ module std::collections::priorityqueue{Type}; import std::collections::priorityqueue::private; -distinct PriorityQueue = inline PrivatePriorityQueue{Type, false}; -distinct PriorityQueueMax = inline PrivatePriorityQueue{Type, true}; +typedef PriorityQueue = inline PrivatePriorityQueue{Type, false}; +typedef PriorityQueueMax = inline PrivatePriorityQueue{Type, true}; module std::collections::priorityqueue::private{Type, MAX}; import std::collections::list, std::io; diff --git a/lib/std/compression/qoi.c3 b/lib/std/compression/qoi.c3 index 02cba0ec7..a389d2a12 100644 --- a/lib/std/compression/qoi.c3 +++ b/lib/std/compression/qoi.c3 @@ -37,12 +37,11 @@ struct QOIDesc QOIChannels channels; QOIColorspace colorspace; } - <* QOI Errors. These are all the possible bad outcomes. *> -fault INVALID_PARAMETERS, FILE_OPEN_FAILED, FILE_WRITE_FAILED, INVALID_DATA, TOO_MANY_PIXELS; +faultdef INVALID_PARAMETERS, FILE_OPEN_FAILED, FILE_WRITE_FAILED, INVALID_DATA, TOO_MANY_PIXELS; // Let the user decide if they want to use std::io @@ -417,7 +416,7 @@ macro @enumcast($Type, raw) return INVALID_DATA?; } -distinct Pixel = inline char[<4>]; +typedef Pixel = inline char[<4>]; macro char Pixel.hash(Pixel p) { return (p.r * 3 + p.g * 5 + p.b * 7 + p.a * 11) % 64; diff --git a/lib/std/core/allocators/libc_allocator.c3 b/lib/std/core/allocators/libc_allocator.c3 index db33ff4f4..026aaef8c 100644 --- a/lib/std/core/allocators/libc_allocator.c3 +++ b/lib/std/core/allocators/libc_allocator.c3 @@ -7,7 +7,7 @@ import std::io; import libc; const LibcAllocator LIBC_ALLOCATOR = {}; -distinct LibcAllocator (Allocator, Printable) = uptr; +typedef LibcAllocator (Allocator, Printable) = uptr; fn String LibcAllocator.to_string(&self, Allocator allocator) @dynamic => "Libc allocator".copy(allocator); fn usz? LibcAllocator.to_format(&self, Formatter *format) @dynamic => format.print("Libc allocator"); diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index fecc3e938..a3cdb3b47 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -25,24 +25,24 @@ macro foo(a, #b = EMPTY_MACRO_SLOT) *> const EmptySlot EMPTY_MACRO_SLOT @builtin = null; -distinct EmptySlot = void*; +typedef EmptySlot = void*; macro @is_empty_macro_slot(#arg) @const @builtin => @typeis(#arg, EmptySlot); macro @is_valid_macro_slot(#arg) @const @builtin => !@typeis(#arg, EmptySlot); /* Use `IteratorResult` when reading the end of an iterator, or accessing a result out of bounds. */ -fault NO_MORE_ELEMENT @builtin; +faultdef NO_MORE_ELEMENT @builtin; /* Use `SearchResult` when trying to return a value from some collection but the element is missing. */ -fault NOT_FOUND @builtin; +faultdef NOT_FOUND @builtin; /* Use `CastResult` when an attempt at conversion fails. */ -fault TYPE_MISMATCH @builtin; +faultdef TYPE_MISMATCH @builtin; alias VoidFn = fn void(); @@ -373,7 +373,7 @@ macro swizzle2(v, v2, ...) @builtin @require @typekind(#expr) == OPTIONAL : `@catch expects an Optional value` *> -macro anyfault @catch(#expr) @builtin +macro fault @catch(#expr) @builtin { if (catch f = #expr) return f; return {}; diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index 80948fad1..3ef63db93 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -1,8 +1,8 @@ module std::core::dstring; import std::io; -distinct DString (OutStream) = DStringOpaque*; -distinct DStringOpaque = void; +typedef DString (OutStream) = DStringOpaque*; +typedef DStringOpaque = void; const usz MIN_CAPACITY @private = 16; diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index 337d1812a..0c9f7c3a8 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -157,6 +157,7 @@ const bool ADDRESS_SANITIZER = $$ADDRESS_SANITIZER; const bool MEMORY_SANITIZER = $$MEMORY_SANITIZER; const bool THREAD_SANITIZER = $$THREAD_SANITIZER; const bool ANY_SANITIZER = ADDRESS_SANITIZER || MEMORY_SANITIZER || THREAD_SANITIZER; +const int LANGUAGE_DEV_VERSION = $$LANGUAGE_DEV_VERSION; macro bool os_is_darwin() @const { diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index 968862e08..7ff3de886 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -8,7 +8,7 @@ import std::math; const MAX_MEMORY_ALIGNMENT = 0x1000_0000; const DEFAULT_MEM_ALIGNMENT = (void*.alignof) * 2; -fault OUT_OF_MEMORY, INVALID_ALLOC_SIZE; +faultdef OUT_OF_MEMORY, INVALID_ALLOC_SIZE; macro bool @constant_is_power_of_2($x) @const @private { diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index 6f803b2d2..228491377 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -358,7 +358,7 @@ macro void*? @aligned_realloc(#calloc_fn, #free_fn, void* old_pointer, usz bytes // All allocators -alias mem = thread_allocator @builtin; +alias mem @builtin = thread_allocator ; tlocal Allocator thread_allocator @private = base_allocator(); Allocator temp_base_allocator @private = base_allocator(); @@ -444,7 +444,7 @@ fn TempAllocator* temp_allocator_next() @private } const NullAllocator NULL_ALLOCATOR = {}; -distinct NullAllocator (Allocator) = uptr; +typedef NullAllocator (Allocator) = uptr; fn void*? NullAllocator.acquire(&self, usz bytes, AllocInitType init_type, usz alignment) @dynamic { diff --git a/lib/std/core/sanitizer/tsan.c3 b/lib/std/core/sanitizer/tsan.c3 index b9bf3da7b..90dfe254c 100644 --- a/lib/std/core/sanitizer/tsan.c3 +++ b/lib/std/core/sanitizer/tsan.c3 @@ -1,6 +1,6 @@ module std::core::sanitizer::tsan; -distinct MutexFlags = inline CUInt; +typedef MutexFlags = inline CUInt; const MutexFlags MUTEX_LINKER_INIT = 1 << 0; const MutexFlags MUTEX_WRITE_REENTRANT = 1 << 1; diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 491345f12..ac05d8b3f 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -2,14 +2,16 @@ module std::core::string; import std::ascii; import std::io; -distinct String @if(!$defined(String)) = inline char[]; -distinct ZString = inline char*; -distinct WString = inline Char16*; +typedef String @if(!$defined(String)) = inline char[]; +typedef ZString = inline char*; +typedef WString = inline Char16*; + alias Char32 = uint; alias Char16 = ushort; -fault INVALID_UTF8, INVALID_UTF16, CONVERSION_FAILED, EMPTY_STRING, NEGATIVE_VALUE, MALFORMED_INTEGER, - INTEGER_OVERFLOW, MALFORMED_FLOAT, FLOAT_OUT_OF_RANGE; +faultdef INVALID_UTF8, INVALID_UTF16, CONVERSION_FAILED, + EMPTY_STRING, NEGATIVE_VALUE, MALFORMED_INTEGER, + INTEGER_OVERFLOW, MALFORMED_FLOAT, FLOAT_OUT_OF_RANGE; const uint SURROGATE_OFFSET @private = 0x10000; const uint SURROGATE_GENERIC_MASK @private = 0xF800; @@ -19,7 +21,6 @@ const uint SURROGATE_BITS @private = 10; const uint SURROGATE_LOW_VALUE @private = 0xDC00; const uint SURROGATE_HIGH_VALUE @private = 0xD800; - macro Char32* @wstring32(String $string) @builtin { return (Char32*)&&$$wstr32($string); @@ -279,7 +280,7 @@ fn String[] String.split(s, Allocator allocator, String needle, usz max = 0, boo *> fn String[] String.tsplit(s, String needle, usz max = 0, bool skip_empty = false) => s.split(tmem(), needle, max, skip_empty) @inline; -fault BUFFER_EXCEEDED; +faultdef BUFFER_EXCEEDED; <* Split a string into parts, e.g "a|b|c" split with "|" yields { "a", "b", "c" } diff --git a/lib/std/core/test.c3 b/lib/std/core/test.c3 index 7103c610f..c5d4dc897 100644 --- a/lib/std/core/test.c3 +++ b/lib/std/core/test.c3 @@ -8,10 +8,7 @@ Example: module sample::m; import std::io; -fault MathError -{ - DIVISION_BY_ZERO -} +faultdef DIVISION_BY_ZERO; fn double? divide(int a, int b) { @@ -87,7 +84,7 @@ macro @check(#condition, String format = "", args...) @param error_expected : `expected error of function execution` @require runtime::test_context != null : "Only allowed in @test functions" *> -macro @error(#funcresult, anyfault error_expected) +macro @error(#funcresult, fault error_expected) { if (catch err = #funcresult) { diff --git a/lib/std/core/types.c3 b/lib/std/core/types.c3 index e5a4d891b..f92281a7a 100644 --- a/lib/std/core/types.c3 +++ b/lib/std/core/types.c3 @@ -3,7 +3,7 @@ module std::core::types; import libc; -fault VALUE_OUT_OF_RANGE, VALUE_OUT_OF_UNSIGNED_RANGE; +faultdef VALUE_OUT_OF_RANGE, VALUE_OUT_OF_UNSIGNED_RANGE; <* @require $Type.kindof.is_int() : "Type was not an integer" @@ -356,7 +356,7 @@ enum TypeKind : char UNSIGNED_INT, FLOAT, TYPEID, - ANYFAULT, + FAULT, ANY, ENUM, STRUCT, diff --git a/lib/std/encoding/base32.c3 b/lib/std/encoding/base32.c3 index 912716982..1fb5a6d5a 100644 --- a/lib/std/encoding/base32.c3 +++ b/lib/std/encoding/base32.c3 @@ -242,7 +242,7 @@ const char INVALID @private = 0xff; const int STD_PADDING = '='; const int NO_PADDING = -1; -distinct Alphabet = char[32]; +typedef Alphabet = char[32]; // Standard base32 Alphabet const Alphabet STD_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; // Extended Hex Alphabet diff --git a/lib/std/encoding/encoding.c3 b/lib/std/encoding/encoding.c3 index e94d34f04..f3bc02b2a 100644 --- a/lib/std/encoding/encoding.c3 +++ b/lib/std/encoding/encoding.c3 @@ -1,3 +1,3 @@ module std::encoding; -fault INVALID_CHARACTER, INVALID_PADDING; \ No newline at end of file +faultdef INVALID_CHARACTER, INVALID_PADDING; \ No newline at end of file diff --git a/lib/std/encoding/json.c3 b/lib/std/encoding/json.c3 index 265641c47..99cfa7e98 100644 --- a/lib/std/encoding/json.c3 +++ b/lib/std/encoding/json.c3 @@ -6,7 +6,7 @@ import std::io; import std::ascii; import std::collections::object; -fault UNEXPECTED_CHARACTER, INVALID_ESCAPE_SEQUENCE, DUPLICATE_MEMBERS, INVALID_NUMBER; +faultdef UNEXPECTED_CHARACTER, INVALID_ESCAPE_SEQUENCE, DUPLICATE_MEMBERS, INVALID_NUMBER; fn Object*? parse_string(Allocator allocator, String s) { diff --git a/lib/std/hash/fnv32a.c3 b/lib/std/hash/fnv32a.c3 index f5c7ec597..a0eddaeca 100644 --- a/lib/std/hash/fnv32a.c3 +++ b/lib/std/hash/fnv32a.c3 @@ -3,7 +3,7 @@ // a copy of which can be found in the LICENSE_STDLIB file. module std::hash::fnv32a; -distinct Fnv32a = uint; +typedef Fnv32a = uint; const FNV32A_START @private = 0x811c9dc5; const FNV32A_MUL @private = 0x01000193; diff --git a/lib/std/hash/fnv64a.c3 b/lib/std/hash/fnv64a.c3 index 628e6704f..cd108710a 100644 --- a/lib/std/hash/fnv64a.c3 +++ b/lib/std/hash/fnv64a.c3 @@ -3,7 +3,7 @@ // a copy of which can be found in the LICENSE_STDLIB file. module std::hash::fnv64a; -distinct Fnv64a = ulong; +typedef Fnv64a = ulong; const FNV64A_START @private = 0xcbf29ce484222325; const FNV64A_MUL @private = 0x00000100000001b3; diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index ba1e89ffd..1a9d92935 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -10,8 +10,8 @@ interface Printable fn usz? to_format(Formatter* formatter) @optional; } -fault BUFFER_EXCEEDED, INTERNAL_BUFFER_EXCEEDED, INVALID_FORMAT, NOT_ENOUGH_ARGUMENTS, - INVALID_ARGUMENT; +faultdef BUFFER_EXCEEDED, INTERNAL_BUFFER_EXCEEDED, INVALID_FORMAT, + NOT_ENOUGH_ARGUMENTS, INVALID_ARGUMENT; alias OutputFn = fn void?(void* buffer, char c); alias FloatType = double; @@ -70,7 +70,7 @@ struct Formatter uint width; uint prec; usz idx; - anyfault first_fault; + fault first_fault; } } @@ -146,8 +146,8 @@ fn usz? Formatter.out_str(&self, any arg) @private return self.out_substr("typeid"); case VOID: return self.out_substr("void"); - case ANYFAULT: - return self.out_substr((*(anyfault*)arg.ptr).nameof); + case FAULT: + return self.out_substr((*(fault*)arg.ptr).nameof); case INTERFACE: case ANY: return self.out_str(*(any*)arg); diff --git a/lib/std/io/formatter_private.c3 b/lib/std/io/formatter_private.c3 index 399124b87..dbaf5f035 100644 --- a/lib/std/io/formatter_private.c3 +++ b/lib/std/io/formatter_private.c3 @@ -4,7 +4,7 @@ import std::math; const char[16] XDIGITS_H = "0123456789ABCDEF"; const char[16] XDIGITS_L = "0123456789abcdef"; -fault BAD_FORMAT; +faultdef BAD_FORMAT; fn usz? print_hex_chars(Formatter* f, char[] out, bool uppercase) @inline { @@ -22,7 +22,7 @@ fn usz? print_hex_chars(Formatter* f, char[] out, bool uppercase) @inline return len; } -macro Formatter.first_err(&self, anyfault f) +macro Formatter.first_err(&self, fault f) { if (self.first_fault) return self.first_fault; self.first_fault = f; diff --git a/lib/std/io/io.c3 b/lib/std/io/io.c3 index 9454c5341..cf1edda21 100644 --- a/lib/std/io/io.c3 +++ b/lib/std/io/io.c3 @@ -11,7 +11,7 @@ enum Seek END } -fault +faultdef ALREADY_EXISTS, BUSY, CANNOT_READ_DIR, diff --git a/lib/std/io/os/file_libc.c3 b/lib/std/io/os/file_libc.c3 index 663c0e5d5..388b1c7e6 100644 --- a/lib/std/io/os/file_libc.c3 +++ b/lib/std/io/os/file_libc.c3 @@ -76,7 +76,7 @@ fn usz? native_fread(CFile file, char[] buffer) @inline return libc::fread(buffer.ptr, 1, buffer.len, file); } -macro anyfault file_open_errno() @local +macro fault file_open_errno() @local { switch (libc::errno()) { @@ -104,7 +104,7 @@ macro anyfault file_open_errno() @local } } -macro anyfault file_seek_errno() @local +macro fault file_seek_errno() @local { switch (libc::errno()) { diff --git a/lib/std/io/path.c3 b/lib/std/io/path.c3 index 2aa71bb0c..43908e9cc 100644 --- a/lib/std/io/path.c3 +++ b/lib/std/io/path.c3 @@ -9,7 +9,7 @@ const char PREFERRED_SEPARATOR = env::WIN32 ? PREFERRED_SEPARATOR_WIN32 : PREFER alias PathList = List { Path }; -fault INVALID_PATH, NO_PARENT; +faultdef INVALID_PATH, NO_PARENT; alias Path = PathImp; diff --git a/lib/std/libc/libc.c3 b/lib/std/libc/libc.c3 index 686f29d99..1f1a6aeb1 100644 --- a/lib/std/libc/libc.c3 +++ b/lib/std/libc/libc.c3 @@ -46,12 +46,12 @@ fn void errno_set(Errno e) os::errno_set((int)e); } -distinct Errno = inline CInt; +typedef Errno = inline CInt; alias TerminateFunction = fn void(); alias CompareFunction = fn int(void*, void*); alias JmpBuf = uptr[$$JMP_BUF_SIZE]; alias Fd = CInt; -alias Fpos_t = long @if(env::WIN32); +alias Fpos_t @if(env::WIN32) = long; alias SignalFunction = fn void(CInt); const CInt SIGHUP = 1; @@ -433,11 +433,11 @@ struct TimeSpec } -alias Clock_t = int @if(env::WIN32); -alias Clock_t = CLong @if(!env::WIN32); +alias Clock_t @if(env::WIN32) = int; +alias Clock_t @if(!env::WIN32) = CLong; -alias TimeOffset = int @if(env::WASI) ; -alias TimeOffset = CLong @if(!env::WASI) ; +alias TimeOffset @if(env::WASI) = int; +alias TimeOffset @if(!env::WASI) = CLong ; const int TIME_UTC = 1; diff --git a/lib/std/libc/os/posix.c3 b/lib/std/libc/os/posix.c3 index 0cac1dc5b..2efa1a256 100644 --- a/lib/std/libc/os/posix.c3 +++ b/lib/std/libc/os/posix.c3 @@ -27,8 +27,8 @@ const CUInt SA_RESTART = env::LINUX ? 0x10000000 : 0x0002; const CUInt SA_RESETHAND = env::LINUX ? 0x80000000 : 0x0004; const CUInt SA_SIGINFO = env::LINUX ? 0x00000004 : 0x0040; -alias Sigset_t = uint @if(!env::LINUX); -alias Sigset_t = ulong[16] @if(env::LINUX); +alias Sigset_t @if(!env::LINUX) = uint; +alias Sigset_t @if(env::LINUX) = ulong[16]; alias SigActionFunction = fn void(CInt, void*, void*); struct Sigaction @@ -64,10 +64,10 @@ extern fn CInt sigaction(CInt signum, Sigaction *action, Sigaction *oldaction); module libc::termios @if(env::LIBC &&& env::POSIX); -distinct Cc = char; -distinct Speed = CUInt; -distinct Tcflags = CUInt; -distinct Tcactions = CInt; +typedef Cc = char; +typedef Speed = CUInt; +typedef Tcflags = CUInt; +typedef Tcactions = CInt; const Tcactions TCOOFF = 0; const Tcactions TCOON = 1; @@ -187,14 +187,15 @@ extern fn CInt cfsetospeed(Termios* self, Speed speed); extern fn CInt cfsetispeed(Termios* self, Speed speed); const CInt NCCS = 32; -struct Termios { - Tcflags c_iflag; - Tcflags c_oflag; - Tcflags c_cflag; - Tcflags c_lflag; - Cc c_line; - Cc[NCCS] c_cc; - Speed c_ispeed; - Speed c_ospeed; +struct Termios +{ + Tcflags c_iflag; + Tcflags c_oflag; + Tcflags c_cflag; + Tcflags c_lflag; + Cc c_line; + Cc[NCCS] c_cc; + Speed c_ispeed; + Speed c_ospeed; } diff --git a/lib/std/libc/termios.c3 b/lib/std/libc/termios.c3 index de33e4875..b1730db2b 100644 --- a/lib/std/libc/termios.c3 +++ b/lib/std/libc/termios.c3 @@ -13,110 +13,112 @@ fn int Termios.setAttr(Termios* self, Fd fd, Tcactions optional_actions) => tcse module libc::termios @if(!env::LIBC ||| !env::POSIX); -distinct Cc = char; -distinct Speed = CUInt; -distinct Tcflags = CUInt; -struct Termios { - void* dummy; +typedef Cc = char; +typedef Speed = CUInt; +typedef Tcflags = CUInt; + +struct Termios +{ + void* dummy; } fn CInt tcgetattr(Fd fd, Termios* self) { - unreachable("tcgetattr unavailable"); + unreachable("tcgetattr unavailable"); } fn CInt tcsetattr(Fd fd, CInt optional_actions, Termios* self) { - unreachable("tcsetattr unavailable"); + unreachable("tcsetattr unavailable"); } fn CInt tcsendbreak(Fd fd, CInt duration) { - unreachable("tcsendbreak unavailable"); + unreachable("tcsendbreak unavailable"); } fn CInt tcdrain(Fd fd) { - unreachable("tcdrain unavailable"); + unreachable("tcdrain unavailable"); } fn CInt tcflush(Fd fd, CInt queue_selector) { - unreachable("tcflush unavailable"); + unreachable("tcflush unavailable"); } fn CInt tcflow(Fd fd, CInt action) { - unreachable("tcflow unavailable"); + unreachable("tcflow unavailable"); } fn Speed cfgetospeed(Termios* self) { - unreachable("cfgetospeed unavailable"); + unreachable("cfgetospeed unavailable"); } fn Speed cfgetispeed(Termios* self) { - unreachable("cfgetispeed unavailable"); + unreachable("cfgetispeed unavailable"); } fn CInt cfsetospeed(Termios* self, Speed speed) { - unreachable("cfsetospeed unavailable"); + unreachable("cfsetospeed unavailable"); } fn CInt cfsetispeed(Termios* self, Speed speed) { - unreachable("cfsetispeed unavailable"); + unreachable("cfsetispeed unavailable"); } fn int sendBreak(Fd fd, int duration) { - unreachable("sendBreak unavailable"); + unreachable("sendBreak unavailable"); } fn int drain(Fd fd) { - unreachable("drain unavailable"); + unreachable("drain unavailable"); } fn int flush(Fd fd, int queue_selector) { - unreachable("flush unavailable"); + unreachable("flush unavailable"); } fn int flow(Fd fd, int action) { - unreachable("flow unavailable"); + unreachable("flow unavailable"); } fn Speed Termios.getOSpeed(Termios* self) { - unreachable("Termios.getOSpeed unavailable"); + unreachable("Termios.getOSpeed unavailable"); } fn Speed Termios.getISpeed(Termios* self) { - unreachable("Termios.getISpeed unavailable"); + unreachable("Termios.getISpeed unavailable"); } fn int Termios.setOSpeed(Termios* self, Speed speed) { - unreachable("Termios.setOSpeed unavailable"); + unreachable("Termios.setOSpeed unavailable"); } fn int Termios.setISpeed(Termios* self, Speed speed) { - unreachable("Termios.setISpeed unavailable"); + unreachable("Termios.setISpeed unavailable"); } fn int Termios.getAttr(Termios* self, Fd fd) { - unreachable("Termios.getAttr unavailable"); + unreachable("Termios.getAttr unavailable"); } fn int Termios.setAttr(Termios* self, Fd fd, int optional_actions) { - unreachable("Termios.setAttr unavailable"); + unreachable("Termios.setAttr unavailable"); } diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index f41563e59..71343cf5f 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -80,43 +80,41 @@ enum RoundingMode : int TOWARD_NEG_INFINITY } -fault OVERFLOW, MATRIX_INVERSE_DOESNT_EXIST; +faultdef OVERFLOW, MATRIX_INVERSE_DOESNT_EXIST; -alias Complexf = Complex{float}; -alias Complex = Complex{double}; -alias COMPLEX_IDENTITY = complex::IDENTITY{double} @builtin; -alias COMPLEXF_IDENTITY = complex::IDENTITY{float} @builtin; +alias Complexf = Complex {float}; +alias Complex = Complex {double}; +alias COMPLEX_IDENTITY @builtin = complex::IDENTITY {double}; +alias COMPLEXF_IDENTITY @builtin = complex::IDENTITY {float}; -alias Quaternionf = Quaternion{float}; -alias Quaternion = Quaternion{double}; -alias QUATERNION_IDENTITY = quaternion::IDENTITY{double} @builtin; -alias QUATERNIONF_IDENTITY = quaternion::IDENTITY{float} @builtin; +alias Quaternionf = Quaternion {float}; +alias Quaternion = Quaternion {double}; +alias QUATERNION_IDENTITY @builtin = quaternion::IDENTITY {double}; +alias QUATERNIONF_IDENTITY @builtin = quaternion::IDENTITY {float}; -alias Matrix2f = Matrix2x2{float}; -alias Matrix2 = Matrix2x2{double}; -alias Matrix3f = Matrix3x3{float}; -alias Matrix3 = Matrix3x3{double}; -alias Matrix4f = Matrix4x4{float}; -alias Matrix4 = Matrix4x4{double}; -alias matrix4_ortho = matrix::ortho{double} @builtin; -alias matrix4_perspective = matrix::perspective{double} @builtin; -alias matrix4f_ortho = matrix::ortho{float} @builtin; -alias matrix4f_perspective = matrix::perspective{float} @builtin; +alias Matrix2f = Matrix2x2 {float}; +alias Matrix2 = Matrix2x2 {double}; +alias Matrix3f = Matrix3x3 {float}; +alias Matrix3 = Matrix3x3 {double}; +alias Matrix4f = Matrix4x4 {float}; +alias Matrix4 = Matrix4x4 {double}; +alias matrix4_ortho @builtin = matrix::ortho {double}; +alias matrix4f_ortho @builtin = matrix::ortho {float}; +alias matrix4_perspective @builtin = matrix::perspective {double}; +alias matrix4f_perspective @builtin = matrix::perspective {float}; -alias MATRIX2_IDENTITY = matrix::IDENTITY2{double} @builtin; -alias MATRIX2F_IDENTITY = matrix::IDENTITY2{float} @builtin; -alias MATRIX3_IDENTITY = matrix::IDENTITY3{double} @builtin; -alias MATRIX3F_IDENTITY = matrix::IDENTITY3{float} @builtin; -alias MATRIX4_IDENTITY = matrix::IDENTITY4{double} @builtin; -alias MATRIX4F_IDENTITY = matrix::IDENTITY4{float} @builtin; +alias MATRIX2_IDENTITY @builtin = matrix::IDENTITY2 {double}; +alias MATRIX2F_IDENTITY @builtin = matrix::IDENTITY2 {float}; +alias MATRIX3_IDENTITY @builtin = matrix::IDENTITY3 {double}; +alias MATRIX3F_IDENTITY @builtin = matrix::IDENTITY3 {float}; +alias MATRIX4_IDENTITY @builtin = matrix::IDENTITY4 {double}; +alias MATRIX4F_IDENTITY @builtin = matrix::IDENTITY4 {float}; <* @require types::is_numerical($typeof(x)) : `The input must be a numerical value or numerical vector` *> -macro deg_to_rad(x) { - return x * PI / 180; -} +macro deg_to_rad(x) => x * PI / 180; <* @require types::is_numerical($typeof(x)) : `The input must be a numerical value or numerical vector` @@ -209,7 +207,7 @@ macro sincos(x) *> macro atan(x) { - $if @typeid(x) == float.typeid: + $if @typeis(x, float): return _atanf(x); $else return _atan(x); @@ -221,7 +219,7 @@ macro atan(x) *> macro atanh(x) { - $if @typeid(x) == float.typeid: + $if @typeis(x, float): return _atanhf(x); $else return _atanh(x); @@ -233,7 +231,7 @@ macro atanh(x) *> macro acos(x) { - $if @typeid(x) == float.typeid: + $if @typeis(x, float): return _acosf(x); $else return _acos(x); @@ -245,7 +243,7 @@ macro acos(x) *> macro acosh(x) { - $if @typeid(x) == float.typeid: + $if @typeis(x, float): return _acoshf(x); $else return _acosh(x); @@ -257,7 +255,7 @@ macro acosh(x) *> macro asin(x) { - $if @typeid(x) == float.typeid: + $if @typeis(x, float): return _asinf(x); $else return _asin(x); @@ -269,7 +267,7 @@ macro asin(x) *> macro asinh(x) { - $if @typeid(x) == float.typeid: + $if @typeis(x, float): return _asinhf(x); $else return _asinh(x); diff --git a/lib/std/math/random/math.lcg.c3 b/lib/std/math/random/math.lcg.c3 index 79e0fe2b0..df65f3428 100644 --- a/lib/std/math/random/math.lcg.c3 +++ b/lib/std/math/random/math.lcg.c3 @@ -13,7 +13,7 @@ const MUL_LCG16 @local = 0x915d; // TODO: Find good constant // Lcg128_64 -distinct Lcg128Random (Random) = uint128; +typedef Lcg128Random (Random) = uint128; fn void Lcg128Random.set_seed(&self, char[] input) @dynamic { @@ -40,7 +40,7 @@ fn char Lcg128Random.next_byte(&self) @dynamic => (char)self.next_long(); // -------------------------------- Lcg64_32 -------------------------------- -distinct Lcg64Random (Random) = ulong; +typedef Lcg64Random (Random) = ulong; fn void Lcg64Random.set_seed(&self, char[] seed) @dynamic { @@ -67,7 +67,7 @@ fn char Lcg64Random.next_byte(&self) @dynamic => (char)self.next_int(); // -------------------------------- Lcg32_16 -------------------------------- -distinct Lcg32Random (Random) = uint; +typedef Lcg32Random (Random) = uint; fn void Lcg32Random.set_seed(&self, char[] seed) @dynamic { @@ -90,7 +90,7 @@ fn char Lcg32Random.next_byte(&self) @dynamic => (char)self.next_short(); // -------------------------------- Lcg16_8 -------------------------------- -distinct Lcg16Random (Random) = ushort; +typedef Lcg16Random (Random) = ushort; fn void Lcg16Random.set_seed(&self, char[] seed) @dynamic { diff --git a/lib/std/math/random/math.mcg.c3 b/lib/std/math/random/math.mcg.c3 index 4c57787c4..a82e90b51 100644 --- a/lib/std/math/random/math.mcg.c3 +++ b/lib/std/math/random/math.mcg.c3 @@ -7,7 +7,7 @@ const MUL_MCG16 @local = 0x93d5; // TODO: Find good constant // Mcg128_64 -distinct Mcg128Random (Random) = uint128; +typedef Mcg128Random (Random) = uint128; fn void Mcg128Random.set_seed(&self, char[] seed) @dynamic { @@ -40,7 +40,7 @@ fn char Mcg128Random.next_byte(&self) @dynamic => (char)self.next_long(); // Mcg64RandomState -distinct Mcg64Random (Random) = ulong; +typedef Mcg64Random (Random) = ulong; fn void Mcg64Random.set_seed(&self, char[] seed) @dynamic { @@ -71,7 +71,7 @@ fn char Mcg64Random.next_byte(&self) @dynamic => (char)self.next_int(); // Mcg32Random -distinct Mcg32Random (Random) = uint; +typedef Mcg32Random (Random) = uint; fn void Mcg32Random.set_seed(&self, char[] seed) @dynamic { @@ -97,7 +97,7 @@ fn char Mcg32Random.next_byte(&self) @dynamic => (char)self.next_short(); // -------------------------------- Mcg16RandomState -------------------------------- -distinct Mcg16Random (Random) = ushort; +typedef Mcg16Random (Random) = ushort; fn void Mcg16Random.set_seed(&self, char[] seed) @dynamic { diff --git a/lib/std/math/random/math.pcg.c3 b/lib/std/math/random/math.pcg.c3 index 53d56c477..aa0fc44a9 100644 --- a/lib/std/math/random/math.pcg.c3 +++ b/lib/std/math/random/math.pcg.c3 @@ -15,7 +15,7 @@ const MUL_LCG16 @local = 0x915d; // TODO: Find good constant // -------------------------------- Pcg128_64 -------------------------------- -distinct Pcg128Random (Random) = uint128; +typedef Pcg128Random (Random) = uint128; fn void Pcg128Random.set_seed(&self, char[] input) @dynamic { @@ -44,7 +44,7 @@ fn char Pcg128Random.next_byte(&self) @dynamic => (char)self.next_long(); // -------------------------------- Pcg64_32 -------------------------------- -distinct Pcg64Random (Random) = ulong; +typedef Pcg64Random (Random) = ulong; fn void Pcg64Random.set_seed(&self, char[] input) @dynamic { @@ -73,7 +73,7 @@ fn char Pcg64Random.next_byte(&self) @dynamic => (char)self.next_int(); // -------------------------------- Pcg32_16 -------------------------------- -distinct Pcg32Random (Random) = uint; +typedef Pcg32Random (Random) = uint; fn void Pcg32Random.set_seed(&self, char[] input) @dynamic { @@ -101,7 +101,7 @@ fn char Pcg32Random.next_byte(&self) @dynamic => (char)self.next_short(); // -------------------------------- Pcg16_8 -------------------------------- -distinct Pcg16Random (Random) = ushort; +typedef Pcg16Random (Random) = ushort; fn void Pcg16Random.set_seed(&self, char[] input) @dynamic { diff --git a/lib/std/math/random/math.sfc.c3 b/lib/std/math/random/math.sfc.c3 index acf05822e..df3a2ee6f 100644 --- a/lib/std/math/random/math.sfc.c3 +++ b/lib/std/math/random/math.sfc.c3 @@ -10,9 +10,9 @@ const ODD_PHI8 @local = 0x9f; // Sfc128 -distinct Sfc128Random (Random) = uint128[4]; +typedef Sfc128Random (Random) = uint128[4]; -fn void Sfc128Random.set_seed(&self, char[] input) @dynamic +fn void Sfc128Random.set_seed(&self, char[] input) @dynamic { *self = (Sfc128Random)random::make_seed(uint128[4], input); } @@ -40,7 +40,7 @@ fn char Sfc128Random.next_byte(&self) @dynamic => (char)self.next_int128(); // -------------------------------- Sfc64 -------------------------------- -distinct Sfc64Random (Random) = ulong[4]; +typedef Sfc64Random (Random) = ulong[4]; fn void Sfc64Random.set_seed(&self, char[] input) @dynamic { @@ -69,7 +69,7 @@ fn char Sfc64Random.next_byte(&self) @dynamic => (char)self.next_long(); // -------------------------------- Sfc32 -------------------------------- -distinct Sfc32Random (Random) = uint[4]; +typedef Sfc32Random (Random) = uint[4]; fn void Sfc32Random.set_seed(&self, char[] input) @dynamic { @@ -98,7 +98,7 @@ fn char Sfc32Random.next_byte(&self) @dynamic => (char)self.next_int(); // -------------------------------- Sfc16 -------------------------------- -distinct Sfc16Random (Random) = ushort[4]; +typedef Sfc16Random (Random) = ushort[4]; fn void Sfc16Random.set_seed(&self, char[] input) @dynamic { @@ -129,7 +129,7 @@ fn char Sfc16Random.next_byte(&self) @dynamic => (char)self.next_short(); // -------------------------------- Sfc8 -------------------------------- -distinct Sfc8Random (Random) = char[4]; +typedef Sfc8Random (Random) = char[4]; fn void Sfc8Random.set_seed(&self, char[] input) @dynamic { diff --git a/lib/std/math/random/math.simple_random.c3 b/lib/std/math/random/math.simple_random.c3 index 07a43b3fe..3bc781247 100644 --- a/lib/std/math/random/math.simple_random.c3 +++ b/lib/std/math/random/math.simple_random.c3 @@ -1,6 +1,6 @@ module std::math::random; -distinct SimpleRandom (Random) = ulong; +typedef SimpleRandom (Random) = ulong; fn void SimpleRandom.set_seed(&self, char[] seed) @dynamic diff --git a/lib/std/math/uuid.c3 b/lib/std/math/uuid.c3 index b7cc28b0b..b05279d5d 100644 --- a/lib/std/math/uuid.c3 +++ b/lib/std/math/uuid.c3 @@ -2,7 +2,7 @@ module std::math::uuid; import std::math::random @public; import std::io; -distinct Uuid (Printable) = char[16]; +typedef Uuid (Printable) = char[16]; <* Generate a version 4 UUID from the default random. diff --git a/lib/std/net/net.c3 b/lib/std/net/net.c3 index c65f216ac..36ba78100 100644 --- a/lib/std/net/net.c3 +++ b/lib/std/net/net.c3 @@ -1,7 +1,7 @@ module std::net; import std::io; -fault +faultdef INVALID_URL, URL_TOO_LONG, INVALID_SOCKET, diff --git a/lib/std/net/os/common.c3 b/lib/std/net/os/common.c3 index 4ede40da9..525ab014b 100644 --- a/lib/std/net/os/common.c3 +++ b/lib/std/net/os/common.c3 @@ -1,15 +1,15 @@ module std::net::os; const bool SUPPORTS_INET = env::LIBC && (env::WIN32 || env::DARWIN || env::LINUX); -distinct AIFamily = CInt; -distinct AIProtocol = CInt; -distinct AISockType = CInt; -distinct AIFlags = CInt; +typedef AIFamily = CInt; +typedef AIProtocol = CInt; +typedef AISockType = CInt; +typedef AIFlags = CInt; -alias Socklen_t = CUInt @if(!env::WIN32); -alias Socklen_t = usz @if(env::WIN32); +alias Socklen_t @if(!env::WIN32) = CUInt; +alias Socklen_t @if(env::WIN32) = usz; -distinct SockAddrPtr = void*; +typedef SockAddrPtr = void*; struct AddrInfo { diff --git a/lib/std/net/os/posix.c3 b/lib/std/net/os/posix.c3 index 0f9f05971..8cb86daf4 100644 --- a/lib/std/net/os/posix.c3 +++ b/lib/std/net/os/posix.c3 @@ -4,7 +4,7 @@ import std::io, libc; const int F_GETFL = 3; const int F_SETFL = 4; -distinct NativeSocket = inline Fd; +typedef NativeSocket = inline Fd; struct Posix_pollfd { @@ -30,7 +30,7 @@ const CUShort POLLERR = 0x0008; const CUShort POLLHUP = 0x0010; const CUShort POLLNVAL = 0x0020; -fn anyfault convert_error(Errno error) +fn fault convert_error(Errno error) { switch (error) { @@ -51,7 +51,7 @@ fn anyfault convert_error(Errno error) } } -fn anyfault socket_error() +fn fault socket_error() { return convert_error(libc::errno()); } diff --git a/lib/std/net/os/win32.c3 b/lib/std/net/os/win32.c3 index e1a23afd3..90c4459de 100644 --- a/lib/std/net/os/win32.c3 +++ b/lib/std/net/os/win32.c3 @@ -12,7 +12,7 @@ const int FIONREAD = 1074030207; const int FIONBIO = -2147195266; const int FIOASYNC = -2147195267; -distinct NativeSocket = inline Win32_SOCKET; +typedef NativeSocket = inline Win32_SOCKET; extern fn CInt ioctlsocket(NativeSocket, CLong cmd, CULong *argp); extern fn WSAError closesocket(NativeSocket); @@ -61,7 +61,7 @@ const int SO_RCVTIMEO = 0x1006; const int SO_ERROR = 0x1007; const int SO_TYPE = 0x1008; -fn anyfault convert_error(WSAError error) +fn fault convert_error(WSAError error) { switch (error) { @@ -86,7 +86,7 @@ fn anyfault convert_error(WSAError error) } } -fn anyfault socket_error() +fn fault socket_error() { return convert_error(win32_WSAGetLastError()); } diff --git a/lib/std/net/socket.c3 b/lib/std/net/socket.c3 index 8425bfde6..455a1dc2b 100644 --- a/lib/std/net/socket.c3 +++ b/lib/std/net/socket.c3 @@ -25,8 +25,8 @@ macro void @loop_over_ai(AddrInfo* ai; @body(NativeSocket fd, AddrInfo* ai)) const Duration POLL_FOREVER = -1; -distinct PollSubscribes = ushort; -distinct PollEvents = ushort; +typedef PollSubscribes = ushort; +typedef PollEvents = ushort; const PollSubscribes SUBSCRIBE_ANY_READ = os::POLLIN; const PollSubscribes SUBSCRIBE_PRIO_READ = os::POLLPRI; diff --git a/lib/std/net/tcp.c3 b/lib/std/net/tcp.c3 index e2428f322..d800efe04 100644 --- a/lib/std/net/tcp.c3 +++ b/lib/std/net/tcp.c3 @@ -2,8 +2,8 @@ module std::net::tcp @if(os::SUPPORTS_INET); import std::net @public; import std::time, libc; -distinct TcpSocket = inline Socket; -distinct TcpServerSocket = inline Socket; +typedef TcpSocket = inline Socket; +typedef TcpServerSocket = inline Socket; fn TcpSocket? connect(String host, uint port, Duration timeout = 0, SocketOption... options, IpProtocol ip_protocol = UNSPECIFIED) { diff --git a/lib/std/net/udp.c3 b/lib/std/net/udp.c3 index 93586144d..1f7b96eb7 100644 --- a/lib/std/net/udp.c3 +++ b/lib/std/net/udp.c3 @@ -1,7 +1,7 @@ module std::net::udp @if(os::SUPPORTS_INET); import std::net @public; -distinct UdpSocket = inline Socket; +typedef UdpSocket = inline Socket; fn UdpSocket? connect(String host, uint port, SocketOption... options, IpProtocol ip_protocol = UNSPECIFIED) { diff --git a/lib/std/net/url.c3 b/lib/std/net/url.c3 index 6549c36fe..26ee1238b 100644 --- a/lib/std/net/url.c3 +++ b/lib/std/net/url.c3 @@ -2,7 +2,7 @@ module std::net::url; import std::io, std::collections::map, std::collections::list; -fault +faultdef EMPTY, INVALID_SCHEME, INVALID_USER, diff --git a/lib/std/net/url_encoding.c3 b/lib/std/net/url_encoding.c3 index fa506d6a4..0976a40b3 100644 --- a/lib/std/net/url_encoding.c3 +++ b/lib/std/net/url_encoding.c3 @@ -15,7 +15,7 @@ enum UrlEncodingMode : char (String allowed) FRAGMENT = "$&+,/:;=?@!()*", // section 4.1 } -fault INVALID_HEX; +faultdef INVALID_HEX; <* Returns true if char c should be encoded according to RFC 3986. diff --git a/lib/std/os/backtrace.c3 b/lib/std/os/backtrace.c3 index 14f6940b0..c44e771a2 100644 --- a/lib/std/os/backtrace.c3 +++ b/lib/std/os/backtrace.c3 @@ -1,7 +1,8 @@ module std::os::backtrace; import std::collections::list, std::os, std::io; -fault SEGMENT_NOT_FOUND, EXECUTABLE_PATH_NOT_FOUND, IMAGE_NOT_FOUND, NO_BACKTRACE_SYMBOLS, RESOLUTION_FAILED; +faultdef SEGMENT_NOT_FOUND, EXECUTABLE_PATH_NOT_FOUND, IMAGE_NOT_FOUND, NO_BACKTRACE_SYMBOLS, + RESOLUTION_FAILED; const Backtrace BACKTRACE_UNKNOWN = { 0, "", "", "", 0, null, false }; @@ -86,9 +87,9 @@ fn void*[] capture_current(void*[] buffer) alias BacktraceList = List{Backtrace}; -alias symbolize_backtrace = linux::symbolize_backtrace @if(env::LINUX); -alias symbolize_backtrace = win32::symbolize_backtrace @if(env::WIN32); -alias symbolize_backtrace = darwin::symbolize_backtrace @if(env::DARWIN); +alias symbolize_backtrace @if(env::LINUX) = linux::symbolize_backtrace; +alias symbolize_backtrace @if(env::WIN32) = win32::symbolize_backtrace; +alias symbolize_backtrace @if(env::DARWIN) = darwin::symbolize_backtrace; fn BacktraceList? symbolize_backtrace(Allocator allocator, void*[] backtrace) @if(!env::NATIVE_STACKTRACE) { diff --git a/lib/std/os/macos/cf_allocator.c3 b/lib/std/os/macos/cf_allocator.c3 index fd23e9be9..6f6324fc1 100644 --- a/lib/std/os/macos/cf_allocator.c3 +++ b/lib/std/os/macos/cf_allocator.c3 @@ -1,7 +1,7 @@ module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework"); -distinct CFAllocatorRef = void*; -distinct CFAllocatorContextRef = void*; +typedef CFAllocatorRef = void*; +typedef CFAllocatorContextRef = void*; alias CFOptionFlags = usz; macro CFAllocatorRef default_allocator() => macos_CFAllocatorGetDefault(); diff --git a/lib/std/os/macos/cf_array.c3 b/lib/std/os/macos/cf_array.c3 index 749afa5af..aa9c05bab 100644 --- a/lib/std/os/macos/cf_array.c3 +++ b/lib/std/os/macos/cf_array.c3 @@ -1,8 +1,8 @@ module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework"); -distinct CFArrayRef = void*; -distinct CFArrayCallBacksRef = void*; -distinct CFMutableArrayRef = void*; +typedef CFArrayRef = void*; +typedef CFArrayCallBacksRef = void*; +typedef CFMutableArrayRef = void*; extern fn CFArrayRef macos_CFArrayCreate(CFAllocatorRef allocator, void** values, CFIndex num_values, CFArrayCallBacksRef callBacks) @extern("CFArrayCreate") @builtin; extern fn CFArrayRef macos_CFArrayCopy(CFAllocatorRef allocator, CFArrayRef array) @extern("CFArrayCopy") @builtin; extern fn CFIndex macos_CFArrayGetCount(CFArrayRef array) @extern("CFArrayGetCount") @builtin; diff --git a/lib/std/os/macos/core_foundation.c3 b/lib/std/os/macos/core_foundation.c3 index fe7a7cc9b..43c585aba 100644 --- a/lib/std/os/macos/core_foundation.c3 +++ b/lib/std/os/macos/core_foundation.c3 @@ -1,7 +1,8 @@ module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework"); -distinct CFTypeRef = void*; +typedef CFTypeRef = void*; alias CFIndex = isz; + struct CFRange { CFIndex location; diff --git a/lib/std/os/macos/objc.c3 b/lib/std/os/macos/objc.c3 index be26460f2..2bc96bd62 100644 --- a/lib/std/os/macos/objc.c3 +++ b/lib/std/os/macos/objc.c3 @@ -1,13 +1,13 @@ module std::os::macos::objc @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework"); -distinct ObjcClass = void*; -distinct ObjcMethod = void*; -distinct ObjcIvar = void*; -distinct ObjcSelector = void*; +typedef ObjcClass = void*; +typedef ObjcMethod = void*; +typedef ObjcIvar = void*; +typedef ObjcSelector = void*; alias ObjcId = void*; alias SendVoid = fn void*(void*, ObjcSelector); -fault CLASS_NOT_FOUND, UNKNOWN_EVENT; +faultdef CLASS_NOT_FOUND, UNKNOWN_EVENT; macro ZString ObjcClass.name(ObjcClass cls) => class_getName(cls); macro ObjcClass ObjcClass.superclass(ObjcClass cls) => class_getSuperclass(cls); diff --git a/lib/std/os/posix/files.c3 b/lib/std/os/posix/files.c3 index e4608c7e8..dc3076483 100644 --- a/lib/std/os/posix/files.c3 +++ b/lib/std/os/posix/files.c3 @@ -2,7 +2,7 @@ module std::os::posix @if(env::POSIX); import libc; alias Mode_t = uint; -distinct DIRPtr = void*; +typedef DIRPtr = void*; struct Posix_dirent { diff --git a/lib/std/os/posix/threads.c3 b/lib/std/os/posix/threads.c3 index efeda7efe..0ef156293 100644 --- a/lib/std/os/posix/threads.c3 +++ b/lib/std/os/posix/threads.c3 @@ -7,7 +7,7 @@ const PTHREAD_MUTEX_ERRORCHECK = env::LINUX ? 2 : 1; const PTHREAD_MUTEX_RECURSIVE = env::LINUX ? 1 : 2; alias PosixThreadFn = fn void*(void*); -distinct Pthread_t = void*; +typedef Pthread_t = void*; extern fn CInt pthread_create(Pthread_t*, Pthread_attr_t*, PosixThreadFn, void*); extern fn CInt pthread_cancel(Pthread_t*); @@ -89,25 +89,25 @@ extern fn void pthread_cleanup_push(PosixThreadFn routine, void* routine_arg); extern fn int sched_yield(); module std::thread::os @if(env::POSIX && !env::LINUX); -distinct Pthread_attr_t = ulong[8]; -distinct Pthread_cond_t = ulong[6]; -distinct Pthread_condattr_t = ulong[8]; -distinct Pthread_key_t = ulong; -distinct Pthread_mutex_t = ulong[8]; -distinct Pthread_mutexattr_t = ulong[2]; -distinct Pthread_once_t = ulong[2]; -distinct Pthread_rwlock_t = ulong[25]; -distinct Pthread_rwlockattr_t = ulong[3]; -distinct Pthread_sched_param = ulong; +typedef Pthread_attr_t = ulong[8]; +typedef Pthread_cond_t = ulong[6]; +typedef Pthread_condattr_t = ulong[8]; +typedef Pthread_key_t = ulong; +typedef Pthread_mutex_t = ulong[8]; +typedef Pthread_mutexattr_t = ulong[2]; +typedef Pthread_once_t = ulong[2]; +typedef Pthread_rwlock_t = ulong[25]; +typedef Pthread_rwlockattr_t = ulong[3]; +typedef Pthread_sched_param = ulong; module std::thread::os @if(env::LINUX); -distinct Pthread_attr_t = ulong[7]; // 24 on 32bit -distinct Pthread_cond_t = ulong[6]; -distinct Pthread_condattr_t = uint; -distinct Pthread_key_t = uint; -distinct Pthread_mutex_t = ulong[5]; // 24 on 32 bit -distinct Pthread_mutexattr_t = uint; -distinct Pthread_once_t = int; -distinct Pthread_rwlock_t = ulong[7]; // 32 on 3bit -distinct Pthread_rwlockattr_t = uint; -distinct Pthread_sched_param = uint; +typedef Pthread_attr_t = ulong[7]; // 24 on 32bit +typedef Pthread_cond_t = ulong[6]; +typedef Pthread_condattr_t = uint; +typedef Pthread_key_t = uint; +typedef Pthread_mutex_t = ulong[5]; // 24 on 32 bit +typedef Pthread_mutexattr_t = uint; +typedef Pthread_once_t = int; +typedef Pthread_rwlock_t = ulong[7]; // 32 on 3bit +typedef Pthread_rwlockattr_t = uint; +typedef Pthread_sched_param = uint; diff --git a/lib/std/os/subprocess.c3 b/lib/std/os/subprocess.c3 index a8368569e..1613f93ee 100644 --- a/lib/std/os/subprocess.c3 +++ b/lib/std/os/subprocess.c3 @@ -3,7 +3,7 @@ import std::io, libc, std::os; // This code is based on https://github.com/sheredom/subprocess.h -fault +faultdef FAILED_TO_CREATE_PIPE, FAILED_TO_OPEN_STDIN, FAILED_TO_OPEN_STDOUT, diff --git a/lib/std/os/win32/types.c3 b/lib/std/os/win32/types.c3 index 4b6285319..28aa6e352 100644 --- a/lib/std/os/win32/types.c3 +++ b/lib/std/os/win32/types.c3 @@ -189,7 +189,7 @@ union Win32_LARGE_INTEGER ulong quadPart; } -distinct Win32_CRITICAL_SECTION = ulong[5]; +typedef Win32_CRITICAL_SECTION = ulong[5]; struct Win32_SECURITY_ATTRIBUTES { diff --git a/lib/std/os/win32/wsa.c3 b/lib/std/os/win32/wsa.c3 index f5a55ec93..843074bb4 100644 --- a/lib/std/os/win32/wsa.c3 +++ b/lib/std/os/win32/wsa.c3 @@ -2,7 +2,7 @@ module std::os::win32 @if(env::WIN32); // See https://github.com/wine-mirror/wine/blob/master/include/winsock2.h -distinct WSAError = int; +typedef WSAError = int; struct Win32_pollfd { diff --git a/lib/std/sort/countingsort.c3 b/lib/std/sort/countingsort.c3 index 0eed19147..e2d23090c 100644 --- a/lib/std/sort/countingsort.c3 +++ b/lib/std/sort/countingsort.c3 @@ -26,21 +26,21 @@ macro quicksort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPT module std::sort::cs{Type, KeyFn}; -alias Counts = usz[256] @private; -alias Ranges = usz[257] @private; -alias Indexs = char[256] @private; +alias Counts @private = usz[256]; +alias Ranges @private = usz[257]; +alias Indexs @private = char[256]; alias ElementType = $typeof((Type){}[0]); const bool NO_KEY_FN @private = types::is_same(KeyFn, EmptySlot); const bool KEY_BY_VALUE @private = NO_KEY_FN ||| $assignable((Type){}[0], $typefrom(KeyFn.paramsof[0].type)); const bool LIST_HAS_REF @private = $defined(&(Type){}[0]); -alias KeyFnReturnType = $typefrom(KeyFn.returns) @if(!NO_KEY_FN); -alias KeyFnReturnType = ElementType @if(NO_KEY_FN); -alias CmpCallback = fn int(ElementType, ElementType) @if(KEY_BY_VALUE && NO_KEY_FN); -alias CmpCallback = fn int(ElementType*, ElementType*) @if(!KEY_BY_VALUE && NO_KEY_FN); -alias CmpCallback = fn int(ElementType, ElementType, KeyFn) @if(KEY_BY_VALUE && !NO_KEY_FN); -alias CmpCallback = fn int(ElementType*, ElementType*, KeyFn) @if(!KEY_BY_VALUE && !NO_KEY_FN); +alias KeyFnReturnType @if(!NO_KEY_FN) = $typefrom(KeyFn.returns) ; +alias KeyFnReturnType @if(NO_KEY_FN) = ElementType; +alias CmpCallback @if(KEY_BY_VALUE && NO_KEY_FN) = fn int(ElementType, ElementType) ; +alias CmpCallback @if(!KEY_BY_VALUE && NO_KEY_FN) = fn int(ElementType*, ElementType*); +alias CmpCallback @if(KEY_BY_VALUE && !NO_KEY_FN) = fn int(ElementType, ElementType, KeyFn); +alias CmpCallback @if(!KEY_BY_VALUE && !NO_KEY_FN) = fn int(ElementType*, ElementType*, KeyFn); fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx) { diff --git a/lib/std/sort/quicksort.c3 b/lib/std/sort/quicksort.c3 index 7ae35e113..dc558a1c6 100644 --- a/lib/std/sort/quicksort.c3 +++ b/lib/std/sort/quicksort.c3 @@ -43,7 +43,7 @@ struct StackElementItem @private isz high; } -alias Stack = StackElementItem[64] @private; +alias Stack @private = StackElementItem[64]; // Based on https://alienryderflex.com/quicksort by Darel Rex Finley, Public Domain. diff --git a/lib/std/text/i18n.c3 b/lib/std/text/i18n.c3 index f2f9ec42e..6acc33318 100644 --- a/lib/std/text/i18n.c3 +++ b/lib/std/text/i18n.c3 @@ -1,7 +1,7 @@ /*module std::text::i18n; import std::collections::map; import std::hash::fnv32a; -distinct Language = char[]; +typedef Language = char[]; const Language EN = "en"; diff --git a/lib/std/threads/buffered_channel.c3 b/lib/std/threads/buffered_channel.c3 index 57ba3cc21..65602ba51 100644 --- a/lib/std/threads/buffered_channel.c3 +++ b/lib/std/threads/buffered_channel.c3 @@ -1,6 +1,6 @@ module std::thread::channel{Type}; -distinct BufferedChannel = void*; +typedef BufferedChannel = void*; struct BufferedChannelImpl @private { @@ -48,7 +48,7 @@ fn void? BufferedChannel.destroy(&self) { BufferedChannelImpl* channel = (BufferedChannelImpl*)(*self); - anyfault err = @catch(channel.mu.destroy()); + fault err = @catch(channel.mu.destroy()); err = @catch(channel.send_cond.destroy()) ?: err; err = @catch(channel.read_cond.destroy()) ?: err; allocator::free(channel.allocator, channel); @@ -147,7 +147,7 @@ fn void? BufferedChannel.close(self) { BufferedChannelImpl* channel = (BufferedChannelImpl*)self; - anyfault err = @catch(channel.mu.lock()); + fault err = @catch(channel.mu.lock()); channel.closed = true; diff --git a/lib/std/threads/event/event_thread.c3 b/lib/std/threads/event/event_thread.c3 index 7031b09ae..c14cce0db 100644 --- a/lib/std/threads/event/event_thread.c3 +++ b/lib/std/threads/event/event_thread.c3 @@ -21,9 +21,9 @@ struct EventThreadTask Event*[] events; } -distinct EventQueue = void; -distinct EventHandler = void; -distinct EventMultiQueue = void; +typedef EventQueue = void; +typedef EventHandler = void; +typedef EventMultiQueue = void; fn EventThreadTask EventQueue.wait_for_task(&self) => EventThreadTask {}; diff --git a/lib/std/threads/fixed_pool.c3 b/lib/std/threads/fixed_pool.c3 index c275d3a83..d75796900 100644 --- a/lib/std/threads/fixed_pool.c3 +++ b/lib/std/threads/fixed_pool.c3 @@ -1,5 +1,5 @@ module std::thread; -fault THREAD_QUEUE_FULL; +faultdef THREAD_QUEUE_FULL; module std::thread::threadpool @if (env::POSIX || env::WIN32); import std::thread; diff --git a/lib/std/threads/os/thread_none.c3 b/lib/std/threads/os/thread_none.c3 index 6b916ad74..5ff058a7d 100644 --- a/lib/std/threads/os/thread_none.c3 +++ b/lib/std/threads/os/thread_none.c3 @@ -1,6 +1,6 @@ module std::thread::os @if (!env::POSIX && !env::WIN32); -distinct NativeMutex = int; -distinct NativeConditionVariable = int; -distinct NativeOnceFlag = int; -distinct NativeThread = int; \ No newline at end of file +typedef NativeMutex = int; +typedef NativeConditionVariable = int; +typedef NativeOnceFlag = int; +typedef NativeThread = int; \ No newline at end of file diff --git a/lib/std/threads/os/thread_win32.c3 b/lib/std/threads/os/thread_win32.c3 index 34f8565c5..a2f9fbd52 100644 --- a/lib/std/threads/os/thread_win32.c3 +++ b/lib/std/threads/os/thread_win32.c3 @@ -1,7 +1,7 @@ module std::thread::os @if(env::WIN32); import std::os::win32, std::time; -distinct NativeThread = inline Win32_HANDLE; +typedef NativeThread = inline Win32_HANDLE; struct NativeMutex { diff --git a/lib/std/threads/thread.c3 b/lib/std/threads/thread.c3 index a3ee2804c..a030da9f6 100644 --- a/lib/std/threads/thread.c3 +++ b/lib/std/threads/thread.c3 @@ -2,24 +2,24 @@ module std::thread; import std::thread::os; import std::time; -distinct MutexType = int; +typedef MutexType = int; const MutexType MUTEX_PLAIN = 0; const MutexType MUTEX_TIMED = 1; const MutexType MUTEX_RECURSIVE = 2; -distinct Mutex = NativeMutex; -distinct TimedMutex = inline Mutex; -distinct RecursiveMutex = inline Mutex; -distinct TimedRecursiveMutex = inline Mutex; -distinct ConditionVariable = NativeConditionVariable; -distinct Thread = inline NativeThread; -distinct OnceFlag = NativeOnceFlag; +typedef Mutex = NativeMutex; +typedef TimedMutex = inline Mutex; +typedef RecursiveMutex = inline Mutex; +typedef TimedRecursiveMutex = inline Mutex; +typedef ConditionVariable = NativeConditionVariable; +typedef Thread = inline NativeThread; +typedef OnceFlag = NativeOnceFlag; alias OnceFn = fn void(); alias ThreadFn = fn int(void* arg); -fault +faultdef INIT_FAILED, DESTROY_FAILED, LOCK_FAILED, diff --git a/lib/std/threads/unbuffered_channel.c3 b/lib/std/threads/unbuffered_channel.c3 index 90ce3f770..f7b4ffd7f 100644 --- a/lib/std/threads/unbuffered_channel.c3 +++ b/lib/std/threads/unbuffered_channel.c3 @@ -1,6 +1,6 @@ module std::thread::channel {Type}; -distinct UnbufferedChannel = void*; +typedef UnbufferedChannel = void*; struct UnbufferedChannelImpl @private { @@ -44,7 +44,7 @@ fn void? UnbufferedChannel.destroy(&self) { UnbufferedChannelImpl* channel = (UnbufferedChannelImpl*)(*self); - anyfault err = @catch(channel.mu.destroy()); + fault err = @catch(channel.mu.destroy()); err = @catch(channel.send_mu.destroy()) ?: err; err = @catch(channel.send_cond.destroy()) ?: err; err = @catch(channel.read_mu.destroy()) ?: err; @@ -126,7 +126,7 @@ fn void? UnbufferedChannel.close(self) { UnbufferedChannelImpl* channel = (UnbufferedChannelImpl*)self; - anyfault err = @catch(channel.mu.lock()); + fault err = @catch(channel.mu.lock()); channel.closed = true; diff --git a/lib/std/time/time.c3 b/lib/std/time/time.c3 index b7c4de95b..b1aa50416 100644 --- a/lib/std/time/time.c3 +++ b/lib/std/time/time.c3 @@ -1,10 +1,10 @@ module std::time; import std::io, std::time::os; -distinct Time = long; -distinct Duration = long; -distinct Clock = ulong; -distinct NanoDuration (Printable) = long; +typedef Time = long; +typedef Duration = long; +typedef Clock = ulong; +typedef NanoDuration (Printable) = long; const Time FAR_FUTURE = long.max; const Time FAR_PAST = long.min; diff --git a/releasenotes.md b/releasenotes.md index 507a5cce4..0d146d14f 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -22,16 +22,20 @@ - `$for` "()" replaced by trailing ":" `$for (var $x = 0; $x < FOO; $x++)` -> `$for var $x = 0; $x < FOO; $x++:` - `$switch` "()" replaced by trailing ":" `$switch ($Type)` -> `$switch $Type:` - Empty `$switch` requires trailing ":" `$switch` -> `$switch:` -- Rename `@return` to `@return?` and change syntax to require ":" after faults. +- Rename `@return!` to `@return?` and change syntax to require ":" after faults. - Remove `if (catch foo) { case ... }` syntax. - Remove `[?]` syntax. - Change `int!` to `int?` syntax. -- New `fault` declarations. +- New `fault` declaration using `faultdef`. - Enum associated values can reference the calling enum. - Improve error message on `foo ?? io::EOF` with missing '?' #2036 - Make `@public` import recursive. #2018 - Fault nameof prefixes the first last module path, for instance `std::io::EOF` is rendered as `io::EOF`. - Rename `def` to `alias`. +- Change `distinct` -> `typedef`. +- Order of attribute declaration is changed for `alias`. +- Added `LANGUAGE_DEV_VERSION` env constant. +- Rename `anyfault` -> `fault`. ### Fixes - Fix address sanitizer to work on MachO targets (e.g. MacOS). diff --git a/resources/examples/base64.c3 b/resources/examples/base64.c3 index d91e6b0aa..6f019e8a9 100644 --- a/resources/examples/base64.c3 +++ b/resources/examples/base64.c3 @@ -1,6 +1,6 @@ module base64; -fault INVALID_CHARACTER; +faultdef INVALID_CHARACTER; // Based on the C2 version. diff --git a/resources/examples/brainfk.c3 b/resources/examples/brainfk.c3 index da5901dd1..0c2f99754 100644 --- a/resources/examples/brainfk.c3 +++ b/resources/examples/brainfk.c3 @@ -4,7 +4,7 @@ import std::io; const BF_MEM = 30000; char[BF_MEM] memory; -fault INTEPRET_FAILED; +faultdef INTEPRET_FAILED; fn void? print_error_type_at(usz pos, String err) { diff --git a/resources/examples/contextfree/boolerr.c3 b/resources/examples/contextfree/boolerr.c3 index 9fbef88e6..bae2ca25d 100644 --- a/resources/examples/contextfree/boolerr.c3 +++ b/resources/examples/contextfree/boolerr.c3 @@ -4,8 +4,7 @@ import libc; import std::io; import std::collections::maybe; -fault TITLE_MISSING; -fault BAD_READ; +faultdef TITLE_MISSING, BAD_READ; struct Doc { diff --git a/resources/examples/contextfree/cleanup.c3 b/resources/examples/contextfree/cleanup.c3 index bc0f6b804..2942473c5 100644 --- a/resources/examples/contextfree/cleanup.c3 +++ b/resources/examples/contextfree/cleanup.c3 @@ -6,7 +6,7 @@ struct Resource String name; } -fault WELCOME_TO_YOUR_DOOM; +faultdef WELCOME_TO_YOUR_DOOM; fn Resource? resource_init(String name) { diff --git a/resources/examples/contextfree/guess_number.c3 b/resources/examples/contextfree/guess_number.c3 index ffbcd9d24..49f2db291 100644 --- a/resources/examples/contextfree/guess_number.c3 +++ b/resources/examples/contextfree/guess_number.c3 @@ -11,7 +11,7 @@ struct Game int high; } -fault NOT_AN_INT, FAILED_TO_READ; +faultdef NOT_AN_INT, FAILED_TO_READ; int err_count = 0; diff --git a/resources/examples/map.c3 b/resources/examples/map.c3 index cc3ac485f..b8dfa0197 100644 --- a/resources/examples/map.c3 +++ b/resources/examples/map.c3 @@ -2,7 +2,7 @@ module std::container::map{Key, Type}; import std::core::builtin; import std::io; -fault KEY_NOT_FOUND; +faultdef KEY_NOT_FOUND; struct Entry { diff --git a/resources/examples/opengl/src/glfw/glfw.c3 b/resources/examples/opengl/src/glfw/glfw.c3 index 0588a71fd..226b510b6 100644 --- a/resources/examples/opengl/src/glfw/glfw.c3 +++ b/resources/examples/opengl/src/glfw/glfw.c3 @@ -2,8 +2,8 @@ module glfw; import std::io; -distinct Window @public = inline _Window*; -distinct Monitor @public = inline _Monitor*; +typedef Window @public = inline _Window*; +typedef Monitor @public = inline _Monitor*; fn void Window.create(&self, int width, int height, String title, Monitor monitor = {}, Window share = {} ) @public @@ -37,8 +37,8 @@ extern fn void terminate() @extern("glfwTerminate") @public; extern fn void pollEvents() @extern("glfwPollEvents") @public; -distinct _Window @private = void; -distinct _Monitor @private = void; +typedef _Window @private = void; +typedef _Monitor @private = void; extern fn _Window* _glfwCreateWindow(int width, int height, char* title, _Monitor* monitor, _Window* share) @extern("glfwCreateWindow") @private; diff --git a/resources/examples/plus_minus.c3 b/resources/examples/plus_minus.c3 index ff5269a55..9a90818ac 100644 --- a/resources/examples/plus_minus.c3 +++ b/resources/examples/plus_minus.c3 @@ -2,7 +2,7 @@ module test; import std::io; import libc; -fault NO_MORE_TOKENS; +faultdef NO_MORE_TOKENS; // While we could have written this with libc diff --git a/resources/examples/retry.c3 b/resources/examples/retry.c3 index 0665cac88..9b8693067 100644 --- a/resources/examples/retry.c3 +++ b/resources/examples/retry.c3 @@ -1,7 +1,7 @@ module test; import libc; -fault NOPE; +faultde NOPE; fn int? eventually_succeed() { @@ -13,7 +13,7 @@ fn int? eventually_succeed() macro @retry(#function, int retries = 3) { var $Type = $typeof(#function); - anyfault e; + fault e; do { $Type? result = #function; diff --git a/src/compiler/c_codegen.c b/src/compiler/c_codegen.c index faddcd8fb..14acfb5a0 100644 --- a/src/compiler/c_codegen.c +++ b/src/compiler/c_codegen.c @@ -412,7 +412,6 @@ static void c_emit_expr(GenContext *c, CValue *value, Expr *expr) case EXPR_MAKE_SLICE: case EXPR_INT_TO_BOOL: case EXPR_VECTOR_FROM_ARRAY: - case EXPR_ANYFAULT_TO_FAULT: break; case NON_RUNTIME_EXPR: case UNRESOLVED_EXPRS: @@ -651,7 +650,7 @@ static void c_emit_return(GenContext *c, Ast *stmt) if (ast->return_stmt.cleanup_fail) { llvm_value_rvalue(c, &be_value); - LLVMValueRef error_out = llvm_emit_alloca_aligned(c, type_anyfault, "reterr"); + LLVMValueRef error_out = llvm_emit_alloca_aligned(c, type_fault, "reterr"); llvm_store_to_ptr(c, error_out, &be_value); PUSH_DEFER_ERROR(error_out); llvm_emit_statement_chain(c, ast->return_stmt.cleanup_fail); @@ -678,7 +677,7 @@ static void c_emit_return(GenContext *c, Ast *stmt) if (c->cur_func.prototype && type_is_optional(c->cur_func.prototype->rtype)) { error_return_block = llvm_basic_block_new(c, "err_retblock"); - error_out = llvm_emit_alloca_aligned(c, type_anyfault, "reterr"); + error_out = llvm_emit_alloca_aligned(c, type_fault, "reterr"); c->catch = (OptionalCatch) { error_out, error_return_block }; } @@ -730,7 +729,7 @@ static void c_emit_return(GenContext *c, Ast *stmt) llvm_emit_statement_chain(c, ast->return_stmt.cleanup_fail); POP_DEFER_ERROR(); BEValue value; - llvm_value_set_address_abi_aligned(&value, error_out, type_anyfault); + llvm_value_set_address_abi_aligned(&value, error_out, type_fault); llvm_emit_return_abi(c, NULL, &value); }*/ } diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 3326a6b31..a299d87f5 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -1398,6 +1398,7 @@ void compile() setup_bool_define("BENCHMARKING", compiler.build.benchmarking); setup_int_define("JMP_BUF_SIZE", jump_buffer_size(), type_int); setup_bool_define("TESTING", compiler.build.testing); + setup_int_define("LANGUAGE_DEV_VERSION", 7, type_int); setup_bool_define("ADDRESS_SANITIZER", compiler.build.feature.sanitize_address); setup_bool_define("MEMORY_SANITIZER", compiler.build.feature.sanitize_memory); setup_bool_define("THREAD_SANITIZER", compiler.build.feature.sanitize_thread); diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 1139e4c6b..6a79bec89 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1869,7 +1869,7 @@ extern Type *type_ichar, *type_short, *type_int, *type_long, *type_isz; extern Type *type_char, *type_ushort, *type_uint, *type_ulong, *type_usz; extern Type *type_iptr, *type_uptr; extern Type *type_u128, *type_i128; -extern Type *type_typeid, *type_anyfault, *type_any, *type_typeinfo, *type_member; +extern Type *type_typeid, *type_fault, *type_any, *type_typeinfo, *type_member; extern Type *type_untypedlist; extern Type *type_wildcard; extern Type *type_cint; @@ -3385,7 +3385,6 @@ static inline void expr_set_span(Expr *expr, SourceSpan loc) case EXPR_VECTOR_FROM_ARRAY: case EXPR_ADDR_CONVERSION: case EXPR_RECAST: - case EXPR_ANYFAULT_TO_FAULT: expr_set_span(expr->inner_expr, loc); return; case EXPR_EXPRESSION_LIST: @@ -3678,7 +3677,7 @@ INLINE void expr_rewrite_const_bool(Expr *expr, Type *type, bool b) INLINE void expr_rewrite_const_fault(Expr *expr, Decl *fault) { expr->expr_kind = EXPR_CONST; - expr->type = type_anyfault; + expr->type = type_fault; expr->const_expr = (ExprConst) { .fault = fault, .const_kind = CONST_FAULT }; expr->resolve_status = RESOLVE_DONE; } diff --git a/src/compiler/copying.c b/src/compiler/copying.c index 6ed8c3033..52a831459 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -486,7 +486,6 @@ Expr *copy_expr(CopyStruct *c, Expr *source_expr) case EXPR_FLOAT_TO_INT: case EXPR_SLICE_LEN: case EXPR_DISCARD: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_FROM_ARRAY: case EXPR_RVALUE: case EXPR_RECAST: diff --git a/src/compiler/enums.h b/src/compiler/enums.h index fd08c6a6f..d3c65ca74 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -243,7 +243,7 @@ typedef enum FLAG_ATTR ATTR_UNION = 1 << 5, ATTR_CONST = 1 << 6, ATTR_FAULT = 1 << 7, - ATTR_DEF = 1 << 8, + ATTR_ALIAS = 1 << 8, ATTR_MEMBER = 1 << 9, ATTR_BITSTRUCT_MEMBER = 1 << 10, ATTR_INTERFACE = 1 << 11, @@ -254,8 +254,13 @@ typedef enum FLAG_ATTR ATTR_ENUM_VALUE = 1 << 16, ATTR_INTERFACE_METHOD = 1 << 17, ATTR_PARAM = 1 << 18, + ATTR_FNTYPE = 1 << 19, } AttributeDomain; +#define EXPORTED_USER_DEFINED_TYPES (ATTR_ENUM | ATTR_UNION | ATTR_STRUCT | ATTR_FAULT) +#define CALLABLE_TYPE (ATTR_FUNC | ATTR_INTERFACE_METHOD | ATTR_MACRO | ATTR_FNTYPE) +#define USER_DEFINED_TYPES EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_DISTINCT + typedef enum { ATTRIBUTE_ALIGN, @@ -756,7 +761,6 @@ typedef enum EXPR_INT_TO_FLOAT, EXPR_INT_TO_PTR, EXPR_PTR_TO_INT, - EXPR_ANYFAULT_TO_FAULT, EXPR_LAMBDA, EXPR_LAST_FAULT, EXPR_MACRO_BLOCK, @@ -1126,29 +1130,28 @@ typedef enum TOKEN_USZ, TOKEN_FLOAT128, TOKEN_ANY, - TOKEN_ANYFAULT, + TOKEN_FAULT, TOKEN_TYPEID, // Keywords TOKEN_ALIAS, TOKEN_ASSERT, TOKEN_ASM, + TOKEN_ATTRDEF, TOKEN_BITSTRUCT, TOKEN_BREAK, TOKEN_CASE, TOKEN_CATCH, TOKEN_CONST, TOKEN_CONTINUE, - TOKEN_DEF, TOKEN_DEFAULT, TOKEN_DEFER, - TOKEN_DISTINCT, TOKEN_DO, TOKEN_ELSE, TOKEN_ENUM, TOKEN_EXTERN, TOKEN_FALSE, - TOKEN_FAULT, + TOKEN_FAULTDEF, TOKEN_FOR, TOKEN_FOREACH, TOKEN_FOREACH_R, @@ -1168,6 +1171,7 @@ typedef enum TOKEN_SWITCH, TOKEN_TRUE, TOKEN_TRY, + TOKEN_TYPEDEF, TOKEN_UNION, TOKEN_VAR, TOKEN_WHILE, @@ -1618,7 +1622,7 @@ static_assert(EXPR_LAST < 128, "Too many expression types"); case TOKEN_IPTR: case TOKEN_LONG: \ case TOKEN_SHORT: case TOKEN_UINT128: case TOKEN_UINT: case TOKEN_ULONG: \ case TOKEN_UPTR: case TOKEN_USHORT: case TOKEN_USZ: \ - case TOKEN_ISZ: case TOKEN_FLOAT128: case TOKEN_TYPEID: case TOKEN_ANYFAULT: case TOKEN_ANY + case TOKEN_ISZ: case TOKEN_FLOAT128: case TOKEN_TYPEID: case TOKEN_FAULT: case TOKEN_ANY #define TYPE_TOKENS NON_VOID_TYPE_TOKENS: case TOKEN_VOID #define CT_TYPE_TOKENS TOKEN_CT_TYPE_IDENT: case TOKEN_CT_TYPEOF: case TOKEN_CT_EVALTYPE: \ case TOKEN_CT_VATYPE: case TOKEN_CT_TYPEFROM diff --git a/src/compiler/expr.c b/src/compiler/expr.c index 8bd631571..af0553736 100644 --- a/src/compiler/expr.c +++ b/src/compiler/expr.c @@ -57,7 +57,6 @@ const char *expr_kind_to_string(ExprKind kind) case EXPR_INT_TO_FLOAT: return "int_to_float"; case EXPR_INT_TO_PTR: return "int_to_ptr"; case EXPR_PTR_TO_INT: return "ptr_to_int"; - case EXPR_ANYFAULT_TO_FAULT: return "anyfault_to_fault"; case EXPR_LAMBDA: return "lambda"; case EXPR_LAST_FAULT: return "last_fault"; case EXPR_MACRO_BLOCK: return "macro_block"; @@ -228,7 +227,6 @@ bool expr_may_addr(Expr *expr) case EXPR_BENCHMARK_HOOK: case EXPR_TEST_HOOK: case EXPR_VECTOR_FROM_ARRAY: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_TO_ARRAY: case EXPR_SLICE_TO_VEC_ARRAY: case EXPR_SCALAR_TO_VECTOR: @@ -339,7 +337,6 @@ bool expr_is_runtime_const(Expr *expr) case UNRESOLVED_EXPRS: UNREACHABLE case EXPR_VECTOR_FROM_ARRAY: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_RVALUE: case EXPR_RECAST: case EXPR_ADDR_CONVERSION: @@ -776,7 +773,6 @@ bool expr_is_pure(Expr *expr) case EXPR_SLICE_LEN: case EXPR_DISCARD: case EXPR_VECTOR_FROM_ARRAY: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_RVALUE: case EXPR_RECAST: case EXPR_ADDR_CONVERSION: diff --git a/src/compiler/headers.c b/src/compiler/headers.c index 257577a4e..88e33ee16 100644 --- a/src/compiler/headers.c +++ b/src/compiler/headers.c @@ -241,7 +241,7 @@ static void header_gen_function_ptr(HeaderContext *c, Type *type) { extra_ret = rtype->optional; header_gen_maybe_generate_type(c, extra_ret, false); - rtype = type_anyfault; + rtype = type_fault; } header_gen_maybe_generate_type(c, rtype, false); FOREACH(Decl *, param, sig->params) @@ -295,7 +295,7 @@ static void header_gen_function(HeaderContext *c, Decl *decl, bool print_fn, boo { extra_ret = rtype->optional; if (!print_fn) header_gen_maybe_generate_type(c, extra_ret, false); - rtype = type_anyfault; + rtype = type_fault; } if (!print_fn) header_gen_maybe_generate_type(c, rtype, false); if (print_fn) diff --git a/src/compiler/json_output.c b/src/compiler/json_output.c index 7783ec828..2767e7236 100644 --- a/src/compiler/json_output.c +++ b/src/compiler/json_output.c @@ -88,7 +88,7 @@ static inline const char *decl_type_to_string(Decl *type) case DECL_CT_EXEC: return "$exec"; case DECL_CT_INCLUDE: return "$include"; case DECL_DEFINE: return "def"; - case DECL_DISTINCT: return "distinct"; + case DECL_DISTINCT: return "typedef"; case DECL_ENUM: return "enum"; case DECL_ENUM_CONSTANT: return "enum_const"; case DECL_FAULT: return "fault"; diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 97516de41..0eb945899 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -97,7 +97,7 @@ LLVMBuilderRef llvm_create_builder(GenContext *c) LLVMValueRef llvm_emit_is_no_opt(GenContext *c, LLVMValueRef error_value) { - LLVMValueRef compare = LLVMBuildICmp(c->builder, LLVMIntEQ, error_value, llvm_get_zero(c, type_anyfault), "not_err"); + LLVMValueRef compare = LLVMBuildICmp(c->builder, LLVMIntEQ, error_value, llvm_get_zero(c, type_fault), "not_err"); return llvm_emit_expect_raw(c, compare); } @@ -618,7 +618,7 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl) LLVMValueRef optional_ref = decl->var.optional_ref; if (optional_ref) { - llvm_set_alignment(optional_ref, type_alloca_alignment(type_anyfault)); + llvm_set_alignment(optional_ref, type_alloca_alignment(type_fault)); LLVMSetUnnamedAddress(optional_ref, LLVMGlobalUnnamedAddr); } LLVMValueRef optional_value = NULL; @@ -635,7 +635,7 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl) LLVMSetInitializer(decl->backend_ref, init_value); if (optional_ref) { - LLVMSetInitializer(optional_ref, optional_value ? optional_value : llvm_get_zero(c, type_anyfault)); + LLVMSetInitializer(optional_ref, optional_value ? optional_value : llvm_get_zero(c, type_fault)); } } @@ -1115,10 +1115,10 @@ void llvm_add_global_decl(GenContext *c, Decl *decl) } if (IS_OPTIONAL(decl)) { - LLVMTypeRef anyfault = llvm_get_type(c, type_anyfault); + LLVMTypeRef fault = llvm_get_type(c, type_fault); scratch_buffer_set_extern_decl_name(decl, true); scratch_buffer_append(".f"); - decl->var.optional_ref = llvm_add_global_raw(c, scratch_buffer_to_string(), anyfault, 0); + decl->var.optional_ref = llvm_add_global_raw(c, scratch_buffer_to_string(), fault, 0); } llvm_set_decl_linkage(c, decl); llvm_set_global_tls(decl); @@ -1390,7 +1390,7 @@ INLINE GenContext *llvm_gen_tests(Module** modules, unsigned module_count, LLVMC LLVMValueRef *names = NULL; LLVMValueRef *decls = NULL; - LLVMTypeRef opt_test = LLVMFunctionType(llvm_get_type(c, type_anyfault), NULL, 0, false); + LLVMTypeRef opt_test = LLVMFunctionType(llvm_get_type(c, type_fault), NULL, 0, false); for (unsigned i = 0; i < module_count; i++) { Module *module = modules[i]; @@ -1458,7 +1458,7 @@ INLINE GenContext *llvm_gen_benchmarks(Module** modules, unsigned module_count, LLVMValueRef *names = NULL; LLVMValueRef *decls = NULL; - LLVMTypeRef opt_benchmark = LLVMFunctionType(llvm_get_type(c, type_anyfault), NULL, 0, false); + LLVMTypeRef opt_benchmark = LLVMFunctionType(llvm_get_type(c, type_fault), NULL, 0, false); for (unsigned i = 0; i < module_count; i++) { Module *module = modules[i]; diff --git a/src/compiler/llvm_codegen_debug_info.c b/src/compiler/llvm_codegen_debug_info.c index 5f9cc2933..1c19408a4 100644 --- a/src/compiler/llvm_codegen_debug_info.c +++ b/src/compiler/llvm_codegen_debug_info.c @@ -551,7 +551,7 @@ static LLVMMetadataRef llvm_debug_func_type(GenContext *c, Type *type) } else { - vec_add(buffer, llvm_get_debug_type(c, type_anyfault)); + vec_add(buffer, llvm_get_debug_type(c, type_fault)); vec_add(buffer, llvm_get_debug_type(c, type_get_ptr(type_no_optional(return_type)))); } FOREACH(Type *, param_type, prototype->param_types) diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 1197d80d2..a37fae956 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -207,7 +207,7 @@ BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *expr, LLVMValue if (optional) { - llvm_store_to_ptr_raw(c, optional, llvm_get_zero(c, type_anyfault), type_anyfault); + llvm_store_to_ptr_raw(c, optional, llvm_get_zero(c, type_fault), type_fault); } POP_CATCH(); @@ -217,8 +217,8 @@ BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *expr, LLVMValue if (rejump_block) { llvm_emit_block(c, rejump_block); - LLVMValueRef error = llvm_load_abi_alignment(c, type_anyfault, optional, "reload_err"); - llvm_store_to_ptr_raw(c, c->catch.fault, error, type_anyfault); + LLVMValueRef error = llvm_load_abi_alignment(c, type_fault, optional, "reload_err"); + llvm_store_to_ptr_raw(c, c->catch.fault, error, type_fault); llvm_emit_br(c, c->catch.block); } llvm_emit_block(c, assign_block); @@ -4250,7 +4250,7 @@ static inline void llvm_emit_rethrow_expr(GenContext *c, BEValue *be_value, Expr LLVMBasicBlockRef no_err_block = llvm_basic_block_new(c, "noerr_block"); // Set the catch/error var - LLVMValueRef error_var = llvm_emit_alloca_aligned(c, type_anyfault, "error_var"); + LLVMValueRef error_var = llvm_emit_alloca_aligned(c, type_fault, "error_var"); PUSH_CATCH_VAR_BLOCK(error_var, guard_block); @@ -4275,7 +4275,7 @@ static inline void llvm_emit_rethrow_expr(GenContext *c, BEValue *be_value, Expr llvm_emit_statement_chain(c, expr->rethrow_expr.cleanup); POP_DEFER_ERROR(); BEValue value; - llvm_value_set_address_abi_aligned(&value, error_var, type_anyfault); + llvm_value_set_address_abi_aligned(&value, error_var, type_fault); if (expr->rethrow_expr.in_block) { BlockExit *exit = *expr->rethrow_expr.in_block; @@ -4305,7 +4305,7 @@ static inline void llvm_emit_force_unwrap_expr(GenContext *c, BEValue *be_value, LLVMBasicBlockRef no_err_block = llvm_basic_block_new(c, "noerr_block"); // Set the catch/error var - LLVMValueRef error_var = llvm_emit_alloca_aligned(c, type_anyfault, "error_var"); + LLVMValueRef error_var = llvm_emit_alloca_aligned(c, type_fault, "error_var"); PUSH_CATCH_VAR_BLOCK(error_var, panic_block); @@ -4330,8 +4330,8 @@ static inline void llvm_emit_force_unwrap_expr(GenContext *c, BEValue *be_value, SourceSpan loc = expr->span; BEValue *varargs = NULL; BEValue fault_arg; - llvm_value_set_address(&fault_arg, error_var, type_anyfault, type_abi_alignment(type_anyfault)); - llvm_emit_any_from_value(c, &fault_arg, type_anyfault); + llvm_value_set_address(&fault_arg, error_var, type_fault, type_abi_alignment(type_fault)); + llvm_emit_any_from_value(c, &fault_arg, type_fault); vec_add(varargs, fault_arg); llvm_emit_panic(c, "Force unwrap failed!", loc, "Unexpected fault '%s' was unwrapped!", varargs); } @@ -4747,8 +4747,8 @@ static void llvm_emit_const_expr(GenContext *c, BEValue *be_value, Expr *expr) { Decl *decl = expr->const_expr.fault; ASSERT(decl); - LLVMValueRef value = LLVMBuildPtrToInt(c->builder, llvm_get_ref(c, decl), llvm_get_type(c, type_anyfault), ""); - llvm_value_set(be_value, value, type_anyfault); + LLVMValueRef value = LLVMBuildPtrToInt(c->builder, llvm_get_ref(c, decl), llvm_get_type(c, type_fault), ""); + llvm_value_set(be_value, value, type_fault); return; } case CONST_ENUM: @@ -5354,7 +5354,7 @@ void llvm_emit_raw_call(GenContext *c, BEValue *result_value, FunctionPrototype BEValue error_holder = *result_value; if (error_var) { - llvm_value_set_address_abi_aligned(&error_holder, c->catch.fault, type_anyfault); + llvm_value_set_address_abi_aligned(&error_holder, c->catch.fault, type_fault); } LLVMValueRef stored_error; @@ -6289,8 +6289,8 @@ static inline void llvm_emit_try_unwrap(GenContext *c, BEValue *value, Expr *exp if (!expr->try_expr.optional) { LLVMValueRef fail_ref = decl_optional_ref(expr->try_expr.decl); - LLVMValueRef errv = llvm_load(c, llvm_get_type(c, type_anyfault), fail_ref, type_abi_alignment(type_anyfault), "load.err"); - LLVMValueRef result = LLVMBuildICmp(c->builder, LLVMIntEQ, errv, llvm_get_zero(c, type_anyfault), "result"); + LLVMValueRef errv = llvm_load(c, llvm_get_type(c, type_fault), fail_ref, type_abi_alignment(type_fault), "load.err"); + LLVMValueRef result = LLVMBuildICmp(c->builder, LLVMIntEQ, errv, llvm_get_zero(c, type_fault), "result"); llvm_value_set(value, result, type_bool); return; } @@ -6327,8 +6327,8 @@ void llvm_emit_catch_unwrap(GenContext *c, BEValue *value, Expr *expr) } else { - LLVMValueRef temp_err = llvm_emit_alloca_aligned(c, type_anyfault, "temp_err"); - llvm_value_set_address_abi_aligned(&addr, temp_err, type_anyfault); + LLVMValueRef temp_err = llvm_emit_alloca_aligned(c, type_fault, "temp_err"); + llvm_value_set_address_abi_aligned(&addr, temp_err, type_fault); } LLVMBasicBlockRef catch_block = llvm_basic_block_new(c, "end_block"); @@ -6347,11 +6347,11 @@ void llvm_emit_catch_unwrap(GenContext *c, BEValue *value, Expr *expr) POP_CATCH(); - llvm_store_raw(c, &addr, llvm_get_zero(c, type_anyfault)); + llvm_store_raw(c, &addr, llvm_get_zero(c, type_fault)); llvm_emit_br(c, catch_block); llvm_emit_block(c, catch_block); llvm_value_rvalue(c, &addr); - llvm_value_set(value, addr.value, type_anyfault); + llvm_value_set(value, addr.value, type_fault); } @@ -6656,7 +6656,7 @@ static LLVMValueRef llvm_get_benchmark_hook_global(GenContext *c, Expr *expr) INLINE void llvm_emit_last_fault(GenContext *c, BEValue *value) { ASSERT(c->defer_error_var); - llvm_value_set_address_abi_aligned(value, c->defer_error_var, type_anyfault); + llvm_value_set_address_abi_aligned(value, c->defer_error_var, type_fault); } INLINE void llmv_emit_benchmark_hook(GenContext *c, BEValue *value, Expr *expr) @@ -7036,12 +7036,6 @@ void llvm_emit_expr(GenContext *c, BEValue *value, Expr *expr) llvm_value_rvalue(c, value); value->type = type_lowering(expr->type); return; - case EXPR_ANYFAULT_TO_FAULT: - REMINDER("Improve anyfault -> fault"); - llvm_emit_expr(c, value, expr->inner_expr); - llvm_value_rvalue(c, value); - value->type = type_lowering(expr->type); - return; case EXPR_VECTOR_FROM_ARRAY: llvm_emit_vector_from_array(c, value, expr); return; diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c index ce84144f2..f79b20f27 100644 --- a/src/compiler/llvm_codegen_function.c +++ b/src/compiler/llvm_codegen_function.c @@ -313,7 +313,7 @@ void llvm_emit_return_abi(GenContext *c, BEValue *return_value, BEValue *optiona return_out = c->optional_out; if (!optional) { - llvm_value_set(&no_fail, llvm_get_zero(c, type_anyfault), type_anyfault); + llvm_value_set(&no_fail, llvm_get_zero(c, type_fault), type_fault); optional = &no_fail; } return_value = optional; @@ -399,7 +399,7 @@ void llvm_emit_return_implicit(GenContext *c) return; } BEValue value; - llvm_value_set(&value, llvm_get_zero(c, type_anyfault), type_anyfault); + llvm_value_set(&value, llvm_get_zero(c, type_fault), type_fault); llvm_emit_return_abi(c, NULL, &value); } diff --git a/src/compiler/llvm_codegen_stmt.c b/src/compiler/llvm_codegen_stmt.c index b9713e797..4089e2d3f 100644 --- a/src/compiler/llvm_codegen_stmt.c +++ b/src/compiler/llvm_codegen_stmt.c @@ -47,12 +47,12 @@ void llvm_emit_local_static(GenContext *c, Decl *decl, BEValue *value) decl->backend_ref = llvm_add_global(c, "temp", decl->type, decl->alignment); if (IS_OPTIONAL(decl)) { - LLVMTypeRef anyfault = llvm_get_type(c, type_anyfault); + LLVMTypeRef fault = llvm_get_type(c, type_fault); scratch_buffer_append(c->cur_func.name); scratch_buffer_append_char('.'); scratch_buffer_append(decl->name); scratch_buffer_append(".f"); - decl->var.optional_ref = llvm_add_global_raw(c, scratch_buffer_to_string(), anyfault, 0); + decl->var.optional_ref = llvm_add_global_raw(c, scratch_buffer_to_string(), fault, 0); } llvm_emit_global_variable_init(c, decl); // Pop the builder @@ -133,7 +133,7 @@ void llvm_emit_local_decl(GenContext *c, Decl *decl, BEValue *value) scratch_buffer_clear(); scratch_buffer_append(decl->name ? decl->name : "anon"); scratch_buffer_append(".f"); - decl->var.optional_ref = llvm_emit_alloca_aligned(c, type_anyfault, scratch_buffer_to_string()); + decl->var.optional_ref = llvm_emit_alloca_aligned(c, type_fault, scratch_buffer_to_string()); // Only clear out the result if the assignment isn't an optional. } @@ -154,7 +154,7 @@ void llvm_emit_local_decl(GenContext *c, Decl *decl, BEValue *value) llvm_value_set(value, LLVMGetUndef(alloc_type), decl->type); if (is_optional) { - llvm_store_to_ptr_raw(c, decl->var.optional_ref, llvm_get_undef(c, type_anyfault), type_anyfault); + llvm_store_to_ptr_raw(c, decl->var.optional_ref, llvm_get_undef(c, type_fault), type_fault); } return; } @@ -164,7 +164,7 @@ void llvm_emit_local_decl(GenContext *c, Decl *decl, BEValue *value) llvm_value_set_decl_address(c, value, decl); if (is_optional) { - llvm_store_to_ptr_zero(c, decl->var.optional_ref, type_anyfault); + llvm_store_to_ptr_zero(c, decl->var.optional_ref, type_fault); // Prevent accidental optional folding in "llvm_store_zero"! value->kind = BE_ADDRESS; @@ -228,7 +228,7 @@ static inline void llvm_emit_return(GenContext *c, Ast *ast) if (ast->return_stmt.cleanup_fail) { llvm_value_rvalue(c, &be_value); - LLVMValueRef error_out = llvm_emit_alloca_aligned(c, type_anyfault, "reterr"); + LLVMValueRef error_out = llvm_emit_alloca_aligned(c, type_fault, "reterr"); llvm_store_to_ptr(c, error_out, &be_value); PUSH_DEFER_ERROR(error_out); llvm_emit_statement_chain(c, ast->return_stmt.cleanup_fail); @@ -245,7 +245,7 @@ static inline void llvm_emit_return(GenContext *c, Ast *ast) if (c->cur_func.prototype && type_is_optional(c->cur_func.prototype->rtype)) { error_return_block = llvm_basic_block_new(c, "err_retblock"); - error_out = llvm_emit_alloca_aligned(c, type_anyfault, "reterr"); + error_out = llvm_emit_alloca_aligned(c, type_fault, "reterr"); c->catch = (OptionalCatch) { error_out, error_return_block }; } @@ -297,7 +297,7 @@ static inline void llvm_emit_return(GenContext *c, Ast *ast) llvm_emit_statement_chain(c, ast->return_stmt.cleanup_fail); POP_DEFER_ERROR(); BEValue value; - llvm_value_set_address_abi_aligned(&value, error_out, type_anyfault); + llvm_value_set_address_abi_aligned(&value, error_out, type_fault); llvm_emit_return_abi(c, NULL, &value); } } diff --git a/src/compiler/llvm_codegen_value.c b/src/compiler/llvm_codegen_value.c index 821647d72..00cb40440 100644 --- a/src/compiler/llvm_codegen_value.c +++ b/src/compiler/llvm_codegen_value.c @@ -151,7 +151,7 @@ void llvm_emit_jump_to_optional_exit(GenContext *c, LLVMValueRef opt_value) llvm_emit_block(c, error_block); } - llvm_store_to_ptr_raw(c, c->catch.fault, opt_value, type_anyfault); + llvm_store_to_ptr_raw(c, c->catch.fault, opt_value, type_fault); llvm_emit_br(c, c->catch.block); llvm_emit_block(c, after_block); } @@ -160,7 +160,7 @@ void llvm_value_fold_optional(GenContext *c, BEValue *value) { if (value->kind == BE_ADDRESS_OPTIONAL) { - llvm_emit_jump_to_optional_exit(c, llvm_load_abi_alignment(c, type_anyfault, value->optional, "optval")); + llvm_emit_jump_to_optional_exit(c, llvm_load_abi_alignment(c, type_fault, value->optional, "optval")); value->kind = BE_ADDRESS; } } diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index c6f8b218f..a9ca80b92 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -210,7 +210,7 @@ static inline Expr *parse_catch_unwrap(ParseContext *c) return expr; } - // We don't have a chain, so it's either "anyfault f" or "f" or an expression. + // We don't have a chain, so it's either "fault f" or "f" or an expression. if (sub_expr->expr_kind == EXPR_TYPEINFO) { // Assign the type @@ -227,7 +227,7 @@ static inline Expr *parse_catch_unwrap(ParseContext *c) // If we don't have an '=', we check whether if (!try_consume(c, TOKEN_EQ)) { - // If we had "anyfault f", then we MUST have '=' + // If we had "fault f", then we MUST have '=' if (expr->unresolved_catch_expr.type) { PRINT_ERROR_HERE("Expected a '=' here."); @@ -1949,7 +1949,7 @@ ParseRule rules[TOKEN_EOF + 1] = { [TOKEN_FLOAT128] = { parse_type_identifier, NULL, PREC_NONE }, [TOKEN_VOID] = { parse_type_identifier, NULL, PREC_NONE }, [TOKEN_TYPEID] = { parse_type_identifier, NULL, PREC_NONE }, - [TOKEN_ANYFAULT] = { parse_type_identifier, NULL, PREC_NONE }, + [TOKEN_FAULT] = { parse_type_identifier, NULL, PREC_NONE }, [TOKEN_ANY] = { parse_type_identifier, NULL, PREC_NONE }, [TOKEN_QUESTION] = { NULL, parse_ternary_expr, PREC_TERNARY }, diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index a4fbd85ad..84e876e95 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -48,8 +48,9 @@ void recover_top_level(ParseContext *c) case TOKEN_EXTERN: case TOKEN_ENUM: case TOKEN_ALIAS: - case TOKEN_DEF: - case TOKEN_FAULT: + case TOKEN_TYPEDEF: + case TOKEN_ATTRDEF: + case TOKEN_FAULTDEF: return; case TOKEN_CONST: case TOKEN_ASM: @@ -1066,14 +1067,7 @@ static bool parse_attributes_for_global(ParseContext *c, Decl *decl) return true; } -/** - * attribute_list ::= attribute* - * - * Patch visibility and builtin attributes immediately. - * - * @return true if parsing succeeded, false if recovery is needed - */ -bool parse_attributes(ParseContext *c, Attr ***attributes_ref, Visibility *visibility_ref, bool *builtin_ref, bool *cond_ref) +static inline bool parse_attribute_list(ParseContext *c, Attr ***attributes_ref, Visibility *visibility_ref, bool *builtin_ref, bool *cond_ref, bool use_comma) { Visibility visibility = -1; // NOLINT if (cond_ref) *cond_ref = false; @@ -1130,10 +1124,22 @@ bool parse_attributes(ParseContext *c, Attr ***attributes_ref, Visibility *visib if (other_attr->name == name) RETURN_PRINT_ERROR_AT(false, attr, "Repeat of attribute '%s' here.", name); } vec_add(*attributes_ref, attr); + if (use_comma && !try_consume(c, TOKEN_COMMA)) break; } return true; } +/** + * attribute_list ::= attribute* + * + * Patch visibility and builtin attributes immediately. + * + * @return true if parsing succeeded, false if recovery is needed + */ +bool parse_attributes(ParseContext *c, Attr ***attributes_ref, Visibility *visibility_ref, bool *builtin_ref, bool *cond_ref) +{ + return parse_attribute_list(c, attributes_ref, visibility_ref, builtin_ref, cond_ref, false); +} /** * global_declaration ::= TLOCAL? optional_type IDENT (('=' expression)? | (',' IDENT)* opt_attributes) ';' @@ -1679,11 +1685,11 @@ static bool parse_struct_body(ParseContext *c, Decl *parent) /** - * distinct_declaration ::= 'distinct' TYPE_IDENT opt_interfaces '=' 'inline'? type ';' + * typedef_declaration ::= 'typedef' TYPE_IDENT opt_interfaces attributes? '=' 'inline'? type ';' */ -static inline Decl *parse_distinct_declaration(ParseContext *c) +static inline Decl *parse_typedef_declaration(ParseContext *c) { - advance_and_verify(c, TOKEN_DISTINCT); + advance_and_verify(c, TOKEN_TYPEDEF); Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_DISTINCT); @@ -1701,7 +1707,7 @@ static inline Decl *parse_distinct_declaration(ParseContext *c) if (tok_is(c, TOKEN_FN)) { - PRINT_ERROR_HERE("A distinct type cannot define a new function type, but you can make a distinct type from an existing function type, e.g. `def FooFn = fn void(); distinct Bar = FooFn;`"); + PRINT_ERROR_HERE("A distinct type cannot define a new function type, but you can make a distinct type from an existing function type, e.g. `alias FooFn = fn void(); typedef Bar = FooFn;`"); return poisoned_decl; } // 2. Now parse the type which we know is here. @@ -1928,7 +1934,7 @@ static inline void decl_add_type(Decl *decl, TypeKind kind) decl->type = type; } /** - * typedef_declaration ::= ALIAS TYPE_IDENT '=' typedef_type ';' + * typedef_declaration ::= ALIAS TYPE_IDENT attributes? '=' typedef_type ';' * * typedef_type ::= func_typedef | type generic_params? * func_typedef ::= 'fn' optional_type parameter_type_list @@ -1958,6 +1964,8 @@ static inline Decl *parse_alias_type(ParseContext *c) return poisoned_decl; } + if (!parse_attributes_for_global(c, decl)) return poisoned_decl; + CONSUME_OR_RET(TOKEN_EQ, poisoned_decl); // 1. Did we have `fn`? In that case it's a function pointer. @@ -1974,7 +1982,7 @@ static inline Decl *parse_alias_type(ParseContext *c) { return poisoned_decl; } - if (!parse_attributes_for_global(c, decl)) return poisoned_decl; + if (!parse_attributes(c, &decl_type->attributes, NULL, NULL, NULL)) return poisoned_decl; RANGE_EXTEND_PREV(decl_type); RANGE_EXTEND_PREV(decl); CONSUME_EOS_OR_RET(poisoned_decl); @@ -2015,7 +2023,6 @@ static inline Decl *parse_alias_type(ParseContext *c) { decl->typedef_decl.is_redef = true; } - if (!parse_attributes_for_global(c, decl)) return poisoned_decl; RANGE_EXTEND_PREV(decl); CONSUME_EOS_OR_RET(poisoned_decl); @@ -2023,16 +2030,14 @@ static inline Decl *parse_alias_type(ParseContext *c) } /** - * define_ident ::= 'define' (IDENT | CONST_IDENT | AT_IDENT) '=' identifier_alias generic_params? + * define_ident ::= 'define' (IDENT | CONST_IDENT | AT_IDENT) attributes? '=' identifier_alias generic_params? * * identifier_alias ::= path? (IDENT | CONST_IDENT | AT_IDENT) */ static inline Decl *parse_alias_ident(ParseContext *c) { // 1. Store the beginning of the "alias". - // TODO remove - advance(c); - // advance_and_verify(c, TOKEN_ALIAS); + advance_and_verify(c, TOKEN_ALIAS); // 2. At this point we expect an ident or a const token. @@ -2064,6 +2069,9 @@ static inline Decl *parse_alias_ident(ParseContext *c) } // 4. Advance and consume the '=' advance(c); + + if (!parse_attributes_for_global(c, decl)) return poisoned_decl; + CONSUME_OR_RET(TOKEN_EQ, poisoned_decl); if (tok_is(c, TOKEN_FN)) @@ -2073,7 +2081,6 @@ static inline Decl *parse_alias_ident(ParseContext *c) ASSIGN_EXPR_OR_RET(decl->define_decl.alias_expr, parse_expr(c), poisoned_decl); - if (!parse_attributes_for_global(c, decl)) return poisoned_decl; RANGE_EXTEND_PREV(decl); CONSUME_EOS_OR_RET(poisoned_decl); @@ -2081,15 +2088,11 @@ static inline Decl *parse_alias_ident(ParseContext *c) } /** - * define_attribute ::= 'alias' AT_TYPE_IDENT '(' parameter_list ')' opt_attributes '=' '{' attributes? '}' ';' + * define_attribute ::= 'attrdef' AT_TYPE_IDENT '(' parameter_list ')' opt_attributes '=' '{' attributes? '}' ';' */ -static inline Decl *parse_alias_attribute(ParseContext *c) +static inline Decl *parse_attrdef(ParseContext *c) { - // 1. Store the beginning of the "alias". - // TODO remove - advance(c); - // advance_and_verify(c, TOKEN_ALIAS); - + advance_and_verify(c, TOKEN_ATTRDEF); Decl *decl = decl_new(DECL_ATTRIBUTE, symstr(c), c->span); @@ -2107,24 +2110,24 @@ static inline Decl *parse_alias_attribute(ParseContext *c) } Attr **attributes = NULL; + if (!parse_attributes_for_global(c, decl)) return poisoned_decl; + + // Empty + if (try_consume(c, TOKEN_EOS)) return decl; CONSUME_OR_RET(TOKEN_EQ, poisoned_decl); - CONSUME_OR_RET(TOKEN_LBRACE, poisoned_decl); - bool is_cond; bool is_builtin = false; - if (!parse_attributes(c, &attributes, NULL, decl_needs_prefix(decl) ? &is_builtin : NULL, &is_cond)) return poisoned_decl; - CONSUME_OR_RET(TOKEN_RBRACE, poisoned_decl); + if (!parse_attribute_list(c, &attributes, NULL, decl_needs_prefix(decl) ? &is_builtin : NULL, &is_cond, true)) return poisoned_decl; decl->attr_decl.attrs = attributes; decl->is_cond = is_cond; decl->is_autoimport = is_builtin; - if (!parse_attributes_for_global(c, decl)) return poisoned_decl; CONSUME_EOS_OR_RET(poisoned_decl); return decl; } /** - * define_decl ::= ALIAS define_type_body | + * define_decl ::= ALIAS define_type_body */ static inline Decl *parse_alias(ParseContext *c) { @@ -2132,9 +2135,6 @@ static inline Decl *parse_alias(ParseContext *c) { case TOKEN_TYPE_IDENT: return parse_alias_type(c); - case TOKEN_AT_TYPE_IDENT: - // define @Foo = @inline, @noreturn - return parse_alias_attribute(c); default: return parse_alias_ident(c); } @@ -2255,11 +2255,11 @@ static inline Decl *parse_fault(ParseContext *c) } /** - * fault_declaration ::= FAULT CONST_IDENT (',' CONST_IDENT)* ','? ';' + * faultdef_declaration ::= FAULTDEF CONST_IDENT (',' CONST_IDENT)* ','? ';' */ -static inline Decl *parse_fault_declaration(ParseContext *c) +static inline Decl *parse_faultdef_declaration(ParseContext *c) { - advance_and_verify(c, TOKEN_FAULT); + advance_and_verify(c, TOKEN_FAULTDEF); if (c->lexer.token_type == TOKEN_EOS) { @@ -2942,10 +2942,13 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **context_out) PRINT_ERROR_HERE("There are more than one doc comment in a row, that is not allowed."); return poisoned_decl; case TOKEN_ALIAS: - case TOKEN_DEF: if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; decl = parse_alias(c); break; + case TOKEN_ATTRDEF: + if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; + decl = parse_attrdef(c); + break; case TOKEN_FN: decl = parse_func_definition(c, contracts, c->unit->is_interface_file ? FUNC_PARSE_C3I : FUNC_PARSE_REGULAR); break; @@ -2998,9 +3001,9 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **context_out) if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; decl = parse_interface_declaration(c); break; - case TOKEN_DISTINCT: + case TOKEN_TYPEDEF: if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; - decl = parse_distinct_declaration(c); + decl = parse_typedef_declaration(c); break; case TOKEN_CONST: if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; @@ -3018,9 +3021,9 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **context_out) if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; decl = parse_enum_declaration(c); break; - case TOKEN_FAULT: + case TOKEN_FAULTDEF: if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; - decl = parse_fault_declaration(c); + decl = parse_faultdef_declaration(c); break; case TOKEN_IDENT: if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 18c76b402..f431a62d7 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -559,7 +559,7 @@ static inline Ast* parse_defer_stmt(ParseContext *c) if (!expect_ident(c, "identifier")) return poisoned_ast; Ast *compound = ast_new_curr(c, AST_COMPOUND_STMT); Ast *first = ast_new_curr(c, AST_DECLARE_STMT); - Decl *decl = decl_new_var(c->data.string, c->span, type_info_new_base(type_anyfault, c->span), VARDECL_LOCAL); + Decl *decl = decl_new_var(c->data.string, c->span, type_info_new_base(type_fault, c->span), VARDECL_LOCAL); defer_stmt->defer_stmt.is_catch = true; decl->var.init_expr = expr_new(EXPR_LAST_FAULT, decl->span); first->declare_stmt = decl; @@ -1363,9 +1363,9 @@ Ast *parse_stmt(ParseContext *c) advance(c); return poisoned_ast; case TOKEN_ALIAS: - case TOKEN_DEF: // TODO remove case TOKEN_AND: case TOKEN_ARROW: + case TOKEN_ATTRDEF: case TOKEN_BANGBANG: case TOKEN_BITSTRUCT: case TOKEN_BIT_AND_ASSIGN: @@ -1383,7 +1383,6 @@ Ast *parse_stmt(ParseContext *c) case TOKEN_CT_EXEC: case TOKEN_CT_INCLUDE: case TOKEN_CT_VASPLAT: - case TOKEN_DISTINCT: case TOKEN_DIV: case TOKEN_DIV_ASSIGN: case TOKEN_DOCS_END: @@ -1399,7 +1398,7 @@ Ast *parse_stmt(ParseContext *c) case TOKEN_EQ: case TOKEN_EQEQ: case TOKEN_EXTERN: - case TOKEN_FAULT: + case TOKEN_FAULTDEF: case TOKEN_FN: case TOKEN_GREATER: case TOKEN_GREATER_EQ: @@ -1429,6 +1428,7 @@ Ast *parse_stmt(ParseContext *c) case TOKEN_SHR: case TOKEN_SHR_ASSIGN: case TOKEN_STRUCT: + case TOKEN_TYPEDEF: case TOKEN_UNDERSCORE: case TOKEN_UNION: PRINT_ERROR_HERE("Unexpected '%s' found when expecting a statement.", diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index d90e58d76..e588a5ef8 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -1880,21 +1880,6 @@ static void cast_untyped_list_to_other(Expr *expr, Type *to_type) expr_recursively_rewrite_untyped_list(expr, to_type); } -static void cast_anyfault_to_fault(Expr *expr, Type *type) -{ - if (!sema_cast_const(expr)) - { - expr->inner_expr = expr_copy(expr); - expr->expr_kind = EXPR_ANYFAULT_TO_FAULT; - expr->type = type; - expr->resolve_status = RESOLVE_DONE; - return; - } - ASSERT(expr_is_const_fault(expr)); - Decl *value = expr->const_expr.enum_val; - ASSERT(value->type != type); - expr->type = type; -} static void cast_slice_to_ptr(Expr *expr, Type *type) { diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 0119216a1..f20d245de 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -4,10 +4,6 @@ #include "sema_internal.h" -#define EXPORTED_USER_DEFINED_TYPES (ATTR_ENUM | ATTR_UNION | ATTR_STRUCT | ATTR_FAULT) -#define CALLABLE_TYPE (ATTR_FUNC | ATTR_INTERFACE_METHOD | ATTR_MACRO) -#define USER_DEFINED_TYPES EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_DISTINCT - static inline bool sema_analyse_func_macro(SemaContext *context, Decl *decl, AttributeDomain domain, bool *erase_decl); static inline bool sema_analyse_func(SemaContext *context, Decl *decl, bool *erase_decl); static inline bool sema_analyse_macro(SemaContext *context, Decl *decl, bool *erase_decl); @@ -1377,7 +1373,7 @@ bool sema_analyse_function_signature(SemaContext *context, Decl *func_decl, Type static inline bool sema_analyse_fntype(SemaContext *context, Decl *decl, bool *erase_decl) { - if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_DEF, erase_decl)) return decl_poison(decl); + if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_FNTYPE, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; Signature *sig = &decl->fntype_decl; return sema_analyse_function_signature(context, decl, NULL, sig->abi, sig); @@ -1385,7 +1381,7 @@ static inline bool sema_analyse_fntype(SemaContext *context, Decl *decl, bool *e static inline bool sema_analyse_typedef(SemaContext *context, Decl *decl, bool *erase_decl) { - if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_DEF, erase_decl)) return decl_poison(decl); + if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_ALIAS, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; bool is_export = decl->is_export; @@ -1614,7 +1610,7 @@ static inline bool sema_analyse_fault(SemaContext *context, Decl *decl, bool *er { if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_FAULT, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; - decl->type = type_anyfault; + decl->type = type_fault; decl->alignment = type_abi_alignment(type_string); return true; } @@ -2248,7 +2244,7 @@ static inline bool sema_analyse_method(SemaContext *context, Decl *decl) case TYPE_ANYFAULT: if (kw == kw_type || kw == kw_nameof) { - errname = "'anyfault'"; + errname = "'fault'"; goto NOT_VALID_NAME; } break; @@ -2393,15 +2389,17 @@ static const char *attribute_domain_to_string(AttributeDomain domain) case ATTR_CONST: return "constant"; case ATTR_FAULT: - return "fault"; - case ATTR_DEF: - return "def"; + return "faultdef"; + case ATTR_ALIAS: + return "alias"; case ATTR_CALL: return "call"; case ATTR_DISTINCT: return "distinct"; case ATTR_INTERFACE_METHOD: return "interface method"; + case ATTR_FNTYPE: + return "function type"; } UNREACHABLE } @@ -2409,9 +2407,9 @@ static const char *attribute_domain_to_string(AttributeDomain domain) // Helper method INLINE bool update_abi(Decl *decl, CallABI abi) { - if (decl->decl_kind == DECL_TYPEDEF) + if (decl->decl_kind == DECL_FNTYPE) { - decl->typedef_decl.decl->fntype_decl.abi = abi; + decl->fntype_decl.abi = abi; return true; } decl->func_decl.signature.abi = abi; @@ -2466,9 +2464,6 @@ static bool update_call_abi_from_string(SemaContext *context, Decl *decl, Expr * RETURN_SEMA_ERROR(expr, "Unknown call convention, only 'cdecl', 'stdcall' and 'veccall' are supported"); } -#define EXPORTED_USER_DEFINED_TYPES (ATTR_ENUM | ATTR_UNION | ATTR_STRUCT | ATTR_FAULT) -#define CALLABLE_TYPE (ATTR_FUNC | ATTR_INTERFACE_METHOD | ATTR_MACRO) -#define USER_DEFINED_TYPES EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_DISTINCT /** * Analyse almost all attributes. @@ -2483,12 +2478,12 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ [ATTRIBUTE_BENCHMARK] = ATTR_FUNC, [ATTRIBUTE_BIGENDIAN] = ATTR_BITSTRUCT, [ATTRIBUTE_BUILTIN] = ATTR_MACRO | ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST, - [ATTRIBUTE_CALLCONV] = ATTR_FUNC | ATTR_DEF | ATTR_INTERFACE_METHOD, + [ATTRIBUTE_CALLCONV] = ATTR_FUNC | ATTR_INTERFACE_METHOD | ATTR_FNTYPE, [ATTRIBUTE_COMPACT] = ATTR_STRUCT | ATTR_UNION, [ATTRIBUTE_CONST] = ATTR_MACRO, [ATTRIBUTE_DEPRECATED] = USER_DEFINED_TYPES | CALLABLE_TYPE | ATTR_CONST | ATTR_GLOBAL | ATTR_MEMBER | ATTR_BITSTRUCT_MEMBER | ATTR_INTERFACE, [ATTRIBUTE_DYNAMIC] = ATTR_FUNC, - [ATTRIBUTE_EXPORT] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_DEF, + [ATTRIBUTE_EXPORT] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_ALIAS, [ATTRIBUTE_EXTERN] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES, [ATTRIBUTE_FINALIZER] = ATTR_FUNC, [ATTRIBUTE_IF] = (AttributeDomain)~(ATTR_CALL | ATTR_LOCAL | ATTR_PARAM), @@ -2496,7 +2491,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ [ATTRIBUTE_INLINE] = ATTR_FUNC | ATTR_CALL, [ATTRIBUTE_LINK] = ATTR_FUNC | ATTR_MACRO | ATTR_CONST | ATTR_GLOBAL, [ATTRIBUTE_LITTLEENDIAN] = ATTR_BITSTRUCT, - [ATTRIBUTE_LOCAL] = ATTR_FUNC | ATTR_MACRO | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_DEF | ATTR_INTERFACE, + [ATTRIBUTE_LOCAL] = ATTR_FUNC | ATTR_MACRO | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_ALIAS | ATTR_INTERFACE, [ATTRIBUTE_MAYDISCARD] = CALLABLE_TYPE, [ATTRIBUTE_NAKED] = ATTR_FUNC, [ATTRIBUTE_NOALIAS] = ATTR_PARAM, @@ -2512,8 +2507,8 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ [ATTRIBUTE_OPTIONAL] = ATTR_INTERFACE_METHOD, [ATTRIBUTE_OVERLAP] = ATTR_BITSTRUCT, [ATTRIBUTE_PACKED] = ATTR_STRUCT | ATTR_UNION, - [ATTRIBUTE_PRIVATE] = ATTR_FUNC | ATTR_MACRO | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_DEF | ATTR_INTERFACE, - [ATTRIBUTE_PUBLIC] = ATTR_FUNC | ATTR_MACRO | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_DEF | ATTR_INTERFACE, + [ATTRIBUTE_PRIVATE] = ATTR_FUNC | ATTR_MACRO | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_ALIAS | ATTR_INTERFACE, + [ATTRIBUTE_PUBLIC] = ATTR_FUNC | ATTR_MACRO | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_ALIAS | ATTR_INTERFACE, [ATTRIBUTE_PURE] = ATTR_CALL, [ATTRIBUTE_REFLECT] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES, [ATTRIBUTE_SAFEMACRO] = ATTR_MACRO, @@ -2523,7 +2518,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ [ATTRIBUTE_UNUSED] = (AttributeDomain)~(ATTR_CALL), [ATTRIBUTE_USED] = (AttributeDomain)~(ATTR_CALL), [ATTRIBUTE_WASM] = ATTR_FUNC, - [ATTRIBUTE_WEAK] = ATTR_FUNC | ATTR_CONST | ATTR_GLOBAL | ATTR_DEF, + [ATTRIBUTE_WEAK] = ATTR_FUNC | ATTR_CONST | ATTR_GLOBAL | ATTR_ALIAS, [ATTRIBUTE_WINMAIN] = ATTR_FUNC, }; // NOLINTEND(*.EnumCastOutOfRange) @@ -2579,10 +2574,6 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ decl->func_decl.attr_winmain = true; break; case ATTRIBUTE_CALLCONV: - if (domain == ATTR_DEF && (decl->decl_kind != DECL_TYPEDEF || !decl->typedef_decl.is_func)) - { - RETURN_SEMA_ERROR(attr, "'@callconv' cannot only be used with fn types."); - } if (!expr) RETURN_SEMA_ERROR(decl, "Expected a string argument."); if (expr && !sema_analyse_expr(context, expr)) return false; if (!expr_is_const_string(expr)) RETURN_SEMA_ERROR(expr, "Expected a constant string value as argument."); @@ -2882,7 +2873,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ } return true; case ATTRIBUTE_WEAK: - if (domain == ATTR_DEF) + if (domain == ATTR_ALIAS) { if (decl->decl_kind != DECL_TYPEDEF) RETURN_SEMA_ERROR(attr, "'@weak' can only be used on type aliases."); if (!decl->typedef_decl.is_redef) @@ -3854,7 +3845,7 @@ static bool sema_analyse_variable_type(SemaContext *context, Type *type, SourceS { RETURN_SEMA_ERROR_AT(span, "The use of %s as a variable type is not permitted, " "catch the error using 'if (catch err = foo) { ... }'," - " or use '@catch(foo)' to convert it to an 'anyfault'.", + " or use '@catch(foo)' to convert it to a 'fault'.", type_quoted_error_string(type)); } RETURN_SEMA_ERROR_AT(span, "The use of %s as a variable type is not permitted.", type_quoted_error_string(type)); @@ -4513,7 +4504,7 @@ Decl *sema_analyse_parameterized_identifier(SemaContext *c, Path *decl_path, con static inline bool sema_analyse_attribute_decl(SemaContext *context, SemaContext *c, Decl *decl, bool *erase_decl) { - if (!sema_analyse_attributes(c, decl, decl->attributes, ATTR_DEF, erase_decl)) return decl_poison(decl); + if (!sema_analyse_attributes(c, decl, decl->attributes, ATTR_ALIAS, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; Decl **params = decl->attr_decl.params; @@ -4538,7 +4529,7 @@ static inline bool sema_analyse_attribute_decl(SemaContext *context, SemaContext static inline bool sema_analyse_define(SemaContext *context, Decl *decl, bool *erase_decl) { - if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_DEF, erase_decl)) return decl_poison(decl); + if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_ALIAS, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; Expr *expr = decl->define_decl.alias_expr; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 8ead09c9e..661c49e55 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -610,7 +610,6 @@ static bool sema_binary_is_expr_lvalue(SemaContext *context, Expr *top_expr, Exp case EXPR_TYPECALL: case EXPR_TYPEID_INFO: case EXPR_TYPEINFO: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_FROM_ARRAY: case EXPR_VECTOR_TO_ARRAY: case EXPR_SLICE_TO_VEC_ARRAY: @@ -657,7 +656,6 @@ static bool expr_may_ref(Expr *expr) case EXPR_PTR_TO_INT: case EXPR_SLICE_LEN: case EXPR_VECTOR_FROM_ARRAY: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_INT_TO_BOOL: case EXPR_RVALUE: case EXPR_RECAST: @@ -5191,7 +5189,7 @@ CHECK_DEEPER: expr_rewrite_to_builtin_access(expr, current_parent, ACCESS_ENUMNAME, type_string); return true; } - if (flat_type == type_anyfault) + if (flat_type == type_fault) { if (sema_cast_const(current_parent)) { @@ -7803,7 +7801,7 @@ static inline bool sema_expr_analyse_or_error(SemaContext *context, Expr *expr, Type *common = type_find_max_type(type, else_type); if (!common) { - if (else_type == type_anyfault) + if (else_type == type_fault) { RETURN_SEMA_ERROR(right, "There is no common type for %s and %s, did you perhaps forget a '?' after the last expression?", type_quoted_error_string(type), type_quoted_error_string(else_type)); } @@ -8039,7 +8037,7 @@ static inline bool sema_expr_analyse_optional(SemaContext *context, Expr *expr, Type *type = inner->type->canonical; - if (type != type_anyfault) + if (type != type_fault) { if (failed_ref) goto ON_FAILED; RETURN_SEMA_ERROR(inner, "You cannot use the '?' operator on expressions of type %s", @@ -9205,7 +9203,6 @@ static inline bool sema_expr_analyse_ct_defined(SemaContext *context, Expr *expr case EXPR_PTR_ACCESS: case EXPR_ENUM_FROM_ORD: case EXPR_SLICE_LEN: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_FROM_ARRAY: case EXPR_RVALUE: case EXPR_RECAST: @@ -9550,7 +9547,6 @@ static inline bool sema_analyse_expr_dispatch(SemaContext *context, Expr *expr, return sema_analyse_expr(context, expr->inner_expr); case EXPR_PTR_ACCESS: case EXPR_SLICE_LEN: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_FROM_ARRAY: return sema_analyse_expr(context, expr->inner_expr); case EXPR_INT_TO_BOOL: @@ -9612,7 +9608,7 @@ static inline bool sema_analyse_expr_dispatch(SemaContext *context, Expr *expr, return true; } case EXPR_LAST_FAULT: - expr->type = type_anyfault; + expr->type = type_fault; return true; case EXPR_RETVAL: return sema_expr_analyse_retval(context, expr); @@ -9736,11 +9732,11 @@ bool sema_analyse_expr_rhs(SemaContext *context, Type *to, Expr *expr, bool allo Type *to_canonical = to ? to->canonical : NULL; Type *rhs_type = expr->type; Type *rhs_type_canonical = rhs_type->canonical; - // Let's have a better error on `return io::FILE_NOT_FOUND;` when the return type is not anyfault. - if (to && allow_optional && to_canonical != rhs_type_canonical && rhs_type_canonical == type_anyfault) + // Let's have a better error on `return io::FILE_NOT_FOUND;` when the return type is not fault. + if (to && allow_optional && to_canonical != rhs_type_canonical && rhs_type_canonical == type_fault) { Type *flat = type_flatten(to); - if (flat != type_anyfault && sema_cast_const(expr)) + if (flat != type_fault && sema_cast_const(expr)) { if (no_match_ref) goto NO_MATCH_REF; print_error_after(expr->span, "You need to add a trailing '?' here to make this an optional."); @@ -10085,7 +10081,6 @@ IDENT_CHECK:; case EXPR_TYPECALL: case EXPR_TYPEID_INFO: case EXPR_TYPEINFO: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_FROM_ARRAY: case EXPR_VECTOR_TO_ARRAY: case EXPR_SLICE_TO_VEC_ARRAY: diff --git a/src/compiler/sema_liveness.c b/src/compiler/sema_liveness.c index 604d809a3..3f2ac7bf7 100644 --- a/src/compiler/sema_liveness.c +++ b/src/compiler/sema_liveness.c @@ -337,7 +337,6 @@ RETRY: case EXPR_INT_TO_PTR: case EXPR_PTR_TO_INT: case EXPR_SLICE_LEN: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_FROM_ARRAY: case EXPR_RVALUE: case EXPR_RECAST: diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index cba6191bb..26986b914 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -783,7 +783,6 @@ static inline bool sema_expr_valid_try_expression(Expr *expr) case EXPR_INT_TO_PTR: case EXPR_PTR_TO_INT: case EXPR_SLICE_LEN: - case EXPR_ANYFAULT_TO_FAULT: case EXPR_VECTOR_FROM_ARRAY: case EXPR_RVALUE: case EXPR_RECAST: @@ -930,13 +929,13 @@ static inline bool sema_analyse_catch_unwrap(SemaContext *context, Expr *expr) Decl *decl = NULL; if (!type && !ident) goto RESOLVE_EXPRS; - type = type ? type : type_info_new_base(type_anyfault, expr->span); + type = type ? type : type_info_new_base(type_fault, expr->span); if (!sema_resolve_type_info(context, type, RESOLVE_TYPE_DEFAULT)) return false; - if (type->type->canonical != type_anyfault) + if (type->type->canonical != type_fault) { - RETURN_SEMA_ERROR(type, "Expected the type to be %s, not %s.", type_quoted_error_string(type_anyfault), + RETURN_SEMA_ERROR(type, "Expected the type to be %s, not %s.", type_quoted_error_string(type_fault), type_quoted_error_string(type->type)); } if (ident->expr_kind != EXPR_UNRESOLVED_IDENTIFIER) @@ -966,7 +965,7 @@ RESOLVE_EXPRS:; } expr->catch_expr = (ExprCatch) { .exprs = exprs, .decl = decl }; expr->expr_kind = EXPR_CATCH; - expr->type = type_anyfault; + expr->type = type_fault; expr->resolve_status = RESOLVE_DONE; return true; } @@ -2028,7 +2027,7 @@ static bool sema_analyse_nextcase_stmt(SemaContext *context, Ast *statement) return false; } - Type *expected_type = parent->ast_kind == AST_SWITCH_STMT ? cond->type : type_anyfault; + Type *expected_type = parent->ast_kind == AST_SWITCH_STMT ? cond->type : type_fault; if (!sema_analyse_expr_rhs(context, expected_type, value, false, NULL, false)) return false; @@ -2743,7 +2742,7 @@ static inline bool sema_analyse_switch_stmt(SemaContext *context, Ast *statement } else { - switch_type = type_anyfault; + switch_type = type_fault; } statement->switch_stmt.defer = context->active_scope.defer_last; diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 9a370272f..feb0b4089 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -616,7 +616,7 @@ static inline Type *func_create_new_func_proto(Signature *sig, CallABI abi, uint Type *real_return_type = rtype->optional; proto->ret_by_ref_type = rtype->optional; proto->ret_by_ref = !type_is_void(real_return_type); - proto->abi_ret_type = type_anyfault; + proto->abi_ret_type = type_fault; } else { diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index a3786617c..5a072e849 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -187,12 +187,12 @@ const char *token_type_to_string(TokenType type) // Keywords case TOKEN_ALIAS: return "alias"; - case TOKEN_ANYFAULT: - return "anyfault"; case TOKEN_ASM: return "asm"; case TOKEN_ASSERT: return "assert"; + case TOKEN_ATTRDEF: + return "attrdef"; case TOKEN_BITSTRUCT: return "bitstruct"; case TOKEN_BREAK: @@ -205,14 +205,10 @@ const char *token_type_to_string(TokenType type) return "const"; case TOKEN_CONTINUE: return "continue"; - case TOKEN_DEF: - return "def"; case TOKEN_DEFAULT: return "default"; case TOKEN_DEFER: return "defer"; - case TOKEN_DISTINCT: - return "distinct"; case TOKEN_DO: return "do"; case TOKEN_ELSE: @@ -223,8 +219,8 @@ const char *token_type_to_string(TokenType type) return "extern"; case TOKEN_FALSE: return "false"; - case TOKEN_FAULT: - return "fault"; + case TOKEN_FAULTDEF: + return "faultdef"; case TOKEN_FOR: return "for"; case TOKEN_FOREACH: @@ -263,6 +259,8 @@ const char *token_type_to_string(TokenType type) return "true"; case TOKEN_TRY: return "try"; + case TOKEN_TYPEDEF: + return "typedef"; case TOKEN_TYPEID: return "typeid"; case TOKEN_UNION: @@ -277,6 +275,8 @@ const char *token_type_to_string(TokenType type) return "void"; case TOKEN_ANY: return "any"; + case TOKEN_FAULT: + return "fault"; case TOKEN_BOOL: return "bool"; case TOKEN_FLOAT128: @@ -401,7 +401,6 @@ const char *token_type_to_string(TokenType type) return ""; case TOKEN_EOF: return "EOF"; - } UNREACHABLE } diff --git a/src/compiler/types.c b/src/compiler/types.c index 7646590a3..573465e61 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -14,7 +14,7 @@ static struct Type bf16, f16, f32, f64, f128; Type usz, isz, uptr, iptr; Type string; - Type voidstar, typeid, anyfault, member, typeinfo, untyped_list; + Type voidstar, typeid, fault, member, typeinfo, untyped_list; Type any, wildcard; } t; @@ -43,7 +43,7 @@ Type *type_ulong = &t.u64; Type *type_u128 = &t.u128; Type *type_uptr = &t.uptr; Type *type_usz = &t.usz; -Type *type_anyfault = &t.anyfault; +Type *type_fault = &t.fault; Type *type_untypedlist = &t.untyped_list; Type *type_wildcard = &t.wildcard; Type *type_member = &t.member; @@ -1385,7 +1385,7 @@ void type_setup(PlatformTarget *target) alignment_slice = MAX(type_abi_alignment(&t.voidstar), type_abi_alignment(t.usz.canonical)); size_slice = (unsigned)(alignment_slice * 2); - type_init("anyfault", &t.anyfault, TYPE_ANYFAULT, target->width_pointer, target->align_pointer); + type_init("fault", &t.fault, TYPE_ANYFAULT, target->width_pointer, target->align_pointer); type_chars = type_get_slice(type_char); type_wildcard_optional = type_get_optional(type_wildcard); Decl *string_decl = decl_new_with_type(symtab_preset("String", TOKEN_TYPE_IDENT), INVALID_SPAN, DECL_DISTINCT); @@ -1520,8 +1520,8 @@ Type *type_from_token(TokenType type) { case TOKEN_ANY: return type_any; - case TOKEN_ANYFAULT: - return type_anyfault; + case TOKEN_FAULT: + return type_fault; case TOKEN_VOID: return type_void; case TOKEN_BOOL: @@ -2006,7 +2006,7 @@ RETRY_DISTINCT: // some way? return NULL; case TYPE_ANYFAULT: - return type_anyfault; + return type_fault; case TYPE_FUNC_PTR: if (other == type_voidptr) return other; if (other->type_kind != TYPE_FUNC_PTR) return NULL; diff --git a/test/test_suite/arrays/slice_array.c3 b/test/test_suite/arrays/slice_array.c3 index ac5ddd612..bdae1e199 100644 --- a/test/test_suite/arrays/slice_array.c3 +++ b/test/test_suite/arrays/slice_array.c3 @@ -1,4 +1,4 @@ -distinct Bar = inline void; +typedef Bar = inline void; struct Foo { diff --git a/test/test_suite/assert/unreachable_in_macro.c3t b/test/test_suite/assert/unreachable_in_macro.c3t index 17bb5a1d4..0b5847b5b 100644 --- a/test/test_suite/assert/unreachable_in_macro.c3t +++ b/test/test_suite/assert/unreachable_in_macro.c3t @@ -11,7 +11,7 @@ fn int main() return 0; } -fault ABC; +faultdef ABC; macro test() { diff --git a/test/test_suite/attributes/attr_not_imported.c3 b/test/test_suite/attributes/attr_not_imported.c3 index afd866b16..a21f52997 100644 --- a/test/test_suite/attributes/attr_not_imported.c3 +++ b/test/test_suite/attributes/attr_not_imported.c3 @@ -1,6 +1,6 @@ module abc; -alias @Foo = { @inline }; +attrdef @Foo = @inline; module bar; diff --git a/test/test_suite/attributes/attribute_params.c3 b/test/test_suite/attributes/attribute_params.c3 index b18e6bab9..39666e238 100644 --- a/test/test_suite/attributes/attribute_params.c3 +++ b/test/test_suite/attributes/attribute_params.c3 @@ -1,5 +1,5 @@ -alias @Foo() = { @inline }; // #error: At least one parameter was expected -alias @Bar = { @inline }; +attrdef @Foo() = @inline; // #error: At least one parameter was expected +attrdef @Bar = @inline; fn void test1() @Foo { } fn void test2() @Foo() { } // #error: An expression was diff --git a/test/test_suite/attributes/attribute_visibility.c3t b/test/test_suite/attributes/attribute_visibility.c3t index 87cd85ca6..d9ffbc3bc 100644 --- a/test/test_suite/attributes/attribute_visibility.c3t +++ b/test/test_suite/attributes/attribute_visibility.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; const int FOO @private = 4; -alias @Align(x) = { @align(x * FOO) }; +attrdef @Align(x) = @align(x * FOO); module test2; import test; diff --git a/test/test_suite/attributes/attributes_repeat_param.c3t b/test/test_suite/attributes/attributes_repeat_param.c3t index 99bdc2c7b..f1e3985bd 100644 --- a/test/test_suite/attributes/attributes_repeat_param.c3t +++ b/test/test_suite/attributes/attributes_repeat_param.c3t @@ -1,7 +1,7 @@ // #target: macos-aarch64 module test; -alias @Test(x) = { @extern("Foo" +++ x) }; +attrdef @Test(x) = @extern("Foo" +++ x); fn void hello_world() @Test("Megaman") {} diff --git a/test/test_suite/attributes/recursive_attributes.c3 b/test/test_suite/attributes/recursive_attributes.c3 index 3c25d73c8..5f10fc88c 100644 --- a/test/test_suite/attributes/recursive_attributes.c3 +++ b/test/test_suite/attributes/recursive_attributes.c3 @@ -1,8 +1,8 @@ module test; -alias @Align(y) = { @Align16(y / 2) }; -alias @Align16(x) = { @align(4) @Align(8 * x) }; // #error: Recursive declaration of attribute -alias @Test = { @noinline }; +attrdef @Align(y) = @Align16(y / 2); +attrdef @Align16(x) = @align(4), @Align(8 * x); // #error: Recursive declaration of attribute +attrdef @Test = @noinline; struct Foo { int z; diff --git a/test/test_suite/attributes/user_defined_attributes.c3t b/test/test_suite/attributes/user_defined_attributes.c3t index a166773a3..3a9628188 100644 --- a/test/test_suite/attributes/user_defined_attributes.c3t +++ b/test/test_suite/attributes/user_defined_attributes.c3t @@ -2,12 +2,12 @@ module test; -alias @Foo = { @noreturn @weak }; +attrdef @Foo = @noreturn, @weak; -alias @Align(y) = { @align(y) }; -alias @Align16(x) = { @Align(8 * x) @align(1024) } @private; -alias @Test = { @noinline }; -alias @TestZero = { }; +attrdef @Align(y) = @align(y); +attrdef @Align16(x) @private = @Align(8 * x), @align(1024); +attrdef @Test = @noinline; +attrdef @TestZero; struct Foo { int z; diff --git a/test/test_suite/bitstruct/bitstruct_init.c3 b/test/test_suite/bitstruct/bitstruct_init.c3 index b7ba43915..d042dcc4c 100644 --- a/test/test_suite/bitstruct/bitstruct_init.c3 +++ b/test/test_suite/bitstruct/bitstruct_init.c3 @@ -68,7 +68,7 @@ bitstruct Flags1 : int bool c; } -distinct Bool = bool; +typedef Bool = bool; bitstruct Flags2 : int { diff --git a/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 b/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 index 95c33992d..9e3c8d1df 100644 --- a/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 +++ b/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 @@ -5,8 +5,8 @@ bitstruct Test : int float a : 1..3; // #error: 'float' is not supported in a bitstruct, only enums, integer and boolean values may be used. } -distinct Baz = float; -distinct Foo = bool; +typedef Baz = float; +typedef Foo = bool; enum Boo { BAR diff --git a/test/test_suite/cast/cast_rcast.c3 b/test/test_suite/cast/cast_rcast.c3 index 92484c037..7eba30cd5 100644 --- a/test/test_suite/cast/cast_rcast.c3 +++ b/test/test_suite/cast/cast_rcast.c3 @@ -8,7 +8,7 @@ bitstruct Image_Tag : uint char x4 : 0..7; } -distinct Glyph_Format = CInt; +typedef Glyph_Format = CInt; const Glyph_Format GLYPH_FORMAT_BITMAP = (Glyph_Format)(Image_Tag) {'b', 'i', 't', 's'}; fn void main() { diff --git a/test/test_suite/cast/cast_subarray.c3t b/test/test_suite/cast/cast_subarray.c3t index 3ed733ca8..7ae584623 100644 --- a/test/test_suite/cast/cast_subarray.c3t +++ b/test/test_suite/cast/cast_subarray.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; -distinct Foo = int; +typedef Foo = int; fn void main() { int*[] abc = { }; diff --git a/test/test_suite/cast/cast_to_failable.c3 b/test/test_suite/cast/cast_to_failable.c3 index 1f5350d6b..9be529b1e 100644 --- a/test/test_suite/cast/cast_to_failable.c3 +++ b/test/test_suite/cast/cast_to_failable.c3 @@ -1,4 +1,4 @@ -fault FOO; +faultdef FOO; fn void test() { diff --git a/test/test_suite/compile_time/compile_time_access_subscript.c3t b/test/test_suite/compile_time/compile_time_access_subscript.c3t index f797b254e..3171bf79b 100644 --- a/test/test_suite/compile_time/compile_time_access_subscript.c3t +++ b/test/test_suite/compile_time/compile_time_access_subscript.c3t @@ -22,7 +22,7 @@ macro check_type($Type) enum Blurb { FOO } -distinct Bdd = Abc; +typedef Bdd = Abc; fn void main() { var $i = (int[4]) { 1, 2, 3, 4 }; @@ -30,7 +30,7 @@ fn void main() var $c = (any[4]) {}; check_type(int); check_type(Abc); - check_type(anyfault); + check_type(fault); check_type(Blurb); check_type(int*); check_type(bool); diff --git a/test/test_suite/compile_time/comptime_array_folding.c3t b/test/test_suite/compile_time/comptime_array_folding.c3t index 34fa10fa2..0cfd85a0a 100644 --- a/test/test_suite/compile_time/comptime_array_folding.c3t +++ b/test/test_suite/compile_time/comptime_array_folding.c3t @@ -2,9 +2,7 @@ module test; import std; -alias @TaggedAttr(value) = { - @tag("foo", (ValueHere[*]){ value }) -}; +attrdef @TaggedAttr(value) = @tag("foo", (ValueHere[*]){ value }); const FOO_STR = "foo"; diff --git a/test/test_suite/compile_time_introspection/recursive_tag.c3 b/test/test_suite/compile_time_introspection/recursive_tag.c3 index baefc9f86..2b61e97b7 100644 --- a/test/test_suite/compile_time_introspection/recursive_tag.c3 +++ b/test/test_suite/compile_time_introspection/recursive_tag.c3 @@ -1,6 +1,6 @@ enum Test @tag("test", Test.FOO) {FOO} // #error: Recursive definition of 'Test' -alias @Test(Foo val) = {}; +attrdef @Test(Foo val); enum Foo @tag("test", Foo.BAR) // #error: Recursive definition of 'Foo' { diff --git a/test/test_suite/debug_symbols/defer_macro.c3t b/test/test_suite/debug_symbols/defer_macro.c3t index 58c0cb3d1..38ded9f74 100644 --- a/test/test_suite/debug_symbols/defer_macro.c3t +++ b/test/test_suite/debug_symbols/defer_macro.c3t @@ -86,7 +86,7 @@ macro Id unique() } -distinct Color = float[<4>]; +typedef Color = float[<4>]; const Color BLACK = {0, 0, 0, 1}; const Color WHITE = {1, 1, 1, 1}; @@ -477,7 +477,7 @@ expr_block.exit: ; preds = %after_check, %if.th panic_block: ; preds = %assign_optional %29 = insertvalue %any undef, ptr %error_var, 0, !dbg !167 - %30 = insertvalue %any %29, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1, !dbg !167 + %30 = insertvalue %any %29, i64 ptrtoint (ptr @"$ct.fault" to i64), 1, !dbg !167 store %any %30, ptr %varargslots, align 16 %31 = insertvalue %"any[]" undef, ptr %varargslots, 0 %"$$temp" = insertvalue %"any[]" %31, i64 1, 1 diff --git a/test/test_suite/defer/defer_catch_direct_error.c3t b/test/test_suite/defer/defer_catch_direct_error.c3t index 3fee956e0..fab31c79c 100644 --- a/test/test_suite/defer/defer_catch_direct_error.c3t +++ b/test/test_suite/defer/defer_catch_direct_error.c3t @@ -8,7 +8,7 @@ fn void? example_fn() } defer (catch err) { - anyfault f = err; + fault f = err; } return io::FILE_NOT_FOUND?; } diff --git a/test/test_suite/defer/defer_catch_err.c3t b/test/test_suite/defer/defer_catch_err.c3t index ff16f158d..d65e61284 100644 --- a/test/test_suite/defer/defer_catch_err.c3t +++ b/test/test_suite/defer/defer_catch_err.c3t @@ -2,7 +2,7 @@ module foo; import std::io; -fault FOO; +faultdef FOO; fn void? test2() { @@ -104,14 +104,14 @@ opt_block_cleanup: ; preds = %assign_optional %3 = load i64, ptr %z.f, align 8 store i64 %3, ptr %err, align 8 %4 = insertvalue %any undef, ptr %err, 0 - %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %5, ptr %varargslots, align 16 %6 = call i64 @std.io.printfn(ptr %retparam, ptr @.str, i64 6, ptr %varargslots, i64 1) store i64 ptrtoint (ptr @foo.FOO to i64), ptr %err, align 8 %7 = load i64, ptr %z.f, align 8 store i64 %7, ptr %err3, align 8 %8 = insertvalue %any undef, ptr %err3, 0 - %9 = insertvalue %any %8, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %9 = insertvalue %any %8, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %9, ptr %varargslots4, align 16 %10 = call i64 @std.io.printfn(ptr %retparam5, ptr @.str.1, i64 8, ptr %varargslots4, i64 1) br label %after_assign @@ -142,14 +142,14 @@ err_retblock: ; preds = %assign_optional12 %14 = load i64, ptr %reterr, align 8 store i64 %14, ptr %err14, align 8 %15 = insertvalue %any undef, ptr %err14, 0 - %16 = insertvalue %any %15, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %16 = insertvalue %any %15, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %16, ptr %varargslots15, align 16 %17 = call i64 @std.io.printfn(ptr %retparam16, ptr @.str.3, i64 6, ptr %varargslots15, i64 1) store i64 ptrtoint (ptr @foo.FOO to i64), ptr %err14, align 8 %18 = load i64, ptr %reterr, align 8 store i64 %18, ptr %err19, align 8 %19 = insertvalue %any undef, ptr %err19, 0 - %20 = insertvalue %any %19, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %20 = insertvalue %any %19, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %20, ptr %varargslots20, align 16 %21 = call i64 @std.io.printfn(ptr %retparam21, ptr @.str.4, i64 8, ptr %varargslots20, i64 1) %22 = load i64, ptr %reterr, align 8 diff --git a/test/test_suite/defer/defer_catch_mix.c3t b/test/test_suite/defer/defer_catch_mix.c3t index 745b6d0f9..863e9c094 100644 --- a/test/test_suite/defer/defer_catch_mix.c3t +++ b/test/test_suite/defer/defer_catch_mix.c3t @@ -366,7 +366,7 @@ after_check: ; preds = %match panic_block: ; preds = %assign_optional %18 = insertvalue %any undef, ptr %error_var, 0 - %19 = insertvalue %any %18, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %19 = insertvalue %any %18, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %"char[]" { ptr @.panic_msg.4, i64 36 }, ptr %taddr7, align 8 %20 = load [2 x i64], ptr %taddr7, align 8 store %"char[]" { ptr @.file, i64 16 }, ptr %taddr8, align 8 diff --git a/test/test_suite/defer/defer_catch_try.c3t b/test/test_suite/defer/defer_catch_try.c3t index 54bfbd64a..db4647212 100644 --- a/test/test_suite/defer/defer_catch_try.c3t +++ b/test/test_suite/defer/defer_catch_try.c3t @@ -2,7 +2,7 @@ module test; extern fn void printf(char*, ...); -fault FOO; +faultdef FOO; fn int? abc(int x) { diff --git a/test/test_suite/define/common2.c3 b/test/test_suite/define/common2.c3 index a6a74cd67..16c43314b 100644 --- a/test/test_suite/define/common2.c3 +++ b/test/test_suite/define/common2.c3 @@ -1,6 +1,6 @@ int ofek; const OFKEOK = 2; -distinct Helo = int; +typedef Helo = int; fn void Helo.test(&self) {} alias hupp = Helo.test; diff --git a/test/test_suite/define/forbidden_defines.c3 b/test/test_suite/define/forbidden_defines.c3 index bb94c1252..3f602fba2 100644 --- a/test/test_suite/define/forbidden_defines.c3 +++ b/test/test_suite/define/forbidden_defines.c3 @@ -1,3 +1,3 @@ alias Abc = int[*]; // #error: Inferred array types can only -alias Bcd = anyfault; +alias Bcd = fault; alias Efd = any; diff --git a/test/test_suite/define/test_at.c3 b/test/test_suite/define/test_at.c3 index 04839f7ad..e1ae72061 100644 --- a/test/test_suite/define/test_at.c3 +++ b/test/test_suite/define/test_at.c3 @@ -10,7 +10,7 @@ module bar; import foo @public; -distinct Int = int; +typedef Int = int; macro Int.@test(self) {} alias intHello = foo::@hello{int}; // #error: An at-macro like diff --git a/test/test_suite/define/weak_alias_fails.c3 b/test/test_suite/define/weak_alias_fails.c3 index 0a7641058..d89285ca2 100644 --- a/test/test_suite/define/weak_alias_fails.c3 +++ b/test/test_suite/define/weak_alias_fails.c3 @@ -3,7 +3,7 @@ alias Vec2f = float[<2>]; module abc; import std::math; -alias Vec2f = std::math::vector::Vec2f @weak; +alias Vec2f @weak = std::math::vector::Vec2f; fn Vec2f foo(Vec2f a) { return a * 2; } module gog; @@ -13,7 +13,7 @@ alias Vec2f = std::math::vector::Vec2f; module deef; import gog; -alias Vec2f = gog::Vec2f @weak; +alias Vec2f @weak = gog::Vec2f; fn Vec2f foo(Vec2f a) { return a * 2; } module test; diff --git a/test/test_suite/define/weak_aliases.c3 b/test/test_suite/define/weak_aliases.c3 index 53f007bea..3deacd2c0 100644 --- a/test/test_suite/define/weak_aliases.c3 +++ b/test/test_suite/define/weak_aliases.c3 @@ -3,17 +3,17 @@ alias Vec2f = float[<2>]; module abc; import std::math; -alias Vec2f = std::math::vector::Vec2f @weak; +alias Vec2f @weak = std::math::vector::Vec2f; fn Vec2f foo(Vec2f a) { return a * 2; } module gog; import std::math; -alias Vec2f = std::math::vector::Vec2f @weak; +alias Vec2f @weak = std::math::vector::Vec2f; module deef; import gog; -alias Vec2f = gog::Vec2f @weak; +alias Vec2f @weak = gog::Vec2f; fn Vec2f foo(Vec2f a) { return a * 2; } module test; diff --git a/test/test_suite/distinct/distinct_function.c3t b/test/test_suite/distinct/distinct_function.c3t index 0eb55209a..2d72cae3a 100644 --- a/test/test_suite/distinct/distinct_function.c3t +++ b/test/test_suite/distinct/distinct_function.c3t @@ -1,8 +1,8 @@ module test; alias FnA = fn void(int*); -distinct FnB = FnA; -distinct FnC = inline FnA; +typedef FnB = FnA; +typedef FnC = inline FnA; fn void func(int*) {} diff --git a/test/test_suite/distinct/distinct_function_call.c3 b/test/test_suite/distinct/distinct_function_call.c3 index 06cce91fa..58eeff554 100644 --- a/test/test_suite/distinct/distinct_function_call.c3 +++ b/test/test_suite/distinct/distinct_function_call.c3 @@ -1,5 +1,5 @@ alias Abc = fn void(); -distinct Foo = inline Abc; +typedef Foo = inline Abc; struct Bar { inline Abc a; diff --git a/test/test_suite/distinct/distinct_inline_access.c3 b/test/test_suite/distinct/distinct_inline_access.c3 index 617ff2c63..847d7c12c 100644 --- a/test/test_suite/distinct/distinct_inline_access.c3 +++ b/test/test_suite/distinct/distinct_inline_access.c3 @@ -7,7 +7,7 @@ fn void main() FooInt foo; } -distinct FooInt = inline Foo; +typedef FooInt = inline Foo; struct Bar { diff --git a/test/test_suite/distinct/distinct_invalid.c3 b/test/test_suite/distinct/distinct_invalid.c3 index 7086142ea..d76b42ce0 100644 --- a/test/test_suite/distinct/distinct_invalid.c3 +++ b/test/test_suite/distinct/distinct_invalid.c3 @@ -1,9 +1,9 @@ -fault ABC; +faultdef ABC; -distinct Foo1 = Error; +typedef Foo1 = Error; -distinct Foo3 = void; +typedef Foo3 = void; -distinct Foo4 = typeid; +typedef Foo4 = typeid; -distinct Foo = fn void(Foo** x); // #error: cannot define a new function type \ No newline at end of file +typedef Foo = fn void(Foo** x); // #error: cannot define a new function type \ No newline at end of file diff --git a/test/test_suite/distinct/distinct_max.c3t b/test/test_suite/distinct/distinct_max.c3t index cd48b09e0..505d6e823 100644 --- a/test/test_suite/distinct/distinct_max.c3t +++ b/test/test_suite/distinct/distinct_max.c3t @@ -1,5 +1,5 @@ module test; -distinct Time = long; +typedef Time = long; fn void main(String[] args) { diff --git a/test/test_suite/distinct/distinct_shift.c3t b/test/test_suite/distinct/distinct_shift.c3t index 61fdaeb5a..31516b95c 100644 --- a/test/test_suite/distinct/distinct_shift.c3t +++ b/test/test_suite/distinct/distinct_shift.c3t @@ -4,7 +4,7 @@ import std::io; const ODD_PHI16 @local = 0x9e37; -distinct Lcg16_8 = ushort; +typedef Lcg16_8 = ushort; fn void Lcg16_8.seed(Lcg16_8* lcg, char[2] seed) { diff --git a/test/test_suite/distinct/distinct_slicing.c3 b/test/test_suite/distinct/distinct_slicing.c3 index 0bc172857..cfe5fac2e 100644 --- a/test/test_suite/distinct/distinct_slicing.c3 +++ b/test/test_suite/distinct/distinct_slicing.c3 @@ -1,4 +1,4 @@ -distinct Foo = double[]; +typedef Foo = double[]; fn void main() { diff --git a/test/test_suite/distinct/distinct_struct.c3 b/test/test_suite/distinct/distinct_struct.c3 index 11a18d1f5..767816299 100644 --- a/test/test_suite/distinct/distinct_struct.c3 +++ b/test/test_suite/distinct/distinct_struct.c3 @@ -5,7 +5,7 @@ struct Struct double y; } -distinct Foo = Struct; +typedef Foo = Struct; struct Struct2 { diff --git a/test/test_suite/distinct/distinct_struct_array.c3 b/test/test_suite/distinct/distinct_struct_array.c3 index a8b1dee82..3b1412591 100644 --- a/test/test_suite/distinct/distinct_struct_array.c3 +++ b/test/test_suite/distinct/distinct_struct_array.c3 @@ -1,6 +1,6 @@ module test; -distinct Foo = int; +typedef Foo = int; struct Struct { @@ -8,8 +8,8 @@ struct Struct int y; } -distinct Struct2 = Struct; -distinct StructArr = Struct2[3]; +typedef Struct2 = Struct; +typedef StructArr = Struct2[3]; fn void test(int x) { diff --git a/test/test_suite/distinct/distinct_sub.c3t b/test/test_suite/distinct/distinct_sub.c3t index 3e15c283c..dcb1910a6 100644 --- a/test/test_suite/distinct/distinct_sub.c3t +++ b/test/test_suite/distinct/distinct_sub.c3t @@ -1,4 +1,4 @@ -distinct Foo = uint; +typedef Foo = uint; macro @test($abc) { diff --git a/test/test_suite/distinct/distinct_union.c3 b/test/test_suite/distinct/distinct_union.c3 index 855d509ff..726219f31 100644 --- a/test/test_suite/distinct/distinct_union.c3 +++ b/test/test_suite/distinct/distinct_union.c3 @@ -6,7 +6,7 @@ union Union double y; } -distinct Foo = Union; +typedef Foo = Union; union Union2 { @@ -19,9 +19,9 @@ union Union2 } Foo f = { .x = 1 }; -distinct Union3 = Union2; +typedef Union3 = Union2; -distinct UnionArr = Union3[3]; +typedef UnionArr = Union3[3]; fn void test(int x) { diff --git a/test/test_suite/distinct/test_errors.c3 b/test/test_suite/distinct/test_errors.c3 index c98887c28..7f19fe849 100644 --- a/test/test_suite/distinct/test_errors.c3 +++ b/test/test_suite/distinct/test_errors.c3 @@ -1,6 +1,6 @@ module test; -distinct Int2 = int; +typedef Int2 = int; fn void test() { diff --git a/test/test_suite/distinct/test_ops_on_int.c3 b/test/test_suite/distinct/test_ops_on_int.c3 index 4013b7c92..853195695 100644 --- a/test/test_suite/distinct/test_ops_on_int.c3 +++ b/test/test_suite/distinct/test_ops_on_int.c3 @@ -1,6 +1,6 @@ module test; -distinct Foo = int; +typedef Foo = int; fn int test1() { diff --git a/test/test_suite/distinct/test_ops_on_struct.c3 b/test/test_suite/distinct/test_ops_on_struct.c3 index ddd8255da..64e8088c3 100644 --- a/test/test_suite/distinct/test_ops_on_struct.c3 +++ b/test/test_suite/distinct/test_ops_on_struct.c3 @@ -6,7 +6,7 @@ struct Struct double y; } -distinct Foo = Struct; +typedef Foo = Struct; struct Struct2 { diff --git a/test/test_suite/dynamic/inline_protocol.c3 b/test/test_suite/dynamic/inline_protocol.c3 index 76494b27b..f3f01a4e8 100644 --- a/test/test_suite/dynamic/inline_protocol.c3 +++ b/test/test_suite/dynamic/inline_protocol.c3 @@ -20,7 +20,7 @@ struct Def fn int Abc.foo(&self) @dynamic => 1; -distinct Foob = inline Abc; +typedef Foob = inline Abc; fn void test1() { diff --git a/test/test_suite/enumerations/enum_add_sub.c3t b/test/test_suite/enumerations/enum_add_sub.c3t index 20772f44a..54ab79737 100644 --- a/test/test_suite/enumerations/enum_add_sub.c3t +++ b/test/test_suite/enumerations/enum_add_sub.c3t @@ -4,8 +4,8 @@ enum Foo { ABC } -distinct Abc = inline Foo; -distinct BarInt = int; +typedef Abc = inline Foo; +typedef BarInt = int; enum Bar : BarInt { ABC diff --git a/test/test_suite/enumerations/inc_assign.c3t b/test/test_suite/enumerations/inc_assign.c3t index 88c71105a..60443cbba 100644 --- a/test/test_suite/enumerations/inc_assign.c3t +++ b/test/test_suite/enumerations/inc_assign.c3t @@ -9,7 +9,7 @@ enum Abc OFKEOFK } -distinct Bob = inline Abc; +typedef Bob = inline Abc; fn void main() { Abc y; diff --git a/test/test_suite/enumerations/inc_assign_fail.c3 b/test/test_suite/enumerations/inc_assign_fail.c3 index f31877c7e..b9c76521b 100644 --- a/test/test_suite/enumerations/inc_assign_fail.c3 +++ b/test/test_suite/enumerations/inc_assign_fail.c3 @@ -9,7 +9,7 @@ enum Abc OFKEOFK } -distinct Bob = Abc; +typedef Bob = Abc; fn void main() { Abc y; diff --git a/test/test_suite/errors/anyfault_void.c3t b/test/test_suite/errors/anyfault_void.c3t index 2293cd8d8..e0c9b7f84 100644 --- a/test/test_suite/errors/anyfault_void.c3t +++ b/test/test_suite/errors/anyfault_void.c3t @@ -1,4 +1,4 @@ -fault FOO, BAR; +faultdef FOO, BAR; fn void? errorThing() { @@ -13,7 +13,7 @@ fn void? errorThing2() extern fn void printf(char*, ...); fn void main() { - anyfault z = @catch(errorThing()); + fault z = @catch(errorThing()); printf("Z; %llx\n", (iptr)(z)); printf("BAR: %llx\n", (iptr)(BAR)); printf("FOO: %llx\n", (iptr)(FOO)); diff --git a/test/test_suite/errors/empty_fault.c3 b/test/test_suite/errors/empty_fault.c3 index 08a98a186..19f59d505 100644 --- a/test/test_suite/errors/empty_fault.c3 +++ b/test/test_suite/errors/empty_fault.c3 @@ -1,2 +1,2 @@ module test; -fault; // #error: Expected +faultdef; // #error: Expected diff --git a/test/test_suite/errors/error_decl_ok.c3 b/test/test_suite/errors/error_decl_ok.c3 index f24be2c26..b1f0fa404 100644 --- a/test/test_suite/errors/error_decl_ok.c3 +++ b/test/test_suite/errors/error_decl_ok.c3 @@ -1,9 +1,9 @@ module errors; -fault A; +faultdef A; -fault A2, B2; +faultdef A2, B2; -fault C, D; +faultdef C, D; diff --git a/test/test_suite/errors/error_else.c3t b/test/test_suite/errors/error_else.c3t index 77b8dba67..d3bcf224e 100644 --- a/test/test_suite/errors/error_else.c3t +++ b/test/test_suite/errors/error_else.c3t @@ -1,6 +1,6 @@ module foo; -fault TEST; +faultdef TEST; module bar; import foo; diff --git a/test/test_suite/errors/error_regression_2.c3t b/test/test_suite/errors/error_regression_2.c3t index df2f3ab7c..4e5437951 100644 --- a/test/test_suite/errors/error_regression_2.c3t +++ b/test/test_suite/errors/error_regression_2.c3t @@ -45,7 +45,7 @@ macro dupe(value) return temp; } -fault BAD_READ, OUT_OF_MEMORY; +faultdef BAD_READ, OUT_OF_MEMORY; fn Doc? readDoc(char[] url) { @@ -85,7 +85,7 @@ fn Summary readAndBuildSummary(char[] url) } -fault TITLE_MISSING; +faultdef TITLE_MISSING; fn bool? isTitleNonEmpty(Doc doc) { @@ -105,7 +105,7 @@ fn char* bool_to_string(bool b) { return b ? "true" : "false"; } -fn char* nameFromError(anyfault e) +fn char* nameFromError(fault e) { switch (e) { diff --git a/test/test_suite/errors/error_semantic_fails.c3 b/test/test_suite/errors/error_semantic_fails.c3 index 2352298e4..bd94cd94d 100644 --- a/test/test_suite/errors/error_semantic_fails.c3 +++ b/test/test_suite/errors/error_semantic_fails.c3 @@ -1,4 +1,4 @@ -fault +faultdef A, A // #error: would shadow a previous declaration diff --git a/test/test_suite/errors/error_throw.c3 b/test/test_suite/errors/error_throw.c3 index d80e1ec50..00999b77d 100644 --- a/test/test_suite/errors/error_throw.c3 +++ b/test/test_suite/errors/error_throw.c3 @@ -1,6 +1,6 @@ module foo; -fault Z; +faultdef Z; fn void main() { diff --git a/test/test_suite/errors/error_union.c3 b/test/test_suite/errors/error_union.c3 index d9af8ef5e..8d3be3a2d 100644 --- a/test/test_suite/errors/error_union.c3 +++ b/test/test_suite/errors/error_union.c3 @@ -1,8 +1,8 @@ module foo; -fault X, Y, Z; +faultdef X, Y, Z; fn void main() { - anyfault foo; + fault foo; } \ No newline at end of file diff --git a/test/test_suite/errors/failable_catch.c3t b/test/test_suite/errors/failable_catch.c3t index fab5d84bb..b0323869d 100644 --- a/test/test_suite/errors/failable_catch.c3t +++ b/test/test_suite/errors/failable_catch.c3t @@ -1,6 +1,6 @@ // #target: macos-x64 -fault TEST; +faultdef TEST; macro foo(int x) { diff --git a/test/test_suite/errors/fault_conv.c3t b/test/test_suite/errors/fault_conv.c3t index f4a424cd9..89516399c 100644 --- a/test/test_suite/errors/fault_conv.c3t +++ b/test/test_suite/errors/fault_conv.c3t @@ -2,9 +2,9 @@ module test; import std::io; -fault BAD_STUFF, WORSE_STUFF, THE_WORST_STUFF; +faultdef BAD_STUFF, WORSE_STUFF, THE_WORST_STUFF; -fn int exitcode(anyfault error) +fn int exitcode(fault error) { switch (error) { diff --git a/test/test_suite/errors/general_error_regression.c3t b/test/test_suite/errors/general_error_regression.c3t index a8b10fed6..cdc5c114b 100644 --- a/test/test_suite/errors/general_error_regression.c3t +++ b/test/test_suite/errors/general_error_regression.c3t @@ -2,16 +2,16 @@ module foo; import std::io; import libc; -fault +faultdef X, Y, Z, W, W1; -fault X1, Y2; +faultdef X1, Y2; -distinct Bar = int; +typedef Bar = int; enum MyEnum { @@ -30,9 +30,9 @@ fn void MyEnum.hello(MyEnum *myenum) } fn void main() { - anyfault f = X; - anyfault ef = Y; - anyfault x = f; + fault f = X; + fault ef = Y; + fault x = f; ulong z = (ulong)(x); libc::printf("1: %p\n", z); x = ef; diff --git a/test/test_suite/errors/macro_err2.c3t b/test/test_suite/errors/macro_err2.c3t index adfa40347..091b43ab1 100644 --- a/test/test_suite/errors/macro_err2.c3t +++ b/test/test_suite/errors/macro_err2.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; import libc; -fault FOO; +faultdef FOO; fn int? abc() { diff --git a/test/test_suite/errors/macro_err3.c3t b/test/test_suite/errors/macro_err3.c3t index db3245ee5..13e6a8c54 100644 --- a/test/test_suite/errors/macro_err3.c3t +++ b/test/test_suite/errors/macro_err3.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; import libc; -fault FOO; +faultdef FOO; macro test() diff --git a/test/test_suite/errors/missing_bang.c3 b/test/test_suite/errors/missing_bang.c3 index 5342b4aaf..0ca305638 100644 --- a/test/test_suite/errors/missing_bang.c3 +++ b/test/test_suite/errors/missing_bang.c3 @@ -1,5 +1,5 @@ -fault FOO; +faultdef FOO; fn int? test() { diff --git a/test/test_suite/errors/more_optional_tests.c3 b/test/test_suite/errors/more_optional_tests.c3 index 507634733..c64d36951 100644 --- a/test/test_suite/errors/more_optional_tests.c3 +++ b/test/test_suite/errors/more_optional_tests.c3 @@ -1,6 +1,6 @@ module foo; -fault ABC; +faultdef ABC; fn void test() { diff --git a/test/test_suite/errors/multiple_catch.c3t b/test/test_suite/errors/multiple_catch.c3t index c690aa2f8..e9bac5db4 100644 --- a/test/test_suite/errors/multiple_catch.c3t +++ b/test/test_suite/errors/multiple_catch.c3t @@ -3,7 +3,7 @@ module demo1; import std::io; -fault ABC, DEF; +faultdef ABC, DEF; fn int? hello(int a) { @@ -30,7 +30,7 @@ fn void main() { io::printn("3 Ok"); } - if (catch anyfault err = hello(0), bye()) + if (catch fault err = hello(0), bye()) { io::printfn("4 Got %s", err); } @@ -95,7 +95,7 @@ end_block: ; preds = %after_check4, %assi if.then: ; preds = %end_block %5 = insertvalue %any undef, ptr %err, 0 - %6 = insertvalue %any %5, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %6 = insertvalue %any %5, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %6, ptr %varargslots, align 16 %7 = call i64 @std.io.printfn(ptr %retparam5, ptr @.str.2, i64 8, ptr %varargslots, i64 1) br label %if.exit @@ -137,7 +137,7 @@ end_block18: ; preds = %after_check17, %ass if.then20: ; preds = %end_block18 %13 = insertvalue %any undef, ptr %err8, 0 - %14 = insertvalue %any %13, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %14 = insertvalue %any %13, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %14, ptr %varargslots21, align 16 %15 = call i64 @std.io.printfn(ptr %retparam22, ptr @.str.3, i64 8, ptr %varargslots21, i64 1) br label %if.exit25 @@ -273,7 +273,7 @@ end_block66: ; preds = %after_check65, %ass if.then68: ; preds = %end_block66 %35 = insertvalue %any undef, ptr %err56, 0 - %36 = insertvalue %any %35, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %36 = insertvalue %any %35, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %36, ptr %varargslots69, align 16 %37 = call i64 @std.io.printfn(ptr %retparam70, ptr @.str.5, i64 8, ptr %varargslots69, i64 1) br label %if.exit73 diff --git a/test/test_suite/errors/optional_chained_init.c3t b/test/test_suite/errors/optional_chained_init.c3t index dbd8b855e..1ea4b3fbd 100644 --- a/test/test_suite/errors/optional_chained_init.c3t +++ b/test/test_suite/errors/optional_chained_init.c3t @@ -2,7 +2,7 @@ module test; import std::io; -fault FOO; +faultdef FOO; fn void test1() { @@ -92,7 +92,7 @@ end_block: ; preds = %after_check, %assig if.then: ; preds = %end_block %2 = insertvalue %any undef, ptr %err, 0 - %3 = insertvalue %any %2, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %3 = insertvalue %any %2, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %3, ptr %varargslots, align 16 %4 = call i64 @std.io.printfn(ptr %retparam, ptr @.str, i64 13, ptr %varargslots, i64 1) br label %if.exit @@ -121,7 +121,7 @@ end_block9: ; preds = %after_check8, %assi if.then11: ; preds = %end_block9 %7 = insertvalue %any undef, ptr %err3, 0 - %8 = insertvalue %any %7, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %8 = insertvalue %any %7, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %8, ptr %varargslots12, align 16 %9 = call i64 @std.io.printfn(ptr %retparam13, ptr @.str.1, i64 13, ptr %varargslots12, i64 1) br label %if.exit16 @@ -231,7 +231,7 @@ end_block: ; preds = %after_check5, %assi if.then: ; preds = %end_block %4 = insertvalue %any undef, ptr %err, 0 - %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %5, ptr %varargslots, align 16 %6 = call i64 @std.io.printfn(ptr %retparam, ptr @.str.4, i64 13, ptr %varargslots, i64 1) br label %if.exit @@ -260,7 +260,7 @@ end_block14: ; preds = %after_check13, %ass if.then16: ; preds = %end_block14 %9 = insertvalue %any undef, ptr %err8, 0 - %10 = insertvalue %any %9, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %10 = insertvalue %any %9, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %10, ptr %varargslots17, align 16 %11 = call i64 @std.io.printfn(ptr %retparam18, ptr @.str.5, i64 13, ptr %varargslots17, i64 1) br label %if.exit21 @@ -371,7 +371,7 @@ end_block: ; preds = %after_check5, %assi if.then: ; preds = %end_block %4 = insertvalue %any undef, ptr %err, 0 - %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %5, ptr %varargslots, align 16 %6 = call i64 @std.io.printfn(ptr %retparam, ptr @.str.8, i64 13, ptr %varargslots, i64 1) br label %if.exit @@ -400,7 +400,7 @@ end_block14: ; preds = %after_check13, %ass if.then16: ; preds = %end_block14 %9 = insertvalue %any undef, ptr %err8, 0 - %10 = insertvalue %any %9, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %10 = insertvalue %any %9, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %10, ptr %varargslots17, align 16 %11 = call i64 @std.io.printfn(ptr %retparam18, ptr @.str.9, i64 13, ptr %varargslots17, i64 1) br label %if.exit21 diff --git a/test/test_suite/errors/optional_contracts.c3 b/test/test_suite/errors/optional_contracts.c3 index 1c89ed6a3..812472594 100644 --- a/test/test_suite/errors/optional_contracts.c3 +++ b/test/test_suite/errors/optional_contracts.c3 @@ -1,10 +1,10 @@ -fault +faultdef ABC, DEF, ZED; -fault XYZ; +faultdef XYZ; <* hello world diff --git a/test/test_suite/errors/optional_inits.c3t b/test/test_suite/errors/optional_inits.c3t index 727649808..7d0fc9425 100644 --- a/test/test_suite/errors/optional_inits.c3t +++ b/test/test_suite/errors/optional_inits.c3t @@ -2,7 +2,7 @@ module test; import std::io; -fault MY_VAL1, MY_VAL2; +faultdef MY_VAL1, MY_VAL2; struct Bar { diff --git a/test/test_suite/errors/optional_taddr_and_access.c3t b/test/test_suite/errors/optional_taddr_and_access.c3t index 397da6838..adc082ad7 100644 --- a/test/test_suite/errors/optional_taddr_and_access.c3t +++ b/test/test_suite/errors/optional_taddr_and_access.c3t @@ -6,7 +6,7 @@ struct Foo int x, y; } -fault FOO; +faultdef FOO; extern fn int printf(char *c, ...); diff --git a/test/test_suite/errors/optional_untyped_list.c3 b/test/test_suite/errors/optional_untyped_list.c3 index 7b53e4b54..dc4bee854 100644 --- a/test/test_suite/errors/optional_untyped_list.c3 +++ b/test/test_suite/errors/optional_untyped_list.c3 @@ -4,7 +4,7 @@ struct Foo int x, y; } -fault FOO; +faultdef FOO; extern fn int printf(char *c, ...); diff --git a/test/test_suite/errors/optional_with_optional.c3t b/test/test_suite/errors/optional_with_optional.c3t index 187db6110..e4e4d321b 100644 --- a/test/test_suite/errors/optional_with_optional.c3t +++ b/test/test_suite/errors/optional_with_optional.c3t @@ -2,7 +2,7 @@ module test; import std::io; -fault ABC, DEF; +faultdef ABC, DEF; fn void main() { @@ -190,7 +190,7 @@ if.exit: ; preds = %end_block expr_block.exit: ; preds = %if.exit, %if.then %29 = insertvalue %any undef, ptr %blockret, 0 - %30 = insertvalue %any %29, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %30 = insertvalue %any %29, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %30, ptr %varargslots44, align 16 %31 = call i64 @std.io.printfn(ptr %retparam45, ptr @.str.3, i64 4, ptr %varargslots44, i64 1) store i32 3, ptr %taddr49, align 4 @@ -220,7 +220,7 @@ if.exit60: ; preds = %end_block57 expr_block.exit61: ; preds = %if.exit60, %if.then59 %37 = insertvalue %any undef, ptr %blockret54, 0 - %38 = insertvalue %any %37, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %38 = insertvalue %any %37, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %38, ptr %varargslots53, align 16 %39 = call i64 @std.io.printfn(ptr %retparam62, ptr @.str.5, i64 4, ptr %varargslots53, i64 1) br label %testblock68 @@ -248,7 +248,7 @@ if.exit74: ; preds = %end_block71 expr_block.exit75: ; preds = %if.exit74, %if.then73 %42 = insertvalue %any undef, ptr %blockret66, 0 - %43 = insertvalue %any %42, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %43 = insertvalue %any %42, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %43, ptr %varargslots65, align 16 %44 = call i64 @std.io.printfn(ptr %retparam76, ptr @.str.6, i64 4, ptr %varargslots65, i64 1) store i64 3, ptr %x, align 8 diff --git a/test/test_suite/errors/or_and_rethrow.c3t b/test/test_suite/errors/or_and_rethrow.c3t index 37d5de2b1..4923a4a2a 100644 --- a/test/test_suite/errors/or_and_rethrow.c3t +++ b/test/test_suite/errors/or_and_rethrow.c3t @@ -2,7 +2,7 @@ module foo; import std::io; -fault ABC; +faultdef ABC; fn void blurb() { io::printn("Blurb");} @@ -31,10 +31,10 @@ fn void? test2(int x) fn void main() { - anyfault a = @catch(test(0)); - anyfault b = @catch(test(1)); - anyfault c = @catch(test2(0)); - anyfault d = @catch(test2(1)); + fault a = @catch(test(0)); + fault b = @catch(test(1)); + fault c = @catch(test2(0)); + fault d = @catch(test2(1)); } /* #expect: foo.ll diff --git a/test/test_suite/errors/or_and_rethrow_missing_question.c3 b/test/test_suite/errors/or_and_rethrow_missing_question.c3 index d0f8ce373..2a45552d5 100644 --- a/test/test_suite/errors/or_and_rethrow_missing_question.c3 +++ b/test/test_suite/errors/or_and_rethrow_missing_question.c3 @@ -1,5 +1,5 @@ module faults; -fault +faultdef EXAMPLE, DOG_ATE_MY_HOMEWORK, MY_TEXTBOOK_CAUGHT_FIRE, diff --git a/test/test_suite/errors/printing_errors.c3t b/test/test_suite/errors/printing_errors.c3t index a91a50353..742f63637 100644 --- a/test/test_suite/errors/printing_errors.c3t +++ b/test/test_suite/errors/printing_errors.c3t @@ -2,10 +2,10 @@ module test; import std::io; -fault HELLO, WORLD; +faultdef HELLO, WORLD; fn void main() { - anyfault x = WORLD; + fault x = WORLD; io::printf("%s %s\n", HELLO.nameof, x.nameof); } diff --git a/test/test_suite/errors/simple_static_failable.c3t b/test/test_suite/errors/simple_static_failable.c3t index 313b0ba21..bfa09fac8 100644 --- a/test/test_suite/errors/simple_static_failable.c3t +++ b/test/test_suite/errors/simple_static_failable.c3t @@ -2,7 +2,7 @@ module foo; -fault Y; +faultdef Y; fn void main() { diff --git a/test/test_suite/errors/try_assign.c3t b/test/test_suite/errors/try_assign.c3t index fba1f22ab..916953b86 100644 --- a/test/test_suite/errors/try_assign.c3t +++ b/test/test_suite/errors/try_assign.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 extern fn int? err(); -fault QBERT; +faultdef QBERT; extern fn int printf(char* fmt, ...); fn void main() diff --git a/test/test_suite/errors/try_catch_if.c3t b/test/test_suite/errors/try_catch_if.c3t index 86b8b0cb0..8ba8f48b2 100644 --- a/test/test_suite/errors/try_catch_if.c3t +++ b/test/test_suite/errors/try_catch_if.c3t @@ -13,7 +13,7 @@ fn int? tester() return 222; } -fault A; +faultdef A; fn void test1() { diff --git a/test/test_suite/errors/try_catch_unwrapping_while_if.c3 b/test/test_suite/errors/try_catch_unwrapping_while_if.c3 index 20fb8909c..51d6209bd 100644 --- a/test/test_suite/errors/try_catch_unwrapping_while_if.c3 +++ b/test/test_suite/errors/try_catch_unwrapping_while_if.c3 @@ -1,7 +1,7 @@ extern fn int printf(char* fmt, ...); extern fn int? err(); -fault X; +faultdef X; fn void test1() { diff --git a/test/test_suite/errors/try_with_unwrapper.c3t b/test/test_suite/errors/try_with_unwrapper.c3t index 833d0b803..57363f10e 100644 --- a/test/test_suite/errors/try_with_unwrapper.c3t +++ b/test/test_suite/errors/try_with_unwrapper.c3t @@ -13,7 +13,7 @@ fn int? tester() return 222; } -fault A; +faultdef A; fn void test1() { diff --git a/test/test_suite/expressions/addr_of_fails.c3 b/test/test_suite/expressions/addr_of_fails.c3 index 7284fe3e2..9c3b3dd09 100644 --- a/test/test_suite/expressions/addr_of_fails.c3 +++ b/test/test_suite/expressions/addr_of_fails.c3 @@ -61,8 +61,8 @@ fn void test6() } alias Baz = Foo; -distinct Bar = int; -fault FOO; +typedef Bar = int; +faultdef FOO; union Un { int x; } enum MyEnum { BAR } diff --git a/test/test_suite/expressions/assign_optional.c3t b/test/test_suite/expressions/assign_optional.c3t index 4a2de4837..2ba88671b 100644 --- a/test/test_suite/expressions/assign_optional.c3t +++ b/test/test_suite/expressions/assign_optional.c3t @@ -3,7 +3,7 @@ module test; fn void main() { - anyfault x = NOT_FOUND; + fault x = NOT_FOUND; int? a = x?; int? b = a = x?; int? c = b = a; diff --git a/test/test_suite/expressions/casts/cast_enum_const_to_distinct.c3 b/test/test_suite/expressions/casts/cast_enum_const_to_distinct.c3 index 3d2b4fd8a..6a6b0e487 100644 --- a/test/test_suite/expressions/casts/cast_enum_const_to_distinct.c3 +++ b/test/test_suite/expressions/casts/cast_enum_const_to_distinct.c3 @@ -2,7 +2,7 @@ enum Foo { ABC } -distinct Abc = int; +typedef Abc = int; fn void main() { Abc d = Foo.ABC; // #error: to 'Abc' diff --git a/test/test_suite/expressions/casts/cast_failable.c3 b/test/test_suite/expressions/casts/cast_failable.c3 index bb8a1cb86..07ff36bcd 100644 --- a/test/test_suite/expressions/casts/cast_failable.c3 +++ b/test/test_suite/expressions/casts/cast_failable.c3 @@ -1,4 +1,4 @@ -fault FOO; +faultdef FOO; fn void test() { diff --git a/test/test_suite/expressions/casts/cast_implicit_inline_distinct.c3 b/test/test_suite/expressions/casts/cast_implicit_inline_distinct.c3 index 7dce84d2b..9f2bcb82d 100644 --- a/test/test_suite/expressions/casts/cast_implicit_inline_distinct.c3 +++ b/test/test_suite/expressions/casts/cast_implicit_inline_distinct.c3 @@ -1,5 +1,5 @@ -distinct DistinctInt = inline int; -distinct DistinctInt2 = inline DistinctInt; +typedef DistinctInt = inline int; +typedef DistinctInt2 = inline DistinctInt; fn void test() { diff --git a/test/test_suite/expressions/casts/explicit_cast.c3 b/test/test_suite/expressions/casts/explicit_cast.c3 index f77ba8cec..29e6140ee 100644 --- a/test/test_suite/expressions/casts/explicit_cast.c3 +++ b/test/test_suite/expressions/casts/explicit_cast.c3 @@ -1,6 +1,6 @@ alias Number8 = char; alias Number32 = int; -distinct DNumber32 = int; +typedef DNumber32 = int; fn void test1() { int a = (ichar)(10); diff --git a/test/test_suite/expressions/casts/failed_distinct_float_conversions.c3 b/test/test_suite/expressions/casts/failed_distinct_float_conversions.c3 index ba1d99002..d458d0be5 100644 --- a/test/test_suite/expressions/casts/failed_distinct_float_conversions.c3 +++ b/test/test_suite/expressions/casts/failed_distinct_float_conversions.c3 @@ -1,5 +1,5 @@ -distinct Foo = double; -distinct Bar = void*; +typedef Foo = double; +typedef Bar = void*; fn int main() { float f = 1; diff --git a/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 b/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 index c18c228fc..040a4e36c 100644 --- a/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 +++ b/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 @@ -1,6 +1,6 @@ module test; -distinct Foo = int; +typedef Foo = int; fn void test1() { diff --git a/test/test_suite/expressions/casts/void_casting.c3t b/test/test_suite/expressions/casts/void_casting.c3t index 0680e36ca..eb0dfad43 100644 --- a/test/test_suite/expressions/casts/void_casting.c3t +++ b/test/test_suite/expressions/casts/void_casting.c3t @@ -4,7 +4,7 @@ module test; fn void? foo() {} -fault AAA; +faultdef AAA; macro int? bar() { diff --git a/test/test_suite/expressions/chained_ternary.c3t b/test/test_suite/expressions/chained_ternary.c3t index 99f1c1f9a..f5b269ae3 100644 --- a/test/test_suite/expressions/chained_ternary.c3t +++ b/test/test_suite/expressions/chained_ternary.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; -fault FOO, BAR; +faultdef FOO, BAR; fn void test() { diff --git a/test/test_suite/expressions/enum_ct_sub.c3t b/test/test_suite/expressions/enum_ct_sub.c3t index 9a20d46c8..806be819b 100644 --- a/test/test_suite/expressions/enum_ct_sub.c3t +++ b/test/test_suite/expressions/enum_ct_sub.c3t @@ -3,7 +3,7 @@ enum Foo : char ABC, BCD } -distinct Abc = int; +typedef Abc = int; fn void main() { $assert Foo.BCD - 1 == Foo.ABC; diff --git a/test/test_suite/expressions/optional_ternary.c3t b/test/test_suite/expressions/optional_ternary.c3t index 76746daeb..40f5cc114 100644 --- a/test/test_suite/expressions/optional_ternary.c3t +++ b/test/test_suite/expressions/optional_ternary.c3t @@ -2,7 +2,7 @@ module test; -fault X; +faultdef X; fn int? test(int i) { diff --git a/test/test_suite/from_docs/examples_if_catch.c3t b/test/test_suite/from_docs/examples_if_catch.c3t index 92111cd61..a52ba6e88 100644 --- a/test/test_suite/from_docs/examples_if_catch.c3t +++ b/test/test_suite/from_docs/examples_if_catch.c3t @@ -3,7 +3,7 @@ module demo; import libc; import std::io; -fault DIVISION_BY_ZERO; +faultdef DIVISION_BY_ZERO; fn int foo() { return 123; } fn int bar() { return 0; } diff --git a/test/test_suite/functions/c_vararg_expansion.c3t b/test/test_suite/functions/c_vararg_expansion.c3t index 6627c42a8..102f12dfa 100644 --- a/test/test_suite/functions/c_vararg_expansion.c3t +++ b/test/test_suite/functions/c_vararg_expansion.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; extern fn void printf(char*,...); -distinct Foo = float; +typedef Foo = float; fn void main() { Foo a = 12.3; diff --git a/test/test_suite/functions/default_param_fail.c3 b/test/test_suite/functions/default_param_fail.c3 index d64e1a040..240f32330 100644 --- a/test/test_suite/functions/default_param_fail.c3 +++ b/test/test_suite/functions/default_param_fail.c3 @@ -1,7 +1,7 @@ int z; -fault FOO; +faultdef FOO; fn void test(int a = z) {} diff --git a/test/test_suite/functions/distinct_fn_ptr_and_lambda.c3t b/test/test_suite/functions/distinct_fn_ptr_and_lambda.c3t index 18fca77af..81e78d3f1 100644 --- a/test/test_suite/functions/distinct_fn_ptr_and_lambda.c3t +++ b/test/test_suite/functions/distinct_fn_ptr_and_lambda.c3t @@ -1,6 +1,6 @@ alias Foo = fn void(int x); -distinct Bar = Foo; +typedef Bar = Foo; fn void main() { diff --git a/test/test_suite/functions/test_regression.c3t b/test/test_suite/functions/test_regression.c3t index 1fc24c33a..fa8cb2fab 100644 --- a/test/test_suite/functions/test_regression.c3t +++ b/test/test_suite/functions/test_regression.c3t @@ -201,7 +201,7 @@ fn Type getMult(Type a) } Type argh = 234; -fault X, Y; +faultdef X, Y; enum Hello : int { diff --git a/test/test_suite/functions/test_regression_mingw.c3t b/test/test_suite/functions/test_regression_mingw.c3t index 1527c3a47..88a22e912 100644 --- a/test/test_suite/functions/test_regression_mingw.c3t +++ b/test/test_suite/functions/test_regression_mingw.c3t @@ -203,7 +203,7 @@ fn Type getMult(Type a) } Type argh = 234; -fault X, Y; +faultdef X, Y; enum Hello : int { diff --git a/test/test_suite/generic/generic_lambda_complex.c3t b/test/test_suite/generic/generic_lambda_complex.c3t index acc92fac0..0a514dbdb 100644 --- a/test/test_suite/generic/generic_lambda_complex.c3t +++ b/test/test_suite/generic/generic_lambda_complex.c3t @@ -7,7 +7,7 @@ import std::collections::list; alias TextTagList = List{TextTag}; -fault UNTERMINATED_TAG, EMPTY_TAG, MISSING_TAG, UNSUPPORTED_TAG; +faultdef UNTERMINATED_TAG, EMPTY_TAG, MISSING_TAG, UNSUPPORTED_TAG; enum TextTagKind: char { @@ -210,7 +210,7 @@ after_check: ; preds = %if.exit panic_block: ; preds = %assign_optional %6 = insertvalue %any undef, ptr %error_var, 0 - %7 = insertvalue %any %6, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %7 = insertvalue %any %6, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %7, ptr %varargslots, align 16 %8 = insertvalue %"any[]" undef, ptr %varargslots, 0 %"$$temp" = insertvalue %"any[]" %8, i64 1, 1 @@ -233,7 +233,7 @@ after_check6: ; preds = %noerr_block panic_block7: ; preds = %assign_optional5 %11 = insertvalue %any undef, ptr %error_var3, 0 - %12 = insertvalue %any %11, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %12 = insertvalue %any %11, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %12, ptr %varargslots8, align 16 %13 = insertvalue %"any[]" undef, ptr %varargslots8, 0 %"$$temp9" = insertvalue %"any[]" %13, i64 1, 1 diff --git a/test/test_suite/generic/generic_local.c3 b/test/test_suite/generic/generic_local.c3 index 4595c15e1..1e8cdcbc9 100644 --- a/test/test_suite/generic/generic_local.c3 +++ b/test/test_suite/generic/generic_local.c3 @@ -13,7 +13,7 @@ module foo; import foo::private; // Bug #856 -distinct Foo = inline PrivateFoo{int}; // #error: could not be found +typedef Foo = inline PrivateFoo{int}; // #error: could not be found module foo::private{Type} @local; diff --git a/test/test_suite/generic/nested_typedef.c3t b/test/test_suite/generic/nested_typedef.c3t index 718dd864a..5d3e7459a 100644 --- a/test/test_suite/generic/nested_typedef.c3t +++ b/test/test_suite/generic/nested_typedef.c3t @@ -1,6 +1,6 @@ // #target: macos-x64 module broken{Type}; -distinct Bar = Type; +typedef Bar = Type; alias Bar2 = Type; struct Baz { diff --git a/test/test_suite/globals/init_with_err.c3t b/test/test_suite/globals/init_with_err.c3t index ef108bf95..7fcd4a2ef 100644 --- a/test/test_suite/globals/init_with_err.c3t +++ b/test/test_suite/globals/init_with_err.c3t @@ -2,7 +2,7 @@ module test; import std::io; -fault FOO; +faultdef FOO; const String? ABC = FOO?; String? abc = FOO?; const String? DEF = ABC; diff --git a/test/test_suite/macros/macro_failable_return_rethrow.c3t b/test/test_suite/macros/macro_failable_return_rethrow.c3t index c23622d08..98266b740 100644 --- a/test/test_suite/macros/macro_failable_return_rethrow.c3t +++ b/test/test_suite/macros/macro_failable_return_rethrow.c3t @@ -45,7 +45,7 @@ noerr_block: ; preds = %after_check panic_block: ; preds = %guard_block %3 = insertvalue %any undef, ptr %error_var, 0 - %4 = insertvalue %any %3, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %4 = insertvalue %any %3, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %4, ptr %varargslots, align 16 %5 = insertvalue %"any[]" undef, ptr %varargslots, 0 %"$$temp" = insertvalue %"any[]" %5, i64 1, 1 diff --git a/test/test_suite/macros/unifying_implicit_void.c3t b/test/test_suite/macros/unifying_implicit_void.c3t index 7f09c91ae..e0973b8b6 100644 --- a/test/test_suite/macros/unifying_implicit_void.c3t +++ b/test/test_suite/macros/unifying_implicit_void.c3t @@ -103,7 +103,7 @@ if.exit: ; preds = %end_block br label %noerr_block panic_block: ; preds = %if.then %17 = insertvalue %any undef, ptr %error_var, 0 - %18 = insertvalue %any %17, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %18 = insertvalue %any %17, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %18, ptr %varargslots, align 16 %19 = insertvalue %"any[]" undef, ptr %varargslots, 0 %"$$temp" = insertvalue %"any[]" %19, i64 1, 1 diff --git a/test/test_suite/methods/distinct_arr_method_resolution.c3 b/test/test_suite/methods/distinct_arr_method_resolution.c3 index 05573c744..f0c64095c 100644 --- a/test/test_suite/methods/distinct_arr_method_resolution.c3 +++ b/test/test_suite/methods/distinct_arr_method_resolution.c3 @@ -1,6 +1,6 @@ module abc; -distinct Foo = int; -distinct Bar = int; +typedef Foo = int; +typedef Bar = int; fn void Foo[2].foo(&self) {} // Same with: macro Bar[2].bar(&self) {} diff --git a/test/test_suite/methods/enum_distinct_err_methods.c3t b/test/test_suite/methods/enum_distinct_err_methods.c3t index 2a47d2a10..2be59ad4f 100644 --- a/test/test_suite/methods/enum_distinct_err_methods.c3t +++ b/test/test_suite/methods/enum_distinct_err_methods.c3t @@ -3,9 +3,9 @@ module foo; import std::io; -fault X; +faultdef X; -distinct Bar = int; +typedef Bar = int; enum MyEnum { diff --git a/test/test_suite/methods/methods_with_inferred_type.c3t b/test/test_suite/methods/methods_with_inferred_type.c3t index 5e38793d8..74121da71 100644 --- a/test/test_suite/methods/methods_with_inferred_type.c3t +++ b/test/test_suite/methods/methods_with_inferred_type.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; -distinct Foo = int; +typedef Foo = int; struct Abc { diff --git a/test/test_suite/methods/operator_defined_twice.c3 b/test/test_suite/methods/operator_defined_twice.c3 index 9720ec498..37decf6b6 100644 --- a/test/test_suite/methods/operator_defined_twice.c3 +++ b/test/test_suite/methods/operator_defined_twice.c3 @@ -1,4 +1,4 @@ -distinct Foo = int; +typedef Foo = int; fn int Foo.fadd(&self, int x) @operator([]) { return 1; } fn int Foo.badd(&self, int x) @operator([]) { return 1; } // #error: This operator is already defined diff --git a/test/test_suite/methods/self_methods_null.c3t b/test/test_suite/methods/self_methods_null.c3t index 80819d3c4..3c204c64d 100644 --- a/test/test_suite/methods/self_methods_null.c3t +++ b/test/test_suite/methods/self_methods_null.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 // #safe: yes module test; -distinct Foo = int; +typedef Foo = int; fn void Foo.test(&self) {} fn int main() { diff --git a/test/test_suite/statements/for_with_optional.c3t b/test/test_suite/statements/for_with_optional.c3t index 12684b438..5790c7119 100644 --- a/test/test_suite/statements/for_with_optional.c3t +++ b/test/test_suite/statements/for_with_optional.c3t @@ -100,7 +100,7 @@ after_check3: ; preds = %loop.cond br label %noerr_block panic_block: ; preds = %assign_optional %4 = insertvalue %any undef, ptr %error_var, 0 - %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.anyfault" to i64), 1 + %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.fault" to i64), 1 store %any %5, ptr %varargslots, align 16 %6 = insertvalue %"any[]" undef, ptr %varargslots, 0 %"$$temp" = insertvalue %"any[]" %6, i64 1, 1 diff --git a/test/test_suite/statements/foreach_custom_errors.c3 b/test/test_suite/statements/foreach_custom_errors.c3 index 08c581ab9..512689856 100644 --- a/test/test_suite/statements/foreach_custom_errors.c3 +++ b/test/test_suite/statements/foreach_custom_errors.c3 @@ -4,7 +4,7 @@ fn void test1() foreach (a : x) { }; // #error: It's not possible to enumerate an expression of type 'int' } -distinct Test1 = int; +typedef Test1 = int; fn void test2() { diff --git a/test/test_suite/statements/foreach_distinct_iterable.c3t b/test/test_suite/statements/foreach_distinct_iterable.c3t index c69667fdb..9ace98afb 100644 --- a/test/test_suite/statements/foreach_distinct_iterable.c3t +++ b/test/test_suite/statements/foreach_distinct_iterable.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; import std; -distinct TypeA = char[]; +typedef TypeA = char[]; fn char TypeA.get(self, usz i) @operator([]) { return ((char[])self)[i]; diff --git a/test/test_suite/statements/foreach_distinct_pointer_1506.c3 b/test/test_suite/statements/foreach_distinct_pointer_1506.c3 index 5e6c2d262..bd30044be 100644 --- a/test/test_suite/statements/foreach_distinct_pointer_1506.c3 +++ b/test/test_suite/statements/foreach_distinct_pointer_1506.c3 @@ -1,4 +1,4 @@ -distinct Type = char*; +typedef Type = char*; fn usz Type.len(str) { return 0; diff --git a/test/test_suite/statements/foreach_r_custom_errors.c3 b/test/test_suite/statements/foreach_r_custom_errors.c3 index 1ef972b44..029e2d4dd 100644 --- a/test/test_suite/statements/foreach_r_custom_errors.c3 +++ b/test/test_suite/statements/foreach_r_custom_errors.c3 @@ -4,7 +4,7 @@ fn void test1() foreach_r (a : x) { }; // #error: It's not possible to enumerate an expression of type 'int' } -distinct Test1 = int; +typedef Test1 = int; fn void test2() { diff --git a/test/test_suite/statements/if_only_throw.c3t b/test/test_suite/statements/if_only_throw.c3t index b755219c6..268434d27 100644 --- a/test/test_suite/statements/if_only_throw.c3t +++ b/test/test_suite/statements/if_only_throw.c3t @@ -2,7 +2,7 @@ module foo; import std::io; -fault ABC; +faultdef ABC; fn void? test() { diff --git a/test/test_suite/statements/switch_errors.c3 b/test/test_suite/statements/switch_errors.c3 index ace0cd4bc..895c9ccb0 100644 --- a/test/test_suite/statements/switch_errors.c3 +++ b/test/test_suite/statements/switch_errors.c3 @@ -135,7 +135,7 @@ fn void test_missing_no_cases(Baz x) } } -fault DIVISION_BY_ZERO; +faultdef DIVISION_BY_ZERO; // Rethrowing an error uses "!!" suffix fn void? testMayError() diff --git a/test/test_suite/statements/various_switching.c3t b/test/test_suite/statements/various_switching.c3t index 8c398c6cd..6092e3cd4 100644 --- a/test/test_suite/statements/various_switching.c3t +++ b/test/test_suite/statements/various_switching.c3t @@ -3,8 +3,8 @@ module mymodule; extern fn void printf(char *, ...); -fault FOO; -fault BAR, BAZ; +faultdef FOO; +faultdef BAR, BAZ; fn void test() { diff --git a/test/test_suite/struct/struct_bad_member.c3 b/test/test_suite/struct/struct_bad_member.c3 index 762832436..d32b70691 100644 --- a/test/test_suite/struct/struct_bad_member.c3 +++ b/test/test_suite/struct/struct_bad_member.c3 @@ -7,7 +7,7 @@ struct Foo2 { Void bar; // #error: Members cannot be of } -distinct Void2 = void; +typedef Void2 = void; struct Foo3 { Void2 bar; // #error: has unknown size } diff --git a/test/test_suite/switch/failable_switch.c3 b/test/test_suite/switch/failable_switch.c3 index 379c78687..e6c4386d0 100644 --- a/test/test_suite/switch/failable_switch.c3 +++ b/test/test_suite/switch/failable_switch.c3 @@ -1,4 +1,4 @@ -fault FOO; +faultdef FOO; fn void test() { diff --git a/test/test_suite/switch/switch_in_defer_macro.c3t b/test/test_suite/switch/switch_in_defer_macro.c3t index b8605f315..866f0c355 100644 --- a/test/test_suite/switch/switch_in_defer_macro.c3t +++ b/test/test_suite/switch/switch_in_defer_macro.c3t @@ -19,7 +19,7 @@ enum Kind : char IDENTIFIER, } -fault UNTERMINATED_STRING, UNTERMINATED_RUNE, UNTERMINATED_COMMENT; +faultdef UNTERMINATED_STRING, UNTERMINATED_RUNE, UNTERMINATED_COMMENT; alias TokenTrie = Trie{Token, ushort}; @@ -126,7 +126,7 @@ fn Kind? Lexer.peek(&self) return self.kind; } -fn Token? Lexer.expect(&self, anyfault err, Token... tokens) +fn Token? Lexer.expect(&self, fault err, Token... tokens) { Kind kind = self.next()!; if (kind == TOKEN) @@ -457,9 +457,9 @@ import std::collections::list; import trie::bitmap; alias TrieNodeList = List{TrieNode}; -alias TriePath = List{Index} @private; +alias TriePath @private = List{Index}; -fault TRIE_FULL; +faultdef TRIE_FULL; struct Trie { diff --git a/test/unit/regression/catch_err.c3 b/test/unit/regression/catch_err.c3 index bbc9eaf4d..ceabdc3ad 100644 --- a/test/unit/regression/catch_err.c3 +++ b/test/unit/regression/catch_err.c3 @@ -2,16 +2,16 @@ module catch_err @test; fn void test() { - anyfault a; - int? z = fn int?(anyfault* a) { + fault a; + int? z = fn int?(fault* a) { const ABC = 4; int? x = NOT_FOUND?; defer (catch err) *a = err; return x; }(&a); assert(a == NOT_FOUND); - anyfault y; - z = fn int?(anyfault* y) { + fault y; + z = fn int?(fault* y) { const ABC = 4; int? x = 1; defer (catch err) *y = err; diff --git a/test/unit/regression/distinct_inline.c3 b/test/unit/regression/distinct_inline.c3 index 85d5d0332..aab1a339e 100644 --- a/test/unit/regression/distinct_inline.c3 +++ b/test/unit/regression/distinct_inline.c3 @@ -1,12 +1,12 @@ module distinct_inline @test; -distinct Foo = inline int; -distinct Bar = inline Foo; -distinct Baz = inline Foo; -distinct Abc = inline Baz; -distinct Def = inline Abc; -distinct Other = inline int; -distinct Other2 = inline Other; +typedef Foo = inline int; +typedef Bar = inline Foo; +typedef Baz = inline Foo; +typedef Abc = inline Baz; +typedef Def = inline Abc; +typedef Other = inline int; +typedef Other2 = inline Other; fn void test_binary() { assert($typeof((Foo)1 + 1).typeid == Foo.typeid); @@ -16,8 +16,8 @@ fn void test_binary() assert($typeof((Other2)1 + (Def)1).typeid == int.typeid); } -distinct DistinctInt = inline int; -distinct DistinctUInt = inline uint; +typedef DistinctInt = inline int; +typedef DistinctUInt = inline uint; fn void test_comparison() { diff --git a/test/unit/stdlib/core/test_test.c3 b/test/unit/stdlib/core/test_test.c3 index fd837d214..6fdc5328c 100644 --- a/test/unit/stdlib/core/test_test.c3 +++ b/test/unit/stdlib/core/test_test.c3 @@ -273,7 +273,7 @@ fn void test_check_fails_no_info() alias TestIntFn = fn int? (int a, int b); alias TestFailFn = fn void? (bool to_fail); -fault FOO; +faultdef FOO; fn void test_error() { diff --git a/test/unit/stdlib/math/math_complex.c3 b/test/unit/stdlib/math/math_complex.c3 index e8031b094..d2f370e71 100644 --- a/test/unit/stdlib/math/math_complex.c3 +++ b/test/unit/stdlib/math/math_complex.c3 @@ -1,17 +1,17 @@ module math_tests @test; import math_tests::complex; -alias ComplexDouble = ComplexType{double} @local; -alias ComplexInt = ComplexType{int} @local; +alias ComplexDouble @local = ComplexType {double}; +alias ComplexInt @local = ComplexType {int}; -module math_tests::complex{ElementType} @test; +module math_tests::complex {ElementType} @test; import std::math; -alias ComplexType = Complex{ElementType}; +alias ComplexType = Complex {ElementType}; fn void complex_mul_imaginary() { - ComplexType i = complex::IMAGINARY{ElementType}; + ComplexType i = complex::IMAGINARY {ElementType}; assert(i.mul(i).equals((ComplexType){-1, 0})); assert(i.mul(i).mul(i).equals((ComplexType){0, -1})); } diff --git a/test/unit/stdlib/net/url_encoding.c3 b/test/unit/stdlib/net/url_encoding.c3 index 78404d663..dbc5f1122 100644 --- a/test/unit/stdlib/net/url_encoding.c3 +++ b/test/unit/stdlib/net/url_encoding.c3 @@ -7,7 +7,7 @@ struct EncodeTest { String in; String out; - anyfault err; + fault err; UrlEncodingMode mode; } diff --git a/test/unit/stdlib/threads/channel.c3 b/test/unit/stdlib/threads/channel.c3 index 38b6edb2d..139301dbd 100644 --- a/test/unit/stdlib/threads/channel.c3 +++ b/test/unit/stdlib/threads/channel.c3 @@ -231,7 +231,7 @@ fn void sending_to_full_buffered_chan_aborted_by_close() @test return 0; }, (void*)c)!!; - anyfault err = @catch(c.push(1)); + fault err = @catch(c.push(1)); if (err) { assert(err == thread::CHANNEL_CLOSED); @@ -257,7 +257,7 @@ fn void sending_to_unbuffered_chan_aborted_by_close() @test return 0; }, (void*)c)!!; - anyfault err = @catch(c.push(1)); + fault err = @catch(c.push(1)); if (err) { assert(err == thread::CHANNEL_CLOSED);