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

Configure Feed

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

gleam / CHANGELOG.md
15 kB 516 lines
1# Changelog 2 3## Unreleased 4 5### Compiler 6 7- The compiler can now tell if some branches with bit array patterns are 8 unreachable. For example, the following code: 9 10 ```gleam 11 case payload { 12 <<first_byte, _:bits>> -> first_byte 13 <<1, _:bits>> -> 1 14 _ -> 0 15 } 16 ``` 17 18 Will raise the following warning: 19 20 ``` 21 warning: Unreachable case clause 22 ┌─ /src/bit_array.gleam:4:5 23 24 4 │ <<1, _:bits>> -> 1 25 │ ^^^^^^^^^^^^^^^^^^ 26 This case clause cannot be reached as a previous clause matches the same 27 values. 28 Hint: It can be safely removed. 29 ``` 30 31 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 32 33- The code generated for pattern matching on the JavaScript target has been 34 improved to be more efficient and perform as little checks as possible. 35 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 36 37- The compiler now raises a warning when it can tell that an integer segment 38 with a literal value is going to be truncated. For example, if you wrote this: 39 40 ```gleam 41 <<258>> 42 ``` 43 44 The compiler will now warn you: 45 46 ```txt 47 warning: Truncated bit array segment 48 ┌─ /src/main.gleam:4:5 49 50 4 │ <<258>> 51 │ ^^^ You can safely replace this with 2 52 53 This segment is 1 byte long, but 258 doesn't fit in that many bytes. It 54 would be truncated by taking its its first byte, resulting in the value 2. 55 ``` 56 57 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 58 59- The compiler will now include labels in the error message when a `case` 60 expression is inexhaustive. For example, this code: 61 62 ```gleam 63 pub type Person { 64 Person(name: String, age: Int) 65 } 66 67 pub fn classify(person: Person) { 68 case person { 69 Person(name: "John", age: 27) -> todo 70 Person(name: _, age: 42) -> todo 71 } 72 } 73 ``` 74 75 Will produces this error: 76 77 ``` 78 error: Inexhaustive patterns 79 ┌─ /src/main.gleam:6:3 80 81 6 │ ╭ case person { 82 7 │ │ Person(name: "John", age: 27) -> todo 83 8 │ │ Person(name: _, age: 42) -> todo 84 9 │ │ } 85 │ ╰───^ 86 87 This case expression does not have a pattern for all possible values. If it 88 is run on one of the values without a pattern then it will crash. 89 90 The missing patterns are: 91 92 Person(name:, age:) 93 ``` 94 95 ([Surya Rose](https://github.com/GearsDatapacks)) 96 97- The analysis of lists, tuples, negation operators, `panic`, `echo` and `todo` 98 is now fault tolerant, meaning that the compiler will not stop reporting 99 errors as soon as it finds one. 100 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 101 102- The error message for types used with the wrong number of arguments has been 103 improved. For example, this piece of code: 104 105 ```gleam 106 type Wibble(a) 107 108 type Wobble { 109 Wobble(Wibble) 110 } 111 ``` 112 113 Produces the following error: 114 115 ```txt 116 error: Incorrect arity 117 ┌─ /src/one/two.gleam:5:10 118119 5 │ Wobble(Wibble) 120 │ ^^^^^^ Expected 1 type argument, got 0 121 122 `Wibble` requires 1 type argument but none where provided. 123 ``` 124 125 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 126 127- You can now use the `assert` keyword by itself to test a boolean expression. 128 If the expression evaluates to `False` at runtime, the `assert` statement 129 will cause the program to panic, with information about the expression that 130 was asserted. 131 132 For example: 133 134 ```gleam 135 pub fn ok_error_test() { 136 assert result.is_ok(Ok(10)) 137 assert result.is_error(Error("Some error")) 138 assert Ok(1) != Error(1) 139 assert result.is_error(Ok(42)) // panic: Assertion failed 140 } 141 ``` 142 143 A custom panic message can also be provided in order to add extra information: 144 145 ```gleam 146 pub fn identity_test() { 147 assert function.identity(True) as "Identity of True should never be False" 148 } 149 ``` 150 151 ([Surya Rose](https://github.com/GearsDatapacks)) 152 153- The compiler will now emit a warning when the return value of a call to a 154 function without side effects is unused. For example the following code: 155 156 ```gleam 157 fn add(a, b) { a + b } 158 ``` 159 160 Will produce the following warning: 161 162 ``` 163 warning: Unused value 164 ┌─ /src/main.gleam:4:3 165166 4 │ add(1, 2) 167 │ ^^^^^^^^^ This value is never used 168 169 This expression computes a value without any side effects, but then the 170 value isn't used at all. You might way to assign it to a variable, or 171 delete the expression entirely if it's not needed. 172 ``` 173 174 ([Surya Rose](https://github.com/GearsDatapacks)) 175 176- The compiler will now generate more efficient code for `let assert` on the 177 Erlang target. 178 ([Surya Rose](https://github.com/GearsDatapacks)) 179 180- The compiler will now reject bit array segment patterns whose constant size is 181 zero or negative. Previously a zero or negative sized segment would crash the 182 compiler. 183 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 184 185- The compiler will not generate needless code for unused pattern variables. 186 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 187 188- Function parameters are now fault tolerant, meaning that type-checking can 189 continue to occur if a function references invalid type in its signature. 190 ([Surya Rose](https://github.com/GearsDatapacks)) 191 192- The compiler is now fault tolerant when analysing patterns for custom types, 193 meaning it won't stop at the first error it encounters (for example if a 194 constructor is wrong). 195 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 196 197### Build tool 198 199- The build tool now supports placing modules in a directory called `dev`, 200 which like `test`, is only for development code. 201 ([Surya Rose](https://github.com/GearsDatapacks)) 202 203- There is now a new CLI command, `gleam dev`, which runs the `$PACKAGE_dev` 204 module, for running development entrypoints. 205 ([Surya Rose](https://github.com/GearsDatapacks)) 206 207- Updated the Erlang shipment POSIX entrypoint script to add an exec statement 208 so the Erlang process replaces the shell's process and can receive signals 209 when deployed. 210 ([Christopher De Vries](https://github.com/devries)) 211 212- The build tool now provides additional information when printing warnings for 213 deprecated environment variables. 214 ([Surya Rose](https://github.com/GearsDatapacks)) 215 216- When generating documentation, the build tool now prints type variable using 217 the same names as were used in the code for function signatures. For example, 218 this code: 219 220 ```gleam 221 pub fn to_list(entries: List(#(key, value))) -> Dict(key, value) { 222 ... 223 } 224 ``` 225 226 Previously would have been printed as: 227 228 ```gleam 229 pub fn to_list(entries: List(#(a, b))) -> Dict(a, b) 230 ``` 231 232 But now is rendered as the following: 233 234 ```gleam 235 pub fn to_list(entries: List(#(key, value))) -> Dict(key, value) 236 ``` 237 238 ([Surya Rose](https://github.com/GearsDatapacks)) 239 240- When generating documentation, types from other modules are now rendered with 241 their module qualifiers. Hovering over them shows the full path to their module. 242 For example, this code: 243 244 ```gleam 245 import gleam/dynamic/decode 246 247 pub fn something_decoder() -> decode.Decoder(Something) { 248 ... 249 } 250 ``` 251 252 Will now generate the following documentation: 253 254 ```gleam 255 pub fn something_decoder() -> decode.Decoder(Something) 256 ``` 257 258 And hovering over the `decode.Decoder` text will show the following: 259 260 ```txt 261 gleam/dynamic/decode.{type Decoder} 262 ``` 263 264 ([Surya Rose](https://github.com/GearsDatapacks)) 265 266- When generating documentation, types in rendered documentation code will now 267 link to their corresponding documentation pages. 268 ([Surya Rose](https://github.com/GearsDatapacks)) 269 270### Language server 271 272- The code action to add missing labels to function now also works in patterns: 273 274 ```gleam 275 pub type Person { 276 Person(name: String, age: Int, job: String) 277 } 278 279 pub fn age(person: Person) { 280 let Person(age:) = person 281 age 282 } 283 ``` 284 285 Becomes: 286 287 ```gleam 288 pub type Person { 289 Person(name: String, age: Int, job: String) 290 } 291 292 pub fn age(person: Person) { 293 let Person(age:, name:, job:) = person 294 age 295 } 296 ``` 297 298 ([Surya Rose](https://github.com/GearsDatapacks)) 299 300- The JSON encoding function that the language server code action generates is 301 now named `$TYPENAME_to_json` instead of `encode_$TYPENAME`. This is to remove 302 ambiguity with functions that encode to other formats, and to make the 303 function easier to discover by searching. 304 305 ([Louis Pilfold](https://github.com/lpil)) 306 307- The code action to add missing patterns to a `case` expression now includes 308 labels in the generated patterns. For example: 309 310 ```gleam 311 pub type Person { 312 Person(name: String, age: Int) 313 } 314 315 pub fn classify(person: Person) { 316 case person { 317 Person(name: "John", age: 27) -> todo 318 Person(name: _, age: 42) -> todo 319 } 320 } 321 ``` 322 323 Will now become: 324 325 ```gleam 326 pub type Person { 327 Person(name: String, age: Int) 328 } 329 330 pub fn classify(person: Person) { 331 case person { 332 Person(name: "John", age: 27) -> todo 333 Person(name: _, age: 42) -> todo 334 Person(name:, age:) -> todo 335 } 336 } 337 ``` 338 339 ([Surya Rose](https://github.com/GearsDatapacks)) 340 341- The language server now provides hover, autocomplete and goto definition 342 for constant definitions. 343 ([Surya Rose](https://github.com/GearsDatapacks)) 344 345- The "generate function" code action can now choose better names based on the 346 labels and variables used. For example if I write the following code: 347 348 ```gleam 349 pub fn main() -> List(Int) { 350 let list = [1, 2, 3] 351 let number = 1 352 remove(each: number, in: list) 353 //^^^^ This function doesn't exist yet! 354 } 355 ``` 356 357 And ask the language server to generate the missing function, the generated 358 code will now look like this: 359 360 ```gleam 361 fn remove(each number: Int, in list: List(Int)) -> List(Int) { 362 todo 363 } 364 ``` 365 366 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 367 368- The language server now provides autocomplete suggestions for labels after 369 part of the label has already been typed. For example, in this code: 370 371 ```gleam 372 pub type Person { 373 Person(name: String, number: Int) 374 } 375 376 pub fn main() { 377 Person(n|) 378 } 379 ``` 380 381 The language server will provide `name:` and `number:` as autocomplete 382 suggestions. 383 384 ([Surya Rose](https://github.com/GearsDatapacks)) 385 386- The language server now provides a code action to automatically generate a new 387 variant from incorrect code: 388 389 ```gleam 390 pub type Msg { 391 ServerSentResponse(Json) 392 } 393 394 pub fn view() -> Element(Msg) { 395 div([], [ 396 button([on_click(UserPressedButton)], [text("Press me!")]) 397 // ^^^^^^^^^^^^^^^^^ This doesn't exist yet! 398 ]) 399 } 400 ``` 401 402 Triggering the code action on the `UserPressedButton` will add it to the `Msg` 403 type: 404 405 ```gleam 406 pub type Msg { 407 ServerSentResponse(Json) 408 UserPressedButton 409 } 410 ``` 411 412 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 413 414### Formatter 415 416### Installation 417 418- Windows ARM64 pre-built binaries are now provided. 419 ([Jonatan Männchen](https://github.com/maennchen)) 420 421### Bug fixes 422 423- Fixed a bug where `case` expressions in custom panic messages would compile 424 to invalid syntax on the JavaScript target. 425 ([Surya Rose](https://github.com/GearsDatapacks)) 426 427- Fixed a bug where `case` expressions in custom panic messages would compile 428 to invalid syntax on the JavaScript target. 429 ([Surya Rose](https://github.com/GearsDatapacks)) 430 431- Fixed a bug where an underscore after a zero in a number would compile to 432 invalid syntax on the JavaScript target. 433 ([Surya Rose](https://github.com/GearsDatapacks)) 434 435- Fixed a bug where the "generate function" code action could generate invalid 436 code when the same variable was passed as an argument twice. 437 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 438 439- Fixed a bug where replacing a Hex dependency with a Git dependency of the 440 same name would cause the build tool to fail. 441 ([Surya Rose](https://github.com/GearsDatapacks)) 442 443- Fixed a bug where updating the remote URL of a Git dependency would fail to 444 update the remote in the local dependency, causing a caching issue. 445 ([Surya Rose](https://github.com/GearsDatapacks)) 446 447- Fix slightly wrong error message for missing main function in test module. 448 ([Samuel Cristobal](https://github.com/scristobal)) 449 450- Fixed a bug where the compiler would not properly warn for unreachable 451 patterns in a `case` expression when the clause matched on multiple 452 alternative patterns. 453 ([Surya Rose](https://github.com/GearsDatapacks)) 454 455- Fixed a bug where the language server would generate invalid code for the 456 "fill in missing labels" code action. 457 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 458 459- Fixed a bug where referencing an earlier segment of the bit array in a bit 460 array pattern in a `let assert` assignment would generate invalid code on the 461 Erlang target. 462 ([Surya Rose](https://github.com/GearsDatapacks)) 463 464- Fixed instances where the "Extract variable" code action would produce invalid 465 code, most noticeable in code inside `case` clauses and `use` expressions. 466 ([Matias Carlander](https://github.com/matiascr)) 467 468- Fixed a bug where the compiler would crash when type-checking code containing 469 an assignment pattern inside a bit-array pattern. 470 ([Surya Rose](https://github.com/GearsDatapacks)) 471 472- Fixed a bug where using the pipe operator in the `size` option of a bit array 473 segment would generate invalid code on the Erlang target. 474 ([Surya Rose](https://github.com/GearsDatapacks)) 475 476- Fixed a bug where the language server would generate invalid code for the 477 "convert to use" code action, when used on a function call with labelled 478 arguments. 479 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 480 481- Fixed a bug where a reference to an imported external function with a 482 non-alphanumeric module name would compile to invalid syntax on the Erlang 483 target. 484 ([Mathieu Darse](https://github.com/mdarse)) 485 486- Fixed a bug where the compiler would not correctly check the size of bit 487 arrays when doing bit array pattern matching on the JavaScript target. 488 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 489 490- Fixed a bug where using the pipe operator inside a record update would cause 491 the compiler to generate invalid code on the JavaScript target. 492 ([Surya Rose](https://github.com/GearsDatapacks)) 493 494- Fixed a bug where some code actions would produce invalid code when a file 495 contained characters that were represented with more than one byte in UTF-8. 496 ([Surya Rose](https://github.com/GearsDatapacks)) 497 498- Fixed a bug where LSP ranges would be incorrect when a file contained characters 499 that were represented with more than one byte in UTF-8. 500 ([Surya Rose](https://github.com/GearsDatapacks)) 501 502- Only print the user-friendly LSP message when stdin is a terminal to avoid 503 emitting redundant logs. 504 ([Ariel Parker](https://github.com/arielherself)) 505 506- Fixed a bug where the language server would wrongly override local variables 507 if they were shadowing an unqualified module function. 508 ([Samuel Cristobal](https://github.com/scristobal)) 509 510- Fixed a bug where renaming a local variable which is used in combination with 511 label shorthand syntax would produce invalid code. 512 ([Surya Rose](https://github.com/GearsDatapacks)) 513 514- Fixed a bug where the stack would overflow on Windows when type-checking 515 multiple nested `use` expressions. 516 ([Surya Rose](https://github.com/GearsDatapacks))