From f4dcb112d99ac8eec5a1fca928e73501609e2642 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Sat, 24 Feb 2024 18:43:06 +0000 Subject: [PATCH 1/4] Start work on adding reference types --- src/hir/definitions.rs | 11 ++++++-- src/lexer/mod.rs | 10 +++----- src/lexer/token.rs | 22 +++++----------- src/nameresolution/mod.rs | 6 ++--- src/parser/ast.rs | 39 ++++++++++++++++++++++++++-- src/parser/mod.rs | 50 ++++++++++++++++++++++++++++++------ src/parser/pretty_printer.rs | 7 +++-- src/types/mod.rs | 11 ++++---- src/types/typechecker.rs | 4 +-- src/types/typeprinter.rs | 11 +++++--- stdlib/prelude.an | 12 ++++----- 11 files changed, 129 insertions(+), 54 deletions(-) diff --git a/src/hir/definitions.rs b/src/hir/definitions.rs index 49293745..73cff068 100644 --- a/src/hir/definitions.rs +++ b/src/hir/definitions.rs @@ -63,7 +63,10 @@ impl std::hash::Hash for DefinitionType { types::Type::TypeVariable(_) => (), // Do nothing types::Type::Function(_) => (), types::Type::TypeApplication(_, _) => (), - types::Type::Ref(_) => (), + types::Type::Ref(shared, mutable, _) => { + shared.hash(state); + mutable.hash(state); + }, types::Type::Struct(field_names, _) => { for name in field_names { name.hash(state); @@ -91,7 +94,11 @@ fn definition_type_eq(a: &types::Type, b: &types::Type) -> bool { match (a, b) { (Type::Primitive(primitive1), Type::Primitive(primitive2)) => primitive1 == primitive2, (Type::UserDefined(id1), Type::UserDefined(id2)) => id1 == id2, - (Type::TypeVariable(_), Type::TypeVariable(_)) | (Type::Ref(_), Type::Ref(_)) => true, // Do nothing + (Type::TypeVariable(_), Type::TypeVariable(_)) => true, // Do nothing + // This will monomorphize separate definitions for polymorphically-owned references + // which is undesired. Defaulting them to shared/owned though can change behavior + // if traits are involved. + (Type::Ref(shared1, mutable1, _), Type::Ref(shared2, mutable2, _)) => shared1 == shared2 && mutable1 == mutable2, (Type::Function(f1), Type::Function(f2)) => { if f1.parameters.len() != f2.parameters.len() { return false; diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index ab042eb2..bea49a64 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -121,20 +121,16 @@ impl<'cache, 'contents> Lexer<'cache, 'contents> { ("Ptr", Token::PointerType), ("Bool", Token::BooleanType), ("Unit", Token::UnitType), - ("Ref", Token::Ref), ("mut", Token::Mut), ("true", Token::BooleanLiteral(true)), ("false", Token::BooleanLiteral(false)), ("and", Token::And), ("as", Token::As), ("block", Token::Block), - ("break", Token::Break), - ("continue", Token::Continue), ("do", Token::Do), ("effect", Token::Effect), ("else", Token::Else), ("extern", Token::Extern), - ("for", Token::For), ("fn", Token::Fn), ("given", Token::Given), ("handle", Token::Handle), @@ -142,14 +138,16 @@ impl<'cache, 'contents> Lexer<'cache, 'contents> { ("impl", Token::Impl), ("import", Token::Import), ("in", Token::In), - ("is", Token::Is), - ("isnt", Token::Isnt), ("loop", Token::Loop), ("match", Token::Match), ("module", Token::Module), ("not", Token::Not), ("or", Token::Or), + ("owned", Token::Owned), ("return", Token::Return), + ("ref", Token::Ref), + ("return", Token::Return), + ("shared", Token::Shared), ("then", Token::Then), ("trait", Token::Trait), ("type", Token::Type), diff --git a/src/lexer/token.rs b/src/lexer/token.rs index 307f520d..84cfd51a 100644 --- a/src/lexer/token.rs +++ b/src/lexer/token.rs @@ -85,20 +85,16 @@ pub enum Token { PointerType, BooleanType, UnitType, - Ref, Mut, // Keywords And, As, Block, - Break, - Continue, Do, Effect, Else, Extern, - For, Fn, Given, Handle, @@ -106,14 +102,15 @@ pub enum Token { Impl, Import, In, - Is, - Isnt, Loop, Match, Module, Not, Or, + Owned, + Ref, Return, + Shared, Then, Trait, Type, @@ -166,8 +163,6 @@ impl Token { And | As | At | In - | Is - | Isnt | Not | Or | EqualEqual @@ -186,7 +181,7 @@ impl Token { | LessThanOrEqual | GreaterThanOrEqual | Divide - | Ampersand + | Range ) } } @@ -271,20 +266,16 @@ impl Display for Token { Token::PointerType => write!(f, "'Ptr'"), Token::BooleanType => write!(f, "'bool'"), Token::UnitType => write!(f, "'unit'"), - Token::Ref => write!(f, "'ref'"), Token::Mut => write!(f, "'mut'"), // Keywords Token::And => write!(f, "'and'"), Token::As => write!(f, "'as'"), Token::Block => write!(f, "'block'"), - Token::Break => write!(f, "'break'"), - Token::Continue => write!(f, "'continue'"), Token::Do => write!(f, "'do'"), Token::Effect => write!(f, "'effect'"), Token::Else => write!(f, "'else'"), Token::Extern => write!(f, "'extern'"), - Token::For => write!(f, "'for'"), Token::Fn => write!(f, "'fn'"), Token::Given => write!(f, "'given'"), Token::Handle => write!(f, "'handle'"), @@ -292,14 +283,15 @@ impl Display for Token { Token::Impl => write!(f, "'impl'"), Token::Import => write!(f, "'import'"), Token::In => write!(f, "'in'"), - Token::Is => write!(f, "'is'"), - Token::Isnt => write!(f, "'isnt'"), Token::Loop => write!(f, "'loop'"), Token::Match => write!(f, "'match'"), Token::Module => write!(f, "'module'"), Token::Not => write!(f, "'not'"), Token::Or => write!(f, "'or'"), + Token::Owned => write!(f, "'owned'"), Token::Return => write!(f, "'return'"), + Token::Ref => write!(f, "'ref'"), + Token::Shared => write!(f, "'shared'"), Token::Then => write!(f, "'then'"), Token::Trait => write!(f, "'trait'"), Token::Type => write!(f, "'type'"), diff --git a/src/nameresolution/mod.rs b/src/nameresolution/mod.rs index af6a9519..ac67ec9d 100644 --- a/src/nameresolution/mod.rs +++ b/src/nameresolution/mod.rs @@ -589,7 +589,7 @@ impl<'c> NameResolver { Type::TypeVariable(_) => 0, Type::UserDefined(id) => cache[*id].args.len(), Type::TypeApplication(_, _) => 0, - Type::Ref(_) => 1, + Type::Ref(..) => 1, Type::Struct(_, _) => 0, Type::Effects(_) => 0, } @@ -739,14 +739,14 @@ impl<'c> NameResolver { Type::TypeApplication(Box::new(pair), args) }, - ast::Type::Reference(_) => { + ast::Type::Reference(sharednes, mutability, _) => { // When translating ref types, all have a hidden lifetime variable that is unified // under the hood by the compiler to determine the reference's stack lifetime. // This is never able to be manually specified by the programmer, so we use // next_type_variable_id on the cache rather than the NameResolver's version which // would add a name into scope. let lifetime_variable = cache.next_type_variable_id(self.let_binding_level); - Type::Ref(lifetime_variable) + Type::Ref(*sharednes, *mutability, lifetime_variable) }, } } diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 23b51271..2aa8e402 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -33,6 +33,7 @@ use crate::types::typechecker::TypeBindings; use crate::types::{self, LetBindingLevel, TypeInfoId}; use std::borrow::Cow; use std::collections::{BTreeMap, HashMap, HashSet}; +use std::fmt::Display; use std::rc::Rc; #[derive(Clone, Debug, Eq, PartialOrd, Ord)] @@ -205,7 +206,7 @@ pub enum Type<'a> { Pointer(Location<'a>), Boolean(Location<'a>), Unit(Location<'a>), - Reference(Location<'a>), + Reference(Sharedness, Mutability, Location<'a>), Function(Vec>, Box>, /*varargs:*/ bool, /*closure*/ bool, Location<'a>), TypeVariable(String, Location<'a>), UserDefined(String, Location<'a>), @@ -213,6 +214,40 @@ pub enum Type<'a> { Pair(Box>, Box>, Location<'a>), } +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Sharedness { + Polymorphic, + Shared, + Owned, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Mutability { + Polymorphic, + Immutable, + Mutable, +} + +impl Display for Sharedness { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Sharedness::Polymorphic => Ok(()), + Sharedness::Shared => write!(f, "shared"), + Sharedness::Owned => write!(f, "owned"), + } + } +} + +impl Display for Mutability { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Mutability::Polymorphic => write!(f, "mut?"), + Mutability::Immutable => Ok(()), + Mutability::Mutable => write!(f, "mut"), + } + } +} + /// The AST representation of a trait usage. /// A trait's definition would be a TraitDefinition node. /// This struct is used in e.g. `given` to list the required traits. @@ -801,7 +836,7 @@ impl<'a> Locatable<'a> for Type<'a> { Type::Pointer(location) => *location, Type::Boolean(location) => *location, Type::Unit(location) => *location, - Type::Reference(location) => *location, + Type::Reference(_, _, location) => *location, Type::Function(_, _, _, _, location) => *location, Type::TypeVariable(_, location) => *location, Type::UserDefined(_, location) => *location, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 3fd28112..ce050a6b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -25,12 +25,14 @@ pub mod pretty_printer; use std::{collections::HashSet, iter::FromIterator}; -use crate::error::location::Location; use crate::lexer::token::Token; +use crate::{error::location::Location, parser::ast::Mutability}; use ast::{Ast, Trait, Type, TypeDefinitionBody}; use combinators::*; use error::{ParseError, ParseResult}; +use self::ast::Sharedness; + type AstResult<'a, 'b> = ParseResult<'a, 'b, Ast<'b>>; /// The entry point to parsing. Parses an entire file, printing any @@ -178,7 +180,7 @@ parser!(type_alias loc = _ <- expect(Token::Type); name <- typename; args <- many0(identifier); - _ <- expect(Token::Is); + _ <- expect(Token::Equal); body !<- parse_type; Ast::type_definition(name, args, TypeDefinitionBody::Alias(body), loc) ); @@ -370,8 +372,6 @@ fn precedence(token: &Token) -> Option<(i8, bool)> { Token::Or => Some((4, false)), Token::And => Some((5, false)), Token::EqualEqual - | Token::Is - | Token::Isnt | Token::NotEqual | Token::GreaterThan | Token::LessThan @@ -597,7 +597,7 @@ fn function_arg_type<'a, 'b>(input: Input<'a, 'b>) -> ParseResult<'a, 'b, Type<' } fn parse_type_no_pair<'a, 'b>(input: Input<'a, 'b>) -> ParseResult<'a, 'b, Type<'b>> { - or(&[function_type, type_application, basic_type], "type")(input) + or(&[function_type, reference_type, type_application, basic_type], "type")(input) } fn basic_type<'a, 'b>(input: Input<'a, 'b>) -> ParseResult<'a, 'b, Type<'b>> { @@ -611,7 +611,7 @@ fn basic_type<'a, 'b>(input: Input<'a, 'b>) -> ParseResult<'a, 'b, Type<'b>> { Token::PointerType => pointer_type(input), Token::BooleanType => boolean_type(input), Token::UnitType => unit_type(input), - Token::Ref => reference_type(input), + Token::Ampersand => basic_reference_type(input), Token::Identifier(_) => type_variable(input), Token::TypeName(_) => user_defined_type(input), Token::ParenthesisLeft => parenthesized_type(input), @@ -861,10 +861,44 @@ parser!(unit_type loc -> 'b Type<'b> = ); parser!(reference_type loc -> 'b Type<'b> = - _ <- expect(Token::Ref); - Type::Reference(loc) + _ <- expect(Token::Ampersand); + sharedness <- sharedness; + mutability <- maybe(expect(Token::Mut)); + element <- maybe(reference_element_type); + { + let mutability = if mutability.is_some() { Mutability::Mutable } else { Mutability::Immutable }; + make_reference_type(Type::Reference(sharedness, mutability, loc), element, loc) + } +); + +// The basic reference type `&t` can be used without parenthesis in a type application +parser!(basic_reference_type loc -> 'b Type<'b> = + _ <- expect(Token::Ampersand); + element <- maybe(basic_type); + make_reference_type(Type::Reference(Sharedness::Polymorphic, Mutability::Immutable, loc), element, loc) +); + +parser!(reference_element_type loc -> 'b Type<'b> = + typ <- or(&[type_application, basic_type], "type"); + typ ); +fn make_reference_type<'b>(reference: Type<'b>, element: Option>, loc: Location<'b>) -> Type<'b> { + match element { + Some(element) => Type::TypeApplication(Box::new(reference), vec![element], loc), + None => reference, + } +} + +// Parses 'owned' or 'shared' on a reference type +fn sharedness<'a, 'b>(input: Input<'a, 'b>) -> ParseResult<'a, 'b, Sharedness> { + match input[0].0 { + Token::Shared => Ok((&input[1..], Sharedness::Shared, input[0].1)), + Token::Owned => Ok((&input[1..], Sharedness::Owned, input[0].1)), + _ => Ok((input, Sharedness::Polymorphic, input[0].1)), + } +} + parser!(type_variable loc -> 'b Type<'b> = name <- identifier; Type::TypeVariable(name, loc) diff --git a/src/parser/pretty_printer.rs b/src/parser/pretty_printer.rs index 097f7c54..0bd2bb42 100644 --- a/src/parser/pretty_printer.rs +++ b/src/parser/pretty_printer.rs @@ -1,7 +1,7 @@ //! Defines a simple pretty printer to print the Ast to stdout. //! Used for the golden tests testing parsing to ensure there //! are no parsing regressions. -use crate::parser::ast::{self, Ast}; +use crate::parser::ast::{self, Ast, Sharedness}; use crate::util::{fmap, join_with}; use std::fmt::{self, Display, Formatter}; use std::sync::atomic::AtomicUsize; @@ -98,7 +98,10 @@ impl<'a> Display for ast::Type<'a> { Pointer(_) => write!(f, "Ptr"), Boolean(_) => write!(f, "Bool"), Unit(_) => write!(f, "Unit"), - Reference(_) => write!(f, "Ref"), + Reference(shared, mutable, _) => { + let space = if *shared == Sharedness::Polymorphic { "" } else { " " }; + write!(f, "&{shared}{space}{mutable}") + } TypeVariable(name, _) => write!(f, "{}", name), UserDefined(name, _) => write!(f, "{}", name), Function(params, return_type, varargs, is_closure, _) => { diff --git a/src/types/mod.rs b/src/types/mod.rs index b0c442aa..05f7422c 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -9,6 +9,7 @@ use std::collections::BTreeMap; use crate::cache::{DefinitionInfoId, ModuleCache}; use crate::error::location::{Locatable, Location}; use crate::lexer::token::{FloatKind, IntegerKind}; +use crate::parser::ast::{Mutability, Sharedness}; use crate::util::fmap; use crate::{lifetimes, util}; @@ -102,7 +103,7 @@ pub enum Type { /// A region-allocated reference to some data. /// Contains a region variable that is unified with other refs during type /// inference. All these refs will be allocated in the same region. - Ref(lifetimes::LifetimeVariableId), + Ref(Sharedness, Mutability, lifetimes::LifetimeVariableId), /// A (row-polymorphic) struct type. Unlike normal rho variables, /// the type variable used here replaces the entire type if bound. @@ -190,7 +191,7 @@ impl Type { use Type::*; match self { Primitive(_) => None, - Ref(_) => None, + Ref(..) => None, Function(function) => function.return_type.union_constructor_variants(cache), TypeApplication(typ, _) => typ.union_constructor_variants(cache), UserDefined(id) => cache.type_infos[id.0].union_variants(), @@ -231,7 +232,7 @@ impl Type { function.environment.traverse_rec(cache, f); function.return_type.traverse_rec(cache, f); }, - Type::TypeVariable(id) | Type::Ref(id) => match &cache.type_bindings[id.0] { + Type::TypeVariable(id) | Type::Ref(_, _, id) => match &cache.type_bindings[id.0] { TypeBinding::Bound(binding) => binding.traverse_rec(cache, f), TypeBinding::Unbound(_, _) => (), }, @@ -273,7 +274,7 @@ impl Type { Type::Primitive(_) => (), Type::UserDefined(_) => (), Type::TypeVariable(_) => (), - Type::Ref(_) => (), + Type::Ref(..) => (), Type::Function(function) => { for parameter in &function.parameters { @@ -324,7 +325,7 @@ impl Type { let args = fmap(args, |arg| arg.approx_to_string()); format!("({} {})", constructor, args.join(" ")) }, - Type::Ref(id) => format!("(ref tv{})", id.0), + Type::Ref(shared, mutable, id) => format!("&'{} {}{}", id.0, shared, mutable), Type::Struct(fields, id) => { let fields = fmap(fields, |(name, typ)| format!("{}: {}", name, typ.approx_to_string())); format!("{{ {}, ..tv{} }}", fields.join(", "), id.0) diff --git a/src/types/typechecker.rs b/src/types/typechecker.rs index 04e8fa7c..e5e25601 100644 --- a/src/types/typechecker.rs +++ b/src/types/typechecker.rs @@ -30,7 +30,7 @@ use crate::cache::{DefinitionInfoId, DefinitionKind, EffectInfoId, ModuleCache, use crate::cache::{ImplScopeId, VariableId}; use crate::error::location::{Locatable, Location}; use crate::error::{Diagnostic, DiagnosticKind as D, TypeErrorKind, TypeErrorKind as TE}; -use crate::parser::ast::{self, ClosureEnvironment}; +use crate::parser::ast::{self, ClosureEnvironment, Sharedness, Mutability}; use crate::types::traits::{RequiredTrait, TraitConstraint, TraitConstraints}; use crate::types::typed::Typed; use crate::types::EffectSet; @@ -154,7 +154,7 @@ pub fn type_application_bindings(info: &TypeInfo<'_>, typeargs: &[Type], cache: /// Given `a` returns `ref a` fn ref_of(typ: Type, cache: &mut ModuleCache) -> Type { let new_var = next_type_variable_id(cache); - let constructor = Box::new(Type::Ref(new_var)); + let constructor = Box::new(Type::Ref(Sharedness::Polymorphic, Mutability::Polymorphic, new_var)); TypeApplication(constructor, vec![typ]) } diff --git a/src/types/typeprinter.rs b/src/types/typeprinter.rs index 4d50606d..13568e22 100644 --- a/src/types/typeprinter.rs +++ b/src/types/typeprinter.rs @@ -4,6 +4,7 @@ //! types/traits are displayed via `type.display(cache)` rather than directly having //! a Display impl. use crate::cache::{ModuleCache, TraitInfoId}; +use crate::parser::ast::{Sharedness, Mutability}; use crate::types::traits::{ConstraintSignature, ConstraintSignaturePrinter, RequiredTrait, TraitConstraintId}; use crate::types::typechecker::find_all_typevars; use crate::types::{FunctionType, PrimitiveType, Type, TypeBinding, TypeInfoId, TypeVariableId}; @@ -165,7 +166,7 @@ impl<'a, 'b> TypePrinter<'a, 'b> { Type::TypeVariable(id) => self.fmt_type_variable(*id, f), Type::UserDefined(id) => self.fmt_user_defined_type(*id, f), Type::TypeApplication(constructor, args) => self.fmt_type_application(constructor, args, f), - Type::Ref(lifetime) => self.fmt_ref(*lifetime, f), + Type::Ref(shared, mutable, lifetime) => self.fmt_ref(*shared, *mutable, *lifetime, f), Type::Struct(fields, rest) => self.fmt_struct(fields, *rest, f), Type::Effects(effects) => self.fmt_effects(effects, f), } @@ -277,11 +278,15 @@ impl<'a, 'b> TypePrinter<'a, 'b> { } } - fn fmt_ref(&self, lifetime: TypeVariableId, f: &mut Formatter) -> std::fmt::Result { + fn fmt_ref(&self, shared: Sharedness, mutable: Mutability, lifetime: TypeVariableId, f: &mut Formatter) -> std::fmt::Result { match &self.cache.type_bindings[lifetime.0] { TypeBinding::Bound(typ) => self.fmt_type(typ, f), TypeBinding::Unbound(..) => { - write!(f, "{}", "ref".blue())?; + let shared = shared.to_string(); + let mutable = mutable.to_string(); + let space = if shared.is_empty() { "" } else { " " }; + + write!(f, "{}{}{}{}", "&".blue(), shared.blue(), space, mutable.blue())?; if self.debug { match self.typevar_names.get(&lifetime) { diff --git a/stdlib/prelude.an b/stdlib/prelude.an index 4f735f34..a65d4ead 100644 --- a/stdlib/prelude.an +++ b/stdlib/prelude.an @@ -321,20 +321,20 @@ offset (ptr: Ptr t) (index: Usz) : Ptr t = // new_addr = addr + index * size_of (MkType: Type t) // transmute new_addr -deref (x: Ref t) : t = +deref (x: &t) : t = builtin "Deref" x deref_ptr (p: Ptr t) : t = deref <| transmute p ptr_store (p: Ptr a) (value: a) : Unit = - addr: Ref a = transmute p + addr: &a = transmute p addr := value array_insert (p: Ptr a) (index: Usz) (value: a) : Unit = offset p index |> ptr_store value -ptr_to_ref: Ptr a -> Ref a = transmute +ptr_to_ref: Ptr a -> &a = transmute (@) = deref @@ -416,7 +416,7 @@ impl Print (Maybe a) given Print a with | Some a -> printne a | None -> printne "None" -impl Print (Ref a) given Print a with +impl Print &a given Print a with printne r = printne @r unwrap (m: Maybe t) : t = @@ -517,7 +517,7 @@ with // // Some (if isNeg then -1 * sum else sum) -impl Eq (Ref t) given Eq t with +impl Eq &t given Eq t with (==) l r = deref l == deref r // This `given` clause is required by the current trait checker since t is generalized @@ -559,7 +559,7 @@ impl Iterator InFile String with else Some (infile, next_line infile) // TODO: manually construct a String from parts -// impl Cast (Ref Char) String with +// impl Cast &Char String with // cast c_string = String c_string (cast (strlen c_string)) // impl Eq String From ae31ff378196804bd4c5eafb71b77fd92439cc63 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Mon, 4 Mar 2024 15:09:08 -0600 Subject: [PATCH 2/4] Fix compiler errors --- src/hir/monomorphisation.rs | 16 +++++----- src/types/typechecker.rs | 61 +++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/hir/monomorphisation.rs b/src/hir/monomorphisation.rs index 0cebbd4a..fd2f9874 100644 --- a/src/hir/monomorphisation.rs +++ b/src/hir/monomorphisation.rs @@ -142,12 +142,12 @@ impl<'c> Context<'c> { let fuel = fuel - 1; match &self.cache.type_bindings[id.0] { - Bound(TypeVariable(id2) | Ref(id2)) => self.find_binding(*id2, fuel), + Bound(TypeVariable(id2) | Ref(_, _, id2)) => self.find_binding(*id2, fuel), Bound(binding) => Ok(binding), Unbound(..) => { for bindings in self.monomorphisation_bindings.iter().rev() { match bindings.get(&id) { - Some(TypeVariable(id2) | Ref(id2)) => return self.find_binding(*id2, fuel), + Some(TypeVariable(id2) | Ref(_, _, id2)) => return self.find_binding(*id2, fuel), Some(binding) => return Ok(binding), None => (), } @@ -204,7 +204,7 @@ impl<'c> Context<'c> { let args = fmap(args, |arg| self.follow_all_bindings_inner(arg, fuel)); TypeApplication(Box::new(con), args) }, - Ref(_) => typ.clone(), + Ref(..) => typ.clone(), Struct(fields, id) => match self.find_binding(*id, fuel) { Ok(binding) => self.follow_all_bindings_inner(binding, fuel), Err(_) => { @@ -346,7 +346,7 @@ impl<'c> Context<'c> { _ => unreachable!("Kind error inside size_of_type"), }, - Ref(_) => Self::ptr_size(), + Ref(..) => Self::ptr_size(), Struct(fields, rest) => { if let Ok(binding) = self.find_binding(*rest, RECURSION_LIMIT) { let binding = binding.clone(); @@ -519,7 +519,7 @@ impl<'c> Context<'c> { let typ = self.follow_bindings_shallow(typ); match typ { - Ok(Primitive(PrimitiveType::Ptr) | Ref(_)) => Type::Primitive(hir::PrimitiveType::Pointer), + Ok(Primitive(PrimitiveType::Ptr) | Ref(..)) => Type::Primitive(hir::PrimitiveType::Pointer), Ok(Primitive(PrimitiveType::IntegerType)) => { if self.is_type_variable(&args[0]) { // Default to i32 @@ -553,7 +553,7 @@ impl<'c> Context<'c> { } }, - Ref(_) => { + Ref(..) => { unreachable!( "Kind error during monomorphisation. Attempted to translate a `ref` without a type argument" ) @@ -1517,7 +1517,7 @@ impl<'c> Context<'c> { TypeApplication(typ, args) => { match typ.as_ref() { // Pass through ref types transparently - types::Type::Ref(_) => self.get_field_index(field_name, &args[0]), + types::Type::Ref(..) => self.get_field_index(field_name, &args[0]), // These last 2 cases are the same. They're duplicated to avoid another follow_bindings_shallow call. typ => self.get_field_index(field_name, typ), } @@ -1551,7 +1551,7 @@ impl<'c> Context<'c> { let ref_type = match lhs_type { types::Type::TypeApplication(constructor, args) => match self.follow_bindings_shallow(constructor.as_ref()) { - Ok(types::Type::Ref(_)) => Some(self.convert_type(&args[0])), + Ok(types::Type::Ref(..)) => Some(self.convert_type(&args[0])), _ => None, }, _ => None, diff --git a/src/types/typechecker.rs b/src/types/typechecker.rs index e5e25601..f81f2e4d 100644 --- a/src/types/typechecker.rs +++ b/src/types/typechecker.rs @@ -204,10 +204,13 @@ pub fn replace_all_typevars_with_bindings( UserDefined(id) => UserDefined(*id), // We must recurse on the lifetime variable since they are unified as normal type variables - Ref(lifetime) => match replace_typevar_with_binding(*lifetime, new_bindings, Ref, cache) { - TypeVariable(new_lifetime) => Ref(new_lifetime), - Ref(new_lifetime) => Ref(new_lifetime), - _ => unreachable!("Bound Ref lifetime to non-lifetime type"), + Ref(sharedness, mutability, lifetime) => { + let make_ref = |new_lifetime| Ref(*sharedness, *mutability, new_lifetime); + match replace_typevar_with_binding(*lifetime, new_bindings, make_ref, cache) { + TypeVariable(new_lifetime) => make_ref(new_lifetime), + new_ref @ Ref(..) => new_ref, + _ => unreachable!("Bound Ref lifetime to non-lifetime type"), + } }, TypeApplication(typ, args) => { @@ -240,7 +243,7 @@ pub fn replace_all_typevars_with_bindings( /// `default` should be either TypeVariable or Ref and controls which kind of type gets /// created that wraps the newly-instantiated TypeVariableId if one is made. fn replace_typevar_with_binding( - id: TypeVariableId, new_bindings: &mut TypeBindings, default: fn(TypeVariableId) -> Type, + id: TypeVariableId, new_bindings: &mut TypeBindings, default: impl FnOnce(TypeVariableId) -> Type, cache: &mut ModuleCache<'_>, ) -> Type { if let Bound(typ) = &cache.type_bindings[id.0] { @@ -249,8 +252,9 @@ fn replace_typevar_with_binding( var.clone() } else { let new_typevar = next_type_variable_id(cache); - new_bindings.insert(id, default(new_typevar)); - default(new_typevar) + let typ = default(new_typevar); + new_bindings.insert(id, typ.clone()); + typ } } @@ -275,10 +279,13 @@ pub fn bind_typevars(typ: &Type, type_bindings: &TypeBindings, cache: &ModuleCac }, UserDefined(id) => UserDefined(*id), - Ref(lifetime) => match bind_typevar(*lifetime, type_bindings, Ref, cache) { - TypeVariable(new_lifetime) => Ref(new_lifetime), - Ref(new_lifetime) => Ref(new_lifetime), - _ => unreachable!("Bound Ref lifetime to non-lifetime type"), + Ref(sharedness, mutability, lifetime) => { + let make_ref = |lifetime| Ref(*sharedness, *mutability, lifetime); + match bind_typevar(*lifetime, type_bindings, make_ref, cache) { + TypeVariable(new_lifetime) => make_ref(new_lifetime), + new_ref @ Ref(..) => new_ref, + _ => unreachable!("Bound Ref lifetime to non-lifetime type"), + } }, TypeApplication(typ, args) => { @@ -322,7 +329,7 @@ pub fn bind_typevars(typ: &Type, type_bindings: &TypeBindings, cache: &ModuleCac /// and it is found in the type_bindings. If a type_binding wasn't found, a /// default TypeVariable or Ref is constructed by passing the relevant constructor to `default`. fn bind_typevar( - id: TypeVariableId, type_bindings: &TypeBindings, default: fn(TypeVariableId) -> Type, cache: &ModuleCache<'_>, + id: TypeVariableId, type_bindings: &TypeBindings, default: impl FnOnce(TypeVariableId) -> Type, cache: &ModuleCache<'_>, ) -> Type { // TODO: This ordering of checking type_bindings first is important. // There seems to be an issue currently where forall-bound variables @@ -356,7 +363,7 @@ pub fn contains_any_typevars_from_list(typ: &Type, list: &[TypeVariableId], cach || contains_any_typevars_from_list(&function.effects, list, cache) }, - Ref(lifetime) => type_variable_contains_any_typevars_from_list(*lifetime, list, cache), + Ref(_, _, lifetime) => type_variable_contains_any_typevars_from_list(*lifetime, list, cache), TypeApplication(typ, args) => { contains_any_typevars_from_list(typ, list, cache) @@ -555,7 +562,7 @@ pub(super) fn occurs( .then_all(&function.parameters, |param| occurs(id, level, param, bindings, fuel, cache)), TypeApplication(typ, args) => occurs(id, level, typ, bindings, fuel, cache) .then_all(args, |arg| occurs(id, level, arg, bindings, fuel, cache)), - Ref(lifetime) => typevars_match(id, level, *lifetime, bindings, fuel, cache), + Ref(_, _, lifetime) => typevars_match(id, level, *lifetime, bindings, fuel, cache), Struct(fields, var_id) => typevars_match(id, level, *var_id, bindings, fuel, cache) .then_all(fields.iter().map(|(_, typ)| typ), |field| occurs(id, level, field, bindings, fuel, cache)), Effects(effects) => effects.occurs(id, level, bindings, fuel, cache), @@ -582,7 +589,7 @@ pub(super) fn typevars_match( /// Returns what a given type is bound to, following all typevar links until it reaches an Unbound one. pub fn follow_bindings_in_cache_and_map(typ: &Type, bindings: &UnificationBindings, cache: &ModuleCache<'_>) -> Type { match typ { - TypeVariable(id) | Ref(id) => match find_binding(*id, bindings, cache) { + TypeVariable(id) | Ref(_, _, id) => match find_binding(*id, bindings, cache) { Bound(typ) => follow_bindings_in_cache_and_map(&typ, bindings, cache), Unbound(..) => typ.clone(), }, @@ -592,7 +599,7 @@ pub fn follow_bindings_in_cache_and_map(typ: &Type, bindings: &UnificationBindin pub fn follow_bindings_in_cache(typ: &Type, cache: &ModuleCache<'_>) -> Type { match typ { - TypeVariable(id) | Ref(id) => match &cache.type_bindings[id.0] { + TypeVariable(id) | Ref(_, _, id) => match &cache.type_bindings[id.0] { Bound(typ) => follow_bindings_in_cache(typ, cache), Unbound(..) => typ.clone(), }, @@ -664,7 +671,11 @@ pub fn try_unify_with_bindings_inner<'b>( }, // Refs have a hidden lifetime variable we need to unify here - (Ref(a_lifetime), Ref(_)) => { + (Ref(shared1, mut1, a_lifetime), Ref(shared2, mut2, _)) => { + if shared1 != shared2 || mut1 != mut2 { + return Err(()); + } + try_unify_type_variable_with_bindings(*a_lifetime, t1, t2, bindings, location, cache) }, @@ -816,7 +827,7 @@ fn get_fields( } }, TypeApplication(constructor, args) => match follow_bindings_in_cache_and_map(constructor, bindings, cache) { - Ref(_) => get_fields(&args[0], &[], bindings, cache), + Ref(..) => get_fields(&args[0], &[], bindings, cache), other => get_fields(&other, args, bindings, cache), }, Struct(fields, rest) => match &cache.type_bindings[rest.0] { @@ -960,7 +971,7 @@ pub fn find_all_typevars(typ: &Type, polymorphic_only: bool, cache: &ModuleCache } type_variables }, - Ref(lifetime) => find_typevars_in_typevar_binding(*lifetime, polymorphic_only, cache), + Ref(_, _, lifetime) => find_typevars_in_typevar_binding(*lifetime, polymorphic_only, cache), Struct(fields, id) => match &cache.type_bindings[id.0] { Bound(t) => find_all_typevars(t, polymorphic_only, cache), Unbound(..) => { @@ -1672,11 +1683,7 @@ impl<'a> Inferable<'a> for ast::Definition<'a> { let previous_level = CURRENT_LEVEL.swap(level.0, Ordering::SeqCst); // t, traits - let mut result = infer(self.expr.as_mut(), cache); - if self.mutable { - let lifetime = next_type_variable_id(cache); - result.typ = Type::TypeApplication(Box::new(Type::Ref(lifetime)), vec![result.typ]); - } + let result = infer(self.expr.as_mut(), cache); // The rhs of a Definition must be inferred at a greater LetBindingLevel than // the lhs below. Here we use level for the rhs and level - 1 for the lhs @@ -1942,7 +1949,8 @@ impl<'a> Inferable<'a> for ast::Assignment<'a> { result.combine(&mut rhs, cache); let lifetime = next_type_variable_id(cache); - let mutref = Type::TypeApplication(Box::new(Type::Ref(lifetime)), vec![rhs.typ.clone()]); + let mut_ref = Type::Ref(Sharedness::Polymorphic, Mutability::Mutable, lifetime); + let mutref = Type::TypeApplication(Box::new(mut_ref), vec![rhs.typ.clone()]); match try_unify(&result.typ, &mutref, self.location, cache, TE::NeverShown) { Ok(bindings) => bindings.perform(cache), @@ -1959,7 +1967,8 @@ fn issue_assignment_error<'c>( // Try to offer a more specific error message let lifetime = next_type_variable_id(cache); let var = next_type_variable(cache); - let mutref = Type::TypeApplication(Box::new(Type::Ref(lifetime)), vec![var]); + let mutref = Type::Ref(Sharedness::Polymorphic, Mutability::Mutable, lifetime); + let mutref = Type::TypeApplication(Box::new(mutref), vec![var]); if let Err(msg) = try_unify(&mutref, lhs, lhs_loc, cache, TE::AssignToNonMutRef) { cache.push_full_diagnostic(msg); From 1c2d72b7a1d22d729b0fc8b0f2f2ee9dd4dea78b Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 4 Jul 2024 11:59:36 -0500 Subject: [PATCH 3/4] Update inkwell and llvm to 17.0 --- Cargo.lock | 586 ++++++++++++++++++++++---------------------- Cargo.toml | 2 +- README.md | 16 +- src/llvm/builtin.rs | 3 +- src/llvm/mod.rs | 23 +- 5 files changed, 314 insertions(+), 316 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e351076b..e7a919a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom", "once_cell", @@ -30,59 +30,60 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "anstream" -version = "0.6.4" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.1" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -123,51 +124,50 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "async-trait" -version = "0.1.76" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531b97fb4cd3dfdce92c35dedbfdc1f0b9d8091c8ca943d6dae340ef5012d514" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] name = "auto_impl" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", "cfg-if", "libc", "miniz_oxide", - "object 0.32.2", + "object 0.36.1", "rustc-demangle", ] @@ -179,9 +179,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitmaps" @@ -200,18 +200,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" [[package]] name = "cfg-if" @@ -221,9 +218,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.8" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" +checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" dependencies = [ "clap_builder", "clap_derive", @@ -231,9 +228,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.8" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" +checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" dependencies = [ "anstream", "anstyle", @@ -243,44 +240,43 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.4.4" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffe91f06a11b4b9420f62103854e90867812cd5d01557f853c5ee8e791b12ae" +checksum = "1d598e88f6874d4b888ed40c71efbcbf4076f1dfbae128a08a8c9e45f710605d" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "colored" -version = "2.0.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" dependencies = [ - "is-terminal", "lazy_static", "windows-sys 0.48.0", ] @@ -415,45 +411,37 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] [[package]] name = "crossbeam-deque" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", - "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "dashmap" @@ -462,7 +450,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown 0.14.2", + "hashbrown 0.14.5", "lock_api", "once_cell", "parking_lot_core", @@ -476,9 +464,9 @@ checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "env_logger" @@ -499,16 +487,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" -dependencies = [ - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "fixedbitset" version = "0.4.2" @@ -580,7 +558,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] @@ -624,9 +602,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -635,9 +613,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "goldentests" @@ -668,27 +646,27 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "humantime" @@ -732,18 +710,18 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.2", + "hashbrown 0.14.5", ] [[package]] name = "inkwell" -version = "0.2.0" -source = "git+https://github.com/TheDan64/inkwell?branch=master#7a09ad8a5f3b1fc416f95b5e1c97d33df0ab3f06" +version = "0.4.0" +source = "git+https://github.com/TheDan64/inkwell?branch=master#5c9f7fcbb0a667f7391b94beb65f1a670ad13221" dependencies = [ "either", "inkwell_internals", @@ -755,77 +733,78 @@ dependencies = [ [[package]] name = "inkwell_internals" -version = "0.8.0" -source = "git+https://github.com/TheDan64/inkwell?branch=master#7a09ad8a5f3b1fc416f95b5e1c97d33df0ab3f06" +version = "0.9.0" +source = "git+https://github.com/TheDan64/inkwell?branch=master#5c9f7fcbb0a667f7391b94beb65f1a670ad13221" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] name = "is-terminal" -version = "0.4.9" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ "hermit-abi", - "rustix", - "windows-sys 0.48.0", + "libc", + "windows-sys 0.52.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libmimalloc-sys" -version = "0.1.35" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3979b5c37ece694f1f5e51e7ecc871fdb0f517ed04ee45f88d15d6d553cb9664" +checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" dependencies = [ "cc", "libc", ] -[[package]] -name = "linux-raw-sys" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" - [[package]] name = "llvm-sys" -version = "160.1.3" +version = "170.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf51981ac0622b10fe4790763e3de1f3d68a0ee4222e03accaaab6731bd508d" +checksum = "bb8b6d5671d471fec5010c24daa7c031e172bfaab1c48497ef6185c75eed88a5" dependencies = [ + "anyhow", "cc", "lazy_static", "libc", - "regex", + "regex-lite", "semver", ] [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -833,9 +812,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lsp-types" @@ -861,33 +840,24 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "memoffset" -version = "0.9.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mimalloc" -version = "0.1.39" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa01922b5ea280a911e323e4d2fd24b7fe5cc4042e0d2cda3c40775cdc4bdc9c" +checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" dependencies = [ "libmimalloc-sys", ] [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -927,24 +897,24 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -952,15 +922,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -971,39 +941,39 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "petgraph" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.1.0", + "indexmap 2.2.6", ] [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -1011,44 +981,20 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1070,9 +1016,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -1080,9 +1026,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -1090,11 +1036,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.6.0", ] [[package]] @@ -1111,9 +1057,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.2" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -1123,20 +1069,26 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "region" @@ -1162,28 +1114,15 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustix" -version = "0.38.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" -dependencies = [ - "bitflags 2.4.1", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.48.0", -] +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scopeguard" @@ -1193,35 +1132,35 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.20" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.195" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -1230,13 +1169,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] @@ -1247,18 +1186,18 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] [[package]] name = "similar" -version = "2.3.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aeaf503862c419d66959f5d7ca015337d864e9c49485d771b732e2a20453597" +checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" [[package]] name = "sized-chunks" @@ -1287,18 +1226,18 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1309,26 +1248,15 @@ checksum = "e9557cb6521e8d009c51a8666f09356f4b817ba9ba0981a305bd86aee47bd35c" [[package]] name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "syn" -version = "1.0.109" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -1337,9 +1265,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "termcolor" @@ -1352,29 +1280,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" dependencies = [ "tinyvec_macros", ] @@ -1387,9 +1315,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "bytes", @@ -1406,27 +1334,26 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -1480,7 +1407,7 @@ checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] @@ -1508,7 +1435,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] @@ -1528,9 +1455,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -1540,18 +1467,18 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -1561,9 +1488,9 @@ dependencies = [ [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "version_check" @@ -1595,11 +1522,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -1627,7 +1554,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -1636,21 +1572,43 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.48.5", "windows_aarch64_msvc 0.48.5", "windows_i686_gnu 0.48.5", "windows_i686_msvc 0.48.5", "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.48.5", "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" @@ -1663,6 +1621,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.36.1" @@ -1675,6 +1639,18 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.36.1" @@ -1687,6 +1663,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" @@ -1699,12 +1681,24 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" @@ -1716,3 +1710,9 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index c67f3379..4ed28fab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ clap = { version = "4", features = ["derive"] } colored = "2.0.0" mimalloc = { version = "0.1.29", default-features = false } difference = "2.0.0" -inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm16-0", "llvm16-0-prefer-dynamic"], optional = true } +inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm17-0", "llvm17-0-prefer-dynamic"], optional = true } cranelift = "0.86.1" cranelift-module = "0.86.1" cranelift-jit = "0.86.1" diff --git a/README.md b/README.md index 2fbbc7c3..d645bc76 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ than development updates. You can also feel free to file issues or ask questions ### Building -Ante currently optionally requires llvm 16.0 while building. If you already have this installed with +Ante currently optionally requires llvm 17.0 while building. If you already have this installed with sources, you may be fine building with `cargo install --path .` alone. If cargo complains about not finding any suitable llvm version, you can either choose to build ante without the llvm backend via `cargo install --path . --no-default-features` or you can build llvm from @@ -66,23 +66,23 @@ source via [CMake](#CMake) as covered in the next sections. #### Linux and Mac -The easiest method to install llvm 16.0 would be through your package manager, making sure to install any `-dev` packages +The easiest method to install llvm 17.0 would be through your package manager, making sure to install any `-dev` packages if they are available for your distro. Once installed, if `cargo b` still cannot find the right version of llvm, you may -need to make sure to set the `LLVM_SYS_160_PREFIX` to the path llvm was installed to: +need to make sure to set the `LLVM_SYS_170_PREFIX` to the path llvm was installed to: ```bash -$ LLVM_SYS_160_PREFIX=$(llvm-config --obj-root) +$ LLVM_SYS_170_PREFIX=$(llvm-config --obj-root) ``` -If your distro ships a version other than llvm 16.0 you can try changing the inkwell dependency Ante's Cargo.toml. +If your distro ships a version other than llvm 17.0 you can try changing the inkwell dependency Ante's Cargo.toml. This dependency controls the llvm version expected and by default it is: ```toml -inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm16-0"], optional = true } +inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm17-0"], optional = true } ``` -Change the quoted llvm portion to `"llvm-15-0"` for example to build with llvm 15.0. Also don't forget that after changing -this version the environment variable's name will be different, using llvm 15.0 for example it would be `LLVM_SYS_150_PREFIX`. +Change the quoted llvm portion to `"llvm-16-0"` for example to build with llvm 16.0. Also don't forget that after changing +this version the environment variable's name will be different, using llvm 16.0 for example it would be `LLVM_SYS_160_PREFIX`. It is likely that versions older than this will not work since there have been API changes in LLVM itself and inkwell. 15.0 itself is also unverified. diff --git a/src/llvm/builtin.rs b/src/llvm/builtin.rs index 079d963f..85293b0c 100644 --- a/src/llvm/builtin.rs +++ b/src/llvm/builtin.rs @@ -11,7 +11,6 @@ use crate::hir::{Ast, Builtin, PrimitiveType, Type}; use crate::llvm::{CodeGen, Generator}; use inkwell::attributes::{Attribute, AttributeLoc}; -use inkwell::types::BasicType; use inkwell::values::{BasicValueEnum, IntValue}; use inkwell::{AddressSpace, FloatPredicate, IntPredicate}; @@ -168,7 +167,7 @@ fn eq_bool<'g>(a: IntValue<'g>, b: IntValue<'g>, generator: &mut Generator<'g>) fn deref_ptr<'g>(ptr: &Ast, typ: &Type, generator: &mut Generator<'g>) -> BasicValueEnum<'g> { let element_type = generator.convert_type(typ); - let ret = element_type.ptr_type(AddressSpace::default()); + let ret = generator.context.ptr_type(AddressSpace::default()); let ptr = ptr.codegen(generator).into_pointer_value(); let ptr = generator.builder.build_pointer_cast(ptr, ret, "bitcast").unwrap(); diff --git a/src/llvm/mod.rs b/src/llvm/mod.rs index 1260fd08..212b0cd8 100644 --- a/src/llvm/mod.rs +++ b/src/llvm/mod.rs @@ -27,7 +27,7 @@ use inkwell::basic_block::BasicBlock; use inkwell::builder::Builder; use inkwell::context::Context; use inkwell::module::{Linkage, Module}; -use inkwell::passes::{PassManager, PassManagerBuilder}; +use inkwell::passes::PassManager; use inkwell::targets::{CodeModel, FileType, RelocMode, TargetTriple}; use inkwell::targets::{InitializationConfig, Target, TargetMachine}; use inkwell::types::{BasicType, BasicTypeEnum, FunctionType}; @@ -164,15 +164,14 @@ impl<'g> Generator<'g> { fn optimize(&self, optimization_argument: char) { let config = InitializationConfig::default(); Target::initialize_native(&config).unwrap(); - let pass_manager_builder = PassManagerBuilder::create(); - let optimization_level = to_optimization_level(optimization_argument); - let size_level = to_size_level(optimization_argument); - pass_manager_builder.set_optimization_level(optimization_level); - pass_manager_builder.set_size_level(size_level); + let _optimization_level = to_optimization_level(optimization_argument); + let _size_level = to_size_level(optimization_argument); let pass_manager = PassManager::create(()); - pass_manager_builder.populate_module_pass_manager(&pass_manager); + + // No optimizations currently since the PassManagerBuilder was removed + // in addition to all the add_pass methods. pass_manager.run_on(&self.module); // TODO: It seems this method was removed; re-evaluate if inlining is still done @@ -264,10 +263,10 @@ impl<'g> Generator<'g> { PrimitiveType::Char => self.context.i8_type().into(), PrimitiveType::Boolean => self.context.bool_type().into(), PrimitiveType::Unit => self.context.bool_type().into(), - PrimitiveType::Pointer => self.context.i8_type().ptr_type(AddressSpace::default()).into(), + PrimitiveType::Pointer => self.context.ptr_type(AddressSpace::default()).into(), } }, - hir::Type::Function(f) => self.convert_function_type(f).ptr_type(AddressSpace::default()).into(), + hir::Type::Function(_) => self.context.ptr_type(AddressSpace::default()).into(), hir::Type::Tuple(tuple) => { let fields = fmap(tuple, |typ| self.convert_type(typ)); self.context.struct_type(&fields, true).into() @@ -335,7 +334,7 @@ impl<'g> Generator<'g> { let value = global.as_pointer_value(); - let cstring_type = self.context.i8_type().ptr_type(AddressSpace::default()); + let cstring_type = self.context.ptr_type(AddressSpace::default()); let cast = self .builder @@ -388,7 +387,7 @@ impl<'g> Generator<'g> { self.builder.build_store(alloca, value).expect("Could not create store during cast"); - let target_pointer_type = target_type.ptr_type(AddressSpace::default()); + let target_pointer_type = self.context.ptr_type(AddressSpace::default()); let cast = self.builder.build_pointer_cast(alloca, target_pointer_type, "cast").expect("Error creating pointer cast"); @@ -706,7 +705,7 @@ impl<'g> CodeGen<'g> for hir::Assignment { let rhs = self.rhs.codegen(generator); - let rhs_ptr = rhs.get_type().ptr_type(AddressSpace::default()); + let rhs_ptr = generator.context.ptr_type(AddressSpace::default()); let lhs = generator .builder .build_pointer_cast(lhs, rhs_ptr, "bitcast") From 6ebd8c3235eb543c04c3b622e20d56abb7bb4717 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 4 Jul 2024 13:03:36 -0500 Subject: [PATCH 4/4] Rename 'Ref' type to '&mut' --- examples/codegen/mutability.an | 2 +- examples/codegen/string_builder.an | 4 ++-- examples/nameresolution/type_decl.an | 4 ++-- examples/parsing/type_decl.an | 8 ++++---- src/hir/definitions.rs | 4 +++- src/lexer/mod.rs | 4 ++-- src/parser/mod.rs | 6 +++--- src/parser/pretty_printer.rs | 2 +- src/types/typechecker.rs | 19 +++++++++++++++---- src/types/typeprinter.rs | 6 ++++-- stdlib/HashMap.an | 12 ++++++------ stdlib/StringBuilder.an | 8 ++++---- stdlib/Vec.an | 18 +++++++++--------- 13 files changed, 56 insertions(+), 41 deletions(-) diff --git a/examples/codegen/mutability.an b/examples/codegen/mutability.an index d6b6e073..a2119fd8 100644 --- a/examples/codegen/mutability.an +++ b/examples/codegen/mutability.an @@ -6,7 +6,7 @@ print num mutate num print num -mutate (n: Ref I32) = +mutate (n: &mut I32) = x = double @n n := x diff --git a/examples/codegen/string_builder.an b/examples/codegen/string_builder.an index df9ce468..28e56781 100644 --- a/examples/codegen/string_builder.an +++ b/examples/codegen/string_builder.an @@ -1,11 +1,11 @@ import StringBuilder -sb: Ref StringBuilder = mut empty () +sb: &mut StringBuilder = mut empty () reserve sb 10 append sb "你好," append sb " World!" -print (to_string sb) +print (to_string @sb) // args: --delete-binary // expected stdout: 你好, World! diff --git a/examples/nameresolution/type_decl.an b/examples/nameresolution/type_decl.an index 5abe8e1f..2c4db879 100644 --- a/examples/nameresolution/type_decl.an +++ b/examples/nameresolution/type_decl.an @@ -1,7 +1,7 @@ type Struct1 = a:I32, b:F64, c:String -type Thingy is Struct1 +type Thingy = Struct1 type Generic a b = first: a, second: b @@ -17,7 +17,7 @@ type Option a = t = Just 1 -type UniquePtr a is Ref a +type MyRef a = &a // args: --check // expected stdout: diff --git a/examples/parsing/type_decl.an b/examples/parsing/type_decl.an index 46c79007..a24a9a67 100644 --- a/examples/parsing/type_decl.an +++ b/examples/parsing/type_decl.an @@ -11,10 +11,10 @@ type Maybe a = | Some a | None -type List a = | Nil | Cons a (ref (List a)) +type List a = | Nil | Cons a (&List a) -type UniquePtr a is ref a +type UniquePtr a = &a t = 3 : I32 @@ -24,6 +24,6 @@ t = 3 : I32 // (type Struct2 t = a: Thingy, b: (Generic t Thingy)); // (type Union1 ab = | Variant1 | Variant2 ); // (type Maybe a = | Some a| None ); -// (type List a = | Nil | Cons a (ref (List a))); -// (type UniquePtr a = (ref a)); +// (type List a = | Nil | Cons a (& (List a))); +// (type UniquePtr a = (& a)); // (t = (: 3 I32)) diff --git a/src/hir/definitions.rs b/src/hir/definitions.rs index 73cff068..199ea6bf 100644 --- a/src/hir/definitions.rs +++ b/src/hir/definitions.rs @@ -98,7 +98,9 @@ fn definition_type_eq(a: &types::Type, b: &types::Type) -> bool { // This will monomorphize separate definitions for polymorphically-owned references // which is undesired. Defaulting them to shared/owned though can change behavior // if traits are involved. - (Type::Ref(shared1, mutable1, _), Type::Ref(shared2, mutable2, _)) => shared1 == shared2 && mutable1 == mutable2, + (Type::Ref(shared1, mutable1, _), Type::Ref(shared2, mutable2, _)) => { + shared1 == shared2 && mutable1 == mutable2 + }, (Type::Function(f1), Type::Function(f2)) => { if f1.parameters.len() != f2.parameters.len() { return false; diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index bea49a64..0ecbb8ce 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -588,7 +588,7 @@ impl<'cache, 'contents> Iterator for Lexer<'cache, 'contents> { // This will overflow if there are mismatched parenthesis, // should we handle this inside the lexer, // or leave that to the parsing stage? - self.open_braces.parenthesis -= 1; + self.open_braces.parenthesis = self.open_braces.parenthesis.saturating_sub(1); self.advance_with(Token::ParenthesisRight) }, ('+', _) => self.advance_with(Token::Add), @@ -597,7 +597,7 @@ impl<'cache, 'contents> Iterator for Lexer<'cache, 'contents> { self.advance_with(Token::BracketLeft) }, (']', _) => { - self.open_braces.square -= 1; + self.open_braces.square = self.open_braces.square.saturating_sub(1); self.advance_with(Token::BracketRight) }, ('|', _) => self.advance_with(Token::Pipe), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index ce050a6b..8b98530d 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -172,7 +172,7 @@ parser!(type_definition loc = name <- typename; args <- many0(identifier); _ <- expect(Token::Equal); - body !<- type_definition_body; + body <- type_definition_body; Ast::type_definition(name, args, body, loc) ); @@ -181,7 +181,7 @@ parser!(type_alias loc = name <- typename; args <- many0(identifier); _ <- expect(Token::Equal); - body !<- parse_type; + body <- parse_type; Ast::type_definition(name, args, TypeDefinitionBody::Alias(body), loc) ); @@ -589,7 +589,7 @@ parser!(type_annotation loc = ); fn parse_type<'a, 'b>(input: Input<'a, 'b>) -> ParseResult<'a, 'b, Type<'b>> { - or(&[function_type, pair_type, type_application, basic_type], "type")(input) + or(&[function_type, pair_type, reference_type, type_application, basic_type], "type")(input) } fn function_arg_type<'a, 'b>(input: Input<'a, 'b>) -> ParseResult<'a, 'b, Type<'b>> { diff --git a/src/parser/pretty_printer.rs b/src/parser/pretty_printer.rs index 0bd2bb42..251eff91 100644 --- a/src/parser/pretty_printer.rs +++ b/src/parser/pretty_printer.rs @@ -101,7 +101,7 @@ impl<'a> Display for ast::Type<'a> { Reference(shared, mutable, _) => { let space = if *shared == Sharedness::Polymorphic { "" } else { " " }; write!(f, "&{shared}{space}{mutable}") - } + }, TypeVariable(name, _) => write!(f, "{}", name), UserDefined(name, _) => write!(f, "{}", name), Function(params, return_type, varargs, is_closure, _) => { diff --git a/src/types/typechecker.rs b/src/types/typechecker.rs index f81f2e4d..6d6853e1 100644 --- a/src/types/typechecker.rs +++ b/src/types/typechecker.rs @@ -30,7 +30,7 @@ use crate::cache::{DefinitionInfoId, DefinitionKind, EffectInfoId, ModuleCache, use crate::cache::{ImplScopeId, VariableId}; use crate::error::location::{Locatable, Location}; use crate::error::{Diagnostic, DiagnosticKind as D, TypeErrorKind, TypeErrorKind as TE}; -use crate::parser::ast::{self, ClosureEnvironment, Sharedness, Mutability}; +use crate::parser::ast::{self, ClosureEnvironment, Mutability, Sharedness}; use crate::types::traits::{RequiredTrait, TraitConstraint, TraitConstraints}; use crate::types::typed::Typed; use crate::types::EffectSet; @@ -329,7 +329,8 @@ pub fn bind_typevars(typ: &Type, type_bindings: &TypeBindings, cache: &ModuleCac /// and it is found in the type_bindings. If a type_binding wasn't found, a /// default TypeVariable or Ref is constructed by passing the relevant constructor to `default`. fn bind_typevar( - id: TypeVariableId, type_bindings: &TypeBindings, default: impl FnOnce(TypeVariableId) -> Type, cache: &ModuleCache<'_>, + id: TypeVariableId, type_bindings: &TypeBindings, default: impl FnOnce(TypeVariableId) -> Type, + cache: &ModuleCache<'_>, ) -> Type { // TODO: This ordering of checking type_bindings first is important. // There seems to be an issue currently where forall-bound variables @@ -673,7 +674,11 @@ pub fn try_unify_with_bindings_inner<'b>( // Refs have a hidden lifetime variable we need to unify here (Ref(shared1, mut1, a_lifetime), Ref(shared2, mut2, _)) => { if shared1 != shared2 || mut1 != mut2 { - return Err(()); + if *shared1 != Sharedness::Polymorphic && *shared2 != Sharedness::Polymorphic { + if *mut1 != Mutability::Polymorphic && *mut2 != Mutability::Polymorphic { + return Err(()); + } + } } try_unify_type_variable_with_bindings(*a_lifetime, t1, t2, bindings, location, cache) @@ -1683,7 +1688,13 @@ impl<'a> Inferable<'a> for ast::Definition<'a> { let previous_level = CURRENT_LEVEL.swap(level.0, Ordering::SeqCst); // t, traits - let result = infer(self.expr.as_mut(), cache); + let mut result = infer(self.expr.as_mut(), cache); + if self.mutable { + let lifetime = next_type_variable_id(cache); + let shared = Sharedness::Polymorphic; + let mutability = Mutability::Mutable; + result.typ = Type::TypeApplication(Box::new(Type::Ref(shared, mutability, lifetime)), vec![result.typ]); + } // The rhs of a Definition must be inferred at a greater LetBindingLevel than // the lhs below. Here we use level for the rhs and level - 1 for the lhs diff --git a/src/types/typeprinter.rs b/src/types/typeprinter.rs index 13568e22..0b97a484 100644 --- a/src/types/typeprinter.rs +++ b/src/types/typeprinter.rs @@ -4,7 +4,7 @@ //! types/traits are displayed via `type.display(cache)` rather than directly having //! a Display impl. use crate::cache::{ModuleCache, TraitInfoId}; -use crate::parser::ast::{Sharedness, Mutability}; +use crate::parser::ast::{Mutability, Sharedness}; use crate::types::traits::{ConstraintSignature, ConstraintSignaturePrinter, RequiredTrait, TraitConstraintId}; use crate::types::typechecker::find_all_typevars; use crate::types::{FunctionType, PrimitiveType, Type, TypeBinding, TypeInfoId, TypeVariableId}; @@ -278,7 +278,9 @@ impl<'a, 'b> TypePrinter<'a, 'b> { } } - fn fmt_ref(&self, shared: Sharedness, mutable: Mutability, lifetime: TypeVariableId, f: &mut Formatter) -> std::fmt::Result { + fn fmt_ref( + &self, shared: Sharedness, mutable: Mutability, lifetime: TypeVariableId, f: &mut Formatter, + ) -> std::fmt::Result { match &self.cache.type_bindings[lifetime.0] { TypeBinding::Bound(typ) => self.fmt_type(typ, f), TypeBinding::Unbound(..) => { diff --git a/stdlib/HashMap.an b/stdlib/HashMap.an index 9a94f4d4..7f208db8 100644 --- a/stdlib/HashMap.an +++ b/stdlib/HashMap.an @@ -15,14 +15,14 @@ trait Hash t with empty () = HashMap 0 0 (null ()) -clear (map: Ref (HashMap k v)) : Unit = +clear (map: &mut HashMap k v) : Unit = if map.capacity != 0 then repeat map.capacity fn i -> entry = mut deref_ptr <| offset map.entries i entry.&occupied := false entry.&tombstone := false -resize (map: Ref (HashMap k v)) (new_capacity: Usz) : Unit = +resize (map: &mut HashMap k v) (new_capacity: Usz) : Unit = if new_capacity > map.capacity then new_memory = calloc new_capacity (size_of (MkType : Type (Entry k v))) @@ -44,16 +44,16 @@ should_resize (map: HashMap k v) : Bool = scale_factor = 2 (map.len + 1) * scale_factor > map.capacity -insert (map: Ref (HashMap k v)) (key: k) (value: v) : Unit = +insert (map: &mut HashMap k v) (key: k) (value: v) : Unit = if should_resize @map then resize map ((map.capacity + 1) * 2) - iter_until (map: Ref (HashMap k v)) (key: k) (value: v) (start: Usz) (end: Usz) : Bool = + iter_until (map: &mut HashMap k v) (key: k) (value: v) (start: Usz) (end: Usz) : Bool = if start >= end then false else entry_ptr = offset (map.entries) start - entry = transmute entry_ptr : Ref (Entry k v) + entry = transmute entry_ptr : &mut Entry k v if entry.occupied then iter_until map key value (start + 1) end else @@ -105,7 +105,7 @@ get (map: HashMap k v) (key: k) : Maybe v = | None -> None -remove (map: ref (HashMap k v)) (key: k) : Maybe v = +remove (map: &mut HashMap k v) (key: k) : Maybe v = match get_entry (@map) key | None -> None | Some e2 -> diff --git a/stdlib/StringBuilder.an b/stdlib/StringBuilder.an index 5bb49b7f..d21fbfa1 100644 --- a/stdlib/StringBuilder.an +++ b/stdlib/StringBuilder.an @@ -6,7 +6,7 @@ type StringBuilder = empty () = StringBuilder (null ()) 0 0 // reserve space for at least n additional characters -reserve (s: Ref StringBuilder) (n: Usz) : Unit = +reserve (s: &mut StringBuilder) (n: Usz) : Unit = if s.length + n > s.cap then new_size = s.cap + n ptr = realloc s.data new_size @@ -19,15 +19,15 @@ reserve (s: Ref StringBuilder) (n: Usz) : Unit = s.&cap := new_size // append a string -append (s: Ref StringBuilder) (new_str: String) : Unit = +append (s: &mut StringBuilder) (new_str: String) : Unit = reserve s new_str.length memcpy (cast (cast s.data + s.length)) new_str.c_string (cast (new_str.length+1)) s.&length := s.length + new_str.length // convert to string -to_string (s: Ref StringBuilder) : String = +to_string (s: StringBuilder) : String = String (s.data) (s.length) impl Print StringBuilder with - printne (s: Ref StringBuilder) : Unit = + printne (s: StringBuilder) : Unit = print (to_string s) diff --git a/stdlib/Vec.an b/stdlib/Vec.an index f50a9af7..583b77d9 100644 --- a/stdlib/Vec.an +++ b/stdlib/Vec.an @@ -18,12 +18,12 @@ len v = v.len capacity v = v.cap //Fill Vec with items from the iterable -fill (v: Ref (Vec t)) iterable : Ref (Vec t) = +fill (v: &mut Vec t) iterable : &mut Vec t = iter iterable (push v _) v //reserve numElements in Vec v, elements will be uninitialized -reserve (v: Ref (Vec t)) (numElems: Usz) : Unit = +reserve (v: &mut Vec t) (numElems: Usz) : Unit = if v.len + numElems > v.cap then size = (v.cap + numElems) * size_of (MkType: Type t) ptr = realloc (v.data) size @@ -37,7 +37,7 @@ reserve (v: Ref (Vec t)) (numElems: Usz) : Unit = //push an element onto the end of the vector. //resizes if necessary -push (v: Ref (Vec t)) (elem: t) : Unit = +push (v: &mut Vec t) (elem: t) : Unit = if v.len >= v.cap then reserve v (if v.cap == 0usz then 1 else v.cap) @@ -46,7 +46,7 @@ push (v: Ref (Vec t)) (elem: t) : Unit = //pop the last element off if it exists //this will never resize the vector. -pop (v: Ref (Vec t)) : Maybe t = +pop (v: &mut Vec t) : Maybe t = if is_empty v then None else v.&len := v.len - 1 @@ -54,7 +54,7 @@ pop (v: Ref (Vec t)) : Maybe t = //remove the element at the given index and return it. //will error if the index is out of bounds. -remove_index (v: Ref (Vec t)) (idx:Usz) : t = +remove_index (v: &mut Vec t) (idx:Usz) : t = if idx == v.len - 1 then v.&len := v.len - 1 else if idx >= 0 and idx < v.len - 1 then @@ -71,7 +71,7 @@ remove_index (v: Ref (Vec t)) (idx:Usz) : t = //the vector or none if the element was not found. //Uses == to determine element equality. //returns the index where the element was found. -remove_first (v: Ref (Vec t)) (elem: t) : Maybe Usz = +remove_first (v: &mut Vec t) (elem: t) : Maybe Usz = loop (i = 0) -> if i >= v.len then None @@ -83,7 +83,7 @@ remove_first (v: Ref (Vec t)) (elem: t) : Maybe Usz = //Remove the given indices from the vector //Expects the indices to be in sorted order. //Will error if any index is out of bounds. -remove_indices (v: Ref (Vec t)) (idxs: Vec Usz) : Unit = +remove_indices (v: &mut Vec t) (idxs: Vec Usz) : Unit = moved = mut 0 iter (indices idxs) fn i -> cur = idxs.data#i @@ -105,7 +105,7 @@ remove_indices (v: Ref (Vec t)) (idxs: Vec Usz) : Unit = //remove all matching elements from the vector and //return the number of elements removed. //Uses = to determine element equality. -remove_all (v: Ref (Vec t)) (elem: t) : Usz = +remove_all (v: &mut Vec t) (elem: t) : Usz = idxs = mut empty () iter (indices @v) fn i -> if elem == v.data#i then @@ -118,7 +118,7 @@ remove_all (v: Ref (Vec t)) (elem: t) : Usz = //Remove an element by swapping it with the last element in O(1) time. //Returns true if a swap was performed or false otherwise. //Will not swap if the given index is the index of the last element. -swap_last (v: Ref (Vec t)) (idx:Usz) : Bool = +swap_last (v: &mut Vec t) (idx:Usz) : Bool = if idx >= v.len or idx + 1 == v.len then false else v.&len := v.len - 1