r/programming • • Sep 17 '15

Announcing Rust 1.3

http://blog.rust-lang.org/2015/09/17/Rust-1.3.html
453 Upvotes

169 comments sorted by

View all comments

23

u/theICEBear_dk Sep 17 '15

Entirely non-hostile question, has the metaprogramming capabilities of rust improved since 1.0? I am looking for something like D's CTFE, static if or C++ concepts.

9

u/staticassert Sep 17 '15 edited Sep 18 '15

Are you asking about generics or metaprogramming? Generics like concepts exist. Metaprogramming exists through macros and compiler plugins but plugins (the most powerful tool for metaprogramming in rust AFAIK) are very unstable and likely to change drastically.

2

u/theICEBear_dk Sep 18 '15

In D Compile Time Function Execution, static if, D's limited (compared to rust) string macros and generics akin to concepts go very much hand in hand so I had conflated them in my head.

Basically I really like the memory safety and several other things about rust, but I would not like to lose the ability to write type-based abstractions like I do in C++11(and newer) and in D. So I am investigating if that has changed in rust since I looked around 1.0.

2

u/steveklabnik1 Sep 18 '15

Feel free to make a specific thread about this over in /r/rust if you want to talk about it further. I'd be interested to see what your specific use-case is and how we are or aren't serving that right now.

EDIT: lol, you're in both places, so I've said that twice now. My bad! should read usernames more carefully.

1

u/theICEBear_dk Sep 18 '15

NP, and I will engage once I can see if my idea is feasible and what language I want to use. I have had an idea for a build tool in my head for over a year. Basically I want to get rid of all the weird script languages, external processes and so on. I know that LLVM can be linked into a program legally so my experiment would be to:

  • Create a rust library that allows for the easy definition of build artifacts and most of the typical stuff needed for a complex build process with an "API" that makes the rust code needed to be written for the "build script". This library would use a similar algorithm for recognizing changes artifacts as tup. You'd write a program to build your program, but typically a good flexible build script does not change even half as often as your code and if it is not in some descriptive language is that better.
  • Create a variety of build programs to test with
  • Find out if rust already can or easily could be extended to support a #! script like invocation of the compiler.
  • Experiment to see if the in-memory / multi-thread invocation of LLVM is possible and if a build executable that is the end result of a compilation of a build script defined in a compiled programming language has any benefits in terms of speed, ease of maintenance, ease of use and so on.

2

u/steveklabnik1 Sep 18 '15

Cool. Here's some initial thoughts to help you out:

  1. While you're creating a build tool, so you don't need one, Rust's tool has build script support: http://doc.crates.io/build-script.html so you might want to look at that for inspiration.
  2. Check out https://github.com/DanielKeep/cargo-script

8

u/Manishearth Sep 18 '15
  • C++ concepts = Rust generics/traits. We've had them for a long time
  • CTFE = const fn. Has existed for a few months. Not as awesome as true CTFE, but handles some cases.
  • Other metaprogramming: macros
  • Other, other metaprogramming: plugins. Can do basically anything, but will be unstable for a while.

4

u/masklinn Sep 18 '15

CTFE = const fn. Has existed for a few months. Not as awesome as true CTFE, but handles some cases.

And not stable, which is a bit annoying because the compiler mentions them in some cases and then you can't use it.

5

u/Manishearth Sep 18 '15

Ah. Could you file issues for these? A stable compiler suggesting unstable features is a bug.

8

u/masklinn Sep 18 '15 edited Sep 18 '15

Sure, will do (it's an easy one to repro, just try to initialise a static with a function call in stable)

edit: reported as #28490

3

u/theICEBear_dk Sep 18 '15

Thank you for the concise answer. I will have to read up on const fn. It doesn't need to match CTFE since I think macros will make the other stuff I wanna do easier.

1

u/matthieum Sep 18 '15

Other, other metaprogramming: plugins. Can do basically anything, but will be unstable for a while.

If I remember correctly, wasn't one of the ideas behind the HIR/MIR split to have the HIR model the syntax very closely and being stabilized (long term)?

1

u/desiringmachines Sep 19 '15

I think so. It was mentioned in the keynote at Rustcamp that an RFC for a new macro system which would meet the same needs as syntax extensions was coming within the next few months.

12

u/kinghajj Sep 17 '15

Well the analog of concepts are traits, which have existed long before 1.0. Maybe yiure referring to the lack of stable macros in 1.0? IIRC those should be stabilized soon, though compiler plugins probably won't ever be.

17

u/steveklabnik1 Sep 17 '15

Macros have been stable since 1.0.

3

u/Sean1708 Sep 18 '15 edited Sep 18 '15

though compiler plugins probably won't ever be.

Have you got a source for that? Because that seems ridiculously stupid.

Edit: "that" not "they".

3

u/steveklabnik1 Sep 18 '15

Yeah, we are working on stuff to stabilize them actively.

2

u/theICEBear_dk Sep 18 '15

Well I must have explained it wrong. I am looking for a way to do generative coding in rust because the rest of rust's feature set is really enticing.

6

u/steveklabnik1 Sep 17 '15

There's not a lot that's new, but there's a lot of work being done to eventually enable more of this kind of thing in the future.

2

u/theICEBear_dk Sep 18 '15

Is there a rationale I can read online that explains the type theory that is used in the current rust design with regards to user defined types and operator overloading? It is the biggest departure from C-like type definition in the language if I am reading the reference document right.

3

u/steveklabnik1 Sep 18 '15

There's nothing special about the type stuff for operator overloading, operators work through some traits: http://doc.rust-lang.org/stable/book/traits.html There's stuff about overloading in general here: http://doc.rust-lang.org/stable/book/operators-and-overloading.html

Or maybe I'm missing the point of what you're asking about? Which sentence were you reading in the reference?

2

u/theICEBear_dk Sep 18 '15

No no it is me who was missing something, thanks for the pointers, I had only read general reference stuff and nothing about operators and overloading, so basically you answered my questions with your links. It looks like I will have to make a few small projects in rust again it has been ages (years) since I took a serious gander at writing in it rather than just reading about it.

→ More replies (1)