5 ms·
What specifically, that they mention Zig or that you learned of Zig or that Zig has a lazy build system or ??? The thing I really find interesting about Zig is
by seg_lol 6y ago
What specifically, that they mention Zig or that you learned of Zig or that Zig has a lazy build system or ???
The thing I really find interesting about Zig is the compile time function evaluation [1] and how it can stand-in for macros, code generation, precomputing values, etc. I think of CTFE as a continuation that comes baked into the binary from an earlier point in time, T-days_ago.
As for this release, I am stoked to see Flang making progress. I am excited about Fortran in the browser.
The interesting thing of note is that Zig is in the process of creating their own backend, but I don't see them dropping LLVM any time soon. An alternate backend is a great way to find bugs in codegen.
[1] https://andrewkelley.me/post/zig-programming-language-blurs-line-compile-time-run-time.html https://andrewkelley.me/post/zig-programming-language-blurs-...
- mhh__ 6y agoI'm probably biased but comptime doesn't seem as elegant as the mechanism D provides for doing CTFE (i.e. I prefer a separation of quasi-template parameters)
- nikki93 6y agoCan you eg. generate a struct with fields based on an existing struct or on a comptime array in D? Can you receive a structure literal of anonymous type and iterate over it at compile time? (curious bc. these were a few things I found straightforward in Zig, and in C++ the main proposals involve tons of new metaclasses and reflection features for)
- mhh__ 6y agoYes to all points. D doesn't go the C++ route, the way code like this works is via generating new code (in text) at compile time which the compiler then compiles (duh) and replaces the mixin statement within. Here's an annotated example of these features in use https://run.dlang.io/is/2b5zgC https://run.dlang.io/is/2b5zgC
- fithisux 6y agoBrilliant.
- Matheus28 6y agoThat is beautiful. I wish C++ had something like that... Perhaps in addition to its current template system. Having a separate build pass to generate files is annoying.
- pjmlp 6y agoIt does, via constexpr, which just got more expressive in C++20, and is the basis for the ongoing compile time reflection work on C++23. Code injection might eventually come later via Microsoft's ongoing research in C++ metaclasses. "Dynamic Polymorphism with Metaclasses and Code Injection" https://www.youtube.com/watch?v=8c6BAQcYF_E https://www.youtube.com/watch?v=8c6BAQcYF_E
- Matheus28 6y agoThat looks a lot more complicated than D's simple "output text that gets fed back into the compiler". But admittedly I only quickly jumped around the video. Hopefully it works well, though.
- pjmlp 6y agoTrue, but a programming language is more than just syntax and for better or worse, the ecosystem is what matters.
- mhh__ 6y agoThat's what I meant by doesn't go the C++ way. The standards committee over complicate everything (concepts still haven't landed yet for example, D has D a better more flexible system 15 years ago I think)
- pjmlp 6y ago
- renox 6y agoWhile I agree that D is a 'treasure' (full of good ideas that should be copied more often by other languages) I don't understand why you think that D's way is better than Zig here.. What exactly do you prefer?
- mhh__ 6y agoIt's personal preference, but if a parameter is well and truly compile time I think it should be separate from the others (it certainly makes introspection "easier")
- seg_lol 6y agoAside, there no reason that this comment should be downvoted.
- fpoling 6y agoZig's comptime is surprisingly powerful and does not suffer C++ template problem when an error message at the instantiation site is extremely unhelpful. And Zig managed it without constrains or traits just via bunch of useful compile-time operations on types. Still I do not see how one can have, for example, a struct field or enum case available only at certain compile-time condition like OS version.
- nikki93 6y agoYou can put together an `std.builtin.TypeInfo` structure describing the type (eg. by using `@typeInfo` on an existing type and editing the result, adding something under `.Struct.fields`); then use `@Type` to 'unreflect' it back into a real type.
- fpoling 6y agoSplendid! This is much more flexible than various static if aproaches like in D or modern C++.
- throwaway17_17 6y agoRandom question, but you’re the first commenter who mentioned flang, so I am hoping you know the answer: is Flang doing its own alias management to enable Fortran’s optimizations on arrays, or did LLVM finally regain usable alias attributes in the backend?
- seg_lol 6y agoPerf isn't a high priority for me, more about getting Fortran into the browser. I don't have insights into the aliasing.
- throwaway17_17 6y agoThat’s interesting. Is it personal familiarity with the language that drives your desire or is some features of the language that you find lacking in alternative languages already in the browser space?
- skavi 6y agoAnother option may be wanting to port existing Fortran libraries to web.
- drfuchs 6y agoZig's home-grown backend is strictly for super-quick turnaround compile and link during development. For optimized release builds, they'll depend on LLVM forever.
- seg_lol 6y agoI think that is a lovely solution for a couple reasons. First it allows the project to optimize for its goals (dev latency), this allows the team to have more local control and autonomy. Second, it puts _less_ pressure on LLVM to have both a low latency version and a highly optimized version. If the LLVM IR could be more of a common format, I think it would provide a medium for tools to compose better. Eventually we will get there, compiler gods willing. I think LLVM should be the place for the massive-engineering-effort optimization passes. Lastly, it provides for differential testing of both backends, this makes Zig's homegrown one AND LLVM better. Thanks for sponsoring Zig!