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/
<daurnimator> mikdusan: btw, new recommendation would be std.fifo instead of std.Buffer
lunamn_ has quit [Quit: leaving]
marijnfs has joined #zig
marijnfs__ has quit [Ping timeout: 240 seconds]
<scientes> are slices guaranteed to be aligned?
crimson_penguin has quit [Ping timeout: 264 seconds]
mq32 has quit [Ping timeout: 268 seconds]
mq32 has joined #zig
data-man has joined #zig
<scientes> ummm, godbolt.org broke?
<scientes> it just says "no output file" for me
crimson_penguin has joined #zig
data-man has quit [Ping timeout: 260 seconds]
Ichorio_ has joined #zig
Jezza__ has quit [Ping timeout: 264 seconds]
ky0ko_ has quit [Remote host closed the connection]
crimson_penguin has quit [Ping timeout: 264 seconds]
ky0ko has joined #zig
<mikdusan> daurnimator: hmm... `readableSliceMut() / readableSlice()` vs. crypto, mem, array_list, buffer, all have `toSlice() / toSliceConst()`
<mikdusan> do we instead want `readableSlice() / readableSliceConst()` for consistency?
<scientes> hmmmmmm, why isn't alloc's alignment parameter comptime?
<scientes> this is preventing the pointer from getting an alignment annotation
crimson_penguin has joined #zig
<scientes> i don't think run-time alignment is useful
<scientes> because alignment is mostly to improve codegen
<tgschultz> Because it is an interface, I think. Comptime parameters can't really work with runtime-known function pointers.
<scientes> well malloc() generally switches on the size
<scientes> and interfaces in zig are entirely comptime
<scientes> tgschultz, my problem is that I want pointers made with directallocator to get annotated with a 4096 alignment
<tgschultz> ...no they aren't?
<tgschultz> Allocator is a struct of two runtime function pointers last I checked.
<scientes> yeah but its all static
<scientes> llvm can optimize it
<tgschultz> maybe, but the language doesn't treat it like that.
<andrewrk> pointers do get alignment annotations if you go through the std.mem.Allocator interface
<scientes> I just think annotation diretallocator results with aligned(4096) would be nice
mla has quit [Ping timeout: 265 seconds]
<scientes> and we already have comptime alignment on the other functions
<tgschultz> andrewrk, how does that work?
<scientes> 127 @memset(byte_slice.ptr, undefined, byte_slice.len);
<scientes> this isn't getting optimized out in --release-fast
<scientes> guess that is a llvm bug
<andrewrk> tgschultz, have a look at std.mem.Allocator.alignedAlloc
<tgschultz> Oh, right!
<tgschultz> I'd forgotten completely about those functions
<scientes> andrewrk, yeah, but why can't it put that when you use alloc() from directallocator
<scientes> as it knows it is 4096 or the page size
muffindrake has quit [Ping timeout: 246 seconds]
<andrewrk> scientes, in theory that should actually give more information to the optimizer. but if llvm can't deal with it, let's omit it in release fast mode
<andrewrk> scientes, you mean when you call the function pointer that has to match the non-aligned Allocator interface API?
<scientes> I could do it with @alignCast() but alignment is a run-time value, not comptime
<scientes> also we kind of need two @alignCast()s--one that only bumbs the alignment up, and one that sets it definitively
muffindrake has joined #zig
<scientes> but really it should jsut go up, and to set it definitely you need to use @ptrCast() IMHO
<scientes> because if it wasn't right, they you already have UB
<andrewrk> even @ptrCast won't bump it down
<scientes> oh, that is @intToPtr() then
<scientes> call void @llvm.memset.p0i8.i64(i8* align 1 %byte_slice.sroa.0.0.copyload.i, i8 -86, i64 1073741824, i1 false) #3, !dbg !1234, !noalias !1225
<scientes> -86 is 0xaa
<scientes> so our release-fast is messed up
<daurnimator> mikdusan: .readableSliceMut() is essentially internal: it's so you can "unget"
<daurnimator> mikdusan: the Mut suffix came from andrew
chemist69 has quit [Ping timeout: 245 seconds]
chemist69 has joined #zig
muffindrake has quit [Quit: muffindrake]
muffindrake has joined #zig
doublex_ has joined #zig
doublex has quit [Ping timeout: 245 seconds]
ltriant has quit [Quit: leaving]
doublex_ has quit [Ping timeout: 240 seconds]
dingenskirchen has quit [Read error: Connection reset by peer]
dingenskirchen1 has joined #zig
dingenskirchen1 is now known as dingenskirchen
SimonN has joined #zig
SimonNa has quit [Ping timeout: 240 seconds]
doublex has joined #zig
vexu has joined #zig
_whitelogger has joined #zig
<mq32> thanks andrewrk and LemonBoy for fixing all those bugs :)
traviss has quit [Remote host closed the connection]
casaca has quit [Ping timeout: 276 seconds]
jjido has joined #zig
FireFox317 has joined #zig
casaca has joined #zig
traviss has joined #zig
dantix has joined #zig
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
return0e_ has joined #zig
traviss has quit [Remote host closed the connection]
vexu has quit [Quit: WeeChat 2.6]
FireFox317 has quit [Remote host closed the connection]
Ichorio_ has quit [Ping timeout: 264 seconds]
<muffindrake> It seems to be possible to currently use something like 'array = {};' in code - does that simply zero-initialize the given object, or is there some other thing that does?
<muffindrake> It's not mentioned in the documentation, if I'm not mistaken, but it will compile.
bjorob has joined #zig
bjorob has quit [Ping timeout: 240 seconds]
dingenskirchen has quit [Quit: dingenskirchen]
return0__ has joined #zig
return0e_ has quit [Ping timeout: 240 seconds]
<dantix> muffindrake: It will not compile as you've described. You can use `const all_zero = [_]u16{0} ** 10;` where `10` is array length or `undefined` if you are okay with uninitialized memory.
return0e_ has joined #zig
<muffindrake> Then what does {} mean if you assign it to a variable? Because doing that actually compiles at the moment.
dingenskirchen has joined #zig
<dantix> It is `void`
return0__ has quit [Ping timeout: 264 seconds]
<muffindrake> Is that meaningful in some way?
<dantix> There are some examples - https://ziglang.org/documentation/master/#void
<muffindrake> I see, thank you.
waleee-cl has joined #zig
kllr_sbstn has joined #zig
kllr_sbstn has quit [Remote host closed the connection]
waleee-cl has quit [Quit: Connection closed for inactivity]
<mq32> zig has ruined my c# skills. i always forget that you need to add the position of args in the format string instead of just writing "{}"
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
<mq32> andrewrk: is it possible to create an arm freestanding COFF/PE file with zig?
<scientes> mq32, there was work on that
<scientes> or at least interest'
<scientes> but why not just do a freestanding arm ELF?
<scientes> uboot can boot that
<scientes> ELF has a little problem in the linker in that debug sections must be linked, but other than that, ELF kinda won
<mq32> scientes, because windows requires PE ;)
<scientes> so are you talking about a statically linked windows executable?
<scientes> that isn't freestanding
<mq32> no
<scientes> hmm i'm confused
<mq32> i talk about a dynamically linked windows PE file with no dependencies at all (not even kernel32.dll or something)
<mq32> i have a Windows CE device at my hands
<scientes> yeah but it still makes kernel calls
<scientes> without kernel32.dll
<mq32> it will?
<mq32> why?
<scientes> otherwise it can't do anything
<mq32> yes
<scientes> *anything*
<mq32> i don't want an "executable", but a "library"
<mq32> i can load with C#
<mq32> to run code with
<scientes> ohhhh
<mq32> and i think about porting an application of mine to Windows CE
<scientes> that still isn't freestanding
<scientes> its a dll
<mq32> and before rewriting it in C#, i would rewrite it in zig, as i wanted to port it to zig anyways
<mq32> hm, okay
<mq32> this is gonna be interesting
<mq32> so what would that target be called then? :D
<scientes> I don't know enought about windows to tell you
<mq32> hmmmm
<fengb> Isn't that just a dynamic library?
<fengb> "-dynamic create a shared library (.so; .dll; .dylib)"
<mq32> but the root question is still valid: can i output PE for "any" target?
<scientes> it works for linux
<mq32> fengb: not the "dynamic libarry" is the problem but the format of it
<fengb> Oh Windows arm...
waleee-cl has joined #zig
<mq32> [felix@ing05-linux src]$ zig build-lib -dynamic -target thumbv7-windows main.zig
<mq32> LLVM ERROR: target does not implement codeview register mapping
<mq32> hm. sad
<mq32> okay, so some issue on Github/Rust says that it works with thumbv7a-windows ... but zig doesn't support that arch
<fengb> Windows arm is listed as tier 3 support
<scientes> mq32, arm-windows-gnu
<scientes> ^thats what you want
<scientes> thats thumbv7a
<scientes> thumb
<scientes> v7
<scientes> thumbv7-windows-gnu
<mq32> hm, same error
<scientes> ahhh
<mq32> (register mapping)
<scientes> thats my problem
<mq32> fengb: i'm totally okay with tier 3
<fengb> Oh it's a pretty deep error I see. I'll let the experts talk >_>
<mq32> scientes: I'm willing to put some time into this, could you help me out a bit later?
<scientes> I just know nothing about windows
<scientes> I'm been Linux only for years
<mq32> yeah, me too, but you have worked with the compiler internals already...
<mq32> but i first have to dig some time into the error message
<scientes> I also added arm64
<mq32> there's probably a solution anywhere out there
<mq32> so i can find the windows specific bits
<mq32> okay. first finding: windows CE uses the same calling conventions as linux/generic ARM
marler8997_ has quit [Ping timeout: 252 seconds]
dimenus is now known as Guest75066
Guest75066 has quit [Killed (cherryh.freenode.net (Nickname regained by services))]
dimenus has joined #zig
Guest75066 has joined #zig
<dimenus> is there any way to get the name/location of the calling function?
<scientes> dimenus, yes, that is how stack trace works
<euantor> Anybody got any ideas on this comment? It seems Zig is looking for VCRuntime on Windows: https://chocolatey.org/packages/zig#comment-4680983596
<mq32> dimenus: @returnAddress + debug info
<mikdusan> euantor: if i remember correct, due to a compiler upgrade, 0.5.0 release on windows introduced a new runtime .dll requirement,
<mikdusan> and sometime thereafter, the windows master builds were enhanced to drastically reduce .dll requirements
<mikdusan> long story short, if a recent master build is used that should solve the issue
<tgschultz> see #3391, but should have been fixed in #3467
<euantor> Right, I'll need to update the Chocolatey package then and work out what exact dependencies it has. The commenter claims to have VC redist installed so I'll need to set up a clean windows environment to test
<euantor> The chocolatey packages currently only have released versions, as it takes a while for reviews to complete so maintianing master builds would be a pain
<mikdusan> euantor: commenter claims up to 2017 redistributable installed. vcruntime140_1.dll is a '2019 thing
<euantor> Ah, will reply again recommending 2019 and add it as a dependency
return0e_ has quit [Remote host closed the connection]
porky11 has joined #zig
wootehfoot has joined #zig
clktmr has joined #zig
doublex has quit [Ping timeout: 264 seconds]
dimenus has quit [Read error: Connection reset by peer]
jjido has joined #zig
Akuli has joined #zig
porky11 has quit [Remote host closed the connection]
wink_ has quit [Remote host closed the connection]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
doublex has joined #zig
porky11 has joined #zig
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
lunamn has joined #zig
porky11 has quit [Quit: Leaving]
doublex_ has joined #zig
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
doublex_ has quit [Read error: Connection reset by peer]
doublex has quit [Ping timeout: 240 seconds]
jjido has joined #zig
<shakesoda> does zig have a way to do lambda functions/closures
vexu has joined #zig
Akuli has quit [Quit: Leaving]
<shakesoda> oh, looks like #1717 is about this
<leeward> If I have a function that wants to take an array of 2 bytes as input and never change them, what should the type of the argument be? I'd also like to be able to pass slices of a bigger array in.
<fengb> []const u8 ?
<tgschultz> if you want to take slices, then []const u8
<leeward> I'd like to communicate in the interface that it expects exactly 2 bytes. Is that just not a thing I can do?
<tgschultz> [2]u8
<leeward> But not `[2] const u8`
<tgschultz> no, slices do not have comptime known length
<tgschultz> you could say *const [2]u8
<leeward> I guess the issue is where I raise the error, right?
<tgschultz> I'm not sure if any simple slicing syntax will work though...
<fengb> [2]u8 implies const already. It's Zig's fancy pass ref by const value
<leeward> I can have it take []const u8, but the function now returns !whatever
<leeward> Ohhh, ok
<fengb> It's the same as declaring "const foo: [2]u8". You won't be able to edit the data
<leeward> I think I might submit a suggestion then: s/error: const qualifier invalid on array type/error: const qualifier superfluous on array type/
<fengb> Equivalent to*. Obviously not the same :P
<fengb> tgschultz: can Zig downcast larger arrays to fit into 2 bytes?
<tgschultz> I'm not sure, but I doubt it
<tgschultz> I mean, array[0..N] should be able to cast to *const [N]u8 if N is a comptime constant, but I'm not sure the compiler does that.
<fengb> `error: expected type '[2]u8', found '[3]u8'` :(
<tgschultz> That isn't surprising, but try what I posted above.
<tgschultz> because downcasting an array to a smaller array would be hidden behavior anyway
<andrewrk> fengb, I was thinking to change @sliceToBytes and @bytesToSlice to be more powerful
<andrewrk> @toBytes and @fromBytes
<andrewrk> hmm maybe @ptrToBytes and @valueToBytes
<tgschultz> just moving mem.as/fromBytes into builtins?
<andrewrk> no it has to operate on a pointer. always a pointer. ok so it accepts a pointer, but the point is that it would return *[N]u8 if the len was comptime known
<andrewrk> oh right. this can be std lib
<andrewrk> does this already exist?
<tgschultz> pretty sure it was added by Hejsil and I in the meta pr (though it is part of mem).
<andrewrk> oh nice tgschultz I forgot you did this
<mq32> do we have a thing like @sizeOf that has bits size?
<tgschultz> Not really, because it would only really work for primitives given the complexities of what you mean when you'd use it on a struct, and for primitives it is simple math.
<andrewrk> I think it will become meaningfully once 3133 is done
<andrewrk> it basically tells you how much space the type fills up in a packed struct if you leave it unaligned
<mq32> right now i have this error: error: array of 'Entry' not allowed in packed struct due to padding bits
<andrewrk> mq32, yes this is what #3133 is addressing - let you put any type in a packed struct
<leeward> Is there a way to cast a `[]const u8` to `[2]u8`?
doublex has joined #zig
<mq32> andrewrk, ah oka
<mq32> have to read that up
<andrewrk> leeward, after https://github.com/ziglang/zig/issues/863 it will be slice[0..2], which will give you a *[2]u8. until then @ptrCast(*[2]u8, slice.ptr)
<andrewrk> I'm missing `const` in there but you get the idea
<mq32> 3133 will probably also fix the bug with invalid sizeOf?
<mq32> huh... haven't i reported this?
<leeward> andrewrk: Excellent, that's what I was looking for.
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<mq32> ah, it wasn't a new issue...
kllr_sbstn has joined #zig
wink_ has joined #zig
jjido has joined #zig
protty has joined #zig
marijnfs_ has joined #zig
<marijnfs_> is there a nice binary serialization library for zig?
<waleee-cl> I guess you could half-ass it by using C's fopen/fwrite if nothing else
<scientes> I don't tihnk that is what he is asking
<THFKA4> someone was working on integrating protos
<andrewrk> I don't think that addresses marijnfs's use case. zig std lib has clear facilities for writing files. this question is about some kind of reflection-based system
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
vexu has quit [Quit: WeeChat 2.6]
FireFox317 has joined #zig
FireFox317 has quit [Remote host closed the connection]
FireFox317 has joined #zig
<FireFox317> Someone in here with uart experience? I'm trying andrewrk's clashos bootloader, but I'm having a weird issue which only happens with real hardware and not in qemu. When I'm sending a new image over uart after two null bytes have been send, the raspberry only receives null bytes afterwards.
<FireFox317> I tried using different usb to uart bridges, but that didn't help
<andrewrk> something to do with baud rate maybe?
<andrewrk> I'm a total beginner at bare metal coding
<andrewrk> FireFox317, oh, have you tried #osdev? it's a helpful channel
<FireFox317> Nope I haven't thanks for the suggestions
<FireFox317> I'm getting close to the usb keyboard support in clashos btw, but Its super annoying when i constantly have to switch sd cards between the rpi and my pc. Thats why I'm trying the bootloader, but no success yet
wootehfoot has quit [Read error: Connection reset by peer]
<andrewrk> does the bootloader work for you in qemu?
<FireFox317> Jup it does
<FireFox317> I also tried a much lower baudrate, but exactly the same problem
<FireFox317> So weird
<marijnfs_> c++ has a nice serialization library called Cereal
<marijnfs_> something like that would be nice
<marijnfs_> with all the introspection it might be possible
<andrewrk> FireFox317, hmm ok. if I were working on this right now, trying to get the bootloader working on real hardware would be my top priority
protty has quit [Remote host closed the connection]
<FireFox317> andrewrk: I went back to this commit a804d7d, before markfirmware's framebuffer stuff, just so you know
<andrewrk> good to know
<mq32> FireFox317: how do you connect to your uart?
<mq32> because you may need to change your tt settings
kllr_sbstn has quit [Quit: leaving]
<FireFox317> Well using a bus pirate actually
<FireFox317> Setting that into transparant bridge mode
<Snektron> every time i see how c++ allocators work i get reminded how nice those of Zig work
<shakesoda> every time i see how pretty much anything in c++ works i run for my life
<Snektron> oh, come on, enable_if is not so hard ;)
<fengb> I’m always impressed that not having a default allocator exposes so many nice benefits
Guest75066 has quit [Remote host closed the connection]
<mq32> true dat, fengb