ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
hoppetosse has joined #zig
rohju has quit [Quit: Leaving]
hoppetosse has quit [Ping timeout: 240 seconds]
cenomla has joined #zig
mal`` has quit [Quit: Leaving]
mal`` has joined #zig
cenomla has quit [Quit: cenomla]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
grinz has joined #zig
<grinz> const struct_type = @typeOf(Point); @compileLog(@typeId(struct_type));
<grinz> this code outputs "TypeId.Type". Is there a way to "dereference" struct_type so it will act as if I passed Point directly?
jacobdufault has quit [*.net *.split]
monteslu has quit [*.net *.split]
<andrewrk> grinz, const struct_type = Point;
<andrewrk> is that what you want?
monteslu has joined #zig
jacobdufault has joined #zig
<grinz> I cannot understand that difference
lorde_kumamon[m] has quit [Ping timeout: 255 seconds]
<grinz> Oh I got it. I was confused by return type of typeOf being "type"
return0e_ has quit []
return0e has joined #zig
jacobdufault has quit [*.net *.split]
monteslu has quit [*.net *.split]
<grinz> What is the right way to return comptime value from a function?
<GitHub102> [zig] tiehuis opened pull request #784: Add utf8 string view (master...utf8-string-view) https://git.io/vA2il
monteslu has joined #zig
jacobdufault has joined #zig
tiehuis has joined #zig
<tiehuis> grinz: do the following: `comptime const info = comptime get_type_info(Point);`
<tiehuis> you don't need to explicitly specify the comptime on that variable either
<grinz> thanks
<tiehuis> so `const info = comptime get_type_info(Point);` will suffice
<tiehuis> i usually find you can do most everything you need by either calling a function with comptime or specifying a function argument as comptime
<grinz> why compiler ignores comptime specifier on return type? Or compiler automatically converts comptime value to runtime value unless you specify comptime on call site?
<tiehuis> i'm not sure the internals on that sorry
<grinz> You can also write struct { t: (comptime type) } with the same result
<grinz> Feels like a bug / missing check
<tiehuis> i think all function calls are runtime by default now unless explicitly specified with comptime
<tiehuis> this issue seems to suggest that while proposing for a way to prefer comptime evaluation where possible: https://github.com/zig-lang/zig/issues/425
lorde_kumamon[m] has joined #zig
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
<grinz> @memberCount(type) => no value count available for type 'type'
<tiehuis> what is the type in this case?
<grinz> But it has fields in some cases like (&u32).Child
<grinz> Where can I get all possible fields of type metaobject?
<grinz> like Child
<tiehuis> oh i see, let me see if i can find a list
<tiehuis> couldn't find a specific list but there are some uses here: https://github.com/zig-lang/zig/blob/master/test/cases/reflection.zig
<tiehuis> see also this issue which would make this information a little less opaque of implemented: https://github.com/zig-lang/zig/issues/383
tiehuis has quit [Quit: WeeChat 2.0.1]
<grinz> I want to make a function which return type depends on argument type. I implemented it is this way: fn return_type_test(comptime Type: type) map_type(Type) { ... }
<grinz> Does Zig have something like automatic return type inference so I can replace map_type(Type) with something like 'auto'?
<MajorLag_> Theoretically "var" should work as a return type, but that isn't handled currently. A workaround is to return "type", and then return a new empty struct type containing your data: return struct { var data = "Test"; };
<MajorLag_> If your comptime Type is the same as your return type though, you can just do this: fn return_type_test(comptime Type: type) Type { ... }
<MajorLag_> which you probably already know, but in case you didn't.
<grinz> so you are defining struct with no fields but with global variable in struct scope?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<grinz> My best attempt. Any ideas how to get rid of double function evaluation?
<MajorLag_> No, you'll have the same issue you have with the function you're calling inside your test function. You'd have to wrap it up in an empty struct and return it that way again. Or, since you know the two values types it could return you could use a union I suppose.
<grinz> can i use comptime string as field name when defining struct?
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
hoppetosse has joined #zig
grinz has quit [Quit: Page closed]
steveno_ has joined #zig
steveno_ has quit [Ping timeout: 276 seconds]
steveno_ has joined #zig
<GitHub113> [zig] bnoordhuis opened pull request #785: allow implicit cast from `S` to `?&const S` (master...fix731) https://git.io/vAaZ4
hoppetosse has left #zig ["Leaving"]
hoppetosse has joined #zig
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
cenomla has joined #zig
cenomla has quit [Ping timeout: 240 seconds]
<MajorLag_> grinz, I don't think there's any way to do that today. I've wondered about doing that sort of thing myself.
<andrewrk> MajorLag_, I'll add return type inference
<andrewrk> do we have an issue yet?
hoppetosse has quit [Ping timeout: 256 seconds]
hoppetosse has joined #zig
return0e_ has joined #zig
return0e has quit [Read error: No route to host]
davr0s has joined #zig
davr0s has quit [Quit: Textual IRC Client: www.textualapp.com]
davr0s has joined #zig
monteslu_ has joined #zig
l1x_ has joined #zig
monteslu has quit [*.net *.split]
l1x has quit [*.net *.split]
monteslu_ is now known as monteslu
l1x_ is now known as l1x
hoppetosse has quit [Ping timeout: 260 seconds]
<MajorLag_> `.&` was an interesting suggestion. It looks weird, but it does have a certain logic to it, is unambiguous, clearly visible, and doesn't introduce any new symbols. I like it overall.
<MajorLag_> andrewrk, for block `[]` types, has t been considered to add a .size pseudofield? Like .len, but that gives @sizeOf(@typeOf(blockVar))*blockVar.len?
<MajorLag_> Because although that expression makes sense on the face of it, I believe it would be incorrect in the case of the new `[ ... ]null` types, since .len would not include the terminator.
steveno_ has quit [Quit: Leaving]
<andrewrk> I accepted josh's updated proposal
<andrewrk> MajorLag_, hmm that's an interesting question
<andrewrk> I can't think of when I would use the size instead of the length in practice
<MajorLag_> In an allocator implementation?
<andrewrk> wouldn't you request exactly N bytes, and then get a []T?
<andrewrk> where does a null terminated pointer come into play?
<andrewrk> s/bytes/items/
<MajorLag_> I don't know, just kinda thinking out loud. I even took the wrong type in that expression.
<andrewrk> I think in practice the null thing will be clear and clean
<andrewrk> based on having written all the OS abstraction code
<MajorLag_> You'd have a better idea than I would, for sure. I haven't written any Zig yet that cares about C interfaces other than the handful of calls I make to SDL. Though I have some projects I'd like to use it for in the near future that would be interfacing with kernel APIs and probably a bunch of other C-oriented interfaces.
<andrewrk> I think most application developers could ignore the null terminated pointer types
<andrewrk> and if for some reason you have a null terminated pointer type, it implicitly casts to the other ones
<MajorLag_> Ok, well, thinking it through it's a pretty easy to comprehend rule: null terminates the block, it is not a part of it. So if it comes up and I have to fill a buffer with null terminated strings from a list of strings, the code would be consistent regardless of the kind of block in the source string list and I'd have to insert the nulls during the copy.
<andrewrk> exactly
<andrewrk> a null terminated pointer type is an assertion that there is a null/0 there. so you would make a []T of len N + 1, and then do something like this to get []null T: ([]null T)(slice[0..slice.len - 1])
<andrewrk> there would be a runtime safety check here (when not in release mode)
hoppetosse has joined #zig
tridactyla has quit [Remote host closed the connection]
tridactyla has joined #zig
klltkr has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
klltkr has quit [Ping timeout: 240 seconds]
grinz has joined #zig
davr0s has joined #zig
<grinz> What is the point of having dedicated []null T pointer syntax? Interop with C?
<grinz> It's rather limited. Let's say I want to write fast lexer. Null-terminated string are quite handy in this particular case but one terminated zero is not enought to get best perfomance.
<grinz> When SIMD comes into play, you want something like 15 trailing zeroes. And this is where new type become completely useless.
<grinz> But sometimes having these bytes readable is enough (i.e. guarantee that slice end is at least 15 bytes away from page boundary)
<grinz> Any ideas how to implement that without helper function?
<grinz> []null T is of no use if you want to interact with WinAPI which uses UTF-8 (2 trailing zero bytes)