Merge branch 'main' into typecheck-module-params

This commit is contained in:
Agus Zubiaga 2024-08-07 18:55:33 -03:00
commit 762799052e
No known key found for this signature in database
600 changed files with 30337 additions and 17782 deletions

View file

@ -3,7 +3,7 @@ use self::BinOp::*;
use std::cmp::Ordering;
use std::fmt;
const PRECEDENCES: [(BinOp, u8); 20] = [
const PRECEDENCES: [(BinOp, u8); 16] = [
(Caret, 8),
(Star, 7),
(Slash, 7),
@ -20,14 +20,9 @@ const PRECEDENCES: [(BinOp, u8); 20] = [
(GreaterThanOrEq, 2),
(And, 1),
(Or, 0),
// These should never come up
(Assignment, 255),
(IsAliasType, 255),
(IsOpaqueType, 255),
(Backpassing, 255),
];
const ASSOCIATIVITIES: [(BinOp, Associativity); 20] = [
const ASSOCIATIVITIES: [(BinOp, Associativity); 16] = [
(Caret, RightAssociative),
(Star, LeftAssociative),
(Slash, LeftAssociative),
@ -44,14 +39,9 @@ const ASSOCIATIVITIES: [(BinOp, Associativity); 20] = [
(GreaterThanOrEq, NonAssociative),
(And, RightAssociative),
(Or, RightAssociative),
// These should never come up
(Assignment, LeftAssociative),
(IsAliasType, LeftAssociative),
(IsOpaqueType, LeftAssociative),
(Backpassing, LeftAssociative),
];
const DISPLAY_STRINGS: [(BinOp, &str); 20] = [
const DISPLAY_STRINGS: [(BinOp, &str); 16] = [
(Caret, "^"),
(Star, "*"),
(Slash, "/"),
@ -68,10 +58,6 @@ const DISPLAY_STRINGS: [(BinOp, &str); 20] = [
(GreaterThanOrEq, ">="),
(And, "&&"),
(Or, "||"),
(Assignment, "="),
(IsAliasType, ":"),
(IsOpaqueType, ":="),
(Backpassing, "<-"),
];
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -89,8 +75,21 @@ pub enum CalledVia {
/// e.g. "$(first) $(last)" is transformed into Str.concat (Str.concat first " ") last.
StringInterpolation,
/// This call is the result of desugaring a Record Builder field.
/// This call is the result of desugaring an old style Record Builder field.
/// e.g. succeed { a <- get "a" } is transformed into (get "a") (succeed \a -> { a })
OldRecordBuilder,
/// This call is the result of desugaring a map2-based Record Builder field. e.g.
/// ```roc
/// { Task.parallel <-
/// foo: get "a",
/// bar: get "b",
/// }
/// ```
/// is transformed into
/// ```roc
/// Task.parallel (get "a") (get "b") \foo, bar -> { foo, bar }
/// ```
RecordBuilder,
/// This call is the result of desugaring a Task.await from `!` syntax
@ -134,10 +133,6 @@ pub enum BinOp {
GreaterThanOrEq,
And,
Or,
Assignment,
IsAliasType,
IsOpaqueType,
Backpassing,
// lowest precedence
}
@ -148,7 +143,6 @@ impl BinOp {
Caret | Star | Slash | Percent | Plus | Minus | LessThan | GreaterThan => 1,
DoubleSlash | Equals | NotEquals | LessThanOrEq | GreaterThanOrEq | And | Or
| Pizza => 2,
Assignment | IsAliasType | IsOpaqueType | Backpassing => unreachable!(),
}
}
}
@ -182,25 +176,13 @@ pub enum Associativity {
impl BinOp {
pub fn associativity(self) -> Associativity {
// The compiler should never pass any of these to this function!
debug_assert_ne!(self, Assignment);
debug_assert_ne!(self, IsAliasType);
debug_assert_ne!(self, IsOpaqueType);
debug_assert_ne!(self, Backpassing);
const ASSOCIATIVITY_TABLE: [Associativity; 20] = generate_associativity_table();
const ASSOCIATIVITY_TABLE: [Associativity; 16] = generate_associativity_table();
ASSOCIATIVITY_TABLE[self as usize]
}
fn precedence(self) -> u8 {
// The compiler should never pass any of these to this function!
debug_assert_ne!(self, Assignment);
debug_assert_ne!(self, IsAliasType);
debug_assert_ne!(self, IsOpaqueType);
debug_assert_ne!(self, Backpassing);
const PRECEDENCE_TABLE: [u8; 20] = generate_precedence_table();
const PRECEDENCE_TABLE: [u8; 16] = generate_precedence_table();
PRECEDENCE_TABLE[self as usize]
}
@ -220,19 +202,14 @@ impl Ord for BinOp {
impl std::fmt::Display for BinOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
debug_assert_ne!(*self, Assignment);
debug_assert_ne!(*self, IsAliasType);
debug_assert_ne!(*self, IsOpaqueType);
debug_assert_ne!(*self, Backpassing);
const DISPLAY_TABLE: [&str; 20] = generate_display_table();
const DISPLAY_TABLE: [&str; 16] = generate_display_table();
write!(f, "{}", DISPLAY_TABLE[*self as usize])
}
}
const fn generate_precedence_table() -> [u8; 20] {
let mut table = [0u8; 20];
const fn generate_precedence_table() -> [u8; 16] {
let mut table = [0u8; 16];
let mut i = 0;
while i < PRECEDENCES.len() {
@ -243,8 +220,8 @@ const fn generate_precedence_table() -> [u8; 20] {
table
}
const fn generate_associativity_table() -> [Associativity; 20] {
let mut table = [NonAssociative; 20];
const fn generate_associativity_table() -> [Associativity; 16] {
let mut table = [NonAssociative; 16];
let mut i = 0;
while i < ASSOCIATIVITIES.len() {
@ -255,8 +232,8 @@ const fn generate_associativity_table() -> [Associativity; 20] {
table
}
const fn generate_display_table() -> [&'static str; 20] {
let mut table = [""; 20];
const fn generate_display_table() -> [&'static str; 16] {
let mut table = [""; 16];
let mut i = 0;
while i < DISPLAY_STRINGS.len() {

View file

@ -36,10 +36,6 @@ pub enum LowLevel {
ListReplaceUnsafe,
ListConcat,
ListPrepend,
ListMap,
ListMap2,
ListMap3,
ListMap4,
ListSortWith,
ListSublist,
ListDropAt,
@ -48,6 +44,8 @@ pub enum LowLevel {
ListIsUnique,
ListClone,
ListConcatUtf8,
ListIncref,
ListDecref,
NumAdd,
NumAddWrap,
NumAddChecked,
@ -135,7 +133,7 @@ pub enum LowLevel {
macro_rules! higher_order {
() => {
ListMap | ListMap2 | ListMap3 | ListMap4 | ListSortWith
ListSortWith
};
}
@ -152,10 +150,6 @@ impl LowLevel {
use LowLevel::*;
match self {
ListMap => 1,
ListMap2 => 2,
ListMap3 => 3,
ListMap4 => 4,
ListSortWith => 1,
_ => unreachable!(),
}
@ -211,10 +205,6 @@ macro_rules! map_symbol_to_lowlevel {
// these are higher-order lowlevels. these need the surrounding
// function to provide enough type information for code generation
LowLevel::ListMap => unreachable!(),
LowLevel::ListMap2 => unreachable!(),
LowLevel::ListMap3 => unreachable!(),
LowLevel::ListMap4 => unreachable!(),
LowLevel::ListSortWith => unreachable!(),
// (un)boxing is handled in a custom way
@ -239,6 +229,8 @@ macro_rules! map_symbol_to_lowlevel {
LowLevel::RefCountIncDataPtr => unimplemented!(),
LowLevel::RefCountDecDataPtr=> unimplemented!(),
LowLevel::RefCountIsUnique => unimplemented!(),
LowLevel::ListIncref => unimplemented!(),
LowLevel::ListDecref => unimplemented!(),
LowLevel::SetJmp => unimplemented!(),
LowLevel::LongJmp => unimplemented!(),

View file

@ -462,6 +462,13 @@ impl<'a, T> PackageQualified<'a, T> {
}
}
pub fn unqualified(&self) -> Option<&T> {
match self {
PackageQualified::Unqualified(name) => Some(name),
PackageQualified::Qualified(_, _) => None,
}
}
pub fn package_shorthand(&self) -> Option<&'a str> {
match self {
PackageQualified::Unqualified(_) => None,
@ -1087,41 +1094,42 @@ define_builtins! {
16 GENERIC_EQ_REF: "#generic_eq_by_ref" // equality of arbitrary layouts, passed as an opaque pointer
17 GENERIC_RC_REF: "#generic_rc_by_ref" // refcount of arbitrary layouts, passed as an opaque pointer
18 GENERIC_COPY_REF: "#generic_copy_by_ref" // copy of arbitrary layouts, passed as an opaque pointer
18 GENERIC_EQ: "#generic_eq" // internal function that checks generic equality
19 GENERIC_EQ: "#generic_eq" // internal function that checks generic equality
// a user-defined function that we need to capture in a closure
// see e.g. Set.walk
19 USER_FUNCTION: "#user_function"
20 USER_FUNCTION: "#user_function"
// A caller (wrapper) that we pass to zig for it to be able to call Roc functions
20 ZIG_FUNCTION_CALLER: "#zig_function_caller"
21 ZIG_FUNCTION_CALLER: "#zig_function_caller"
// a caller (wrapper) for comparison
21 GENERIC_COMPARE_REF: "#generic_compare_ref"
22 GENERIC_COMPARE_REF: "#generic_compare_ref"
// used to initialize parameters in borrow.rs
22 EMPTY_PARAM: "#empty_param"
23 EMPTY_PARAM: "#empty_param"
// used by the dev backend to store the pointer to where to store large return types
23 RET_POINTER: "#ret_pointer"
24 RET_POINTER: "#ret_pointer"
// used in wasm dev backend to mark temporary values in the VM stack
24 WASM_TMP: "#wasm_tmp"
25 WASM_TMP: "#wasm_tmp"
// the _ used in mono when a specialized symbol is deleted
25 REMOVED_SPECIALIZATION: "#removed_specialization"
26 REMOVED_SPECIALIZATION: "#removed_specialization"
// used in dev backend
26 DEV_TMP: "#dev_tmp"
27 DEV_TMP2: "#dev_tmp2"
28 DEV_TMP3: "#dev_tmp3"
29 DEV_TMP4: "#dev_tmp4"
30 DEV_TMP5: "#dev_tmp5"
27 DEV_TMP: "#dev_tmp"
28 DEV_TMP2: "#dev_tmp2"
29 DEV_TMP3: "#dev_tmp3"
30 DEV_TMP4: "#dev_tmp4"
31 DEV_TMP5: "#dev_tmp5"
31 ATTR_INVALID: "#attr_invalid"
32 ATTR_INVALID: "#attr_invalid"
32 CLONE: "#clone" // internal function that clones a value into a buffer
33 CLONE: "#clone" // internal function that clones a value into a buffer
}
// Fake module for synthesizing and storing derived implementations
1 DERIVED_SYNTH: "#Derived" => {