Fork of daniellemaywood.uk/gleam — Wasm codegen work
1<!--
2 SPDX-License-Identifier: Apache-2.0
3 SPDX-FileCopyrightText: 2020 The Gleam contributors
4-->
5
6# Changelog
7
8## v1.12.0 - 2025-08-05
9
10### Bug fixes
11
12- Corrected an error message that used incorrect terminology.
13 ([Louis Pilfold](https://github.com/lpil))
14
15## v1.12.0-rc3 - 2025-07-31
16
17### Bug fixes
18
19- Fixed a bug where using `echo` in a module with a function named `process`
20 would result in a runtime error on JavaScript.
21 ([Peter Saxton](https://github.com/CrowdHailer))
22
23## v1.12.0-rc2 - 2025-07-24
24
25### Formatter
26
27- The formatter now allows more control over how bit arrays are split. By adding
28 a trailing comma at the end of a bit array that can fit on a single line, the
29 bit array will be split on multiple lines:
30
31 ```gleam
32 pub fn dgram() -> BitArray {
33 <<ip_version:4, header_length:4, service_type:8,>>
34 }
35 ```
36
37 Will be formatted as:
38
39 ```gleam
40 pub fn dgram() -> BitArray {
41 <<
42 ip_version:4,
43 header_length:4,
44 service_type:8,
45 >>
46 }
47 ```
48
49 By removing the trailing comma, the formatter will try and fit the bit array
50 on a single line again:
51
52 ```gleam
53 pub fn dgram() -> BitArray {
54 <<
55 ip_version:4,
56 header_length:4,
57 service_type:8
58 >>
59 }
60 ```
61
62 Will be formatted back to a single line:
63
64 ```gleam
65 pub fn dgram() -> BitArray {
66 <<ip_version:4, header_length:4, service_type:8>>
67 }
68 ```
69
70 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
71
72- The formatter now allows more control over how bit arrays are formatted.
73 If a bit array is split with multiple segments on the same line, removing the
74 trailing comma will make sure the formatter keeps each segment on its own
75 line:
76
77 ```gleam
78 pub fn dgram() -> BitArray {
79 <<
80 "This bit array was formatted", "keeping segments on the same line",
81 "notice how the formatting changes by removing the trailing comma ->",
82 >>
83 }
84 ```
85
86 Is formatted as:
87
88 ```gleam
89 pub fn dgram() -> BitArray {
90 <<
91 "This bit array was formatted",
92 "keeping segments on the same line",
93 "notice how the formatting changes by removing the trailing comma ->"
94 >>
95 }
96 ```
97
98 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
99
100### Bug fixes
101
102- Fixed a bug where the formatter would move a comment before `assert` to be
103 after it.
104 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
105
106- Fixed a bug where the message following an `echo`, `panic`, `todo`, `assert`,
107 or `let assert` would not be formatted properly when preceded by a comment.
108 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
109
110- Fixed a bug where the compiler would generate invalid code for an `assert`
111 using pipes on the JavaScript target.
112 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
113
114## v1.12.0-rc1 - 2025-07-18
115
116### Compiler
117
118- It is now possible to add a custom message to be printed by `echo`, making it
119 easier to include additional context to be printed at runtime:
120
121 ```gleam
122 pub fn main() {
123 echo 11 as "lucky number"
124 }
125 ```
126
127 Will output to stderr:
128
129 ```txt
130 /src/module.gleam:2 lucky number
131 11
132 ```
133
134 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
135
136- Generated JavaScript functions, constants, and custom type constructors now
137 include any doc comment as a JSDoc comment, making it easier to use the
138 generated code and browse its documentation from JavaScript.
139 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
140
141- The code generated for a `case` expression on the JavaScript target is now
142 reduced in size in many cases.
143 ([Surya Rose](https://github.com/GearsDatapacks))
144
145- The code generators now perform usage-based dead code elimination. Unused
146 definitions are not longer generated.
147 ([Louis Pilfold](https://github.com/lpil))
148
149- `echo` now has better support for character lists, JavaScript errors, and
150 JavaScript circular references.
151 ([Louis Pilfold](https://github.com/lpil))
152
153- The look of errors and warnings has been improved. Additional labels providing
154 context for the error message are no longer highlighted with the same style as
155 the source of the problem.
156 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
157
158- Gleam will now emit a helpful message when attempting to import modules using
159 `.` instead of `/`.
160
161 ```txt
162 error: Syntax error
163 ┌─ /src/parse/error.gleam:1:11
164 │
165 1 │ import one.two.three
166 │ ^ I was expecting either `/` or `.{` here.
167
168 Perhaps you meant one of:
169
170 import one/two
171 import one.{item}
172 ```
173
174 ([Zij-IT](https://github.com/zij-it))
175
176- The compiler now emits a warning when a top-level constant or function
177 declaration shadows an imported name in the current module.
178 ([Aayush Tripathi](https://github.com/aayush-tripathi))
179
180- The compiler can now tell when an unknown variable might be referring to an
181 ignored variable and provide an helpful error message highlighting it. For
182 example, this piece of code:
183
184 ```gleam
185 pub fn go() {
186 let _x = 1
187 x + 1
188 }
189 ```
190
191 Now results in the following error:
192
193 ```
194 error: Unknown variable
195 ┌─ /src/one/two.gleam:4:3
196 │
197 3 │ let _x = 1
198 │ -- This value is discarded
199 4 │ x + 1
200 │ ^ So it is not in scope here.
201
202 Hint: Change `_x` to `x` or reference another variable
203 ```
204
205 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
206
207- The code generated for pattern matching has been optimised on the JavaScript
208 target to reuse the matched variables when safe to do so. Take the following
209 snippet of Gleam code:
210
211 ```gleam
212 pub fn find_book() {
213 case ask_for_isbn() {
214 Ok(isbn) -> load_book(isbn)
215 Error(Nil) -> Error(Nil)
216 }
217 }
218 ```
219
220 Notice how in the `Error` case we're returning exactly the same value that is
221 being matched on! Now the compiler will generate the following JavaScript code
222 instead of allocating a new `Error` variant entirely:
223
224 ```js
225 export function find_book() {
226 let result = ask_for_isbn();
227 if (result instanceof Ok) {
228 let isbn = result[0];
229 return load_book(isbn);
230 } else {
231 // Previously this would have been: `return new Error(undefined);`!
232 return result;
233 }
234 }
235 ```
236
237 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
238
239- The compiler now raises a warning when performing a redundant comparison that
240 it can tell is always going to succeed or fail. For example, this piece of
241 code:
242
243 ```gleam
244 pub fn find_line(lines) {
245 list.find(lines, fn(x) { x == x })
246 }
247 ```
248
249 Would result in the following warning:
250
251 ```
252 warning: Redundant comparison
253 ┌─ /src/warning.gleam:2:17
254 │
255 1 │ list.find(lines, fn(x) { x == x })
256 │ ^^^^^^ This is always `True`
257
258 This comparison is redundant since it always succeeds.
259 ```
260
261 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
262
263- Attempting to use the list prefix syntax with two lists will now
264 show a helpful error message. For example, this snippet of code:
265
266 ```gleam
267 pub fn main() -> Nil {
268 let xs = [1, 2, 3]
269 let ys = [5, 6, 7]
270 [1, ..xs, ..ys]
271 }
272 ```
273
274 Would result in the following error:
275
276 ```
277 error: Syntax error
278 ┌─ /src/parse/error.gleam:5:13
279 │
280 5 │ [1, ..xs, ..ys]
281 │ -- ^^ I wasn't expecting a second list here
282 │ │
283 │ You're using a list here
284
285 Lists are immutable and singly-linked, so to join two or more lists
286 all the elements of the lists would need to be copied into a new list.
287 This would be slow, so there is no built-in syntax for it.
288 ```
289
290 ([Carl Bordum Hansen](https://github.com/carlbordum)) and
291 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
292
293- The error message one gets when calling a function with the wrong number of
294 arguments has been improved and now only suggests the relevant missing labels.
295 For example, this piece of code:
296
297 ```gleam
298 pub type Pokemon {
299 Pokemon(id: Int, name: String, moves: List(String))
300 }
301
302 pub fn best_pokemon() {
303 Pokemon(198, name: "murkrow")
304 }
305 ```
306
307 Would result in the following error, suggesting the missing labels:
308
309 ```txt
310 error: Incorrect arity
311 ┌─ /src/main.gleam:6:3
312 │
313 6 │ Pokemon(198, name: "murkrow")
314 │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected 3 arguments, got 2
315
316 This call accepts these additional labelled arguments:
317
318 - moves
319 ```
320
321 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
322
323- Code generators now reuse existing variables when possible for the record
324 update syntax, reducing the size of the generated code and number of
325 variables defined for both Erlang and JavaScript.
326
327 ```gleam
328 pub fn main() -> Nil {
329 let trainer = Trainer(name: "Ash", badges: 0)
330 battle(Trainer(..trainer, badges: 1))
331 }
332 ```
333
334 Previously this Gleam code would generate this Erlang code:
335
336 ```erlang
337 -spec main() -> nil.
338 main() ->
339 Trainer = {trainer, 0, <<"Ash"/utf8>>},
340 battle(
341 begin
342 _record = Trainer,
343 {trainer, 1, erlang:element(3, _record)}
344 end
345 ).
346 ```
347
348 Now this code will be generated instead:
349
350 ```erlang
351 -spec main() -> nil.
352 main() ->
353 Trainer = {trainer, 0, <<"Ash"/utf8>>},
354 battle({trainer, 1, erlang:element(3, Trainer)}).
355 ```
356
357 ([Louis Pilfold](https://github.com/lpil))
358
359- The compiler now allows using bit array options to specify endianness when
360 constructing or pattern matching on UTF codepoints in bit arrays.
361 ([Surya Rose](https://github.com/GearsDatapacks))
362
363- Calculations are now allowed in the size options of bit array patterns. For
364 example, the following code is now valid:
365
366 ```gleam
367 let assert <<size, data:bytes-size(size / 8 - 1)>> = some_bit_array
368 ```
369
370 ([Surya Rose](https://github.com/GearsDatapacks))
371
372- On the Erlang target each generated module enables inlining from the Erlang
373 compiler.
374 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
375
376- The code generated for division and modulo operators on the JavaScript target
377 has been improved to avoid performing needless checks.
378 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
379
380### Build tool
381
382- `gleam update`, `gleam deps update`, and `gleam deps download` will now print
383 a message when there are new major versions of packages available. For
384 example:
385
386 ```txt
387 $ gleam update
388 Resolving versions
389
390 The following dependencies have new major versions available:
391
392 gleam_http 1.7.0 -> 4.0.0
393 gleam_json 1.0.1 -> 3.0.1
394 lustre 3.1.4 -> 5.1.1
395 ```
396
397 ([Amjad Mohamed](https://github.com/andho))
398
399- The documentation generator now strips trailing slashes from Gitea/Forgejo
400 hosts so sidebar "Repository" and "View Source" links never include `//`, and
401 single-line "View Source" anchors emit `#Lx` instead of `#Lx-x`.
402 ([Aayush Tripathi](https://github.com/aayush-tripathi))
403
404- The build tool can now compile packages that will have already booted the
405 Erlang compiler application instead of failing.
406 ([Louis Pilfold](https://github.com/lpil))
407
408- `gleam deps list` now uses a tab rather than a space as a separator.
409 ([Louis Pilfold](https://github.com/lpil))
410
411- The build tool now also supports `.cjs` files placed in the `src`, `dev` or
412 `test` directories.
413 ([yoshi](https://github.com/yoshi-monster))
414
415- The build tool now produces better error messages when version resolution
416 fails. For example:
417
418 ```
419 $ gleam add wisp@1
420 Resolving versions
421 error: Dependency resolution failed
422
423 There's no compatible version of `gleam_otp`:
424 - You require wisp >= 1.0.0 and < 2.0.0
425 - wisp requires mist >= 1.2.0 and < 5.0.0
426 - mist requires gleam_otp >= 0.9.0 and < 1.0.0
427 - You require lustre >= 5.2.1 and < 6.0.0
428 - lustre requires gleam_otp >= 1.0.0 and < 2.0.0
429
430 There's no compatible version of `gleam_json`:
431 - You require wisp >= 1.0.0 and < 2.0.0
432 - wisp requires gleam_json >= 3.0.0 and < 4.0.0
433 - You require gleam_json >= 2.3.0 and < 3.0.0
434 ```
435
436 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
437
438- The `repository` section in `gleam.toml` now allows specifying the
439 `tag-prefix` property, which is prepended to the default tag.
440 This makes it possible to have multiple packages with different versions in
441 the same repository (together with `path`), without breaking links to source
442 code in documentation.
443 ([Sakari Bergen](https://github.com/sbergen))
444
445### Language server
446
447- It is now possible to use the "Pattern match on variable" code action on
448 variables on the left hand side of a `use`. For example:
449
450 ```gleam
451 pub type User {
452 User(id: Int, name: String)
453 }
454
455 pub fn main() {
456 use user <- result.try(load_user())
457 // ^^^^ Triggering the code action here
458 todo
459 }
460 ```
461
462 Would result in the following code:
463
464 ```gleam
465 pub type User {
466 User(id: Int, name: String)
467 }
468
469 pub fn main() {
470 use user <- result.try(load_user())
471 let User(id:, name:) = user
472 todo
473 }
474 ```
475
476 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
477
478- The "generate function" and "generate variant" code actions are now
479 quickfixes, allowing them to be more easily applied to code which is producing
480 an error.
481 ([Surya Rose](https://github.com/GearsDatapacks))
482
483- The language server now offers a code action to remove needless blocks
484 wrapping a single expression. For example, in this code snippet:
485
486 ```gleam
487 case greeting {
488 User(name:) -> { "Hello, " <> name }
489 // ^^^^^^^^^^^^^^^^^^^^^ Triggering the code action
490 // with the cursor over this block.
491 Anonymous -> "Hello, stranger!"
492 }
493 ```
494
495 Would be turned into:
496
497 ```gleam
498 case greeting {
499 User(name:) -> "Hello, " <> name
500 Anonymous -> "Hello, stranger!"
501 }
502 ```
503
504 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
505
506- It is now possible to trigger the "Add type annotation" code action anywhere
507 between the start of a function definition and the start of its body. For
508 example the action can trigger here while it previously wouldn't:
509
510 ```gleam
511 pub fn my_lucky_number() {
512 // ^^ The action can trigger here as well!
513 11
514 }
515 ```
516
517 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
518
519### Formatter
520
521- The formatter now allows more control over how lists are split. By adding a
522 trailing comma at the end of a list that can fit on a single line, the list
523 will be split on multiple lines:
524
525 ```gleam
526 pub fn my_favourite_pokemon() -> List(String) {
527 ["natu", "chimecho", "milotic",]
528 }
529 ```
530
531 Will be formatted as:
532
533 ```gleam
534 pub fn my_favourite_pokemon() -> List(String) {
535 [
536 "natu",
537 "chimecho",
538 "milotic",
539 ]
540 }
541 ```
542
543 By removing the trailing comma, the formatter will try and fit the list on a
544 single line again:
545
546 ```gleam
547 pub fn my_favourite_pokemon() -> List(String) {
548 [
549 "natu",
550 "chimecho",
551 "milotic"
552 ]
553 }
554 ```
555
556 Will be formatted back to a single line:
557
558 ```gleam
559 pub fn my_favourite_pokemon() -> List(String) {
560 ["natu", "chimecho", "milotic"]
561 }
562 ```
563
564 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
565
566- The formatter now allows more control over how lists are formatted.
567 If a list is split with multiple elements on the same line, removing the
568 trailing comma will make sure the formatter keeps each item on its own line:
569
570 ```gleam
571 pub fn my_favourite_pokemon() -> List(String) {
572 [
573 "This list was formatted", "keeping multiple elements on the same line",
574 "notice how the formatting changes by removing the trailing comma ->"
575 ]
576 }
577 ```
578
579 Is formatted as:
580
581 ```gleam
582 pub fn my_favourite_pokemon() -> List(String) {
583 [
584 "This list was formatted",
585 "keeping multiple elements on the same line",
586 "notice how the formatting changes by removing the trailing comma ->",
587 ]
588 }
589 ```
590
591 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
592
593- The formatter no longer removes empty lines between list items. In case an
594 empty line is added between list items they will all be split on multiple
595 lines. For example:
596
597 ```gleam
598 pub fn main() {
599 [
600 "natu", "xatu",
601
602 "chimeco"
603 ]
604 }
605 ```
606
607 Is formatted as:
608
609 ```gleam
610 pub fn main() {
611 [
612 "natu",
613 "xatu",
614
615 "chimeco",
616 ]
617 }
618 ```
619
620 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
621
622### Bug fixes
623
624- Fixed a bug where the language server would not show type-related code actions
625 for record fields in custom type definitions.
626 ([cysabi](https://github.com/cysabi))
627
628- Fixed a bug where the "Inline variable" code action would be offered for
629 function parameters and other invalid cases.
630 ([Surya Rose](https://github.com/GearsDatapacks))
631
632- Fixed a bug where the "Inline variable" code action would not be applied
633 correctly to variables using label shorthand syntax.
634 ([Surya Rose](https://github.com/GearsDatapacks))
635
636- Fixed a bug where the compiler would emit the same error twice for patterns
637 with the wrong number of labels.
638 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
639
640- Fixed a bug where the language server would generate invalid code when the
641 "Extract variable" code action was used on a `use` expression.
642 ([Surya Rose](https://github.com/GearsDatapacks))
643
644- Fixed a bug where the compiler would crash when using the `utf8_codepoint`
645 bit array segment on the JavaScript target.
646 ([Surya Rose](https://github.com/GearsDatapacks))
647
648- Fixed a bug where `==` and `!=` would return incorrect output for some
649 JavaScript objects.
650 ([Louis Pilfold](https://github.com/lpil))
651
652- Fixed a bug where specific combinations of options in bit array segments would
653 not be allowed on the JavaScript target.
654 ([Surya Rose](https://github.com/GearsDatapacks))
655
656- Fixed a bug where invalid code would be generated for `let assert` in some
657 cases on the JavaScript target.
658 ([Surya Rose](https://github.com/GearsDatapacks))
659
660- Fixed a bug where using the prelude `Ok` and `Error` values in a qualified
661 fashion could cause a conflict with user-defined `Ok` and `Error` values when
662 generating code on the JavaScript target.
663 ([Surya Rose](https://github.com/GearsDatapacks))
664
665- Fixed a bug where the "Import module" code action would suggest importing
666 internal modules from other packages.
667 ([Surya Rose](https://github.com/GearsDatapacks))
668
669- Fixed a bug where the language server would not rename variables defined in
670 alternative patterns.
671 ([Surya Rose](https://github.com/GearsDatapacks))
672
673- Fixed a bug where trying to rename a type or value from the Gleam prelude
674 would result in invalid code.
675 ([Surya Rose](https://github.com/GearsDatapacks))
676
677- Fixed a bug where the generated documentation would not be formatted properly.
678 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
679
680- Fixed a bug where the language server wouldn't allow you to jump to the
681 definition of a record from a record update expression.
682 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
683
684- Fixed a bug where the language server would allow using the "extract variable"
685 code action on variables used in record updates.
686 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
687
688- Fixed a bug where a record pattern with a spread `..` would not be formatted
689 properly.
690 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
691
692- Fixed a bug where fields of custom types named `prototype` would not be
693 properly escaped on the JavaScript target.
694 ([Surya Rose](https://github.com/GearsDatapacks))
695
696## v1.11.1 - 2025-06-05
697
698### Compiler
699
700- The displaying of internal types in HTML documentation has been improved.
701 ([Louis Pilfold](https://github.com/lpil))
702
703- A warning is now emitted when the same module is imported
704 multiple times into the same module with different aliases.
705 ([Louis Pilfold](https://github.com/lpil))
706
707### Bug fixes
708
709- Fixed a bug where a bit array segment matching on a floating point number
710 would match with `NaN` or `Infinity` on the JavaScript target.
711 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))