Live data from Hacker News

Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

gitlab.com

21–30 of 35 posts

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#21

Would it be possible to write a compiler from Java to Rust? C# to rust? The goal then would be to get fast(er) execution times.

Rust get’s a speed advantage over those languages from three things:

1. Being safer for writing concurrent programs and therefore having programs which are concurrent

2. (mostly) Type safe memory management which means most things are allocated on the stack and those things that are allocated in the heap don’t need to be gc’d (but note that gc doesn’t mean slow memory management but it is harder to have a shared heap in concurrent programs as some synchronisation is needed), and rust programs are typically written in a way that doesn’t allocate much on the heap.

3. Specialisation of generic code to specific data types

1 and 2 are hard for Java and c# as programs are not normally written in ways which would satisfy rust’s checks and so a compiler would just compile these to runtime checks like the c# or Java compilers would use. For number 3. C# already does this.

Note that actually if C# or Java program were translated into a rust program which does the same work then the Rust program would probably be slower because the Java and C# compilers are much better at optimising programs written in the Java/C# style. A fourth advantage rust gets (part of 3 and part of the type system) is a lack of subclassing and vtables which are typically fast at runtime but hard to inline.

One way to make a Java or C# program faster is to be conscious of the hidden work being done and trying to write programs in a way that safety checks can be eliminated and allocation can be made automatic.

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#22

Would it be possible to write a compiler from Java to Rust? C# to rust? The goal then would be to get fast(er) execution times.

> Would it be possible to write a compiler from Java to Rust? C# to rust?

It's possible to write a compiler from any Turing-complete language to any other Turing-complete language

> The goal then would be to get fast(er) execution times.

You'd improve startup times from not having to warm up the JIT, but otherwise it would very unlikely you'd get a noticeable performance improvement. The speed of a language is at least as dependent on its execution model and idioms as its compiler. Not to mention that the JVM already does plenty of optimizations

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#23
Perhaps I don't understand something? (I've only done a very small amount of Rust.)

What exactly does this do? Let you write Java-style code in Rust? Why would I use this? (Is it because writing code like this is easier than straight rust?)

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#24
post #23

Perhaps I don't understand something? (I've only done a very small amount of Rust.) What exactly does this do? Let you write Java-style code in Rust? Why would I use this? (Is it because writing code like this is easier than straight rust?)

> Let you write Java-style code in Rust?

Yep

> Why would I use this?

You wouldn't. It's a toy

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#25

Would it be possible to write a compiler from Java to Rust? C# to rust? The goal then would be to get fast(er) execution times.

> Would it be possible to write a compiler from Java to Rust? C# to rust? It's possible to write a compiler from any Turing-complete language to any other Turing-complete language > The goal then would be to get fast(er) execution times. You'd improve startup times from not having to warm up the JIT, but otherwise it would very unlikely you'd get a noticeable performance improvement. The speed of a language is at lea…

[deleted]

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#26

Cool. On the other hand, projects like these suggest to me that Macro systems like Rust's are a bit too powerful. Not that I know how to make it just enough less powerful.

Rust macros are intended to be powerful, by design.

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#27
post #4

But the issue with Rust ins't the syntax, it's where you need to change your entire thought model to match what Rust expects. Well, ok, the syntax can be pretty horrific at times, but going to something Java-like doesn't seem like much improvement.

The issue contrariwise with most other languages that can achieve similar performance characteristics as Rust, is that if you don't think about your code in a similar level of detail as the Rust compiler can "think" about Rust code ... then you get undefined behavior, memory leaks, and all sorts of really exciting run-time bugs that your tests may or may not detect.

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#28
post #16

Cool. On the other hand, projects like these suggest to me that Macro systems like Rust's are a bit too powerful. Not that I know how to make it just enough less powerful.

Rust's macro system is actually quite limited (I don't know if it's Turing-complete, but the artificial recursion limit is low enough that even if it is, it's not going to be all that abusable); macros are mostly just good for getting rid of repetitive boilerplate, and community norms (and implementation papercuts) discourage people from reaching for macros willy-nilly.

They are Turing complete, see https://github.com/durka/brainmunch

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#29
Get 24/7 Unlimited Roadside Assistance For As Little As $9.95 a Month Unlimited 24/7 roadside assistance. (Whether you’ve got a flat tire, out of gas, locked out of your car, or need towing, just call us, and we’ll be there in 45 minutes or less) Get reimbursed for calling your own tow company up to $100. If your car is undriveable due to an accident we will cover your rental car up to $500. Or, if you’re far from home, we’ll pay up to $500 for food, lodging or transportation click below for more information https://roadsidekings.com

Re: Show HN: A Rust macro that parses Java-like syntax and runs it as a Rust program

#30

Would it be possible to write a compiler from Java to Rust? C# to rust? The goal then would be to get fast(er) execution times.

> Would it be possible to write a compiler from Java to Rust? C# to rust? It's possible to write a compiler from any Turing-complete language to any other Turing-complete language > The goal then would be to get fast(er) execution times. You'd improve startup times from not having to warm up the JIT, but otherwise it would very unlikely you'd get a noticeable performance improvement. The speed of a language is at lea…

I'm not sure the statement "It's possible to write a compiler from any Turing-complete language to any other Turing-complete language" is really accurate, other than in a strict cs sense. If you have a language that only allows printing to the screen as output and reading from the keyboard as input then you can't write anything that requires low level hardware access in it.
Post reply on HN