ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<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>
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....
<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 sr.ht, wikipedia, and rosettacode
<benjikun>
the test.py and output.html files are just for testing how it looks
<hryx>
tite benji!!
<benjikun>
ty :)
<benjikun>
if anyone sees anything wrong in `zig_lexer.py` 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/sr.ht/rosettacode
<hryx>
wadu heck
<benjikun>
:/
<benjikun>
maybe he's wrong because the repo seems to still get updated but they aren't accepting PRs
<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?
<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.
<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
<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?
<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
<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>
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>
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:
<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]