Stream: t-compiler/wg-rls-2.0

Topic: Source refactoring


matklad (Sep 16 2019 at 14:25, on Zulip):

it's module identity that distinguishes one foo from another.

nikomatsakis (Sep 16 2019 at 14:25, on Zulip):

(I'm going to break this out into its own topic, it seems worth separating; also, I'm going to have to run for a bit, but I'll continue async)

nikomatsakis (Sep 16 2019 at 14:25, on Zulip):

ok carry on @matklad, I'm following so far :)

matklad (Sep 16 2019 at 14:26, on Zulip):

So far, this jump from "value-type syntax" to "identity-based hir" was pretty adhoc

matklad (Sep 16 2019 at 14:28, on Zulip):

However, we had an struct Source<T> { file_id: HirFileId, ast: T} type just to conveniently describe a piece of ast in a file. It was used mostly by the IDE side of thing, so that you can go from hir::Struct (which is an id) to Source<ast::StructDef> which you can use in the editor for goto def (this is essentially a span: file name + text range inside a file)

matklad (Sep 16 2019 at 14:28, on Zulip):

And now, in the https://github.com/rust-analyzer/rust-analyzer/pull/1815, it seems like this Source<T> thing is how we'd add a hygine

nikomatsakis (Sep 16 2019 at 14:29, on Zulip):

struct Source<T> { file_id: HirFileId, ast: T}

does this also include the line/column/whatever within the file?

matklad (Sep 16 2019 at 14:30, on Zulip):

Yeah: currently each node in AST remembers position within a file

matklad (Sep 16 2019 at 14:30, on Zulip):

That is, this info will be present in T for reasonable Ts

matklad (Sep 16 2019 at 14:31, on Zulip):

So, using the file_id field of the Source you should be able to fetch hygiene tables from the database, and assign proper hygiene to identifiers in the AST

matklad (Sep 16 2019 at 14:32, on Zulip):

this is super hand-wavy, as this is a naturally emerging abstraction, I am not sure about the details yet :)

matklad (Sep 16 2019 at 14:33, on Zulip):

This Source<T> is also used in https://github.com/rust-analyzer/rust-analyzer/pull/1853, which cleanups the way IDE goes from offsets to hir.

matklad (Sep 16 2019 at 14:34, on Zulip):

Basically, the problem in IDE is that if you have #[path = "foo.rs"] mod x; #[path = "foo.rs"] mod y; and the user asks for "Goto Definition" for some definition inside foo.rs, the request is ambiguous, as foo.rs is effectively included twice.

matklad (Sep 16 2019 at 14:34, on Zulip):

The Source thing captures that ambiguity precisely

Jeremy Kolb (Sep 16 2019 at 14:42, on Zulip):

Is source_binder going away?

matklad (Sep 16 2019 at 14:42, on Zulip):

yeah

Last update: Nov 12 2019 at 16:35UTC