What is Borrow Checker?

I was reading a bit about Rust and came across this term, I would like to know:

  • what is Borrow Checker?
  • is there any relation to reference counting ?
  • What would be the translation for this term in Portuguese?
Author: Maniero, 2020-03-07

1 answers

What is Borrow Checker?

Is the code parser contained in the compiler (it would not need to be but in Rust it is, it is part of the philosophy of the language) that identifies whether the lifetime of objects is being respected.

When you have a reference to an object that reference has ownership of it, then another reference can only have the object on loan, it does not own the object and can not do as it sees fit with it, for example not you can destroy it.

In some cases the Rust parser can identify if everything is ok and places lifetime annotations of the object for you, in other cases you, the programmer, must explicitly annotate to indicate that there is loan compliance, which will prevent certain code constructs that would subvert it.

So it is a static analysis (compile time) about the object's lifetime allowing only its owner to destroy it. He gives Reference Security for Rust without creating cost to the executable.

Is there any relation to reference counting?

No direct. In a way it has if we consider that it is almost an opposition to it. While the loan ensures that only one reference has ownership of the object and it is borrowed through other references, the reference count allows multiple references to own the object together, not needing to make one loan. It is a runtime engine that needs to store and control a reference counter and indicate whether the object can be destroyed, so it has a cost.

What would be the translation for this term in Portuguese?

Loan Analyzer? Property parser could fit too, but obviously not the most correct.

 7
Author: Maniero, 2020-03-09 13:10:27