Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upconstruct MIR for all crates up to and including rustdoc #27893
Conversation
rust-highfive
assigned
huonw
Aug 18, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
nikomatsakis
force-pushed the
nikomatsakis:mir
branch
from
b32e41a
to
e2ba889
Aug 18, 2015
steveklabnik
referenced this pull request
Aug 18, 2015
Closed
Tracking issue for MIR (RFC #1211) #27840
steveklabnik
reviewed
Aug 18, 2015
| @@ -479,6 +494,16 @@ pub trait Labeller<'a,N,E> { | |||
| } | |||
| } | |||
|
|
|||
| /// Escape tags in such a way that it is suitable for inclusion in a | |||
| /// Graphviz HTML label. | |||
| pub fn escape_html(s: &str) -> String { | |||
This comment has been minimized.
This comment has been minimized.
steveklabnik
Aug 18, 2015
Member
... this isn't a great escape function, but I guess it's not really untrusted input.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The HIR in this patch is fairly distant from @nrc's HIR: his HIR is very close to the (expanded) syntax, and intended to separate type-checking from the details of expansion/resolution, while the HIR in this patch is more like an elaborated, desugared version of Rust. |
arielb1
reviewed
Aug 18, 2015
| Vec { fields: Vec<ExprRef<H>> }, | ||
| Tuple { fields: Vec<ExprRef<H>> }, | ||
| Adt { adt_def: H::AdtDef, | ||
| variant_index: usize, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Aug 19, 2015
Author
Contributor
why don't you store the variant itself?
Because it was inconvenient to get from the variant to the containing enum and recompute its index, I think. Maybe I should just add those two bits of information to the VariantDef though.
This comment has been minimized.
This comment has been minimized.
Yes, sure. It may be that we evolve @nrc's HIR downwards (I hope we do), but in any case I agree they are not identical, though in my head they play pretty much the same role: a relatively high-level, AST-oriented view on Rust. Anyway I didn't see a suggestion for a better name in your comment. :P |
This comment has been minimized.
This comment has been minimized.
|
MHIR or HMIR? :p EDIT: Perhaps AIR, for Abstract Intermediate Representation. Or HAIR. |
This comment has been minimized.
This comment has been minimized.
|
EIR: Elevated Intermediate Representation... |
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl Her Majesty's Intermediate Representation? /British |
Ms2ger
reviewed
Aug 19, 2015
| pub fn escape_html(s: &str) -> String { | ||
| s | ||
| .replace("\"", """) | ||
| .replace("&", "&") |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl hmm, I do like "HAIR" :) |
oli-obk
reviewed
Aug 20, 2015
| } | ||
|
|
||
| /// Compile `expr`, yielding a compile-time constant. Assumes that | ||
| /// `expr` is a valid compile-time constant! |
This comment has been minimized.
This comment has been minimized.
oli-obk
Aug 20, 2015
Contributor
is the idea that after check_const runs, everything marked as const will get turned into a const-rvalue?
I'd have thought the const-evaluator would be like an llvm-optimization-pass, simply running on the MIR without much more information (global consts + extern consts + const-fn are needed of course).
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Aug 21, 2015
Author
Contributor
@oli-obk I started writing a response and found I had more to say than seemed appropriate for a GitHub comment. See this thread: https://internals.rust-lang.org/t/how-to-handle-constants-in-the-compiler/2543
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
pnkfelix
and unassigned
huonw
Aug 21, 2015
oli-obk
reviewed
Aug 21, 2015
| Use(Lvalue<H>), | ||
|
|
||
| // [x; 32] | ||
| Repeat(Lvalue<H>, Lvalue<H>), |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hmm, yes, I see, I see. Of course I copied this approach from how trans does things, but I agree it's not right. I'm modifying the MIR construction now, but it seems to push me more in favor of introducing an |
nikomatsakis
force-pushed the
nikomatsakis:mir
branch
2 times, most recently
from
fe02dd8
to
107f822
Aug 24, 2015
This comment has been minimized.
This comment has been minimized.
|
OK, I just did a major rebase that folded in all of the WIP comments. In particular I introduced a new concept into the MIR,
It also means we do NOT introduce temporaries for constants in expressions like It seems like these properties are worthy of unit testing, so I may turn some attention to how we can build up a unit test framework. That said, introducing the notion of Also, it should be no problem to purge unnecessary temporaries later, once we have ascertained for sure that there is no mutation to the source of the temporary. As @arielb1 said, I'd rather do that in a separate, dedicated pass (this can also cover the optimizations around pattern matching we now do in trans, I imagine.) This may be worth updating the RFC for as well, since it marks the first departure, but I'll hold off on that. (And the RFC was clearly intended to evolve anyhow.) |
This comment has been minimized.
This comment has been minimized.
|
|
eddyb
reviewed
Aug 25, 2015
|
|
||
| #[derive(Clone, PartialEq)] | ||
| pub enum Operand<H:HIR> { | ||
| Lvalue(Lvalue<H>), |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Of course this won't do the decision-tree optimizations, but the temporary-elimination optimizations we do in trans are basically the reverse of RVO. We translate code like match foo {
Some(foo_inner) => return Some(f(foo_inner));
None => return None
}into MIR (sugared-assmebly-format, rather than graph-format, temporaries are
Standard RVO would replaces temporaries that are written somewhere with the place they are written to:
Match optimization substitutes temporaries with their values
|
This comment has been minimized.
This comment has been minimized.
|
Maybe DVIR (desugared value-level IR) for the "HIR"? |
This comment has been minimized.
This comment has been minimized.
Yes, this is what I meant. |
nikomatsakis
force-pushed the
nikomatsakis:mir
branch
2 times, most recently
from
2cee71c
to
d44473b
Sep 1, 2015
This comment has been minimized.
This comment has been minimized.
|
I rebased and implement support for slice patterns, using the strategy described in https://internals.rust-lang.org/t/slice-patterns-in-the-land-of-mir/2525/. This means that rustdoc builds and (hopefully) that Windows will build. I'm not sure whether this merits a re-r? -- I would say yes but that this code is somewhat preliminary anyway. It required some mild restructuring of the pattern matching because now simplification and other steps can produce temporaries (storing the slice). |
nikomatsakis
added some commits
Aug 18, 2015
nikomatsakis
force-pushed the
nikomatsakis:mir
branch
from
af818c0
to
2f00086
Sep 6, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors try |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Sep 6, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
nikomatsakis
force-pushed the
nikomatsakis:mir
branch
from
2f00086
to
c8a6618
Sep 6, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors r=nrc |
This comment has been minimized.
This comment has been minimized.
|
|
nikomatsakis commentedAug 18, 2015
This PR contains a new crate,
rustc_mir, which implements the MIR as specified in the RFC (more or less). There are no targeted unit tests at the moment, as I didn't decide what kind of infrastructure would be best and didn't take the time to implement it.NB: In packaging up this PR, I realized that MIR construction code is not triggering for methods right now, I think it's only for fixed fns. I'll push a fix for this soon. Hopefully it doesn't stop any crates from building. :)Fixed. Everything still seems to work.However, the MIR construction code (
librustc_mir/build) is intentionally quite distinct from the code which munges the compiler's data structures (librustc_mir/tcx). The interface between the two is theHIRtrait (librustc_mir/hir). To avoid confusion with @nrc's work, perhaps a better name for this trait is warranted, although ultimately this trait will be connected to the HIR, I imagine, so in a way the name is perfect. Anyway, I'm open to suggestions. The initial motivation for this split was to allow for the MIR construction code to be unit-tested. But while I didn't end up writing unit tests (yet), I did find the split made the code immensely easier to think about, since the messiness of our existing system, with its myriad hashtables, punning, and so forth, is confined to one part, which simply transforms to a more fully explicit AST-like form. I tried to separate out the commits somewhat, but since this mostly new code, it mostly winds up coming in one fell swoop in the MIR commit.Quick guide to the MIR crate:
repr.rsdefines the MIR itself; each MIR instance is parameterized by some HIRHbuild/is the MIR construction code, parameterized by a particular HIRhir/is the definition of the HIR interfacetcx/is the impl of the HIR interface for the tcxdump.rsis the minimal compiler pass that invokes the HIROne open question: