Stream: t-compiler/help

Topic: history of typeck and borrowck


Tshepang Lekhonkhobe (Apr 03 2020 at 06:38, on Zulip):

When ast-borrowck was implemented (in 2012), there was no hir. Once hir was added, did ast-borrowck move to make use of it? Where does typeck fit in... am I right in assuming typeck has to happen before borrowck, and if so, did it also move from using ast to using hir?

bjorn3 (Apr 03 2020 at 08:49, on Zulip):

typeck moved to hir. i don't know how it was before, but after the move typeck stores inferred types in a side table, as hir is immutable. typeck indeed has to happen before borrowck as typeck may add implicit dereferences and references. eg a.foo() where foo takes &self results in (&a).foo(). borrowck has to know about this.

eddyb (Apr 03 2020 at 09:25, on Zulip):

borrowck requires the inferred types, so yeah

eddyb (Apr 03 2020 at 09:26, on Zulip):

when the AST/HIR split was introduced, nothing moved, it's just that post-expansion AST became HIR, roughly

eddyb (Apr 03 2020 at 09:26, on Zulip):

so everything that worked after macros have been expanded and name resolution happened, were now using HIR

Tshepang Lekhonkhobe (Apr 03 2020 at 09:51, on Zulip):

@eddyb if typeck used ast, then hir gets introduced, how does it automatically get to use hir (without changing)

eddyb (Apr 03 2020 at 09:52, on Zulip):

@Tshepang Lekhonkhobe it's just a plain rename at first

eddyb (Apr 03 2020 at 09:52, on Zulip):

like, some parts kept using the ast name, the others used hir instead of ast

eddyb (Apr 03 2020 at 09:54, on Zulip):

but there wasn't anything deeper than a duplication/rename

eddyb (Apr 03 2020 at 09:54, on Zulip):

typeck didn't change how it worked or when it ran

Tshepang Lekhonkhobe (Apr 03 2020 at 09:54, on Zulip):

so, if ast-borrowck was named hir-borrowck, my confusion would not exist

eddyb (Apr 03 2020 at 09:55, on Zulip):

that's because HIR (the rustc IR) is an AST (the concept)

eddyb (Apr 03 2020 at 09:55, on Zulip):

like both rustc_ast and rustc_hir are ASTs

Tshepang Lekhonkhobe (Apr 03 2020 at 09:55, on Zulip):

ah, I see

eddyb (Apr 03 2020 at 09:55, on Zulip):

that's where the name ast_borrowck arises

eddyb (Apr 03 2020 at 09:56, on Zulip):

but yeah hir_borrowck would've been fine

eddyb (Apr 03 2020 at 09:56, on Zulip):

(the main reason for that name was to make it distinct from "MIR borrowck")

Tshepang Lekhonkhobe (Apr 03 2020 at 09:57, on Zulip):

so, in rust terms, mir is lot different to hir, than hir is different to ast

eddyb (Apr 03 2020 at 09:57, on Zulip):

yupp

eddyb (Apr 03 2020 at 09:57, on Zulip):

AST -> HIR is mostly a desugaring step

bjorn3 (Apr 03 2020 at 09:57, on Zulip):

mir is a (control flow) graph, while ast and hir are (abstract syntax) trees

eddyb (Apr 03 2020 at 09:57, on Zulip):

HIR -> MIR builds a control-flow graph, and requires type-checking results

Tshepang Lekhonkhobe (Apr 03 2020 at 10:06, on Zulip):

thanks very

centril (Apr 03 2020 at 12:00, on Zulip):

Also: HAIR is another AST

centril (Apr 03 2020 at 12:01, on Zulip):

which is even more desugared and explicit than HIR, but also typed rather than using side-tables (eww)

eddyb (Apr 03 2020 at 12:11, on Zulip):

one of the items in my colleagues' TODO list is "rename HAIR to THIR" :P

Tshepang Lekhonkhobe (Apr 03 2020 at 12:32, on Zulip):

what does T mean @eddyb

eddyb (Apr 03 2020 at 12:33, on Zulip):

typed

eddyb (Apr 03 2020 at 12:33, on Zulip):

the "A" in the current "HAIR" means "abstract", which is much less useful

bjorn3 (Apr 03 2020 at 12:33, on Zulip):

I thought the T meant too :)

bjorn3 (Apr 03 2020 at 12:34, on Zulip):

As in Too High-level Intermediate Representation.

eddyb (Apr 03 2020 at 12:34, on Zulip):

>_<

Tshepang Lekhonkhobe (Apr 03 2020 at 12:35, on Zulip):

is there a reason we have both hair and hir... do we need both, or can we get away with hir users be hair users

bjorn3 (Apr 03 2020 at 12:36, on Zulip):

I believe hir is lazily converted to hair: hair::ExprRef for example refers to hir::Expr. Also hair is always typed, which means that you can't run typeck on it.

eddyb (Apr 03 2020 at 12:37, on Zulip):

the difference is HAIR further desugars HIR based on typeck results

eddyb (Apr 03 2020 at 12:37, on Zulip):

it's only used to build MIR

centril (Apr 03 2020 at 12:38, on Zulip):

it's only used to build MIR

And for exhaustiveness checking!

eddyb (Apr 03 2020 at 12:39, on Zulip):

right, HAIR patterns are also used in match checking

Tshepang Lekhonkhobe (Apr 03 2020 at 12:39, on Zulip):

wow, this rustc is complex

mark-i-m (Apr 03 2020 at 21:27, on Zulip):

I've always liked the name HAIR. I feel that it is a big missed pun opportunity.

centril (Apr 03 2020 at 21:28, on Zulip):

@mark-i-m consider this renaming as a final hair cut.

Last update: Sep 28 2020 at 15:15UTC