Racer type-inference with stable rustc?


Hi Internals list,

I’ve come to a halt with Racer recently because I’m unclear how to progress wrt type analysis.

  1. racer needs rustc’s help in order to perform ‘perfect’ type analysis
  2. rustc’s internal api is unstable (because the api changes regularly)
  3. rustc is tightly coupled to the build artifacts it generates (e.g. .rlibs)

Unfortunately (2) means currently a rustc-enabled racer cannot be built with stable rust, and (3) means a rustc-enabled racer built with nightly rust cannot process stable rlib artifacts to derive completions (I think - is this true?).

So actually racer needs to be built against rustc stable (I think). Does anybody have a good idea for how to solve this problem?

One possibility would be to expose a stable coarse grained api for distribution with rustc, maybe in a separate lib. E.g. something like:

let ctx = setup_compiler(args);
let path = ctx.resolve_type_of_expr(search_file, span);

Where args is an array of command line args [&String] in the same format as rustc takes, ‘search_file’ and ‘span’ compose the coordinates of an expression and resolve_type_of_expr returns a Path encoded as a String. (span coordinates would be local to the file rather than the crate)

This isn’t a great solution, but I don’t have any others. Would the team be open to a PR with this sort of api? Any altenative suggestions would be gratefully appreciated!

Thanks very much!




My suggestion for racer/rider was to bundle them with the compiler and have the stable interface for IDEs be racer/rider themselves.

In the meanwhile, you can actually compile against the stable compiler, because it’s not actually… locked down.

Instead of doing something sane like having two drivers, one for building its own libs and one that is released, we ended up with a hack (which I was against at the time): an environment variable is checked for a magic value to determine whether the compiler is unstable-feature-enabled.

You can probably find the magic value in the build logs, or extract it from the binaries (I have done this in the past with just grep and sed).

I can provide further assistance on IRC.



Thanks @eddyb, this is really useful info. It was pretty straightforward to extract the magic value from the stable binary libs so I will run with this to begin with.

Once I have something workable I’ll be back to see if there’s any appetite for adding it to the rustc distribution. (Otherwise we’ll need to release racer binaries for people wanting to use this functionality with stable rust).


closed #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.