ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<Cadey> specifically, in zig/lib/std/special/start.zig `wasm_freestanding_start` is calling `callMain` but discarding the return code
<msiism> andrewrk: Ok, I just can't, well, I can't really put into words how exactly i don't understand that... I mean I (think I) understand what a data type is, like an integer value of 1 or the return type of a function. But then, a command, like `break` is “not data”, is it? That's why I can't really imagine what, e.g., `break` having a type would really mean.
<andrewrk> Cadey, ah yes. wasm32-freestanding does not provide a way to deal with the error code. your OS does, so wasm_freestanding_start is not the correct entry point. give me a sec I have a diff for you to try
<Cadey> :=1:
<Cadey> :+1:
<andrewrk> Cadey, can you try this diff? https://clbin.com/ygcoZ -> 2 things: (1) olin os package should export _start and call main (2) your target should be `wasm32-other`, not `wasm32-freestanding`
<andrewrk> msiism, "noreturn" is a type that means "not data"
<Cadey> andrewrk: from the os package, how do i call main()?
<Cadey> just `main()`?
<andrewrk> you can look at the file that diff patches as an example
<andrewrk> hm maybe the std lib should expose that callMain function
<msiism> andrewrk: Hm... ok. And what then is the rationale behind having a data type that has the meaning of ”not data”? (If that's already explained somewhere, a link will do.)
ur5us has quit [Ping timeout: 252 seconds]
<Cadey> andrewrk: std.os.raise unimplemented for this target
<Cadey> i'm gonna experiment with making callMain pub
<msiism> andrewrk: Ok, thanks. Seems like I simply ran into something here that's just way over my head. Not a big deal.
msiism has left #zig [#zig]
<andrewrk> Cadey, raise is getting pulled in from abort(), which is getting pulled in from the default panic impl
<Cadey> huh, i thought i had a panic impl already
<andrewrk> we should probably have a way to override the default panic in the os layer as well, check std/builtin.zig:425
<Cadey> ah yep, there's a way to override it
<Cadey> it's in `root.panic` though, would it be safe to move it to `root.os.panic`?
<andrewrk> yeah you can already override it per-application, but you probably can provide a better default in the os layer as well
<andrewrk> someone might want to override panic while using your OS layer package
<Cadey> true
<andrewrk> I suggest to allow OS layer override inside default_panic impl
<andrewrk> or you could provide abort() instead
<Cadey> still getting the `std.os.raise unimplemented for this target` error
ur5us has joined #zig
<andrewrk> here's another diff to apply https://clbin.com/FiLBE
<Cadey> kk
<Cadey> `error: container 'std.os.system' has no member called 'abort'`
<Cadey> olin.zig: https://clbin.com/AvLCG, allyourbase.zig: https://clbin.com/VaSar
<pixelherodev> std.os.system should be your OS layer IIRC
<pixelherodev> i.e. @import("root").os
<Cadey> yeah, that's what's confusing me too
<andrewrk> Cadey, fyi that panic function isn't pub
<pixelherodev> Cadey, you put it in a system struct
<andrewrk> pixelherodev, it is, look at https://clbin.com/AvLCG
<pixelherodev> That's what I'm saying - wait - you mean it's *supposed* to be?
<pixelherodev> ... mine isn't...
<pixelherodev> Was the OS layer changed?
<andrewrk> I don't think so
<pixelherodev> I think that's wrong then
<andrewrk> pixelherodev, Indomitable has it in a system struct too
<pixelherodev> ... wait I do?
<andrewrk> yeah I sent you that PR
<pixelherodev> Ah, okay
<pixelherodev> Ah - `pub const system = if (@hasDecl(root, "os") and root.os != @This()) root.os.system`
<pixelherodev> That does root.os.system instead of root.os
<pixelherodev> Which now that I think about it makes sense
<pixelherodev> But doesn't solve the issue
<andrewrk> Cadey, I'm not sure why that error would be happening, can you double check stuff on your end? e.g. that the changes are getting picked up or whatever
<andrewrk> which line is giving the compile error?
<Cadey> /home/cadey/prefix/zig/lib/zig/std/os.zig:202:11: error: container 'std.os.system' has no member called 'abort'
<Cadey> and my copy of that file: https://clbin.com/ah9ot
<pixelherodev> Huh
<pixelherodev> That's weird
<andrewrk> make sure your application file has `pub` on your `os`. in the example you provided it is correct, but the panic function is not
<Cadey> i do
<Cadey> assuming `pub const os` is the right order
<andrewrk> yeah that should be fine
<andrewrk> let me try to reproduce
<andrewrk> both my zig checkouts have dirty working trees, good thing I have a third checkout
<Cadey> i'm almost at the level of making a fresh zig environment in a docker container lol
traviss has quit [Remote host closed the connection]
<pixelherodev> andrewrk, if you have a third, then "both" isn't entirely accurate now is it? :)
<andrewrk> 🤔
<pixelherodev> Oh, and regarding the earlier " there's --emit llvm-ir"
<pixelherodev> I know, that's what I used to produce the test files
<pixelherodev> (along with --strip for good measure)
<pixelherodev> But if the goal is to remove LLVm
<pixelherodev> LLVM*
<pixelherodev> and my real goal is to support a backend to *Zig*, not *LLVM*...
<pixelherodev> Then I'm going to need to switch the input source :P
<pixelherodev> I was going to ask actually: is the goal to remove LLVM completely? Or just as a mandatory dependency for native compilation?
waleee-cl has quit [Quit: Connection closed for inactivity]
<andrewrk> pixelherodev, my eventual goal is to make it an optional dependency of self-hosted
<pixelherodev> And remove it entirely for stage2?
<pixelherodev> Real question:
<pixelherodev> Will stage2 be able to generate LLVM IR?
<andrewrk> the zig language specification will not mention LLVM
<pixelherodev> Right but practically
<pixelherodev> Will LLVM be an alternative to e.g. x86?
<andrewrk> the ability to output llvm ir will always be an "extension" or "implementation defined" feature
<pixelherodev> Is that true of e.g. ARM also?
<pixelherodev> And practically
<andrewrk> that's a good question, how architectures fit into it
<pixelherodev> I'd support having LLVM IR as a backend, even if the dependency on LLVM as a library is removed
<andrewrk> still not quite sure what you're trying to figure out. I feel like I probably can answer it but haven't understood the question yet
<pixelherodev> With `-target`
<andrewrk> oh I see
<pixelherodev> Sorry, starting over:
<pixelherodev> Basically, will there be an alternate to `-emit llvm-ir` in stage2?
<pixelherodev> e.g. `-target llvm-ir`?
<andrewrk> you're suggesting a use case of LLVM IR (or bitcode) as a target, not necessarily with the actual LLVM project as a dependency
<pixelherodev> Right
<pixelherodev> That's why I was interested in the idea of a Zig-specific IR, but I feel like LLVM as a target is a better option that trying to stablize a Zig-specific IR
<andrewrk> I'll have to think about how that might work. it wouldn't really be an architecture, because if it was then every sub-architecture would be all the other architectures
<pixelherodev> Oh, that reminds me
<pixelherodev> Is there a way to override the LLVM target to a custom definition for Zig?
<pixelherodev> stage1
<pixelherodev> Right now I'm using i386-freestanding since that's the closest match
<pixelherodev> But it's not fully accurate, and if I want to try targeting e.g. z80 I need more customization
<andrewrk> Cadey, ok I can reproduce
<Cadey> \o/ my environment isn't as insane as i thought it was
adamkowalski has joined #zig
<andrewrk> oh, this is happening when building zig's freestanding memcpy/memset/ other libcalls like that
return0e has quit [Ping timeout: 250 seconds]
<pixelherodev> https://git.sr.ht/~pixelherodev/llvm_parser - a simple `make` will build the parser and two test files, one for the LIMN architecture (an ISA designed for the LIMNstation Fantasy Console - disclaimer: not by me :) and one for x86 (though since I haven't actually implemented the x86 backend or some needed instructions, the x86 backend is just a basic freestanding code being partly translated into x86 asm)
<pixelherodev> Warning: code is *very* ugly
<pixelherodev> That'll be fixed soon enough
<andrewrk> Cadey, there's still room for improvement here, but this is an improvement over status quo: https://clbin.com/xUkuC
<andrewrk> should get you past the abort() not found thing
<andrewrk> the error was correct; what was not clear is that it was happening when we were building our freestanding libc functions from source
<pixelherodev> Idea: std.os.is_overridden() function?
<andrewrk> pixelherodev, neat, I'll check it out.
<pixelherodev> Don't expect it to work on basically anything yet
<pixelherodev> Very rudimentary, I was focused on the core
<pixelherodev> Now that the general proof-of-concept works, I can actually flesh it out and add broad LLVM support :)
adamkowalski has quit [Quit: Lost terminal]
<pixelherodev> std.os.is_overridden idea: That way, instead of checking `if freestanding or other`, it allows overriding the code even when targeting supported systems, and doesn't result in accidentally checking only freestanding or other
<andrewrk> pixelherodev, I do want to make the self-hosted compiler have a straightforward way to add backends to it. idea bing you can add a minimal amount of data to an ISA database and then the compiler gains support for it as a backend
return0e has joined #zig
<Cadey> andrewrk: how do i import `lib/std/special/start.zig`?
<andrewrk> I want to make this data format flexible enough to even support e.g. a C code backend, potentially lllvm ir
<pixelherodev> You might be interested in ddevault's cozy idea
<andrewrk> Cadey, you would have to expose it in std/std.zig
<Cadey> :+1:
<Cadey> yep
<Cadey> that works
<Cadey> $ cwa -main-func _start allyourbase.wasm
<Cadey> All your base are belong to us.
<Cadey> error: Unknown
<Cadey> 2019/12/12 01:31:01 allyourbase.wasm: exit status 1
<andrewrk> grats
<Cadey> https://clbin.com/KNBYK here's the full diff
<pixelherodev> Nice!
<Cadey> thanks andrewrk :D
<andrewrk> np, mind PRing it so we can let the tests run?
<Cadey> will do
<andrewrk> why did you end up needing to expose start.zig ?
<Cadey> i was following the pattern used in other parts of `std`
<andrewrk> are you using callMain? because it's still private in your PR
<Cadey> oh
<Cadey> i see
<Cadey> so guess what patch i forgot to copy over from ~/prefix/zig
<Cadey> fixed
<Cadey> also, thank you for making the zig downloads list in json
<Cadey> that saves me so much time
<Cadey> would be nice if you could put the version tag in that json file to avoid some double-cut piping
<Cadey> for master*
<andrewrk> you mean like "0.5.0+c3d8b1ffe"
<andrewrk> ?
<Cadey> yeah
<Cadey> right now i'm extracting it with like
<Cadey> zig_version="$(basename $(curl https://ziglang.org/download/index.json | jq '.master["x86_64-linux"].tarball') | cut -d- -f4- | cut -d. -f1-3)"
<andrewrk> good point
<Cadey> which works, but feels kinda satanic lol
<pixelherodev> You think that's bad?
<pixelherodev> You should see my version extraction script for *my own program* :P
<Cadey> i mean
<Cadey> i've done some crimes against humanity with shell script before
<Cadey> but if i can avoid it, i'd like to
<pixelherodev> Literally uses nested for loops to find VERSION in a CMake file and then find the next token :P
<Cadey> dear god
<pixelherodev> He's absent right now, should I take a message?
<pixelherodev> My shell scripts are so bad they give deities migraines :)
mogu has joined #zig
traviss has joined #zig
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
<fengb> `note: '*align(4) const std.os.bits.wasi.sockaddr' has alignment 4`
mogu has quit [Ping timeout: 268 seconds]
lunamn has quit [Quit: leaving]
<pixelherodev> That reminds me. Saw a very unclear error earlier. "Type u64 cannot contain all 64-bit integers!"
<pixelherodev> Was an error in my code of course, but that was very confusing
mahmudov has quit [Remote host closed the connection]
<fengb> Also these silly sockaddrs really should be a tagged union -_-
<fengb> Oh... the method signature: `pub fn initPosix(addr: *align(4) const os.sockaddr) Address {`
return0e_ has joined #zig
return0e has quit [Ping timeout: 265 seconds]
dddddd has quit [Remote host closed the connection]
qbradley has joined #zig
darithorn has quit [Ping timeout: 246 seconds]
<frmdstryr> Is there like a "MemoryPool" allocator?
<pixelherodev> If not, I plan on writing one tomorrow anyways
<pixelherodev> I can always make sure to generalize it and then open a PR
traviss has quit [Ping timeout: 245 seconds]
<andrewrk> frmdstryr, what would MemoryPool do?
traviss has joined #zig
darithorn has joined #zig
ur5us has quit [Ping timeout: 250 seconds]
<fengb> andrewrk: initPosix uses align(4) but wasi defines sockaddr as align(max_align_t) https://github.com/CraneStation/wasi-libc/blob/master/libc-bottom-half/headers/public/__struct_sockaddr.h#L10
<daurnimator> andrewrk: Cadey: re: os.io.getStd*: it sounds like you want the os lib to provide a mixin :)
<daurnimator> I'd add in io.zig: `const os = if(@hasDecl(root, "os")) root.os else std.os; pub usingnamespace os.io;`
<fengb> Should I just ignore the wasi alignment for now?
<frmdstryr> I'm thinking the MemoryPool allocator would be more or less an ArrayList Fixedbufferallocator's
<daurnimator> frmdstryr: huh?
<daurnimator> frmdstryr: do you mean an arena allocator that can free?
<frmdstryr> when one FixedBufferAllocator is deinited it's space goes back into the pool
<fengb> ObjectPool with fixed sizes?
<daurnimator> I had one in the works.... but got messed up that align is non-comptime.... except when its comptime
<frmdstryr> fengb: Yes, is there an object pool?
<andrewrk> fengb, that should be fine, I'm sure max_align_t is at least align 4
<fengb> It's 8 or 16. But neither will work with the existing code that's only align(4)
<andrewrk> if initPosix takes something align(4) that specifies a minimum alignment
<frmdstryr> daurnimator: Yes, just it free's back into a pool instead of freeing using the child_allocator
<andrewrk> so if the wasi struct is aligned 8 or 16 it will work
<fengb> It's trying to build the wasi struct
<daurnimator> frmdstryr: remind me tonight and I can go over mine with you if you want?
<frmdstryr> I can take a look if you have it somewhere
<andrewrk> fengb, I see. we should use a constant from bits instead of 4 then
ur5us has joined #zig
<daurnimator> frmdstryr: it's in a git stash somewhere on my home desktop
<fengb> Ah okay, would it make sense to put `pub sockaddr_alignment = 4` into all the other os bits?
<fengb> And set sockaddr_alignment = max_align_t for wasi
muffindrake has quit [Ping timeout: 276 seconds]
muffindrake has joined #zig
<fengb> I'm also getting a weird issue where initUnix just pops into existence and errors out the compiler. Deleting the method fixes the compile error so I'm not sure why it's being built
<frmdstryr> daurnimator: Just got error.FileDescriptorAlreadyPresentInSet
<daurnimator> frmdstryr: great; I'm not the only one!
<daurnimator> frmdstryr: would be fantastic to get that debugged/fixed
<frmdstryr> It doesn't really make sense, I'm only using one connection
<daurnimator> it seems to happen when an epoll wait gets picked up in another thread
<frmdstryr> Were you reusing frame pointers?
<frmdstryr> It started when I tried doing that and doesn't happen if I don't
<daurnimator> 'reusing'?
<andrewrk> fengb, yes I'm ok with this. we may benefit from putting it in the sockaddr struct, since that namepsace is sort of "unclaimed" in terms of posix
<andrewrk> actually I think it should just be @alignOf() whatever the union type is
<andrewrk> there's a type that is supposed to be allowed to be pointer casted to any sock addr type
<andrewrk> that type should be properly aligned, and then we can use @alignOf() on it
Sargun has joined #zig
<Sargun> Is there a zig style guide
<pixelherodev> Thought experiment: second else clause to if/else statements
<pixelherodev> Basically: `if (a) {} else if (b) {} else {} else {}`
<pixelherodev> Not necessary though, there's a number of ways to accomplish the same thing already
<pixelherodev> I just find the idea of a second else clause amusing
<daurnimator> pixelherodev: when would it run?
<fengb> andrewrk: I think that's where the align(4) came from. The base struct (sockaddr) is partially built and thus has a natural alignment of 2. It really should be the max of (sockaddr_in, sockaddr_in6, sockaddr_un)
<fengb> Wasi is apparently the only one that aligns the common struct correctly >_>
<andrewrk> yeah, can we fix by aligning the common struct correctly for the other systems?
<fengb> Sure, I can add an explicit alignment in the same style
ur5us has quit [Ping timeout: 250 seconds]
<fengb> Another question — I can't figure out what's causing this to be compiled: https://github.com/ziglang/zig/blob/master/lib/std/net.zig#L220
<fengb> Deleting the method altogether convinces the compiler to continue
<daurnimator> fengb: printing/formatting the struct is usually the source of such a thing
<Sargun> I'm going to ask a very newb question. Why is this segfaulting? https://gist.github.com/sargun/bf85419cd4f3066d535e193282617937 -- And I guess, how would I figure out why it's segfaulting?
<daurnimator> Sargun: first though looks like you're on an old release/colmmit?
<pixelherodev> daurnimator, basically if the first else *doesn't* run - that is, if any of the previous branches are taken
<Sargun> daurnimator: of zig? I'm on 0.5.0
<daurnimator> Sargun: segfault when building or running it? a quick once-over I don't see any obvious issues
<Sargun> daurnimator: When running it.
<daurnimator> Sargun: k. most of us are on master now. so much changes so quickly :)
<Sargun> It's not even doing anything right now, except maybe allocating some memory.
<Sargun> ah
<daurnimator> Sargun: so first thing I would do is to run it under gdb and get a backtrace
qbradley has quit [Ping timeout: 260 seconds]
<pixelherodev> ^
<pixelherodev> That's always the first thing to do on a segfault
<pixelherodev> Second is often valgrind, which is underratedly helpful with segfaults IIRC
<Sargun> I ran it already (under lldb)
<Sargun> #0 0x0000000000000000 in ?? ()
<Sargun> #1 0x0000000000203e9c in __unnamed_322 ()
<Sargun> #2 0x0000000000000000 in ?? ()
<pixelherodev> Huh
<Sargun> and it's compiled in debug mode
<pixelherodev> That's... wat
<Sargun> I have a gift for breaking computers.
<daurnimator> Sargun: are you stripping the executable or something? that's not a backtrace I expect to see
<pixelherodev> ^
<Sargun> I mean, the exact invocation I'm using: zig build-exe --verbose-cc src/main.zig -lc && ./main
<Sargun> And I also tried blowing away the zig cache
<daurnimator> Sargun: `gdb ./main` `r` `bt` ?
<Sargun> daurnimator: yep, that's what yielded the above output
<pixelherodev> Check the IR?
<pixelherodev> Assembly, rather
<Sargun> How do I dump the llvm IR
<Sargun> Yeah, I'm currently looking through the assembly
<pixelherodev> Do you know _unnamed_322 corresponds to?
<Sargun> Zig assembly isn't so pretty
<Sargun> Nope
<pixelherodev> Mind pastebinning it so I can took a look?
<Sargun> I'm just objdump'ing main. Is there a better way to go about this?
<pixelherodev> ... yeah that won't be pretty
<pixelherodev> Try compiling with `-emit asm`
<pixelherodev> Should produce main.s instead of main
<Sargun> Invalid argument: -emit
<pixelherodev> --emit then
<pixelherodev> My bad
<daurnimator> Sargun: so I think the issue is that `.Events = [_]Event{` doesn't do what you might want?
<daurnimator> .Events is a pointer. and you're trying to initialise it to an array
<daurnimator> on master it has a compile error as it should
<Sargun> Aren't arrays just pointers?
<daurnimator> no
<daurnimator> they're actual chunks of data
<pixelherodev> In some languages (*cough* C *cough*), arrays *implicitly convert* to a pointer to the first element, but in reality, they're distinct
<Sargun> yeah, I'm coming from C / Go.
<fengb> Well Go arrays aren't pointers either but using them directly isn't very common
marler8997_ has joined #zig
<pixelherodev> I got the transpiled code running! :)
<pixelherodev> At first there was a bus error because I gave it the wrong origin, but now it's busily doing nothing!
<pixelherodev> Now to just implement array values properly so I can test a Puts :)
ltriant has quit [Ping timeout: 250 seconds]
<fengb> daurnimator: expectError is somehow triggering the method's existence. Any ideas on why?
<fengb> Well... any printing. I've tried deleting the format() and it still breaks
<pixelherodev> What's the context for this?
<fengb> This method can't build in wasi because it doesn't support sockaddr_un
<fengb> But it's also not referenced so the compiler shouldn't be building it
<pixelherodev> What from std.net *are* you using? Anything?
<fengb> Just trying to run the test
<fengb> zig test --override-lib-dir lib lib/std/net.zig -target wasm32-wasi
<pixelherodev> Weird
<pixelherodev> Only place that's directly used in std.net is connectUnixSocket
<pixelherodev> And that's not used anywhere in std.net or the tests...
<fengb> Yeah, the bufPrint and expectErrors are the triggerpoints
<fengb> But I'm not sure how that would force the method into existence
<pixelherodev> Does parseIp use it?
<pixelherodev> Because that's the most obvious conclusion
<pixelherodev> bufPrint and expectError would force addr to be resolved
<pixelherodev> Which would force parseIp and thus indirectly initunix
<pixelherodev> But it doesn't look like they use it...
<fengb> Something in fmt.format
return0e_ has quit [Read error: Connection reset by peer]
return0e has joined #zig
<pixelherodev> Then why would expectE - oh wait, that probably formats...
<pixelherodev> Could it be a bug in lazy analysis?
<pixelherodev> Also, shouldn't that function (initUnix?) print an error and do unreachable on wasi anyways?
<pixelherodev> So if someone tries using it they'll know why it's not an option
<fengb> I can set it to return an error with a comptime block, but that feels like working around the symptom
<fengb> ... I'm pretty sure @typeInfo is causing it but that makes no sense
darithorn has quit [Ping timeout: 250 seconds]
marler8997_ has quit [Ping timeout: 268 seconds]
squeek502_ has joined #zig
squeek502 has quit [Ping timeout: 276 seconds]
squeek_ has joined #zig
ur5us has joined #zig
squeek502_ has quit [Ping timeout: 268 seconds]
<pixelherodev> fengb, I'd argue that it should return an error even without the bug
<pixelherodev> Because it's not out of the question that someone might try using it even though it's unsupported
<mq32> hey
<mq32> what is the current state of the AVR backend?
<mq32> i remember it being "you can compile objects, but do not link"
<pixelherodev> I was planning on debugging it, but...
<pixelherodev> Well, first there were some IRL problems, then I had to rebuild LLVM with support for it, then Zig was annoyed because LLVM=10 but Clang=9 so now I need to rebuilt Clang...
<pixelherodev> So I have no clue atm
<dch> wrt https://github.com/ziglang/zig/pull/3197 & insufficient RAM I can provide something suitable.
<mq32> pixelherodev: hmm.
<mq32> i want to hack something over the weekend and think about using zig for it. but it's an AVR project, so i require the AVR backend :(
<mq32> hmm
<mq32> void (%"[]u8"*, %std.builtin.StackTrace*)* bitcast (void (%"[]u8"*, %std.builtin.StackTrace*) addrspace(1)* @panic to void (%"[]u8"*, %std.builtin.StackTrace*)*)
<mq32> seems like there's a function pointer messup
<pixelherodev> That reminds me
<pixelherodev> Function pointers inside of packed structures appears to be borked
<pixelherodev> Fortunately, it's a simple enough structure (and my backend doesn't actually tweak non-packed structures) so it's fine even non-packed
<mq32> yeah i think the problem with the AVR backend is that zig doesn't care for address spaces right now
FireFox317 has joined #zig
FireFox317 has quit [Remote host closed the connection]
<mq32> pixelherodev, andrewrk: looks like the AVR target regressed from 0.5 to "now": https://godbolt.org/z/_3xoVZ
<pixelherodev> hmm
ur5us has quit [Ping timeout: 250 seconds]
<mq32> okay, i'm doing a fake bisect now :D
<mq32> still works: zig-linux-x86_64-0.5.0+1f0bcefe4
<mq32> zig-linux-x86_64-0.5.0+55685ae78 does also work
<mq32> all other variants i have installed do not work
<Snektron> I though avr was llvm 10
<pixelherodev> It is
<Snektron> can't wait to dump avr-gcc in favor of Zig tbh
<mq32> Snektron: oh yeah
<Snektron> i'm not a fan of those PORTB macros
<bgiannan> no sure i get where i should put my custom panic function. what's the root source file ? (https://ziglang.org/documentation/master/#Root-Source-File)
<mq32> well, the macros are okayish
<mq32> bgiannan: the file you start your compilation with
<mq32> where your main is located in
<mq32> so if you do "zig build-exe foobla.zig", foobla.zig is your root source file
<bgiannan> that's what i thought but my panic function is not called
<mq32> pub fn panic(msg: []const u8, stackTrace: ?*std.builtin.StackTrace) noreturn { }
<mq32> should be the signature
<bgiannan> the signature is correct (zig complained when it wasn't), but it doesn't seem to be called;
marmotini_ has joined #zig
<mq32> huh
<mq32> just do an @panic() and try :D
<mq32> Snektron: you can do the PORTB in zig probably like this:
<mq32> extern PORTB : u8;
<mq32> at least for 8bit avr
<bgiannan> i managed to trigger an error and i have the regular stacktrace instead of my simple debug.warn
<Snektron> mq32, PORTB isn't a value, its a macro defined as (volatile uint8_t)(value)
<Snektron> `*(volatile uint8_t*)(value)`
<bgiannan> ok so @panic calls it
<bgiannan> so i just don't understand when panic is called
<Snektron> but it'd just be an extern volatile pointer instead
<mq32> Snektron: you can also just extern it and define it via linker script
<mq32> bgiannan: panic is called when you do checkable undefined behaviour
<mq32> so overflow, out-of-bounds check, ...
<mq32> but only in debug and release-safe mode
<bgiannan> oh
<mq32> invalid pointer access is non-checkable undefined behaviour
<mq32> Snektron: i once made an attempt for an C++ lib for AVR
<mq32> it was gorgious template magic :D
<mq32> avr::io::pin<avr::io::portb, 3> led0;
* pixelherodev pukes
<mq32> led0 = avr::on;
<pixelherodev> no offense
<Snektron> thats not so bad tbh
<mq32> it compiled really well, so the line above is a single instruction "set bit"
<mq32> pixelherodev: that's just a HAL, would do the same thing with zig
<pixelherodev> I just find templates.... ugly
<pixelherodev> It's not a problem I have with you
<Snektron> pixelherodev, did you see my solution for some advent of code last week
<pixelherodev> It's one I have with C++
<pixelherodev> Nope
<mq32> const led0 = avr.io.Pin(.portb, 3);
<mq32> led0.set();
<mq32> :)
<pixelherodev> ...
<mq32> Snektron: its funny that you use the turing-completness of c++ syntax :D
<Snektron> Its actually just a pure functional language with some really weird syntax
<Snektron> With pattern matching built-in
<Snektron> i have another nice repository
<mq32> yeah, but it's syntax :D
<mq32> so, c++ code is undecidable :D
<Snektron> its perfectly decidable
<Pistahh> Snektron: this template based fizzbuzz.. it is.. it is.. no words. :P
<Snektron> i like the private member access even more, though i didn't come up with it
<mq32> Snektron: you can write a turing machine emulator with that => undecidable
<mq32> :D
<Snektron> I think there was actually a template function to check wether an expression is undecidable
<Snektron> Because if a constexpr function in c++ errors or cannot be calculated, it'll defer to runtime
<Snektron> so all you have to do is check wether that function is evaluated
<Snektron> also, mq32, there is a maximum template depth so its pretty much guaranteed to error at some point
marmotini_ has quit [Remote host closed the connection]
ltriant has joined #zig
ltriant has quit [Client Quit]
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
<daurnimator> you can get pretty far with plain C too
<daurnimator> the secret to stupid hacks in C is that ternarys can return different types
<daurnimator> (for each branch)
dimenus has joined #zig
<dimenus> Snektron: you said you have vulkan experience, yeah?
return0e_ has joined #zig
return0e has quit [Ping timeout: 250 seconds]
<frmdstryr> daurnimator: I'm trying the h1 branch again, getting the error error: no member named 'ensureCapacity' in struct 'std.io.BufferedInStreamCustom(4096,std.fs.file.File)'
<daurnimator> frmdstryr: uh... traceback?
<daurnimator> frmdstryr: doh. should be `try self.fifo.ensureCapacity`
<frmdstryr> try buf_stream.fill(start_contination_line, 1);
<frmdstryr> in h1_connection.zig:178:32: error: expected 2 arguments, found 3
<daurnimator> hang on.... let me tidy up and force push
<frmdstryr> Also push the script you're using into tests/standalone/http_server/ or something
waleee-cl has joined #zig
traviss has quit [Ping timeout: 250 seconds]
<daurnimator> frmdstryr: pushed.
<aperezdc> I am trying to rewrite an existing C project, piecewise, for the fun
<frmdstryr> thanks will give it a try
<daurnimator> frmdstryr: it seems to randomly get stuck all the time...
<daurnimator> and if I push it hard with `wrk` then it fails with that EEXIST error
<aperezdc> I feel like the way argc/argv are forwarded to the foo_main() functions (which are still in C) is unnecessarily complicated. As I am a total Zig newbie, comments and suggestions are super welcome :)
<frmdstryr> yeah I noticed wrk seems to close and reopen connections periodically
<daurnimator> that should be fine...
<daurnimator> aperezdc: why do I know your name?
<frmdstryr> I think it's trying to read before the previous handle is removed
<daurnimator> aperezdc: hmmm... arcan?
<aperezdc> mmh, Lua mailing list?
<daurnimator> aperezdc: that would work too
<daurnimator> aperezdc: some misc notes: make use of null terminated pointers: `[*:0]` instead of `[*]`
<aperezdc> I posted Arcan PKGBUILDs to package it for Arch Linux, too
<aperezdc> oh, I hadn't noticed the null-terminated pointers in the manual (still reading through as I try things), neat
kristoff_it has joined #zig
<daurnimator> aperezdc: `if (......) else unreachable` is weird
<aperezdc> daurnimator: FWIW, I've been a fan of lua-http for quite some time :-D
<aperezdc> ah, the “else unreachable” probably I am going to change into some kind of print error + exit
<aperezdc> unreachable is more of an assertion, then, isn't it?
<daurnimator> aperezdc: C assertion yes. (lua assertion no)
<daurnimator> aperezdc: I assume the applets are going to be somewhat dynamic? otherwise I'd suggest making an enum of them
<daurnimator> aperezdc: also, run `zig fmt` over your code :)
<daurnimator> aperezdc: no need to use argsAlloc: just use std.process.ArgIterator
<frmdstryr> daurnimator: Did you push to github?
<daurnimator> frmdstryr: yes. my h1 branch.
<aperezdc> mmh, the applets are a fixed set, I suppose an enum makes more sense, yeah
<frmdstryr> It says last update 5 days ago?
<daurnimator> frmdstryr: I amended. it keeps the old author time (but updates the commit time)
dddddd has joined #zig
<frmdstryr> Yeah it works now
<frmdstryr> For whatever reason the original test file I had was segfaulting
<aperezdc> mmh, zig fmt is neat <3
<frmdstryr> It was using 85% cpu?
adamkowalski has joined #zig
<daurnimator> frmdstryr: oh I see one stupid mistake of mine (unrelated)
<frmdstryr> Also I'm interested to see what the raw http parser benchmarks at
<frmdstryr> I can't get how they're doing ~1.8GB/s
scientes has left #zig ["Leaving"]
<daurnimator> frmdstryr: its just the parser; not the network operations
<frmdstryr> I know, even with just the parser that I can't get near that
<frmdstryr> The fastest parse speed I can get is ~700MB/s
<daurnimator> are you doing it on all cores?
<frmdstryr> No that's a single thread
traviss has joined #zig
nofmal has joined #zig
<nofmal> hello guys, i have a newbie question
<nofmal> i tried to link my application with argon2
<nofmal> but everytime, it always says: error: /usr/lib/libargon2.so: undefined reference to explicit_bzero
<nofmal> i honestly have no idea what to do
Akuli has joined #zig
<fengb> Looks like that libargon2 requires glibc. Have you linked to libc? -lc
<daurnimator> error: incompatible types: '[3]u8' and '*const [3:0]u8'
<daurnimator> break :blk status.* == "204" or status.* == "304";
<daurnimator> ^ should those really be incompatible?
<frmdstryr> const & not const?
<fengb> It thinks one is a pointer. But why?
<nofmal> fengb: i have, but it still doesnt work
<nofmal> explicit_bzero()'s already in glibc as far as i'm concerned
<fengb> Zig doesn't link glibc by default
<nofmal> oh, i know. like i said, i've already linked libc in my build.zig
<fengb> Are you passing in a specific target?
<nofmal> not really, no
<fengb> Can you check `ldd [built-exe]`
<frmdstryr> Any ideas why this would happen? https://travis-ci.org/frmdstryr/zhp/jobs/624229792#L720
adamkowalski has quit [Ping timeout: 252 seconds]
<nofmal> fengb: sorry, how do i do that?
<fengb> `$ ldd [the zig executable]`
<fengb> glibc should be linked in, but if not that might be Zig using musl instead
<nofmal> oh you meant the compiler. gotcha, wait a sec
<nofmal> it says statically linked
<fengb> Er not the compiler, the binary you built
<nofmal> oh, in that case, libc is linked in
<nofmal> and so is libargon2
<fengb> Hmm, I'm out of ideas :/
<nofmal> ehh it's fine. thank you anyway
<daurnimator> nofmal: what version of glibc do you have?
<daurnimator> IIRC it was absent in 2.24
<nofmal> mine is 2.29
<nofmal> i'd checked the symbol table thing and it is there
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 245 seconds]
<andrewrk> ugh I'm tired of debugging corrupt unions in c++. wish I had zig's "use of inactive union field" safety
wootehfoot has joined #zig
kristoff_it has quit [Ping timeout: 276 seconds]
adamkowalski has joined #zig
<fengb> Does any other language allow you to use any union field but also error checks it?
<mq32> andrewrk: what about std::variant?
<Cadey> it looks like the tests on master are failing, i'm gonna look into it and see if i can fix them
<mq32> it's the c++ way of "tagged union" with pain
adamkowalski has quit [Ping timeout: 265 seconds]
<daurnimator> misc note before I go to bed: in mid January I'll be at Linux.conf.au. I'd love to be able to give a demo of writing a kernel module in zig. There's a backlog of related items at https://github.com/ziglang/zig/projects/5
<andrewrk> daurnimator, that's a great motivating use case
<andrewrk> Cadey, it's just a timeout on the aarch64 server, tests running too long
<andrewrk> it's a crime really, they're giving us like 60 cpus and we're using 1 for 2 hours and getting timed out
<Cadey> ah, when is the master release updated?
<andrewrk> you are correct that the failing ci blocked the download page from getting updated
<Cadey> ah, lol, makes sense
<daurnimator> andrewrk: oh shit; I forgot: I think that arm box on packet.net is still running?
<andrewrk> daurnimator, I'm not personally using it, although I believe we gave access to several other community members, including LemonBoy and markfirmware
<daurnimator> ah okay. as long as its in use
<fengb> Is it a physical aarch64 box?
<andrewrk> daurnimator, we should probably advertise that it is available for community members to experiment with
<daurnimator> fengb: yes. a very very beefy one
<andrewrk> idk maybe on the wiki or reddit announcement or something
<daurnimator> andrewrk: how do you want to manage access?
* daurnimator isn't familiar with nix tooling
<andrewrk> btw anyone else want to mod /r/zig? right now it's just me, and what if I die
<daurnimator> andrewrk: sure. same username
<Cadey> i'm a somewhat avid redditor, /u/shadowh511
<mq32> andrewrk: and what if I die
<andrewrk> daurnimator, I think we can get away with "if you ask for it, you get a user account" for now
<daurnimator> andrewrk: though if you die... I think the bus factor is still 1
<mq32> then i don't think zig will ever get awesome again!
<daurnimator> andrewrk: I more meant: how are you deploying keys onto the box
<andrewrk> asking people for their pub keys, manually creating user and copying the pub key in there
<daurnimator> Cadey: I know how to *get* keys. the question is how to create a user account and populating things
<daurnimator> oh I thought there was nix magic around that sort of thing
<andrewrk> would be happy to hand off admin of this box to someone else
<daurnimator> mq32: any chance you'll be going past brussels soon?
<daurnimator> (or anyone else?)
<mq32> brussels?! :D
<aperezdc> FOSDEM?
<mq32> ah, i think you told here already some time
<aperezdc> I usually go, but can't make it thus time due to $LIFE
<mq32> i just know the name, but i have no idea what FOSDEM is
nofmal has quit [Remote host closed the connection]
<aperezdc> It's a conference, two days, usually first weekend of February
<daurnimator> aperezdc: actually I just want someone to pick up beer for me :P
<mq32> ah
<mq32> nah, i'm not the conference guy
<aperezdc> Well, it's more of a huge gathering of free software people
FireFox317 has joined #zig
<aperezdc> With lots of talks, because conference, too
<aperezdc> For me it's more of a social event
<aperezdc> ;-)
dddddd has quit [Ping timeout: 250 seconds]
<mq32> yeah, doesn't sound that appealing to me, sorry :D
deesix has quit [Ping timeout: 268 seconds]
<mq32> i'm more the demoparty guy ^^
<aperezdc> Oh, I like those when they're the real deal, with actual demoscene competitions
<aperezdc> Not the ones which have devolved into LAN-parties
* aperezdc should try to attend Assembly sometime
<andrewrk> daurnimator, invite sent
<andrewrk> there is nix magic probably for user accounts. I don't really know anything about nixos beyond setting up my personal dev environment
<daurnimator> /bed
<daurnimator> 5:20am and I have to get up in.... 3 hours
<andrewrk> goodness
<fengb> Good night
<aperezdc> Ouch, make the most of the sleep time, daurnimator !
<Cadey> has anyone made a cgi library in zig yet?
<andrewrk> fengb, can you help Cadey get the CI green in #3891 ? what's happening is that we're trying to call wasi.abort() which doesn't exist. it was working before because it used raise() but you showed me that they removed raise from wasi
<andrewrk> so basically, what should be the impl of std.os.abort() for wasi?
<andrewrk> it would be nice if there was just a single-page list of wasi syscalls
<mq32> aperezdc, come to UNC at 27,28th december in darmstadt!
<fengb> https://github.com/WebAssembly/WASI/issues/166 wasi hasn't defined a replacement for signals
<andrewrk> this is problematic, a trap can be resumed from
<fengb> So anything we do is a hack
<Cadey> wait what?
<andrewrk> ok. I think it should be @breakpoint(); exit(1);
<aperezdc> mq32: thanks, but not at this time... it's a bit complicated to go to conferences with a newborn at home O:-)
<mq32> aperezdc: damn, stop fork()ing! :D
<mq32> this just slows down life processing
dddddd has joined #zig
<Cadey> andrewrk: how do i install the stuff in `deps`?
<Cadey> the zig build docs command is wanting llvm-config from there
<andrewrk> deps/ is a red herring
<Cadey> Unable to spawn the following command: file not found
<Cadey> /deps/local/bin/llvm-config --shared-mode
<Cadey> oh, do i need to do the cmake rain dance?
<andrewrk> interesting, I hadn't considered this use case, downloaded zig binary against a source checkout
<andrewrk> this awkwardness stems from the fact that we're not self hosted yet
<fengb> Hmm, the docs are building wasi already?
<aperezdc> mq32: xDDDD
<mq32> *grin*
<andrewrk> I think the wasmer output is hard coded
<mq32> i wish you at least 1h of free time a day, aperezdc!
<aperezdc> mq32: wouldn't it be more like unfork()? that is: merging two processes into a new one?
<aperezdc> as in unfork(): https://github.com/whitequark/unfork
<aperezdc> mq32: thanks for the good wish, I have maybe... 30-40min to myself every other day
<aperezdc> a bit more when the grandparents come to help a bit; then what we do is sleeping
<mq32> it's something!
FireFox317 has quit [Ping timeout: 265 seconds]
<frmdstryr> project managers.... expect stuff they didn't even ask you to do to just magically work
lunamn has joined #zig
<fengb> That's just all non-technical people
traviss has quit [Ping timeout: 268 seconds]
FireFox317 has joined #zig
<frmdstryr> yes but that's expected :)
adamkowalski has joined #zig
adamkowalski has quit [Quit: Lost terminal]
<andrewrk> ooh, vexu is working on self-hosted translate-c
<andrewrk> excited about that
<mq32> *thumbs up*
kristoff_it has joined #zig
<FireFox317> He is not in here right? He's contributing so much, awesome to see that!
<FireFox317> Or she* :)
darithorn has joined #zig
ur5us has joined #zig
<Cadey> zig fmt is continuously so good
<Cadey> i have a lua script that's generating every HTTP status code from a json file, zig fmt makes it look nice :D
<fengb> Shouldn't that be a zig script? 🤔
<Cadey> probably
<Cadey> but when you're hammering things out, it's generally a good idea to start with what you understand _very well_
<fengb> Yeah I'm just trolling >_>
<andrewrk> I'd hack it up with a vim macro, wouldn't even write code for that
<Cadey> i'm not enough of an elder god for vim macros like that lol
<fengb> Word of god says he wouldn’t use his own creation 🙃
<andrewrk> lol
<andrewrk> you could chop off `StatusCode` from all those switch progns
<andrewrk> uhh you could also replace the entire body with @tagName(status_code)
<Cadey> TIL!
FireFox317 has quit [Ping timeout: 268 seconds]
Akuli has quit [Quit: Leaving]
<Cadey> by the way, to install that tool i'm using to generate that listing of the files: `go get github.com/rogpeppe/go-internal/cmd/txtar-c`
mahmudov has joined #zig
<dch> andrewrk: I'm interested in providing more freebsd ci capacity. in particular I'm not particularly limited by cpu nor ram constraints
<dch> how can I help?
<andrewrk> dch, what CI service are you offering?
<Cadey> what is zig's atoi?
<andrewrk> std.fmt.parseInt
<Cadey> thanks
<Snektron> Hold up
<Snektron> Why does mmap return -1 instead of a nullptr
<daurnimator> Snektron: because you can map null
<daurnimator> (on some architectures)
<daurnimator> Snektron: but also... you mean the C mmap right?
<daurnimator> Cadey: FWIW I've been looking into http pieces lately
<daurnimator> Cadey: I've been trying to figure out a StringMap that would work at compile time without too much luck :(
<Snektron> yeah i mean that
<daurnimator> Cadey: (for reason phrase mapping)
<Snektron> I have this really strange issue where when i mremap on one compute node it works but it returns EFAULT on the other
<daurnimator> Snektron: but also in general, for libc wrapped syscalls 0 is a success code. -1 is failure. look at e.g. sysctl
<daurnimator> Snektron: huh. I forget mmap exists. We should use it from the page allocator
<daurnimator> *mrema
<Cadey> how do i pass a non-const argument to a function?
<daurnimator> Cadey: pass a pointer to it
<Cadey> like &foo?
<daurnimator> Cadey: your function would need to take a *T instead
<Cadey> ah
tgschultz has quit [Read error: Connection reset by peer]
wootehfoot has quit [Read error: Connection reset by peer]
wootehfoot has joined #zig
mikdusan has quit [Read error: Connection reset by peer]
return0e_ has quit [Read error: Connection reset by peer]
wootehfoot has quit [Client Quit]
mikdusan has joined #zig
tgschultz has joined #zig
return0e has joined #zig
frmdstryr has quit [Ping timeout: 268 seconds]
<andrewrk> or you can make a copy of the parameter
<andrewrk> var mutable_thing = thing;
<Snektron> daurnimator, i was thinking that too
<Snektron> It seems like a decent option to make it more efficient
ur5us has quit [Ping timeout: 250 seconds]
<Cadey> zig-cgi is working!
<Cadey> the /metrics thing is a lie, but otherwise it works
<andrewrk> sweet!
<andrewrk> I'm almost done merging your PR
qbradley has joined #zig
<andrewrk> I added into the branch, un-special-casing the start code from the compiler
<andrewrk> so you'll have to change std.special.start.callMain to std.start.callMain
<Cadey> :+1:
<Cadey> sounds good to me
<andrewrk> but the cool thing is that std/start.zig no longer has any special casing in the compiler, it's just another std lib file like everything else
<Cadey> oh wow
<andrewrk> `comptime { _ = start; }` in std/std.zig makes it get analyzed; then the comptime block in start.zig has all the start logic of what symbols if any to export
<Cadey> lol
GrooveStomp has joined #zig
<Snektron> What if you @import std from another source file though?
<Snektron> Wouldnt that also import the bootstrap code
<andrewrk> Snektron, start code is always unconditionally analyzed for all builds
<andrewrk> this logic determines whether anything further is done: https://github.com/ziglang/zig/blob/7699b5b997c7a024a6d9558df0ec72d71ef402fe/lib/std/start.zig#L22-L44 nothing else in that file exports any symbols, unless explicitly done with @export in that comptime block
kristoff_it has quit [Ping timeout: 250 seconds]