<HollMax>
inline for over declarations in SDL might be too much
<fengb>
@compileLog for printing but it’ll stop compilation
<HollMax>
yeah, that won't cut it.
<fengb>
I think general IO is out of scope for comptime
<ikskuh>
i kinda wonder when the first will try to implement ctre in Zig
<ikskuh>
(compile time regular expressions)
<HollMax>
are there any issues I'm missing? I'd assume this to be trivial in Zig (in comparison to most other languages)
<ikskuh>
it will probably just take way too long to compile
<oats>
I haven't looked closely at zig compiler internals at all. How does comptime stuff work? Is there a subset of the language that can be interpreted or something?
<daurnimator>
ikskuh: I've been wanting to do a PEG in zig that works at compile time
<ikskuh>
a PEG? crazy :D
<daurnimator>
ikskuh: though I've also said in here before: re2 probably makes sense
<ikskuh>
oats: there's zig IR which can be executed i think. it's not a subset, it's the full language feature set except for syscalls
<daurnimator>
fengb: I saw that post and started wondering how we should do i18n in zig: should we be supporting fluent?
<ikskuh>
if i find an invalid identifier, i can now just scan for the next ; or } and be happy, because i know that i can continue parsing the file and emit more errors in one go
<ikskuh>
and now: good night
<fengb>
Good night!
<HollMax>
since `zig c++` is a thing, how about including and calling C++ from zig?
<fengb>
I might take some inspiration from this code
<HollMax>
@ikskuh good nigh
<ikskuh>
HollMax: i've explained it on the Discord just a moment ago
<ikskuh>
sticking to C ABI is the sane option
<ikskuh>
Calling "actual" c++ from zig would mean that zig needs the whole feature set of c++ with templates and everything
<fengb>
Zig doesn’t know how to call C++ but both understand C. So create a wrapper function with extern “C”
<ikskuh>
sticking to C abi means that you can call C++ code (I'm doing that a lot by now) but you are bound to the C type system
<ikskuh>
also you're more flexibel with a C interface anyways, as you can also trivially attach C#, Nim, Python
<ikskuh>
and many other languages that support C bindings (luajit has a nice FFI afaik)
<HollMax>
I suppose I could do anything I could reasonably want once 383 gets in
HollMax has quit [Remote host closed the connection]
ur5us has joined #zig
<andrewrk>
there's a good chance 383 will not be accepted
ur5us has quit [Quit: Leaving]
<Xavi92>
I'd like to experiment with zig by using it on a PS1 (used mipsel-unknown-elf-gcc in the past). I have a couple of questions though
<andrewrk>
PS1 is mipsel?? TIL
<daurnimator>
andrewrk: another reason for 383 came up the other day: creating an enum from a list of struct fields
<Xavi92>
It is a freestanding environment, so does .bss need to be cleared before main in zig?
<daurnimator>
Xavi92: quite possibly
<companion_cube>
ok, controversial idea: why not use npm's package.json for describing zig's modules? gives a lot of tooling for free
<companion_cube>
(including github's tracking of dependencies)
<Xavi92>
But it looks like this has been patched recently
<pmwhite>
Is there a way to wrap with zig fmt when there are a lot of expressions joined by boolean and.
<andrewrk>
you can line break after binary operators
<Xavi92>
andrewrk, daurnimator: thanks for the examples, good to know it's done the same way as in C
<andrewrk>
daurnimator, hmm yeah I mean zig's codegen assumes bss is initialized, so it might be important to formalize why this is defined behavior or not in the lang spec
<andrewrk>
e.g. maybe we can define @memset to not depend on .bss for the freestanding target or something like that
<daurnimator>
andrewrk: but if it can be faster by using bss.... I wouldn't want to stop it
<daurnimator>
andrewrk: it just means you have to use inline assembly in your _start
<andrewrk>
yeah
<daurnimator>
though one thing I wasn't sure about was if I need to use `asm volatile` or not
<daurnimator>
e.g. would zig/llvm optimise it to something that uses BSS again?
<Xavi92>
BTW, can't 'extern' be used inside a function? I see __bss_start and __bss_end being declared at file scope, but I'd like to move these definitions if only accessed from one function
<Xavi92>
So these definitions are only visible inside that function
<andrewrk>
`volatile` for asm means it has side effects, which clearing bss certainly does
<andrewrk>
without that zig can delete the asm volatile if you don't use the result
<daurnimator>
andrewrk: I thought `volatile` indicated that the compiler is not allowed to optimize the contents?
<andrewrk>
Xavi92, you can do that by declaring a struct inside a function and using that namespace
<Xavi92>
daurnimator: for inline assembly it could mean the compiler can remove code or reorganize it, IIRC
<daurnimator>
I'm happy for the optimiser to move it around...
<daurnimator>
The side effects I should capture by adding a memory clobber I guess?
<andrewrk>
you don't want the optimizer to move around your bss clear
<daurnimator>
andrewrk: I don't mind if it e.g. does the rodata copy first
<Xavi92>
andrewrk: I didn't get the point completely (sorry, discovered zig a couple of hours ago). Do you mean creating a struct (e.g.: Bss) with two u8 values and then a Bss instance with its values assigned to __bss_start and __bss_end?
knebulae has quit [Read error: Connection reset by peer]
xackus has quit [Ping timeout: 265 seconds]
<andrewrk>
Xavi92, in zig, all files are structs, and declarations inside structs are namespaced globals. exported or external declarations are not namespaced, however
<andrewrk>
const S = struct { extern var __bss_start: u8; extern var __bss_end: u8; };
<andrewrk>
you can now reference them with e.g. `&S.__bss_start`
nephele has quit [Ping timeout: 260 seconds]
nephele_ has joined #zig
<Xavi92>
andrewrk: whoa. It'll take me some time to process that
darithorn has joined #zig
<andrewrk>
you can see some similar example code in the implementation of std.Thread.spawn
<Xavi92>
daurnimator: oh, hadn't realize it was using 0.4.0. Thanks for the tip! That made it work
<daurnimator>
Xavi92: also consider @ptrCast instead of @as there
<andrewrk>
why's that?
<daurnimator>
`*volatile [1]u8` isn't exactly correct now is it.
<andrewrk>
@as([*]volatile u8, &S.__bss_start) should work
<daurnimator>
`@ptrCast([*]u8, &S.__bss_start)` would be more correct IMO
<andrewrk>
the volatile is needed, the store has a side effect
<daurnimator>
andrewrk: i don't think you can use @as to get from a *u8 to a [*]u8?
<andrewrk>
also it only guarantees not reordering according to other volatile operations, so you need a @fence(.Acquire) after it
<andrewrk>
ah yeah in that case @ptrCast is fine. but be careful telling people to use @ptrCast over @as, because it's the other way around. The thing to change here was the dest type (and needing to use @ptrCast is a consequence, not the goal)
<Xavi92>
I read the differences between @as and @ptrCast, but I'm still not sure why I should choose one over the other. Is @as safer?
<andrewrk>
yes
<andrewrk>
the flow chart is: always use @as (or other forms of automatic type coercion which are equivalent)
<andrewrk>
if you can't, because of a compile error, then consider other options
<andrewrk>
"Type coercions are only allowed when it is completely unambiguous how to get from one type to another, and the transformation is guaranteed to be safe."
xackus has quit [Read error: Connection reset by peer]
xackus has joined #zig
<Xavi92>
andrewrk: why is the [1] needed on @as(*volatile [1]u8, &S.__bss_start), though? Isn't &S.__bss_Start returning a pointer to 1 element, for which '*volatile u8' would suffice?
<andrewrk>
it's harmless now but @memset should probably be improved to emit a compile error for this, since you're asking to copy > 1 byte, but giving it a pointer that supposedly points at 1 byte
<Xavi92>
andrewrk: so how could you cast from __bss_start to [*]T? From what I can read, &x returns a single-item pointer
<andrewrk>
this is one of those occasions where you have more information than the compiler
<andrewrk>
it's not really a one item pointer, is it? it's really a byte that is conveniently aliased to the start of bss
<Xavi92>
Exactly
<andrewrk>
right, so when you have more information than the compiler, is when @ptrCast or other less-safe-than-@as casts are relevant
<Xavi92>
Byte or even word. The underlying type does not really mater, as it is never accessed directly
<Xavi92>
Alright
<daurnimator>
Xavi92: I mentioned that above: > `@ptrCast([*]u8, &S.__bss_start)` would be more correct IMO
<Xavi92>
daurnimator: what about @ptrCast([*] volatile u8, &S.__bss_start) ?
<daurnimator>
Xavi92: that would work too. Though I'm not sure why andrewrk is saying it needs the volatile....
<Xavi92>
Sounds more correct to me - as andrewrk said, it has side effects the compiler should be aware of
<daurnimator>
andrewrk: it's not MMIO: why would it need volatile?
<Xavi92>
daurnimator: I think it's because you're modifying a whole range of items and the compiler could not be aware of that
knebulae has joined #zig
<Xavi92>
Or probably it ensures @memset is not assuming any value from __bss_start to __bss_end, don't know
<daurnimator>
Xavi92: `volatile` means that reads/writes to the memory have actual side effects e.g. due to MMIO; or because you're debugging with an oscilloscope and want to see an exact values written to exact locations
<Xavi92>
Yup, those are the cases I'm also aware of when writing software in C for embedded devices
<Xavi92>
Probably 'volatile' isn't needed in @memset
<daurnimator>
Xavi92: note that that error message means that whatever you did expects an `fd_t` to exist: what operation are you attempting?
<Xavi92>
Just experimenting so far. The micro kernel (aka BIOS or the epic boot screen) on the PS1 provides a working implementation of printf, so I was thinking of ways to use it from zig
<andrewrk>
the null hypothesis is to just call that stuff explicitly and not try to integrate with zig's std lib OS layer
<Xavi92>
The error obviously popped up when I attempted to use stdout.print(), just to see how the compiler would complain at the lack of such definition
<andrewrk>
you can use the rest of zig's std lib without the OS layer. whatever you don't call doesn't get compiled in. so the data structures for example are all fair game
<Xavi92>
Sure, but getting stdout.print() features would be a great addition
<Xavi92>
Not that I'm going to implement that now, I'm just feeling curious
<andrewrk>
the vision for this is that you would be able to make a "ps1" OS package and people would be able to depend on the package, and then put `pub const os = @import("ps1");` next to main() and it would make printing work and do the bss before main and stuff
<Xavi92>
Sounds great
<daurnimator>
Xavi92: you should will be able to create an `OutStream` that uses the BIOS' printf
<Xavi92>
Alright
<daurnimator>
Xavi92: you will function that writes bytes using your bios primitive; then do something like: `io.OutStream(File, PossibleWriteErrors, mywritefunction){}`
<daurnimator>
uh, s/File/void/
v64 has joined #zig
<Xavi92>
BTW, is it possible to define custom types for integer data types, like in C's typedef?
<Xavi92>
Not that I like typedef, but sometimes uart_data_bits (contrived example) is more meaningful than u8
<Xavi92>
Probably the correct term would be 'alias'
<fengb>
You can make an alias with const foo = u8;
<Xavi92>
fengb: great, thanks!
<fengb>
Won’t be distinct though, unlike Go
<shakesoda>
to get distinct you need a one field struct, right?
<Xavi92>
I still don't really get the 'const' for type definitions. Are they supposed to allocate any memory?
<shakesoda>
you can use types more or less the same way you use anything else.
<shakesoda>
until 1717 is done, the only thing this isn't true of is functions really
<Xavi92>
I mean, why not simply 'foo = u8' or 'alias foo = u8'? Similarly for 'const Point = struct {x: u8, y: u8};'
<shakesoda>
that's just adding inconsistencies
<shakesoda>
everything being the same is a feature
<fengb>
const and var (and fn for now) are the only ways to declare an identifier
<Xavi92>
Coming from a C background 'const' reads as read-only variable, not type definition. Of course, zig does not have to follow that convention
<fengb>
const in zig just means it’s constant. It doesn’t actually mean stack. Some consts get shoved into the data section
<Xavi92>
I see
<fengb>
Others are comptime, which only exists to the compiler
<Xavi92>
You could never define a struct as var, though, if only the type is being defined
<fengb>
Types are comptime, as are literal numbers (unless they’re coerced into a runtime value)
<Xavi92>
For example, 'var Point = struct {x: u8, y: u8};'
<fengb>
Yeah I don’t think that’s allowed
<Xavi92>
Alright thanks!
<shakesoda>
clearly we need types that you can screw with at any arbitrary time, so you can write zig as if it had lua tables ;)
<shakesoda>
disclaimer: i have utterly no idea how you'd make that sane, but i really do love lua tables
<daurnimator>
Xavi92: you can at comptime
<Xavi92>
daurnimator: something like 'var Point = struct {x: u8, y: u8};' you mean?
<daurnimator>
Xavi92: `comptime var Point = struct {x: u8, y: u8};`
<daurnimator>
and from there you could e.g. use an `inline for` loop to wrap it to some arbitrary comptime depth
<Xavi92>
That's great
<Xavi92>
Anyway, bed time guys
<Xavi92>
Thanks a lot for your help! zig definitely is a very interesting project
<daurnimator>
(the actual one just `return`s directly; but if it was nicer to write it with a `var` `type` then we would be able to do so
<daurnimator>
)
<Xavi92>
zig's type introspection capabilities look really interesting
<daurnimator>
Xavi92: types are just another... type of variable
<Xavi92>
I see
<Xavi92>
How does the compiler solve this? Using UUIDs for each type?
<daurnimator>
Xavi92: what do you mean?
waleee-cl has quit [Quit: Connection closed for inactivity]
<daurnimator>
Xavi92: some types (e.g. `type`, `comptime_int`, `comptime_float`) only exist at comptime
<Xavi92>
Oh sorry, missed the comptime requirement
<Xavi92>
Thanks for the clarification
xackus has quit [Read error: Connection reset by peer]
xackus has joined #zig
<Xavi92>
See ya!
Xavi92 has quit [Remote host closed the connection]
<daurnimator>
andrewrk: : CommandLine Error: Option 'mc-relax-all' registered more than once! LLVM ERROR: inconsistency in registered CommandLine options
<daurnimator>
^ trying to compile master locally..... (let me try and re-run cmake)
darithorn has quit [Quit: Leaving]
<andrewrk>
this generally means a static library got compiled in twice
<andrewrk>
e.g. 2 different dynamic libraries
<andrewrk>
what os?
<daurnimator>
linux x86_64
<daurnimator>
trying to run cmake again it keeps finding my system llvm instead of the one I'm passing to CMAKE_PREFIX_PATH
<andrewrk>
the only thing that changed in aaf99371b is it looks for -lclang-cpp before other stuff
<andrewrk>
ugh, llvm's configuration is out of control, it does not have to be this complicated
<daurnimator>
cmake is a bad build system
joey152 has quit [Ping timeout: 256 seconds]
<andrewrk>
you can pass -DZIG_STATIC_LLVM=ON to skip trying -lclang-cpp
<daurnimator>
`-DCMAKE_PREFIX_PATH=../../llvm-project/prefix` is what I'm meant to be passing right?
<daurnimator>
where ../../llvm-project/prefix contains: bin include lib libexec share
<andrewrk>
yes
<andrewrk>
but I guess cmake is looking first there for -lclang-cpp and then to system default locations and finding it
<andrewrk>
basically the "if we did not find -lclang-cpp" logic is a false negative
<andrewrk>
this is actually not possible to fix. llvm has made it impossible to fix this
<daurnimator>
luckily that wasn't it.
<daurnimator>
problem was you have to add it to your path too: `PATH=~/src/llvm-project/prefix/bin:$PATH cmake -DCMAKE_PREFIX_PATH=~/src/llvm-project/prefix ..` worked
<andrewrk>
that doesn't make any sense
<daurnimator>
otherwise it runs system llvm-config
<andrewrk>
I believe you but it's annoying that it works that way
<daurnimator>
okay. still fails with `: CommandLine Error: Option 'mc-relax-all' registered more than once! LLVM ERROR: inconsistency in registered CommandLine options`
<andrewrk>
I have half a mind to require the bootstrap repository for building zig from source just so we can side-step all the many incompatible ways llvm is packaged and configured
<daurnimator>
that will not fly for distro packaging
<andrewrk>
did you try -DZIG_STATIC_LLVM=ON yet
<daurnimator>
right now I'm reverting to previous HEAD and checking it was this commit that broke it
<daurnimator>
yep it was
<daurnimator>
-DZIG_STATIC_LLVM=ON has same error
<andrewrk>
it would help for me to see the linker line for all 3 of those cases
<andrewrk>
should be able to do just `make VERBOSE=1`
<andrewrk>
-lclang-cpp includes *some* llvm static libs that we need, but not all of them
<andrewrk>
if we don't include llvm static libs, we get the LLVM ERROR: inconsistency in registered CommandLine options
<andrewrk>
if we don't include them, we get undefined symbol linker errors
<andrewrk>
ok, reverting the commit. this is making me crazy
<daurnimator>
back to #4992 ?
<andrewrk>
4992 can't work either, everything is fucked
<andrewrk>
I'm just going to put in a cmake option that homebrew users will have to use
<andrewrk>
btw c++ static initializers are also to blame for this
<wilsonk>
wow, has anyone else built llvm/clang-10.0.0 with LTO+PGO optimizations? It took me hours on a 64 core machine so it isn't for the faint of heart, but it improved build times of llvm/clang-10.0.0 from 9:34 to 7:14 mins...buuuuuttt then building zig0 ends up in an infinite loop!?!??! WTH!! UGH
<wilsonk>
so I can't even use it for zig now after all that build time...darnit!
<andrewrk>
daurnimator, reverted
<daurnimator>
andrewrk: thanks. can build now
<daurnimator>
andrewrk: 7 issues left in the milestone; how you feeling?
<mikdusan>
andrewrk: is it ok for me to create a "qemu-static" repo w/ docker, patches, script, sources?
<daurnimator>
mikdusan: hmm? what does it do exactly?
<mikdusan>
it's an alpine docker to build qemu-static for linux. I already do it from alpine vm, but decided to try this dang fangled docker thing :)
<daurnimator>
mikdusan: who would use it?
<mikdusan>
every linux build uses qemu for various target tests
<mikdusan>
every *CI* build
<daurnimator>
mikdusan: e.g. on arch I use install qemu-arch-extra and it has everything in it
<daurnimator>
mikdusan: https://download.qemu.org/ has a couple of 5.0 rcs; but 4.2 is the latest release...
<andrewrk>
mikdusan, you can probably use ziglang/docker-zig as a template
<mikdusan>
andrewrk: it's pretty much done. just prepping for upload
<andrewrk>
nice
<daurnimator>
mikdusan: as soon as 5.0 actually gets a release arch would package it
<andrewrk>
daurnimator, the point is so the CI gets a newer qemu, so we can run the SIMD tests with it
<andrewrk>
because older qemu was crashing
<mikdusan>
and CI doesn't run archlinux?
<andrewrk>
it's ubuntu yeah
<daurnimator>
I guess I just don't see the point over e.g. a dockerfile that just does `FROM archlinux` `RUN pacman -Syu qemu-arch-extra`
<andrewrk>
I don't understand what that would accomplish
<andrewrk>
we already have it working now without docker
<andrewrk>
and in fact it works in any linux distro, so we're not tied to ubuntu or arch
<daurnimator>
but what mikdusan is proposing is to use an alpine base...
<mikdusan>
alpine (static musl) is what makes it work everywhere
<daurnimator>
mikdusan: can you compile it with `zig cc`? :)
<andrewrk>
daurnimator, do you understand that we're downloading a binary tarball with every ci run?
<andrewrk>
whew. finished going through commit logs. now I just have to flesh out all 91 sections of the page
<andrewrk>
if I put in 36 hours before monday that leaves me with ~23 minutes to spend per section
<daurnimator>
andrewrk: most CI systems (I suspect all that we use) support a "cache" directive where you can tell it to cache binary artifacts between runs. it's useful for large dependencies etc.
<Xavi92>
LLVM ERROR: Code generation for MIPS-I is not implemented
marijnfs_ has joined #zig
daex has quit [Ping timeout: 256 seconds]
marijnfs has quit [Ping timeout: 240 seconds]
daex has joined #zig
marijnfs_ has quit [Quit: leaving]
decentpenguin has joined #zig
<FireFox317>
that's sad Xavi92 :(
squeek502 has quit [Ping timeout: 256 seconds]
<decentpenguin>
This may be a dumb way to do things, but is there a way to store a variable's type in runtime? I'm writing this (https://gitlab.com/snippets/1964721) but I can't figure out a way to make query() behave like queryAs() since I can't see how to store the type in EntityIndex
<fengb>
Types can’t exist at runtime. You’ll have to invent some enum to manually map them
<decentpenguin>
I see. Thanks.
gpanders has quit [Ping timeout: 250 seconds]
gpanders has joined #zig
daex_ has joined #zig
daex has quit [Ping timeout: 264 seconds]
AndroidKitKat has quit [Quit: バイバイ〜!]
AndroidKitKat has joined #zig
daex has joined #zig
daex_ has quit [Ping timeout: 260 seconds]
Yardanico has quit [Killed (Sigyn (Spam is off topic on freenode.))]
RagingDave has joined #zig
RagingDave has quit [Client Quit]
RagingDave has joined #zig
Xavi92 has quit [Remote host closed the connection]
Yardanico has joined #zig
gpanders has quit [Ping timeout: 265 seconds]
gpanders has joined #zig
dimenus has joined #zig
<dimenus>
how old is the zig compiler that godbolt uses?
<dimenus>
trunk I mean
<Yardanico>
dimenus: it tells if you press the little "i" on the bottom of the right window (the assembly viewer)
<Yardanico>
0.5.0+543031db3
<Yardanico>
seems to be a pretty recent commit from 21 hours ago
<Yardanico>
i'm surprised they update stuff that often
<fengb>
I wouldn't be surprised they just pull the nightly build
<dimenus>
i was just curious because the godbolt example produces a lot more code than my local one, though I'm not sure what flags godbolt automatically passes
<layneson>
nycex: put a & before the [_] of the second argument: &[_][]const u8 ...
reductum has joined #zig
<nycex>
yeah that works thanks
wootehfoot has quit [Ping timeout: 246 seconds]
<andrewrk>
nycex, thanks, will update
<jamii>
Looks like `&[_]t{}` does the trick.
decentpenguin has quit [Quit: decentpenguin]
<nycex>
but i don't know if i'm doing anything wrong but the build.zig does now compile but the example itself doesn't work, I did it like in the example and get the following:
<nycex>
Looks like `&[_]t{}` does the trick. e/bernhard/dev/zig/segfaulthandler/test.c:1:10: fatal error: 'mylib.h' file not found
<Xavi92>
Unreachable at /deps/zig/src/link.cpp:1719 in getLDMOption. This is a bug in the Zig compiler.
<Xavi92>
(Have tested an empty main also on AVR, but raises a compiler bug, apparently)
r4pr0n has joined #zig
dimenus|home has joined #zig
dimenus has quit [Read error: Connection reset by peer]
<r4pr0n>
andrewrk: a few days ago you told me how to enable the zig segfault handler in c programs. i tried that. is it normal that there is no stacktrace but rather `Panicked during a panic. Aborting.` because it's no zig code but c code?