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/
bjorob has quit [Ping timeout: 265 seconds]
Ichorio has quit [Ping timeout: 245 seconds]
mikdusan has quit [Ping timeout: 250 seconds]
mikdusan has joined #zig
<gruebite> hmm
<gruebite> i'm getting expected 'comptime_int' when using c.ENUM where it expects it
_whitelogger has joined #zig
<gruebite> had to do `@intToEnum(c.some_c_enum, c.SOME_C_ENUM_A)` is this required?
<gruebite> C enums are not by default their enum type?
<andrewrk> gruebite, are you sure the .h file defines it as an enum?
<gruebite> typedef'd heh
_whitelogger has joined #zig
<gruebite> not `struct foo` but `typedef struct {} foo`
<gruebite> the zig header also has extern enum def
adamkowalski has joined #zig
doublex_ has joined #zig
<andrewrk> that should work fine in theory. looks like an improvement is needed to translate-c
<gruebite> works if i do it explicitely
doublex has quit [Ping timeout: 246 seconds]
<gruebite> i had to do: c.godot_method_rpc_mode.GODOT_METHOD_RPC_MODE_DISABLED
<gruebite> and it worked, otherwise c.GODOT_METHOD_RPC_MODE_DISABLED didn't work
adamkowalski has quit [Ping timeout: 245 seconds]
<daurnimator> gruebite: FWIW you should just be able to write: `.GODOT_METHOD_RPC_MODE_DISABLED`
<gruebite> cool
<gruebite> c. no though
<gruebite> does does a self-hosted translate-c look like?
<andrewrk> gruebite, self-hosted translate-c is in progress. you can experiment with `zig translate-c-2` and see also this issue: https://github.com/ziglang/zig/issues/1964
<daurnimator> andrewrk: are you back home from handmade now?
<andrewrk> once self-hosted catches up to the C++ version, we get to delete 4,000 lines of C++ and then start using the self-hosted translate-c for everything
<andrewrk> daurnimator, yep!
<daurnimator> sort of wish I'd paid more attention to it and tried to go... sounded like fun
<andrewrk> I think it was the best one yet
adamkowalski has joined #zig
<gruebite> handmade?
<andrewrk> I went to this convention over the weekend: https://www.handmade-seattle.com/
<andrewrk> ran a zig booth. had some fun conversations
<gruebite> nice! i'm based out of seattle
<gruebite> i could've gone
<andrewrk> ah, you'll have to go next year
<gruebite> yeah
<andrewrk> one guy came up and said, alright, C replacement? What's one reason I should use Zig instead of C?
<andrewrk> I said "Hmm let me see... What do segfaults look like for you?"
<andrewrk> "Well, I try to make sure they don't happen. I have a lot of asserts."
<andrewrk> "OK, what do asserts look like for you?"
<andrewrk> "You know - function name, line number, message, abort()"
<andrewrk> "Yeah, yeah, OK, let me show you what an assert looks like in zig."
<gruebite> niiiice
<andrewrk> (invoke integer overflow or something in a short example, and the stack trace displays on the screen)
<andrewrk> "Oh, wow. Oh... that is nice"
<gruebite> haha
<gruebite> yeah, coming from c to zig is refreshing
<gruebite> currently writing bindings for godot's nativescript. there are cpp/rust/d bindings now
<andrewrk> yeah. ideally the @cImport would be enough, but as you've observed, translate-c is at proof-of-concept stage, not at completed-and-mature stage
<gruebite> right now i'm just running .patch at part of the build step, for now at least
<andrewrk> fengb, I saw this PR but haven't dug into it yet
<andrewrk> this is one of those "hard" PRs
<andrewrk> and uh to be honest there are a dozen "hard" PRs in line before you
<fengb> I thought I had some simple results but the more I fiddle, the less confident I am with the numbers
<andrewrk> one thing to keep in mind is that std.sort.insertionSort is intended to be just that- exactly the insertion sort algorithm, nothing more, nothing less
<fengb> I can loop back once I actually finish implementing grailsort if that makes more sense than doing it incrementally
<andrewrk> we can have more sort algorithms but they need to have names that describe what they are, and then of course there will be a "default" sort which can do heuristics based stuff
<fengb> Okay, I'll convert this over to just an improvement of the bsearch instead
<andrewrk> I think that will be easier to merge
<fengb> Cool thanks
<gruebite> i've been struggling with opaque types
<daurnimator> andrewrk: FWIW I've got 2 PRs to send on top of #3644. One of which is the overhaul of "stream" :)
<gruebite> seems if a struct is defined after the opaque type is used in a function, it just treats it as an opaque type
<gruebite> function prototype*
<andrewrk> daurnimator, #3644 is definitely hard. but also important
<andrewrk> it's on my shortlist
<andrewrk> gruebite, have you discovered how to observe warnings from translate-c?
<daurnimator> andrewrk: oh? I thought it would be pretty easy (its the first follow up thats hard!). what makes it hard?
<gruebite> yeah, i'll see if there is a warning for the struct
<andrewrk> in the self-hosted version they conveniently show up as comments, but in the c++ version you need --verbose-cimport to see warnings
<gruebite> string not found
<andrewrk> daurnimator, sorry, I meant the thing that changes the streaming API & implementations. It does look like #3644 messes with std.io implementations a bit
<gruebite> when searching the struct
<andrewrk> daurnimator, that's the part that I want to look at carefully
<daurnimator> andrewrk: you mean you want to look at the std.io changes carefully? the changes are in PeekStream, BufferedInStreamCustom, BufferedOutStreamCustom: I pretty much just swapped out their buffer management to just use fifo methods instead.
<andrewrk> daurnimator, yes that's what I mean. It's probably fine, I just want to think it through so I can be on the same page with the next steps that you're taking
<daurnimator> k
<daurnimator> If I can figure out a way to do comptime callbacks in a nicer way, I will be able to get rid of those 3 classes entirely!
<andrewrk> I'm also asking myself the question "are all these abstraction layers necessary?"
<andrewrk> maybe the answer is "yes"
<andrewrk> but, yes, maybe the answer is to fix issues related to comptime callbacks
<andrewrk> sometimes code reviews are harder for me because I'm not just asking the question, "is this the correct code based on a language that already exists?" but "does this code demonstrate that the language or std lib is designed incorrectly?"
<daurnimator> andrewrk: the answer is "almost no". What those 3 do compared to a plain fifo, is "auto-fill" from another chained stream. I intend to add that facility to fifo via comptime callbacks: you'd create a Fifo instance that has a callback for "onEmpty" that would fetch from another backing stream.
<daurnimator> andrewrk: for callbacks; this is the only thing I have working: https://godbolt.org/z/v6UWcX its ugly.... trying to figure out any alternative
<andrewrk> btw quetzalb, do you have a use case for windows on aarch64? I'm curious about the details
<fengb> andrewrk: is there a way to convince zig/llvm to use cmov? I found https://reviews.llvm.org/D36858 which removes it altogether
<andrewrk> fengb, are you trying to do constant-time operations?
<andrewrk> can you elaborate on the use case?
<fengb> It's for binary search. I found an old resource that uses cmov for removing a conditional branch
<fengb> I wanted to test it out to see if it's helpful since bsearch is pretty bad for branch predictors
<fengb> \
<adamkowalski> andrewrk: i've been using zig for a couple days I wanted to say how fun it's been to use. The ability to have first class types rather then having a seperate language such as a template metaprogramming system makes everything feel much more unified and well thought out
<fengb> I guess I'll learn a little assembly while I'm at i :P
<adamkowalski> I also really enjoyed learning about the allocator model and it made me realize how much of what i've written had the potential to fail due to hidden allocations
<andrewrk> fengb, yeah I think this might be a "use-inline-assembly" use case
<andrewrk> that llvm code review thing you linked does a pretty good job explaining why the instruction selector chose branches rather than CMOVs
<andrewrk> adamkowalski, glad to hear it! looking forward to seeing what you create
<fengb> Yeah it makes sense in the general case
<fengb> But sometimes I want to tell the optimizer to stop helping >_>
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<fengb> Ugh, I seemed to have killed my raspberry pi :(
<gruebite> i am doing `while (core) |ext| { core = ext.nest; }
<gruebite> https://hastebin.com/itikikatil.zig this is the generated zig code from the header "cannot access fields of type X"
<gruebite> i guess i have to cast it?
<gruebite> struct_some_c != some_c?
doublex_ has quit [Ping timeout: 265 seconds]
doublex has joined #zig
muffindrake has quit [Ping timeout: 246 seconds]
muffindrake has joined #zig
doublex has quit [Read error: Connection reset by peer]
doublex_ has joined #zig
<fengb> zig test src/bench.zig --release-fast -target armv6-linux /// error: instruction requires: armv6k
<fengb> Ah, probably .arm, .aarch64 => asm volatile ("yield"),
doublex_ has quit [Read error: Connection reset by peer]
doublex has joined #zig
<gruebite> I have to do `@as(*const c.godot_gdnative_api_struct, ext).next` which i hope doesn't crash
return0e_ has joined #zig
return0e has quit [Read error: Connection reset by peer]
reductum has joined #zig
reductum has quit [Client Quit]
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
chemist69 has quit [Ping timeout: 276 seconds]
<gruebite> is `var i = 0; while (i < n) : (i += 1) { }` the correct way to do range loops?
chemist69 has joined #zig
<gruebite> also, it seems like every field i am encountering is opaque typed
<gruebite> :/
<gruebite> i do not want to cast everything everytime
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
reductum has joined #zig
doublex has quit [Read error: Connection reset by peer]
doublex_ has joined #zig
reductum has quit [Quit: WeeChat 2.6]
<gruebite> just got this Assertion failed at /home/grue/packages/aur/zig-git/src/zig/src/list.hpp:31 in at. This is a bug in the Zig compiler.
<gruebite> how can I run it with a backtrace?
<daurnimator> gruebite: run the zig command under gdb?
<gruebite> had to rebuild with debug symbols
<gruebite> looks like master is broken right now though?
dbandstra has joined #zig
quetzalb74 has joined #zig
<quetzalb74> I tried to add "pub const io_mode = .evented" to my hello world zig file. But when I compile it using master, it get an llvm error. Is it a known issue? Any workaround or suggestion on how to debug?
<quetzalb74> C:\Users\qbradley\source\repos\events>..\zig\build\bin\zig.exe build-exe events.zigbroken LLVM module found: Instruction does not dominate all uses! %743 = load %std.pdb.MsfStream**, %std.pdb.MsfStream*** %92, align 8, !dbg !7527 %501 = load %std.pdb.MsfStream*, %std.pdb.MsfStream** %743, align 8, !dbg !7549Instruction does not dominate all uses!
<quetzalb74> %743 = load %std.pdb.MsfStream**, %std.pdb.MsfStream*** %92, align 8, !dbg !7527 %512 = load %std.pdb.MsfStream*, %std.pdb.MsfStream** %743, align 8, !dbg !7555Unable to dump stack trace: debug info stripped
<quetzalb74> I downloaded zig-linux-x86_64-0.5.0+aa4e92f3b and tried on windows subsystem for linux and no repro. However if I add "-target x86_64-windows-gnu" to cross compile for windows it repros on linux too
quetzalb has quit [Remote host closed the connection]
<daurnimator> quetzalb74: yeah it looks related to OutStreams and async
<daurnimator> quetzalb74: note that targets with a .exe/.pdb output use different code to elf targets
<daurnimator> so you'll be hitting the non-async-ness of the OutStream in std.pdb
<daurnimator> I have a PR coming up to refactor all that... but please do file an issue anyway
<quetzalb74> oic
<quetzalb74> Ok
quetzalb74 has quit [Remote host closed the connection]
mahmudov has joined #zig
doublex_ has quit [Quit: Quit]
adamkowalski has quit [Ping timeout: 240 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Quit: Lost terminal]
demizer has joined #zig
doublex has joined #zig
<dbandstra> code generation is so easy with zig's build system
<dbandstra> although i just copy pasted how to do it from somewhere... one line in my build.zig and i'm using a zig script to generate something which is then imported by my main program, and it all works and only rebuilds when the script changes
<dbandstra> i made a script to generate zig bindings from GLSL shader, so i just edit the shader, run zig build, and can start following the compile errors in my program where i need to update my calls
<dbandstra> i think i was conditioned to believe this should be hard because i grew up with MSVC
<traviss> dbandstra, do you have a link showing how you're doing code gen?
nomadgamma has quit [Quit: Leaving]
<dbandstra> traviss: the glsl thing is not online yet but i used it in another project for some webgl related stuff: https://github.com/dbandstra/oxid/blob/master/build.zig#L26
<traviss> thank you. i didn't know where to look when i considered trying something similar myself.
<dbandstra> i just stumbled across it when checking out one of andrewrk's repos, maybe clashos
reductum has joined #zig
<traviss> on another issue, is var args already gone from master? and what is the new way to do var args? something like `.{._0 = arg0, ._1 = arg1...}` and a function accepts an `args: var` param where you then get its values using `@field(args, "_0")`.
<traviss> i'm thinking it would be simpler to use a slice...
reductum has quit [Quit: WeeChat 2.6]
<dbandstra> var args is not gone from master yet
<dbandstra> i believe the plan is for the literal `.{ ... }` syntax to be an array if all the elements are of the same type
<dbandstra> i mean when passed as a `var` typed argument
<traviss> i'm thinking it would be simpler to use a slice...
<traviss> oops sorry
<dbandstra> it already works to call a function `fn func(params: var) void` like this `func(.{"one", "two", "three"})`
<dbandstra> but @typeOf(params) will be a struct, so it's a little awkward to iterate in the function
<traviss> ok thank. that looks good. was just a bit confused as anon arrays aren't in master yet along with anon structs.
<dbandstra> they are
<traviss> oh, so i am wrong again. i'll give it a try :)
<dbandstra> but it was merged recently and there are still some rough spots
<mq32> dbandstra, actually it's not that awkward ;)
<mq32> for(std.meta.fields(params)) |fld| { std.debug.warn("{} = {}\n", fld.name, @field(params, fld.name)); }
<dbandstra> yeah not bad, but someone could just pass any struct with named fields into that function. if you wanted an array you would have to check if a fieldname is "_0" or something and compile error if it's not
<traviss> yes, thats pretty much what i have now. +1
<dbandstra> or i guess the field is actually `@"0"`
<traviss> yeah i just noticed the same thing. thanks again.
<mq32> i still don't know if i really like this change
<mq32> but it allows for many interesting options
<mq32> std.debug.warn("{.x} = {.y} * {.z}", .{ .x=60, .y=20, .z=3 });
<dbandstra> it does seem a little sketchy the amount of things that `.{` can represent
<dbandstra> but i don't have any better ideas
jjido has joined #zig
jjido has quit [Client Quit]
dbandstra has quit [Quit: leaving]
FireFox317_ has joined #zig
<Snektron> Struct literals are basicslly initializer lists
<Snektron> Wait, .{} With all elements the same will be an array? That doesnt sound right
<Snektron> I'd rather see either a dedicated array literal or a std lib function to transform a struct literal into an array
<Snektron> Is .{a = 10, "b"} also valid?
<mq32> i don't see a reason why it should not be allowed
return0e has joined #zig
FireFox317_ has quit [Ping timeout: 246 seconds]
fsateler has quit [Ping timeout: 240 seconds]
fsateler has joined #zig
<mq32> andrewrk: i think i found some regression in the zig compiler, but i cannot really locate it
<mq32> but: with the current version, the TextEditor component in ZGS is broken and panics with a your-memory-contents-here "message"
knebulae has quit [Quit: Leaving]
<traviss> .{a = 10, "b"} gives compiler error: expected token '}', found 'StringLiteral'. pointing at "b"
lunamn has quit [Remote host closed the connection]
knebulae has joined #zig
return0__ has joined #zig
return0e has quit [Ping timeout: 265 seconds]
<muffindrake> How does one handle strings, particularly variably-sized ones returned from a function? Since there is no end-of-string character in Zig, I suspect there's little fun to be had.
return0e has joined #zig
return0__ has quit [Ping timeout: 245 seconds]
<mq32> muffindrake: simple ;)
<mq32> use slices (pointer+length) and allocators for allocating them
<muffindrake> I don't consider 'use memory allocation' a satisfactory solution for this ...
<mq32> you can take a look at https://ziglang.org/documentation/master/std/#std;fmt.bufPrint
<mq32> bufPrint(sliceInput, …) → sliceOutput
<mq32> the function returns a part of the input slice as an output, containing the formatted string
<mq32> or maybe i didn't understand your question in the first place ^^
return0__ has joined #zig
return0e has quit [Read error: Connection reset by peer]
<muffindrake> I'll be fine with slices as per your suggestion, but I still feel like there could be better handling for strings. C makes it a bit easier since you can arbitrarily end one with a \x00 character
<mq32> i don't think nullterminated strings are easier to handle
<mq32> slices have the nice option that strings *may* contain 0x00 as a legal character
<mq32> and that comes handy some times
<mq32> also slices are much faster than zero-terminated strings, as "strlen" will be O(1) instead of O(N)
<Snektron> muffindrake: even in C that string has to be allocated somewhere
<Snektron> If its a string literal it will be allocated in a data segment in the executable
<Snektron> In Zig its similar
<Snektron> Except its a slice or array instead of a pointer
jokoon has joined #zig
waleee-cl has joined #zig
kenaryn has joined #zig
<kenaryn> Hello computer guys. Does the word `undefined` when defining an absence of value tells the compiler to load a register and store a 0-length buffer with a address like 0x0 or does it do nothing at all at compile-time?
<fengb> For safe builds, it sets the value to 0xaaaa to assist with debugging
<fengb> For release it’s the same as not setting it in C, so whatever garbage was at that location (undefined behavior)
<kenaryn> As always, thank you fengb for teaching me. I will add it to my memorandum immediately.
jokoon has quit [Quit: jokoon]
kenaryn has quit [Quit: WeeChat 2.3]
<frmdstryr> Would it be difficult for zig to support function "kwargs"? Eg
<frmdstryr> fn foo(struct{ a: u32, b: []const u8, c: bool = false}) void { //...
<frmdstryr> foo(.a=1, .b="abc")
<frmdstryr> or something like that
<mq32> frmdstryr: it's not necessary
<mq32> if you want to do that, just make a parameter a struct
<mq32> foo(FooArgs{.a = 1, .b = "abc"});
<frmdstryr> I know but then code gets cluttered when using outside, eg
<frmdstryr> var server = net.StreamServer.init(net.StreamServer.Options{});
<mq32> i don't know how that will work with anonymous struct literals
<mq32> maybe you can even just do
<mq32> foo(.{.a = 1, .b = "abc" });
<frmdstryr> Does zig infer what the first . there means? That'd also work
<mq32> yeah, that's a new thing
<mq32> i think andrew knows most about it right now :D
mahmudov has quit [Remote host closed the connection]
<mq32> btw, wo did the godbolt implementation for zig?
<frmdstryr> Just using . works, nice!
<mq32> so it looks like that zig accidently got a kind of default args as well as named parameters?
<frmdstryr> Yeah, I was going to create an issue to ask but it seems like it already works :)
<frmdstryr> It should be documented
<mq32> go for it!
<mq32> make a fork, write some documentation
FireFox317 has joined #zig
<FireFox317> mq32: That is so cool!
<fengb> I've been using godbolt 0.3.0 :/
<mq32> FireFox317: simplicity + creativity → Zig
<mq32> hmm
dimenus has quit [Read error: Connection reset by peer]
<mq32> this looks like it could be adjusted to work with newer zig versions than 0.3
dimenus has joined #zig
return0e has joined #zig
FireFox317 has quit [Ping timeout: 265 seconds]
return0e_ has quit [Ping timeout: 240 seconds]
FireFox317 has joined #zig
<andrewrk> mq32, I found this building RetrOS with master branch: https://github.com/ziglang/zig/issues/3692
<mq32> interesting
<mq32> i didn't run into this, but two other bugs related to *something* :D
<mq32> also i have some weird runtime crash where the code is doing ... stuff
<mq32> i have to track that down, but i short: the text editor is kinda exploding in my face
<mq32> the panic handler triggers (which is nice) and outputs random memory(which is not nice)
<frmdstryr> That happend to me yesterday as well. It ended up being me using a pointer from the stack instead of allocating one.
<mq32> frmdstryr: afaik it should not be possible to @panic with a runtime pointer and i'm sure i'm not using one
adamkowalski has joined #zig
reductum has joined #zig
<adamkowalski> andrewrk: I watched your video about compile time programming in zig and your implementation of the perfect hash function for switching on strings at compile time. During that episode you mentioned that you weren't a huge fan of SFINAE. I'm curious what your thoughts are on Concepts and generic programming as a whole. In my eyes SFINAE solves the problem when you want to have many generic functions with
<adamkowalski> the same name and want to exclude a particular one from the list of possible candidates
<andrewrk> sfinae solves a meta problem that shouldn't exist in the first place. I'm interested in solving actual problems
<adamkowalski> This is really usefull when for example you want to deal with random access iterators differently then forward iterators. Maybe if you have random access capabilities in your data structure you want to support sorting. Otherwise if you have a linked list for example, you can can match on the forward iterator generic function and do something else. Maybe you can copy the contents to a vector, sort that,
<adamkowalski> and then move things back to a linked list
<andrewrk> "debug your application rather than your programming language knowledge"
<adamkowalski> Fair, but how would you approach a similar problem in Zig?
<adamkowalski> Right now when I need to support both slices and static arrays I find myself using vars
<scientes> what even is "SFINAE", it is a LAIDKBLAI?
<andrewrk> adamkowalski, why do you need both? just use slices
<adamkowalski> substitution failure is not an error
<adamkowalski> andrewrk yeah that was my plan, but I had a matrix rather then a vector
<adamkowalski> scientes I recommend this video https://www.youtube.com/watch?v=ybaE9qlhHvw
<adamkowalski> I had a static array of static arrays
<scientes> adamkowalski, if you have to watch a video to understand a small language feature, then the language feature is too complicated
<adamkowalski> it's not a small language feature though
<adamkowalski> it's one of the main things that you can do in modern c++
<adamkowalski> it's getting simpler now with concepts
<adamkowalski> but generic programming is all the rage these days
<adamkowalski> but it can be explained simply
<mq32> adamkowalski: scientes statement is still correct though
<adamkowalski> you want to write a generic function. but you want to constrain the possible inputs to only types that meet certain requirements
<mq32> SFINAE is a horrible way to implement generic code and zig doesn't require such thing, it just works different
<adamkowalski> however, you want to utilize overloading as well
<mq32> just @compileError your asssumptions on the types then ;)
return0__ has quit []
<adamkowalski> if you use static assert, then you prevent other people from adding to the overload set
<scientes> adamkowalski, you just don't get it. Good programming is all about data structures. These endless features can all be implemented in the language, rather than being part of it. LLVM re-invents many C++ features for various reasons (like std::map), which shows that the features were unnecessary and poorely thought-out
<scientes> The only reason you want these features is that you don't understand what they really do. You only see them in the context of the language that has these features.
<adamkowalski> it is about data structures, I absolutely agree
<scientes> sorry, that might have come accross as harsh
<companion_cube> D has contracts on generic argiments
<mq32> adamkowalski: why that? i can assert type structures in zig without problems
<adamkowalski> yeah D has template constraints which works really well
<scientes> like GNU's IFUNC was porely though out, like C++ features
<companion_cube> I mean you can say taht a function must comptime-evaluate to true when applied to a type
<mq32> "a requires to be an array of size N×X, b requires to be an array of the same element type as a and also of size X×N"
<adamkowalski> companion_cube yeah we can express compile time constraints on types in zig
<adamkowalski> by having a predicate on a type
<scientes> adamkowalski, you can just use function pointers
<adamkowalski> you can for example say that I accept any function that has a .next() method
<adamkowalski> however, what if you want to do something different if you have a .nth() method
<mq32> this is much more powerful than any non-programmable kind of "concepts", "constraints", ...
<scientes> no reason function pointers can't be comptime
<adamkowalski> and someobody else on your team comes in and says, hey I want to add an additional specialization
<adamkowalski> if your data structure actually exists on the gpu, I want to do yet another thing
<adamkowalski> so you have two functions, both which operate on random access data structures
<companion_cube> mq32: I'm not completely sure Zig is more powerful than D when it comes to comptime
<mq32> adamkowalski: if(@hasDecl(@typeOf(arg), ".nth()") { … } else { … }
<adamkowalski> but one specializes further to utilize the gpu
<companion_cube> (preconditions are neat)
<scientes> companion_cube, D has a garbage collector
<mq32> companion_cube: zig is "fully programmable at comptime", so no, nothing can be "more powerful" in computation
<adamkowalski> mq32 right but then all the logic gets placed into one function
<mq32> also not necessary ;)
<scientes> mq32, well, its limited right now. there is no comptime memory model
<adamkowalski> mq32 c++ and D also have compile time evaluation
<companion_cube> mq32: note the negation
<mq32> replace "…" with "callFunWithNth" and "callFunWithoutNth"
<companion_cube> D might still be as powerful
<adamkowalski> I think we shouldn't be so quick to dismiss language features and whole languages in general
<mq32> companion_cube: then it's programmable by definition ;)
<companion_cube> it is, yes
<adamkowalski> you may think zig is more powerful, but learning from how others approached problems is always useful
<scientes> adamkowalski, "whole languages"---this does not exist
<scientes> turing complete languages are recursively enumerable
adamkowalski has quit [Quit: Lost terminal]
<scientes> the biggest problem with garbage collectors, from my point of view, is that they are too complicated to model
<scientes> like the OOM killer
<andrewrk> D's compile time function features I believe are more powerful than zig's since you can generate arbitrary strings. But there are downsides to that too
<companion_cube> oh interesting
<andrewrk> e.g. I'm not sure it respects the target when cross compiling
<andrewrk> either it has that downside, or it's not more powerful than zig's. one of those 2 is true
<andrewrk> but yeah SIFNAE is right out. absolutely not. that's c++ cruft that has no place in zig
<companion_cube> no one said it's more powerful :D
<companion_cube> (but it might as powerful, all I'm saying)
<mq32> btw, it's interesting how little zig code you need to achieve quite complex stuff
<mq32> this is a 1500 LOC assembler, from parser to code generation, everything included. most complex piece i use from the std library is std.StringHashMap
<mq32> if i'd written that in C/C++ i probably would've used at least flex which produces easily more code than this in a single invocation
<scientes> mq32, awesome
<mq32> but beware: the code isn't beautiful :D it was written in like 4 hours or such :D
<scientes> fn isHexDigit(c: u8) bool {
<companion_cube> I wrote a tiny http server in OCaml recently, it's funny how simple it can actually be (if you support a reasonable subset of the RFCs)
<scientes> ahh whatever, I don't need to blah
<companion_cube> now I think I understand better the idea that the package manager could bootstrap from a simple handmade HTTP client
<companion_cube> (+ hashing)
<scientes> companion_cube, http 1.1 is beautifully easy
<companion_cube> yeah I was surprised
<scientes> you can do it over netcat
<companion_cube> there are some weird corners, but to get to a point where curl is happy, is quite easy
<scientes> much easier than SMTP
<companion_cube> scientes: if you can count the size of bodies accurately yeah
<tgschultz> most protocols from the early days of the net can be done by hand.
<mq32> yeah, HTTP is actually really easy :)
<mq32> i think the most complex part is header parsing when it comes to those weird header-parameter stuff
<fengb> Was* :P
<mq32> fengb: true
<tgschultz> IRC is even easier. FTP has some weirdness with addressing.
<scientes> I have not worked with it, but WebDav also looked quite nice
<scientes> and you can even use ranged requests with that
<scientes> but i guess there is no locking
<scientes> the problem with sftp is that you get 2 or three round trips to do a write then fsync()
<mq32> i really have to code a tftp client+server some day, that protocol is just so handy some times
mahmudov has joined #zig
<andrewrk> adamkowalski, I don't understand why having a matrix rather than a vector means you can't use a slice
<gruebite> okay, found the issue. gonna submit a bug report though
<gruebite> encountered a " This is a bug in the Zig compiler"
<gruebite> relevantly, how can i escape keywords that could be names in C?
<gruebite> there's a struct with "type" as a field
<gruebite> backticks ` are common in some languages
<fengb> @“type”
wootehfoot has joined #zig
<gruebite> fengb: thanks
<gruebite> still getting the bug though
<gruebite> i cannot seem to build master (need to rebuild with debug symbols to get stacktrace)
<reductum> andrewrk, I had a lot of fun doing advent of code 2018 in our zig group. Are you planning on setting another one up this year?
<gruebite> `zig/src/zig_clang_cc1as_main.cpp:511:23: error: ‘Value’ may be used uninitialized in this function`
<andrewrk> reductum, sure! that starts dec 1st right?
<andrewrk> I can't believe it's been an entire year
<reductum> Yeah I just checked the website. It starts 2019-12-01 at midnight eastern time.
<reductum> Yeah it's amazing how fast this year passed!
<gruebite> how can i build zig with debug symbols?
<gruebite> 2019 has been weird :P
<gruebite> andrewrk: do you live in seattle?
<scientes> gruebite, New York
<gruebite> ahhh. so just visiting the past weekend
adamkowalski has joined #zig
<reductum> andrewrk It was great to meet you at HMS 2019, btw. Thanks for flying out! I'm enjoying my Ziguana.
<andrewrk> reductum, nice to meet you too :)
<adamkowalski> andrewrk: about not having SFINAE, I think we don't need it. However, what are your thoughts about something akin to traits/protocols/concepts/etc
<andrewrk> gruebite, if you build from source, the default is debug symbols on
<adamkowalski> Some way of saying that I can accept anything that has this particular form
<adamkowalski> or do you recommend just accepting a var and then using compile time functions to introspect on the type
<andrewrk> adamkowalski, that's something that is not stable yet. the open issue is https://github.com/ziglang/zig/issues/130. Lots of discussion but no concrete plans yet
<adamkowalski> Also about the matrix, the issue I was having was i wanted to write a matmul function
<adamkowalski> I accepted two matrices by [][]T
<adamkowalski> however, the matrix I was passing in was a [3][3]
<adamkowalski> lets say it was called x
<adamkowalski> so I said x[0..]
<adamkowalski> which gives you a [][3]
<adamkowalski> what I ended up doing was this: https://pastebin.com/ZXxFt4QJ
<andrewrk> that looks pretty reasonable to me
<adamkowalski> And then i'm going to write a second version, which is almost identical except which takes matrices where the len is only known at runtime and it takes in a allocator and returns the slices
<andrewrk> the fact that the one that can fail and requires an allocator will be a different implementation also makes sense to me
<adamkowalski> so the reason I wanted concepts/traits/protocols/whatever was so rather then saying var I can communicate my intent to the consumer of the api
<adamkowalski> I can say I take in a matrix like thing which has it's dimensions known at comiple time
<adamkowalski> thats the concept I require
<adamkowalski> so the way I wrote it sounds reasonable to you though?
<andrewrk> yes this pastebin code looks fine to me
<andrewrk> I think in a given project, the matrix math code is likely to be the least maintenance required component
<adamkowalski> my project is entirely matrix math haha
<adamkowalski> it's all data science, machine learning, data visualization
<andrewrk> ah interesting
<adamkowalski> it's currently in Python, and it works pretty well as long as you stick with Numpy/TensorFlow/PyTorch/Jax
<adamkowalski> but as soon as you need to do something custom or god forbid a loop, performance goes down the drain
<adamkowalski> and lack of static typing has bitten us over and over again when refactoring as the code size grew
<andrewrk> this sounds like a job for zig's portable simd
<adamkowalski> so I'm hoping zig can be the replacement for it haha
<adamkowalski> i'm really excited about the simd support here
<adamkowalski> I'm also curious if you've thought about automatic differentiation and gradient descent based optimization in zig?
<andrewrk> I have to go learn what those are to answer that question
<companion_cube> I was going to link https://dlang.org/spec/template.html#template_constraints about the traits thing, but you can just do a comptime assert to check that, actually
<gruebite> if I do not have -DCMAKE_BUILD_TYPE=None i get compilation errors
<andrewrk> -DCMAKE_BUILD_TYPE=None is not supported
<adamkowalski> Okay i'd really like to talk with you further about that at some point. Those are the basis for all the neural network hype you hear about with machine learning these days
<adamkowalski> if you can define a loss function (the distance between your prediction and the correct value) and differentiate it with respect to the parameters of your model
<adamkowalski> then you can improve the weights iteratively, shrinking the loss and causing your model to (learn)
lunamn has joined #zig
<gruebite> interesting. the aur PKGBUILD has that as the default and it works
<gruebite> so I commented it out and now the build fails with that paste
<adamkowalski> tensorflow/pytorch/jax/whatever pretty much provide a linear algebra library and a automatic differentiation tool. thats it
<gruebite> this fails, but uncommenting works: https://pastebin.com/5GkdyDXd
<FireFox317> gruebite: You are doing this because you want stack traces right? Note that when an assert in cpp land happends the stack trace won't work anyway
<FireFox317> Well that is for me the case. When I get an assert hit, I always just gdb it and use that to get a backtrace
<companion_cube> adamkowalski: does mypy not fit the bill for y'all?
jjido has joined #zig
<gruebite> FireFox317: hmm, should i just try to create a minimal replication case?
<adamkowalski> mypy is okay but it's not enforced. it doesn't lead to compile or runtime errors
<adamkowalski> it's just hints for humans and ides
<FireFox317> gruebite: If you want to submit an issue, its always a really good idea to have a minimal replication case yes.
<adamkowalski> I think statically typing is quite useful. In addition I like the value proposition of Zig which is to build performant, reliabile systems
<Snektron> andrewrk: Any thoughts on a strong alias builtin? So like @OpaqueType but for every type. (i mentioned this before but im not sure if you read back)
<adamkowalski> Can't you do that with a compile time function?
<Snektron> no
<adamkowalski> Have a function which takes a type, and generates a new type which has the same fields
<Snektron> Well:
<FireFox317> gruebite: And if you still want debug symbols in your zig compiler the options for -DCMAKE_BUILD_TYPE are "Debug Release RelWithDebInfo MinSizeRel"
<FireFox317> Debug by default I think
<Snektron> The builtin to create types doesn't support structs (yet).
<Snektron> and my intended usecase was for primitive types rather than structs
<Snektron> What i mean is that strong aliased types retain their operators
<Snektron> `const A = @StrongAlias(i32); const a = @as(A, 10) + @as(A, 20);` would be valid
<adamkowalski> I don't think that would work without operator overload or a numeric trait
<Snektron> but `const A = @StrongAlias(i32); const a = @as(A, 10) + 20;` would yield a type error
<adamkowalski> but if instead of using operatros you define an add method on the struct
<adamkowalski> Thats why I tend not to use operators
<adamkowalski> you cannot write generic code with them
<Snektron> nah thats just lame plus too much work
<adamkowalski> but if you just way I have an add function, then create a new struct and add the add method
<Snektron> thats just because theres no operator overloading
<Snektron> Strong aliases are something different
<adamkowalski> well they are a type that looks and behaves like the old type but has a different name
<adamkowalski> so if you want a meter type that can contain a float so you have type safety for your units
<Snektron> exactly
<gruebite> how can I create a [*c] pointer in zig?
<gruebite> casting?
<gruebite> FireFox317: thanks :)
<gruebite> i'd like to know how to initialize a [*c]([*c] Foo) type
frmdstryr has quit [Remote host closed the connection]
<andrewrk> that's any double pointer
<andrewrk> set up your data the correct way and it will implicitly coerce to that type
adamkowalski has quit [Ping timeout: 240 seconds]
Akuli has joined #zig
noonien has joined #zig
<gruebite> https://pastebin.com/A4SscDsu struggling to initialize this
<gruebite> tried &[_] and & and [*c]
<andrewrk> gruebite, don't use [*c], use normal pointer types
<andrewrk> your code is planned to be a compile error with https://github.com/ziglang/zig/issues/2984
<gruebite> i'm getting a "this is a compiler bug" error though
<andrewrk> the workaround is not to use c pointers
<gruebite> i see. cast it to a non-c pointer when interacting with a C api?
<andrewrk> let me rephrase: whatever your workaround options are, putting C pointers in your zig source code is never the answer
<andrewrk> zig's pointer types implicitly coerce to and from C pointer types. the only reason C pointer types exist is for auto translated C code
<andrewrk> gruebite, if the code in your paste used normal pointer types it would be easier for me to see what you are trying to do
<gruebite> stuck on learning how to initialize this :D
<gruebite> .ext = [_](*const Foo){&foo0} not quite
<gruebite> [1]* != [*c][*c]
<andrewrk> you haven't provided the information I need to help you, which is the type of `ext`
<gruebite> in my previous paste: .ext = [_](*const Foo){&foo0}
<andrewrk> that's not a type
<gruebite> oops
<gruebite> ext: [*c]([*c]const Foo)
<andrewrk> stop using c pointers. try again
<andrewrk> c pointers do not tell me enough information about the type
<gruebite> i'm attempting to replicate the compiler crash "this is a compiler bug" by replicating the generated C header code
<andrewrk> oh, you're working on a test reduction, not trying to write code?
<gruebite> yeah
<andrewrk> I see
<gruebite> sorry if that wasn't clear :D
<Pistahh> andrewrk: does (or will) zig have any answers on stale pointers or use after free?
<gruebite> what i'm doing in my real code is iterate through a C type which is a linked list, so I end up looping a [*c][*c] type. i assume you're saying i shouldn't access this directly and should coerce them to zig pointers before accessing?
<gruebite> erm, linked list with a C array of pointers*
frmdstryr has joined #zig
<gruebite> in each list node
<andrewrk> Pistahh, I'm planning on addressing use-after-free in this release cycle
<gruebite> https://pastebin.com/PBdu9xpk basically iterating through this in zig is my real code, but I encountered a compiler bug while messing around
<andrewrk> gruebite, I'm saying in any code that you type into your editor, you will need `[*c]`, because zig pointers implicitly coerce to and from those. so use zig pointer types for everything
<andrewrk> sorry, you will *NOT* need `[*c]`
<gruebite> my zig code is using zig pointers, but i'm accessing the C stuff like `something.*.field`
<FireFox317> and gruebite you are probably getting that compiler error because you are using [*c] in your code, and as stated by andrewrk don't put any [*c] in your own zig file
<andrewrk> FireFox317, there's a compiler bug gruebite is in the process of creating a reduction for
lunamn has quit [Quit: leaving]
<FireFox317> Oh yeah sorry, ignore me gruebite :)
<gruebite> line 61 is where I get a crash https://pastebin.com/JWnXFvRU
<gruebite> removing that line no crash
<gruebite> trying to replicate it but i'm stuck on initializing the type that line 61 accesses
lunamn has joined #zig
<andrewrk> what error do you get
<gruebite> Assertion failed at /home/grue/packages/aur/zig-git/src/zig/src/list.hpp:31 in at. This is a bug in the Zig compiler.
<andrewrk> so you have successfully created the reduction then? what's the problem?
<gruebite> not yet, still haven't figured out how to initialize a [*c]([*c]const Foo) type :D
<gruebite> still learning zig as i do this
<lunamn> andrewrk: is there a plan to have implicit coercion for c pointer parameters when passing extern functions?
<andrewrk> gruebite, my advice to come up with a real type for ext is still valid. What is the actual type? without c pointers
<gruebite> it's an array of pointers
<andrewrk> lunamn, I'm pretty sure there already is
<lunamn> andrewrk: sadly, that didn't work in practice when using libexpat and passing callbacks
<andrewrk> lunamn, sounds like a bug
<FireFox317> I think it's not really clear to new Zig user that if you just import c stuff you can just use zig pointers, instead of the special c pointers. Same holds for when exporting stuff, you can just export zig pointers and they are valid c pointers
<andrewrk> FireFox317, I completely agree. I don't know how to solve this. The underlying problem is that .h files have shit pointer types
<gruebite> this gives me that compiler error
<gruebite> reduced case
<gruebite> not sure if can be reduced further
<FireFox317> That is a good reduction gruebite!
<lunamn> andrewrk: for example, "expected '?extern fn(?*c_void, [*c]const u8, [*c][*c]const u8) void', found 'extern fn(?*c_void, [*]const u8, [*][*]const u8) void'"
<lunamn> maybe its caused by it being slice of slice?
<andrewrk> lunamn, are there any error notes?
<FireFox317> gruebite: Do you also get the error if you don't use the type field in the Foo struct?
<lunamn> andrewrk: no notes other than "referenced here", so no
<FireFox317> gruebite: I mean if you name the field different
<andrewrk> lunamn, https://clbin.com/JxGje
<andrewrk> lunamn, you need `?`
<gruebite> FireFox317: testing
<gruebite> yeah it still crashes when field is not type
<gruebite> i'll reduce this further heh
<gruebite> https://pastebin.com/b80U9eAa this does it too
<gruebite> i'm on HEAD
<gruebite> is there an online zig sandbox? :D
<FireFox317> godbolt.org
<gruebite> seems like a simple case, no?
<FireFox317> Maybe it's actually because you have nothing in the switch case?
<gruebite> possible
<gruebite> also, there should be something official called "zag"
<gruebite> zigzag
<gruebite> hehe
<FireFox317> Yeah that is the issue gruebite: https://godbolt.org/z/Xzxnvv
<gruebite> yep
adamkowalski has joined #zig
<gruebite> maybe I can submit a pull request?
<gruebite> seems like a simple one
<FireFox317> If you would like to do that, yes!
<gruebite> :D
<gruebite> i can do it this afternoon (6 hours) if that's not too long?
<FireFox317> Should probably add a compile error when there is nothing in a switch indeed :)
<gruebite> yeah
<gruebite> or should empty switches be allowed?
<gruebite> just like empty ifs?
<FireFox317> Yeah I don't know actually, andrewrk?
bjorob has joined #zig
<andrewrk> empty switch is useful for empty error sets. you get an error if an error possibility is added
<frmdstryr> Is there something like a mem.replace?
<gruebite> what about switching on other types like an int?
<FireFox317> Ah jup indeed, but when switching on anything other than error sets give a compile error?
adamkowalski has quit [Ping timeout: 276 seconds]
<FireFox317> gruebite: The error is on line 24762 of ir.cpp, it sees that there is no else prong so it will check if all the possible integer values are switched on.
Akuli has quit [Quit: Leaving]
<FireFox317> gruebite: Are you making a PR? If not I have a patch ready
<dimenus> i like how I can do `const file = @This()` and not have name collisions
<dimenus> eg i can have `file.createVertexBuffer` which takes granular params and a `context.createVertexBuffer` which takes fewer params
adamkowalski has joined #zig
slice has quit [Ping timeout: 276 seconds]
adamkowalski has quit [Ping timeout: 240 seconds]
slice has joined #zig
<lunamn> andrewrk: would it be interesting to have an issue open to have compile notes in regards to making the parameters optional or?
<gruebite> FireFox317: I was going to do it this evening when I'm back at home
<gruebite> You can go ahead and submit it :)
<gruebite> I'll look at it and learn
<FireFox317> Are you sure? You can try it first and I can submit it tomorrow if you don't figure it out.
kristoff_it has joined #zig
<FireFox317> Or I can just submit it now yes xd
<gruebite> I'll take a stab at it :D
<gruebite> I may have questions tonight
<FireFox317> I can't answer them, because of different timezones I'm afraid. Tonight is already here :)
<gruebite> Europe?
<FireFox317> West Europe yes
<gruebite> Nice, I've only ever visited eastern europe
<gruebite> I'm in Seattle, currently looking at the olympic mountain range. It's quite cloudy
<FireFox317> Ah cool, we don't have mountains in the Netherlands :^)
<andrewrk> lunamn, yes, in fact I'm pretty sure it's a TODO in the compiler already, just needs a bit of glue code to wire that up
<gruebite> you have clouds though
adamkowalski has joined #zig
<FireFox317> gruebite: Yes unfortunately we have those too, btw the patch is just adding 33 chars on one line :)
<gruebite> and a test case?
<FireFox317> Yeah, you could add that as well
<mikdusan> corner case: `var x: u0 = 0; switch (x) {};`
<andrewrk> yes that should be allowed
<gruebite> `var x: u1 = 0; switch(x) {};`?
<FireFox317> Then it won't be 33 chars on one line xd
<FireFox317> For `u1` it should give a compile error I think
<gruebite> seems like this is a fairly important decision based on how the compiler wants to enforce things
<companion_cube> `var x: unreachable; switch(x) {};` ? :)
<gruebite> is it lax with non-error types and switches?
<gruebite> or should it be exhaustive for integer types
<andrewrk> it's always exhaustive
moo has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
wootehfoot has quit [Ping timeout: 276 seconds]
Ichorio has joined #zig
FireFox317 has quit [Ping timeout: 246 seconds]
<muffindrake> Is there some way to express 'this passed-in buffer must be at least this many elements big'? In C, function parameters are still pointers, but the language does support something along the lines of `int arr[static 5]` for 'this parameter is a pointer to at least 5 elements of type int`
<andrewrk> muffindrake, the closest zig has to that is doc comments + assert
casaca has quit [Ping timeout: 250 seconds]
<mq32> fun fact: zig has now 6,666 commits
<mikdusan> 👹
<adamkowalski> Has anybody worked on vim-test integration for zig?
<adamkowalski> I've implemented test file, and will start working on test nearest
<adamkowalski> but if somebody else has already done all that too I don't want to duplicate effort
<andrewrk> I believe you would be the first
<adamkowalski> Alright cool, I was just checking. Once it's in a reasonable state I'll make a PR to vim-test
moo has quit [Read error: Connection reset by peer]
<adamkowalski> Also i've been talking with the maintainer of the zig lsp implementation. We've been discussing anonymous structs. Those currently don't work. They currently implement parsing on their end as well. So when the compiler adds new features the lsp falls behind. Is there any way we can rely on the compiler to generate the AST and use that?
<gruebite> anyone else making zig bindings to godot native? :p
<adamkowalski> I think currently if you use the standard library zig parser it stops on the first misparse. They wanted to collect all the errors at once and then lint your file afterwards
<daurnimator> companion_cube: scientes: http 1.1 is terrifying difficult...
<daurnimator> it looks easy on the surface but is full of footguns
<companion_cube> yeah, if you want to make a fully featured thing (like nginx)
<andrewrk> I bet it's easy if you're willing to return "501 not implemented" and "413 request entity too large" for various things
<andrewrk> which IMO is entirely appropriate
<daurnimator> or even not be vulnerable to desync attacks.... or not fail terribly on a badly created server (if you're a client) or not fail on a bad client (if you're a server)
mahmudov has quit [Remote host closed the connection]
<daurnimator> e.g. what do you do when you receive two Content-Type headers back from the server? Did you remember to check for that?
lobsta has joined #zig
<andrewrk> zig is an ideal language for a perfect implementation of a spec such as this
<daurnimator> uh I meant to say Content-Length; but Content-Type is a simpler starting point
<daurnimator> andrewrk: yes! but its foolish to say that http 1.1 is simple
<andrewrk> I agree it's not simple, but I also want to point out that it is desirable to put resource limitations on the implementation, and this this does make things simpler
<andrewrk> e.g. if you have `content_length: ?u64` rather than `header_map: StringHashMap`, dealing with double content length is going to be in your face
<andrewrk> although with zig not letting you ignore return values and put() returning the old value, even the hash map version would help
adamkowalski has quit [Quit: Lost terminal]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<kristoff_it> I have a function with this signature: `pub fn init(keys: []const []const u8) Self`, when I call it like this `init(.{ "lol", "123", "test" });` I get an error. Is it reasonable to expect an automatic conversion for this case in the future?
<andrewrk> kristoff_it, yes, that's planned to work just fine
<andrewrk> there are a few issues related to anon struct/list literals to work out
<kristoff_it> andrewrk: very cool. I'm asking because this is an API I want to present to my users. Anonymous structs and arg lists are very powerful, I'm having a blast. Also all the async/await issues that I encountered in the past seem solved (with the occasional work-around) so great job on that too!
<fengb> expected type 'main.struct:512:31', found 'main.struct:512:31'
<fengb> Shouldn't that mean they're the same type?
<daurnimator> andrewrk: where should I put AFD struct definitions? make a new file windows/afd.zig ?
<andrewrk> sorry, I need to focus on a bug for a moment