Guest54845 has quit [Killed (weber.freenode.net (Nickname regained by services))]
Guest54845 has joined #zig
<gpanders>
Hi all, I'm trying to make a temp file with a given extension. I haven't been able to find anything in the Zig standard library that can do this, so I'm thinking I'll have to turn to using libc; however, the only portable libc functions I can find that do tempfile generation don't let you specify a file extension. The one function that does do this (mkstemps) is a GNU extension and doesn't appear to
<gpanders>
be supported by Zig ("container .cimport has no member called 'mkstemps'"). Anyone have any advice on how to get this done?
alexnask has quit [Quit: Leaving]
<gpanders>
oh and I should add that the tmpnam function (which I think would also work) explicitly says "avoid using these functions; use mkstemp(3) or tmpfile(3) instead.", so I'm thinking I should probably use that advice and avoid tmpnam
<andrewrk>
gpanders, what do you want to do with the temp file, just curious? there might be even higher level api for you to use
<gpanders>
I'm exec'ing pandoc to convert a plain text file to HTML, and need to provide a file path for it to write to, which is then opened in the browser (via xdg-open or similar)
doublex has quit [Ping timeout: 240 seconds]
<gpanders>
The .html extension is necessary so that xdg-open (or whatever) knows how to properly open the file
doublex has joined #zig
<andrewrk>
I see
knebulae has quit [Read error: Connection reset by peer]
<andrewrk>
I think your best bet right now is to follow the example of some of the code in std/fs.zig which generates random bytes, and then uses fs.base64_encoder
<gpanders>
Thanks, I'll take a look
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
satchmo has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
nephele_ has joined #zig
nephele has quit [Ping timeout: 260 seconds]
nephele_ is now known as nephele
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 264 seconds]
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
doublex has quit [Read error: Connection reset by peer]
doublex_ has joined #zig
ur5us has joined #zig
ifreund has quit [Ping timeout: 256 seconds]
doublex_ has quit [Ping timeout: 260 seconds]
knebulae has joined #zig
layneson has joined #zig
[rg] has quit [Ping timeout: 272 seconds]
<oats>
I can't find the issue about extending error enum types to be more like tagged enums, can someone help me find that one?
<tez>
I'm getting this error -> error: import of file outside package path. When i google it, I see you have to, "map your packages in as packages, or you'll have to choose an explicit root directory for the main package."
<tez>
How do I do that/
satchmo has quit [Ping timeout: 260 seconds]
stripedpajamas has joined #zig
<andrewrk>
tez, --main-pkg-path
layneson has quit [Ping timeout: 272 seconds]
<tez>
I typed in this -> zig test Test_Vertex.zig --main-pkg-path /home/tez/Desktop/zig/Master_Grapher/ and it seemed to work. Thanks!
<tez>
If I import something like this in my source code -> const VertexModule = @import("../src/VertexModule.zig");
<tez>
can i then make several instances of that thing that I import like this-> const vertex1 = VertexModule; const vertex2 = VertexModule;
wozeparrot__ has quit [Ping timeout: 256 seconds]
ur5us has quit [Remote host closed the connection]
ur5us has joined #zig
[rg] has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #zig
tez has left #zig ["Leaving"]
dddddd has quit [Ping timeout: 258 seconds]
xackus has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
[rg] has quit [Remote host closed the connection]
demizer has joined #zig
aerona has quit [Quit: Leaving]
gpanders has quit [Ping timeout: 256 seconds]
satchmo_ has quit [Ping timeout: 272 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 258 seconds]
ur5us has quit [Ping timeout: 260 seconds]
Guest54845 has quit [Read error: Connection reset by peer]
dimenus has quit [Ping timeout: 265 seconds]
SimonNa has joined #zig
halbeno has quit [Quit: Leaving.]
_Vi has joined #zig
halbeno has joined #zig
drp has quit [Ping timeout: 264 seconds]
stripedpajamas has quit [Quit: sleeping...]
dermetfan has joined #zig
riba has joined #zig
tdc has joined #zig
riba has quit [Ping timeout: 246 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 256 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 260 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 260 seconds]
satchmo_ has joined #zig
<pixelherodev>
Guessing no one can give me an instant answer as to where old_inst's "unnamed$N" comes from, or am I going to need to spend more time figuring this out? :P
<pixelherodev>
s/or/so
andy_bainbridge has joined #zig
<pixelherodev>
Ah wait, there's only one place outside translate_c where it can be :)
satchmo_ has quit [Ping timeout: 265 seconds]
satchmo_ has joined #zig
<pixelherodev>
andrewrk: what's old_inst in resolveInst?
<pixelherodev>
It's not documented :(
<pixelherodev>
... meh, hopefully I can figure it out from context
<andy_bainbridge>
Hi all. There's this code over here: https://github.com/andrewrk/zig-window. I have a vague memory that andrewrk made a video explaining it. But I can't find it.
<pixelherodev>
Ohhh, I think I see now
<pixelherodev>
andy_bainbridge: did you check the YouTube archives?
<andy_bainbridge>
Yeah. Searched X11, with no luck. Also searched by date for around 2 years ago which is when the code looks like it was written.
<pixelherodev>
resolveInst is taking the inst from one form and producing another; old_inst is literally just that, the inst being resolved
<pixelherodev>
andy_bainbridge: sorry, no idea
<pixelherodev>
Maybe wait for Andrew to be on and ask him?
dermetfan has quit [Ping timeout: 272 seconds]
<andy_bainbridge>
OK, ta.
satchmo_ has quit [Ping timeout: 272 seconds]
<pixelherodev>
... ohhh, GDB still has that "printing wrong value for enums" bug IIRC
<pixelherodev>
Ohhh, right, it's probably a *relative* offset that's incorrect
<pixelherodev>
It misidentifies where in the structure the enum is?
<pixelherodev>
... that shouldn't matter though
<pixelherodev>
It's using two different addresses for the same value, maybe?
<pixelherodev>
Oh okay, yeah, the address is wrong
<pixelherodev>
dammit
<pixelherodev>
It's actually tag_type *2* but GDB is printing it as *0*
<pixelherodev>
The question is whether that's a GDB bug, a Zig bug, or an LLVM bug
<pixelherodev>
None of the three are good for me, because I don't want to deal with fixing it *before* fixing stage2 :(
satchmo_ has quit [Ping timeout: 246 seconds]
satchmo_ has joined #zig
<pixelherodev>
Ugh
<pixelherodev>
I'm opening a freaking issue
<pixelherodev>
I've been running into this one for months now
<pixelherodev>
If it's a GDB issue, at least we can mark it down as upstream and known
satchmo_ has quit [Ping timeout: 256 seconds]
satchmo_ has joined #zig
keegans has quit [Ping timeout: 265 seconds]
satchmo_ has quit [Ping timeout: 265 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 260 seconds]
_Vi has quit [Ping timeout: 260 seconds]
andy_bainbridge has quit [Ping timeout: 258 seconds]
satchmo_ has joined #zig
dermetfan has joined #zig
satchmo_ has quit [Ping timeout: 264 seconds]
johnLate has quit [Ping timeout: 272 seconds]
satchmo_ has joined #zig
Kingsquee has joined #zig
satchmo_ has quit [Ping timeout: 240 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 265 seconds]
satchmo_ has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
dingenskirchen has quit [Client Quit]
dingenskirchen has joined #zig
<pixelherodev>
Ohhhh, lazy analysis!
<pixelherodev>
A lot of stage2 makes a lot more sense now that I know what to look for
ur5us has joined #zig
satchmo_ has quit [Ping timeout: 258 seconds]
<afontain_>
hi! I've got a question about module organisation. Let's say I've got a `map.zig` file (for cartography stuff), that I import using a `const map = @import(math.zig)` at the top of the file. I also only have one map, so the first thing that comes in mind is calling it map too.
<pixelherodev>
Yeah, resolveDecl evaluates looking for the non-existent func and passes it up the chain, where performAllTheWork does some cleaning and then continues trying to process
<afontain_>
how such issues are usually handled?
<pixelherodev>
afontain_: give it a different name? :)
<pixelherodev>
or `const map: Map = ...`
<pixelherodev>
Or, if there's only object
<pixelherodev>
`const map = @import("map.zig").`
<afontain_>
in other languages, they are either from different namespace (C) or have different case (Haskell)
<pixelherodev>
C doesn't have namespaces...
<afontain_>
yes, but `struct t` and `t` can coexist
<pixelherodev>
but if the only reference to it is with a single object, I'd say not to bother naming the import
<pixelherodev>
afontain_: true
<ikskuh>
pixelherodev: C does have namespaces ;)
<pixelherodev>
Oh no
<ikskuh>
afontain_: use a different name for your local namespace
<afontain_>
I don't know how to call that, namespace is the first thing that comes in mind
<pixelherodev>
What troll argument am I going to hear now :P
<ikskuh>
it's called namespace
<pixelherodev>
afontain_: no yeah, that naming maes sense
<pixelherodev>
makes*
<pixelherodev>
ikskuh: I was referring to userspace namespacing
<pixelherodev>
That is, the ability to sort values into arbitrary named spaces
<pixelherodev>
C has a tiny bit of namespacing, in that it has a few predefined spaces
<afontain_>
it's passed from one function to another
satchmo_ has joined #zig
<ikskuh>
afontain_: i'd call the import namespace "mapping"
<pixelherodev>
I'd say var but please don't do that
<ikskuh>
instead of map
<afontain_>
and it's not a comptime constant
<pixelherodev>
Doesn't need to be
<pixelherodev>
var means "arg of any type"
<pixelherodev>
It generates runtime code at compile time, and only the type needs to be comptime known
<pixelherodev>
But yeah, just give them different names really
<ikskuh>
> If more than one declaration of a particular identifier is visible at any point in a translation unit, the syntactic context disambiguates uses that refer to different entities. Thus, there are separate name
<ikskuh>
spaces for various categories of identifiers, as follows:
<pixelherodev>
MapType and map, Map and map, mapping and map, doesn't matter
<pixelherodev>
ikskuh: you mean scoping?
<ikskuh>
> 6.2.3 Name spaces of identifiers
<pixelherodev>
shadowing?
<ikskuh>
if you want to look that up in the C standard ;)
<pixelherodev>
Ugh, the standard
<afontain_>
well, I'll have just one module upper
<pixelherodev>
What is this, ##c?
<ikskuh>
labels are not in the struct, enum, union, global or field member namespace :D
<pixelherodev>
Yes but again
<ikskuh>
typedef enum c c; struct c { c c; }; enum c { };
<ikskuh>
:D
<pixelherodev>
That's what I said
<pixelherodev>
C has predefined namespaces
<afontain_>
*upper case
<afontain_>
seems weird, but maybe things coming from std can be lower case and my stuff can be camel case
<pixelherodev>
It doesn't let you defined arbitrary namespaces
<pixelherodev>
I was referring to the latter
<pixelherodev>
Okay, so now I fully understand the error handling
<pixelherodev>
Yay
<pixelherodev>
New problem
<ikskuh>
afontain_: usually you use PascalCase for types and error names, camelCase for functions and snake_case for everything else
<pixelherodev>
No idea why it's reading an array instead of a slice :P
satchmo_ has quit [Ping timeout: 240 seconds]
<ikskuh>
just use a different name for your imported namespace
<ikskuh>
var map: mapping.Map = …;
<afontain_>
yeah, I'll do that then
satchmo_ has joined #zig
lornokto has joined #zig
<alehander92>
ok
<alehander92>
are there any additional safety rules for pointers
<alehander92>
except nulability one-s
<ikskuh>
never return pointer-to-stackmemory
<ikskuh>
never use pointers free'd by an allocator
<alehander92>
hm: how is this enforced
<ikskuh>
by you
<alehander92>
ok
<alehander92>
so i remember there was at least some debug allocator tooling to make it easier to debug
<alexnask>
there is a leak checking allocator in std
satchmo_ has quit [Ping timeout: 272 seconds]
<alexnask>
Andrew was working on a debug allocator, not sure exactly what features it supports
<lornokto>
Did somebody try to use @call and anonymous touples to call C functions that couldn't be called before? I had some problem with that, but can't remember precisely
<alehander92>
i wondered how quickly does one reproduce stuff with it
<alexnask>
I havent tried C functions specifically lornokto but Ive used it with fn pointers before without issues
<alehander92>
one posibility is to property-test/mutability test stuff somehow with
<alehander92>
e.g. broken pointers/inserting free-s etc
<alehander92>
but i guess this is a bit hard to define
<ikskuh>
alehander92: "free" isn't defined in Zig itself
<ikskuh>
it's a userland concept
<ikskuh>
you have to check this in userland
<alehander92>
but you can still detect it
<ikskuh>
not all of it
<alehander92>
if you have a generalized concept of X Y operations which "cancel" themselves
<ikskuh>
only if you completl give up performance
<ikskuh>
still not detectable though ;)
<ikskuh>
at least for all non-trivial cases
<ikskuh>
where you don't tooling to find such errors
<alehander92>
eh of course
<alehander92>
i mean tooling which does it on compile time :)
<ikskuh>
as they are obvious by just looking at the code
<ikskuh>
yeah, still.
<ikskuh>
i can return a pointer
<ikskuh>
in a function
<ikskuh>
which comes from anywhere
<ikskuh>
and i call allocator.free(p) on that
satchmo_ has joined #zig
ifreund has joined #zig
<lornokto>
Just tracking of alloc/frees is possible with tools like valgrind, it'd be cool to have tracking of places in code where and what was allocated/freed though
satchmo_ has quit [Ping timeout: 256 seconds]
johnLate has joined #zig
satchmo_ has joined #zig
<ikskuh>
lornokto: that's possible
<ikskuh>
you can always request stacktraces
<ikskuh>
and store them with allocations
satchmo_ has quit [Ping timeout: 260 seconds]
satchmo_ has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
<lornokto>
zig is so good, it can handle vcpkg on any system, it can handle pkg-config inside of MSYS2 on windows, it can build webassembly modules with musl without additional setup... I think i need an idea of what to implement in zig
satchmo_ has quit [Ping timeout: 272 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 272 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 256 seconds]
satchmo_ has joined #zig
Xavi92 has joined #zig
<alehander92>
hm
<alehander92>
ikskuh thats generally an useful strategy with async as well
<alehander92>
i use it in nim lately (stacktraces connected to all kinds of events)
<alehander92>
yeah but comes from anywhere depends on your safety rules
<alehander92>
e.g. a hardcoded one can require some kind of assert/unsafe annotation
_Vi has joined #zig
<alehander92>
so one can have a hint on whats happening before running it
<KoljaKube>
Hi. I'm running into segfaults in zig's linking step - does anybody have any pointers how I could try to debug that?
greenfork has joined #zig
cole-h has quit [Quit: Goodbye]
<daurnimator>
linking zig itself? or when using zig as a linker? or when using the linker step in build.zig?
satchmo_ has quit [Ping timeout: 246 seconds]
KoljaKube has quit [Ping timeout: 260 seconds]
KoljaKube has joined #zig
<KoljaKube>
Linking program written in zig (using `zig build`)
satchmo_ has joined #zig
<daurnimator>
so first step would be to get a backtrace
<daurnimator>
run under gdb/lldb and type `bt`
satchmo_ has quit [Ping timeout: 246 seconds]
<KoljaKube>
OK, that basically prints the same stack trace that lld printed when crashing
<KoljaKube>
That is a very long line of nested C++ template stuff
<alehander92>
btw
<alehander92>
why was c++ used instead of c
<alehander92>
for writing zig initially
<KoljaKube>
I have linked against the same set of libraries and frameworks in a C++ program before, successfully. It only crashes when doing the same with zig
<alehander92>
i'd guess that c would be closer to zig and a bit easier to port to zig one day
<ikskuh>
alehander92: simple: because LLVM has a C++ API
<alehander92>
yeah thats what i wondered llvm
<KoljaKube>
The segfault is 12 frames deep in lld
<alehander92>
but the frontend isn't really .. hm
<ikskuh>
KoljaKube: are you on windows?
<KoljaKube>
macOS
<alehander92>
i mean it can just generate llvm ir in any language
<alehander92>
but maybe there are much more interactions than i think
<ikskuh>
yes, there is a lot
<ikskuh>
also genreating LLVM ir is more work than just using the LLVM API itself
satchmo_ has joined #zig
<ikskuh>
also, it's not really relevant in what stage0/stage1 are written
<ikskuh>
only thing that counts is that stage2 is awesome :)
satchmo_ has quit [Ping timeout: 260 seconds]
satchmo_ has joined #zig
<alehander92>
yeah but what i mean is
<alehander92>
yeah probably if stage2 is written from 0
<ikskuh>
it is
<ikskuh>
andrew is currently working on it and from what he already showed, it's gonna be freakin' awesome
satchmo_ has quit [Ping timeout: 258 seconds]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 256 seconds]
Kingsquee has quit [Quit: Konversation terminated!]
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 258 seconds]
<alehander92>
awesome !
<alehander92>
another question i had
<alehander92>
does anyone plan additional backends for zig, more precisely web-related
<alehander92>
e.g. wasm or javascript(i guess javascript doesnt make sense for a new lang, as we already have wasm)
<alehander92>
or does the llvm wasm support bring everything needed
<ikskuh>
wasm is a pretty nice backend already
<ikskuh>
it's fully usable, but it doesn't generate any fancypants bindings
<ikskuh>
i worked with it already and it's a joy :)
<ikskuh>
and yeah, zig stage2 plans to have *all* the backends
<alehander92>
so any others than native backends for many arch-s + wasm? :P
<alehander92>
(not that it's needed, just wanted to understand more precisely the scope)
<ikskuh>
well, what is "native" in your terms?
<ikskuh>
native in zig terms is the machine the compiler is running on
<alehander92>
yeah, basically that
<ikskuh>
well
<ikskuh>
zig targets a lot more platforms than native ;)
<alehander92>
hm, can you give an example, maybe i am missing something
<ikskuh>
i think stage2 will probably have a non-LLVM codegen for aarch64 and x86_64 planned for now
<ikskuh>
if i compile an aarch64 program on my x86_64 system, that's not the native target
dddddd has joined #zig
<alehander92>
ah yeah, but this is cross-compilation, right
slurpie has quit [Ping timeout: 260 seconds]
<ikskuh>
yes
<ikskuh>
but i think your question was:
<ikskuh>
"does zig also target pure virtual instruction sets like CLI/JVM/lua bytecode/wasm/…"
<ikskuh>
:D
<ikskuh>
and for that i can answer you: i want to try adding backends for CLI and JVM if possible without *too* much work
<ikskuh>
because that would be too awesome
<ikskuh>
also: zig has destroyed my c++ coding
<ikskuh>
i always forget to type "auto" before const :D
<alehander92>
yeah, i also wonder about that
<shakesoda>
yeah it destroyed my c++ coding also and i've been having an extremely difficult time finding it in myself to mind
<ifreund>
for me it's just further reduced the subset of C++ that I allow myself to use
<shakesoda>
that can pretty much only be a good thing
<ikskuh>
ifreund: yeah, pretty much
<ikskuh>
except for some nice syntax layers around that :)
kushalp has quit [Ping timeout: 260 seconds]
kushalp has joined #zig
andy_bainbridge has joined #zig
antaoiseach has joined #zig
antaoiseach has quit [Client Quit]
antaoiseach has joined #zig
satchmo_ has joined #zig
satchmo_ has quit [Ping timeout: 260 seconds]
dermetfan has quit [Ping timeout: 260 seconds]
gpanders has joined #zig
andy_bainbridge has quit [Ping timeout: 256 seconds]
hsh has joined #zig
antaoiseach has left #zig [#zig]
dermetfan has joined #zig
frmdstryr has joined #zig
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
satchmo_ has joined #zig
waleee-cl has joined #zig
xackus has quit [Ping timeout: 240 seconds]
xackus has joined #zig
layneson has joined #zig
layneson has quit [Ping timeout: 260 seconds]
Akuli has joined #zig
aerona has joined #zig
Snetry has quit [Ping timeout: 256 seconds]
Snetry has joined #zig
wozeparrot has joined #zig
metheflea has joined #zig
jhamren has joined #zig
<jhamren>
I know that there's no http client in the stdlib, but is there any 3rd party lib that's gained some traction? Nothing obvious from a quick google.
<lornokto>
curl works amazingly good
<jhamren>
I was hoping for something in zig, but I may go for a C lib, and perhaps curl.
<ikskuh>
h11
<ikskuh>
+ zig-network
<ikskuh>
and zig-bearssl when using https
<ikskuh>
but note that h11 is kinda unstable and breaks apart when the server does not respond as expected
<lornokto>
arent they bindings to C libs anyway?
<ikskuh>
except for bearssl: no
<ikskuh>
and bearssl has no external dependencies
<andrewrk>
pixelherodev, re: "old_inst" what line of code are you looking at?
<lornokto>
i think curl also hasn't dependencies but optionally needs something for SSL
wozeparrot has quit [Remote host closed the connection]
<jhamren>
ikskuh: thanks, I'll check 'em out.
wozeparrot has joined #zig
<ikskuh>
jhamren, github.com/MasterQ32/zpm implements an example on how to do HTTP(s)
<jhamren>
zig has been a joy to work in so far. even with no internet the entire weekend things was pretty easy to understand with too much ripgrepping the std lib to be healty.
<lornokto>
but actually i'm using the amazing power of linkSystemLibrary which does all magic of searching and linking dependencies and adding include directories...
<jhamren>
scientes: Yeah, but I saw something in the std lib code about a fs thread, so got curious
<scientes>
but that doesn't have anything to do with M:N
<scientes>
I'm just giving you the definition of M:N, which is what go uses
<jhamren>
Oh, I see. alright, I'm asking between the lines then
<ifreund>
true, but that kindof of control flow is what I was trying to avoid. Want to catch multiple trys all at once from within a function
<ikskuh>
ifreund: just make a function then
<ikskuh>
what is really funny
<ifreund>
i mean, that's what i would do
<ikskuh>
we can store failed states
<ikskuh>
const foo = std.fs.cwd().openFile(…);
<ikskuh>
…
<ikskuh>
const file = try foo;
<ifreund>
I'm doing this cause I disagree with #5421 and wanted to provide an alternative
<fengb>
IIFE? :P
<fengb>
Gotta port over more JS
<ikskuh>
ifreund: you're involed already
<ikskuh>
you can probably do stuff with errdefer pretty easily
<ifreund>
errdefer is tricky if you want to keep doing stuff after handling the error
<ifreund>
(which i think is dumb by the way)
<ifreund>
anyhow, i've probably put too much time into this
<ifreund>
i just think the control flow of the proposed change is really ugly and hard to follow
<fengb>
It’s exception like handling
<ifreund>
well, not in simple cases. But as soon as things get more complex it will be
<ikskuh>
errdefer |e| {
<ikskuh>
std.debug.warn("{} happened!\n", .{ e } );
<ikskuh>
}
<ikskuh>
there's this btw :)
<ifreund>
yes i know
<fengb>
errdefer doesn’t cancel the error
<ifreund>
oh, i didn't realize that
<fengb>
This specific usecase lumps a bunch of stuff together and handles the errors in one spot
<ifreund>
let me play with this
<fengb>
Very common for exception based languages
<fengb>
I haven’t encountered Zig code I’d want to do like this but it’s possible
wootehfoot has joined #zig
dermetfan has quit [Ping timeout: 260 seconds]
<ifreund>
oh errdefer does work like I thought it did
<ifreund>
i misinterpreted what you said
<ikskuh>
btw, ifreund: go's defer is actually runtime based
<ikskuh>
if i remember right
<ikskuh>
so you build a defer-list instead of doing block-based defers
<ifreund>
why
<ikskuh>
go also pre-evaluates defer statements
<ikskuh>
it's completly weird imho
<ifreund>
what
<ifreund>
does that make my translated version have different semantics than the go version?
<ifreund>
i think it's right
<ikskuh>
file = os.Opne()
<ikskuh>
defer file.Close()
<ikskuh>
file = os.Open()
<ikskuh>
defer file.Close()
<ikskuh>
will open and close *two* files
* ikskuh
is confused by that
[rg] has joined #zig
gpanders has quit [Ping timeout: 256 seconds]
gpanders has joined #zig
<andrewrk>
so we have std.time.nanoTimestamp() now
<andrewrk>
it returns an i128 number of nanoseconds
<ikskuh>
nice!
<ikskuh>
but why i128?
<ikskuh>
i72 would be sufficient *grin*
<andrewrk>
no big deal, it's just a value that is big enough to measure, down to nanoseconds, the beginning of the universe, all the way until Estimated time until the Earth collides with the black dwarf Sun due to the decay of its orbit via emission of gravitational radiation,[126] if the Earth is not ejected from its orbit by a stellar encounter or engulfed by the Sun during its red giant phase
<ikskuh>
so we can now timestamp *any point in calculatable timeÜ
<andy_bainbridge>
Was there a video that explained this? Maybe I live coding session or something?
<andrewrk>
no
<andy_bainbridge>
OK, my memory is playing tricks on me.
<andrewrk>
it's a project I hope to complete someday but don't work on very often
<fraktor>
Honestly I might just do SDL with some imgui library.
<andrewrk>
the main (still unsolved) problem is getting a static binary that can load vulkan drivers
<ikskuh>
fraktor,
<ikskuh>
i considered it, but it has usually bad interop with the OS
<andrewrk>
glfw is nice
<andy_bainbridge>
I've been playing with my own minimal 2D lib on Windows for years.
<fraktor>
GTK+ might be a good choice then. Never used the API myself though.
<andy_bainbridge>
I'm currently trying to port it to X11. And I'd like to learn more about Zig. Looks like a good place to do both.
<andrewrk>
zig-window is vaporware
<andy_bainbridge>
Haha.
<andrewrk>
the readme is pretty clear about how far along the project is
<andy_bainbridge>
Yeah, that's fine.
<andy_bainbridge>
I just can't find any code that does anything. eg minimal.zig calls XCreateSimpleWindow, but I can't find that function's body.
<fraktor>
Also maybe this is me being spoiled by classes, but it's quite frustrating to have to do something like SDL_Whatever(context, ...). Would it be possible to do code generation that would create a struct with methods on it, wherever that datatype is the first argument?
<fraktor>
Not that that should be integrated into the compiler, but could that be a userland/library thing?
<andrewrk>
fraktor, does that actually solve a problem?
<shakesoda>
fraktor: that is you being spoiled by classes, i am quite sure
<andrewrk>
one thing I've learned over the years is to be careful to fall into the trap of doing meta work that feels like I'm accomplishing something but actually does not do anything measurably better
<fraktor>
Eh, maybe I'm just spoiled.
<andrewrk>
that said, it may be possible in the future to declare "namespaces" when doing @cImport
<shakesoda>
reminds me i need to try zls
<alexnask>
You should :-D
<fraktor>
As in stripping prefixes like `SDL_` or whatever?
<demizer>
I can't wait for zls. It would help a lot with learning. Just not ready to shave that yak yet.
<andrewrk>
fraktor, yeah and putting them into structs, so it would be e.g. `SDL.whatever`
<andrewrk>
I'm pretty sure this is an open issue somewhere
<alexnask>
Aggregate @Type would allow us to make this in userland :d (hides)
<andrewrk>
unsure whether the yak you are referring to is installing this, or implementing a competitor
<demizer>
oh nice. I have to integrate it with nvim-lsp, haven't had time. Maybe i'll try that today.
<fraktor>
I really like using ALE, so integrating that would be super nice
<demizer>
While I'm at it, i'm writing my first zig program while learning Zig, a markdown parser and viewer, and have been stuck on the following problem for a few days. I am trying to turn my parser struct into a json string so I can test against it. I am having some d
<demizer>
<demizer>
/home/demizer/zig-linux-x86_64-0.6.0+48dc3b6fe/lib/zig/std/json.zig:2571:17: error: Unable to stringify type 'fn(*std.mem.Allocator, []u8, u29, usize, u29) []u8'
<demizer>
else => @compileError("Unable to stringify type '" ++ @typeName(T) ++ "'"),
<alexnask>
demizer, That check will happen at comptime if you do `if(comptime !mem.eql(u8, Field.name, "Children")) { ... }`
<demizer>
oh interesting, I will try that
<alexnask>
Functions are not evaluated at comptime by default unless they return comptime only types or are used in a comptime only context (comtpime blocks, type expressions)
<demizer>
I am still learning about comptime, I've never used a language with that feature
<alexnask>
'fn(*std.mem.Allocator, []u8, u29, usize, u29) []u8' looks like Allocator.shrunkFn's type
<alexnask>
shrinkFn*
<alexnask>
Well, it doesnt look like it, it is its type :p
<demizer>
I assumed that was the ArrayList's type
<demizer>
not sure how to monkey patch json.stringfy for that :
<demizer>
alexnask, that worked! thank you
greenfork has joined #zig
<xackus>
laptop fixed! now i can get back to zig
<alexnask>
demizer, \o/
slurpie has joined #zig
<pixelherodev>
andrewrk: I was looking at the resolveInstCall call chain
<pixelherodev>
but I figured it out :)
<alexnask>
pixelherodev, Package support landed in zls about 1 hour ago btw ;)
gpanders has quit [Ping timeout: 264 seconds]
<pixelherodev>
Awesome
<pixelherodev>
alexnask: what path does the build runner need?
<andrewrk>
the self hosted tokenizer is fast: throughput (mean): 308 MiB/s
<alexnask>
Default is next to the executable (the install step will place it there too) but you can use build_runner_path in your config pixelherodev
<pixelherodev>
how's stage1 compare?
<andrewrk>
it's faster than sha256
<pixelherodev>
alexnask: thanks
<pixelherodev>
Oh right, need to update Zig first
<pixelherodev>
I should really reenable that cronjob...
gpanders has joined #zig
<pixelherodev>
Doesn't seem to be working :(
<pixelherodev>
Ohhhh
<pixelherodev>
alexnask: is there a way to override the ZIG path?
<alexnask>
Not yet >.> Do you have access to the stderr output by any chance?
<alexnask>
I will add a zig path configuration option though, makes sense
<pixelherodev>
No
<pixelherodev>
I don't have stderr :(
<pixelherodev>
it's one reason I don't contribute; it's a pain to debug
<pixelherodev>
I have 1.1GB of logs :P
<pixelherodev>
But the only part from ZLS is messages it sent to the client
<alexnask>
I dont think there is a multi editor/platform way for debug output
Aransentin has joined #zig
<pixelherodev>
Similarly, I have a local patch that adds empty textDocument/{hover,references} to fix the constant annoyance I get without them
<pixelherodev>
So my update process is `gsta ; gl; gstp; zig build...`
stripedpajamas has joined #zig
doublex has quit [Remote host closed the connection]
doublex has joined #zig
hsh has quit [Quit: Connection closed for inactivity]
<pixelherodev>
Hmm, so the ZIR parser doesn't even bother reading decl names until they're resolved?
<andrewrk>
keep in mind the parts that will get modified when real ast->zir is implemented
<pixelherodev>
gah, we don't have that yet?
<pixelherodev>
Gotcha
<pixelherodev>
I've been trying to figure out why `call(@realfunc)` works fine, but `call(@doesnotexit)` requires coercion from [N:0] to []
<andrewrk>
I have a few more things I want to tackle in just zir, and then that's next up
<pixelherodev>
Gotcha
<pixelherodev>
I'm just trying to fix up this test, then implementing the graph generator thingy, then getting back to codegen proper
<andrewrk>
I think you might have more smooth sailing if you focus on aspects that aren't related to decls
<pixelherodev>
Maybe, but I'm also learning a lot about the internals from this
<andrewrk>
since that's what is subject to change with adding ast->zir
bjorob has joined #zig
<pixelherodev>
Meh, learning experience is worth it
<pixelherodev>
I'm getting better at quickly stepping through the code and figuring out what's happening and why
<pixelherodev>
Plus, this'll make it easier for me to update the tests later
<fraktor>
I've been able to build zig locally using zig-bootstrap, but have had trouble with the zig repository proper. What do I need to do to bring zig-bootstrap up to date?
<andrewrk>
llvm 10 has been an unmitigated disaster as far as contributors being able to build zig from source
<pixelherodev>
Yeah
<pixelherodev>
It's such a pain
<pixelherodev>
It's a conspiracy to protect Clang from the upstart compilers!!!!
<pixelherodev>
/s
<andrewrk>
my official stance is: if it doesn't work first try with your package manager, build llvm, clang, lld from source, following the instructions on the wiki
<fraktor>
I tried messing with CMakeLists but I'm still having trouble.
<andrewrk>
it will take you an entire day, just do it
<fraktor>
Alright
<andrewrk>
as far as I can tell, zig is the first project that links against all 3 llvm, lld, clang. the packages that have been set up for these are simply incompatible with each other
<andrewrk>
however that's a packaging mishap, it's not a fundamental incompatibility
<andrewrk>
people trying to save disk space but not understanding how to do it correctly
<fraktor>
That's very frustrating. I guess it makes sense that most languages wouldn't link against clang though.
<andrewrk>
yeah
<andrewrk>
or they shell out to lld and say "it has to be installed" rather than linking against it as a library, so that the compiler binary is not doing essentially runtime-linking of the linker
<ifreund>
i'm very glad the maintainers of my distro got it right :)
<pixelherodev>
Mine didn't :(
<pixelherodev>
First issue I've ever had with Gentoo
<pixelherodev>
Fortunately, it's easy to circumvent
<pixelherodev>
I can just use an overlay, but that means taking five minutes to set one up
<andrewrk>
I haven't checked if llvm 10.0.1rc1 solves the problem. it might
<pixelherodev>
And currently, it's easier to just keep using the remote Zig, which is *significantly* faster even with the overhead of networking, so I have no motivation to do it
<pixelherodev>
On that note, an awesome idea for stage2 which I highly doubt is worth considering is the ability to parallelize over distributed computers :P
<pixelherodev>
Split the workload among not just cores in the current machine, but cores in all interconnected machines
<fraktor>
Can you just compile object files with Zig? I never have done that
<fraktor>
If so one could write a wrapper around zig to do that
<pixelherodev>
You can, but that's not quite what I'm referring to
<fraktor>
I mean that you could have multiple machines compile multiple object files and then link them together at the end
<pixelherodev>
I know
<pixelherodev>
But that's really not how Zig is meant to compile
<pixelherodev>
I'm thinking of a way to integrate even the incremental compiler
<alexnask>
fraktor, build-obj ;)
[rg] has joined #zig
<andrewrk>
that's an interesting use case, but I think it's one where there is a lot to be gained by saying, "out of scope"
<pixelherodev>
I agree completely
<pixelherodev>
If it was secure though, the possibilities...
<fraktor>
Maybe I should get more ram. It would at least let me build LLVM with more than one core
<pixelherodev>
How much do you have?
<fraktor>
16G
<pixelherodev>
...
<pixelherodev>
you're joking, right?
<ifreund>
you should be able to use more than 1 core
<pixelherodev>
I've compiled LLVM with four cores with 8GiB of RAM...
<andrewrk>
fraktor, you can try using the ninja generator
<ifreund>
if not something's wrong
<pixelherodev>
^
<pixelherodev>
Something's *definitely* wrong in that picture...
<fraktor>
How do I do that with cmake
<pixelherodev>
Wait
<fraktor>
?
<pixelherodev>
Are you using e.g. LTO?
<andrewrk>
`-G Ninja` on the cmake line and then `ninja` instead of make
<fraktor>
To be perfectly clear, I can't use all 8 which makes me sad.
<andrewrk>
in my experience it properly will compile with multiple cores and then link with fewer
<pixelherodev>
I don't think the overhead of Make is quite that high though
<fraktor>
But I don't know how many I can safely use
<andrewrk>
the problem I've found with make on llvm is that llvm wants to link a bunch of things at once that each take like 4 GiB
* pixelherodev
facepalms
<pixelherodev>
That's ridiculous
<andrewrk>
so if you use make -j$(nproc) you'll crash at link time
<pixelherodev>
It should *never* use that much RAM in the first place
<andrewrk>
but ninja figures out to only link 1 thing at once or something like that
<pixelherodev>
That reeks of poor design to me...
<pixelherodev>
Okay, so I see where it's reading the array from, which makes sense to me; the question now is why the existing name is read as a slice instead
* pixelherodev
shrugs
<pixelherodev>
I'll just implement the coercion and worry about that later
satchmo_ has quit [Ping timeout: 265 seconds]
[rg] has quit [Ping timeout: 256 seconds]
<Aransentin>
Query: Let's say I make a library in Zig, for use by other Zig programs - i.e. you build with the source verbatim just like the stdlib, and not by using a dynlib or the like.
<pixelherodev>
The only real remaining problem I have with ZLS is it's noticably slow sometimes, and I think there are a few infinite memory eaters left :(
<Aransentin>
This library will be split between many files. Some of the functions in these will be used internally by the library in other files and as such need to be `pub`, but shouldn't be touched by the users of the lib. What's the prefered way of solving this? Appending an underscore to the "internal" functions?
<pixelherodev>
Leaving them public
* pixelherodev
shrugs
<pixelherodev>
The worst that can happen is a user decides they know better than you and they want to use the function
<pixelherodev>
That's really not your problem
<Aransentin>
So, by documentation then. I suppose that works.
tez has left #zig ["Leaving"]
<pixelherodev>
Yeah, that's probably the best option
<pixelherodev>
I mean, you *could* go the technical route
[rg] has joined #zig
<pixelherodev>
Add a parameter that must be comptime known and then using reflection blah blah trying to find a heuristic determining who's calling
<pixelherodev>
But it'd be a pain, it might not be possible, it might not work, and there's no point
<pixelherodev>
Hmm, now to test the coercion...
<fraktor>
Aransentin: I will say that sometimes I end up with bigger files in Zig than in some other programming languages (especially Java or C#), so you may still be able to minimize the number of pub functions that are used.
<fraktor>
But if there are functions that are so useful on their own that they need to be accessible in multiple places, the user might want to use those.
<Aransentin>
For sure. I just wanted to see if there's some general solution.
<Aransentin>
It's just that some of these functions look really useful on the surface, but are traps when used in practice...
<andrewrk>
Aransentin, `pub` should be enough. generated docs will only show public stuff, ZLS knows which ones are public
<pixelherodev>
There we go!
<pixelherodev>
Coercion works, now I'm getting "expected error ('no such function etc'), but didn't receive it"
greenfork has quit [Ping timeout: 260 seconds]
[rg] has quit [Ping timeout: 264 seconds]
<pixelherodev>
Gah, can I just send a patch changing the line endings of the deps README and LICENSE files?
<THFKA4>
how do i create a zero-filled struct imported from a C header? std.mem.zeroes doesn't work with extern structs
<THFKA4>
i really don't want to fill out the rest of this giant thing just to pass it to an init(&struct) function
<ikskuh>
THFKA4: memset
<THFKA4>
thank you
<ikskuh>
or if you want to init it (and init will override it anyways) use undefined
<ikskuh>
but: undefied is *really* undefined, not some fixed value
<THFKA4>
yeah i'm fine not zeroing it, since init() should be taking care of this
<fraktor>
undefined is what you want.
<fraktor>
afaik that just doesn't set the memory at all in release mods
<fraktor>
s/mods/modes/
<ikskuh>
there are structs that may require zero-init though
<fraktor>
?
<ikskuh>
fraktor: usually all winapi-structs require zero-init + size-init
andy_bainbridge has quit [Ping timeout: 256 seconds]
linuxgemini has quit [Ping timeout: 256 seconds]
lunamn has quit [Ping timeout: 260 seconds]
linuxgemini has joined #zig
lunamn has joined #zig
traviss has quit [Quit: Leaving]
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen1 has joined #zig
doublex has joined #zig
satchmo_ has joined #zig
dingenskirchen1 is now known as dingenskirchen
slowtyper has quit [Ping timeout: 264 seconds]
<wilsonk>
fraktor: did you figure out your zig0 build problem? It appears as though you built llvm with the z3 verifier enabled (I think I had that problem once before with llvm-9 and just built z3 to get rid of the error, but I removed z3 and built llvm-10 without z3 and everything works fine now).