From 39c022acf5d2d86eb934fe7b78e1e490c0d84916 Mon Sep 17 00:00:00 2001 From: Yann Hamdaoui Date: Fri, 20 Dec 2024 18:29:46 +0100 Subject: [PATCH] Fix compilation errors and warnings --- cli/src/doctest.rs | 6 ++---- core/src/bytecode/ast/typ.rs | 8 ++++++++ core/src/bytecode/typecheck/mod.rs | 2 +- core/src/bytecode/typecheck/operation.rs | 5 ++--- core/src/bytecode/typecheck/record.rs | 6 +++--- core/src/term/mod.rs | 1 - core/src/typ.rs | 14 +++----------- lsp/nls/src/analysis.rs | 3 ++- lsp/nls/src/cache.rs | 5 +++-- lsp/nls/src/position.rs | 3 ++- lsp/nls/src/usage.rs | 3 ++- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cli/src/doctest.rs b/cli/src/doctest.rs index d6c2be37b2..9427b67c20 100644 --- a/cli/src/doctest.rs +++ b/cli/src/doctest.rs @@ -19,10 +19,8 @@ use nickel_lang_core::{ label::Label, match_sharedterm, mk_app, mk_fun, program::Program, - term::{ - make, record::RecordData, LabeledType, RichTerm, Term, Traverse as _, TraverseOrder, - TypeAnnotation, - }, + term::{make, record::RecordData, LabeledType, RichTerm, Term, TypeAnnotation}, + traverse::{Traverse as _, TraverseOrder}, typ::{Type, TypeF}, typecheck::TypecheckMode, }; diff --git a/core/src/bytecode/ast/typ.rs b/core/src/bytecode/ast/typ.rs index 70a2b14bfe..76ff51d015 100644 --- a/core/src/bytecode/ast/typ.rs +++ b/core/src/bytecode/ast/typ.rs @@ -46,6 +46,14 @@ impl<'ast> Type<'ast> { pub fn with_pos(self, pos: TermPos) -> Type<'ast> { Type { pos, ..self } } + + /// Searches for a [crate::typ::TypeF]. If one is found, returns the term it contains. + pub fn find_contract(&self) -> Option<&'ast Ast<'ast>> { + self.find_map(|ty: &Type| match &ty.typ { + TypeF::Contract(f) => Some(*f), + _ => None, + }) + } } impl<'ast> TypeUnr<'ast> { diff --git a/core/src/bytecode/typecheck/mod.rs b/core/src/bytecode/typecheck/mod.rs index 56edd60bd8..635dce726a 100644 --- a/core/src/bytecode/typecheck/mod.rs +++ b/core/src/bytecode/typecheck/mod.rs @@ -2251,7 +2251,7 @@ fn check<'ast, V: TypecheckVisitor<'ast>>( // .map_err(|err| err.into_typecheck_err(state, ast.pos)) // } Node::Type(typ) => { - if let Some(contract) = typ.typ.find_contract() { + if let Some(contract) = typ.find_contract() { todo!("needs to update `error::TypecheckError` first, but not ready to switch to the new typechecker yet") // Err(TypecheckError::CtrTypeInTermPos { // contract, diff --git a/core/src/bytecode/typecheck/operation.rs b/core/src/bytecode/typecheck/operation.rs index 2918209c47..33f1049447 100644 --- a/core/src/bytecode/typecheck/operation.rs +++ b/core/src/bytecode/typecheck/operation.rs @@ -3,15 +3,14 @@ use super::*; use crate::{ bytecode::ast::{ builder, - primop::{PrimOp, RecordOpKind}, + primop::PrimOp, AstAlloc, }, error::TypecheckError, label::{Polarity, TypeVarData}, - position::TermPos, - term::{BinaryOp, NAryOp, RecordExtKind, UnaryOp}, typ::TypeF, }; + use crate::{mk_buty_arrow, mk_buty_enum, mk_buty_record}; pub trait PrimOpType { diff --git a/core/src/bytecode/typecheck/record.rs b/core/src/bytecode/typecheck/record.rs index f2633dc330..8772110277 100644 --- a/core/src/bytecode/typecheck/record.rs +++ b/core/src/bytecode/typecheck/record.rs @@ -270,10 +270,10 @@ impl<'ast> Combine for ResolvedRecord<'ast> { /// A wrapper type around a record that has been resolved but hasn't yet got a position. This is /// done to force the caller of [Record::resolve] to provide a position before doing anything else. -pub struct PoslessResolvedRecord<'ast>(ResolvedRecord<'ast>); +pub(super) struct PoslessResolvedRecord<'ast>(ResolvedRecord<'ast>); impl<'ast> PoslessResolvedRecord<'ast> { - pub fn new( + pub(super) fn new( stat_fields: IndexMap>, dyn_fields: Vec<(&'ast Ast<'ast>, ResolvedField<'ast>)>, ) -> Self { @@ -284,7 +284,7 @@ impl<'ast> PoslessResolvedRecord<'ast> { }) } - pub fn with_pos(self, pos: TermPos) -> ResolvedRecord<'ast> { + pub(super) fn with_pos(self, pos: TermPos) -> ResolvedRecord<'ast> { let PoslessResolvedRecord(record) = self; ResolvedRecord { pos, ..record } diff --git a/core/src/term/mod.rs b/core/src/term/mod.rs index f8ac45e98d..a92b673ed6 100644 --- a/core/src/term/mod.rs +++ b/core/src/term/mod.rs @@ -33,7 +33,6 @@ use crate::{ position::{RawSpan, TermPos}, pretty::PrettyPrintCap, traverse::*, - traverse::{Traverse, TraverseControl, TraverseOrder}, typ::{Type, UnboundTypeVariableError}, typecheck::eq::{contract_eq, type_eq_noenv}, }; diff --git a/core/src/typ.rs b/core/src/typ.rs index e441fb543a..5b58f9ef10 100644 --- a/core/src/typ.rs +++ b/core/src/typ.rs @@ -315,16 +315,16 @@ pub enum TypeF { /// Concrete, recursive definition for an enum row. pub type EnumRow = EnumRowF>; /// Concrete, recursive definition for enum rows. -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Clone, PartialEq, Debug)] pub struct EnumRows(pub EnumRowsF, Box>); /// Concrete, recursive definition for a record row. pub type RecordRow = RecordRowF>; -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Clone, PartialEq, Debug)] /// Concrete, recursive definition for record rows. pub struct RecordRows(pub RecordRowsF, Box>); /// Concrete, recursive type for a Nickel type. -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Clone, PartialEq, Debug)] pub struct Type { pub typ: TypeF, RecordRows, EnumRows, RichTerm>, pub pos: TermPos, @@ -678,14 +678,6 @@ impl TypeF { pub fn is_contract(&self) -> bool { matches!(self, TypeF::Contract(_)) } - - /// Searches for a `TypeF::Contract`. If one is found, returns the term it contains. - pub fn find_contract(&self) -> Option<&Te> { - self.find_map(|ty: &Type| match &ty.typ { - TypeF::Contract(f) => Some(f), - _ => None, - }) - } } impl Traverse for RecordRows { diff --git a/lsp/nls/src/analysis.rs b/lsp/nls/src/analysis.rs index 248f0bb420..14ab6b741e 100644 --- a/lsp/nls/src/analysis.rs +++ b/lsp/nls/src/analysis.rs @@ -4,7 +4,8 @@ use nickel_lang_core::{ files::FileId, identifier::Ident, position::RawSpan, - term::{BinaryOp, RichTerm, Term, Traverse, TraverseControl, UnaryOp}, + term::{BinaryOp, RichTerm, Term, UnaryOp}, + traverse::{Traverse, TraverseControl}, typ::{Type, TypeF}, typecheck::{ reporting::{NameReg, ToType}, diff --git a/lsp/nls/src/cache.rs b/lsp/nls/src/cache.rs index 995a2f98ac..e006ba98c8 100644 --- a/lsp/nls/src/cache.rs +++ b/lsp/nls/src/cache.rs @@ -1,12 +1,13 @@ use codespan::ByteIndex; use lsp_types::{TextDocumentPositionParams, Url}; -use nickel_lang_core::cache::InputFormat; -use nickel_lang_core::term::{RichTerm, Term, Traverse}; use nickel_lang_core::{ + cache::InputFormat, cache::{Cache, CacheError, CacheOp, EntryState, SourcePath, TermEntry}, error::{Error, ImportError}, files::FileId, position::RawPos, + term::{RichTerm, Term}, + traverse::Traverse, typecheck::{self}, }; diff --git a/lsp/nls/src/position.rs b/lsp/nls/src/position.rs index 477144476a..66524e6fa3 100644 --- a/lsp/nls/src/position.rs +++ b/lsp/nls/src/position.rs @@ -3,7 +3,8 @@ use std::ops::Range; use codespan::ByteIndex; use nickel_lang_core::{ position::TermPos, - term::{pattern::bindings::Bindings, RichTerm, Term, Traverse, TraverseControl}, + term::{pattern::bindings::Bindings, RichTerm, Term}, + traverse::{Traverse, TraverseControl}, }; use crate::{identifier::LocIdent, term::RichTermPtr}; diff --git a/lsp/nls/src/usage.rs b/lsp/nls/src/usage.rs index 588baccf50..6187f7e671 100644 --- a/lsp/nls/src/usage.rs +++ b/lsp/nls/src/usage.rs @@ -4,7 +4,8 @@ use nickel_lang_core::{ environment::Environment as GenericEnvironment, identifier::Ident, position::RawSpan, - term::{pattern::bindings::Bindings, MatchData, RichTerm, Term, Traverse, TraverseControl}, + term::{pattern::bindings::Bindings, MatchData, RichTerm, Term}, + traverse::{Traverse, TraverseControl}, }; use crate::{field_walker::Def, identifier::LocIdent};