Fighting the borrow checker, with machine learning?

has anyone tried using reinforcement machine learning to make borrow checker errors go away? effectively a brute-force solution to borrow checker errors?

we could kinda use one right now...

1 Like

Sounds like copilot or tabnine. Never have I used them though.

1 Like

You'd better hope the ML doesn't learn to just use unsafe pointers everywhere... sometimes that is the right solution, but with careful consideration to uphold safety around it.

3 Likes

Those don't really use real-time compiler feedback. They're not well suited to finding the optimal solution to a given particular borrowck issue.

Nah the code with the borrowck issues already uses unsafe everywhere. It'd be nice if the ML used more unsafe. Maybe then it'd actually work.

1 Like

In the vast majority of cases, it would seem to work and then break unexpectedly - maybe even without anyone noticing.

3 Likes

That's what miri with raw pointer tagging is for, ofc!

1 Like

Would it not be that at that rate you're just writing C and shoving it through an address sanitizer?

4 Likes

Nah because the result of all this is a safe Rust API anyone can use without having to think about the internals.

1 Like

Well, it will catch the problem only if it is hit by the code path in use. Do you have the 100% code coverage, at least? (And note that this is not enough, since some code path might hit the UB case only with particular inputs)

1 Like

Yes, the tests should cover all the ways the API user can misuse lifetime variance. Code coverage no longer matters at that point, as it's just transmutes and callbacks.

1 Like