bitmapper has quit [Quit: Connection closed for inactivity]
<qbit>
how would one convert []const u8 to [*:0]const u8?
<andrewrk>
qbit, you have some bytes that are not null terminated, but you need a null byte afterwards. unfortunately there is no way to accomplish this without using a new memory location for the null terminated bytes
<andrewrk>
if you have an allocator handy, you can use allocator.dupeZ
<andrewrk>
if you control how the `[]const u8` is produced, you might want to introduce null termination earlier, to avoid having to do this conversion
<qbit>
drat, ok
<andrewrk>
does anyone remember what that website is that hosts recorded terminal sessions?
factormystic has quit [Read error: Connection reset by peer]
<brzg>
why might changing the length of a slice (in debug build) change the values of the items? am i encountering undocumented/unnoticed undefined behavior?
<brzg>
correction: the length change isn't changing the items, but something else mysterious is
<brzg>
the only events between displaying the original slice and the mysteriously change slice are operations that i thought would be read-only
factormystic has joined #zig
meinside has joined #zig
jumpnbrownweasel has quit [Ping timeout: 240 seconds]
brzg has quit [Quit: leaving]
earnestly has quit [Ping timeout: 265 seconds]
<v0idify>
is there a wayland implementation on zig? cc ifreund
<v0idify>
oh zig-wayland are bindings
<qbit>
can c functions be called at comptime?
<qbit>
getting error: unable to evaluate constant expression
mokafolio has quit [Quit: Bye Bye!]
<v0idify>
i assume not because comptime isn't linked to anything(?)
linuxgemini has quit [Read error: Connection reset by peer]
ave_ has quit [Remote host closed the connection]
lunamn has quit [Remote host closed the connection]
jumpnbrownweasel has joined #zig
osa1_ has joined #zig
osa1 has quit [Ping timeout: 244 seconds]
cole-h has joined #zig
a_chou has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
a_chou has quit [Quit: a_chou]
earnestly has joined #zig
sord937 has joined #zig
tnorth_ has joined #zig
sord937 has quit [Remote host closed the connection]
ur5us has joined #zig
allan0 has quit [Ping timeout: 276 seconds]
sord937 has joined #zig
allan0 has joined #zig
lunamn has joined #zig
ave_ has joined #zig
linuxgemini has joined #zig
cole-h has quit [Ping timeout: 245 seconds]
leon-p has joined #zig
notzmv has quit [Read error: Connection reset by peer]
sundbp has joined #zig
<ifreund>
v0idify: no complete pure wayland implementation in zig yet, zig-wayland is pretty nice to use though
<ifreund>
It is constrained by libwayland's design decisions though and is primarily designed to make working with libraries using libwayland like wlroots nicer
<ifreund>
a pure zig wayland implementation is something I'd like to see as it could potentially provide a much nicer API, lots of design space to explore there
posixlix has quit [Quit: Idle for 30+ days]
jumpnbrownweasel has quit [Quit: Connection closed]
<miartad>
Hello all, I have a question about Zig, specifically about arrays, there seem to be a hidden member "len" in an array. Does Zig plan to keep such hidden fields in arrays or other types in future? Doesn't it go against Zigs theme of not hiding stuff such as "no hidden control flow, no hidden allocations"
<ikskuh>
miartad: they are not hidden, just not well documented :D
<ikskuh>
you can always access array.len
<ikskuh>
you can even assign slice.len and slice.ptr
<ikskuh>
var slice: []const u8 = undefined;
<ikskuh>
slice.ptr = &[_]u8{1,2,3};
<ikskuh>
slice.len = 2;
<miartad>
I mean they are hidden in a way that they are not defined in code you write, you have to look at documentation to know there is such a field there
<ikskuh>
yeah but this is not the thing meant with "hidden"
<ikskuh>
you also have to know that you can use "a" to create a string literal
<miartad>
ok, maybe a better word is implicit
<ikskuh>
so? every type has implicit properties
<ikskuh>
an int has an implicit operator "+" which cannot be used on a enumeration value
<ikskuh>
this is the same level of "hidden" knowledge
<ikskuh>
you have to know that these exist, the same as you have to know the rules when you can apply "+" to a value
<miartad>
I guess so, however a field occupies memory in struct, unless this mechanism is compiler magic
<ikskuh>
neither an array nor a slice are structs
<ikskuh>
an array has thhe ".len" encoded in its type
<ikskuh>
its just the same as writing "3" for an array of length 3
<ikskuh>
but you can express intend and change the array length and update all those constants
<miartad>
ah, so its a compiler construct
<ikskuh>
yeah
<ikskuh>
and a slice is pretty much just struct { ptr: [*]T, len: usize }
<miartad>
ah right, then that makes sense, thanks for explanation
<miartad>
I would be happier with something like @arrayLen instead of .len but I will learn to live with what we have
<miartad>
:)
<ikskuh>
as well as sliceLen?
<ikskuh>
or just a combined one for both?
<miartad>
specifically Im not sure, just the idea would be to have a compile time function instead of using a property
<ifreund>
yeah an array's len field does not take up any memory at runtime
<ifreund>
that would make writing generic code more annoying
<ikskuh>
miartad: structs can also have comptime fields similar to arrays
<miartad>
ifreund I dont think the problem is memory size, its just that if there is additional field that you have not declared, the language is doing something programmer might not expect
<ifreund>
having a len field does not cause anything unexpected to happen
<ifreund>
knowing it is there is just part of the language
<miartad>
as long at it is a compiler construct and does not actually live in memory thats fine I think
bitmapper has joined #zig
miartad has quit [Quit: Connection closed]
Talon has joined #zig
Rum has joined #zig
<Talon>
Hey, I'm pretty new to all this so sorry if this isn't the right place to ask. I'm trying to build Zig on my M1 Mac, but I'm running into the error "Undefined symbols for architecture Arm64" when it's trying to link. I'm using LLVm from homebrew and had to add the paths for it in the cmake files because when I tried to build LLVm as per the instructions I kept getting segmentation faults. Can anyone point me in the right direction, or is Zig on the m1
<Talon>
not possible yet? Might this have anything to do with me using LLVM 11.1.0 instead of 11.0.0?
Scotch has joined #zig
Scotch has quit [Remote host closed the connection]
Rum has quit [Ping timeout: 264 seconds]
<ifreund>
Talon: it should definitely be possible, but I'm not familiar enough with mac to know what specifically is causing your build to fail
yyp has quit [Quit: now it's safe to turn off your computer]
midgard_ has joined #zig
midgard has quit [Ping timeout: 245 seconds]
<Talon>
yeah I'm pretty sure I'm doing something wrong, but not sure what. Homebrew was able to build llvm from source, but when trying to build zig with it, I get the undefined symbols for arm64 error, and when I try to build LLVM from source manually I get weird segmentation faults. I also tried using the llvm from ziglang.org that that pull request used, but same thing.
jokoon has joined #zig
TheLemonMan has joined #zig
<v0idify>
ifreund, there's no wayland-egl bindings no?
<v0idify>
ifreund, yeah but that's just gl not egl. (already using it)
<ikskuh>
this is a pure zig binding (generator, written in mono)
<v0idify>
what epoxy does confuses me
<v0idify>
i'm new to opengl
<ikskuh>
it loads opengl
<ikskuh>
newer opengl (>= 3) will not expose it's api in libGL
<ikskuh>
so you need a way to call these functions
<ikskuh>
there are a lot of libraries out there that load those
<ikskuh>
glew, gl3w, libepoxy, zig-opengl
<v0idify>
ah
<v0idify>
another layer \o/
<ikskuh>
well, it's not another layer
<ikskuh>
all those libs do the same:
<v0idify>
it seems i
<v0idify>
it seems i'm reimplementing part of ZWL lol
<ikskuh>
they load function pointers via some "get proc address" function
<ikskuh>
so it's nothing that *adds* any layer, it's just required to use modern opengl
<v0idify>
huh
<ikskuh>
if you remove the step of loading the function pointers
<ikskuh>
you won't be able to call any opengl function :D
<v0idify>
it still means having another component
<ikskuh>
well
<ikskuh>
you can also *not* use an external library
<ikskuh>
and do the *exact same* work again :D
osa1_ has quit [Ping timeout: 265 seconds]
<v0idify>
:P
<ikskuh>
i will port over zgl to use zig-opengl at some point in the future
<v0idify>
if i generate a file with zig-opengl it can be just saved in the repo instead of zig-opengl no?
<v0idify>
i don't want to add a mono dependency to my project :)
<ikskuh>
yep
<ikskuh>
the stuff won't change after generation anyways
<ikskuh>
except you need more extensions :D
<ifreund>
v0idify: what are you working on by the way?
<v0idify>
ifreund, some kind of gio and microui style GUI toolkit (toy)
osa1 has joined #zig
<ifreund>
sounds lovely :)
<v0idify>
:D
<v0idify>
with minimal footprint ideally, memory and CPU wise
<ifreund>
wayland only? or are you going cross platform?
<v0idify>
ideally cross platform but i'm trying wayland first
<v0idify>
i mean i'm writing it so ideally it could be ported
<v0idify>
but again, a toy and not sure if it will even be remotely finished :)
<ifreund>
I personally would be totally happy if it were wayland only :D
<v0idify>
lol yes but I want it to make cross platform things :P
<v0idify>
funny cause i'm running Qubes so I run sway as a window and run the thing there
<ifreund>
that feature of wlroots is absolutely awesome for development :)
<v0idify>
yes!! it's amazing
<ikskuh>
v0idify: ah, cool!
<ikskuh>
i have tackled my UI project today again :)
<v0idify>
ikskuh, any clue on how to install csc in fedora by any chance? :#
<ikskuh>
install "mono"? :D
<v0idify>
already did
<ikskuh>
hm
<v0idify>
it's mono-complete but yes
<ifreund>
does rpm not have a way to search by file?
<v0idify>
apparently it's `dnf provides <query>` but i still can't find it that way.. i'll look, thanks
<ikskuh>
you can also try mcs
<ikskuh>
:D
letoram has quit [Ping timeout: 240 seconds]
letoram has joined #zig
<qbit>
/window 4
<qbit>
aww
tnorth_ is now known as tno
<v0idify>
ikskuh, mcs works
<sm2n>
this is a dumb question, but how do I allocate memory? I'm trying to use GeneralPurposeAllocator, so I initialize it and then do something like gpa.alloc(u8, 10); however this keeps erroring out with "alloc is private"
<sm2n>
oh, the allocator is a field in the returned struct
<sm2n>
I am stupid, I misread that
<sm2n>
I was actually following that exact guide
<sm2n>
question: in that guide there is the line "var gpa = std.heap.GeneralPurposeAllocator(.{}){};" what does the last {} before the semicolon do?
<g-w1>
it inits the struct returned by GeneralPurposeAllocator
<g-w1>
in zig functions can return structs
<ifreund>
s/struct/struct type/
<sm2n>
why is this necessary?
<sm2n>
i.e shouldn't the struct already be initialized?
<v0idify>
i still need to @cInclude EGL right?
cole-h has joined #zig
<g-w1>
sm2n: no GeneralPurposeAllocator just returns a struct type, you have to initalize it
<dutchie>
consider: `const Point = struct { x: f64 = 0, y: f64 = 0 };` then to make a point you have to do `Point{ .x = 3.1415, .y = 2.7183 }` or (using the defaults) `Point{}`
<sm2n>
oh, I see, it's not a value.
<sm2n>
That is pretty neat
<dutchie>
GeneralPurposeAllocator is the same, but you have to do a function call to get the type (since you can pass it options)
<dutchie>
because the options are passed as an anonymous struct (the odd-looking `.{}` syntax) you get this double {} appearance
<sm2n>
okay this is starting to make sense, thanks!
jumpnbrownweasel has joined #zig
<sm2n>
I'm really liking zig so far, this is my first hour or so writing code, and I already feel comfortable jumping to definition in the stdlib to understand what is going on
<g-w1>
yep, the best way to learn the std is to just read the code
<sm2n>
there are not too many languages where you can do that, but I love when you can
<sm2n>
In C I have better luck reading disassembly than glibc code, though musl is better about it
<sm2n>
I tried to shorten the allocator invocation to "var A = (std.heap.GeneralPurposeAllocator(.{}){}).allocator;", but now I'm getting random segfaults
<sm2n>
is it throwing away bookkeeping information or something?
tno has quit [Quit: Konversation terminated!]
<g-w1>
yes
<g-w1>
you must have a gpa instance for the allocator to call
<g-w1>
basically the Gpa sets some function pointers in the Allocator struct (basically an interface) and they call back into gpa. without the gpa, it has nowhere to call back into and breaks
<g-w1>
reading that might also help you understand the problem more
<sm2n>
so I changed it back, and then added a line "var A = gpa.allocator;", but now I get "error: cannot store runtime value in compile time variable" when I call A.alloc()
<sm2n>
I will read that thanks
<g-w1>
s/var/const
<sm2n>
still get the same error
<g-w1>
ah it should be &gpa.allocator
<sm2n>
ok that works
<sm2n>
why does that work?
<g-w1>
i *think* it is the same error, you are copying the allocator, but somehow it is caught at compile time now
<sm2n>
I see
<sm2n>
thanks for the help
<sm2n>
From the language reference "The initialization value of global variables is implicitly comptime."
<sm2n>
this seems to concur with what you said
<g-w1>
yeah, any global variable's default value has to be comptime known
dyeplexer has quit [Remote host closed the connection]
<txdv>
does it happen on discord?
jumpnbrownweasel has quit [Quit: Connection closed]
<g-w1>
yes
daeluk has joined #zig
jokoon has quit [Quit: Leaving]
daeluk has quit [Remote host closed the connection]
Akuli has joined #zig
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<g-w1>
andrewrk: for the new zir layout branch, the doc comment for error set is this: `/// Create an error set. extra[lhs..rhs]. The values are token index offsets.` I am unsure what lhs and rhs mean? it does not say what the payload type is. is it safe to assume that it is Bin since it has lhs and rhs?
<g-w1>
I can't use astgen as a reference since it is not updated
<andrewrk>
g-w1, look at some of the other tag doc comments for example. that one needs to get updated (the sema code for it is commented out with a @panic("TODO"). I recommend to start with one that has a Sema implementation completed (which is most of them)
<g-w1>
thanks, right now I am trying to reslve the sema panic
<g-w1>
seems like it would be `Bin`
<andrewrk>
I was saving that one because I wanted to audit it
<g-w1>
ohh, so I shouldn't do it?
<andrewrk>
I'm pretty sure enums, unions, structs, opaque, error sets, will be handled externally to the astgen/sema pipeline
<g-w1>
why error sets? they can have decls in them?
<g-w1>
or because they are types?
<andrewrk>
hmm an explicit error set can be handled in there, that's right
<andrewrk>
but they have to interact with inferred error sets, and I'm not sure what that looks like yet
<g-w1>
ah, would there be something better for me to work on for now?
<andrewrk>
yeah, nearly anything else :)
<andrewrk>
I think I'm quite close to getting it to compile
<andrewrk>
then it will be clear how to contribute
<g-w1>
ah, I think I can help with the astgen once it starts to compile; thanks
<andrewrk>
yeah that's a great place to help
<ifreund>
what is enumArray? it doesn't seem to be defined anywhere...
<ifreund>
maybe I should make sure it's not explained in the PR description
<andrewrk>
an imaginary abstraction that I thought of, and SpexGuy happened to implement at the same time, out of pure coincidence :) https://github.com/ziglang/zig/pull/8171
<ifreund>
seems like that should be closed by #8171 to me
<andrewrk>
I think that is precisely what spexguy is intending to do
<Nypsie>
Has an attempt been done to measure the differences between ifreund's SoA and andrewrk's?
<ifreund>
#793 isn't mentioned in the PR yet so I'll leave a comment
<andrewrk>
Nypsie, not yet! that would be some welcome information
<Nypsie>
Sounds like something fun to find out. Will give it a spin this weekend :)
<ifreund>
Nypsie: yeah, I've been too busy with other things to do that benchmarking, go for it
<andrewrk>
be sure to take into account the potential benefits ifreund's version has with regards to fewer future allocations due to less wasted overhead
<andrewrk>
running zig fmt on the std lib would probably be a reasonable bench
<Nypsie>
Ah, thanks for pointing that out
<ifreund>
mine also has a somewhat simpler API as turning it into a struct of owned slices is possible
<andrewrk>
g-w1, I don't see where the error_set zir tag is created, do you?
<g-w1>
zir.zig:520
<andrewrk>
I mean where one is actually instantiated- oh! found it, in astgen.errorSetDecl
<g-w1>
yeah, that seemed not to be updated yet
<g-w1>
the compiler treats them as decls, but also as values
<g-w1>
but vexu left a TODO to make them types
<andrewrk>
confused why we bother to pass them to Sema, seems like we could construct them directly in astgen
<g-w1>
yeah
<andrewrk>
anyway I'll look into this more carefully later, I want to focus on getting it compiling first so others can jump in :)
<g-w1>
makes sense :)
<TheLemonMan>
llvm12 merge when?
<andrewrk>
oh snap did they release?
<mikdusan>
no
<TheLemonMan>
not yet (we can still get some bugfixes in, eg. #8117), but it'd be better to catch any regression asap
<andrewrk>
no wai they have so many open bugs
<andrewrk>
the null hypothesis is we merge it the moment that they officially tag the release
<andrewrk>
TheLemonMan, I'll do a complete test suite run overnight tonight with a debug llvm 12
<TheLemonMan>
beware of #8251, I haven't had enough time to triage it yet
<andrewrk>
noted, thank you
<andrewrk>
I wonder if our CI is green
<andrewrk>
I thought jakub's linker changes were tripping something
<g-w1>
he made some of the things use lld before merging
<andrewrk>
ah he adjusted the default selection logic. nice
Ristovski has quit [Quit: 0]
<andrewrk>
oh snap we have exactly 1000 behavior tests right now
<andrewrk>
I think there is more low hanging fruit like this
<g-w1>
nice
<mikdusan>
I don't grok how zld merge is green. on 2 x86_64 macs (11.2 and 10.13) standalone/global_linkage fails for me; same error message for a simple build-exe hello.zig
<mikdusan>
and ci just passed the very test failing for me.
<andrewrk>
I'm sure jakub would be very interested in a bug report
<mikdusan>
oh wow. might be related to env ZIG_GLOBAL_CACHE_DIR and ZIG_LOCAL_CACHE_DIR which I set.
<mikdusan>
ok no biggie
<ifreund>
stage1-memory-layout branch when? :P
<g-w1>
lol
<andrewrk>
ha
<andrewrk>
idk there is a legitimate argument to be made to do that
<andrewrk>
I mean I'm doing it to some degree right now so I can merge a PR that is blocking stage2
<g-w1>
the enumarray is blocking stage2?
<andrewrk>
yeah
<andrewrk>
need it :)
<g-w1>
for what?
<ifreund>
Consts
<ifreund>
g-w1: see const_inst_list
<yyp>
enumarray?
<g-w1>
ah i see
<yyp>
What even is that? I've never heard of something like this
<andrewrk>
it's when you want an array item where the elements correspond to enum fields
<yyp>
Is there a way to force Zig compiler to dump LLVM IR to a file instead of producing the binary?
Techcable has joined #zig
<g-w1>
--verbose-llvm-ir
<v0idify>
answer to myself -> depends on the driver. on EGL: eglGetProcAddress
<yyp>
g-w1: It dumps a lot of unrelated stuff besides the IR file
<yyp>
I want to see what it actually feeds into llvm
<g-w1>
-femit-llvm-ir=path
<yyp>
Oooh I see, --verbose-llvm-ir is what I wanted, thanks!
Akuli has quit [Quit: Leaving]
<v0idify>
error: cast discards const qualifier -> i'm sure this is fine (c stuff), how can i tell it to f off?
<TheLemonMan>
scary
tughi has quit [Ping timeout: 246 seconds]
tughi has joined #zig
<ifreund>
v0idify: @intToPtr(@ptrToInt())
<yyp>
Does that convert it to const?
<v0idify>
no, const -> non const
<v0idify>
non const -> const are done automatically
<yyp>
Not so sure about non-const -> const
<v0idify>
well i am :)
<ifreund>
v0idify: you can cast away const that way
<v0idify>
yes i understand
<ifreund>
ah, yeah I misinterpereted
<v0idify>
hmm not having wayland-egl along zig-wayland is annoying, i have to ptrCast all over the place I think
<v0idify>
thanks btw
<ifreund>
zig-wayland provides all the wayland-egl functions?
<v0idify>
sorry i meant egl
<ifreund>
or is it missing something?
<v0idify>
using egl with zig-wayland is weird
<ifreund>
you should only need to @ptrCast() like once to initialize egl right?
yyp has quit [Quit: now it's safe to turn off your computer]
<ifreund>
If you see ways to improve this, let me know by the way. I haven't actually written a EGL client in zig yet
<v0idify>
i believe i need it a few times during init, i'll get back to you on it though
<v0idify>
<3
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
sord937 has quit [Quit: sord937]
<v0idify>
ifreund, i also patched my way into zig master with zig-wayland, i can send it if you want
vegai has quit [Ping timeout: 246 seconds]
vegai has joined #zig
<ifreund>
v0idify: oh sure, go ahead and open up a PR if you like. Though I wont merge it until 0.8.0 is released it would save me some time :)
<v0idify>
of course
Thalheim has quit [Ping timeout: 264 seconds]
so has quit [Ping timeout: 246 seconds]
so has joined #zig
sm2n has quit [Quit: Leaving]
sm2n has joined #zig
<v0idify>
ifreund, the shell extension is not registering
<ifreund>
hmm? what do you mean?
<v0idify>
can i PM you? this is very zig-wayland and wayland specific :#
<ifreund>
#river would be fine
Voltaire has joined #zig
<g-w1>
andrewrk: I unfortunately missed the part of the stage2 meeting where you talked about the zir memory layout. was there anything discussed that has not been discussed here/on discord?
Voltaire is now known as Thalheim
mokafolio has quit [Read error: Connection reset by peer]