Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

only store start of operator in binops

author
Giacomo Cavalieri
committer
Louis Pilfold
date (May 21, 2026, 12:52 PM +0100) commit 252fd124 parent 3a3fdd08 change-id tlurllzt
+98 -117
+33 -4
compiler-core/src/ast.rs
··· 1567 1567 | BinOp::Concatenate => None, 1568 1568 } 1569 1569 } 1570 + 1571 + /// This returns how many characters this operator takes. 1572 + pub fn size(&self) -> u32 { 1573 + match self { 1574 + BinOp::LtInt 1575 + | BinOp::GtInt 1576 + | BinOp::RemainderInt 1577 + | BinOp::MultInt 1578 + | BinOp::AddInt 1579 + | BinOp::SubInt 1580 + | BinOp::DivInt => 1, 1581 + 1582 + BinOp::And 1583 + | BinOp::Or 1584 + | BinOp::Eq 1585 + | BinOp::NotEq 1586 + | BinOp::LtEqInt 1587 + | BinOp::GtEqInt 1588 + | BinOp::LtFloat 1589 + | BinOp::GtFloat 1590 + | BinOp::AddFloat 1591 + | BinOp::SubFloat 1592 + | BinOp::MultFloat 1593 + | BinOp::DivFloat 1594 + | BinOp::Concatenate => 2, 1595 + 1596 + BinOp::LtEqFloat | BinOp::GtEqFloat => 3, 1597 + } 1598 + } 1570 1599 } 1571 1600 1572 1601 #[derive(Debug, PartialEq, Eq, Clone, serde::Serialize, serde::Deserialize)] ··· 2260 2289 BinaryOperator { 2261 2290 location: SrcSpan, 2262 2291 operator: BinOp, 2263 - /// This is the span covering the operator itself. For example: 2292 + /// This is where the operator starts in the code. For example: 2264 2293 /// ```gleam 2265 - /// _ if 1.0 +. 2.3 == 3.0 -> todo 2266 - /// // ^^ This! 2294 + /// _ if 1.0 >=. 2.3 -> todo 2295 + /// // ^ Here! 2267 2296 /// ``` 2268 - operator_location: SrcSpan, 2297 + operator_start: u32, 2269 2298 left: Box<Self>, 2270 2299 right: Box<Self>, 2271 2300 },
+1 -1
compiler-core/src/ast/typed.rs
··· 85 85 location: SrcSpan, 86 86 type_: Arc<Type>, 87 87 operator: BinOp, 88 - operator_location: SrcSpan, 88 + operator_start: u32, 89 89 left: Box<Self>, 90 90 right: Box<Self>, 91 91 },
+1 -1
compiler-core/src/ast/untyped.rs
··· 62 62 BinOp { 63 63 location: SrcSpan, 64 64 operator: BinOp, 65 - operator_location: SrcSpan, 65 + operator_start: u32, 66 66 left: Box<Self>, 67 67 right: Box<Self>, 68 68 },
+10 -18
compiler-core/src/ast/visit.rs
··· 215 215 location: &'ast SrcSpan, 216 216 type_: &'ast Arc<Type>, 217 217 operator: &'ast BinOp, 218 - operator_location: &'ast SrcSpan, 218 + operator_start: &'ast u32, 219 219 left: &'ast TypedExpr, 220 220 right: &'ast TypedExpr, 221 221 ) { 222 - visit_typed_expr_bin_op( 223 - self, 224 - location, 225 - type_, 226 - operator, 227 - operator_location, 228 - left, 229 - right, 230 - ); 222 + visit_typed_expr_bin_op(self, location, type_, operator, operator_start, left, right); 231 223 } 232 224 233 225 fn visit_typed_expr_case( ··· 411 403 left: &'ast TypedClauseGuard, 412 404 right: &'ast TypedClauseGuard, 413 405 operator: &'ast BinOp, 414 - operator_location: &'ast SrcSpan, 406 + operator_start: &'ast u32, 415 407 location: &'ast SrcSpan, 416 408 ) { 417 - visit_typed_clause_guard_bin_op(self, left, right, operator, operator_location, location); 409 + visit_typed_clause_guard_bin_op(self, left, right, operator, operator_start, location); 418 410 } 419 411 420 412 fn visit_typed_clause_guard_var( ··· 1331 1323 location, 1332 1324 type_, 1333 1325 operator, 1334 - operator_location, 1326 + operator_start, 1335 1327 left, 1336 1328 right, 1337 - } => v.visit_typed_expr_bin_op(location, type_, operator, operator_location, left, right), 1329 + } => v.visit_typed_expr_bin_op(location, type_, operator, operator_start, left, right), 1338 1330 TypedExpr::Case { 1339 1331 location, 1340 1332 type_, ··· 1584 1576 _location: &'a SrcSpan, 1585 1577 _type_: &'a Arc<Type>, 1586 1578 _operator: &'a BinOp, 1587 - _operator_location: &'a SrcSpan, 1579 + _operator_start: &'a u32, 1588 1580 left: &'a TypedExpr, 1589 1581 right: &'a TypedExpr, 1590 1582 ) where ··· 1837 1829 right, 1838 1830 location, 1839 1831 operator, 1840 - operator_location, 1841 - } => v.visit_typed_clause_guard_bin_op(left, right, operator, operator_location, location), 1832 + operator_start, 1833 + } => v.visit_typed_clause_guard_bin_op(left, right, operator, operator_start, location), 1842 1834 super::ClauseGuard::Block { location: _, value } => v.visit_typed_clause_guard(value), 1843 1835 super::ClauseGuard::Not { 1844 1836 location: _, ··· 1895 1887 left: &'a TypedClauseGuard, 1896 1888 right: &'a TypedClauseGuard, 1897 1889 _operator: &'a BinOp, 1898 - _operator_location: &'a SrcSpan, 1890 + _operator_start: &'a u32, 1899 1891 _location: &'a SrcSpan, 1900 1892 ) where 1901 1893 V: Visit<'a> + ?Sized,
+6 -6
compiler-core/src/ast_folder.rs
··· 303 303 UntypedExpr::BinOp { 304 304 location, 305 305 operator, 306 - operator_location, 306 + operator_start, 307 307 left, 308 308 right, 309 - } => self.fold_bin_op(location, operator, operator_location, left, right), 309 + } => self.fold_bin_op(location, operator, operator_start, left, right), 310 310 311 311 UntypedExpr::PipeLine { expressions } => self.fold_pipe_line(expressions), 312 312 ··· 473 473 UntypedExpr::BinOp { 474 474 location, 475 475 operator, 476 - operator_location, 476 + operator_start, 477 477 left, 478 478 right, 479 479 } => { ··· 482 482 UntypedExpr::BinOp { 483 483 location, 484 484 operator, 485 - operator_location, 485 + operator_start, 486 486 left, 487 487 right, 488 488 } ··· 804 804 &mut self, 805 805 location: SrcSpan, 806 806 operator: BinOp, 807 - operator_location: SrcSpan, 807 + operator_start: u32, 808 808 left: Box<UntypedExpr>, 809 809 right: Box<UntypedExpr>, 810 810 ) -> UntypedExpr { 811 811 UntypedExpr::BinOp { 812 812 location, 813 813 operator, 814 - operator_location, 814 + operator_start, 815 815 left, 816 816 right, 817 817 }
+2 -2
compiler-core/src/inline.rs
··· 591 591 location, 592 592 type_, 593 593 operator, 594 - operator_location, 594 + operator_start, 595 595 left, 596 596 right, 597 597 } => TypedExpr::BinOp { 598 598 location, 599 599 type_, 600 600 operator, 601 - operator_location, 601 + operator_start, 602 602 left: self.boxed_expression(left), 603 603 right: self.boxed_expression(right), 604 604 },
+4 -9
compiler-core/src/parse.rs
··· 4925 4925 } 4926 4926 4927 4927 fn expr_op_reduction( 4928 - (token_start, token, token_end): Spanned, 4928 + (token_start, token, _token_end): Spanned, 4929 4929 left: UntypedExpr, 4930 4930 right: UntypedExpr, 4931 4931 ) -> UntypedExpr { ··· 4945 4945 end: right.location().end, 4946 4946 }, 4947 4947 operator, 4948 - operator_location: SrcSpan { 4949 - start: token_start, 4950 - end: token_end, 4951 - }, 4948 + operator_start: token_start, 4952 4949 left: Box::new(left), 4953 4950 right: Box::new(right), 4954 4951 }, ··· 4960 4957 } 4961 4958 4962 4959 fn clause_guard_reduction( 4963 - (start, token, end): Spanned, 4960 + (start, token, _end): Spanned, 4964 4961 left: UntypedClauseGuard, 4965 4962 right: UntypedClauseGuard, 4966 4963 ) -> UntypedClauseGuard { ··· 4971 4968 let left = Box::new(left); 4972 4969 let right = Box::new(right); 4973 4970 let operator = tok_to_binop(&token).expect("Token could not be converted to binop."); 4974 - let operator_location = SrcSpan::new(start, end); 4975 - 4976 4971 UntypedClauseGuard::BinaryOperator { 4977 4972 location, 4978 4973 operator, 4979 - operator_location, 4974 + operator_start: start, 4980 4975 left, 4981 4976 right, 4982 4977 }
+2 -8
compiler-core/src/parse/snapshots/gleam_core__parse__tests__arithmetic_in_guards.snap
··· 72 72 end: 35, 73 73 }, 74 74 operator: Eq, 75 - operator_location: SrcSpan { 76 - start: 31, 77 - end: 33, 78 - }, 75 + operator_start: 31, 79 76 left: BinaryOperator { 80 77 location: SrcSpan { 81 78 start: 25, 82 79 end: 30, 83 80 }, 84 81 operator: AddInt, 85 - operator_location: SrcSpan { 86 - start: 27, 87 - end: 28, 88 - }, 82 + operator_start: 27, 89 83 left: Var { 90 84 location: SrcSpan { 91 85 start: 25,
+1 -4
compiler-core/src/parse/snapshots/gleam_core__parse__tests__assert_statement.snap
··· 15 15 end: 15, 16 16 }, 17 17 operator: NotEq, 18 - operator_location: SrcSpan { 19 - start: 10, 20 - end: 12, 21 - }, 18 + operator_start: 10, 22 19 left: Int { 23 20 location: SrcSpan { 24 21 start: 7,
+3 -12
compiler-core/src/parse/snapshots/gleam_core__parse__tests__case_guard_with_nested_blocks.snap
··· 44 44 end: 40, 45 45 }, 46 46 operator: Or, 47 - operator_location: SrcSpan { 48 - start: 36, 49 - end: 38, 50 - }, 47 + operator_start: 36, 51 48 left: Block { 52 49 location: SrcSpan { 53 50 start: 16, ··· 59 56 end: 33, 60 57 }, 61 58 operator: Or, 62 - operator_location: SrcSpan { 63 - start: 20, 64 - end: 22, 65 - }, 59 + operator_start: 20, 66 60 left: Constant( 67 61 Int { 68 62 location: SrcSpan { ··· 84 78 end: 31, 85 79 }, 86 80 operator: Or, 87 - operator_location: SrcSpan { 88 - start: 27, 89 - end: 29, 90 - }, 81 + operator_start: 27, 91 82 left: Constant( 92 83 Int { 93 84 location: SrcSpan {
+1 -4
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_has_lower_precedence_than_binop.snap
··· 17 17 end: 10, 18 18 }, 19 19 operator: AddInt, 20 - operator_location: SrcSpan { 21 - start: 7, 22 - end: 8, 23 - }, 20 + operator_start: 7, 24 21 left: Int { 25 22 location: SrcSpan { 26 23 start: 5,
+1 -4
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_message_1.snap
··· 15 15 end: 42, 16 16 }, 17 17 operator: Eq, 18 - operator_location: SrcSpan { 19 - start: 9, 20 - end: 11, 21 - }, 18 + operator_start: 9, 22 19 left: Int { 23 20 location: SrcSpan { 24 21 start: 7,
+1 -4
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_messages_1.snap
··· 15 15 end: 42, 16 16 }, 17 17 operator: Eq, 18 - operator_location: SrcSpan { 19 - start: 9, 20 - end: 11, 21 - }, 18 + operator_start: 9, 22 19 left: Int { 23 20 location: SrcSpan { 24 21 start: 7,
+1 -4
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_messages_3.snap
··· 22 22 end: 18, 23 23 }, 24 24 operator: Eq, 25 - operator_location: SrcSpan { 26 - start: 14, 27 - end: 16, 28 - }, 25 + operator_start: 14, 29 26 left: Int { 30 27 location: SrcSpan { 31 28 start: 12,
+1 -4
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_block.snap
··· 24 24 end: 12, 25 25 }, 26 26 operator: AddInt, 27 - operator_location: SrcSpan { 28 - start: 9, 29 - end: 10, 30 - }, 27 + operator_start: 9, 31 28 left: Int { 32 29 location: SrcSpan { 33 30 start: 7,
+1 -4
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_complex_expression.snap
··· 33 33 end: 32, 34 34 }, 35 35 operator: Concatenate, 36 - operator_location: SrcSpan { 37 - start: 22, 38 - end: 24, 39 - }, 36 + operator_start: 22, 40 37 left: Var { 41 38 location: SrcSpan { 42 39 start: 17,
+2 -8
compiler-core/src/parse/snapshots/gleam_core__parse__tests__string_concatenation_in_case_clause_guard.snap
··· 78 78 end: 89, 79 79 }, 80 80 operator: Eq, 81 - operator_location: SrcSpan { 82 - start: 73, 83 - end: 75, 84 - }, 81 + operator_start: 73, 85 82 left: BinaryOperator { 86 83 location: SrcSpan { 87 84 start: 52, 88 85 end: 72, 89 86 }, 90 87 operator: Concatenate, 91 - operator_location: SrcSpan { 92 - start: 62, 93 - end: 64, 94 - }, 88 + operator_start: 62, 95 89 left: Var { 96 90 location: SrcSpan { 97 91 start: 52,
+18 -12
compiler-core/src/type_/expression.rs
··· 512 512 UntypedExpr::BinOp { 513 513 location, 514 514 operator, 515 - operator_location, 515 + operator_start, 516 516 left, 517 517 right, 518 - } => Ok(self.infer_binop(operator, operator_location, *left, *right, location)), 518 + } => Ok(self.infer_binop(operator, operator_start, *left, *right, location)), 519 519 520 520 UntypedExpr::FieldAccess { 521 521 label_location, ··· 1851 1851 fn infer_binop( 1852 1852 &mut self, 1853 1853 operator: BinOp, 1854 - operator_location: SrcSpan, 1854 + operator_start: u32, 1855 1855 left: UntypedExpr, 1856 1856 right: UntypedExpr, 1857 1857 location: SrcSpan, ··· 1875 1875 return TypedExpr::BinOp { 1876 1876 location, 1877 1877 operator, 1878 - operator_location, 1878 + operator_start, 1879 1879 type_: bool(), 1880 1880 left: Box::new(left), 1881 1881 right: Box::new(right), ··· 1921 1921 if operator.is_float_operator() && left.type_().is_int() && right.type_().is_int() { 1922 1922 self.problems.error(Error::FloatOperatorOnInts { 1923 1923 operator, 1924 - location: operator_location, 1924 + location: SrcSpan::new(operator_start, operator_start + operator.size()), 1925 1925 }) 1926 1926 } else if operator.is_int_operator() && left.type_().is_float() && right.type_().is_float() 1927 1927 { 1928 1928 self.problems.error(Error::IntOperatorOnFloats { 1929 1929 operator, 1930 - location: operator_location, 1930 + location: SrcSpan::new(operator_start, operator_start + operator.size()), 1931 1931 }) 1932 1932 } else if operator == BinOp::AddInt && left.type_().is_string() && right.type_().is_string() 1933 1933 { 1934 1934 self.problems.error(Error::StringConcatenationWithAddInt { 1935 - location: operator_location, 1935 + location: SrcSpan::new(operator_start, operator_start + operator.size()), 1936 1936 }) 1937 1937 } else { 1938 1938 // In all other cases we just report an error for each of the operands. ··· 1957 1957 TypedExpr::BinOp { 1958 1958 location, 1959 1959 operator, 1960 - operator_location, 1960 + operator_start, 1961 1961 type_: output_type, 1962 1962 left: Box::new(left), 1963 1963 right: Box::new(right), ··· 2643 2643 ClauseGuard::BinaryOperator { 2644 2644 location, 2645 2645 operator, 2646 - operator_location, 2646 + operator_start, 2647 2647 left, 2648 2648 right, 2649 2649 } => { ··· 2684 2684 if left.type_().is_float() && right.type_().is_float() { 2685 2685 self.problems.error(Error::IntOperatorOnFloats { 2686 2686 operator, 2687 - location: operator_location, 2687 + location: SrcSpan::new( 2688 + operator_start, 2689 + operator_start + operator.size(), 2690 + ), 2688 2691 }); 2689 2692 } else { 2690 2693 if let Err(error) = unify(int(), left.type_()) { ··· 2713 2716 if left.type_().is_int() && right.type_().is_int() { 2714 2717 self.problems.error(Error::FloatOperatorOnInts { 2715 2718 operator, 2716 - location: operator_location, 2719 + location: SrcSpan::new( 2720 + operator_start, 2721 + operator_start + operator.size(), 2722 + ), 2717 2723 }); 2718 2724 } else { 2719 2725 if let Err(error) = unify(float(), left.type_()) { ··· 2744 2750 ClauseGuard::BinaryOperator { 2745 2751 location, 2746 2752 operator, 2747 - operator_location, 2753 + operator_start, 2748 2754 left: Box::new(left), 2749 2755 right: Box::new(right), 2750 2756 }
+9 -8
language-server/src/code_action.rs
··· 8697 8697 left: Arc<Type>, 8698 8698 right: Arc<Type>, 8699 8699 operator: ast::BinOp, 8700 - operator_location: SrcSpan, 8700 + operator_start: u32, 8701 8701 ) { 8702 + let operator_location = SrcSpan::new(operator_start, operator_start + operator.size()); 8702 8703 if operator.is_int_operator() && left.is_float() && right.is_float() { 8703 8704 self.fix = operator 8704 8705 .float_equivalent() ··· 8733 8734 left: &'ast TypedClauseGuard, 8734 8735 right: &'ast TypedClauseGuard, 8735 8736 operator: &'ast ast::BinOp, 8736 - operator_location: &'ast SrcSpan, 8737 + operator_start: &'ast u32, 8737 8738 location: &'ast SrcSpan, 8738 8739 ) { 8739 8740 let binop_range = self.edits.src_span_to_lsp_range(*location); ··· 8741 8742 return; 8742 8743 } 8743 8744 8744 - self.try_fix(left.type_(), right.type_(), *operator, *operator_location); 8745 + self.try_fix(left.type_(), right.type_(), *operator, *operator_start); 8745 8746 8746 8747 ast::visit::visit_typed_clause_guard_bin_op( 8747 8748 self, 8748 8749 left, 8749 8750 right, 8750 8751 operator, 8751 - operator_location, 8752 + operator_start, 8752 8753 location, 8753 8754 ); 8754 8755 } ··· 8758 8759 location: &'ast SrcSpan, 8759 8760 type_: &'ast Arc<Type>, 8760 8761 operator: &'ast ast::BinOp, 8761 - operator_location: &'ast SrcSpan, 8762 + operator_start: &'ast u32, 8762 8763 left: &'ast TypedExpr, 8763 8764 right: &'ast TypedExpr, 8764 8765 ) { ··· 8767 8768 return; 8768 8769 } 8769 8770 8770 - self.try_fix(left.type_(), right.type_(), *operator, *operator_location); 8771 + self.try_fix(left.type_(), right.type_(), *operator, *operator_start); 8771 8772 8772 8773 ast::visit::visit_typed_expr_bin_op( 8773 8774 self, 8774 8775 location, 8775 8776 type_, 8776 8777 operator, 8777 - operator_location, 8778 + operator_start, 8778 8779 left, 8779 8780 right, 8780 8781 ); ··· 9133 9134 _location: &'ast SrcSpan, 9134 9135 _type_: &'ast Arc<Type>, 9135 9136 _operator: &'ast ast::BinOp, 9136 - _operator_location: &'ast SrcSpan, 9137 + _operator_start: &'ast u32, 9137 9138 left: &'ast TypedExpr, 9138 9139 right: &'ast TypedExpr, 9139 9140 ) {