Merge remote-tracking branch 'remote/main' into builtin-task

This commit is contained in:
Luke Boswell 2024-07-29 16:05:51 +10:00
commit eca453d07f
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
367 changed files with 14084 additions and 12080 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)]
@ -147,10 +133,6 @@ pub enum BinOp {
GreaterThanOrEq,
And,
Or,
Assignment,
IsAliasType,
IsOpaqueType,
Backpassing,
// lowest precedence
}
@ -161,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!(),
}
}
}
@ -195,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]
}
@ -233,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() {
@ -256,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() {
@ -268,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

@ -1175,41 +1175,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" => {