ChanServ changed the topic of #zig to: zig programming language | | be excellent to each other | channel logs:
<unique_id> First of, I'm an absolute atomics noob. I now see that the wikipedia page says that on x86 this is implemented via CMPXCHG.
<unique_id> From a noob's perspective these seem very different. CAS modifies the atomic only if the atomic is equal to some given value
<unique_id> xchg always modifies the atomic, returning the previous
<scientes> thats the cmp of cmpxchg
<scientes> i don't think zig has a xchg without the cmp
<unique_id> I'm not sure I understand you. On atomicRmw: "This builtin function atomically modifies memory and then returns the previous value."
<scientes> oh yeah that one doesn't have the cmp
<scientes> oh yeah atomicrmw has an xchg
<scientes> thats without the compare
<unique_id> In the system I'm designing I have atomics that can be in 3 states (0, 1, or 2). A streaming thread can bring an atomic from 0 to 1. That's a lock. Then it can take it from 1 to 2 (finish), or from 1 to 0 (cancel). With this design, which made be dumb as hell, atomic xchg is not good enough because a thread might bring a 2 to 1 having thought it was at 0.
<unique_id> might*
<unique_id> might* be dumb as hell
<scientes> nah you don't need that
<scientes> yeah you need cmpxchg
<scientes> if you are doing io in the threads while holding locks you need mutexes that use syscalls to avoid wasting lots of power
<unique_id> yes, I use condition variables
<scientes> heres a mutex for linux
<unique_id> I have all of that. This is for something else.
<unique_id> sorry for the language btw, I used the H word :)
<unique_id> I can split the 3 state atomic into two 2 state atomics, that'll work in my case.
<unique_id> One last thing, sorry for being so unclear and mixing singular and plural like that. I actually have lots of these atomics, one per memory/communication 'slot'. That's what I'm unsure about but at least it's simpler to implement than all alternatives.
<andrewrk> hmm maybe my next stream should be on atomics
<unique_id> that would be awesome
redj has quit [Read error: Connection reset by peer]
<scientes> andrewrk, are you still getting hash mismatch?
<scientes> perhaps just remove the secret, as with pull requests it already executes untrusted code
<unique_id> Why am I so blind? ... @cmpxchgStrong, @cmpxchgWeak
redj has joined #zig
return0e has quit [Ping timeout: 252 seconds]
kristate has joined #zig
wink_ has quit [Quit: - A hand crafted IRC client]
wink_ has joined #zig
kristate has quit [Ping timeout: 264 seconds]
mal`` has quit [Quit: Leaving]
mal`` has joined #zig
mahmudov has quit [Ping timeout: 245 seconds]
_whitelogger has joined #zig
kristate has joined #zig
mahmudov has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
porky11 has joined #zig
ofelas has quit [Quit: shutdown -h now]
porky11 has quit [Ping timeout: 250 seconds]
porky11 has joined #zig
porky11 has quit [Client Quit]
porky11 has joined #zig
DutchGh0st has joined #zig
<DutchGh0st> return []void {} ** n; <--- what does this do if `n` is a comptime usize?
return0e has joined #zig
DutchGh0st has quit [Quit: - A hand crafted IRC client]
DutchGh0st has joined #zig
return0e has quit [Remote host closed the connection]
return0e has joined #zig
<unique_id> I don't want to spam this channel with my nonsense, but just fyi I fixed my design. No more 3 state atomics.
<kristate> cool
mahmudov has quit [Ping timeout: 245 seconds]
<DutchGh0st> how fast is compiling normally?
DutchGh0st has quit [Quit: - A hand crafted IRC client]
kristate has quit [Ping timeout: 246 seconds]
_whitelogger has joined #zig
mahmudov has joined #zig
<andrewrk> nice, unique_id
<wink_> Just playing around with @OpaqueType and I thought something like this ( should work, is this possible?
<andrewrk> wink_, you can't pass an opaque type directly as a parameter because opaque types have unknown size
<andrewrk> you can pass a pointer though
<andrewrk> looks like that's what you wanted
<wink_> How do you "pass a pointer" I tried fn "assert(S.getValue(pS) == 1;"
<andrewrk> the compile error is pointing to the line where it is not a pointer
<wink_> I'm dense, I still don't understand how to fix it :(
<andrewrk> wink_, put a * in front of @OpaqueType()
<scientes> how do i get the value of an enum member that has an explicitely set value?
<scientes> cause then the index and the value would be differn't
<scientes> the docs say @memberType does not work on enum
<scientes> (but maybe it should)?
<andrewrk> @enumToInt
<scientes> oh thanks
<scientes> how do i call that with @memberName?
<scientes> I don't think i can
<MajorLag> @enumToInt(@field(EnumType, @memberName(...)));
<scientes> thanks
hoppetosse has joined #zig
<wink_> andrewrk: Adding * gives me error: expected type '*(anonymous opaque at opaquetype.zig:12:31)', found '*S'
<wink_> assert(S.getValue(ps) == 1);
<MajorLag> because `S.getValue(ps)` becomes `getValue(S, ps);`, you're passing type `S` in and the function definition expects @OpaqueType().
<scientes> I really need first-class functions, otherwise I'm going to have to copy the whole of mem.sort.sort just so I can have more control over the compare function
<scientes> I need to iterate over an array of strings, sorting by each character in turn
<hoppetosse> scientes: what do you mean by first class functions? you can pass function pointers just like in c
<scientes> But the number of functions would be the possible length of a string (usize)
<hoppetosse> you can also pass an array of function pointers
<scientes> I guess I could hack it with a global
<scientes> thats what i'll do
<hoppetosse> good luck =)
<scientes> you see the problem?
<scientes> I need to pass compareByChaR(left, right, whichChar: usize) to sort.sort()
<scientes> but there is no way to generate a function with that argument filled in
<scientes> whichChar
<scientes> I think this is a problem for closures
<scientes> (wehich is what i'm doing with a global var)
<hoppetosse> Oh, I see
<hoppetosse> is whichChar known att compile time?
<scientes> no, i'm iterating over the string, sorting repeatedly
<scientes> strings
<scientes> (I basically writing gperf in zig)
<scientes> but all this is basically done at comptime(eventually, it depends on the comptime allocator), and a global means wasting memory at run-time
<hoppetosse> How about generating one function for each character at compiletime?
<hoppetosse> yeah, but check how much memory it actually takes before saying it's too much
<scientes> 4 or 8 bytes
<hoppetosse> I just realized whichChar refers to the index of the char in the string, and not which chatacter to sort "around"
<scientes> yeah
j`ey has joined #zig
<j`ey> in Zig the std lib is distributed as source, right?
<hoppetosse> yep
<j`ey> is it expected to always be like that?
<hoppetosse> I think so
<hoppetosse> It has its advantages
<hoppetosse> in terms of optimization, from inlining to link time stuff
<j`ey> but also have to reparse and build every time!
<j`ey> but I guess the file watching async thingy will counter that
<scientes> maintaining shared libraries is a PITA
<j`ey> which files does the comptime evaluation in src/?
<scientes> mainly ir.cpp
<scientes> but i don't know the source too well
<j`ey> ir_eval_const_value might be it
<scientes> comptime is too limited, maybe there is a way I can return llvm IR from a funtion, and then have the function run at compile-time
<j`ey> I was actually wondering if it used LLVM's jit infrastructure
<scientes> I want to write gperf in zig
<scientes> and comptie doesn't do it, and it would be cool if I could avoid generating source code
<scientes> my idea is to have "comptime" functions, that return LLVM IR, and are run at compile-time
<scientes> meh generating source code isn't horrible, I just want to generate it every time and keep it out of source control
return0e has quit [Remote host closed the connection]
return0e has joined #zig
mahmudov has quit [Remote host closed the connection]
<wink_> MajorLag, andrewrk: Txs for the help, I got it to work you can see the details on the gist Basically I had to have a single defintion of a type with was aligned and an @OpaqueType().
<andrewrk> wink_, nice, glad you got it working
<j`ey> andrewrk: what are you going to do with translate_c with the self hosted compiler?
<andrewrk> j`ey, have a C API wrapper around libclang's c++ API, and then convert the c++ implementation to zig, using the C API wrapper to call into libclang
<j`ey> OK, that's what I was expecting!
<andrewrk> and then stage1 loses the ability to do translate C
<j`ey> doesnt it need that?
<andrewrk> no, it only has to build stage2
<j`ey> but doesnt stage2 use that feature?
<andrewrk> yeah but it doesn't need to. it'll be cleaner anyway to define llvm extern functions in .zig declarations
<j`ey> ah
<andrewrk> we already have this file, might as well complete it and stop doing @cImport
<j`ey> makes sense
hoppetosse has quit [Ping timeout: 252 seconds]
<wink_> In the past you've said stage1 will always needed, it seems to imply that stage one could go away, or am I reading to much in to what you
<wink_> have just said?
<scientes> the purpose of stage1 is to build stage2
<scientes> to avoid the Ken Thompson hack
<wink_> What is the Ken Thompson hack?
<wink_> I assume stageN will eventually build itself, wouldn't you still have the problem at that point?
<scientes> not if you always bootstrap with stage1 and a trusted c++ compiler
<scientes> that way zig is always shipped as *only* source code
<wink_> And you trust a c++ compiler :)
<scientes> no, I don't
<wink_> Me neither, so it seems like a weird problem, off the top of my head if we have the full source history of StageN then that history could be audited and we'd be able to "prove" StageN is non-corrputing. But just a guess.
<andrewrk> it matters how easy it is to build zig from source in practice
<scientes> nope, you don't understand the ken thompson hack
<andrewrk> in practice, when building zig from source, people have gcc/clang installed and do not have zig installed
porky11 has quit [Quit: Leaving]