rename, clippy
This commit is contained in:
parent
46cc73d735
commit
212d06ec76
4 changed files with 33 additions and 25 deletions
|
@ -55,7 +55,8 @@ impl ErrorInner {
|
|||
}
|
||||
|
||||
type TypeMap<'ast> = HashMap<OwnedModuleId, HashMap<UserTypeId, DeclarationType<'ast>>>;
|
||||
type ConstantMap<'ast, T> = HashMap<OwnedModuleId, HashMap<&'ast str, Type<'ast, T>>>;
|
||||
type ConstantMap<'ast, T> =
|
||||
HashMap<OwnedModuleId, HashMap<ConstantIdentifier<'ast>, Type<'ast, T>>>;
|
||||
|
||||
/// The global state of the program during semantic checks
|
||||
#[derive(Debug)]
|
||||
|
@ -349,7 +350,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
|
||||
fn check_constant_definition(
|
||||
&mut self,
|
||||
id: &'ast str,
|
||||
id: ConstantIdentifier<'ast>,
|
||||
c: ConstantDefinitionNode<'ast>,
|
||||
module_id: &ModuleId,
|
||||
state: &State<'ast, T>,
|
||||
|
@ -445,7 +446,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
module_id: &ModuleId,
|
||||
state: &mut State<'ast, T>,
|
||||
functions: &mut HashMap<DeclarationFunctionKey<'ast>, TypedFunctionSymbol<'ast, T>>,
|
||||
constants: &mut HashMap<ConstantIdentifier<'ast>, TypedConstantSymbol<'ast, T>>,
|
||||
constants: &mut HashMap<CanonicalConstantIdentifier<'ast>, TypedConstantSymbol<'ast, T>>,
|
||||
symbol_unifier: &mut SymbolUnifier<'ast>,
|
||||
) -> Result<(), Vec<Error>> {
|
||||
let mut errors: Vec<Error> = vec![];
|
||||
|
@ -506,7 +507,10 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
),
|
||||
true => {
|
||||
constants.insert(
|
||||
ConstantIdentifier::new(declaration.id, module_id.into()),
|
||||
CanonicalConstantIdentifier::new(
|
||||
declaration.id,
|
||||
module_id.into(),
|
||||
),
|
||||
TypedConstantSymbol::Here(c.clone()),
|
||||
);
|
||||
self.insert_into_scope(Variable::with_id_and_type(
|
||||
|
@ -656,11 +660,11 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
}});
|
||||
}
|
||||
true => {
|
||||
let imported_id = ConstantIdentifier::new(import.symbol_id.into(), import.module_id);
|
||||
let id = ConstantIdentifier::new(declaration.id.clone(), module_id.into());
|
||||
let imported_id = CanonicalConstantIdentifier::new(import.symbol_id, import.module_id);
|
||||
let id = CanonicalConstantIdentifier::new(declaration.id, module_id.into());
|
||||
|
||||
constants.insert(id.clone(), TypedConstantSymbol::There(imported_id));
|
||||
self.insert_into_scope(Variable::with_id_and_type(declaration.id.clone(), ty.clone()));
|
||||
self.insert_into_scope(Variable::with_id_and_type(declaration.id, ty.clone()));
|
||||
|
||||
state
|
||||
.constants
|
||||
|
@ -1144,7 +1148,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
match (constants_map.get(name), generics_map.get(&name)) {
|
||||
(Some(ty), None) => {
|
||||
match ty {
|
||||
Type::Uint(UBitwidth::B32) => Ok(DeclarationConstant::Identifier(name)),
|
||||
Type::Uint(UBitwidth::B32) => Ok(DeclarationConstant::Constant(name)),
|
||||
_ => Err(ErrorInner {
|
||||
pos: Some(pos),
|
||||
message: format!(
|
||||
|
|
|
@ -135,7 +135,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> {
|
|||
println!("location {}", self.location.display());
|
||||
|
||||
match c {
|
||||
DeclarationConstant::Identifier(id) => DeclarationConstant::Concrete(
|
||||
DeclarationConstant::Constant(id) => DeclarationConstant::Concrete(
|
||||
match self
|
||||
.constants
|
||||
.get(&self.location)
|
||||
|
|
|
@ -19,9 +19,10 @@ mod variable;
|
|||
pub use self::identifier::CoreIdentifier;
|
||||
pub use self::parameter::{DeclarationParameter, GParameter};
|
||||
pub use self::types::{
|
||||
ConcreteFunctionKey, ConcreteSignature, ConcreteType, ConstantIdentifier,
|
||||
DeclarationFunctionKey, DeclarationSignature, DeclarationType, GArrayType, GStructType, GType,
|
||||
GenericIdentifier, IntoTypes, Signature, StructType, Type, Types, UBitwidth,
|
||||
CanonicalConstantIdentifier, ConcreteFunctionKey, ConcreteSignature, ConcreteType,
|
||||
ConstantIdentifier, DeclarationFunctionKey, DeclarationSignature, DeclarationType, GArrayType,
|
||||
GStructType, GType, GenericIdentifier, IntoTypes, Signature, StructType, Type, Types,
|
||||
UBitwidth,
|
||||
};
|
||||
use crate::typed_absy::types::ConcreteGenericsAssignment;
|
||||
|
||||
|
@ -65,12 +66,12 @@ pub type TypedFunctionSymbols<'ast, T> =
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum TypedConstantSymbol<'ast, T> {
|
||||
Here(TypedConstant<'ast, T>),
|
||||
There(ConstantIdentifier<'ast>),
|
||||
There(CanonicalConstantIdentifier<'ast>),
|
||||
}
|
||||
|
||||
/// A collection of `TypedConstantSymbol`s
|
||||
pub type TypedConstantSymbols<'ast, T> =
|
||||
HashMap<ConstantIdentifier<'ast>, TypedConstantSymbol<'ast, T>>;
|
||||
HashMap<CanonicalConstantIdentifier<'ast>, TypedConstantSymbol<'ast, T>>;
|
||||
|
||||
/// A typed program as a collection of modules, one of them being the main
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
|
|
|
@ -101,15 +101,17 @@ impl<'ast> fmt::Display for GenericIdentifier<'ast> {
|
|||
#[derive(Debug)]
|
||||
pub struct SpecializationError;
|
||||
|
||||
pub type ConstantIdentifier<'ast> = &'ast str;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
|
||||
pub struct ConstantIdentifier<'ast> {
|
||||
pub struct CanonicalConstantIdentifier<'ast> {
|
||||
pub module: OwnedTypedModuleId,
|
||||
pub id: &'ast str,
|
||||
pub id: ConstantIdentifier<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> ConstantIdentifier<'ast> {
|
||||
pub fn new(id: &'ast str, module: OwnedTypedModuleId) -> Self {
|
||||
ConstantIdentifier { id, module }
|
||||
impl<'ast> CanonicalConstantIdentifier<'ast> {
|
||||
pub fn new(id: ConstantIdentifier<'ast>, module: OwnedTypedModuleId) -> Self {
|
||||
CanonicalConstantIdentifier { module, id }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +119,7 @@ impl<'ast> ConstantIdentifier<'ast> {
|
|||
pub enum DeclarationConstant<'ast> {
|
||||
Generic(GenericIdentifier<'ast>),
|
||||
Concrete(u32),
|
||||
Identifier(&'ast str),
|
||||
Constant(ConstantIdentifier<'ast>),
|
||||
}
|
||||
|
||||
impl<'ast> From<u32> for DeclarationConstant<'ast> {
|
||||
|
@ -143,7 +145,7 @@ impl<'ast> fmt::Display for DeclarationConstant<'ast> {
|
|||
match self {
|
||||
DeclarationConstant::Generic(i) => write!(f, "{}", i),
|
||||
DeclarationConstant::Concrete(v) => write!(f, "{}", v),
|
||||
DeclarationConstant::Identifier(v) => write!(f, "{}", v),
|
||||
DeclarationConstant::Constant(v) => write!(f, "{}", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +165,9 @@ impl<'ast, T> From<DeclarationConstant<'ast>> for UExpression<'ast, T> {
|
|||
DeclarationConstant::Concrete(v) => {
|
||||
UExpressionInner::Value(v as u128).annotate(UBitwidth::B32)
|
||||
}
|
||||
DeclarationConstant::Identifier(v) => UExpressionInner::Identifier(Identifier::from(v))
|
||||
.annotate(UBitwidth::from(UBitwidth::B32)),
|
||||
DeclarationConstant::Constant(v) => {
|
||||
UExpressionInner::Identifier(Identifier::from(v)).annotate(UBitwidth::B32)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -991,7 +994,7 @@ pub mod signature {
|
|||
DeclarationConstant::Concrete(s0) => s1 == *s0 as usize,
|
||||
// in the case of a constant, we do not know the value yet, so we optimistically assume it's correct
|
||||
// if it does not match, it will be caught during inlining
|
||||
DeclarationConstant::Identifier(..) => true,
|
||||
DeclarationConstant::Constant(..) => true,
|
||||
}
|
||||
}
|
||||
(DeclarationType::FieldElement, GType::FieldElement)
|
||||
|
@ -1017,7 +1020,7 @@ pub mod signature {
|
|||
let size = match t0.size {
|
||||
DeclarationConstant::Generic(s) => constants.0.get(&s).cloned().ok_or(s),
|
||||
DeclarationConstant::Concrete(s) => Ok(s.into()),
|
||||
DeclarationConstant::Identifier(..) => {
|
||||
DeclarationConstant::Constant(..) => {
|
||||
unreachable!("identifiers should have been removed in constant inlining")
|
||||
}
|
||||
}?;
|
||||
|
|
Loading…
Reference in a new issue