-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Combine Sub
and Equate
#121462
Merged
Merged
Combine Sub
and Equate
#121462
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3cb3631
Preserve variance on error in generalizer
compiler-errors c87b727
Combine sub and eq
compiler-errors 801dd1d
Remove cause
compiler-errors 61daee6
Get rid of some sub_exp and eq_exp
compiler-errors 04e2262
Remove a_is_expected from combine relations
compiler-errors b153656
Fallout from removing a_is_expected
compiler-errors 5072b65
Rebase fallout from TypeRelating::binders, inline higher_ranked_sub
compiler-errors File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,6 @@ pub struct At<'a, 'tcx> { | |
|
||
pub struct Trace<'a, 'tcx> { | ||
at: At<'a, 'tcx>, | ||
a_is_expected: bool, | ||
trace: TypeTrace<'tcx>, | ||
} | ||
|
||
|
@@ -105,23 +104,6 @@ pub trait ToTrace<'tcx>: Relate<'tcx> + Copy { | |
} | ||
|
||
impl<'a, 'tcx> At<'a, 'tcx> { | ||
/// Makes `a <: b`, where `a` may or may not be expected. | ||
/// | ||
/// See [`At::trace_exp`] and [`Trace::sub`] for a version of | ||
/// this method that only requires `T: Relate<'tcx>` | ||
pub fn sub_exp<T>( | ||
self, | ||
define_opaque_types: DefineOpaqueTypes, | ||
a_is_expected: bool, | ||
a: T, | ||
b: T, | ||
) -> InferResult<'tcx, ()> | ||
where | ||
T: ToTrace<'tcx>, | ||
{ | ||
self.trace_exp(a_is_expected, a, b).sub(define_opaque_types, a, b) | ||
} | ||
|
||
/// Makes `actual <: expected`. For example, if type-checking a | ||
/// call like `foo(x)`, where `foo: fn(i32)`, you might have | ||
/// `sup(i32, x)`, since the "expected" type is the type that | ||
|
@@ -138,7 +120,7 @@ impl<'a, 'tcx> At<'a, 'tcx> { | |
where | ||
T: ToTrace<'tcx>, | ||
{ | ||
self.sub_exp(define_opaque_types, false, actual, expected) | ||
self.trace(expected, actual).sup(define_opaque_types, expected, actual) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sub(actual, expected) -> sup(expected, actual) |
||
} | ||
|
||
/// Makes `expected <: actual`. | ||
|
@@ -154,24 +136,7 @@ impl<'a, 'tcx> At<'a, 'tcx> { | |
where | ||
T: ToTrace<'tcx>, | ||
{ | ||
self.sub_exp(define_opaque_types, true, expected, actual) | ||
} | ||
|
||
/// Makes `expected <: actual`. | ||
/// | ||
/// See [`At::trace_exp`] and [`Trace::eq`] for a version of | ||
/// this method that only requires `T: Relate<'tcx>` | ||
pub fn eq_exp<T>( | ||
self, | ||
define_opaque_types: DefineOpaqueTypes, | ||
a_is_expected: bool, | ||
a: T, | ||
b: T, | ||
) -> InferResult<'tcx, ()> | ||
where | ||
T: ToTrace<'tcx>, | ||
{ | ||
self.trace_exp(a_is_expected, a, b).eq(define_opaque_types, a, b) | ||
self.trace(expected, actual).sub(define_opaque_types, expected, actual) | ||
} | ||
|
||
/// Makes `expected <: actual`. | ||
|
@@ -260,48 +225,50 @@ impl<'a, 'tcx> At<'a, 'tcx> { | |
where | ||
T: ToTrace<'tcx>, | ||
{ | ||
self.trace_exp(true, expected, actual) | ||
let trace = ToTrace::to_trace(self.cause, true, expected, actual); | ||
Trace { at: self, trace } | ||
} | ||
} | ||
|
||
/// Like `trace`, but the expected value is determined by the | ||
/// boolean argument (if true, then the first argument `a` is the | ||
/// "expected" value). | ||
pub fn trace_exp<T>(self, a_is_expected: bool, a: T, b: T) -> Trace<'a, 'tcx> | ||
impl<'a, 'tcx> Trace<'a, 'tcx> { | ||
/// Makes `a <: b`. | ||
#[instrument(skip(self), level = "debug")] | ||
pub fn sub<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, ()> | ||
where | ||
T: ToTrace<'tcx>, | ||
T: Relate<'tcx>, | ||
{ | ||
let trace = ToTrace::to_trace(self.cause, a_is_expected, a, b); | ||
Trace { at: self, trace, a_is_expected } | ||
let Trace { at, trace } = self; | ||
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types); | ||
fields | ||
.sub() | ||
.relate(a, b) | ||
.map(move |_| InferOk { value: (), obligations: fields.obligations }) | ||
} | ||
} | ||
|
||
impl<'a, 'tcx> Trace<'a, 'tcx> { | ||
/// Makes `a <: b` where `a` may or may not be expected (if | ||
/// `a_is_expected` is true, then `a` is expected). | ||
/// Makes `a :> b`. | ||
#[instrument(skip(self), level = "debug")] | ||
pub fn sub<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, ()> | ||
pub fn sup<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, ()> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes |
||
where | ||
T: Relate<'tcx>, | ||
{ | ||
let Trace { at, trace, a_is_expected } = self; | ||
let Trace { at, trace } = self; | ||
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types); | ||
fields | ||
.sub(a_is_expected) | ||
.sup() | ||
.relate(a, b) | ||
.map(move |_| InferOk { value: (), obligations: fields.obligations }) | ||
} | ||
|
||
/// Makes `a == b`; the expectation is set by the call to | ||
/// `trace()`. | ||
/// Makes `a == b`. | ||
#[instrument(skip(self), level = "debug")] | ||
pub fn eq<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, ()> | ||
where | ||
T: Relate<'tcx>, | ||
{ | ||
let Trace { at, trace, a_is_expected } = self; | ||
let Trace { at, trace } = self; | ||
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types); | ||
fields | ||
.equate(StructurallyRelateAliases::No, a_is_expected) | ||
.equate(StructurallyRelateAliases::No) | ||
.relate(a, b) | ||
.map(move |_| InferOk { value: (), obligations: fields.obligations }) | ||
} | ||
|
@@ -313,11 +280,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> { | |
where | ||
T: Relate<'tcx>, | ||
{ | ||
let Trace { at, trace, a_is_expected } = self; | ||
let Trace { at, trace } = self; | ||
debug_assert!(at.infcx.next_trait_solver()); | ||
let mut fields = at.infcx.combine_fields(trace, at.param_env, DefineOpaqueTypes::No); | ||
fields | ||
.equate(StructurallyRelateAliases::Yes, a_is_expected) | ||
.equate(StructurallyRelateAliases::Yes) | ||
.relate(a, b) | ||
.map(move |_| InferOk { value: (), obligations: fields.obligations }) | ||
} | ||
|
@@ -327,10 +294,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> { | |
where | ||
T: Relate<'tcx>, | ||
{ | ||
let Trace { at, trace, a_is_expected } = self; | ||
let Trace { at, trace } = self; | ||
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types); | ||
fields | ||
.lub(a_is_expected) | ||
.lub() | ||
.relate(a, b) | ||
.map(move |t| InferOk { value: t, obligations: fields.obligations }) | ||
} | ||
|
@@ -340,10 +307,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> { | |
where | ||
T: Relate<'tcx>, | ||
{ | ||
let Trace { at, trace, a_is_expected } = self; | ||
let Trace { at, trace } = self; | ||
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types); | ||
fields | ||
.glb(a_is_expected) | ||
.glb() | ||
.relate(a, b) | ||
.map(move |t| InferOk { value: t, obligations: fields.obligations }) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Always true