News for hackers. Stuff that matters.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by _bxg1 on Saturday February 01, 2020 @07:04PM (#22214164)
> Another thing is difference in handling invalid code. A traditional compiler front-end is usually organized as a progression of phases, where each phase takes an unstructured input, checks the input for validity, and, if it is indeed valid, adds more structure on top. Specifically, an error in an early phase (like parsing) usually means that the latter phase (like type checking) is not run for this bit of code at all. In other words, "correct code" is a happy case, and everything else can be treated as an error condition. In contrast, in IDE code is always broken, because the user constantly modifies it. As soon as the code is valid, the job of IDE ends and the job of the batch compiler begins. So, an IDE-oriented compiler should accommodate an incomplete and broken code, and provide IDE features, like completion, for such code.

This has been one of the most frustrating things about Rust's development experience. A piece of code looks error-free, then you fix an error somewhere else, reach the next compiler phase, and an error pops up where you just were. It makes it really hard to develop something piece by piece.

I'm glad they're aware of these problems and are making a concerted effort to address them.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by Buttons840 on Saturday February 01, 2020 @07:57PM (#22214392)
> A piece of code looks error-free, then you fix an error somewhere else, reach the next compiler phase, and an error pops up where you just were.

Isn't this the case with all compilers? The most basic example being (for example) I have a syntax error on line 10, and that's the only reported problem, but then I fix the syntax error and now I have an error on line 200.

I agree it is a problem, the world would be better if all languages could avoid it, but I don't expect it ever to go away. Do you believe this problem is better or worse in Rust compared to other languages?

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by the8472 on Saturday February 01, 2020 @09:14PM (#22214707)
Eclipse's ECJ will keep compiling a class even when a specific method is invalid.

And even inside a method it'll try to massage the AST into a somewhat valid state while you're typing so it can keep analyzing the code and show errors/make suggestions. A missing bracket on line 15 won't prevent it from soldiering on to spot a misspelled method call in line 40 even though the nesting is totally messed up and if taken at face value line 40 would be syntactically invalid since it's outside the class body.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by usrusr on Saturday February 01, 2020 @11:15PM (#22215101)
And it doesn't just march on to identify errors elsewhere, it can often continue all the way to runnable bytecode. The invalid parts will just be replaced by exceptions that parrot the compiler error. Meanwhile other code paths can already be exercised which can be very handy at times.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by gmueckl on Sunday February 02, 2020 @02:43AM (#22215740)
On the flipside, I have managed to actually run non-compiling Java classes because of that a couple of times, only to stare at the debugger with wide eyes when I realized what was going on.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by _bxg1 on Saturday February 01, 2020 @09:38PM (#22214797)
I could even understand not trying to handle the brackets scenario. In RLS, a type error on a local variable can hide a borrow-checker problem in a completely different file.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by Matthias247 on Saturday February 01, 2020 @09:39PM (#22214803)
It’s more pronounced than in other languages. You could have an entire file with zero errors. No red squiggles, nothing. Then after you fix your errors in different files suddenly errors show up (eg for borrow checking, thread safety analysis, etc).
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by dx87 on Saturday February 01, 2020 @10:26PM (#22214946)
That always gets me. I'll be writing some code and think I finally got really proficient with Rust because I'm not getting any errors or warnings, then I try to compile and find out an error in another file was preventing the compiler from showing me everything wrong in my current file.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by mxcrossb on Sunday February 02, 2020 @02:57AM (#22215790)
Yes I think what rust fans should argue is not that it’s just like compile time errors in other languages, but more like run time errors.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by _bxg1 on Saturday February 01, 2020 @09:00PM (#22214646)
In other languages I'm familiar with as long as the syntax can actually be parsed, errors are mostly localized. Of course if you change the type of something that can cause errors elsewhere. But this is different. The new errors have nothing at all to do with the one that was fixed except that they come from an earlier stage of the compilation process.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by edflsafoiewq on Saturday February 01, 2020 @08:18PM (#22214490)
> Do you believe this problem is better or worse in Rust compared to other languages?

Unlike other languages, Rust still has borrow checking to go after all the type errors are gone.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by pjmlp on Sunday February 02, 2020 @07:01AM (#22216560)
An idea currently being added to Swift, C++ (via static analysis, core guidelines lifetime profile), Ada/SPARK, D, OCaml and Haskell, originally developed in Cyclone, further explored in ATS.

So that "Unlike other languages" isn't quite true.

What Rust has done, was to prove it is viable to push such ideas into mainstream computing.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by pcwalton on Sunday February 02, 2020 @01:54PM (#22218586)
This is incorrect. Neither Cyclone nor ATS had borrow checking. In fact the ATS author at one point dismissed borrow checking as too inflexible.

The borrow checker is actually original, though based on known techniques. Specifically, the original part is that it allows the per-use-site choice of aliasing vs. mutability instead of making the decision globally.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by pjmlp on Sunday February 02, 2020 @02:16PM (#22218725)
I might be wrong on the origins, but I am certainly right that everyone else is now adopting similar algorithms.

So while it is great that Rust is making these concepts mainstream, in about 5 years time, the other languages will have their New Jersey style implementations mature and available for their communities.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by pcwalton on Sunday February 02, 2020 @02:22PM (#22218781)
Borrow checking cannot be soundly added to C++, or most other languages, for systematic reasons. Soundness isn't a theoretical property here: C++ has constantly been adding things that make it safer as opposed to making it safe, and memory safety problems are still a huge issue.

See "Safe C++ Subset is Vaporware" by Robert O'Callahan: https://robert.ocallahan.org/2016/06/safe-c-subset-is-vapour...

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by pjmlp on Sunday February 02, 2020 @04:25PM (#22219548)
Why do you think I mentioned New Jersey style implementation?

Google and Microsoft are the ones driving that effort, in what concerns C++.

That vapourware is quite welcomed when using DriverKit, Unreal, COM/UWP, Project Treble drivers,..

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by onei on Sunday February 02, 2020 @05:18AM (#22216231)
It depends on the compiler. A naïve parser might reach a syntax error and error out. A more advanced parser will look for a synchronidation point that it can move to and carry on. If the compiler is in a statement, that might be a semicolon, for a function it could be a closing brace. From there it can reset to some degree and carry on parsing the file.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by epage on Saturday February 01, 2020 @07:25PM (#22214264)
Hadn't thought of that potential benefit to the rust-analyzer work: I could get borrow errors upfront even if there are irrelevant errors in other areas of code.

(borrow checker seems like it is one of the last phases).

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by woah on Saturday February 01, 2020 @08:23PM (#22214512)
That’s how you know you’re reaching the light at the end of the tunnel, when the borrow checker errors start showing up
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by _bxg1 on Saturday February 01, 2020 @09:01PM (#22214654)
I've started associating a shower of warnings with "success", because those only appear once all the errors have been taken care of
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by nirui on Sunday February 02, 2020 @02:21AM (#22215671)
Or, in my case, it tells me why I have to restructure my code :(

I mean, an early warning, before I actually made those mistakes would help a lot, if it can be done that is :)

[dead]
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by echelon on Saturday February 01, 2020 @08:45PM (#22214593)
Do you have to dump on Rust because of its learning curve? It isn't even that bad. It's not like Golang doesn't have warts of its own.

I have a hard time believing you make this choice often or "usually". This seems like flat out prejudice.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by galangalalgol on Sunday February 02, 2020 @01:33AM (#22215517)
If go was fast enough why didn't you start out using it, or some other language that is 3x slower than rust but has gc and comfy ergonomics. C#, clojure, julia, ocaml( if you dont need threads). Or just plane Java.
Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by earenndil on Sunday February 02, 2020 @12:00AM (#22215235)
> Another thing is difference in handling invalid code. A traditional compiler front-end is usually organized as a progression of phases, where each phase takes an unstructured input, checks the input for validity, and, if it is indeed valid, adds more structure on top.

Is this true? The way the d compiler does it is to make a special ast node type called 'error', which allows it to avoid this problem. I have also gotten error messages from c compilers that indicated they were doing something similar.

Now, in the d compiler, this is not a panacea, because erroneous code can cause erroneous error messages about unreachable code, but it generally works quite well.

Re:Rust Moving Towards an IDE-Friendly Compiler with Rust An... by estebank on Sunday February 02, 2020 @12:22AM (#22215299)
rustc does the same. I believe the op complaint is that rustc does not perform type and lifetime checks on blocks of code that haven't been successfully parsed.