allow clippy rule, remove unreachable arms
This commit is contained in:
parent
9f69ea3771
commit
cd276760b1
4 changed files with 36 additions and 34 deletions
|
@ -119,7 +119,7 @@ impl<'ast> From<pest::ConstantDefinition<'ast>> for absy::SymbolDeclarationNode<
|
|||
|
||||
absy::SymbolDeclaration {
|
||||
id,
|
||||
symbol: absy::Symbol::Here(SymbolDefinition::Constant(box ty)),
|
||||
symbol: absy::Symbol::Here(SymbolDefinition::Constant(ty)),
|
||||
}
|
||||
.span(span)
|
||||
}
|
||||
|
|
|
@ -51,10 +51,11 @@ pub struct SymbolDeclaration<'ast> {
|
|||
pub symbol: Symbol<'ast>,
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(PartialEq, Clone)]
|
||||
pub enum SymbolDefinition<'ast> {
|
||||
Struct(StructDefinitionNode<'ast>),
|
||||
Constant(Box<ConstantDefinitionNode<'ast>>),
|
||||
Constant(ConstantDefinitionNode<'ast>),
|
||||
Function(FunctionNode<'ast>),
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@ impl ErrorInner {
|
|||
}
|
||||
|
||||
type TypeMap<'ast> = HashMap<OwnedModuleId, HashMap<UserTypeId, DeclarationType<'ast>>>;
|
||||
type ConstantMap<'ast, T> = HashMap<OwnedModuleId, TypedConstantSymbols<'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)]
|
||||
|
@ -475,7 +476,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
})),
|
||||
}
|
||||
}
|
||||
SymbolDefinition::Constant(box c) => {
|
||||
SymbolDefinition::Constant(c) => {
|
||||
match self.check_constant_definition(declaration.id, c, module_id, &state.types)
|
||||
{
|
||||
Ok(c) => {
|
||||
|
@ -503,7 +504,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
.constants
|
||||
.entry(module_id.to_path_buf())
|
||||
.or_default()
|
||||
.insert(declaration.id, TypedConstantSymbol::Here(c))
|
||||
.insert(declaration.id, c.ty)
|
||||
.is_none());
|
||||
}
|
||||
};
|
||||
|
@ -589,10 +590,6 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
.entry(import.module_id.to_path_buf())
|
||||
.or_default()
|
||||
.get(import.symbol_id)
|
||||
.and_then(|sym| match sym {
|
||||
TypedConstantSymbol::Here(tc) => Some(tc),
|
||||
_ => None,
|
||||
})
|
||||
.cloned();
|
||||
|
||||
match (function_candidates.len(), type_candidate, const_candidate) {
|
||||
|
@ -631,7 +628,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
.or_default()
|
||||
.insert(declaration.id.to_string(), t);
|
||||
}
|
||||
(0, None, Some(c)) => {
|
||||
(0, None, Some(ty)) => {
|
||||
match symbol_unifier.insert_constant(declaration.id) {
|
||||
false => {
|
||||
errors.push(Error {
|
||||
|
@ -646,13 +643,13 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
}
|
||||
true => {
|
||||
constants.insert(declaration.id, TypedConstantSymbol::There(import.module_id, declaration.id));
|
||||
self.insert_into_scope(Variable::with_id_and_type(declaration.id, c.ty.clone()));
|
||||
self.insert_into_scope(Variable::with_id_and_type(declaration.id, ty.clone()));
|
||||
|
||||
state
|
||||
.constants
|
||||
.entry(module_id.to_path_buf())
|
||||
.or_default()
|
||||
.insert(declaration.id, TypedConstantSymbol::Here(c)); // we insert as `Here` to avoid later recursive search
|
||||
.insert(declaration.id, ty);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,37 +17,50 @@ impl<'ast, T: Field> ConstantInliner<'ast, T> {
|
|||
}
|
||||
|
||||
pub fn inline(p: TypedProgram<'ast, T>) -> TypedProgram<'ast, T> {
|
||||
// initialize an inliner over all modules, starting from the main module
|
||||
let mut inliner =
|
||||
ConstantInliner::with_modules_and_location(p.modules.clone(), p.main.clone());
|
||||
|
||||
inliner.fold_program(p)
|
||||
}
|
||||
|
||||
pub fn module(&self) -> &TypedModule<'ast, T> {
|
||||
fn module(&self) -> &TypedModule<'ast, T> {
|
||||
self.modules.get(&self.location).unwrap()
|
||||
}
|
||||
|
||||
pub fn change_location(&mut self, location: OwnedTypedModuleId) -> OwnedTypedModuleId {
|
||||
fn change_location(&mut self, location: OwnedTypedModuleId) -> OwnedTypedModuleId {
|
||||
let prev = self.location.clone();
|
||||
self.location = location;
|
||||
prev
|
||||
}
|
||||
|
||||
pub fn get_constant(&mut self, id: &Identifier) -> Option<TypedConstant<'ast, T>> {
|
||||
fn get_constant(&mut self, id: &Identifier) -> Option<TypedConstant<'ast, T>> {
|
||||
self.modules
|
||||
.get(&self.location)
|
||||
.unwrap()
|
||||
.constants
|
||||
.get(id.clone().try_into().unwrap())
|
||||
.cloned()
|
||||
.and_then(|tc| {
|
||||
let symbol = self.fold_constant_symbol(tc);
|
||||
match symbol {
|
||||
TypedConstantSymbol::Here(tc) => Some(tc),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
})
|
||||
.map(|symbol| self.get_canonical_constant(symbol))
|
||||
}
|
||||
|
||||
fn get_canonical_constant(
|
||||
&mut self,
|
||||
symbol: TypedConstantSymbol<'ast, T>,
|
||||
) -> TypedConstant<'ast, T> {
|
||||
match symbol {
|
||||
TypedConstantSymbol::There(module_id, id) => {
|
||||
let location = self.change_location(module_id);
|
||||
let symbol = self.module().constants.get(id).cloned().unwrap();
|
||||
|
||||
let symbol = self.get_canonical_constant(symbol);
|
||||
let _ = self.change_location(location);
|
||||
symbol
|
||||
}
|
||||
TypedConstantSymbol::Here(tc) => TypedConstant {
|
||||
expression: self.fold_expression(tc.expression),
|
||||
..tc
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,17 +98,8 @@ impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> {
|
|||
&mut self,
|
||||
p: TypedConstantSymbol<'ast, T>,
|
||||
) -> TypedConstantSymbol<'ast, T> {
|
||||
match p {
|
||||
TypedConstantSymbol::There(module_id, id) => {
|
||||
let location = self.change_location(module_id);
|
||||
let symbol = self.module().constants.get(id).cloned().unwrap();
|
||||
|
||||
let symbol = self.fold_constant_symbol(symbol);
|
||||
let _ = self.change_location(location);
|
||||
symbol
|
||||
}
|
||||
_ => fold_constant_symbol(self, p),
|
||||
}
|
||||
let tc = self.get_canonical_constant(p);
|
||||
TypedConstantSymbol::Here(tc)
|
||||
}
|
||||
|
||||
fn fold_field_expression(
|
||||
|
|
Loading…
Reference in a new issue