forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#88709 - BoxyUwU:thir-abstract-const, r=lcnr
generic_const_exprs: use thir for abstract consts instead of mir not sure if this is handling some of the weirder `thir::ExprKind` correctly in `recurse_build` (it probably isnt) r? ``@lcnr``
- Loading branch information
Showing
35 changed files
with
351 additions
and
366 deletions.
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//! A subset of a mir body used for const evaluatability checking. | ||
use crate::mir; | ||
use crate::ty::{self, Ty, TyCtxt}; | ||
use rustc_errors::ErrorReported; | ||
|
||
rustc_index::newtype_index! { | ||
/// An index into an `AbstractConst`. | ||
pub struct NodeId { | ||
derive [HashStable] | ||
DEBUG_FORMAT = "n{}", | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] | ||
pub enum CastKind { | ||
/// thir::ExprKind::As | ||
As, | ||
/// thir::ExprKind::Use | ||
Use, | ||
} | ||
|
||
/// A node of an `AbstractConst`. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] | ||
pub enum Node<'tcx> { | ||
Leaf(&'tcx ty::Const<'tcx>), | ||
Binop(mir::BinOp, NodeId, NodeId), | ||
UnaryOp(mir::UnOp, NodeId), | ||
FunctionCall(NodeId, &'tcx [NodeId]), | ||
Cast(CastKind, NodeId, Ty<'tcx>), | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] | ||
pub enum NotConstEvaluatable { | ||
Error(ErrorReported), | ||
MentionsInfer, | ||
MentionsParam, | ||
} | ||
|
||
impl From<ErrorReported> for NotConstEvaluatable { | ||
fn from(e: ErrorReported) -> NotConstEvaluatable { | ||
NotConstEvaluatable::Error(e) | ||
} | ||
} | ||
|
||
TrivialTypeFoldableAndLiftImpls! { | ||
NotConstEvaluatable, | ||
} | ||
|
||
impl<'tcx> TyCtxt<'tcx> { | ||
#[inline] | ||
pub fn thir_abstract_const_opt_const_arg( | ||
self, | ||
def: ty::WithOptConstParam<rustc_hir::def_id::DefId>, | ||
) -> Result<Option<&'tcx [Node<'tcx>]>, ErrorReported> { | ||
if let Some((did, param_did)) = def.as_const_arg() { | ||
self.thir_abstract_const_of_const_arg((did, param_did)) | ||
} else { | ||
self.thir_abstract_const(def.did) | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -11,4 +11,3 @@ crate mod cx; | |
crate mod pattern; | ||
|
||
mod util; | ||
pub mod visit; |
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
Oops, something went wrong.