feilich icon indicating copy to clipboard operation
feilich copied to clipboard

trying to support stage2 compiler

Open endel opened this issue 3 years ago • 2 comments

Hi @Luukdegram, thanks for your efforts on this lib, I'm currently researching and trying to understand TLS1.3/QUIC and this is being really helpful resource to me!

I'm trying to support the stage2 compiler for your lib here, would appreciate it if you can give me any direction I could take to fix these compilation errors:

feilich/src/tls.zig:617:23: error: values of type 'fn(*tls.Curve, [32]u8, *[32]u8) error{IdentityElement}!void' must be comptime known, but operand value is runtime known
        try self.genFn.*(self, private_key, public_key_out);
            ~~~~~~~~~~^~
feilich/src/tls.zig:617:23: note: use '*const fn(*tls.Curve, [32]u8, *[32]u8) error{IdentityElement}!void' for a function pointer type
feilich/src/cert/asn1.zig:194:44: error: values of type 'fn(*cert.asn1.Decoder, u8) error{ContextSpecific,EndOfData,InvalidLength,InvalidTag,OutOfMemory}!cert.asn1.Value' must be comptime known, but operand value is runtime known
                            return callback.*(self, @truncate(u3, tag_byte));
                                   ~~~~~~~~^~
feilich/src/cert/asn1.zig:194:44: note: use '*const fn(*cert.asn1.Decoder, u8) error{ContextSpecific,EndOfData,InvalidLength,InvalidTag,OutOfMemory}!cert.asn1.Value' for a function pointer type
error: test...
error: The following command exited with error code 1:

If I use main_tests.use_stage1 = true; config on build.zig all tests are passing.

Thank you!

endel avatar Aug 30 '22 18:08 endel

Update: managed to get past the compilation error (https://github.com/Luukdegram/feilich/pull/1/commits/d67b815cca3ce19a146766d1a98bfe8118a47f07), now the test suite is panicking here 👀:

Test [21/29] test.Object identifier... thread 984457 panic: access of inactive union field
feilich/src/cert/asn1.zig:330:9: 0x104f45f0b in decodeObjectIdentifier (test)
        identifier.object_identifier.data[0] = initial_byte / 40;
        ^
feilich/src/cert/asn1.zig:219:66: 0x104f27cc3 in decodeMaybeTag (test)
            .object_identifier => try self.decodeObjectIdentifier(),
                                                                 ^
feilich/src/cert/asn1.zig:169:35: 0x104f0d6ff in decode (test)
        return self.decodeMaybeTag(null);
                                  ^
feilich/src/cert/asn1.zig:405:37: 0x104f0e4cf in test.Object identifier (test)
    const value = try decoder.decode();
                                    ^
zig-dev/lib/zig/test_runner.zig:79:28: 0x104e722d7 in main (test)
        } else test_fn.func();
                           ^
zig-dev/lib/zig/std/start.zig:564:22: 0x104e73cab in main (test)
        },
                     ^
???:?:?: 0x18de1142f in ??? (???)
???:?:?: 0x0 in ??? (???)

endel avatar Aug 30 '22 19:08 endel

There was a bug in @unionInit that was fixed last night. It may be worth trying it again with the latest Zig master (you'll have to compile it yourself).

Luukdegram avatar Aug 31 '22 15:08 Luukdegram