From d67e84671217700670e5a2cdd6f65cf678169a02 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 9 Sep 2023 22:49:32 +0200 Subject: [PATCH] Remove cast from void! to anyfault. Rename `@catchof` to `@catch` --- lib/std/core/builtin.c3 | 2 +- lib/std/core/runtime.c3 | 12 +- resources/examples/contextfree/boolerr.c3 | 2 +- .../examples/contextfree/guess_number.c3 | 2 +- src/compiler/sema_casts.c | 30 +-- src/compiler/sema_expr.c | 2 +- src/compiler/sema_stmts.c | 4 +- src/version.h | 2 +- test/test_suite/errors/anyfault_void.c3t | 97 +++++---- test/test_suite/errors/error_regression_2.c3t | 2 +- test/test_suite/errors/failable_catch.c3t | 2 +- .../errors/optional_with_optional.c3t | 6 +- test/test_suite/errors/or_and_rethrow.c3t | 184 ++++++++++++------ test/unit/stdlib/collections/linkedlist.c3 | 6 +- test/unit/stdlib/conv_tests.c3 | 4 +- test/unit/stdlib/core/array.c3 | 4 +- test/unit/stdlib/core/builtintests.c3 | 4 +- test/unit/stdlib/core/string.c3 | 8 +- test/unit/stdlib/io/bytestream.c3 | 2 +- test/unit/stdlib/io/path.c3 | 50 ++--- test/unit/stdlib/net/inetaddr.c3 | 10 +- 21 files changed, 250 insertions(+), 185 deletions(-) diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 7ac359afb..f0c6b2590 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -285,7 +285,7 @@ macro bool @convertible(#expr, $To) @builtin return $checks($To x = #expr); } -macro anyfault @catchof(#expr) @builtin +macro anyfault @catch(#expr) @builtin { if (catch f = #expr) return f; return anyfault {}; diff --git a/lib/std/core/runtime.c3 b/lib/std/core/runtime.c3 index b7de0bdeb..61486e0ce 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -98,18 +98,18 @@ fn bool run_benchmarks(BenchmarkUnit[] benchmarks) name.append_repeat('.', max_name - unit.name.len + 2); io::printf("%s ", name.as_str()); - for(uint i = 0; i < benchmark_warmup_iterations; i++) + for (uint i = 0; i < benchmark_warmup_iterations; i++) { - err = unit.func() @inline; + err = @catch(unit.func()) @inline; @volatile_load(err); } clock = std::time::clock::now(); sys_clock_started = $$sysclock(); - for(uint i = 0; i < benchmark_max_iterations; i++) + for (uint i = 0; i < benchmark_max_iterations; i++) { - err = unit.func() @inline; + err = @catch(unit.func()) @inline; @volatile_load(err); } @@ -129,7 +129,9 @@ fn bool run_benchmarks(BenchmarkUnit[] benchmarks) io::printfn("\n%d benchmark%s run.\n", benchmark_count, benchmark_count > 1 ? "s" : ""); io::printfn("Benchmarks Result: %s. %d passed, %d failed.", - benchmarks_passed < benchmark_count ? "FAILED" : "ok", benchmarks_passed, benchmark_count - benchmarks_passed); + benchmarks_passed < benchmark_count ? "FAILED" : "ok", + benchmarks_passed, + benchmark_count - benchmarks_passed); return benchmark_count == benchmarks_passed; } diff --git a/resources/examples/contextfree/boolerr.c3 b/resources/examples/contextfree/boolerr.c3 index 9c718b36e..389f6cd87 100644 --- a/resources/examples/contextfree/boolerr.c3 +++ b/resources/examples/contextfree/boolerr.c3 @@ -133,7 +133,7 @@ fn void main() bool! has_title = readWhetherTitleNonEmpty(url); // This looks a bit less than elegant, but as you see it's mostly due to having to // use printf here. - io::printf(" Has title: %s vs %s\n", bool_to_string(has_title) ?? (@catchof(has_title)).nameof, has_title ?? false); + io::printf(" Has title: %s vs %s\n", bool_to_string(has_title) ?? (@catch(has_title)).nameof, has_title ?? false); }; dynamic_arena.reset(); } diff --git a/resources/examples/contextfree/guess_number.c3 b/resources/examples/contextfree/guess_number.c3 index 63041b6fb..6676bf6a7 100644 --- a/resources/examples/contextfree/guess_number.c3 +++ b/resources/examples/contextfree/guess_number.c3 @@ -44,7 +44,7 @@ fn int! askGuessMulti(int high) while (true) { int! result = askGuess(high); - if (@catchof(result) == InputResult.NOT_AN_INT) + if (@catch(result) == InputResult.NOT_AN_INT) { libc::printf("I didn't understand that.\n"); err_count++; diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 2ebbd1577..f27c15f0f 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -1558,10 +1558,7 @@ static bool cast_expr_inner(SemaContext *context, Expr *expr, Type *to_type, boo if (!sema_resolve_type_decl(context, from_type)) return false; // Step one, cast from optional. - // This handles: - // 1. *! -> any type - // 2. void! -> anyfault - // 3. void! -> SomeFault (explicit) + // This handles: *! + type -> type! and stops casts when they may not be optional. if (type_is_optional(from_type)) { Type *opt = from_type->optional; @@ -1580,31 +1577,6 @@ static bool cast_expr_inner(SemaContext *context, Expr *expr, Type *to_type, boo return true; } - // If it is void!, then there are special rules: - if (opt == type_void) - { - // void! x; anyfault y = x; - if (!type_is_optional(to_type) && type_is_anyfault(to)) - { - cast(expr, to_type); - return true; - } - - // void! x; FooFault y = (FooFault)x; - // Only allowed if explicit. - if (to->type_kind == TYPE_FAULTTYPE) - { - if (!is_explicit) - { - if (silent) return false; - SEMA_ERROR(expr, "A 'void!' can only be cast into %s using an explicit cast. You can try using (%s)", - type_quoted_error_string(to_type), type_to_error_string(to_type)); - return false; - } - cast(expr, to_type); - return true; - } - } if (may_not_be_optional) { if (silent) return false; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 29ae6129d..669937eba 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -8023,7 +8023,7 @@ bool sema_analyse_cond_expr(SemaContext *context, Expr *expr) if (IS_OPTIONAL(expr)) { SEMA_ERROR(expr, "An optional %s cannot be implicitly converted to a regular boolean value, use '@ok()' " - "and '@catchof()' to conditionally execute on success or failure.", + "and '@catch()' to conditionally execute on success or failure.", type_quoted_error_string(expr->type)); return false; } diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index d395c26da..58eafda7d 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -899,7 +899,7 @@ static inline bool sema_analyse_last_cond(SemaContext *context, Expr *expr, Cond case EXPR_CATCH_UNWRAP: if (cond_type != COND_TYPE_UNWRAP_BOOL && cond_type != COND_TYPE_UNWRAP) { - SEMA_ERROR(expr, "Catch unwrapping is only allowed inside of a 'while' or 'if' conditional, maybe '@catchof()' will do what you need?"); + SEMA_ERROR(expr, "Catch unwrapping is only allowed inside of a 'while' or 'if' conditional, maybe '@catch()' will do what you need?"); return false; } return sema_analyse_catch_unwrap(context, expr); @@ -1062,7 +1062,7 @@ static inline bool sema_analyse_cond(SemaContext *context, Expr *expr, CondType { if (type_no_optional(last->type) == type_void && cast_to_bool) { - SEMA_ERROR(last, "Use '@ok()' or '@catchof()' to explicitly convert a 'void!' to a boolean."); + SEMA_ERROR(last, "Use '@ok()' or '@catch()' to explicitly convert a 'void!' to a boolean."); return false; } SEMA_ERROR(last, "The expression may not be an optional, but was %s.", type_quoted_error_string(last->type)); diff --git a/src/version.h b/src/version.h index 95325ca87..99aab61f1 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.640" \ No newline at end of file +#define COMPILER_VERSION "0.4.641" \ No newline at end of file diff --git a/test/test_suite/errors/anyfault_void.c3t b/test/test_suite/errors/anyfault_void.c3t index bb38e7ee1..59dae647b 100644 --- a/test/test_suite/errors/anyfault_void.c3t +++ b/test/test_suite/errors/anyfault_void.c3t @@ -16,11 +16,11 @@ fn void! errorThing2() extern fn void printf(char*, ...); fn void main() { - anyfault z = errorThing(); + anyfault z = @catch(errorThing()); printf("Z; %llx\n", (iptr)(z)); printf("BAR: %llx\n", (iptr)(MyError.BAR)); printf("FOO: %llx\n", (iptr)(MyError.FOO)); - z = errorThing2(); + z = @catch(errorThing2()); printf("Z2: %llx\n", (iptr)(z)); } @@ -30,60 +30,79 @@ define i64 @anyfault_void.errorThing() #0 { entry: ret i64 ptrtoint (ptr @"anyfault_void.MyError$BAR" to i64) } - ; Function Attrs: nounwind define i64 @anyfault_void.errorThing2() #0 { entry: %reterr = alloca i64, align 8 ret i64 0 } - ; Function Attrs: nounwind declare void @printf(ptr, ...) #0 - ; Function Attrs: nounwind define void @anyfault_void.main() #0 { entry: %z = alloca i64, align 8 - %error_var = alloca i64, align 8 - %error_var1 = alloca i64, align 8 - store i64 0, ptr %error_var, align 8 + %blockret = alloca i64, align 8 + %f = alloca i64, align 8 + %blockret1 = alloca i64, align 8 + %f2 = alloca i64, align 8 + br label %testblock +testblock: ; preds = %entry %0 = call i64 @anyfault_void.errorThing() %not_err = icmp eq i64 %0, 0 %1 = call i1 @llvm.expect.i1(i1 %not_err, i1 true) br i1 %1, label %after_check, label %assign_optional - -assign_optional: ; preds = %entry - store i64 %0, ptr %error_var, align 8 - br label %noerr_block - -after_check: ; preds = %entry - br label %noerr_block - -noerr_block: ; preds = %after_check, %assign_optional - %2 = load i64, ptr %error_var, align 8 - store i64 %2, ptr %z, align 8 - %3 = load i64, ptr %z, align 8 - call void (ptr, ...) @printf(ptr @.str, i64 %3) +assign_optional: ; preds = %testblock + store i64 %0, ptr %f, align 8 + br label %end_block +after_check: ; preds = %testblock + store i64 0, ptr %f, align 8 + br label %end_block +end_block: ; preds = %after_check, %assign_optional + %2 = load i64, ptr %f, align 8 + %neq = icmp ne i64 %2, 0 + br i1 %neq, label %if.then, label %if.exit +if.then: ; preds = %end_block + %3 = load i64, ptr %f, align 8 + store i64 %3, ptr %blockret, align 8 + br label %expr_block.exit +if.exit: ; preds = %end_block + store i64 0, ptr %blockret, align 8 + br label %expr_block.exit +expr_block.exit: ; preds = %if.exit, %if.then + %4 = load i64, ptr %blockret, align 8 + store i64 %4, ptr %z, align 8 + %5 = load i64, ptr %z, align 8 + call void (ptr, ...) @printf(ptr @.str, i64 %5) call void (ptr, ...) @printf(ptr @.str.2, i64 ptrtoint (ptr @"anyfault_void.MyError$BAR" to i64)) call void (ptr, ...) @printf(ptr @.str.3, i64 ptrtoint (ptr @"anyfault_void.MyError$FOO" to i64)) - store i64 0, ptr %error_var1, align 8 - %4 = call i64 @anyfault_void.errorThing2() - %not_err2 = icmp eq i64 %4, 0 - %5 = call i1 @llvm.expect.i1(i1 %not_err2, i1 true) - br i1 %5, label %after_check4, label %assign_optional3 - -assign_optional3: ; preds = %noerr_block - store i64 %4, ptr %error_var1, align 8 - br label %noerr_block5 - -after_check4: ; preds = %noerr_block - br label %noerr_block5 - -noerr_block5: ; preds = %after_check4, %assign_optional3 - %6 = load i64, ptr %error_var1, align 8 - store i64 %6, ptr %z, align 8 - %7 = load i64, ptr %z, align 8 - call void (ptr, ...) @printf(ptr @.str.4, i64 %7) + br label %testblock3 +testblock3: ; preds = %expr_block.exit + %6 = call i64 @anyfault_void.errorThing2() + %not_err4 = icmp eq i64 %6, 0 + %7 = call i1 @llvm.expect.i1(i1 %not_err4, i1 true) + br i1 %7, label %after_check6, label %assign_optional5 +assign_optional5: ; preds = %testblock3 + store i64 %6, ptr %f2, align 8 + br label %end_block7 +after_check6: ; preds = %testblock3 + store i64 0, ptr %f2, align 8 + br label %end_block7 +end_block7: ; preds = %after_check6, %assign_optional5 + %8 = load i64, ptr %f2, align 8 + %neq8 = icmp ne i64 %8, 0 + br i1 %neq8, label %if.then9, label %if.exit10 +if.then9: ; preds = %end_block7 + %9 = load i64, ptr %f2, align 8 + store i64 %9, ptr %blockret1, align 8 + br label %expr_block.exit11 +if.exit10: ; preds = %end_block7 + store i64 0, ptr %blockret1, align 8 + br label %expr_block.exit11 +expr_block.exit11: ; preds = %if.exit10, %if.then9 + %10 = load i64, ptr %blockret1, align 8 + store i64 %10, ptr %z, align 8 + %11 = load i64, ptr %z, align 8 + call void (ptr, ...) @printf(ptr @.str.4, i64 %11) ret void } \ No newline at end of file diff --git a/test/test_suite/errors/error_regression_2.c3t b/test/test_suite/errors/error_regression_2.c3t index 9646919f8..8ac9889ff 100644 --- a/test/test_suite/errors/error_regression_2.c3t +++ b/test/test_suite/errors/error_regression_2.c3t @@ -144,7 +144,7 @@ fn void main() bool! has_title = readWhetherTitleNonEmpty(url); // This looks a bit less than elegant, but as you see it's mostly due to having to // use printf here. - libc::printf(" Has title: %s vs %s\n", bool_to_string(has_title) ?? nameFromError(@catchof(has_title)), (has_title ?? false) ? (char*)"true" : (char*)"false"); + libc::printf(" Has title: %s vs %s\n", bool_to_string(has_title) ?? nameFromError(@catch(has_title)), (has_title ?? false) ? (char*)"true" : (char*)"false"); } } diff --git a/test/test_suite/errors/failable_catch.c3t b/test/test_suite/errors/failable_catch.c3t index 443132a5d..8412ff5e2 100644 --- a/test/test_suite/errors/failable_catch.c3t +++ b/test/test_suite/errors/failable_catch.c3t @@ -22,7 +22,7 @@ fn int main() (void)printf("a = %d\n", a); (void)printf("b = %d\n", b); (void)printf("c = %d\n", c); - if (@catchof(c)) printf("c had error\n"); + if (@catch(c)) printf("c had error\n"); c = 3; (void)printf("c = %d\n", c); return 0; diff --git a/test/test_suite/errors/optional_with_optional.c3t b/test/test_suite/errors/optional_with_optional.c3t index 00f6dc469..4a36be0b5 100644 --- a/test/test_suite/errors/optional_with_optional.c3t +++ b/test/test_suite/errors/optional_with_optional.c3t @@ -9,10 +9,10 @@ fn void main() io::printfn("1:%d", get_a(1) ?? get_b(4) ?? -1); io::printfn("2:%d", get_a(2) ?? get_b(4) ?? -1); io::printfn("3:%d", get_a(1) ?? get_b(5) ?? -1); - io::printfn("4:%s", @catchof(Foo.ABC? ?? Foo.DEF?)); + io::printfn("4:%s", @catch(Foo.ABC? ?? Foo.DEF?)); io::printfn("5:%s", Foo.ABC? ?? 3); - io::printfn("6:%s", @catchof((3 > 2 ? Foo.ABC? : 4) ?? Foo.DEF?)); - io::printfn("7:%s", @catchof((3 < 2 ? Foo.ABC? : 4) ?? Foo.DEF?)); + io::printfn("6:%s", @catch((3 > 2 ? Foo.ABC? : 4) ?? Foo.DEF?)); + io::printfn("7:%s", @catch((3 < 2 ? Foo.ABC? : 4) ?? Foo.DEF?)); long x = Foo.DEF? ?? 3; io::printfn("8:%s", x); int! xy = Foo.ABC? ?? Foo.DEF?; diff --git a/test/test_suite/errors/or_and_rethrow.c3t b/test/test_suite/errors/or_and_rethrow.c3t index c717d3e77..59f209067 100644 --- a/test/test_suite/errors/or_and_rethrow.c3t +++ b/test/test_suite/errors/or_and_rethrow.c3t @@ -31,10 +31,10 @@ fn void! test2(int x) fn void main() { - anyfault a = test(0); - anyfault b = test(1); - anyfault c = test2(0); - anyfault d = test2(1); + anyfault a = @catch(test(0)); + anyfault b = @catch(test(1)); + anyfault c = @catch(test2(0)); + anyfault d = @catch(test2(1)); } /* #expect: foo.ll @@ -514,77 +514,149 @@ voiderr47: ; preds = %noerr_block45, %gua define void @foo.main() #0 { entry: %a = alloca i64, align 8 - %error_var = alloca i64, align 8 + %blockret = alloca i64, align 8 + %f = alloca i64, align 8 %b = alloca i64, align 8 - %error_var1 = alloca i64, align 8 + %blockret1 = alloca i64, align 8 + %f2 = alloca i64, align 8 %c = alloca i64, align 8 - %error_var6 = alloca i64, align 8 + %blockret12 = alloca i64, align 8 + %f13 = alloca i64, align 8 %d = alloca i64, align 8 - %error_var11 = alloca i64, align 8 - store i64 0, ptr %error_var, align 8 + %blockret23 = alloca i64, align 8 + %f24 = alloca i64, align 8 + br label %testblock + +testblock: ; preds = %entry %0 = call i64 @foo.test(i32 0) %not_err = icmp eq i64 %0, 0 %1 = call i1 @llvm.expect.i1(i1 %not_err, i1 true) br i1 %1, label %after_check, label %assign_optional -assign_optional: ; preds = %entry - store i64 %0, ptr %error_var, align 8 - br label %noerr_block +assign_optional: ; preds = %testblock + store i64 %0, ptr %f, align 8 + br label %end_block -after_check: ; preds = %entry - br label %noerr_block +after_check: ; preds = %testblock + store i64 0, ptr %f, align 8 + br label %end_block -noerr_block: ; preds = %after_check, %assign_optional - %2 = load i64, ptr %error_var, align 8 - store i64 %2, ptr %a, align 8 - store i64 0, ptr %error_var1, align 8 - %3 = call i64 @foo.test(i32 1) - %not_err2 = icmp eq i64 %3, 0 - %4 = call i1 @llvm.expect.i1(i1 %not_err2, i1 true) - br i1 %4, label %after_check4, label %assign_optional3 +end_block: ; preds = %after_check, %assign_optional + %2 = load i64, ptr %f, align 8 + %neq = icmp ne i64 %2, 0 + br i1 %neq, label %if.then, label %if.exit -assign_optional3: ; preds = %noerr_block - store i64 %3, ptr %error_var1, align 8 - br label %noerr_block5 +if.then: ; preds = %end_block + %3 = load i64, ptr %f, align 8 + store i64 %3, ptr %blockret, align 8 + br label %expr_block.exit -after_check4: ; preds = %noerr_block - br label %noerr_block5 +if.exit: ; preds = %end_block + store i64 0, ptr %blockret, align 8 + br label %expr_block.exit -noerr_block5: ; preds = %after_check4, %assign_optional3 - %5 = load i64, ptr %error_var1, align 8 - store i64 %5, ptr %b, align 8 - store i64 0, ptr %error_var6, align 8 - %6 = call i64 @foo.test2(i32 0) - %not_err7 = icmp eq i64 %6, 0 - %7 = call i1 @llvm.expect.i1(i1 %not_err7, i1 true) - br i1 %7, label %after_check9, label %assign_optional8 +expr_block.exit: ; preds = %if.exit, %if.then + %4 = load i64, ptr %blockret, align 8 + store i64 %4, ptr %a, align 8 + br label %testblock3 -assign_optional8: ; preds = %noerr_block5 - store i64 %6, ptr %error_var6, align 8 - br label %noerr_block10 +testblock3: ; preds = %expr_block.exit + %5 = call i64 @foo.test(i32 1) + %not_err4 = icmp eq i64 %5, 0 + %6 = call i1 @llvm.expect.i1(i1 %not_err4, i1 true) + br i1 %6, label %after_check6, label %assign_optional5 -after_check9: ; preds = %noerr_block5 - br label %noerr_block10 +assign_optional5: ; preds = %testblock3 + store i64 %5, ptr %f2, align 8 + br label %end_block7 -noerr_block10: ; preds = %after_check9, %assign_optional8 - %8 = load i64, ptr %error_var6, align 8 - store i64 %8, ptr %c, align 8 - store i64 0, ptr %error_var11, align 8 - %9 = call i64 @foo.test2(i32 1) - %not_err12 = icmp eq i64 %9, 0 - %10 = call i1 @llvm.expect.i1(i1 %not_err12, i1 true) - br i1 %10, label %after_check14, label %assign_optional13 +after_check6: ; preds = %testblock3 + store i64 0, ptr %f2, align 8 + br label %end_block7 -assign_optional13: ; preds = %noerr_block10 - store i64 %9, ptr %error_var11, align 8 - br label %noerr_block15 +end_block7: ; preds = %after_check6, %assign_optional5 + %7 = load i64, ptr %f2, align 8 + %neq8 = icmp ne i64 %7, 0 + br i1 %neq8, label %if.then9, label %if.exit10 -after_check14: ; preds = %noerr_block10 - br label %noerr_block15 +if.then9: ; preds = %end_block7 + %8 = load i64, ptr %f2, align 8 + store i64 %8, ptr %blockret1, align 8 + br label %expr_block.exit11 -noerr_block15: ; preds = %after_check14, %assign_optional13 - %11 = load i64, ptr %error_var11, align 8 - store i64 %11, ptr %d, align 8 +if.exit10: ; preds = %end_block7 + store i64 0, ptr %blockret1, align 8 + br label %expr_block.exit11 + +expr_block.exit11: ; preds = %if.exit10, %if.then9 + %9 = load i64, ptr %blockret1, align 8 + store i64 %9, ptr %b, align 8 + br label %testblock14 + +testblock14: ; preds = %expr_block.exit11 + %10 = call i64 @foo.test2(i32 0) + %not_err15 = icmp eq i64 %10, 0 + %11 = call i1 @llvm.expect.i1(i1 %not_err15, i1 true) + br i1 %11, label %after_check17, label %assign_optional16 + +assign_optional16: ; preds = %testblock14 + store i64 %10, ptr %f13, align 8 + br label %end_block18 + +after_check17: ; preds = %testblock14 + store i64 0, ptr %f13, align 8 + br label %end_block18 + +end_block18: ; preds = %after_check17, %assign_optional16 + %12 = load i64, ptr %f13, align 8 + %neq19 = icmp ne i64 %12, 0 + br i1 %neq19, label %if.then20, label %if.exit21 + +if.then20: ; preds = %end_block18 + %13 = load i64, ptr %f13, align 8 + store i64 %13, ptr %blockret12, align 8 + br label %expr_block.exit22 + +if.exit21: ; preds = %end_block18 + store i64 0, ptr %blockret12, align 8 + br label %expr_block.exit22 + +expr_block.exit22: ; preds = %if.exit21, %if.then20 + %14 = load i64, ptr %blockret12, align 8 + store i64 %14, ptr %c, align 8 + br label %testblock25 + +testblock25: ; preds = %expr_block.exit22 + %15 = call i64 @foo.test2(i32 1) + %not_err26 = icmp eq i64 %15, 0 + %16 = call i1 @llvm.expect.i1(i1 %not_err26, i1 true) + br i1 %16, label %after_check28, label %assign_optional27 + +assign_optional27: ; preds = %testblock25 + store i64 %15, ptr %f24, align 8 + br label %end_block29 + +after_check28: ; preds = %testblock25 + store i64 0, ptr %f24, align 8 + br label %end_block29 + +end_block29: ; preds = %after_check28, %assign_optional27 + %17 = load i64, ptr %f24, align 8 + %neq30 = icmp ne i64 %17, 0 + br i1 %neq30, label %if.then31, label %if.exit32 + +if.then31: ; preds = %end_block29 + %18 = load i64, ptr %f24, align 8 + store i64 %18, ptr %blockret23, align 8 + br label %expr_block.exit33 + +if.exit32: ; preds = %end_block29 + store i64 0, ptr %blockret23, align 8 + br label %expr_block.exit33 + +expr_block.exit33: ; preds = %if.exit32, %if.then31 + %19 = load i64, ptr %blockret23, align 8 + store i64 %19, ptr %d, align 8 ret void } diff --git a/test/unit/stdlib/collections/linkedlist.c3 b/test/unit/stdlib/collections/linkedlist.c3 index 630f08633..dbdc5bcaf 100644 --- a/test/unit/stdlib/collections/linkedlist.c3 +++ b/test/unit/stdlib/collections/linkedlist.c3 @@ -158,7 +158,7 @@ fn void! test_pop() assert(list.first()! == 23); assert(list.pop()! == 23); assert(list.len() == 0); - assert(@catchof(list.pop())); + assert(@catch(list.pop())); assert(list.len() == 0); list.push(55); assert(list.len() == 1); @@ -182,7 +182,7 @@ fn void! test_remove_first() assert(list.first()! == 23); assert(@ok(list.remove_first())); assert(list.len() == 0); - assert(@catchof(list.pop())); + assert(@catch(list.pop())); assert(list.len() == 0); list.push(55); assert(list.len() == 1); @@ -206,7 +206,7 @@ fn void! test_remove_last() assert(list.last()! == -3); assert(@ok(list.remove_last())); assert(list.len() == 0); - assert(@catchof(list.remove_last())); + assert(@catch(list.remove_last())); assert(list.len() == 0); list.push(55); assert(list.len() == 1); diff --git a/test/unit/stdlib/conv_tests.c3 b/test/unit/stdlib/conv_tests.c3 index 27c666d55..5cfa1d70e 100644 --- a/test/unit/stdlib/conv_tests.c3 +++ b/test/unit/stdlib/conv_tests.c3 @@ -23,7 +23,7 @@ fn void! comparison_helper_8_to_32(String in, Char32 c32) fn void assert_utf8_is_error(String in) { usz len = in.len; - assert(@catchof(conv::utf8_to_char32(in.ptr, &len)), "Expected error"); + assert(@catch(conv::utf8_to_char32(in.ptr, &len)), "Expected error"); } fn void! test_char32_ut8_boundary() @test @@ -33,7 +33,7 @@ fn void! test_char32_ut8_boundary() @test comparison_helper_32_to_8(0x00000080, { 0xc2, 0x80 })!; comparison_helper_32_to_8(0x00000800, { 0xe0, 0xa0, 0x80 })!; comparison_helper_32_to_8(0x00010000, { 0xf0, 0x90, 0x80, 0x80 })!; - assert(@catchof(comparison_helper_32_to_8(0x10ffff + 1, { 0 })), "Expected error"); + assert(@catch(comparison_helper_32_to_8(0x10ffff + 1, { 0 })), "Expected error"); // Last seq per len comparison_helper_32_to_8(0x0000007f, { 0x7f })!; comparison_helper_32_to_8(0x000007ff, { 0xdf, 0xbf })!; diff --git a/test/unit/stdlib/core/array.c3 b/test/unit/stdlib/core/array.c3 index a5a1edd02..4cd008a76 100644 --- a/test/unit/stdlib/core/array.c3 +++ b/test/unit/stdlib/core/array.c3 @@ -6,7 +6,7 @@ fn void! find() assert(array::index_of(a, 2)! == 1); assert(array::index_of(a, 1)! == 0); assert(array::index_of(a, 3)! == 2); - assert(@catchof(array::index_of(a, 4)) == SearchResult.MISSING); + assert(@catch(array::index_of(a, 4)) == SearchResult.MISSING); } fn void! find_subarray() @@ -15,7 +15,7 @@ fn void! find_subarray() assert(array::index_of(a, 2)! == 1); assert(array::index_of(a, 1)! == 0); assert(array::index_of(a, 3)! == 2); - assert(@catchof(array::index_of(a, 4)) == SearchResult.MISSING); + assert(@catch(array::index_of(a, 4)) == SearchResult.MISSING); } fn void! concat() diff --git a/test/unit/stdlib/core/builtintests.c3 b/test/unit/stdlib/core/builtintests.c3 index a1abe2945..7e7e24a90 100644 --- a/test/unit/stdlib/core/builtintests.c3 +++ b/test/unit/stdlib/core/builtintests.c3 @@ -5,7 +5,7 @@ fn void! test_anycast() int a; any b = &a; assert(anycast(b, int)! == &a); - assert(@catchof(anycast(b, double)) == CastResult.TYPE_MISMATCH); + assert(@catch(anycast(b, double)) == CastResult.TYPE_MISMATCH); } fn void! test_bitcast() @@ -25,7 +25,7 @@ fn void! test_enum_by_name() { assert(enum_by_name(Tester, "ABC")! == Tester.ABC); assert(enum_by_name(Tester, "DEF")! == Tester.DEF); - assert(@catchof(enum_by_name(Tester, "GHI")) == SearchResult.MISSING); + assert(@catch(enum_by_name(Tester, "GHI")) == SearchResult.MISSING); } fn void test_likely() diff --git a/test/unit/stdlib/core/string.c3 b/test/unit/stdlib/core/string.c3 index 04b8e816c..93becec99 100644 --- a/test/unit/stdlib/core/string.c3 +++ b/test/unit/stdlib/core/string.c3 @@ -81,7 +81,7 @@ fn void! test_index_of() assert(test.index_of("o")! == 4); assert(test.index_of("ll")! == 2); assert(test.index_of(" hello")! == 11); - assert(@catchof(test.index_of("wi"))); + assert(@catch(test.index_of("wi"))); } fn void! test_rindex_of() @@ -92,7 +92,7 @@ fn void! test_rindex_of() assert(test.rindex_of("he")! == 12); assert(test.rindex_of("world")! == 6); assert(test.rindex_of("hello ")! == 0); - assert(@catchof(test.rindex_of("wi"))); + assert(@catch(test.rindex_of("wi"))); } fn void! test_index_of_char() @@ -101,7 +101,7 @@ fn void! test_index_of_char() assert(test.index_of_char('o')! == 4); assert(test.index_of_char('l')! == 2); assert(test.index_of_char('h')! == 0); - assert(@catchof(test.index_of_char('x'))); + assert(@catch(test.index_of_char('x'))); } fn void! test_rindex_of_char() @@ -110,5 +110,5 @@ fn void! test_rindex_of_char() assert(test.rindex_of_char('o')! == 16); assert(test.rindex_of_char('l')! == 15); assert(test.rindex_of_char('h')! == 12); - assert(@catchof(test.index_of_char('x'))); + assert(@catch(test.index_of_char('x'))); } \ No newline at end of file diff --git a/test/unit/stdlib/io/bytestream.c3 b/test/unit/stdlib/io/bytestream.c3 index 5bb459ad3..13b6a8eac 100644 --- a/test/unit/stdlib/io/bytestream.c3 +++ b/test/unit/stdlib/io/bytestream.c3 @@ -33,7 +33,7 @@ fn void! bytewriter_buffer() s.write_byte(0)!!; String o = ((ZString)&z).as_str(); assert(o == "hello"); - assert(@catchof(s.write("xxxx"))); + assert(@catch(s.write("xxxx"))); } fn void! bytewriter_read_from() diff --git a/test/unit/stdlib/io/path.c3 b/test/unit/stdlib/io/path.c3 index dc01be610..55d1b9111 100644 --- a/test/unit/stdlib/io/path.c3 +++ b/test/unit/stdlib/io/path.c3 @@ -3,9 +3,9 @@ module std::io::path @test; fn void! test_parent() { Path p = path::new("")!; - assert(@catchof(p.parent())); + assert(@catch(p.parent())); p = path::new("/", .path_env = PathEnv.POSIX)!; - assert(@catchof(p.parent())); + assert(@catch(p.parent())); p = path::new("/a/b/c", .path_env = PathEnv.POSIX)!; assert(p.parent().as_str()! == "/a/b"); p = path::new("/a/b/c", .path_env = PathEnv.WIN32)!; @@ -15,25 +15,25 @@ fn void! test_parent() fn void! test_path_normalized() { assert(path::new("", .path_env = PathEnv.WIN32).as_str()! == ""); - assert(@catchof(path::new("1:\\a\\b\\c.txt", .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(":", .path_env = PathEnv.WIN32))); - assert(@catchof(path::new("1:", .path_env = PathEnv.WIN32))); - assert(@catchof(path::new("1:a", .path_env = PathEnv.WIN32))); -// assert(@catchof(path::new(`\\\a\b\c.txt`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`\\server\a\b\..\..\..\c`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new("1:\\a\\b\\c.txt", .path_env = PathEnv.WIN32))); + assert(@catch(path::new(":", .path_env = PathEnv.WIN32))); + assert(@catch(path::new("1:", .path_env = PathEnv.WIN32))); + assert(@catch(path::new("1:a", .path_env = PathEnv.WIN32))); +// assert(@catch(path::new(`\\\a\b\c.txt`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`\\server\a\b\..\..\..\c`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`\\a`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`/a/b/../../../c`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`/a/b/../../../c`, .path_env = PathEnv.POSIX))); - assert(@catchof(path::new(`/a/b/../../..`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`/a/b/../../..`, .path_env = PathEnv.POSIX))); - assert(@catchof(path::new(`/../a`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`/../a`, .path_env = PathEnv.POSIX))); - assert(@catchof(path::new(`/..`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`/..`, .path_env = PathEnv.POSIX))); - assert(@catchof(path::new(`C:/a/b/../../../c`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`C:/../a`, .path_env = PathEnv.WIN32))); - assert(@catchof(path::new(`C:/..`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`\\a`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`/a/b/../../../c`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`/a/b/../../../c`, .path_env = PathEnv.POSIX))); + assert(@catch(path::new(`/a/b/../../..`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`/a/b/../../..`, .path_env = PathEnv.POSIX))); + assert(@catch(path::new(`/../a`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`/../a`, .path_env = PathEnv.POSIX))); + assert(@catch(path::new(`/..`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`/..`, .path_env = PathEnv.POSIX))); + assert(@catch(path::new(`C:/a/b/../../../c`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`C:/../a`, .path_env = PathEnv.WIN32))); + assert(@catch(path::new(`C:/..`, .path_env = PathEnv.WIN32))); assert(path::new("/", .path_env = PathEnv.POSIX).as_str()! == "/"); assert(path::new("/./", .path_env = PathEnv.POSIX).as_str()! == "/"); @@ -190,11 +190,11 @@ fn void! test_path_normalized() fn void! test_extension() { - assert(@catchof(path::new(`C:`, .path_env = PathEnv.WIN32).extension())); - assert(@catchof(path::new(`C:`, .path_env = PathEnv.POSIX).extension())); - assert(@catchof(path::new(`file`, .path_env = PathEnv.WIN32).extension())); - assert(@catchof(path::new(`file`, .path_env = PathEnv.POSIX).extension())); - assert(@catchof(path::new(`C:\temp\foo.bar\README`, .path_env = PathEnv.WIN32).extension())); + assert(@catch(path::new(`C:`, .path_env = PathEnv.WIN32).extension())); + assert(@catch(path::new(`C:`, .path_env = PathEnv.POSIX).extension())); + assert(@catch(path::new(`file`, .path_env = PathEnv.WIN32).extension())); + assert(@catch(path::new(`file`, .path_env = PathEnv.POSIX).extension())); + assert(@catch(path::new(`C:\temp\foo.bar\README`, .path_env = PathEnv.WIN32).extension())); assert(path::new_windows("file.txt").extension()! == "txt"); assert(path::new_posix("file.txt").extension()! == "txt"); diff --git a/test/unit/stdlib/net/inetaddr.c3 b/test/unit/stdlib/net/inetaddr.c3 index ecdbf5520..653bdc683 100644 --- a/test/unit/stdlib/net/inetaddr.c3 +++ b/test/unit/stdlib/net/inetaddr.c3 @@ -34,11 +34,11 @@ fn void! test_ipv4_parse() assert(a.ipv4.a == 127 && a.ipv4.b == 0 && a.ipv4.c == 0 && a.ipv4.d == 1); a = net::ipv4_from_str("255.254.253.255")!; assert(a.ipv4.a == 255 && a.ipv4.b == 254 && a.ipv4.c == 253 && a.ipv4.d == 255); - assert(@catchof(net::ipv4_from_str(".1.1.1.1"))); - assert(@catchof(net::ipv4_from_str("1..1.1"))); - assert(@catchof(net::ipv4_from_str("1..1.1.1"))); - assert(@catchof(net::ipv4_from_str("1.1.1.256"))); - assert(@catchof(net::ipv4_from_str("256.1.1.1"))); + assert(@catch(net::ipv4_from_str(".1.1.1.1"))); + assert(@catch(net::ipv4_from_str("1..1.1"))); + assert(@catch(net::ipv4_from_str("1..1.1.1"))); + assert(@catch(net::ipv4_from_str("1.1.1.256"))); + assert(@catch(net::ipv4_from_str("256.1.1.1"))); } fn void test_ipv6()