-
Notifications
You must be signed in to change notification settings - Fork 263
(c2rust-analyze
) Handle inline const
refs, including string literals
#886
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
Conversation
f0dacf6
to
4f1d32f
Compare
c2rust-analyze
) Handle local const
refs, including string literalsc2rust-analyze
) Handle inline const
refs, including string literals
I'm not sure if/how this PR should add exact |
@spernsteiner, does this look like it's on the right track? |
I think the best approach for this is to assign |
4f1d32f
to
009c65b
Compare
If I do it this way, would it make more sense to keep |
b6de80d
to
01708f4
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.
Code looks good to me, aside from that final actual/expected permission check discussed above.
@kkysen why not go about it this way, i.e. why is |
I was going to change it back to using |
I think it would be cleaner to keep the |
There's not really a way to tell an |
@spernsteiner, the post-typeck check is erroring, saying the permissions have expanded from |
@spernsteiner, also, do you think any |
ec14e80
to
f19806e
Compare
I agree it would be a little cleaner to use
It's harmless, since
The new test that's currently on this branch and the assertions seem good enough to me. |
05409f6
to
2ce2303
Compare
…row done at which point things crash.
… (local) vs. outline (global) versions.
… `AnalysisCtxt::const_tys: HashMap<ConstantKind, LTy>`.
…:Ref`, as non-refs work fine on their own.
…}` to clarify it's for const refs.
…m `PermissionSet::for_const_ref` (to be used directly later).
…stantKind, LTy> => locs: Vec<Location>` that indexes into `rvalue_tys`, which actually stores the `LTy`s.
…l Iterator<Item = LTy>`.
ada0fc1
to
89fde1b
Compare
…ed to add `PhantomLifetime` to get the lifetimes to work).
89fde1b
to
f14050b
Compare
I moved the @spernsteiner, @aneksteind, does this look good now?
I now unset |
@@ -465,6 +465,10 @@ pub fn visit<'tcx>( | |||
equiv_constraints: Vec::new(), | |||
}; | |||
|
|||
for (ptr, perms) in acx.const_ref_perms() { | |||
tc.constraints.add_all_perms(ptr, perms); |
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.
why not add the constraints as you see consts in visit_rvalue
?
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.
I'm not sure why PhantomLifetime
is necessary. Without knowing for sure it seems like an unnecessary complication. I also think the vector of locations for const refs is similarly unnecessary in that the permissions can be checked in another visit of the body after the permissions have been propagated (maybe in the borrowck
phase or somewhere in between) in combination with adding constraints during the dataflow
visitation.
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.
Despite my comments, however, I think this looks good enough. Insofar as the points made above are valid, consider reducing the complexity slightly.
It was needed due to how lifetimes and |
Do you mean re-iterating through |
I believe re-iterating whether through another visitor or a for-loop is better than adding an extra attribute to the context because it doesn't have an invariant of location being present in the index operations and it wouldn't be keeping extra state. I think the check could happen in |
What do you mean by this? That |
5c1f112
to
012c46f
Compare
…rror on global const refs.
bfde22e
to
6a06083
Compare
Fixes #837.
This only handles
const
refs that are inline and thus local to a function, as determined by beingConstantKind::Val
. Thus, this handles string literals like""
(inline_str
) andb""
(inline_bstr
), which is the main thing we're trying to support.This PR also adds tests for other similar string usages, though they're not handled and turned off for now. The outline cases, where the
const
ref/string literal is used through a named constant, aren't handled, as they are globally accessible and that makes them more complex. Since supporting them isn't necessary for string literals, which is the main usage inlighttpd-rust
.