ChanServ changed the topic of #zig to: zig programming language | | be excellent to each other | channel logs:
<suirad> the build pipeline on my PR keeps failing the tests on an assertion, but im not sure why. im guessing that the env vars are weird on the build machines, but im not sure.
<benjikun> looking at it
<benjikun> the tests worked locally right?
<suirad> yea
<benjikun> I'll try em
<suirad> I appreciate it.
benjikun has quit [Read error: Connection reset by peer]
benjikun has joined #zig
<benjikun> computer crashed, one sec lol
<benjikun> I get an assertion failure on linux
<benjikun> same thing that the azure testbox returns
<benjikun> line 795 in index.zig
<benjikun> lemme try printing out the env variables and see what comes out
<hryx> I don't suppose it has to do with null-terminated strings?
<hryx> (in case mem.eql is returning false due to that)
<suirad> strange, since they should both be []u8
<benjikun> what's the correct way to output to the terminal in a test block?
<benjikun> probably a dumb question
<suirad> i usually just do a std.debug.warn
<benjikun> it isn't outputting anything with warn
<suirad> then regular stdout
<benjikun> will do one sec
<benjikun> still nothing
<suirad> it might be exiting too quickly, output then loop
<suirad> there might be a flush if you're using stdout
<benjikun> I counted the bufmap of envs returned and it came out to be 0, weird
<suirad> that is wierd, but does explain why its failing on non windows, since im only working on windows stuff lol
<benjikun> lol
<benjikun> did you look at the logs for the failure on the windows test?
<suirad> yea, outofmemory apparently
<benjikun> mhm
<suirad> which is funny cause now that im checking, my tests for it pass. But when i call the fn in a small test program i get the overflow error
<suirad> err i meant outofmemory
<benjikun> interesting
<suirad> i know whats causing the outofmemory, but the other systems failing is confusing. at least after this there will be new working tests haha
_whitelogger has joined #zig
<benjikun> this is weird
<benjikun> for some reason in the test, the count returns 0 but if I just use it outside of that it works normally and returns 28 envs
<benjikun> so it's something with the test on line 777
<benjikun> which makes no sense
<benjikun> oh wait
<benjikun> ignore that
<benjikun> wait actually I was right
<benjikun> works outside of the test lol
<hryx> in a normal executable?
<hryx> tests are run in a child process I think -- I wonder if that affects environment
<benjikun> what the heck
<benjikun> I made a test file and copied the exact same test and it works fine
<benjikun> ???
<hryx> though it looks like the env should be getting passed by the compiler:
<hryx> weird
<suirad> lol
<suirad> compiler bug maybe?
<benjikun> is the new built zig version that I'm using (from the PR) somehow finding my default system-wide zig stdlib
<benjikun> is that possible
<hryx> I think the zig exe just looks for ../lib
<hryx> I'll try to find out though
<benjikun> that's what I'm thinking
<hryx> oh, it's based on the install prefix. did you build with `make install`?
<benjikun> yea
<benjikun> I did
<benjikun> can I somehow print out where it's looking?
wink_ has quit [Quit: - A hand crafted IRC client]
<hryx> if you don't mind rebuilding you can put this in main.cpp: printf("%s\n", buf_ptr(get_zig_lib_dir()));
<benjikun> mk will do
<benjikun> hryx: I did it but it isn't printing anywhere
<hryx> benjikun: where did you put the printf? it works for me if I put it here, build, and then call `./bin/zig test`
<benjikun> oh wait, it does output
<benjikun> yeah it's the correct path (not finding my normal install)
<benjikun> I have no clue what else would cause the test in std/os/index.zig to fail but not the same test in its own file
<daurnimator> andrewrk: reading and replying again...
<daurnimator> andrewrk: so to make things not require an allocation I might have to swap Job to be part of an intrusive linked list. (where I previously had the vague CollectionOf(Job))
<daurnimator> have updated my previous comment to match
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<suirad> so weird. its now failing the pipeline somewhere completely unrelated....
<benjikun> strange
<benjikun> why are `i0` and `u0` types?
_whitelogger has joined #zig
<daurnimator> consistency I guess?
<benjikun> yea
<benjikun> yea ig consistency
reductum has joined #zig
<MajorLag> Consider an enum with only one field. The type of the enum would be u0.
<benjikun> oh true
<MajorLag> the tag type
reductum has quit [Quit: WeeChat 2.3]
_whitelogger has joined #zig
<benjikun> I don't have a lot of experience with python but I'm attempting to make the zig plugin for pygments so we can get highlighting on, wikipedia, and rosettacode
<benjikun> This is what I have so far
<benjikun> the and output.html files are just for testing how it looks
<hryx> tite benji!!
<benjikun> ty :)
<benjikun> if anyone sees anything wrong in `` lmk
<hryx> I think I've been having dreams about zig syntax highlighting
<benjikun> lmao
<benjikun> same
<hryx> so you're helping my sleep quality
<benjikun> :p
<hryx> I didn't know pygments was python
<benjikun> yep it is
<hryx> yet as I type the first two letters of "pygments" I feel dumb
<benjikun> hehe
<hryx> yo. here's something weird, maybe someone can explain
<hryx> this is legal at top level: `pub const x: void;`
<hryx> but in a function or container type: "variables must be initialized"
<benjikun> interesting
<hryx> is the top-level one legal because of externs?
<benjikun> I'm not sure
<hryx> everywhere else, you have to say x = undefined to leave it uninitialized
<benjikun> if you try to interact with it though
<benjikun> it says it must be initialized
<benjikun> hmm
<hryx> huh...
<benjikun> e.g. warn("{}\n", @typeOf(x)); in main() makes it realize
<benjikun> feels like a bug to me
<hryx> good idea trying to use the var. Maybe MajorLag or andrewrk could shed some light
<benjikun> only thing I can think of is if it has to do with extern behavior like you said
<benjikun> good catch
<MajorLag> `pub const x = {};` aught to work to initialize a variable to void. `pub const x: void;` isn't complete. `pub const x: void = void{};` would be, but you can shorten it.
<benjikun> it doesn't catch it even if it isn't void
<benjikun> `pub const x: i64` works too
<hryx> yeah MajorLag I don't understand why it's legal to have that incomplete declaration at top level, while inside a function or struct it throws an error
<hryx> without trying to access it, that is
<MajorLag> It shouldn't be, but if you're not using it at all it probably isn't being analyzed far enough.
<hryx> ah that could be why
<hryx> I assumed anything pub was analyzed
<MajorLag> no, but anything extern is
<hryx> dayum
<hryx> also MajorLag what's your GitHub username, if you don't mind sharing?
<MajorLag> tgschultz
<benjikun> followed
<hryx> (^_^)_b
<benjikun> I went to the pygments devs channel (#pocoo) and asked how I could get the ziglexer plugin added to pygments head
<benjikun> but a guy said that the repo isn't actively maintained anymore
<benjikun> what the heck
<benjikun> so I don't have a clue about how we'll get zig highlighted on wikipedia/
<hryx> wadu heck
<benjikun> :/
<benjikun> maybe he's wrong because the repo seems to still get updated but they aren't accepting PRs
<hryx> is that the right repo?
<benjikun> yep
<hryx> last commit 13 hours ago. last one before that: 1+ year ago
<benjikun> ugh
<hryx> oh my mistake, I'm misreading BitBucket's merge tree
<hryx> that was the timestamp of an old commit, recently merged
<MajorLag> Anyone want to see some comptime shenanegans? Pseudo-struct with comptime generated fields:
<benjikun> look at all of the language adding requests in PRs
<benjikun> they make it seem like it's easy as pie to add your language's lexer once you make it on their website lol
<hryx> MajorLag: whoa
<hryx> delightfully devilish, seymour
<hryx> yo that sucks benjikun
<hryx> I feel bad for the maintainer who has to sort through all of it too
<benjikun> true
<benjikun> look at
<hryx> don't worry, they'll rewrite bitbucket in zig in a couple years anyway, so it will obviously be re-prioritized
<hryx> thx atlassian
<benjikun> lmao
<daurnimator> What is the zig equivalent of atoi? (convert string to integer)
<benjikun> you can do it cleverly because of how characters are plain u8s in zig
<daurnimator> I'd be suprised if there isn't something in the standard library....
<hryx> me too. then again, AK was implementing a float parser on stream the other week, so maybe it's TODO still
<MajorLag> std.fmt.parseInt
<MajorLag> no wait, the other way around
<daurnimator> huh? what other way?
<MajorLag> no wait, that was right. brain
<MajorLag> it's too late to be thinking. I'm going to bed.
<daurnimator> night :)
<hryx> peece
<benjikun> night majorlag
<benjikun> I know parseInt is what you wanted
<benjikun> but here is a simple alternative atoi in zig daurnimator
<benjikun> lol
<benjikun> I think using it would be fine if you added in comptime type recognition and possible error returns tbh
<benjikun> possible error returns being invalid character and overflow
<benjikun> speaking of the parseFloat livestream, I'm ready for the next one
<benjikun> I enjoy those streams a ton
_whitelogger has joined #zig
<daurnimator> o.o std.mem.split does not work like expected
<daurnimator> It seems to skip empty fields
<benjikun> what do you mean?
<hryx> daurnimator: Are you saying that you expect "x\t\ty" to split into ["x", "", "y"]?
<daurnimator> hryx: yes
<daurnimator> \t is the field separator.
<benjikun> hmm
<hryx> yeah that's how strings.Split works in Go too
<hryx> as in, what you expected
<hryx> I'll comment on your issue
<benjikun> also how it works in nim
<hryx> good call
<benjikun> yeah I think an `allowEmpty` flag would be great
<benjikun> commented too :p
<hryx> nice
<suirad> can anyone think of a comptime trick to have a defer propagate to the calling function? i tried inlining but that didnt work.
<hryx> suirad: what's the use case?
<suirad> trying to make something to the effect of a unique_ptr by causing a compile error if .deinit() isnt called; using comptime.
<suirad> i feel like a comptime fn that gets inlined should bring its variables and scope to the calling location
<suirad> *comptime variables
<hryx> Interesting idea. But I feel that when I see curly braces, I like knowing where the scope boundaries are
<hryx> What would it be like if an inline function (whose vars were hoisted like you say) were called from many different places?
<hryx> increase chance of symbol collision?
<hryx> side note: cool trick using .rs to highlight the source. I can't wait for zig highlighting :>
porky11 has joined #zig
<suirad> to prevent collision you could probably use some reflection stuff from std.meta or something. i presume XP
<suirad> essentially though, all I need to get this to work is: 1. add some sort of marker/flag for the used variable, in the scope of its use | 2. pre-set/defer an resulting action if the flag isnt cleared(compileerror) | 3. clear the flag on .deinit()
<suirad> 4. have it be contained within comptime; so no additions to the data structure & and cleaned away
<suirad> thats all :)
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<daurnimator> is there a generic string=>enum function around?
<benjikun> daurnimator: Do you mean like using a string as a tag?
davr0s has joined #zig
<daurnimator> ^ should I PR that to zig std lib?
<benjikun> it could work with unions too, right?
<benjikun> would go into std.meta
<benjikun> I think idk
<benjikun> I'm not sure where else it would fit in
<daurnimator> yeah std.meta would probably make sense
<daurnimator> Can I wrap an integer type? I want to add methods to it, but still want it to work with e.g. @intCast().
<daurnimator> silly example: struct Foo { n: u32, fn isEven(self: Foo) bool { return self.n%2==0 } };
<benjikun> there are a few things kinda like this we could add to std.meta but I'm not sure if they're hugely necessary
<benjikun> and I'm not sure if you can do that
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<benjikun> do you want to maintain how it works with operators?
<benjikun> or would you be okay with just `foo.value()`
<benjikun> not entirely sure what I'm even typing, I'm tired
davr0s has joined #zig
<daurnimator> benjikun: hrm. good question. for my particular case now I don't need it to work with operators I think
<benjikun> hmm
<benjikun> I don't think you can without doing a `.something` to retrieve its value
<benjikun> unless there is some hacky way
<benjikun> anyways, off to sleep. night night, have fun programming
<benjikun> :)
benjikun has quit [Quit: Lost terminal]
<daurnimator> If I have an optional enum is a smart packing used?
<daurnimator> Is there a way to say "the int type that can fit at least X"
<daurnimator> e.g. I have a comptime integer 12345 => how do I get the smallest unsigned integer type that it will fit into?
<daurnimator> ^^ I'm going to label those questions 'A' and 'B'
<daurnimator> C: How can I create an array of u21 where each element has the alignment of a u32?
davr0s has quit [Ping timeout: 268 seconds]
davr0s has joined #zig
davr0s has quit [Ping timeout: 268 seconds]
SimonNa has joined #zig
<andrewrk> daurnimator, no smart packing yet but that's planned. I don't know if I made an issue yet
<daurnimator> D. how do you get plain `zig test` to work? I've created a build.zig with a test step, however I always get "Expected source file argument"
<andrewrk> `zig build test` and then add a test step to your build script
<daurnimator> andrewrk: I just used `b.addTest()`
<andrewrk> yeah that's the one
<daurnimator> andrewrk: but that doesn't seem to work?
<daurnimator> I can write: `const test_step = b.step("test", "Test the program");` which gives me the `zig build test` command.
<daurnimator> andrewrk: I'm asking how b.addTest() is meant to be used.
<andrewrk> one of the planned features for this is to output a dependency graph for troubleshooting
<andrewrk> daurnimator, did the example I linked answer your question?
<daurnimator> andrewrk: no.
<andrewrk> b.addTest creates a step to run `zig test` as part of your build process
<daurnimator> andrewrk: okay. so it just is a `zig test` invoker.
steveno has joined #zig
<andrewrk> yes
<daurnimator> andrewrk: the original question was how do I make so I don't need to pass a source to `zig test`: in the help output it says source is optional.
<andrewrk> I don't think [foo] consistently means "optional" in the usage text
<andrewrk> in most of those compile options, the args in brackets are mandatory
<daurnimator> ah
<daurnimator> thats.... odd
<daurnimator> andrewrk: E: would you be interested in a PR to include ?
<andrewrk> yes, I think that once we near 1.0.0 it will be time to think about how to organize the cli
<andrewrk> arg parsing as well as how to communicate the options
<andrewrk> daurnimator, that looks like it belongs in std.meta
<daurnimator> andrewrk: k. I'll send a PR :)
<andrewrk> thanks
<daurnimator> (keeping score: questions A, D, E answered. B, C still open)
<andrewrk> can you repeat them? I've given up on trying to read all the scrollback all the time
<andrewrk> I see this one
<andrewrk> C: How can I create an array of u21 where each element has the alignment of a u32?
<daurnimator> and B is the line(s) just above that :)
<andrewrk> if we made @sizeOf(u17) == 4, as discussed in the pointer subtraction issue, that would make your array of u21, each element have alignment of a u32
<andrewrk> if we don't do that then the question isn't simple. I think we should discuss this in an issue to keep track of the use case
<andrewrk> "the int type that can fit at least X" you can solve this in userland
steveno has quit [Quit: Leaving]
<daurnimator> andrewrk: 'C' is separate to that previous sizeOf issue. I'm writing some code now where I have an array of u21. However for interop with C I want it to have a layout of u32. For the sake of argument lets pretend I wanted a layout of u128 instead.
<daurnimator> andrewrk: 'B' yes I understand it's solvable in userland. But for some reason I'm failing at doing the maths to figure it out :P std.math.log2 seems like the right place to be looking, but I'm not seeing the answer :(
<andrewrk> if it's interoperating with C you should use only integers that have C type equivalents, e.g. u8, u16, c_long, etc=
<andrewrk> if you need an array of u128, make an array of u128s
<daurnimator> andrewrk: so I guess another way of describing what I want is an array of u128 where accesses automatically cast to u21.
<andrewrk> I don't think that's ever going to be a feature of zig. I recommend making an access function that does the cast
<daurnimator> andrewrk: perhaps relatedly I asked a different question earlier today: is there a way to have a single-member struct act like it's only member? e.g. `struct {x: u32, fn customMethod() void {} }`
<andrewrk> no
<andrewrk> any time you want to propose to make the language more complicated, it's an uphill battle, and we need really convincing use cases
<daurnimator> maybe another angle on the same question: can I define @intCast for my structure?
<andrewrk> can you describe what you are trying to accomplish?
<daurnimator> andrewrk: today I've been playing with
<andrewrk> ah, excellent use case
<andrewrk> you're trying to make a Codepoint a more sophisticated type
<daurnimator> yeah
<daurnimator> so that you can do e.g. mycodepoint.toUtf8() or mycodepoint.isLower()
<andrewrk> I would propose this as the null hypothesis: Codepoint as a u21 is perfect. your library can have functions that accept codepoint: u21 as the first arg
<andrewrk> if it's really just the difference between unicode.toUtf8(mycodepoint) vs mycodepoint.toUtf8(), zig philosophy is to resist the urge, and just accept it
<andrewrk> if you can show that it involves potential footguns or other mistakes, and something fancier would prevent mistakes, then we have to reconsider
<daurnimator> okay. will see how things go
<daurnimator> andrewrk: so what I'm currently figuring out is how needs to be changed to work
<andrewrk> why doesn't it work? are you hitting a comptime bug?
<daurnimator> 1. need to adds lots of `comptime` annotations or else `parseUnicodeData` doesn't work.
<daurnimator> 2. too many backwards branches. and uping the limit to makes my computer run out of memory before it gets close to solving it...
<andrewrk> where is the unicodedata.txt file?
<daurnimator> andrewrk: run `zig build test` :)
<andrewrk> oh neat, I see it now
<daurnimator> 3. I don't have any actual "collection" data structure done yet: I'm looking for advice on what to use.
<andrewrk> your code looks fine. zig compiler needs to be made more efficient with regards to computation as well as memory usage in order to correctly run your comptime parsing code
<andrewrk> if you loop over an array of bytes at comptime, I think it currently uses 32 bytes per byte, or something absurd like that
<daurnimator> I can say that my computer uses over 20GB of ram trying to parse that 1.7MB....
<andrewrk> yeah it's much worse than the theoretical minimum
<andrewrk> eventually it should be about as fast as CPython
<daurnimator> It's comptime, so for now I mainly care about it working at all :P
<andrewrk> this use case of using @embedFile and parsing the stuff at comptime, is a good use case of zig. but I think zig is too immature to handle it right now. it'll be worth trying this again when self hosted is done
<daurnimator> so put the project on pause until.... 0.5.0?
<andrewrk> something like that
<daurnimator> k. bed time for me :)
<MajorLag> andrewrk: regarding comptime json->struct from the other day, here's a way it could (almost) be done in userland today:
<andrewrk> MajorLag, very interesting
<andrewrk> I hadn't considered that you can kinda create a struct at comptime via embedding
<MajorLag> it came to me when considering the question of "how could I tack a new field on to a struct?", which is really the only problem that needs solving for this sort of thing.
<andrewrk> for json though, wouldn't you just want to have a normal struct, and then use reflection to populate it with the parsed json?
<andrewrk> returning errors when numbers don't fit, etc
<MajorLag> My understanding of the discussion was that the desire was to create a struct type from a json definition at comptime, to avoid having to manually recreate the struct definition when something changes.
<MajorLag> Of course, this didn't fit their other desire: not using strings to access the fields since the IDE won't handle it like it would a normal field.
<MajorLag> Adding a build step that parses JSON and outputs a .zig file would get them what they wanted though. This was more just an excersize on my part I suppose than a real suggestion of how to do things.
<andrewrk> I'm not sure I agree with the validity of the use case. I think the struct would be the starting point, not the comptime json string
<andrewrk> that's fair
<MajorLag> I like to maintain my reputation as one of the worlds leading experts on abusing comptime.
<andrewrk> haha
<andrewrk> you and Hejsil
<andrewrk> and dbanstra
<MajorLag> oh yeah, I remember that.
<andrewrk> it seems that everyone is more of an expert at abusing comptime than me
<MajorLag> out of necessity, we can't change the compiler to get what we want as easily.
<andrewrk> that's a keen observation
<andrewrk> I have the privilege of writing code how it should be and then fixing the bugs in the compiler
<MajorLag> it's a good thing, exercises the language, finds the gaps or lack thereof.
<andrewrk> and making changes that for others would require approval
<andrewrk> I appreciate everybody's patience. I hate having to keep saying things like "that's planned" "not done yet" "zig is too immature to be good at that use case yet"
<andrewrk> I think the number of "really big" proposals is getting small. I believe the entire set of them is as follows:
<andrewrk> * copy elision * coroutine rewrite / agnostic blocking vs evented I/O * safe recursion / eliminate stack overflow * the object oriented abstraction question * package management * advanced control flow analysis
<andrewrk> after these it's just a steady flow of documentation, bug fixes, and minor improvements
<andrewrk> oh, and * zig build system
<andrewrk> and a linker
SimonNa has quit [Remote host closed the connection]
wink_ has joined #zig
SimonNa has joined #zig
steveno has joined #zig
steveno has quit [Quit: Leaving]
steveno has joined #zig
wootehfoot has joined #zig
steveno has quit [Remote host closed the connection]
wink_ has quit [Quit: - A hand crafted IRC client]
steveno has joined #zig
wink_ has joined #zig
steveno has quit [Ping timeout: 264 seconds]
davr0s has joined #zig
kristate has joined #zig
<kristate> Hi!
<kristate> andrewrk: is something going on with CI?
reductum has joined #zig
<MajorLag> andrewrk, whenever I find myself in a situation where one of the TODO features would be really helpful, I just tell myself I could be writing C instead and remember how good I have it because of what zig already is.
cgag has quit [Quit: WeeChat 2.2]
porky11 has quit [Quit: Leaving]
ibebrett has joined #zig
<reductum> MajorLag: I've been feeling the same way. It's amazing how much of a boost to morale and quality of life Zig already is.
benjikun has joined #zig
reductum has quit [Quit: WeeChat 2.3]
wootehfoot has quit [Read error: Connection reset by peer]
reductum has joined #zig