-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Remove the ty
field from type system Const
s
#125958
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
58feec9
Basic removal of `Ty` from places (boring)
BoxyUwU a9702a6
Add `Ty` to `ConstKind::Value`
BoxyUwU 8d6705c
Fully implement `ConstArgHasType`
BoxyUwU 60a5beb
Add `Ty` to `mir::Const::Ty`
BoxyUwU 432c11f
Remove `Type` from rustdoc `Const`
BoxyUwU a454da3
Misc fixes to cranelift/clippy/miri
BoxyUwU 56092a3
Misc fixes (pattern type lowering, cfi, pretty printing)
BoxyUwU 7fa98d0
ty::Expr reviews
BoxyUwU f74119a
Bless tests and handle tests/crashes
BoxyUwU 2e08267
Fix function-names.rs test
compiler-errors 3a6b606
remove const arg windows debug info tests
BoxyUwU 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -111,12 +111,7 @@ pub trait HirTyLowerer<'tcx> { | |
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>; | ||
|
||
/// Returns the const to use when a const is omitted. | ||
fn ct_infer( | ||
&self, | ||
ty: Ty<'tcx>, | ||
param: Option<&ty::GenericParamDef>, | ||
span: Span, | ||
) -> Const<'tcx>; | ||
fn ct_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx>; | ||
|
||
/// Probe bounds in scope where the bounded type coincides with the given type parameter. | ||
/// | ||
|
@@ -439,15 +434,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
|
||
fn provided_kind( | ||
&mut self, | ||
preceding_args: &[ty::GenericArg<'tcx>], | ||
_preceding_args: &[ty::GenericArg<'tcx>], | ||
param: &ty::GenericParamDef, | ||
arg: &GenericArg<'tcx>, | ||
) -> ty::GenericArg<'tcx> { | ||
let tcx = self.lowerer.tcx(); | ||
|
||
if let Err(incorrect) = self.incorrect_args { | ||
if incorrect.invalid_args.contains(&(param.index as usize)) { | ||
return param.to_error(tcx, preceding_args); | ||
return param.to_error(tcx); | ||
} | ||
} | ||
|
||
|
@@ -487,12 +482,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
ty::Const::from_anon_const(tcx, did).into() | ||
} | ||
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => { | ||
let ty = tcx | ||
.at(self.span) | ||
.type_of(param.def_id) | ||
.no_bound_vars() | ||
.expect("const parameter types cannot be generic"); | ||
self.lowerer.ct_infer(ty, Some(param), inf.span).into() | ||
self.lowerer.ct_infer(Some(param), inf.span).into() | ||
} | ||
(kind, arg) => span_bug!( | ||
self.span, | ||
|
@@ -511,7 +501,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
|
||
if let Err(incorrect) = self.incorrect_args { | ||
if incorrect.invalid_args.contains(&(param.index as usize)) { | ||
return param.to_error(tcx, preceding_args); | ||
return param.to_error(tcx); | ||
} | ||
} | ||
match param.kind { | ||
|
@@ -548,7 +538,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
.no_bound_vars() | ||
.expect("const parameter types cannot be generic"); | ||
if let Err(guar) = ty.error_reported() { | ||
return ty::Const::new_error(tcx, guar, ty).into(); | ||
return ty::Const::new_error(tcx, guar).into(); | ||
} | ||
// FIXME(effects) see if we should special case effect params here | ||
if !infer_args && has_default { | ||
|
@@ -557,10 +547,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
.into() | ||
} else { | ||
if infer_args { | ||
self.lowerer.ct_infer(ty, Some(param), self.span).into() | ||
self.lowerer.ct_infer(Some(param), self.span).into() | ||
} else { | ||
// We've already errored above about the mismatch. | ||
ty::Const::new_misc_error(tcx, ty).into() | ||
ty::Const::new_misc_error(tcx).into() | ||
} | ||
} | ||
} | ||
|
@@ -1908,7 +1898,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
/// | ||
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`] | ||
/// and late-bound ones to [`ty::ConstKind::Bound`]. | ||
pub(crate) fn lower_const_param(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> { | ||
pub(crate) fn lower_const_param(&self, hir_id: HirId) -> Const<'tcx> { | ||
let tcx = self.tcx(); | ||
match tcx.named_bound_var(hir_id) { | ||
Some(rbv::ResolvedArg::EarlyBound(def_id)) => { | ||
|
@@ -1918,12 +1908,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
let generics = tcx.generics_of(item_def_id); | ||
let index = generics.param_def_id_to_index[&def_id]; | ||
let name = tcx.item_name(def_id); | ||
ty::Const::new_param(tcx, ty::ParamConst::new(index, name), param_ty) | ||
ty::Const::new_param(tcx, ty::ParamConst::new(index, name)) | ||
} | ||
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => { | ||
ty::Const::new_bound(tcx, debruijn, ty::BoundVar::from_u32(index), param_ty) | ||
ty::Const::new_bound(tcx, debruijn, ty::BoundVar::from_u32(index)) | ||
} | ||
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar, param_ty), | ||
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar), | ||
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", hir_id), | ||
} | ||
} | ||
|
@@ -2139,7 +2129,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
} | ||
hir::TyKind::Array(ty, length) => { | ||
let length = match length { | ||
hir::ArrayLen::Infer(inf) => self.ct_infer(tcx.types.usize, None, inf.span), | ||
hir::ArrayLen::Infer(inf) => self.ct_infer(None, inf.span), | ||
hir::ArrayLen::Body(constant) => { | ||
ty::Const::from_anon_const(tcx, constant.def_id) | ||
} | ||
|
@@ -2170,17 +2160,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
} | ||
_ => (expr, None), | ||
}; | ||
let c = match &expr.kind { | ||
let (c, c_ty) = match &expr.kind { | ||
hir::ExprKind::Lit(lit) => { | ||
let lit_input = | ||
LitToConstInput { lit: &lit.node, ty, neg: neg.is_some() }; | ||
match tcx.lit_to_const(lit_input) { | ||
let ct = match tcx.lit_to_const(lit_input) { | ||
Ok(c) => c, | ||
Err(LitToConstError::Reported(err)) => { | ||
ty::Const::new_error(tcx, err, ty) | ||
ty::Const::new_error(tcx, err) | ||
} | ||
Err(LitToConstError::TypeError) => todo!(), | ||
} | ||
}; | ||
(ct, ty) | ||
} | ||
|
||
hir::ExprKind::Path(hir::QPath::Resolved( | ||
|
@@ -2198,19 +2189,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
.type_of(def_id) | ||
.no_bound_vars() | ||
.expect("const parameter types cannot be generic"); | ||
self.lower_const_param(expr.hir_id, ty) | ||
let ct = self.lower_const_param(expr.hir_id); | ||
(ct, ty) | ||
} | ||
|
||
_ => { | ||
let err = tcx | ||
.dcx() | ||
.emit_err(crate::errors::NonConstRange { span: expr.span }); | ||
ty::Const::new_error(tcx, err, ty) | ||
(ty::Const::new_error(tcx, err), Ty::new_error(tcx, err)) | ||
} | ||
}; | ||
self.record_ty(expr.hir_id, c.ty(), expr.span); | ||
self.record_ty(expr.hir_id, c_ty, expr.span); | ||
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. 🤔 what is this used for, when do we access the type of constants in the not something we have to look at in this PR |
||
if let Some((id, span)) = neg { | ||
self.record_ty(id, c.ty(), span); | ||
self.record_ty(id, c_ty, span); | ||
} | ||
c | ||
}; | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -143,9 +143,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
// `trait_object_dummy_self`, so check for that. | ||
let references_self = match pred.skip_binder().term.unpack() { | ||
ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()), | ||
ty::TermKind::Const(c) => { | ||
c.ty().walk().any(|arg| arg == dummy_self.into()) | ||
} | ||
// FIXME(associated_const_equality): We should walk the const instead of not doing anything | ||
ty::TermKind::Const(_) => false, | ||
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. |
||
}; | ||
|
||
// If the projection output contains `Self`, force the user to | ||
|
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.