-
Notifications
You must be signed in to change notification settings - Fork 13.3k
make MIR type checker handle a number of other cases #46582
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
make MIR type checker handle a number of other cases #46582
Conversation
☔ The latest upstream changes (presumably #46640) made this pull request unmergeable. Please resolve the merge conflicts. |
2a0d380
to
3cf58dc
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.
see comments. Nice PR otherwise.
src/librustc/ty/context.rs
Outdated
@@ -1746,6 +1746,27 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |||
})) | |||
} | |||
|
|||
/// Create an unsafe fn ty based on a safe fn ty. |
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.
bad comment (talks about "unsafe fn ty" but takes a closure signature).
result.push_str("}"); | ||
|
||
result | ||
inferred_values.region_value_str(r) | ||
} | ||
|
||
/// Indicates that the region variable `v` is live at the point `point`. |
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 would prefer more documentation about the sense of the boolean - e.g. "returns true if the region had changed"
@@ -493,7 +493,27 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { | |||
substs.substs |
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.
A comment describing what this function and defining_ty
do would be welcome
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.
Also, for the comment for TyClosure
: weirdly enough, closure substs don't contain any extra regions, so identity_substs.regions().count()
should be the same as substs.substs.regions().count()
.
// types. What is the best way to handle this? Should we | ||
// be checking something other than the type of the def-id | ||
// to figure out what to do (e.g. the def-key?). | ||
ty::TyUint(..) => { |
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.
How does this code work with constants that don't have type uint? Doesn't it get called for them? Associated constants can have region parameters.
We might want to add the free region information to the MIR or to a query on the def id (computed by typeck::collect).
But sure, constants should have no inputs and 1 output.
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 ICEs. I have later patches that do better.
@@ -171,7 +174,42 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { | |||
); | |||
|
|||
let expected_ty = match constant.literal { | |||
Literal::Value { value } => value.ty, | |||
Literal::Value { value } => { | |||
if let ConstVal::Function(def_id, ..) = value.val { |
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.
Yeah this is really the wrong way to go around doing things - we should be having the region relations from the unevaluated constant type, especially if it is an associated constant. value.val
is already "too cooked".
|
||
let ty_fn_ptr_from = tcx.mk_fn_ptr(fn_sig); | ||
|
||
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.at_self()) { |
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 think typeck allows some sort of (e.g. higher-ranked) subtyping here, so you'll need to allow it too.
e.g.
// this sig contains a binder
fn foo<'a>(_x: &'a ()) {}
fn bar<'b>() {
foo as fn(&'b ()); // ... but this doesn't
}
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.
Hmm, that code type-checks. Perhaps because I haven't addressed previous comment yet.
// During NLL region analysis, this will get renumbered to `typeof(foo::<'?0>)` | ||
// where `'?0` is a new region variable. | ||
// | ||
// (Note that if `'a` on `foo` were early-bound, the type would be |
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.
... but 'a is early-bound. Did you mean late-bound?
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 did mean late-bound -- if it were late-bound, it wouldn't be part of the type of foo
OK @arielb1 pushed some comments to address those. |
Otherwise, `run-pass/typeck-fn-to-unsafe-fn-ptr.rs` fails the MIR type checker.
b192e0a
to
2d853aa
Compare
rebased, fixed a few minor things relating to changes in the underlying borrowck leading to slightly different errors, but I kept the separate commits in place |
Error message needs fixing:
|
These tests had FIXMEs for errors that were not previously being reported.
Converting a `RegionElementIndex` to a `Location` is O(n) though could trivially be O(log n), but we don't do it that much anyhow -- just on error and debugging.
Plus an extra assertion.
2d853aa
to
237dd41
Compare
@arielb1 pushed an update to that error msg...let's see what travis thinks |
@bors r+ |
📌 Commit 237dd41 has been approved by |
🌲 The tree is currently closed for pull requests below priority 2, this pull request will be tested once the tree is reopened |
…ielb1 make MIR type checker handle a number of other cases The existing type checker was primarily used to verify types, but was skipping over a number of details. For example, it was not checking that the predicates on functions were satisfied and so forth. This meant that the NLL region checker was not getting a lot of the constraints it needed. This PR closes those gaps. It also includes a bit of refactoring for the way that we store region values, encapsulating the bit matrix over into its own module and improving the data structures in use. This is mostly work by @spastorino being ported over from nll-master. r? @arielb1 or @pnkfelix
☀️ Test successful - status-appveyor, status-travis |
The existing type checker was primarily used to verify types, but was skipping over a number of details. For example, it was not checking that the predicates on functions were satisfied and so forth. This meant that the NLL region checker was not getting a lot of the constraints it needed. This PR closes those gaps. It also includes a bit of refactoring for the way that we store region values, encapsulating the bit matrix over into its own module and improving the data structures in use.
This is mostly work by @spastorino being ported over from nll-master.
r? @arielb1 or @pnkfelix