-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
analyze: new implementation of MIR-to-HIR rewrite lifting #934
Conversation
02553d4
to
b2de7cc
Compare
b2de7cc
to
403d1a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could d875e31 be split into a separate PR? It seems mostly separate and simpler than the rest of the PR.
dbb30b8
to
b3c59ae
Compare
Co-authored-by: Khyber Sen <kkysen@gmail.com>
Co-authored-by: Khyber Sen <kkysen@gmail.com>
Co-authored-by: David Anekstein <da@immunant.com>
c91d13e
to
2100f0f
Compare
I merged #934 (this one) into #839 and tested it. If rebase #934 on |
…tring literals in `string_casts.rs` and `lighttpd-minimal`.
…iled string literals in `string_casts.rs` and `lighttpd-minimal`.
This replaces
rewrite::expr::hir_op
with three new modules:rewrite::expr::unlower
: Builds the "unlowering map", which maps a MIR "precise location" (aLocation
plus aVec<SubLoc>
path) to information about the HIR that was lowered to produce that piece of the MIR. Specifically, it records theHirId
of the HIRExpr
that was lowered along with a description of how the MIR relates to the HIR. For example:For example:
For
f
, the unlowering map annotates the MIR as follows:The statement
_2 = _1
is associated with the expressiona
; the statement as a whole is storing the result of evaluatinga
into a MIR local, and the statement's rvalue_1
represents the expressiona
itself. Similarly,_0 = Add(move _2, const 1)
stores the result ofa + 1
into a local. If needed, we could extend theunlower
pass to also record thatmove _2
(a.k.a.bb0[2]
[Rvalue, RvalueOperand(0)]
) is lowered from theExpr
a
.On
g
, the unlowering map includes the following (among other entries):The call terminator
_4 = f(move _5)
computesf(y)
and stores the result into a local; its rvalue isf(y)
itself, and the first argument of the rvalue isy
.rewrite::expr::distribute
: Given the MIR rewrites produced bymir_op
and the unlowering map fromunlower
, this module distributes MIR rewrites to HIR nodes (identified by theirHirId
s). This step also checks for ambiguous case, such as multiple rewrites from different MIR locations being mapped to the same HIR node, where it's unclear in which order to apply the rewrites, and also detects MIR rewrites that couldn't be mapped to any HIR node.Using the example from above:
A MIR rewrite on
bb0[5]
[Rvalue, CallArg(0)]
would be attached to the MIRExpr
y
, and a rewrite onbb0[5]
[Rvalue
] would be attached tof(y)
.A MIR rewrite on
bb0[5]
[]
(i.e. on the call terminator itself) wouldresult in an error, since there is no good place in the HIR to attach such a
rewrite.
rewrite::expr::convert
: Converts theMirRewrite
s for each HIRExpr
intoSpan
-basedrewrite::Rewrite
s. These are returned as the final result ofexpr::gen_expr_rewrites
and are later applied to the input source code usingrewrite::apply
.Overall, this branch simplifies the handling of
SubLoc
s;distribute
treatsVec<SubLoc>
paths as mostly opaque (it expects each MIR rewrite'ssub_loc
field to exactly match an entry in the unlowering map), andconvert
doesn't deal withSubLoc
s at all. More preciseSubLoc
handling, which will be needed for some tricky pointer-to-pointer cases, goes in theunlower
module, whose sole purpose is establishing the mapping betweenSubLoc
s and HIR. Andunlower
makes the mapping between MIR and HIR explicit (unlikehir_op
, where it was computed implicitly while building rewrites), so it can be inspected for easier debugging.All test cases produce the same rewrites as before this branch, except for one place in
lighttpd-minimal
, where we now place aCell::from_mut
cast in a more appropriate location.