I find this community best place for discussion also I found Andrew Kelley reply here.
So basically I am designing a language which will transpile/compile to zig.
This will be a great step as till now many languages have targeted C like nim, v, etc but no one targeted zig. My main motive behind targeting zig was it’s lightweight compiler(C’s clang or mingw huge size), Cross compilation and easier syntax.
So I am designing the language somewhat memory safe like rust with move and borrow rules.
And I am adding in it a global heap on which all the main memory of programs can be allocated.
It will work like this global.new(T) and global.free(ptr).A new feature than rust I am adding is global will be in a main zincstd.zig in which you can change the allocator using for whole program to any like Gpa,Smp or third party like Mialloc or jalloc or rmpalloc without changing anything in the codebase and infact libraries will also use the new allocator because whole codebase use the one zincstd for main heap of program.
And I am allowing users to use local which is a function scoped version of arena for speed.local will be only one per function and local allocated things can’t be returned from function without converting them to global using local.toglobal(ptr).
Everything will be freed and no memory leaks are guaranteed by the compiler in generated zig.
And when passing a heap allocated variable to function as argument it will always be sent as pointer to the value and not the value it self which I think will solve the stack overflow errors.
Like Rust in zinc also there can be only one owner per heap storage and when the owner is freed all borrowers will be at same time freed.
I am thinking to use Gpa as main allocator in starting so that any memory leak can be caught.
And then moving towards Smp allocator for speed.
I want some rating from users of this community about the design.
We need a link to a project to assess what you have done. Or are you asking for opinions based solely on the idea contained in your post ? In that case I’d say that the biggest hurdle for me was understanding the borrow-checker in rust, so I won’t be willing to learn how it works. I am happy to have the tools in zig to help catch bugs, such as ubsan and co and checked illegal behaviour, it has helped me a lot already. The day I write pacemaker firmware however I may change my mind.
I imagine what they have/will implement is many times simpler, rust has been working on their borrow system for about a decade now, and it still has plenty of (niche) issues.
@ziyaad even if you do have something to show of this, you are not presenting or talking about it. Rather, you are asking for feedback on a design, this would fit more in the brainstorming category.
If/when you do want to show off your language, and have something we can play with, then you’d make a post in showcase presenting it to us.
rusts system is for memory safety. Memory safety is a very complicated thing to handle automatically. A simple borrow system does certainly help, but don’t make it sound like you have solved memory safety, or that it is a simple task.