Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

stage2: boolean type equality checking, compile time error comparison, validate switch errors, error set merging #7092

Closed
wants to merge 11 commits into from

Conversation

g-w1
Copy link
Contributor

@g-w1 g-w1 commented Nov 12, 2020

The theme of this pr is on errors and types.

  • boolean type equality checking (const b: bool = error {Thing1, Thing2} == error {Thing2, Thing1}):
    • add error union and error set case to Type.eql()
  • compile time error comparison (error.B == error.A)
  • validate switch for errors
  • merge error sets (var b: bool = error { Oof } || error { Other } == error { Oof, Other })
  • tests

@daurnimator daurnimator added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Nov 15, 2020
@g-w1 g-w1 force-pushed the type-check-more-stuff branch from 6822486 to 2c3cfdd Compare November 26, 2020 01:27
@g-w1 g-w1 marked this pull request as ready for review November 26, 2020 17:44
src/value.zig Outdated Show resolved Hide resolved
src/type.zig Outdated Show resolved Hide resolved
src/type.zig Outdated Show resolved Hide resolved
src/Module.zig Show resolved Hide resolved
src/Module.zig Outdated
}
var it_dest = dt_e.iterator();
while (it_dest.next()) |entry| {
try fields.put(self.gpa, entry.key, entry.value);
Copy link
Member

Choose a reason for hiding this comment

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

coerce should only check that inst.ty is a subset of dest_type. Error set widening should be happening in resolvePeerTypes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am a little confused. If one can be coerced into another, I shouldn't do it and just return inst? Or should I make a new inst instead of modifying the other inst in place? If making a new inst, should I keep that in coerce, or still move it to peer type?

Copy link
Member

Choose a reason for hiding this comment

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

If inst.ty can coerce into dest_type then you wouldn't need to modify anything or return a new inst since inst.yt would be a subset of dest_type and all of its errors can already be found in dest_type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wouldn't need to modify anything or return a new inst

I think I am understanding you wrong. With a diff of this: (just removing the code that changes the inst)

diff --git a/src/Module.zig b/src/Module.zig
index ca2282060..e6f601738 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -2841,33 +2841,33 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
                             while (it.next()) |entry| {
                                 if (dt_e.get(entry.key) == null) break :blk; // the smaller set has a key not in the larger set
                             }
-                            var it_dest = dt_e.iterator();
-                            while (it_dest.next()) |entry| {
-                                try fields.put(self.gpa, entry.key, entry.value);
-                            }
+                            // var it_dest = dt_e.iterator();
+                            // while (it_dest.next()) |entry| {
+                            //     try fields.put(self.gpa, entry.key, entry.value);
+                            // }
                         }
                         return inst;
                     },
                     .err_single => |name| blk: { // dont have to deinit anything because it is a slice
                         const dt_e = dest_type.getErrs().multiple;
                         if (dt_e.get(name) == null) break :blk; // the smaller set has a key not in the larger set
-                        var new_decl_arena = std.heap.ArenaAllocator.init(self.gpa);
-                        errdefer new_decl_arena.deinit();
-                        const payload_val = try scope.arena().create(Value.Payload.ErrorSet);
-                        payload_val.* = .{
-                            .fields = .{},
-                            .decl = undefined, // populated below
-                        };
-                        payload_val.fields = try dt_e.clone(&new_decl_arena.allocator);
-                        // TODO create name in format "error:line:column"
-                        const new_decl = try self.createAnonymousDecl(scope, &new_decl_arena, .{
-                            .ty = Type.initTag(.type),
-                            .val = Value.initPayload(&payload_val.base),
-                        });
-                        payload_val.decl = new_decl;
-                        const payload_ty = try scope.arena().create(Type.Payload.ErrorSet);
-                        payload_ty.* = .{ .decl = new_decl };
-                        inst.ty = Type.initPayload(&payload_ty.base);
+                        // var new_decl_arena = std.heap.ArenaAllocator.init(self.gpa);
+                        // errdefer new_decl_arena.deinit();
+                        // const payload_val = try scope.arena().create(Value.Payload.ErrorSet);
+                        // payload_val.* = .{
+                        //     .fields = .{},
+                        //     .decl = undefined, // populated below
+                        // };
+                        // payload_val.fields = try dt_e.clone(&new_decl_arena.allocator);
+                        // // TODO create name in format "error:line:column"
+                        // const new_decl = try self.createAnonymousDecl(scope, &new_decl_arena, .{
+                        //     .ty = Type.initTag(.type),
+                        //     .val = Value.initPayload(&payload_val.base),
+                        // });
+                        // payload_val.decl = new_decl;
+                        // const payload_ty = try scope.arena().create(Type.Payload.ErrorSet);
+                        // payload_ty.* = .{ .decl = new_decl };
+                        // inst.ty = Type.initPayload(&payload_ty.base);
                         return inst;
                     },
                     else => unreachable,
@@ -2877,11 +2877,11 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
             .anyerror => {
                 switch (gotten_err_set) {
                     .multiple => |fields| {
-                        inst.ty = Type.initTag(.anyerror);
+                        // inst.ty = Type.initTag(.anyerror);
                         return inst;
                     },
                     .err_single => |_| {
-                        inst.ty = Type.initTag(.anyerror);
+                        // inst.ty = Type.initTag(.anyerror);
                         return inst;
                     },
                     else => unreachable,

I get errors like this when running the test

❯ zig build test-stage2 -Denable-qemu
Test [1/30] test "self-hosted"... tests [1/49] referencing decls which appear later in the file [1/1] up
tests [33/49] switch and coerce error sets [2/4] update [3/3] switch and coerce error sets
Unexpected error:
================
:6:14: error: expected _start__anon_12, found error{Z}
================
Test failed.
error: the following test command failed with exit code 1:
/home/jacob/dev/zig/zig-cache/o/410e73f2855175dd2c3126a64c2793dc/test
The following command exited with error code 1:
/home/jacob/.local/zig/0.7.1+8fc765387/files/zig test /home/jacob/dev/zig/src/test.zig --pkg-begin build
_options /home/jacob/dev/zig/zig-cache/test_build_options.zig --pkg-end --cache-dir /home/jacob/dev/zig/
zig-cache --global-cache-dir /home/jacob/.cache/zig --name test --pkg-begin stage2_tests /home/jacob/dev
/zig/test/stage2/test.zig --pkg-end
error: the following build command failed with exit code 1:
/home/jacob/dev/zig/zig-cache/o/ff28c7d5a2605f406d44b22dd03068c7/build /home/jacob/.local/zig/0.7.1+8fc7
65387/files/zig /home/jacob/dev/zig /home/jacob/dev/zig/zig-cache /home/jacob/.cache/zig test-stage2 -De
nable-qemu

which is expected because it is not coercing anything. I can understand that it is bad to modify the type of the inst, but I am confused where to go from here.

Also, when I do the widening in resolvePeerTypes, should I modify the errorset in place to widen it, or make a new one? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does 0b6e935 fix this comment? I think I will add peer type resolution as a separate pr with coercing error sets to error unions, and values to error unions.

src/zir_sema.zig Outdated Show resolved Hide resolved
src/zir_sema.zig Outdated Show resolved Hide resolved
src/zir_sema.zig Show resolved Hide resolved
src/zir_sema.zig Outdated Show resolved Hide resolved
src/type.zig Show resolved Hide resolved
src/zir_sema.zig Show resolved Hide resolved
@g-w1 g-w1 force-pushed the type-check-more-stuff branch 3 times, most recently from c870327 to 43f0325 Compare December 29, 2020 19:47
src/zir_sema.zig Outdated Show resolved Hide resolved
test/stage2/test.zig Show resolved Hide resolved
src/zir_sema.zig Outdated Show resolved Hide resolved
g-w1 added 9 commits January 2, 2021 09:57
* This allows @typeof(error.X) (error set single), and error {T, ... } and anyerror to be coerced to each other as long as the target error set is wider. (anything can be coerced to anyerror)
* Also validateSwitch for error sets. This allows error sets to be validated in a switch statement.
This is the last of the "features" in this pr. Now I just need to add
tests and clean it up.
I had most of the code before, but I handled a case where `anyerror || error {Thing}` goes to anyerror.
It also works now!
For some reason, only 2 check output tests are running on my machine,
even though im on linux_x64. This is very weird?!?!?!
* make Type.eql for errors not reach unreachable
* use global_error_set instead of getErrorValue
* use value in analyzeInstCmp instead of type and use the u16 error
  value field instead of the name so that we don't need mem.eql
* clean up code by factoring code from Module.zig -> type.zig so that it can be reused in peer type resolution and coercion
* update after rebasing and fix dumb things that I saw when reviewing my own code
@g-w1 g-w1 force-pushed the type-check-more-stuff branch from 43f0325 to e5fcdfa Compare January 2, 2021 16:06
g-w1 added 2 commits January 5, 2021 15:08
commit 3e8aaee
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 22:25:04 2021 -0700

    std: skip more tests on Windows to save CI memory

    I've enabled only the tests that check things specific to Windows that
    are not tested by other systems.

commit 16896a9
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 15:57:54 2021 -0700

    ci: skip crypto tests on windows

    Trying to buy us more time on the Windows CI.

commit 66e5e92
Merge: d957244 2561168
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 14:23:01 2021 -0800

    Merge pull request ziglang#7592 from LemonBoy/fix-7188

    Allow variable captures on multi-prong switch arms

commit d957244
Author: Evan Haas <[email protected]>
Date:   Fri Jan 1 23:13:15 2021 -0800

    Allow dollar sign $ in identifiers in translate-c

    In strictly conforming C, identifiers cannot container dollar signs.
    However GCC and Clang allow them by default, so translate-c should
    handle them. See http://gcc.gnu.org/onlinedocs/cpp/Tokenization.html
    I encountered this in the wild in windows.h

    Fixes ziglang#7585

commit 819f2a0
Author: Felix (xq) Queißner <[email protected]>
Date:   Mon Jan 4 12:20:43 2021 +0100

    Fixes missing error prong in std.os.send.

commit fc3508b
Author: J.C. Moyer <[email protected]>
Date:   Mon Jan 4 09:15:39 2021 -0500

    Fix off-by-one error in SinglyLinkedList.len() and add associated tests

commit a93c123
Author: xackus <[email protected]>
Date:   Mon Jan 4 17:41:24 2021 +0100

    std.c: add some noalias

commit 2fe8a48
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 14:59:18 2021 -0700

    ci: omit stage2 backend from stage1 on Windows

    to avoid out-of-memory on the CI runs.

commit 462c1d8
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 14:33:32 2021 -0700

    stage2: add more perf tracing points

commit fc38b42
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 13:49:17 2021 -0700

    Revert "Fix ziglang#7296:"

    This broke build scripts that wanted to refer to `exe_dir` or
    `install_path`.

    There has also been some pushback and discussion on this breaking
    change. I think it should be re-evaluated.

    This reverts commit a1a1929.

commit ef2fa67
Merge: aa0906e 7e64dc4
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 13:40:51 2021 -0700

    Merge branch 'g-w1-stage2-evalbranch'

    closes ziglang#7682

commit 7e64dc4
Author: Andrew Kelley <[email protected]>
Date:   Mon Jan 4 13:40:01 2021 -0700

    stage2: improvements to `@setEvalBranchQuota`

     * extract magic number into a constant
     * properly use result location casting for the operand
     * naming convention for ZIR instructions

commit 638f93e
Author: g-w1 <[email protected]>
Date:   Sun Jan 3 15:45:22 2021 -0500

    stage2: implementation of `@setEvalBranchQuota`:

    `@setEvalBranchQuota` can be called before the comptime/inline call
    stack is created.

    For example:

    ```zig
    @setEvalBranchQuota(100);
    comptime {
        while (true) {}
    }
    ```

    Here we need to set the branch_quota before the comptime block creates a
    scope for the branch_count.

commit aa0906e
Author: joachimschmidt557 <[email protected]>
Date:   Sat Jan 2 18:53:11 2021 +0100

    stage2 x86_64: fix bug in Function.gen

    Previously, the x86_64 backend would remove code for exitlude relocs
    if the jump amount were 0. This causes issues as earlier jumps rely on
    the jump being present at the same address.

commit 4400d2d
Author: Frank Denis <[email protected]>
Date:   Sun Jan 3 09:10:59 2021 +0100

    std/crypto: add BLAKE2-160 types and tests

commit e4c4a0a
Author: daurnimator <[email protected]>
Date:   Mon Jan 4 01:27:35 2021 +1100

    Improve uring definitions

commit 53a0b79
Merge: c8e44d8 807dc56
Author: Andrew Kelley <[email protected]>
Date:   Sun Jan 3 19:51:38 2021 -0800

    Merge pull request ziglang#7681 from kubkon/stage2-aarch64-fn-args

    stage2: basic fn args for aarch64

commit c8e44d8
Author: Andrew Kelley <[email protected]>
Date:   Sun Jan 3 20:34:17 2021 -0700

    stage2: remove the Cache deadlock detection code

    It's more trouble than it's worth; it didn't even catch the most recent
    incident because it was across process boundaries anyway.

commit 404dc96
Author: Andrew Kelley <[email protected]>
Date:   Sun Jan 3 20:25:04 2021 -0700

    stage2: fix Cache debug deadlock code memory leak

commit 5c92e24
Author: Andrew Kelley <[email protected]>
Date:   Sun Jan 3 20:10:07 2021 -0700

    drone ci: skip compile error tests to save time

    These are covered by other CI scripts and we're up against Drone CI time
    limits.

commit f664425
Merge: 5cc1310 0151f3b
Author: Andrew Kelley <[email protected]>
Date:   Sun Jan 3 16:09:14 2021 -0800

    Merge pull request ziglang#7598 from FireFox317/more-llvm-stage2

    stage2: More improvements to self-hosted LLVM backend

commit 5cc1310
Author: Evan Haas <[email protected]>
Date:   Tue Dec 29 11:07:04 2020 -0800

    Static function declarations with no prototype should not be variadic

    If a static function is defined with no argument list and no prototype
    is given, it should be treated as a function that takes no arguments
    rather than as a variadic function.

    Fixes ziglang#7594

commit 807dc56
Author: Jakub Konka <[email protected]>
Date:   Sun Jan 3 23:20:09 2021 +0100

    stage2: add aarch64 stage2 tests

    Fix missing string format specifier in Mach-O used to generate
    path to debug symbols bundle.

commit 2a410ba
Author: Jakub Konka <[email protected]>
Date:   Sun Jan 3 23:01:22 2021 +0100

    stage2: implement basic function params aarch64

    Implement missing `.register` prong for `aarch64` `genSetReg`.

commit 0151f3b
Author: Timon Kruiper <[email protected]>
Date:   Sun Jan 3 17:10:28 2021 +0100

    stage2: Add support for testing LLVM enabled builds in test-stage2

    To make sure that we don't have to rebuild libc for every case, we now
    have a seperate cache directory for the global cache, which remains
    the same between test runs.

    Also make sure to destory the Compilation before executing a child process,
    otherwise the compiler deadlocks. (ziglang#7596)

commit a926c91
Author: Timon Kruiper <[email protected]>
Date:   Sun Jan 3 16:48:52 2021 +0100

    stage2: enable building test-stage2 with LLVM backend enabled

    We can now run `zig build test-stage2 -Denable-llvm`.

commit 7e5aaca
Author: Timon Kruiper <[email protected]>
Date:   Sun Jan 3 16:44:53 2021 +0100

    stage2: add some missing deallocations in Compilation.zig

commit 3c05c60
Author: Timon Kruiper <[email protected]>
Date:   Sun Jan 3 16:09:32 2021 +0100

    stage2: Output the LLVM object files in the cache directory

    Also make sure to properly free everything.

commit 0008bef
Author: Timon Kruiper <[email protected]>
Date:   Sun Jan 3 16:00:12 2021 +0100

    stage2: add support for integers in LLVM backend

    Also adds support for simple operators, like add and subtract.
    The intcast and bitcast instruction also have been implemented.

    Linking with libc also works, so we can now generate working executables!

    `zig build-exe example.zig -fLLVM -lc`:
    ```
    fn add(a: i32, b: i32) i32 {
        return a + b;
    }

    export fn main() c_int {
        var a: i32 = -5;
        const x = add(a, 7);
        var y = add(2, 0);
        y -= x;
        return y;
    }
    ```

commit e095ebf
Author: Timon Kruiper <[email protected]>
Date:   Tue Dec 29 22:47:52 2020 +0100

    stage2: make use of proper LLVM intrinsic APIs in LLVM backend

commit da545d6
Author: Timon Kruiper <[email protected]>
Date:   Tue Dec 29 20:39:58 2020 +0100

    stage2: implement argument passing and returning in LLVM backend

    Furthermore add the Not instruction.

    The following now works:
    ```
    export fn _start() noreturn {
        var x: bool = true;
        var other: bool = foo(x);
        exit();
    }

    fn foo(cond: bool) bool {
        return !cond;
    }

    fn exit() noreturn {
        unreachable;
    }
    ```

commit 47a4d43
Author: Timon Kruiper <[email protected]>
Date:   Tue Dec 29 20:18:17 2020 +0100

    stage2: Add code generation for Load instruction in LLVM backend

    The following now works:
    ```
    export fn _start() noreturn {
        var x: bool = true;
        var y: bool = x;
        exit();
    }

    fn exit() noreturn {
        unreachable;
    }
    ```

commit 19cfd31
Author: Timon Kruiper <[email protected]>
Date:   Tue Dec 29 20:09:08 2020 +0100

    stage2: implement register allocation in LLVM self-hosted backend

    A HashMap has been added which store the LLVM values used in a function.
    Together with the alloc and store instructions the following now works:
    ```
    export fn _start() noreturn {
        var x: bool = true;
        exit();
    }

    fn exit() noreturn {
        unreachable;
    }
    ```

commit a5dab15
Author: Timon Kruiper <[email protected]>
Date:   Tue Dec 29 19:03:04 2020 +0100

    stage2: clear `err_msg` after it has been added to `module.failed_decls`

commit 0ed04aa
Author: Timon Kruiper <[email protected]>
Date:   Tue Dec 29 18:52:53 2020 +0100

    stage2: fix building self-hosted compiler with -Dstatic-llvm

    This supersedes c81ae52

commit 5aac2fc
Author: Frank Denis <[email protected]>
Date:   Sat Jan 2 20:08:27 2021 +0100

    std/crypto: properly support arbitrary output sizes

    Fixes ziglang#7657

commit 6838141
Merge: d8f3f14 33e53d7
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 22:05:31 2021 -0800

    Merge pull request ziglang#7612 from g-w1/do-7296

    Implement ziglang#7296

commit d8f3f14
Merge: 3d151fb 6548322
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 22:01:51 2021 -0800

    Merge pull request ziglang#7647 from ziglang/stage2-comptime-fn-call

    stage2: comptime function calls and inline function calls

commit 6548322
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 22:42:07 2021 -0700

    stage2: support recursive inline/comptime functions

    zir.Inst no longer has an `analyzed_inst` field. This is previously how
    we mapped ZIR to their TZIR counterparts, however with the way inline
    and comptime function calls work, we can potentially have the same ZIR
    structure being analyzed by multiple different analyses, such as during
    a recursive inline function call. This would cause the `analyzed_inst`
    field to become clobbered. So instead, we use a table to map the
    instructions to their semantically analyzed counterparts. This will help
    with multi-threaded compilation as well.

    Scope.Block.Inlining is split into 2 different layers of "sharedness".
    The first layer is shared by the whole inline/comptime function call
    stack. It contains the callsite where something is being inlined and the
    branch count/quota. The second layer is different per function call but
    shared by all the blocks within the function being inlined.

    Add support for debug dumping br and brvoid TZIR instructions.

    Remove the "unreachable code" error. It was happening even for this case:

    ```zig
    if (comptime_condition) return;
    bar(); // error: unreachable code
    ```

    We will need smarter logic for when it is legal to emit this compile
    error.

    Remove the ZIR test cases. These are redundant with other higher level
    Zig source tests we have, and maintaining support for ZIRModule as a
    first-class top level abstraction is getting in the way of clean
    compiler design for the main use case. We will have ZIR/TZIR based test
    cases someday to help with testing optimization passes and ZIR to TZIR
    analysis, but as is, these test cases are not accomplishing that, and
    they are getting in the way.

commit 3d151fb
Author: g-w1 <[email protected]>
Date:   Sat Jan 2 23:11:34 2021 -0500

    fix 7665:

    only add self exe path when testing

commit 50a5301
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 14:28:03 2021 -0700

    stage2: fix handling compile error in inline fn call

     * scopes properly inherit inlining information
     * compile errors of inline function calls are properly attached to the
       caller rather than the callee.
       - added a test case for this
     * --watch still opens a repl if compile errors happen.

commit 006e7f6
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 13:40:23 2021 -0700

    stage2: re-use ZIR for comptime and inline calls

    Instead of freeing ZIR after semantic analysis, we keep it around so
    that it can be used for comptime calls, inline calls, and generic
    function calls. ZIR memory is now managed by the Decl arena.

    Debug dump() functions are conditionally compiled; only available in
    Debug builds of the compiler.

    Add a test for an inline function call.

commit 9362f38
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 12:32:30 2021 -0700

    stage2: implement function call inlining in the frontend

     * remove the -Ddump-zir thing. that's handled through --verbose-ir
     * rework Fn to have an is_inline flag without requiring any more memory
       on the heap per function.
     * implement a rough first version of dumping typed zir (tzir) which is
       a lot more helpful for debugging than what we had before. We don't
       have a way to parse it though.
     * keep track of whether the inline-ness of a function changes because
       if it does we have to go update callsites.
     * add compile error for inline and export used together.

    inline function calls and comptime function calls are implemented the
    same way. A block instruction is set up to capture the result, and then
    a scope is set up that has a flag for is_comptime and some state if the
    scope is being inlined.

    when analyzing `ret` instructions, zig looks for inlining state in the
    scope, and if found, treats `ret` as a `break` instruction instead, with
    the target block being the one set up at the inline callsite.

    Follow-up items:
     * Complete out the debug TZIR dumping code.
     * Don't redundantly generate ZIR for each inline/comptime function
       call. Instead we should add a new state enum tag to Fn.
     * comptime and inlining branch quotas.
     * Add more test cases.

commit fea8659
Author: Andrew Kelley <[email protected]>
Date:   Fri Jan 1 19:24:02 2021 -0700

    stage2: comptime function calls

     * Function calls that happen in a comptime scope get called at
       compile-time. We do this by putting the parameters in place as
       constant values and then running regular function analysis on the
       body.
     * Added `Scope.Block.dump()` for debugging purposes.
     * Fixed some code to call `identifierTokenString` rather than
       `tokenSlice`, making it work for `@""` syntax.
     * Implemented `Value.copy` for big integers.

    Follow-up issues to tackle:
     * Adding compile errors to the callsite instead of the callee Decl.
     * Proper error notes for "called from here".
       - Related: ziglang#7555
     * Branch quotas.
     * ZIR support?

commit fb37c1b
Merge: db1e97d 974c008
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 19:03:37 2021 -0700

    Merge branch 'LemonBoy-revive-6680'

    closes ziglang#6870

commit 974c008
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 19:03:14 2021 -0700

    convert more {} to {d} and {s}

commit 5b981b1
Author: LemonBoy <[email protected]>
Date:   Sat Jan 2 12:29:37 2021 +0100

    Remove some unwanted changes

    Leftovers after a long rebase.

commit 608a73e
Author: LemonBoy <[email protected]>
Date:   Wed Dec 2 20:02:51 2020 +0100

    Decrement max_depth when printing slice elements

commit 04f37dc
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 22:20:44 2020 +0100

    stage2: Use {z} instead of {s} in generated Zig code

commit 1fbe89d
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 19:14:22 2020 +0100

    langref: Update langref to use {s}

commit d2f6fa1
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 17:06:52 2020 +0100

    Fix more stray uses of {} for formatting strings

commit 1ca2dec
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 15:43:28 2020 +0100

    std: Disable the special casing of {} for u8 slices/arrays

    Unless {s} is specified the contents won't be treated as a string.

commit 4420afe
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 13:28:38 2020 +0100

    tests: Use {s} instead of {} when formatting strings

commit 1c13ca5
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 13:19:30 2020 +0100

    stage2: Use {s} instead of {} when formatting strings

commit dd973fb
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 09:48:12 2020 +0100

    std: Use {s} instead of {} when printing strings

commit 5a06fdf
Author: LemonBoy <[email protected]>
Date:   Thu Nov 19 19:02:30 2020 +0100

    Use same brace pairs for arrays/slices/vectors

commit d4a8fc8
Author: LemonBoy <[email protected]>
Date:   Sat Oct 31 15:16:59 2020 +0100

    Small cleanup

commit 2b5e93f
Author: data-man <[email protected]>
Date:   Sat Oct 31 15:12:05 2020 +0100

    Add formatting for arrays

commit 6f53653
Author: LemonBoy <[email protected]>
Date:   Thu Oct 29 22:22:25 2020 +0100

    std: Refactor the slice formatting code

    Also fix the `*` specifier for more types, print an error message if we
    can't show the value address.

commit 5275280
Author: ryuukk <[email protected]>
Date:   Wed Oct 14 18:45:46 2020 +0200

    Formatting fix

commit 1d97747
Author: ryuukk <[email protected]>
Date:   Wed Oct 14 18:38:59 2020 +0200

    Pretty print Slices

    This code is adapted from pixelherodev paste from IRC

    I have added a new fmt option to handle printing slice values ``{v}`` or ``{V}``

    While i think it can be made the default, i want your opinion about it

    ```zig
        var slicea = [0]u32{};
        var sliceb = [3]u32{ 1, 2, 3 };

        std.log.info("Content: {v}", .{slicea});
        std.log.info("Content: {v}", .{sliceb});
    ```

    will print:

    ```
    info: Content: []
    info: Content: [1, 2, 3]
    ```

    Question:

    Should we drop ``{v}`` and make it the default behavior?

commit db1e97d
Author: Cameron Conn <[email protected]>
Date:   Sat Jan 2 18:06:51 2021 -0600

    Improve documentation for ArrayList, ArrayListUnmanaged, etc. (ziglang#7624)

    * Improve ArrayList & co documentation

    - Added doc comments about the validity of references to elements in
    an ArrayList and how they may become invalid after resizing operations.
    - This should help users avoid footguns in future.

    * Improve ArrayListUnmanaged & co's documentation

    - Port improved documentation from ArrayList and ArrayList aligned to
      their unmanaged counterparts.
    - Made documentation for ArrayListUnmanaged & co more inclusive and
      up-to-date.
    - Made documentation more consistent with `ArrayList`.

    * Corrections on ArrayList documentation.

    - Remove incorrect/unpreferred wording on ArrayList vs
      ArrayListUnmanaged.
    - Fix notes about the alignment of ArrayListAligned
    - Be more verbose with warnings on when pointers are invalidated.
    - Copy+paste a few warnings

    * add warning to replaceRange

    * revert changes to append documentation

commit 1856dfe
Author: LemonBoy <[email protected]>
Date:   Fri Jan 1 19:33:53 2021 +0100

    stage1: Use correct format specifier for size_t parameters

    Use `Iu` on Windows, the integer width depends on the target being
    a 32bit or a 64bit one.

commit af8eab5
Author: Sizhe Zhao <[email protected]>
Date:   Sat Jan 2 22:50:49 2021 +0800

    Fix usage message

commit 44c9bf5
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 12:21:19 2021 -0700

    std: disable a couple tests on windows

    They are passing but we're hitting OOM on the Windows CI server. This is
    to buy us more time until stage2 rescues us from the CI memory crisis.

commit 5a65796
Merge: a9c75a2 763d807
Author: Jakub Konka <[email protected]>
Date:   Sat Jan 2 20:08:37 2021 +0100

    Merge pull request ziglang#7506 from kubkon/fix-6923

    zig cc: detect framework include paths when native

commit 763d807
Author: Jakub Konka <[email protected]>
Date:   Sun Dec 20 11:52:25 2020 +0100

    Duplicate OSAtomic.h between aarch64 and x86_64

    The reason this is required is for two reasons: 1) the libc
    targeting `aarch64` macOS is slightly newer than that targeting
    `x86_64`, and 2) `OSAtomic.h` uses relative imports rather than
    system-wide imports for accompanying headers which clearly is an
    oversight on Apple's part. Until such time when `libkern` headers
    between `x86_64` and `aarch64` are identical, this will require a
    manual intervention to duplicate the relevant headers between the
    respective architectures.

commit 91a35e1
Author: Jakub Konka <[email protected]>
Date:   Sun Dec 20 11:45:48 2020 +0100

    Detect native iframework dirs on macOS

    This commit adds default search paths for system frameworks
    on macOS while also adding `-isysroot` for OS versions at least BigSur.
    Since BigSur (11.0.1), neither headers nor libs exist in standard
    root locations (`/usr/include`, `/System/Library/Frameworks`). Instead, they
    are now exclusively part of the installed developer toolchain (either
    via XCode.app or CLT), and specifying `-isysroot` allows us to keep
    using universal search paths such as `/System/Library/Frameworks` while
    only changing the include flag from `-iframework` to
    `-iframeworkwithsysroot`.

commit 33e53d7
Author: g-w1 <[email protected]>
Date:   Thu Dec 31 10:21:58 2020 -0500

    update .gitignore to include /release/ and /debug/

commit a1a1929
Author: g-w1 <[email protected]>
Date:   Wed Dec 30 21:04:27 2020 -0500

    Fix ziglang#7296:

    * makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.

commit 2561168
Author: LemonBoy <[email protected]>
Date:   Tue Dec 29 13:00:01 2020 +0100

    std: Clean up some tests

    No functional changes, remove some dead code.

commit 88634f0
Author: LemonBoy <[email protected]>
Date:   Tue Dec 29 12:58:47 2020 +0100

    stage1: Allow variable capture for multi-prong switch arms

    Handle the multi-prong case as we do with range cases.

    Closes ziglang#7188
@g-w1
Copy link
Contributor Author

g-w1 commented Jan 5, 2021

Sorry for the 2 merge conflicts at the end, I know they clutter stuff up. I tried to rebase, but it was asking me to resolve conflicts multiple times, so I thought a merge would be easier, but the downside is that it creates commits.

@g-w1 g-w1 requested a review from Vexu January 10, 2021 20:38
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

I think this is probably not the right direction for the codebase to go, and any further work on error sets needs to incorporate inferred error sets.

There is too much unrelated stuff in this PR across too many commits. Can you try to break this into smaller, more mergeable chunks?

@@ -1596,6 +1640,123 @@ pub const Type = extern union {
};
}

/// Asserts the type is error_set or error_set_single or anyerror and that if it is error_set, it's decl has been analyzed
/// If it is error_set_single, it will return the []const u8, otherwise a pointer to the map with the error_set or void for anyerror
pub fn getErrs(self: Type) union(enum) { err_single: []const u8, multiple: *std.StringHashMapUnmanaged(u16), anyerror: void } {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think putting this in type.zig is viable - we need the concept of "resolving" an error set which is the part where it figures out what all errors are in the set. Resolving an error set could cause compile errors, which will need to be attached to a Module. So I think this code does not belong here.

if (b.tag() == .anyerror)
return true
else
return false;
Copy link
Member

Choose a reason for hiding this comment

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

This logic is not correct, because (error{Foo} || anyerror) == anyerror is true. An inferred error set could be the LHS too. And again the concept of "resolving" an error set applies here. I think error sets are one of the trickier things to get right here and I don't want to go down a path that leads us towards bugs. Probably even the first implementation of error sets should include inferred ones.

@g-w1
Copy link
Contributor Author

g-w1 commented Jan 11, 2021

Yes, I think it is a good idea to split this into multiple prs. Thanks for the feedback. PRS incoming!

@g-w1 g-w1 closed this Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants