wffl

vaguely burnt

  • it/its

I do stuff; pfp by spicymochi



.lock file for method resolution.

The problem with methods in rust is that basically adding any methods in any way is technically™ a breaking change, since adding a method can either cause ambiguity or a different method to be resolved at the call site.

But what if, when compiling, the compiler outputted a file, which basically says "ah yes, that method call is resolved to this method", then compiler can prioritize the resolution in the .lock file over what actually would be happening.

Now, this has multiple problems (like changing the .lock file affects code in potentially very surprising ways) and would probably be hard to do, but still, would be cool to fix the problem...


You must log in to comment.

in reply to @wffl's post:

if the language has the python/haskell sort of import statement where you can list out your itemized imports, and give them all unique local names, like

from foo import (bar, bas as baz)
from zim import (zang, zung)

and you have a way to refer precisely to any declaration that can be in those modules, then you could get that sort of effect in-band. that reduces the problem to getting your text editor or IDE to generate the import list for you, since maintaining that sort of precise import list manually is a pain

Well, not having methods and always using paths (optionally shortened with use/import statements) is a viable option, but that's not methods anymore :')

Methods are desirable exactly because they normally don't require disambiguation and can work just of the type of the receiver.

Although I guess, you could make it so that you need to import methods, but can then use them as methods (so that the search space is frozen), I could imagine something like use module::Type::{self, method as _}.

That would actually be pretty cool now that I think about it :thinking:

In Rust in particular, methods are largely an illusion, so it also seems viable that an itemized import syntax could also refer to individual methods from individual traits or non-trait impls like use module::{impl Type::{methodA, methodB}}