Merge branch 'main' into allow-try-in-statements

This commit is contained in:
Sam Mohr 2024-12-01 00:35:18 -08:00
commit 29c8759bc0
No known key found for this signature in database
GPG key ID: EA41D161A3C1BC99
320 changed files with 6977 additions and 2011 deletions

View file

@ -113,8 +113,6 @@ pub struct SpecializationId(NonZeroU32);
static_assertions::assert_eq_size!(SpecializationId, Option<SpecializationId>);
pub enum SpecializationLambdaSetError {}
/// A key into a particular implementation of an ability member for an opaque type.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct ImplKey {

View file

@ -132,7 +132,7 @@ pub struct AbleVariable {
pub first_seen: Region,
}
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct IntroducedVariables {
pub wildcards: Vec<Loc<Variable>>,
pub lambda_sets: Vec<Variable>,

View file

@ -929,7 +929,7 @@ pub struct FxExpectation {
pub ann_region: Option<Region>,
}
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FxCallKind {
Call(Option<Symbol>),
Stmt,
@ -943,7 +943,7 @@ pub struct FxSuffixConstraint {
pub region: Region,
}
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FxSuffixKind {
Let(Symbol),
Pattern(Symbol),
@ -957,9 +957,16 @@ impl FxSuffixKind {
Self::UnsuffixedRecordField => IdentSuffix::None,
}
}
pub fn symbol(&self) -> Option<&Symbol> {
match self {
Self::Let(symbol) | Self::Pattern(symbol) => Some(symbol),
Self::UnsuffixedRecordField => None,
}
}
}
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ExpectEffectfulReason {
Stmt,
Ignored,

View file

@ -718,8 +718,6 @@ fn deep_copy_expr_help<C: CopyEnv>(env: &mut C, copied: &mut Vec<Variable>, expr
symbol: *symbol,
},
TypedHole(v) => TypedHole(sub!(*v)),
RuntimeError(err) => RuntimeError(err.clone()),
}
}

View file

@ -453,7 +453,6 @@ fn expr<'a>(c: &Ctx, p: EPrec, f: &'a Arena<'a>, e: &'a Expr) -> DocBuilder<'a,
Dbg { .. } => todo!(),
Expect { .. } => todo!(),
Return { .. } => todo!(),
TypedHole(_) => todo!(),
RuntimeError(_) => todo!(),
}
}

View file

@ -63,7 +63,7 @@ use std::io::Read;
use std::path::PathBuf;
use std::sync::Arc;
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct Def {
pub loc_pattern: Loc<Pattern>,
pub loc_expr: Loc<Expr>,
@ -91,7 +91,7 @@ impl Def {
}
}
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum DefKind {
/// A def that introduces identifiers
Let,
@ -123,7 +123,7 @@ impl DefKind {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct Annotation {
pub signature: Type,
pub introduced_variables: IntroducedVariables,

View file

@ -2,7 +2,7 @@ use crate::pattern::Pattern;
use roc_region::all::{Loc, Region};
use roc_types::types::{AnnotationSource, PReason, Reason};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum Expected<T> {
NoExpectation(T),
FromAnnotation(Loc<Pattern>, usize, AnnotationSource, T),
@ -10,7 +10,7 @@ pub enum Expected<T> {
}
/// Like Expected, but for Patterns.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum PExpected<T> {
NoExpectation(T),
ForReason(PReason, T, Region),

View file

@ -85,7 +85,55 @@ impl Display for IntValue {
}
}
#[derive(Clone, Debug)]
impl IntValue {
pub fn as_u8(self) -> u8 {
self.as_u128() as u8
}
pub fn as_i8(self) -> i8 {
self.as_i128() as i8
}
pub fn as_u16(self) -> u16 {
self.as_u128() as u16
}
pub fn as_i16(self) -> i16 {
self.as_i128() as i16
}
pub fn as_u32(self) -> u32 {
self.as_u128() as u32
}
pub fn as_i32(self) -> i32 {
self.as_i128() as i32
}
pub fn as_u64(self) -> u64 {
self.as_u128() as u64
}
pub fn as_i64(self) -> i64 {
self.as_i128() as i64
}
pub fn as_u128(self) -> u128 {
match self {
IntValue::I128(i128) => i128::from_ne_bytes(i128) as u128,
IntValue::U128(u128) => u128::from_ne_bytes(u128),
}
}
pub fn as_i128(self) -> i128 {
match self {
IntValue::I128(i128) => i128::from_ne_bytes(i128),
IntValue::U128(u128) => u128::from_ne_bytes(u128) as i128,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Expr {
// Literals
@ -104,7 +152,7 @@ pub enum Expr {
loc_elems: Vec<Loc<Expr>>,
},
// An ingested files, it's bytes, and the type variable.
// An ingested files, its bytes, and the type variable.
IngestedFile(Box<PathBuf>, Arc<Vec<u8>>, Variable),
// Lookups
@ -131,7 +179,7 @@ pub enum Expr {
/// The actual condition of the when expression.
loc_cond: Box<Loc<Expr>>,
cond_var: Variable,
/// Result type produced by the branches.
/// Type of each branch (and therefore the type of the entire `when` expression)
expr_var: Variable,
region: Region,
/// The branches of the when, and the type of the condition that they expect to be matched
@ -285,14 +333,11 @@ pub enum Expr {
return_var: Variable,
},
/// Rendered as empty box in editor
TypedHole(Variable),
/// Compiles, but will crash if reached
RuntimeError(RuntimeError),
}
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ExpectLookup {
pub symbol: Symbol,
pub var: Variable,
@ -363,7 +408,7 @@ impl Expr {
Self::Dbg { .. } => Category::Expect,
// these nodes place no constraints on the expression's type
Self::TypedHole(_) | Self::RuntimeError(..) => Category::Unknown,
Self::RuntimeError(..) => Category::Unknown,
}
}
@ -470,7 +515,7 @@ impl Expr {
/// Stores exhaustiveness-checking metadata for a closure argument that may
/// have an annotated type.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AnnotatedMark {
pub annotation_var: Variable,
pub exhaustive: ExhaustiveMark,
@ -494,7 +539,7 @@ impl AnnotatedMark {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct ClosureData {
pub function_type: Variable,
pub closure_type: Variable,
@ -591,7 +636,7 @@ impl StructAccessorData {
/// An opaque wrapper like `@Foo`, which is equivalent to `\p -> @Foo p`
/// These are desugared to closures, but we distinguish them so we can have
/// better error messages during constraint generation.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct OpaqueWrapFunctionData {
pub opaque_name: Symbol,
pub opaque_var: Variable,
@ -663,7 +708,7 @@ impl OpaqueWrapFunctionData {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct Field {
pub var: Variable,
// The region of the full `foo: f bar`, rather than just `f bar`
@ -687,7 +732,7 @@ impl Recursive {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct WhenBranchPattern {
pub pattern: Loc<Pattern>,
/// Degenerate branch patterns are those that don't fully bind symbols that the branch body
@ -696,7 +741,7 @@ pub struct WhenBranchPattern {
pub degenerate: bool,
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct WhenBranch {
pub patterns: Vec<WhenBranchPattern>,
pub value: Loc<Expr>,
@ -2147,7 +2192,6 @@ pub fn inline_calls(var_store: &mut VarStore, expr: Expr) -> Expr {
| other @ ParamsVar { .. }
| other @ AbilityMember(..)
| other @ RunLowLevel { .. }
| other @ TypedHole { .. }
| other @ ForeignCall { .. }
| other @ OpaqueWrapFunction(_)
| other @ Crash { .. }
@ -3512,7 +3556,6 @@ pub(crate) fn get_lookup_symbols(expr: &Expr) -> Vec<ExpectLookup> {
| Expr::RecordAccessor(_)
| Expr::SingleQuote(..)
| Expr::EmptyRecord
| Expr::TypedHole(_)
| Expr::RuntimeError(_)
| Expr::ImportParams(_, _, None)
| Expr::OpaqueWrapFunction(_) => {}

View file

@ -1055,7 +1055,6 @@ fn fix_values_captured_in_closure_expr(
| ParamsVar { .. }
| AbilityMember(..)
| EmptyRecord
| TypedHole { .. }
| RuntimeError(_)
| ZeroArgumentTag { .. }
| RecordAccessor { .. } => {}

View file

@ -19,7 +19,7 @@ use roc_types::types::{LambdaSet, OptAbleVar, PatternCategory, Type};
/// A pattern, including possible problems (e.g. shadowing) so that
/// codegen can generate a runtime error if this pattern is reached.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub enum Pattern {
Identifier(Symbol),
As(Box<Loc<Pattern>>, Symbol),
@ -198,7 +198,7 @@ impl Pattern {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct ListPatterns {
pub patterns: Vec<Loc<Pattern>>,
/// Where a rest pattern splits patterns before and after it, if it does at all.
@ -207,6 +207,7 @@ pub struct ListPatterns {
/// [ .., A, B ] -> patterns = [A, B], rest = 0
/// [ A, .., B ] -> patterns = [A, B], rest = 1
/// [ A, B, .. ] -> patterns = [A, B], rest = 2
/// Optionally, the rest pattern can be named - e.g. `[ A, B, ..others ]`
pub opt_rest: Option<(usize, Option<Loc<Symbol>>)>,
}
@ -228,7 +229,7 @@ impl ListPatterns {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct RecordDestruct {
pub var: Variable,
pub label: Lowercase,
@ -236,14 +237,14 @@ pub struct RecordDestruct {
pub typ: DestructType,
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct TupleDestruct {
pub var: Variable,
pub destruct_index: usize,
pub typ: (Variable, Loc<Pattern>),
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub enum DestructType {
Required,
Optional(Variable, Loc<Expr>),

View file

@ -406,7 +406,6 @@ pub fn walk_expr<V: Visitor>(visitor: &mut V, expr: &Expr, var: Variable) {
} => {
visitor.visit_expr(&return_value.value, return_value.region, *return_var);
}
Expr::TypedHole(_) => { /* terminal */ }
Expr::RuntimeError(..) => { /* terminal */ }
}
}