-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8813: Get some more array lengths! r=lf- a=lf- This is built on #8799 and thus contains its changes. I'll rebase it onto master when that one gets merged. It adds support for r-a understanding the length of: * `let a: [u8; 2] = ...` * `let a = b"aaa"` * `let a = [0u8; 4]` I have added support for getting the values of byte strings, which was not previously there. I am least confident in the correctness of this part and it probably needs some more tests, as we currently have only one test that exercised that part (!). Fixes #2922. Co-authored-by: Jade <software@lfcode.ca>
- Loading branch information
Showing
21 changed files
with
427 additions
and
136 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 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,56 @@ | ||
//! Constant evaluation details | ||
use std::convert::TryInto; | ||
|
||
use hir_def::{ | ||
builtin_type::BuiltinUint, | ||
expr::{Expr, Literal}, | ||
type_ref::ConstScalar, | ||
}; | ||
|
||
use crate::{Const, ConstData, ConstValue, Interner, TyKind}; | ||
|
||
/// Extension trait for [`Const`] | ||
pub trait ConstExt { | ||
/// Is a [`Const`] unknown? | ||
fn is_unknown(&self) -> bool; | ||
} | ||
|
||
impl ConstExt for Const { | ||
fn is_unknown(&self) -> bool { | ||
match self.data(&Interner).value { | ||
// interned Unknown | ||
chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { | ||
interned: ConstScalar::Unknown, | ||
}) => true, | ||
|
||
// interned concrete anything else | ||
chalk_ir::ConstValue::Concrete(..) => false, | ||
|
||
_ => { | ||
log::error!("is_unknown was called on a non-concrete constant value! {:?}", self); | ||
true | ||
} | ||
} | ||
} | ||
} | ||
|
||
// FIXME: support more than just evaluating literals | ||
pub fn eval_usize(expr: &Expr) -> Option<u64> { | ||
match expr { | ||
Expr::Literal(Literal::Uint(v, None)) | ||
| Expr::Literal(Literal::Uint(v, Some(BuiltinUint::Usize))) => (*v).try_into().ok(), | ||
_ => None, | ||
} | ||
} | ||
|
||
/// Interns a possibly-unknown target usize | ||
pub fn usize_const(value: Option<u64>) -> Const { | ||
ConstData { | ||
ty: TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner), | ||
value: ConstValue::Concrete(chalk_ir::ConcreteConst { | ||
interned: value.map(|value| ConstScalar::Usize(value)).unwrap_or(ConstScalar::Unknown), | ||
}), | ||
} | ||
.intern(&Interner) | ||
} |
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
Oops, something went wrong.