From fe06b2806f6cfd8c3aa14bf03d430055a82a31b5 Mon Sep 17 00:00:00 2001 From: David Mak Date: Thu, 3 Oct 2024 12:37:56 +0800 Subject: [PATCH] [meta] Reorganize order of use declarations Use declarations are now grouped into 4 groups: - Declarations from the standard library - Declarations from external crates - Declarations from other crates in this project - Declarations from within this module Furthermore, all use declarations are grouped together to enhance readability. super::super is also replaced by an equivalent crate:: declaration. --- nac3artiq/src/codegen.rs | 47 ++++++------ nac3artiq/src/lib.rs | 71 ++++++++++--------- nac3artiq/src/symbol_resolver.rs | 43 +++++------ nac3artiq/src/timeline.rs | 11 +-- nac3core/build.rs | 3 +- nac3core/src/codegen/builtin_fns.rs | 39 ++++++---- nac3core/src/codegen/classes.rs | 15 ++-- nac3core/src/codegen/concrete_type.rs | 10 +-- nac3core/src/codegen/expr.rs | 34 +++++---- nac3core/src/codegen/extern_fns.rs | 6 +- nac3core/src/codegen/generator.rs | 14 ++-- nac3core/src/codegen/irrt/mod.rs | 25 +++---- nac3core/src/codegen/llvm_intrinsics.rs | 16 +++-- nac3core/src/codegen/mod.rs | 31 ++++---- nac3core/src/codegen/numpy.rs | 18 +++-- nac3core/src/codegen/stmt.rs | 24 ++++--- nac3core/src/codegen/test.rs | 31 ++++---- nac3core/src/symbol_resolver.rs | 20 +++--- nac3core/src/toplevel/builtins.rs | 7 +- nac3core/src/toplevel/composer.rs | 6 +- nac3core/src/toplevel/helper.rs | 13 ++-- nac3core/src/toplevel/mod.rs | 28 ++++---- nac3core/src/toplevel/numpy.rs | 3 +- nac3core/src/toplevel/test.rs | 23 +++--- nac3core/src/toplevel/type_annotation.rs | 14 ++-- nac3core/src/typecheck/function_check.rs | 11 +-- nac3core/src/typecheck/magic_methods.rs | 28 ++++---- nac3core/src/typecheck/type_error.rs | 10 +-- nac3core/src/typecheck/type_inferencer/mod.rs | 32 +++++---- .../src/typecheck/type_inferencer/test.rs | 18 ++--- nac3core/src/typecheck/typedef/mod.rs | 37 ++++++---- nac3core/src/typecheck/typedef/test.rs | 8 ++- nac3ld/src/lib.rs | 9 ++- nac3parser/src/config_comment_helper.rs | 10 +-- nac3parser/src/error.rs | 9 ++- nac3parser/src/fstring.rs | 13 ++-- nac3parser/src/function.rs | 9 ++- nac3parser/src/lexer.rs | 14 ++-- nac3parser/src/parser.rs | 12 ++-- nac3parser/src/token.rs | 3 +- nac3standalone/src/basic_symbol_resolver.rs | 12 ++-- nac3standalone/src/main.rs | 30 ++++---- 42 files changed, 454 insertions(+), 363 deletions(-) diff --git a/nac3artiq/src/codegen.rs b/nac3artiq/src/codegen.rs index 6ce9c11b..413391cf 100644 --- a/nac3artiq/src/codegen.rs +++ b/nac3artiq/src/codegen.rs @@ -1,3 +1,17 @@ +use std::{ + collections::{hash_map::DefaultHasher, HashMap}, + hash::{Hash, Hasher}, + iter::once, + mem, + sync::Arc, +}; + +use itertools::Itertools; +use pyo3::{ + types::{PyDict, PyList}, + PyObject, PyResult, Python, +}; + use nac3core::{ codegen::{ classes::{ @@ -10,38 +24,21 @@ use nac3core::{ stmt::{gen_block, gen_for_callback_incrementing, gen_if_callback, gen_with}, CodeGenContext, CodeGenerator, }, + inkwell::{ + context::Context, + module::Linkage, + types::{BasicType, IntType}, + values::{BasicValueEnum, IntValue, PointerValue, StructValue}, + AddressSpace, IntPredicate, OptimizationLevel, + }, + nac3parser::ast::{Expr, ExprKind, Located, Stmt, StmtKind, StrRef}, symbol_resolver::ValueEnum, toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys, DefinitionId, GenCall}, typecheck::typedef::{iter_type_vars, FunSignature, FuncArg, Type, TypeEnum, VarMap}, }; -use nac3core::nac3parser::ast::{Expr, ExprKind, Located, Stmt, StmtKind, StrRef}; - -use nac3core::inkwell::{ - context::Context, - module::Linkage, - types::{BasicType, IntType}, - values::{BasicValueEnum, PointerValue, StructValue}, - AddressSpace, IntPredicate, OptimizationLevel, -}; - -use pyo3::{ - types::{PyDict, PyList}, - PyObject, PyResult, Python, -}; - use crate::{symbol_resolver::InnerResolver, timeline::TimeFns}; -use itertools::Itertools; -use nac3core::inkwell::values::IntValue; -use std::{ - collections::{hash_map::DefaultHasher, HashMap}, - hash::{Hash, Hasher}, - iter::once, - mem, - sync::Arc, -}; - /// The parallelism mode within a block. #[derive(Copy, Clone, Eq, PartialEq)] enum ParallelMode { diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index c9009ea3..c5d66a7c 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -16,48 +16,53 @@ clippy::wildcard_imports )] -use std::collections::{HashMap, HashSet}; -use std::fs; -use std::io::Write; -use std::process::Command; -use std::rc::Rc; -use std::sync::Arc; +use std::{ + collections::{HashMap, HashSet}, + fs, + io::Write, + process::Command, + rc::Rc, + sync::Arc, +}; use itertools::Itertools; -use nac3core::codegen::{gen_func_impl, CodeGenLLVMOptions, CodeGenTargetMachineOptions}; -use nac3core::inkwell::{ - context::Context, - memory_buffer::MemoryBuffer, - module::{Linkage, Module}, - passes::PassBuilderOptions, - support::is_multithreaded, - targets::*, - OptimizationLevel, -}; -use nac3core::toplevel::builtins::get_exn_constructor; -use nac3core::typecheck::typedef::{into_var_map, TypeEnum, Unifier, VarMap}; -use nac3core::nac3parser::{ - ast::{Constant, ExprKind, Located, Stmt, StmtKind, StrRef}, - parser::parse_program, -}; -use pyo3::create_exception; -use pyo3::prelude::*; -use pyo3::{exceptions, types::PyBytes, types::PyDict, types::PySet}; - use parking_lot::{Mutex, RwLock}; +use pyo3::{ + create_exception, exceptions, + prelude::*, + types::{PyBytes, PyDict, PySet}, +}; +use tempfile::{self, TempDir}; use nac3core::{ - codegen::irrt::load_irrt, - codegen::{concrete_type::ConcreteTypeStore, CodeGenTask, WithCall, WorkerRegistry}, + codegen::{ + concrete_type::ConcreteTypeStore, gen_func_impl, irrt::load_irrt, CodeGenLLVMOptions, + CodeGenTargetMachineOptions, CodeGenTask, WithCall, WorkerRegistry, + }, + inkwell::{ + context::Context, + memory_buffer::MemoryBuffer, + module::{Linkage, Module}, + passes::PassBuilderOptions, + support::is_multithreaded, + targets::*, + OptimizationLevel, + }, + nac3parser::{ + ast::{Constant, ExprKind, Located, Stmt, StmtKind, StrRef}, + parser::parse_program, + }, symbol_resolver::SymbolResolver, toplevel::{ + builtins::get_exn_constructor, composer::{BuiltinFuncCreator, BuiltinFuncSpec, ComposerConfig, TopLevelComposer}, DefinitionId, GenCall, TopLevelDef, }, - typecheck::typedef::{FunSignature, FuncArg}, - typecheck::{type_inferencer::PrimitiveStore, typedef::Type}, + typecheck::{ + type_inferencer::PrimitiveStore, + typedef::{into_var_map, FunSignature, FuncArg, Type, TypeEnum, Unifier, VarMap}, + }, }; - use nac3ld::Linker; use crate::{ @@ -65,15 +70,13 @@ use crate::{ attributes_writeback, gen_core_log, gen_rtio_log, rpc_codegen_callback, ArtiqCodeGenerator, }, symbol_resolver::{DeferredEvaluationStore, InnerResolver, PythonHelper, Resolver}, + timeline::TimeFns, }; -use tempfile::{self, TempDir}; mod codegen; mod symbol_resolver; mod timeline; -use timeline::TimeFns; - #[derive(PartialEq, Clone, Copy)] enum Isa { Host, diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index d3381d12..313b75d8 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -1,17 +1,30 @@ -use crate::PrimitivePythonId; -use itertools::Itertools; -use nac3core::inkwell::{ - module::Linkage, - types::{BasicType, BasicTypeEnum}, - values::BasicValueEnum, - AddressSpace, +use std::{ + collections::{HashMap, HashSet}, + sync::{ + atomic::{AtomicBool, Ordering::Relaxed}, + Arc, + }, }; -use nac3core::nac3parser::ast::{self, StrRef}; + +use itertools::Itertools; +use parking_lot::RwLock; +use pyo3::{ + types::{PyDict, PyTuple}, + PyAny, PyObject, PyResult, Python, +}; + use nac3core::{ codegen::{ classes::{NDArrayType, ProxyType}, CodeGenContext, CodeGenerator, }, + inkwell::{ + module::Linkage, + types::{BasicType, BasicTypeEnum}, + values::BasicValueEnum, + AddressSpace, + }, + nac3parser::ast::{self, StrRef}, symbol_resolver::{StaticValue, SymbolResolver, SymbolValue, ValueEnum}, toplevel::{ helper::PrimDef, @@ -23,18 +36,8 @@ use nac3core::{ typedef::{into_var_map, iter_type_vars, Type, TypeEnum, TypeVar, Unifier, VarMap}, }, }; -use parking_lot::RwLock; -use pyo3::{ - types::{PyDict, PyTuple}, - PyAny, PyObject, PyResult, Python, -}; -use std::{ - collections::{HashMap, HashSet}, - sync::{ - atomic::{AtomicBool, Ordering::Relaxed}, - Arc, - }, -}; + +use crate::PrimitivePythonId; pub enum PrimitiveValue { I32(i32), diff --git a/nac3artiq/src/timeline.rs b/nac3artiq/src/timeline.rs index e9faf43a..f51c553e 100644 --- a/nac3artiq/src/timeline.rs +++ b/nac3artiq/src/timeline.rs @@ -1,8 +1,11 @@ use itertools::Either; -use nac3core::codegen::CodeGenContext; -use nac3core::inkwell::{ - values::{BasicValueEnum, CallSiteValue}, - AddressSpace, AtomicOrdering, + +use nac3core::{ + codegen::CodeGenContext, + inkwell::{ + values::{BasicValueEnum, CallSiteValue}, + AddressSpace, AtomicOrdering, + }, }; /// Functions for manipulating the timeline. diff --git a/nac3core/build.rs b/nac3core/build.rs index 5447a696..8a5c56fe 100644 --- a/nac3core/build.rs +++ b/nac3core/build.rs @@ -1,4 +1,3 @@ -use regex::Regex; use std::{ env, fs::File, @@ -7,6 +6,8 @@ use std::{ process::{Command, Stdio}, }; +use regex::Regex; + fn main() { let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = Path::new(&out_dir); diff --git a/nac3core/src/codegen/builtin_fns.rs b/nac3core/src/codegen/builtin_fns.rs index 5608ec71..66ac807c 100644 --- a/nac3core/src/codegen/builtin_fns.rs +++ b/nac3core/src/codegen/builtin_fns.rs @@ -1,21 +1,30 @@ -use inkwell::types::BasicTypeEnum; -use inkwell::values::{BasicValue, BasicValueEnum, IntValue, PointerValue}; -use inkwell::{FloatPredicate, IntPredicate, OptimizationLevel}; +use inkwell::{ + types::BasicTypeEnum, + values::{BasicValue, BasicValueEnum, IntValue, PointerValue}, + FloatPredicate, IntPredicate, OptimizationLevel, +}; use itertools::Itertools; -use crate::codegen::classes::{ - ArrayLikeValue, NDArrayValue, ProxyValue, RangeValue, TypedArrayLikeAccessor, - UntypedArrayLikeAccessor, UntypedArrayLikeMutator, +use crate::{ + codegen::{ + classes::{ + ArrayLikeValue, NDArrayValue, ProxyValue, RangeValue, TypedArrayLikeAccessor, + UntypedArrayLikeAccessor, UntypedArrayLikeMutator, + }, + expr::destructure_range, + extern_fns, irrt, + irrt::calculate_len_for_slice_range, + llvm_intrinsics, + macros::codegen_unreachable, + numpy, + numpy::ndarray_elementwise_unaryop_impl, + stmt::gen_for_callback_incrementing, + CodeGenContext, CodeGenerator, + }, + toplevel::helper::PrimDef, + toplevel::numpy::unpack_ndarray_var_tys, + typecheck::typedef::{Type, TypeEnum}, }; -use crate::codegen::expr::destructure_range; -use crate::codegen::irrt::calculate_len_for_slice_range; -use crate::codegen::macros::codegen_unreachable; -use crate::codegen::numpy::ndarray_elementwise_unaryop_impl; -use crate::codegen::stmt::gen_for_callback_incrementing; -use crate::codegen::{extern_fns, irrt, llvm_intrinsics, numpy, CodeGenContext, CodeGenerator}; -use crate::toplevel::helper::PrimDef; -use crate::toplevel::numpy::unpack_ndarray_var_tys; -use crate::typecheck::typedef::{Type, TypeEnum}; /// Shorthand for [`unreachable!()`] when a type of argument is not supported. /// diff --git a/nac3core/src/codegen/classes.rs b/nac3core/src/codegen/classes.rs index 3d548205..eee3bdf3 100644 --- a/nac3core/src/codegen/classes.rs +++ b/nac3core/src/codegen/classes.rs @@ -1,17 +1,16 @@ +use inkwell::{ + context::Context, + types::{AnyTypeEnum, ArrayType, BasicType, BasicTypeEnum, IntType, PointerType, StructType}, + values::{ArrayValue, BasicValue, BasicValueEnum, IntValue, PointerValue, StructValue}, + AddressSpace, IntPredicate, +}; + use crate::codegen::{ irrt::{call_ndarray_calc_size, call_ndarray_flatten_index}, llvm_intrinsics::call_int_umin, stmt::gen_for_callback_incrementing, CodeGenContext, CodeGenerator, }; -use inkwell::context::Context; -use inkwell::types::{ArrayType, BasicType, StructType}; -use inkwell::values::{ArrayValue, BasicValue, StructValue}; -use inkwell::{ - types::{AnyTypeEnum, BasicTypeEnum, IntType, PointerType}, - values::{BasicValueEnum, IntValue, PointerValue}, - AddressSpace, IntPredicate, -}; /// A LLVM type that is used to represent a non-primitive type in NAC3. pub trait ProxyType<'ctx>: Into { diff --git a/nac3core/src/codegen/concrete_type.rs b/nac3core/src/codegen/concrete_type.rs index 8680beee..d5c1fc38 100644 --- a/nac3core/src/codegen/concrete_type.rs +++ b/nac3core/src/codegen/concrete_type.rs @@ -1,3 +1,9 @@ +use std::collections::HashMap; + +use indexmap::IndexMap; + +use nac3parser::ast::StrRef; + use crate::{ symbol_resolver::SymbolValue, toplevel::DefinitionId, @@ -9,10 +15,6 @@ use crate::{ }, }; -use indexmap::IndexMap; -use nac3parser::ast::StrRef; -use std::collections::HashMap; - pub struct ConcreteTypeStore { store: Vec, } diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 72b28d02..c478fb3f 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -1,3 +1,23 @@ +use std::{ + cmp::min, + collections::HashMap, + convert::TryInto, + iter::{once, repeat, repeat_with, zip}, +}; + +use inkwell::{ + attributes::{Attribute, AttributeLoc}, + types::{AnyType, BasicType, BasicTypeEnum}, + values::{BasicValueEnum, CallSiteValue, FunctionValue, IntValue, PointerValue, StructValue}, + AddressSpace, IntPredicate, OptimizationLevel, +}; +use itertools::{chain, izip, Either, Itertools}; + +use nac3parser::ast::{ + self, Boolop, Cmpop, Comprehension, Constant, Expr, ExprKind, Location, Operator, StrRef, + Unaryop, +}; + use crate::{ codegen::{ classes::{ @@ -30,20 +50,6 @@ use crate::{ typedef::{FunSignature, FuncArg, Type, TypeEnum, TypeVarId, Unifier, VarMap}, }, }; -use inkwell::{ - attributes::{Attribute, AttributeLoc}, - types::{AnyType, BasicType, BasicTypeEnum}, - values::{BasicValueEnum, CallSiteValue, FunctionValue, IntValue, PointerValue, StructValue}, - AddressSpace, IntPredicate, OptimizationLevel, -}; -use itertools::{chain, izip, Either, Itertools}; -use nac3parser::ast::{ - self, Boolop, Cmpop, Comprehension, Constant, Expr, ExprKind, Location, Operator, StrRef, - Unaryop, -}; -use std::cmp::min; -use std::iter::{repeat, repeat_with}; -use std::{collections::HashMap, convert::TryInto, iter::once, iter::zip}; pub fn get_subst_key( unifier: &mut Unifier, diff --git a/nac3core/src/codegen/extern_fns.rs b/nac3core/src/codegen/extern_fns.rs index 5bbafd30..0db29f26 100644 --- a/nac3core/src/codegen/extern_fns.rs +++ b/nac3core/src/codegen/extern_fns.rs @@ -1,5 +1,7 @@ -use inkwell::attributes::{Attribute, AttributeLoc}; -use inkwell::values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue}; +use inkwell::{ + attributes::{Attribute, AttributeLoc}, + values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue}, +}; use itertools::Either; use crate::codegen::CodeGenContext; diff --git a/nac3core/src/codegen/generator.rs b/nac3core/src/codegen/generator.rs index 6a6b46dd..77981dc5 100644 --- a/nac3core/src/codegen/generator.rs +++ b/nac3core/src/codegen/generator.rs @@ -1,15 +1,17 @@ +use inkwell::{ + context::Context, + types::{BasicTypeEnum, IntType}, + values::{BasicValueEnum, IntValue, PointerValue}, +}; + +use nac3parser::ast::{Expr, Stmt, StrRef}; + use crate::{ codegen::{bool_to_i1, bool_to_i8, classes::ArraySliceValue, expr::*, stmt::*, CodeGenContext}, symbol_resolver::ValueEnum, toplevel::{DefinitionId, TopLevelDef}, typecheck::typedef::{FunSignature, Type}, }; -use inkwell::{ - context::Context, - types::{BasicTypeEnum, IntType}, - values::{BasicValueEnum, IntValue, PointerValue}, -}; -use nac3parser::ast::{Expr, Stmt, StrRef}; pub trait CodeGenerator { /// Return the module name for the code generator. diff --git a/nac3core/src/codegen/irrt/mod.rs b/nac3core/src/codegen/irrt/mod.rs index d8d2a56a..15af3cdb 100644 --- a/nac3core/src/codegen/irrt/mod.rs +++ b/nac3core/src/codegen/irrt/mod.rs @@ -1,4 +1,15 @@ -use crate::{symbol_resolver::SymbolResolver, typecheck::typedef::Type}; +use inkwell::{ + attributes::{Attribute, AttributeLoc}, + context::Context, + memory_buffer::MemoryBuffer, + module::Module, + types::{BasicTypeEnum, IntType}, + values::{BasicValue, BasicValueEnum, CallSiteValue, FloatValue, IntValue}, + AddressSpace, IntPredicate, +}; +use itertools::Either; + +use nac3parser::ast::Expr; use super::{ classes::{ @@ -10,17 +21,7 @@ use super::{ stmt::gen_for_callback_incrementing, CodeGenContext, CodeGenerator, }; -use inkwell::{ - attributes::{Attribute, AttributeLoc}, - context::Context, - memory_buffer::MemoryBuffer, - module::Module, - types::{BasicTypeEnum, IntType}, - values::{BasicValue, BasicValueEnum, CallSiteValue, FloatValue, IntValue}, - AddressSpace, IntPredicate, -}; -use itertools::Either; -use nac3parser::ast::Expr; +use crate::{symbol_resolver::SymbolResolver, typecheck::typedef::Type}; #[must_use] pub fn load_irrt<'ctx>(ctx: &'ctx Context, symbol_resolver: &dyn SymbolResolver) -> Module<'ctx> { diff --git a/nac3core/src/codegen/llvm_intrinsics.rs b/nac3core/src/codegen/llvm_intrinsics.rs index 00bdee22..2bfaad64 100644 --- a/nac3core/src/codegen/llvm_intrinsics.rs +++ b/nac3core/src/codegen/llvm_intrinsics.rs @@ -1,12 +1,14 @@ -use crate::codegen::CodeGenContext; -use inkwell::context::Context; -use inkwell::intrinsics::Intrinsic; -use inkwell::types::AnyTypeEnum::IntType; -use inkwell::types::FloatType; -use inkwell::values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue, PointerValue}; -use inkwell::AddressSpace; +use inkwell::{ + context::Context, + intrinsics::Intrinsic, + types::{AnyTypeEnum::IntType, FloatType}, + values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue, PointerValue}, + AddressSpace, +}; use itertools::Either; +use crate::codegen::CodeGenContext; + /// Returns the string representation for the floating-point type `ft` when used in intrinsic /// functions. fn get_float_intrinsic_repr(ctx: &Context, ft: FloatType) -> &'static str { diff --git a/nac3core/src/codegen/mod.rs b/nac3core/src/codegen/mod.rs index eecf5c2e..145eab6a 100644 --- a/nac3core/src/codegen/mod.rs +++ b/nac3core/src/codegen/mod.rs @@ -1,12 +1,12 @@ -use crate::{ - codegen::classes::{ListType, NDArrayType, ProxyType, RangeType}, - symbol_resolver::{StaticValue, SymbolResolver}, - toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys, TopLevelContext, TopLevelDef}, - typecheck::{ - type_inferencer::{CodeLocation, PrimitiveStore}, - typedef::{CallId, FuncArg, Type, TypeEnum, Unifier}, +use std::{ + collections::{HashMap, HashSet}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, }, + thread, }; + use crossbeam::channel::{unbounded, Receiver, Sender}; use inkwell::{ attributes::{Attribute, AttributeLoc}, @@ -24,14 +24,19 @@ use inkwell::{ AddressSpace, IntPredicate, OptimizationLevel, }; use itertools::Itertools; -use nac3parser::ast::{Location, Stmt, StrRef}; use parking_lot::{Condvar, Mutex}; -use std::collections::{HashMap, HashSet}; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, + +use nac3parser::ast::{Location, Stmt, StrRef}; + +use crate::{ + codegen::classes::{ListType, NDArrayType, ProxyType, RangeType}, + symbol_resolver::{StaticValue, SymbolResolver}, + toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys, TopLevelContext, TopLevelDef}, + typecheck::{ + type_inferencer::{CodeLocation, PrimitiveStore}, + typedef::{CallId, FuncArg, Type, TypeEnum, Unifier}, + }, }; -use std::thread; pub mod builtin_fns; pub mod classes; diff --git a/nac3core/src/codegen/numpy.rs b/nac3core/src/codegen/numpy.rs index 2463f9a0..421b159e 100644 --- a/nac3core/src/codegen/numpy.rs +++ b/nac3core/src/codegen/numpy.rs @@ -1,3 +1,11 @@ +use inkwell::{ + types::{AnyTypeEnum, BasicType, BasicTypeEnum, PointerType}, + values::{BasicValue, BasicValueEnum, IntValue, PointerValue}, + AddressSpace, IntPredicate, OptimizationLevel, +}; + +use nac3parser::ast::{Operator, StrRef}; + use crate::{ codegen::{ classes::{ @@ -27,16 +35,6 @@ use crate::{ typedef::{FunSignature, Type, TypeEnum}, }, }; -use inkwell::{ - types::BasicType, - values::{BasicValueEnum, IntValue, PointerValue}, - AddressSpace, IntPredicate, OptimizationLevel, -}; -use inkwell::{ - types::{AnyTypeEnum, BasicTypeEnum, PointerType}, - values::BasicValue, -}; -use nac3parser::ast::{Operator, StrRef}; /// Creates an uninitialized `NDArray` instance. fn create_ndarray_uninitialized<'ctx, G: CodeGenerator + ?Sized>( diff --git a/nac3core/src/codegen/stmt.rs b/nac3core/src/codegen/stmt.rs index 1def3a4f..fb81c6dc 100644 --- a/nac3core/src/codegen/stmt.rs +++ b/nac3core/src/codegen/stmt.rs @@ -1,3 +1,16 @@ +use inkwell::{ + attributes::{Attribute, AttributeLoc}, + basic_block::BasicBlock, + types::{BasicType, BasicTypeEnum}, + values::{BasicValue, BasicValueEnum, FunctionValue, IntValue, PointerValue}, + IntPredicate, +}; +use itertools::{izip, Itertools}; + +use nac3parser::ast::{ + Constant, ExcepthandlerKind, Expr, ExprKind, Location, Stmt, StmtKind, StrRef, +}; + use super::{ classes::{ArrayLikeIndexer, ArraySliceValue, ListValue, RangeValue}, expr::{destructure_range, gen_binop_expr}, @@ -14,17 +27,6 @@ use crate::{ typedef::{iter_type_vars, FunSignature, Type, TypeEnum}, }, }; -use inkwell::{ - attributes::{Attribute, AttributeLoc}, - basic_block::BasicBlock, - types::{BasicType, BasicTypeEnum}, - values::{BasicValue, BasicValueEnum, FunctionValue, IntValue, PointerValue}, - IntPredicate, -}; -use itertools::{izip, Itertools}; -use nac3parser::ast::{ - Constant, ExcepthandlerKind, Expr, ExprKind, Location, Stmt, StmtKind, StrRef, -}; /// See [`CodeGenerator::gen_var_alloc`]. pub fn gen_var<'ctx>( diff --git a/nac3core/src/codegen/test.rs b/nac3core/src/codegen/test.rs index 9ed495e0..9649e68e 100644 --- a/nac3core/src/codegen/test.rs +++ b/nac3core/src/codegen/test.rs @@ -1,3 +1,20 @@ +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, +}; + +use indexmap::IndexMap; +use indoc::indoc; +use inkwell::{ + targets::{InitializationConfig, Target}, + OptimizationLevel, +}; +use nac3parser::{ + ast::{fold::Fold, FileName, StrRef}, + parser::parse_program, +}; +use parking_lot::RwLock; + use crate::{ codegen::{ classes::{ListType, NDArrayType, ProxyType, RangeType}, @@ -15,20 +32,6 @@ use crate::{ typedef::{FunSignature, FuncArg, Type, TypeEnum, Unifier, VarMap}, }, }; -use indexmap::IndexMap; -use indoc::indoc; -use inkwell::{ - targets::{InitializationConfig, Target}, - OptimizationLevel, -}; -use nac3parser::ast::FileName; -use nac3parser::{ - ast::{fold::Fold, StrRef}, - parser::parse_program, -}; -use parking_lot::RwLock; -use std::collections::{HashMap, HashSet}; -use std::sync::Arc; struct Resolver { id_to_type: HashMap, diff --git a/nac3core/src/symbol_resolver.rs b/nac3core/src/symbol_resolver.rs index 9d7084b9..ccd90a1c 100644 --- a/nac3core/src/symbol_resolver.rs +++ b/nac3core/src/symbol_resolver.rs @@ -1,7 +1,15 @@ -use std::fmt::Debug; -use std::rc::Rc; -use std::sync::Arc; -use std::{collections::HashMap, collections::HashSet, fmt::Display}; +use std::{ + collections::{HashMap, HashSet}, + fmt::{Debug, Display}, + rc::Rc, + sync::Arc, +}; + +use inkwell::values::{BasicValueEnum, FloatValue, IntValue, PointerValue, StructValue}; +use itertools::{chain, izip, Itertools}; +use parking_lot::RwLock; + +use nac3parser::ast::{Constant, Expr, Location, StrRef}; use crate::{ codegen::{CodeGenContext, CodeGenerator}, @@ -11,10 +19,6 @@ use crate::{ typedef::{Type, TypeEnum, Unifier, VarMap}, }, }; -use inkwell::values::{BasicValueEnum, FloatValue, IntValue, PointerValue, StructValue}; -use itertools::{chain, izip, Itertools}; -use nac3parser::ast::{Constant, Expr, Location, StrRef}; -use parking_lot::RwLock; #[derive(Clone, PartialEq, Debug)] pub enum SymbolValue { diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index e2325ebb..4609e43b 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -1,6 +1,5 @@ use std::iter::once; -use helper::{debug_assert_prim_is_allowed, make_exception_fields, PrimDefDetails}; use indexmap::IndexMap; use inkwell::{ attributes::{Attribute, AttributeLoc}, @@ -11,6 +10,10 @@ use inkwell::{ use itertools::Either; use strum::IntoEnumIterator; +use super::{ + helper::{debug_assert_prim_is_allowed, make_exception_fields, PrimDefDetails}, + *, +}; use crate::{ codegen::{ builtin_fns, @@ -23,8 +26,6 @@ use crate::{ typecheck::typedef::{into_var_map, iter_type_vars, TypeVar, VarMap}, }; -use super::*; - type BuiltinInfo = Vec<(Arc>, Option)>; pub fn get_exn_constructor( diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 125e137a..619cc50b 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -1,6 +1,8 @@ -use nac3parser::ast::fold::Fold; use std::rc::Rc; +use nac3parser::ast::fold::Fold; + +use super::*; use crate::{ codegen::{expr::get_subst_key, stmt::exn_constructor}, symbol_resolver::SymbolValue, @@ -10,8 +12,6 @@ use crate::{ }, }; -use super::*; - pub struct ComposerConfig { pub kernel_ann: Option<&'static str>, pub kernel_invariant_ann: &'static str, diff --git a/nac3core/src/toplevel/helper.rs b/nac3core/src/toplevel/helper.rs index 29a662c5..66233ce0 100644 --- a/nac3core/src/toplevel/helper.rs +++ b/nac3core/src/toplevel/helper.rs @@ -1,14 +1,17 @@ use std::convert::TryInto; -use crate::symbol_resolver::SymbolValue; -use crate::toplevel::numpy::unpack_ndarray_var_tys; -use crate::typecheck::typedef::{into_var_map, iter_type_vars, Mapping, TypeVarId, VarMap}; -use ast::ExprKind; -use nac3parser::ast::{Constant, Location}; use strum::IntoEnumIterator; use strum_macros::EnumIter; +use ast::ExprKind; +use nac3parser::ast::{Constant, Location}; + use super::*; +use crate::{ + symbol_resolver::SymbolValue, + toplevel::numpy::unpack_ndarray_var_tys, + typecheck::typedef::{into_var_map, iter_type_vars, Mapping, TypeVarId, VarMap}, +}; /// All primitive types and functions in nac3core. #[derive(Clone, Copy, Debug, EnumIter, PartialEq, Eq)] diff --git a/nac3core/src/toplevel/mod.rs b/nac3core/src/toplevel/mod.rs index 098a2a58..b786aa73 100644 --- a/nac3core/src/toplevel/mod.rs +++ b/nac3core/src/toplevel/mod.rs @@ -6,24 +6,24 @@ use std::{ sync::Arc, }; -use super::codegen::CodeGenContext; -use super::typecheck::type_inferencer::PrimitiveStore; -use super::typecheck::typedef::{ - FunSignature, FuncArg, SharedUnifier, Type, TypeEnum, Unifier, VarMap, -}; -use crate::{ - codegen::CodeGenerator, - symbol_resolver::{SymbolResolver, ValueEnum}, - typecheck::{ - type_inferencer::CodeLocation, - typedef::{CallId, TypeVarId}, - }, -}; use inkwell::values::BasicValueEnum; use itertools::Itertools; -use nac3parser::ast::{self, Location, Stmt, StrRef}; use parking_lot::RwLock; +use nac3parser::ast::{self, Location, Stmt, StrRef}; + +use crate::{ + codegen::{CodeGenContext, CodeGenerator}, + symbol_resolver::{SymbolResolver, ValueEnum}, + typecheck::{ + type_inferencer::{CodeLocation, PrimitiveStore}, + typedef::{ + CallId, FunSignature, FuncArg, SharedUnifier, Type, TypeEnum, TypeVarId, Unifier, + VarMap, + }, + }, +}; + #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug)] pub struct DefinitionId(pub usize); diff --git a/nac3core/src/toplevel/numpy.rs b/nac3core/src/toplevel/numpy.rs index 168658b6..437abbf3 100644 --- a/nac3core/src/toplevel/numpy.rs +++ b/nac3core/src/toplevel/numpy.rs @@ -1,3 +1,5 @@ +use itertools::Itertools; + use crate::{ toplevel::helper::PrimDef, typecheck::{ @@ -5,7 +7,6 @@ use crate::{ typedef::{Type, TypeEnum, TypeVarId, Unifier, VarMap}, }, }; -use itertools::Itertools; /// Creates a `ndarray` [`Type`] with the given type arguments. /// diff --git a/nac3core/src/toplevel/test.rs b/nac3core/src/toplevel/test.rs index 522cb23d..cda680c7 100644 --- a/nac3core/src/toplevel/test.rs +++ b/nac3core/src/toplevel/test.rs @@ -1,21 +1,24 @@ +use std::{collections::HashMap, sync::Arc}; + +use indoc::indoc; +use parking_lot::Mutex; +use test_case::test_case; + +use nac3parser::{ + ast::{fold::Fold, FileName}, + parser::parse_program, +}; + use super::*; -use crate::toplevel::helper::PrimDef; -use crate::typecheck::typedef::into_var_map; use crate::{ codegen::CodeGenContext, symbol_resolver::{SymbolResolver, ValueEnum}, - toplevel::DefinitionId, + toplevel::{helper::PrimDef, DefinitionId}, typecheck::{ type_inferencer::PrimitiveStore, - typedef::{Type, Unifier}, + typedef::{into_var_map, Type, Unifier}, }, }; -use indoc::indoc; -use nac3parser::ast::FileName; -use nac3parser::{ast::fold::Fold, parser::parse_program}; -use parking_lot::Mutex; -use std::{collections::HashMap, sync::Arc}; -use test_case::test_case; struct ResolverInternal { id_to_type: Mutex>, diff --git a/nac3core/src/toplevel/type_annotation.rs b/nac3core/src/toplevel/type_annotation.rs index d997f176..f8b16f86 100644 --- a/nac3core/src/toplevel/type_annotation.rs +++ b/nac3core/src/toplevel/type_annotation.rs @@ -1,10 +1,14 @@ -use super::*; -use crate::symbol_resolver::SymbolValue; -use crate::toplevel::helper::{PrimDef, PrimDefDetails}; -use crate::typecheck::typedef::VarMap; -use nac3parser::ast::Constant; use strum::IntoEnumIterator; +use nac3parser::ast::Constant; + +use super::*; +use crate::{ + symbol_resolver::SymbolValue, + toplevel::helper::{PrimDef, PrimDefDetails}, + typecheck::typedef::VarMap, +}; + #[derive(Clone, Debug)] pub enum TypeAnnotation { Primitive(Type), diff --git a/nac3core/src/typecheck/function_check.rs b/nac3core/src/typecheck/function_check.rs index be2d1dce..9dd84091 100644 --- a/nac3core/src/typecheck/function_check.rs +++ b/nac3core/src/typecheck/function_check.rs @@ -1,13 +1,16 @@ -use crate::toplevel::helper::PrimDef; +use std::{collections::HashSet, iter::once}; -use super::type_inferencer::Inferencer; -use super::typedef::{Type, TypeEnum}; use nac3parser::ast::{ self, Constant, Expr, ExprKind, Operator::{LShift, RShift}, Stmt, StmtKind, StrRef, }; -use std::{collections::HashSet, iter::once}; + +use super::{ + type_inferencer::Inferencer, + typedef::{Type, TypeEnum}, +}; +use crate::toplevel::helper::PrimDef; impl<'a> Inferencer<'a> { fn should_have_value(&mut self, expr: &Expr>) -> Result<(), HashSet> { diff --git a/nac3core/src/typecheck/magic_methods.rs b/nac3core/src/typecheck/magic_methods.rs index 9344dd21..322f7b9e 100644 --- a/nac3core/src/typecheck/magic_methods.rs +++ b/nac3core/src/typecheck/magic_methods.rs @@ -1,18 +1,22 @@ -use crate::symbol_resolver::SymbolValue; -use crate::toplevel::helper::PrimDef; -use crate::toplevel::numpy::{make_ndarray_ty, unpack_ndarray_var_tys}; -use crate::typecheck::{ - type_inferencer::*, - typedef::{FunSignature, FuncArg, Type, TypeEnum, Unifier, VarMap}, -}; +use std::{cmp::max, collections::HashMap, rc::Rc}; + use itertools::{iproduct, Itertools}; -use nac3parser::ast::StrRef; -use nac3parser::ast::{Cmpop, Operator, Unaryop}; -use std::cmp::max; -use std::collections::HashMap; -use std::rc::Rc; use strum::IntoEnumIterator; +use nac3parser::ast::{Cmpop, Operator, StrRef, Unaryop}; + +use crate::{ + symbol_resolver::SymbolValue, + toplevel::{ + helper::PrimDef, + numpy::{make_ndarray_ty, unpack_ndarray_var_tys}, + }, + typecheck::{ + type_inferencer::*, + typedef::{FunSignature, FuncArg, Type, TypeEnum, Unifier, VarMap}, + }, +}; + /// The variant of a binary operator. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum BinopVariant { diff --git a/nac3core/src/typecheck/type_error.rs b/nac3core/src/typecheck/type_error.rs index 706ba5b4..018464a9 100644 --- a/nac3core/src/typecheck/type_error.rs +++ b/nac3core/src/typecheck/type_error.rs @@ -1,14 +1,14 @@ -use std::collections::HashMap; -use std::fmt::Display; +use std::{collections::HashMap, fmt::Display}; -use crate::typecheck::{magic_methods::HasOpInfo, typedef::TypeEnum}; +use itertools::Itertools; + +use nac3parser::ast::{Cmpop, Location, StrRef}; use super::{ magic_methods::Binop, typedef::{RecordKey, Type, Unifier}, }; -use itertools::Itertools; -use nac3parser::ast::{Cmpop, Location, StrRef}; +use crate::typecheck::{magic_methods::HasOpInfo, typedef::TypeEnum}; #[derive(Debug, Clone)] pub enum TypeErrorKind { diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index d27f746e..48736738 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -1,32 +1,36 @@ -use std::cmp::max; -use std::collections::{HashMap, HashSet}; -use std::convert::{From, TryInto}; -use std::iter::once; -use std::{cell::RefCell, sync::Arc}; +use std::{ + cell::RefCell, + cmp::max, + collections::{HashMap, HashSet}, + convert::{From, TryInto}, + iter::once, + sync::Arc, +}; + +use itertools::{izip, Itertools}; + +use nac3parser::ast::{ + self, + fold::{self, Fold}, + Arguments, Comprehension, ExprContext, ExprKind, Located, Location, StrRef, +}; use super::{ magic_methods::*, type_error::{TypeError, TypeErrorKind}, typedef::{ - into_var_map, iter_type_vars, Call, CallId, FunSignature, FuncArg, OperatorInfo, + into_var_map, iter_type_vars, Call, CallId, FunSignature, FuncArg, Mapping, OperatorInfo, RecordField, RecordKey, Type, TypeEnum, TypeVar, Unifier, VarMap, }, }; -use crate::toplevel::type_annotation::TypeAnnotation; use crate::{ symbol_resolver::{SymbolResolver, SymbolValue}, toplevel::{ helper::{arraylike_flatten_element_type, arraylike_get_ndims, PrimDef}, numpy::{make_ndarray_ty, unpack_ndarray_var_tys}, + type_annotation::TypeAnnotation, TopLevelContext, TopLevelDef, }, - typecheck::typedef::Mapping, -}; -use itertools::{izip, Itertools}; -use nac3parser::ast::{ - self, - fold::{self, Fold}, - Arguments, Comprehension, ExprContext, ExprKind, Located, Location, StrRef, }; #[cfg(test)] diff --git a/nac3core/src/typecheck/type_inferencer/test.rs b/nac3core/src/typecheck/type_inferencer/test.rs index 75293a3a..f81e4ca4 100644 --- a/nac3core/src/typecheck/type_inferencer/test.rs +++ b/nac3core/src/typecheck/type_inferencer/test.rs @@ -1,17 +1,19 @@ -use super::super::{magic_methods::with_fields, typedef::*}; +use std::iter::zip; + +use indexmap::IndexMap; +use indoc::indoc; +use parking_lot::RwLock; +use test_case::test_case; + +use nac3parser::{ast::FileName, parser::parse_program}; + use super::*; use crate::{ codegen::CodeGenContext, symbol_resolver::ValueEnum, toplevel::{helper::PrimDef, DefinitionId, TopLevelDef}, + typecheck::{magic_methods::with_fields, typedef::*}, }; -use indexmap::IndexMap; -use indoc::indoc; -use nac3parser::ast::FileName; -use nac3parser::parser::parse_program; -use parking_lot::RwLock; -use std::iter::zip; -use test_case::test_case; struct Resolver { id_to_type: HashMap, diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index 22d04791..96fda4c2 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -1,21 +1,28 @@ -use super::magic_methods::{Binop, HasOpInfo}; -use super::type_error::{TypeError, TypeErrorKind}; -use super::unification_table::{UnificationKey, UnificationTable}; -use crate::symbol_resolver::SymbolValue; -use crate::toplevel::helper::PrimDef; -use crate::toplevel::{DefinitionId, TopLevelContext, TopLevelDef}; -use crate::typecheck::magic_methods::OpInfo; -use crate::typecheck::type_inferencer::PrimitiveStore; +use std::{ + borrow::Cow, + cell::RefCell, + collections::{HashMap, HashSet}, + fmt::{self, Display}, + iter::{repeat, zip}, + rc::Rc, + sync::{Arc, Mutex}, +}; + use indexmap::IndexMap; use itertools::{repeat_n, Itertools}; + use nac3parser::ast::{Cmpop, Location, StrRef, Unaryop}; -use std::cell::RefCell; -use std::collections::HashMap; -use std::fmt::{self, Display}; -use std::iter::{repeat, zip}; -use std::rc::Rc; -use std::sync::{Arc, Mutex}; -use std::{borrow::Cow, collections::HashSet}; + +use super::{ + magic_methods::{Binop, HasOpInfo}, + type_error::{TypeError, TypeErrorKind}, + unification_table::{UnificationKey, UnificationTable}, +}; +use crate::{ + symbol_resolver::SymbolValue, + toplevel::{helper::PrimDef, DefinitionId, TopLevelContext, TopLevelDef}, + typecheck::{magic_methods::OpInfo, type_inferencer::PrimitiveStore}, +}; #[cfg(test)] mod test; diff --git a/nac3core/src/typecheck/typedef/test.rs b/nac3core/src/typecheck/typedef/test.rs index 435c134d..803e388b 100644 --- a/nac3core/src/typecheck/typedef/test.rs +++ b/nac3core/src/typecheck/typedef/test.rs @@ -1,10 +1,12 @@ -use super::super::magic_methods::with_fields; -use super::*; +use std::collections::HashMap; + use indoc::indoc; use itertools::Itertools; -use std::collections::HashMap; use test_case::test_case; +use super::*; +use crate::typecheck::magic_methods::with_fields; + impl Unifier { /// Check whether two types are equal. fn eq(&mut self, a: Type, b: Type) -> bool { diff --git a/nac3ld/src/lib.rs b/nac3ld/src/lib.rs index 9d62d9e8..4946785e 100644 --- a/nac3ld/src/lib.rs +++ b/nac3ld/src/lib.rs @@ -21,13 +21,12 @@ clippy::wildcard_imports )] +use std::{collections::HashMap, mem, ptr, slice, str}; + +use byteorder::{ByteOrder, LittleEndian}; + use dwarf::*; use elf::*; -use std::collections::HashMap; -use std::{mem, ptr, slice, str}; - -extern crate byteorder; -use byteorder::{ByteOrder, LittleEndian}; mod dwarf; mod elf; diff --git a/nac3parser/src/config_comment_helper.rs b/nac3parser/src/config_comment_helper.rs index 737ce985..2664e9b5 100644 --- a/nac3parser/src/config_comment_helper.rs +++ b/nac3parser/src/config_comment_helper.rs @@ -1,8 +1,10 @@ -use crate::ast::Ident; -use crate::ast::Location; -use crate::error::*; -use crate::token::Tok; +use crate::{ + ast::{Ident, Location}, + error::*, + token::Tok, +}; use lalrpop_util::ParseError; + use nac3ast::*; pub fn make_config_comment( diff --git a/nac3parser/src/error.rs b/nac3parser/src/error.rs index b24b513e..6b934b49 100644 --- a/nac3parser/src/error.rs +++ b/nac3parser/src/error.rs @@ -1,13 +1,12 @@ //! Define internal parse error types //! The goal is to provide a matching and a safe error API, maksing errors from LALR -use lalrpop_util::ParseError as LalrpopError; - -use crate::ast::Location; -use crate::token::Tok; - use std::error::Error; use std::fmt; +use lalrpop_util::ParseError as LalrpopError; + +use crate::{ast::Location, token::Tok}; + /// Represents an error during lexical scanning. #[derive(Debug, PartialEq)] pub struct LexicalError { diff --git a/nac3parser/src/fstring.rs b/nac3parser/src/fstring.rs index 4142f7a3..17fa181c 100644 --- a/nac3parser/src/fstring.rs +++ b/nac3parser/src/fstring.rs @@ -1,12 +1,11 @@ -use std::iter; -use std::mem; -use std::str; - -use crate::ast::{Constant, ConversionFlag, Expr, ExprKind, Location}; -use crate::error::{FStringError, FStringErrorType, ParseError}; -use crate::parser::parse_expression; +use std::{iter, mem, str}; use self::FStringErrorType::*; +use crate::{ + ast::{Constant, ConversionFlag, Expr, ExprKind, Location}, + error::{FStringError, FStringErrorType, ParseError}, + parser::parse_expression, +}; struct FStringParser<'a> { chars: iter::Peekable>, diff --git a/nac3parser/src/function.rs b/nac3parser/src/function.rs index 27d98211..33f12513 100644 --- a/nac3parser/src/function.rs +++ b/nac3parser/src/function.rs @@ -1,8 +1,11 @@ -use ahash::RandomState; use std::collections::HashSet; -use crate::ast; -use crate::error::{LexicalError, LexicalErrorType}; +use ahash::RandomState; + +use crate::{ + ast, + error::{LexicalError, LexicalErrorType}, +}; pub struct ArgumentList { pub args: Vec, diff --git a/nac3parser/src/lexer.rs b/nac3parser/src/lexer.rs index ded81462..dfafd465 100644 --- a/nac3parser/src/lexer.rs +++ b/nac3parser/src/lexer.rs @@ -1,17 +1,17 @@ //! This module takes care of lexing python source text. //! //! This means source code is translated into separate tokens. +use std::{char, cmp::Ordering, num::IntErrorKind, str::FromStr}; -pub use super::token::Tok; -use crate::ast::{FileName, Location}; -use crate::error::{LexicalError, LexicalErrorType}; -use std::char; -use std::cmp::Ordering; -use std::num::IntErrorKind; -use std::str::FromStr; use unic_emoji_char::is_emoji_presentation; use unic_ucd_ident::{is_xid_continue, is_xid_start}; +pub use super::token::Tok; +use crate::{ + ast::{FileName, Location}, + error::{LexicalError, LexicalErrorType}, +}; + #[derive(Clone, Copy, PartialEq, Debug, Default)] struct IndentationLevel { tabs: usize, diff --git a/nac3parser/src/parser.rs b/nac3parser/src/parser.rs index 3b124ce5..d3a30443 100644 --- a/nac3parser/src/parser.rs +++ b/nac3parser/src/parser.rs @@ -5,14 +5,16 @@ //! parse a whole program, a single statement, or a single //! expression. -use nac3ast::Location; use std::iter; -use crate::ast::{self, FileName}; -use crate::error::ParseError; -use crate::lexer; +use nac3ast::Location; + pub use crate::mode::Mode; -use crate::python; +use crate::{ + ast::{self, FileName}, + error::ParseError, + lexer, python, +}; /* * Parse python code. diff --git a/nac3parser/src/token.rs b/nac3parser/src/token.rs index f1e9d47d..5162c0c6 100644 --- a/nac3parser/src/token.rs +++ b/nac3parser/src/token.rs @@ -1,8 +1,9 @@ //! Different token definitions. //! Loosely based on token.h from CPython source: -use crate::ast; use std::fmt::{self, Write}; +use crate::ast; + /// Python source code can be tokenized in a sequence of these tokens. #[derive(Clone, Debug, PartialEq)] pub enum Tok { diff --git a/nac3standalone/src/basic_symbol_resolver.rs b/nac3standalone/src/basic_symbol_resolver.rs index 369ce196..631ee737 100644 --- a/nac3standalone/src/basic_symbol_resolver.rs +++ b/nac3standalone/src/basic_symbol_resolver.rs @@ -1,6 +1,13 @@ -use nac3core::nac3parser::ast::{self, StrRef}; +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, +}; + +use parking_lot::{Mutex, RwLock}; + use nac3core::{ codegen::CodeGenContext, + nac3parser::ast::{self, StrRef}, symbol_resolver::{SymbolResolver, SymbolValue, ValueEnum}, toplevel::{DefinitionId, TopLevelDef}, typecheck::{ @@ -8,9 +15,6 @@ use nac3core::{ typedef::{Type, Unifier}, }, }; -use parking_lot::{Mutex, RwLock}; -use std::collections::HashSet; -use std::{collections::HashMap, sync::Arc}; pub struct ResolverInternal { pub id_to_type: Mutex>, diff --git a/nac3standalone/src/main.rs b/nac3standalone/src/main.rs index c307b93d..83985709 100644 --- a/nac3standalone/src/main.rs +++ b/nac3standalone/src/main.rs @@ -8,20 +8,30 @@ #![warn(clippy::pedantic)] #![allow(clippy::too_many_lines, clippy::wildcard_imports)] +use std::{ + collections::{HashMap, HashSet}, + fs, + num::NonZeroUsize, + path::Path, + sync::Arc, +}; + use clap::Parser; -use nac3core::inkwell::{ - memory_buffer::MemoryBuffer, module::Linkage, passes::PassBuilderOptions, - support::is_multithreaded, targets::*, OptimizationLevel, -}; -use nac3core::nac3parser::{ - ast::{Constant, Expr, ExprKind, StmtKind, StrRef}, - parser, -}; +use parking_lot::{Mutex, RwLock}; + use nac3core::{ codegen::{ concrete_type::ConcreteTypeStore, irrt::load_irrt, CodeGenLLVMOptions, CodeGenTargetMachineOptions, CodeGenTask, DefaultCodeGenerator, WithCall, WorkerRegistry, }, + inkwell::{ + memory_buffer::MemoryBuffer, module::Linkage, passes::PassBuilderOptions, + support::is_multithreaded, targets::*, OptimizationLevel, + }, + nac3parser::{ + ast::{Constant, Expr, ExprKind, StmtKind, StrRef}, + parser, + }, symbol_resolver::SymbolResolver, toplevel::{ composer::{ComposerConfig, TopLevelComposer}, @@ -34,10 +44,6 @@ use nac3core::{ typedef::{FunSignature, Type, Unifier, VarMap}, }, }; -use parking_lot::{Mutex, RwLock}; -use std::collections::HashSet; -use std::num::NonZeroUsize; -use std::{collections::HashMap, fs, path::Path, sync::Arc}; mod basic_symbol_resolver; use basic_symbol_resolver::*;