ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<benjikun> I'm probably still missing a lot but still comfy so far
<andrewrk> oconnor0, try https://clbin.com/
wink_ has joined #zig
<benjikun> andrewrk: Is it OK to use clone and use master normally?
<benjikun> or should I wait for next release
<benjikun> I'd like to have the old struct syntax knowing it's already coming back
andrewrk has quit [Ping timeout: 272 seconds]
<suirad> benjikun are you talking about when it was without the .
<benjikun> Yep
<suirad> that was changed back in a recent merge on master, the grammer stuff i believe
<benjikun> changed back to having the `.`?
<suirad> to not having it
<benjikun> yeah ik
<benjikun> Do you use the latest release or do you build from the master branch normally?
<suirad> are you saying you want the `const Thing = struct.{}`
<benjikun> nah
<suirad> current master no longer has that, i believe
<suirad> i use latest release
<benjikun> same
<benjikun> not sure if using master is recommended
<benjikun> ig it probably doesn't matter
return0e has quit [Remote host closed the connection]
andrewrk has joined #zig
return0e has joined #zig
<suirad> the only thing that using master has caused me to do, is clear my appdata cache after the grammar stuff caused the struct dot thing to switch back. no complaints here
<benjikun> you're on windows?
<benjikun> haven't used zig on windows yet
<benjikun> only on the WSL & normal nix
<suirad> primarily yea. i develop on both and use popos(ubuntu) regularly, but my system base is windows.
<benjikun> I've got devuan on my desktop and windows 10 on my laptop
<suirad> ive found zig setup on windows to be as frictionless as on linux. Which isnt the norm and id say is a big plus.
<suirad> download zig.zip; extract and add to path; install git[/gitbash] which comes with vim; install zig vim plugin; good to go
porky11 has quit [Quit: Leaving]
diltsman has quit [Ping timeout: 256 seconds]
Sahnvour has quit [Quit: Page closed]
diltsman has joined #zig
<diltsman> Wasn't expecting @memcpy to compile to __aeabi_memcpy...
<diltsman> lld can't find that. Is it somewhere in the Zig distribution, or would it be somewhere else?
<daurnimator> diltsman: that function is part of the ARM ABI
<andrewrk> diltsman, we need to port __aeabi_memcpy from llvm's compiler_rt into zig's std/special/compiler_rt/
<diltsman> Ok, so work in progress. Good enough. While not a concise, a loop will work.
<andrewrk> or if that's provided by libc we need to port that into std/special/builtin.zig
<andrewrk> bottom line is it's a missing feature of zig, but relatively small effort to add
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<andrewrk> it's still best to provide it, because optimizations can turn your loop into a @memcpy
<oats> so I'm expanding on my little toy kernel that I wrote following the x86 kernel coding livestream, and I'm trying to figure out how I can leverage std.fmt.format() to create my own printf-like function, but I can't figure how format() is supposed to be used. can I get any tips?
<diltsman> To build in release-fast you do "zig.exe build --release-fast", right?
<suirad> yes
<diltsman> Unrecognized argument: --release-fast
<hryx> Hey andrewrk, I want to help with stage2 or std, but I'm not quite able to build stage2 yet. The stage1 compiler segfaults when trying to build any zig files
<hryx> any tips on debugging?
<daurnimator> diltsman: zig version ?
<diltsman> zig-windows-x86_64-0.3.0+3666fbd9
<benjikun> Is there a difference between build-exe and build
<benjikun> perhaps try `zig.exe build-exe file.zig --release-fast`
<hoppetosse> andrewrk: just caught your stream on parsing floats
<diltsman> benjikun: I have a custom linker script and build.zig.
<hoppetosse> I remember doing something waaay back when, can't remember where I ported this from:
<hryx> benjikun: "zig build" uses the zig build system, i.e. you have to write a special build.zig file. "zig build-exe <file>" just builds a regular executable
<benjikun> oh
<andrewrk> hryx, stage2 is blocking pretty hard on coroutine rewrite which is blocking on copy elision
<andrewrk> both high difficulty projects
<hoppetosse> as soon as you mentioned remembering where the dot was, it clicked
<andrewrk> hryx, can I suggest another idea for you?
<hryx> please do!
<diltsman> So, --release-fast won't work. -Drelease-fast does.
<andrewrk> until now I've been telling people "wait until self-hosted" for generated docs
<diltsman> andrewrk: the loop to replace @memcpy optimizes to __eabi_memcpy, too. So, for now, I can only compile in debug or release-small.
<andrewrk> but now I think it's valuable to have in stage1
<hryx> andrewk: ok, sounds good. I'll start poking around with that project
<andrewrk> oats, I don't remember where it is in the source, but I'm pretty sure this project does print formatting: https://github.com/AndreaOrru/zen
<andrewrk> hoppetosse, ah interesting, I'll review your code before next thursday
<andrewrk> diltsman, benjikun: apologies for the CLI args inconsistencies. when we start approaching 1.0.0 I'll do a command line args API audit and gain some consistency
<andrewrk> maybe the different syntax is ok, since the zig build syntax hints that there may be other options outside the set you pass to build-exe, etc
<benjikun> andrewrk: All is good, I suspect copy elision is taking most of your time
<diltsman> My only issue is that the command-line help gives the wrong argument. Other than that, no real preference.
hoppetosse has quit [Ping timeout: 245 seconds]
suirad has quit [Ping timeout: 256 seconds]
* daurnimator is trying to write zig again...
<daurnimator> so... is there a counting for loop?
<daurnimator> e.g. how would you count from 1 to n in zig?
<oats> daurnimator: nope, incrementing can be done with while loops
<benjikun> daurnimator: Unless you want to write a simple custom function, do this with a while loop https://ptpb.pw/VYN5
<oats> var i = 0; while (i < 10) : (i += 1) { ... }
<daurnimator> ah, the 'continue express' helps to keep it cleaner
<daurnimator> *expression
scriptnull has joined #zig
<daurnimator> btw, reading through the manual I don't see where the |value| syntax is introduced... yet it starts showing up in examples
<shachaf> Oh, that's part of while, interesting.
<shachaf> daurnimator: As far as I can tell |x| is syntactically part of for, while, catch, etc., not a standalone thing.
<daurnimator> shachaf: I first notice it in 'if' `if (a) |value| {`
<daurnimator> okay. so it is the result of the thing in the parenthesis?
<daurnimator> what is that form called
<hryx> the |x| syntax is called "capturing" I believe
<daurnimator> hryx: okay. I also see "pointer capture"
<hryx> and it works on if, while, and switch branches
<hryx> ah yeah, |*x| does the same thing, but instead of a copy, you get a reference (pointer)
<daurnimator> is a pointer capture something special syntactically? or can you sort of use other operators on the capture there?
<hryx> just those two forms exist as far as I know
<benjikun> to be fair, the documentation is not a tutorial on purpose (for now)
<hryx> although with for loops, you can additionally capture the index with |x, i|
<benjikun> with how everything is changing
<hryx> or, if you only want the index, discard the value with |_, i|
<hryx> unlike most symbols, _ is actually specially recognized (as "intentionally discarded value")
<hryx> the throwaway variable name. Go uses it too, and (by convention) Lua
<shachaf> Hmm, for some reason I thought ranges were a first-class value, but it looks like they only syntactically exist in a few places?
<hryx> I only know of ranges working in switches
<benjikun> yeah that's the only place I've seen the ... thing
<hryx> i.e. `0...9 => { return; }`
<hryx> yeah
<shachaf> And slices
<benjikun> slices are more
<benjikun> afaik
<hryx> the slicing notation isn't precisely the same thing, but similar. and it uses .. instead of ...
<daurnimator> can you declare args as const?
<benjikun> yes
<hryx> actually, arguments are already const (I thought this was a bug at first)
<benjikun> You normally do that for strings
<benjikun> `const[] u8 filename,` for example, I think
<benjikun> otherwise you'd have to specify the length
<hryx> that would be `[]const u8`, but yep
<benjikun> whoops
<daurnimator> doesn't that say the array members are const? rather than the array itself?
<benjikun> lol yeah I'm still getting the hang of prefixed []
<hryx> I read from left to right as "slice of constant bytes", or `*const i32` as "pointer to constant i32
<hryx> it's backwards from C/others but I think more intuitive :>
<benjikun> the order of that stuff was kind of confusing for me at first, too
<errpr> I'm trying to cast to a void pointer to pass into windows, is this the proper way: `@ptrCast(*c_void, @alignCast(@alignOf(*c_void), BitmapHandle))`
<hryx> daurnimator: yep, []const u8 means that the array members are const
<errpr> I don't really know what pointer alignment means, tbh
<shachaf> For some reason (Ruby?) I thought a..b was [a,b) and a...b was [a,b]
<hryx> However, as I mentioned, function arguments are all const already. So there's no need to declare param as x: const bool
<hryx> (for example)
<shachaf> I didn't find it in the documentation, though.
<benjikun> be forgiving when it comes to the documentation, it isn't done
<hryx> shachaf: .. is only used in slicing `x[0..x.len]` and ... is only used in switch branches
<shachaf> OK.
<shachaf> That's what I get for random guessing.
<daurnimator> so does zig do things at comptime where it can automatically?
<benjikun> yes, I believe so
<daurnimator> is there a way to see if something is getting done at comptime or not?
<benjikun> that's a good question, and I've wondered it myself
<hryx> I think you'd want to look at the zig IR passes?
<hryx> that would probably reveal it (never done it myself)
<daurnimator> that doesn't sound easy
<daurnimator> I guess you could create a comptime{} block in your function and print a compile time warning there or something?
<hryx> it would be awesome to have some kind of IDE/editor integration that told you when inspecting a function
<benjikun> hryx: That would be fantastic
<hryx> `fn f(x: i32) void {} // (comptime)`
<benjikun> interesting idea
<daurnimator> hryx: wouldn't it change depending on parameters?
<hryx> there's an issue for implementing Language Server Protocol, but not sure if it would handle that
<hryx> daurnimator: yeah I think so
<daurnimator> likewise there would be some branches that are comptime and others that aren't? I assume?
<hryx> branches as in branches of an if/switch? Or just blocks?
<hryx> I'm actually still getting the hang of using comptime, so I'm not super sure... I think you can totally have a comptime block in a runtime function, as long as all the values it refers to are comptime-known
<hryx> don't quote me on that (I say while being permanently logged on the internet)
<shachaf> I mean, every comptime block is used in a runtime function.
<benjikun> building from master rn, I keep hitting blocks where CLANG variables are set to NOTFOUND
<shachaf> I have the same problem. :-(
<benjikun> I did `cmake .. -DCMAKE_C_COMPILER/usr/bin/gcc`, and that worked, but the errors came back up after running make
<shachaf> I thought it might be that my version of clang from apt is too old?
<hryx> valid point shachaf - I suppose I meant as opposed to a top-level comptime block
<benjikun> `make CC='/usr/bin/gcc'` doesn't suppress the errors, either hmm
<shachaf> Ah, I guess so.
<hryx> I had to install a ton of stuff using LLVM's own repositories as described here https://apt.llvm.org/
<hryx> under the section labelled "Install (qualification branch)"
<benjikun> will do, thanks hryx
voldyman has joined #zig
<benjikun> what's the deal with `zig build --build-file ../build.zig test` returning "unable to find zig lib directory"
<benjikun> hryx: Any idea?
<benjikun> oh nevermind
<benjikun> Now I'm getting this :/
<benjikun> I installed all of the LLVM stuff hmm
<benjikun> well, I guess running all the tests doesn't really matter; it installed regardless so that's good
suirad has joined #zig
<daurnimator> hrm
<daurnimator> how can I generate structs with a function?
<daurnimator> something like https://ptpb.pw/1qhk
<benjikun> at runtime? an anonymous struct or a predefined one?
<daurnimator> benjikun: at comptime
<benjikun> ah I got ya
<benjikun> one sec
<andrewrk> daurnimator, look for examples in the standard library, for example std/array_list.zig
<daurnimator> benjikun: ah, 'type' is the magic I was looking for
<benjikun> :)
<benjikun> but yeah, looking at a lot of the tests in the stdlib tend to help
<benjikun> so for that, you could search "return struct {" in the zig repo and it will normally give you help
<daurnimator> is there a tailq in the zig std library
<daurnimator> looks like std.linked_list might actually be a tailq?
<benjikun> there's a queue thing, not sure if that's the same
<benjikun> std/atomic/queue.zig
<daurnimator> benjikun: incase you don't know what I'm asking about, see `man TAILQ_HEAD`
<andrewrk> daurnimator, are you talking about an intrusive linked list?
<andrewrk> std.LinkedList can be intrusive if you use @fieldParentPtr
oconnor0 has quit [Ping timeout: 250 seconds]
<daurnimator> andrewrk: yeah intrusive doubly linked list that tracks the tail item.
<daurnimator> (tracking the tail item is actually quite expensive; so you shouldn't do it unless you need to. however it looks like zig's ListedList module does it all the time. Good for me now, but not necessarily for every task)
<daurnimator> in an anonymous struct definition, how do I reference the struct itself?
<daurnimator> ah. const Self = @This();
<benjikun> yep
scriptnull has quit []
<daurnimator> is there a way to not repeat "MyList" here? https://ptpb.pw/szdI
oconnor0 has joined #zig
oconnor0__ has quit [Ping timeout: 256 seconds]
<daurnimator> :( the zig linked list implementation doesn't have a way to concat one list onto another
<daurnimator> ooo fun, segfault while compiling
<benjikun> perhaps make an issue for it
<daurnimator> reducing it down to a test case now
<daurnimator> ^ how *should* be doing that?
<daurnimator> andrewrk: I'm not sure how you're saying to use @fieldParentPtr
<daurnimator> how do I only conditionally have a struct member?
<andrewrk> daurnimator, make the type void or non-void depending on some comptime value
<andrewrk> there are some examples in the std lib
<daurnimator> andrewrk: ah interesting. hadn't considered that
<daurnimator> andrewrk: and what about for a conditional function?
<andrewrk> if you don't call a function, it doesn't go into the binary. that includes if you don't calll it like this: if(false)foo();
<andrewrk> in this example foo is not analyzed and will not emit compile errors
<andrewrk> if(builtin.os == builtin.Os.windows) windowsOnlyFunction();
<daurnimator> andrewrk: but the function uses things that only sometimes exist
<andrewrk> I'm sure if you try to code it, it will make sense
<daurnimator> struct { const Self = @This(); x: if(somecond) u64 : void, pub fn bar(self: *Self) void { dostuffwith(self.x) } }
<andrewrk> I'm headed to bed, good night
<daurnimator> aw
<daurnimator> How can I create *two* structs/types when I call a function at comptime?
<shachaf> daurnimator: The same way you return two things from any function, I guess?
<shachaf> I don't know whether there's a better way to return multiple values, but "const T = struct{a: type, b: type}; fn foo() T { ... }" seems to work
<shachaf> Also I guess there's a thing where "const r: foo().a = (foo.a){...};" is an error but "const R = foo().a; const r: R = R{...};" isn't? So each time a struct is instantiated it's considered a different type or something?
errpr has quit [Ping timeout: 250 seconds]
davr0s has joined #zig
hio has quit [Quit: Connection closed for inactivity]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
<daurnimator> incompatible types: 'bool' and '*bool'
<daurnimator> getting that error on this line: if ((to_pending != &self.expiredList) && (to_pending.first == null)) {
<daurnimator> how is that second bit (after the &&) a *bool?
<daurnimator> hell. replacing it with `true` keeps the same error
<daurnimator> I think the error message is pointing to the wrong thing....
<daurnimator> heh.... yeah I think so: https://ptpb.pw/g60O
<daurnimator> doh. && is not an operator in zig
porky11 has joined #zig
<ltr_> andrewrk: I was looking into the CI script for linux to generate de tarball that goes in the webpage, and when it compiles its never says something about static linking the resulting binary, yet it compoiles to a self contained executable , i cant reproduce that., if i build zig it results on a executable depending on a lot of system libs. any idea whats happening there?, may be its something related with
<ltr_> nixos?
yellow_apple has quit [Remote host closed the connection]
<daurnimator> hrm. rotr on small values is odd
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<daurnimator> When using a pointer capture, can I have it non-const?
scriptnull has joined #zig
scriptnull has quit [Read error: Connection reset by peer]
scriptnull has joined #zig
<daurnimator> how are optional types implemented?
<daurnimator> ==> if I have a ?u64 how much memory does it use?
<MajorLag> You mean like in a for loop? for(whatever) |*b| ? The pointer should only be const if the elements of whatever you are looping over is const, I think.
<daurnimator> and is there some way I can tell zig that a certain bitpattern isn't valid for it so that it can use it as the 'null' value
<MajorLag> Optionl pointers use no extra memory, otherwise it is a tagged union so there is extra space.
<MajorLag> You can check how much using @sizeOf(?u64)
<daurnimator> MajorLag: I hope I condensed this down correctly: https://ptpb.pw/Yi5u
davr0s has joined #zig
<MajorLag> `for (array) |col| {` => `for (array) |*col| {`
<MajorLag> just a guess
<daurnimator> MajorLag: huh. that works :)
<daurnimator> MajorLag: I don't entirely understand why
<MajorLag> If you don't capture a pointer, you're telling the compiler that you don't intend to modify the element, so it is const.
<MajorLag> so within the `for(array)|col|` loop, `col` is const, so `for(col)|*row|` is now looping over a const.
<daurnimator> MajorLag: thanks
<MajorLag> Or maybe a better way to put it is that whatever is captured is const, but when you capture a pointer it is the pointer that's const, not what it points to?
<daurnimator> MajorLag: yep
<daurnimator> Going back to an earlier question that never got answered: how can I only conditionally define a function in a struct
<MajorLag> As in, "this function only exists under these conditions"?
<daurnimator> yes
<daurnimator> something like: fn foo(x: bool) type { return struct { if(x) fn bar() void {} }; }
<MajorLag> Hmmm... I'll have to think on that. Usually I think you'd just write it such that it is generated as a noop under those conditions. One thing that comes immediately to mind is to write it such that under those conditions it throws a compile error. That still isn't exactly what you want because introspection will still see it as present though....
<daurnimator> as an interim solution.... we don't have multiple dispatch do we
<daurnimator> so... I guess I have to pre-declare a magic return time
<daurnimator> something like: fn foo(x: bool) type { const mytype = if(x) realtype else void; return struct { fn bar() mytype { if (x) { realbody(); return stuff; } } }; }
<MajorLag> we don't have runtime multiple dispatch, no. Not as part of the language. I believe alexnask wrote an example vtable implementation in a gist somewhere.
<daurnimator> oh at least I can do: fn foo(x: bool) type { return struct { fn bar() if(x) realtype else void { if (x) { realbody(); return stuff; } } }; }
<MajorLag> seems a little strange. You could write the fn under a different name, then optionally link it to the correct one. I'll give an example, just a sec.
<daurnimator> MajorLag: I'll upload my actual project in a min
<daurnimator> MajorLag: you'll probably see why I'm doing it this way
<MajorLag> This way is similar to what I proposed about the compileError, but at least introspection won't see it as a function if it is set to void.
oconnor0 has quit [Ping timeout: 246 seconds]
oconnor0 has joined #zig
errpr has joined #zig
oconnor0 has quit [Ping timeout: 252 seconds]
oconnor0 has joined #zig
oconnor0 has quit [Ping timeout: 272 seconds]
oconnor0 has joined #zig
diltsman has quit [Ping timeout: 256 seconds]
<andrewrk> ltr_, after the tests pass it builds a static executable in a docker container with alpine linux
<andrewrk> daurnimator, I've been meaning to make a proposal for the "bitpattern not valid" thing you mentioned
oconnor0 has quit [Ping timeout: 268 seconds]
oconnor0 has joined #zig
hoppetosse has joined #zig
oconnor0 has quit [Ping timeout: 250 seconds]
oconnor0 has joined #zig
<ltr_> oh
<MajorLag> andrewrk, thats interesting, I would have thought that'd go against zen. Seems like it could fit pretty well with range-restricted types though and I know that's been brought up.
<MajorLag> andrewrk: no one has been able to tell me, and I can't find any reference to the reasoning behind align() being restricted to a max of @sizeOf(T). I'd like to propose that align() could be used more generally which would make SSE and similar easier to work with by a) allowing align() > @sizeOf(T), b) allowing [N]align() T, and c) adding the ability to alias align()'d types.
<daurnimator> okay all done for now
<daurnimator> that's the first non-trivial piece of zig I've written
<daurnimator> I'd love someone to review it
<daurnimator> andrewrk: ^ do you want a timing wheel library in the standard library at all? :)
oconnor0 has quit [Ping timeout: 252 seconds]
oconnor0 has joined #zig
scriptnull has quit []
<daurnimator> huh.... how can I iterate over the *whole* range of a number?
<daurnimator> e.g. if I have a u8... how do I iterate from 0 to 255? note that the 'normal' way overflows. `var i:myunsignedtype = 0; while (i <= std.math.maxInt(myunsignedtype) - 1) : (i += 1) {}`
<daurnimator> I think the only way is: `var i:myunsignedtype = 0; while (true) : (i += 1) { ..... if (i == std.math.maxInt(myunsignedtype)) { break; }}`
<daurnimator> makes me wish for a do/while loop syntax
oconnor0 has quit [Read error: Connection reset by peer]
oconnor0 has joined #zig
m4ge123 has quit [Read error: Connection reset by peer]
m4ge123 has joined #zig
Sahnvour has joined #zig
<MajorLag> `var i: @IntType(false, MyUnsignedType.bit_count + 1) = 0;`
<daurnimator> MajorLag: assuming that there is a bigger type available
<Sahnvour> hi andrewrk, is it OK to replace an embedded IrInstruction* by another (the result of ir_implicit_cast in my case) without doing more ? No ir_ref_instruction or anything ?
<MajorLag> `var i = MyUnsignedType(0); var done = false; while(!done):(done = @addWithOverflow(MyUnsignedType, i, 1, &i)) {}`; admittedly pretty ugly.
<andrewrk> MajorLag, what do you mean about align being restricted? we support overalignment, I thought
<MajorLag> If that's the intention I'm pretty sure it doesn't work. Hold on a sec, I'll rig up an example, maybe I'm doing it wrong.
<MajorLag> But while I'm doing that, the docs for @alignOf say `The result is a target-specific compile time constant. It is guaranteed to be less than or equal to @sizeOf(T).`
<andrewrk> right, so when you do @alignOf(T) that's called "ABI alignment" and it is guaranteed to be less than or equal to @sizeOf(T), and there's an important reason for that, that I forgot but should probably document
<andrewrk> so when a pointer has the same alignment as ABI alignment, the align annotation is omitted
<andrewrk> but more things always can be implicitly cast to less aligned things
<andrewrk> and you can use any alignment in var and fn declarations
<andrewrk> *more aligned things always can...
<MajorLag> hmm... odd, your test is working but I could have sworn my own experiments showed that even though it compiled, larger alignments didn't actually work.
<andrewrk> the llvm ir for my example: %x = alloca float, align 64
<MajorLag> ah. I see the difference. My experiments all used const instead of var.
<andrewrk> that should work too, smells like a bug
<MajorLag> `const x: f32 align(128) = 12.34; std.debug.warn("x={}\n", @ptrToInt(&x) % 128);` => `x=64`;
<andrewrk> hmm now this smells like an LLVM bug. the IR zig produces for your example looks correct
<andrewrk> wait a minute, I see a problem
<andrewrk> good catch MajorLag. zig is creating a global constant and not applying the correct alignment. this should hopefully be a quick fix
<andrewrk> Sahnvour, I don't think you'll need to use ir_ref_instruction unless you're creating a new ir_build_foo function
<andrewrk> can you elaborate on your question?
<MajorLag> as for the rest of what I was saying, you could define a SEE u8 array: `[16]align(16) u8` and if you're going to use it a lot it'd be helpful to type alias: `const Sse16u8 = [16]align(16) u8;` is all.
<Sahnvour> andrewrk, so I have this IrInstructionAsm and when analyzing it, I use ir_implicit_cast as you advised me to, to handle comptime ints/floats. Basically I'm currently just overwriting the IrInstruction* representing the asm input value (contained in the IrInstructionAsm) by the new instruction that is casting it to another type
<MajorLag> but if you could alias then @alignOf's behavior might not make as much sense. `@alignOf(align(16) u8) == 1;`
<andrewrk> MajorLag, what you are describing is a new feature; currently alignment requirements can only be specified in variable declarations and function definitions
<MajorLag> yeah, I know. I did mention it was a proposal.
<andrewrk> my mistake. I haven't caught up on the chat logs
<MajorLag> there's a lot of it. no worries.
<andrewrk> would it make sense to alias a single-item pointer to an SEE array? `*align(16)[16]u8`
<andrewrk> Sahnvour, I'm not sure overwriting an instruction is a good idea; this would be the first instance of it in the whole compiler
<andrewrk> or maybe I misunderstand
<MajorLag> sure, but you still have no way of aligning the array itself
<MajorLag> other than an allocator
<andrewrk> is this related to SIMD?
<Sahnvour> hmm, then I would have to insert this cast earlier ?
<andrewrk> can I see what you have so far?
<MajorLag> that's what brought it up, yes. I haven't been doing anything with SIMD but someone here was (I forgot who).
<Sahnvour> sure, give me a moment (doing multiple things at once)
<Sahnvour> (and if this was for me ^^')
<andrewrk> Sahnvour, yes :)
<andrewrk> MajorLag, I'm planning on giving SIMD some serious attention in 0.4.0
<hryx> andrewrk: I'm working on stage1 docgen. The source is easy to understand, nice & clean. my compliments to you and all contributors
<andrewrk> hryx, happy to hear that :)
<andrewrk> is this before or after you cracked open ir.cpp?
<hryx> I'm in tokenizer.cpp currently, no ir.cpp yet
<hryx> I want to put together and share a brief implementation plan to make sure I'm not going down the wrong path
<andrewrk> sounds good
<hryx> I'll post it on the GH issue when that's ready
<andrewrk> hryx, here's a pipeline overview: tokenize (tokenizer.cpp) -> AST (parser.cpp) -> Zig IR Pass 1 (no types or comptime computations) (ir.cpp) -> Zig IR Pass 2 (most analysis here) (ir.cpp) -> LLVM IR (codegen.cpp) -> Link (link.cpp)
hoppetosse has quit [Ping timeout: 246 seconds]
<andrewrk> analyze.cpp is utility functions
<hryx> very helpful, thanks!
<wink_> FYI: I've taken std/json* moved them to https://github.com/winksaville/zig-json and added support for floats if anyone is interested. The json tests continue to work and I added a "FloatNumber": 33.0 to the test "json parser dynamic" and was able to get "FloatNumber" and assert it == 33.0. No further testing has been done so careful :)
<Sahnvour> andrewrk, what I have right now https://gist.github.com/Sahnvour/ef8e6d058d33abcbfa0e7e61ba0bbd19 , afaict it compiles and runs fine but I didn't look at the assembly output yet
<Sahnvour> search for `See here`
<Sahnvour> but if this is too late in the sense that asm inputs already have their instructions (and we don't watn to override them), I would have to plug myself earlier, when we are actually creating the instructions, so ir_build_asm_something I guess ?
<andrewrk> Sahnvour, I understand your question now
<andrewrk> what you want to do is have an intermediate instruction IrInstruction *casted_input_value = ir_implicit_cast(...); and then put the casted instruction in the input_list[i] slot. I see now that what you were talking about was not so much "replacing" instructions in the code, but more just a question of whether to use a tmp variable or mutate the list slot directly
<andrewrk> IrInstruction *input_value = asm_instruction->input_list[i]->child; IrInstruction *casted_input_value = ir_implicit_cast(...); input_list[i] = casted_input_value;
<andrewrk> Sahnvour, a couple other things, the way to check for a const instruction is instr_is_comptime, not if the id is Const
<andrewrk> look at examples for this
<andrewrk> and finally, upon considering, I'm not sure, do we want to implicit cast comptime ints and floats? or should they just be compile errors? I'm wondering what it looks like to populate a large register with a large integer constant. e.g. xmm0
<Sahnvour> wow ok, I realise my question was misguiding as I did in fact not read the existing code correctly. It's already creating a new instr based on the input IrInstructionAsm but not modifying/analyzing it as I thought ; should be clear now
<Sahnvour> regarding the implicit cast, my reasoning was that trying to cast to a more or less "native" machine data type would do the trick for most purposes (otherwise one can always do it directly inside the asm template), and that it is better than just crashing
<andrewrk> right - but if it's not correct for all cases, better to make it a compile error, and then the user can choose a type like this: usize(1234)
<Sahnvour> that's sound
<andrewrk> certainly we do not want it to crash
<hryx> I asked earlier but don't have a solution yet: I can build stage1 just fine, but using it to compile zig code causes a segfault. Any ideas or debugging tips?
<andrewrk> hryx, are you using the same compiler to build stage1 as was used to build the llvm and clang you link against?
<hryx> here's Valgrind output from just now https://hastebin.com/uyinuhulet.txt
<hryx> Good question...
<andrewrk> C++ has an ABI mismatch issue
<hryx> is there anything in the Cmake output which would tell me?
<andrewrk> I notice the valgrind stack traces show a segfault where stage1-compiled code calls into llvm/clang libraries
<hryx> That would make sense
<andrewrk> where are you getting llvm/clang from?
<hryx> apt-get on Linux Mint
<andrewrk> to be absolutely sure, you can build them from source. there are instructions in the wiki
<andrewrk> are you building stage1 with clang?
<hryx> It looks like I have a lot of different LLVM versions installed, so this could be possible
<hryx> Yep
<andrewrk> because the default compiler on debian/ubuntu/mint is gcc
<andrewrk> so that's the problem
<hryx> oh, it has to be built with gcc?
<andrewrk> all the apt-get packages are built with the system compiler - gcc
<hryx> fantastic
<hryx> thanks a lot, I'll try that
<andrewrk> so if you link against apt get packages you have to use the system compiler
<andrewrk> or you can use any compiler you want if you build llvm/clang from source
<hryx> BTW, these are from the repositories listed at apt.llvm.org, since my distro doesn't have LLVM 7 yet
<hryx> great tips, that should get me going
<andrewrk> happy to help
<Sahnvour> andrewrk, how would use advise the user to "use something like usize(1234)" but in a compiler-error-y fashion ? "comptime constants are not allowed as inputs, instead use explicit typing" ?
<andrewrk> something like, "expected sized integer or sized float type, found comptime_int"
<andrewrk> one thing I would want to do is understand exactly why it's crashing. I haven't investigated that yet
<andrewrk> e.g. what assumption is the code making that is incorrect, causing it to crash?
<nbjoerg> maybe add an "explicit" in that
<andrewrk> often that assumption can be reworded into a compile error message
<Sahnvour> the thing is that later in the code, we expect that some ir struct has pointers set to continue compilation, but it doesn't, I can check that again, just a minute
<andrewrk> MajorLag, I think copy elision branch might actually fix (or at least clobber) the incorrect alignment of constants issue
<andrewrk> bottom line is that the issue won't be closed until we have test coverage
oconnor0 has quit [Ping timeout: 240 seconds]
<Sahnvour> yeah right, so in ir_render_asm, we iterate over asmexpr->input_list to create the param_types array to pass to LLVM, but the comptime instr has no `type_ref`
<Sahnvour> and it crashes later on in LLVM code
oconnor0 has joined #zig
<andrewrk> and let's see how the type_ref is used
<andrewrk> aha, LLVM's inline assembly syntax requires types on all the inputs
<andrewrk> so it would, I think, make sense to use u128 with xmm0, for example
<andrewrk> and zig doesn't understand assembly yet, so we couldn't infer the type without an explicit annotation
<andrewrk> so therefore I think requiring an explicit type makes sense
<andrewrk> Sahnvour, I'm going to see if this works: https://clbin.com/GfMiL
<andrewrk> error: couldn't allocate input reg for constraint '{xmm0}'
<andrewrk> hmmm
hoppetosse has joined #zig
<andrewrk> anyway this doesn't change anything. I think this is a bug in llvm
<MajorLag> andrewrk, you probably already knew this but I was wrong about not being able to align arrays (because I was doing it wrong from not having thought it through, of course), which would leave my proposal to just the type aliasing, which as you noted could be done by aliasing a pointer type, so I'm pretty sure that whole thing can be chalked up to me not having worked with align() enough to really understand it. At le
<MajorLag> g.
<andrewrk> I resolved the xmm0 issue. it depends on SIMD
oconnor0 has quit [Ping timeout: 272 seconds]
oconnor0 has joined #zig
oconnor0 has quit [Read error: Connection reset by peer]
oconnor0 has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
jjido has joined #zig
jjido has quit [Remote host closed the connection]
hoppetosse has quit [Ping timeout: 240 seconds]
steveno_ has quit [Ping timeout: 268 seconds]
emekoi has joined #zig
<emekoi> is std.Mutex reentrant?
oconnor0 has quit [Read error: Connection reset by peer]
oconnor0 has joined #zig
porky11 has quit [Quit: Leaving]
oconnor0 has quit [Read error: Connection reset by peer]
oconnor0 has joined #zig
oconnor0 has quit [Ping timeout: 268 seconds]
oconnor0 has joined #zig
oconnor0 has quit [Read error: Connection reset by peer]
oconnor0 has joined #zig