-
Notifications
You must be signed in to change notification settings - Fork 234
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
provide statics with hypothetical origins #975
Conversation
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.
Mostly looks good, a couple questions inline.
Sounds right. Loans are created on
Have you checked what Polonius normally does for statics that contain
I'm not sure. What does Polonius do for Note this is separate from the previous point, which is about statics containing refs, like static FOO: i32 = 1;
static BAR: &'static i32 = &FOO; |
a186e9c
to
60be357
Compare
@spernsteiner I've run polonius on the following example: static mut oneshot_fdn: fdnode = fdnode { ctx: &0 };
pub struct fdnode {
pub ctx: &'static u8,
}
unsafe extern "C" fn server_free() {
let x = &oneshot_fdn;
}
fn main() {
unsafe {
server_free();
}
} and it appears:
|
It looks like the MIR for this treats as something like that: _2 = const {alloc1: *mut fdnode}; // scope 0 at test_static.rs:8:14: 8:25
// mir::Constant
// + span: test_static.rs:8:14: 8:25
// + literal: Const { ty: *mut fdnode, val: Value(Scalar(alloc1)) }
_1 = &(*_2); // scope 0 at test_static.rs:8:13: 8:25 and
|
It looks like Accesses of statics (e.g. Since we generally assign regions to raw pointers as well as refs, I think we should treat both the mut and non-mut cases the same: assign a region to the RHS, and leave it unconstrained so it can become For mentions of I think this also simplifies the |
@spernsteiner I haven't addressed the |
… each function argument
…Operand::Constant with any pointer type
…appropriately in field_lty
@spernsteiner would you mind taking another look? |
c2rust-analyze/src/borrowck/mod.rs
Outdated
if let ItemKind::Fn(_, ref generics, _) = item.kind { | ||
for generic in generics.params.iter() { | ||
if matches!(generic.kind, GenericParamKind::Lifetime { .. }) { | ||
func_lifetime_origins.push(maps.origin()) |
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.
There are a bunch of relations that rustc would normally add over these origins - please either emit the relevant facts or add comments pointing out that they're missing:
- My read of the polonius docs is that we should emit
universal_region(origin)
andplaceholder(origin, loan)
(whereloan
is a fresh loan, not connected to anything else) for each of these region parameters and also for'static
(which is treated like a parameter). - There should be either
known_placeholder_subset
orsubset_base
relations matching each outlives constraint'a: 'b
intcx.predicates_of(local_def_id)
. - There should be similar subset relations for the implicit outlives constraints
'static: 'a
for each parameter'a
.
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.
Does this match what you suggest? d6220b7
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.
It seems like there is one remaining known placeholder subset relationship between lifetimes like arg: &'a &'c i32
. I can look into what it would take to add it to this PR or we can save it for another PR
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.
That looks about right to me.
The 'c: 'a
bound that's implied by well-formedness of arg
's type should definitely show up somewhere. I think I've seen bounds like that in the output of either predicates_of
or a related query. Maybe try looking at explicit_predicates_of
, inferred_outlives_of
, and/or predicates_defined_on
.
It would also be fine to just leave a comment about the limitation, especially if you can't find an easy way to get the predicate from rustc.
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.
predicates_defined_on
seems to encapsulate the former two, and predicates_of
is supposed to almost-always be exactly predicates_defined_on
(according to the documentation), but I don't see that any of these options capture the implicit relationship. i'll keep digging
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've created an issue for this: #1002 (comment)
Co-authored-by: spernsteiner <spernsteiner@galois.com>
0cabfc6
to
e195fb3
Compare
Fixes #943 and fixes #776. Assigns origins to static variables, which provides parity in the number of
OriginParams
when comparing equality of LHS and RHS of assignments to local variables (which already had the correct number ofOriginParams
).Questions:
assign_origins
routine for statics adequately cover this?_2 = const {alloc1: *mut fdnode}
the RHS is not issued a loan; is that correct? Polonius appears not to issue any loans here