Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,18 @@
definitions for records with a field named `constructor`.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug where the compiler would generate invalid code for `let assert`
expression with bit array patterns.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug where the compiler would evaluate the numerator and denominator
of a division in the wrong order.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug where the compiler would generate Erlang code that raises further
warnings for unused values.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug where the compiler would raise a warning for truncated int
segments when compiling a function with a JavaScript external.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))
Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ members = [
"hexpm",
"pretty-arena",
"format",
"erlang-term-format",
"erlang-generation",
]

# common dependencies
Expand Down Expand Up @@ -81,8 +83,8 @@ opener = "0"
ignore = "0"
# Parsing of arbitrary width int values
num-bigint = { version = "0.4.6", features = ["serde"] }
num-traits = "0.2.19"
# Unicode grapheme traversal
unicode-segmentation = "1.13.2"
# Checksums
xxhash-rust = { version = "0", features = ["xxh3"] }

3 changes: 2 additions & 1 deletion compiler-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
clippy::match_single_binding,
clippy::inconsistent_struct_constructor,
clippy::assign_op_pattern,
clippy::len_without_is_empty
clippy::len_without_is_empty,
clippy::let_unit_value
)]

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion compiler-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pathdiff = { version = "0", features = ["camino"] }
id-arena = "2"
# Bijective (bi-directional) hashmap
bimap = { version = "0.6.3", features = ["serde"] }
num-traits = "0.2.19"
# Encryption
age = { version = "0.11", features = ["armor"] }
radix_trie = "0.3"
Expand All @@ -50,6 +49,7 @@ sourcemap = "9"
indexmap = "2.12.1"

num-bigint.workspace = true
num-traits.workspace = true
async-trait.workspace = true
base16.workspace = true
camino = { workspace = true, features = ["serde1"] }
Expand All @@ -60,6 +60,7 @@ flate2.workspace = true
futures.workspace = true
hexpm = { path = "../hexpm" }
pretty-arena = { path = "../pretty-arena" }
erlang-generation = { path = "../erlang-generation" }
http.workspace = true
im.workspace = true
itertools.workspace = true
Expand Down
17 changes: 10 additions & 7 deletions compiler-core/src/ast/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,8 @@ impl TypedExpr {
matches!(self, Self::Pipeline { .. })
}

/// Returns true if this function is guaranteed to not have any side
/// effects.
pub fn is_pure_value_constructor(&self) -> bool {
match self {
TypedExpr::Int { .. }
Expand All @@ -1046,10 +1048,8 @@ impl TypedExpr {
// long as it's not called!
TypedExpr::ModuleSelect { .. } => true,

// A pipeline is a pure value constructor if its last step is a record builder,
// or a call to a pure function. For example:
// - `wibble() |> wobble() |> Ok`
// - `"hello" |> fn(s) { s <> " world!" }`
// A pipeline is a pure value constructor if all of its steps are
// pure.
TypedExpr::Pipeline {
first_value,
assignments,
Expand All @@ -1063,6 +1063,9 @@ impl TypedExpr {
&& finally.is_pure_value_constructor()
}

// A function is a pure value constructor if it is a record builder,
// or the called function is understood to be pure. Also all of its
// arguments must be pure value constructors!
TypedExpr::Call { fun, arguments, .. } => {
(fun.is_record_literal() || fun.called_function_purity().is_pure())
&& arguments
Expand Down Expand Up @@ -1091,9 +1094,9 @@ impl TypedExpr {
&& clauses.iter().all(|c| c.then.is_pure_value_constructor())
}

// `panic`, `todo`, and placeholders are never considered pure value constructors,
// we don't want to raise a warning for an unused value if it's one
// of those.
// `panic`, `todo`, and placeholders are never considered pure value
// constructors, we don't want to raise a warning for an unused
// value if it's one of those.
TypedExpr::Todo { .. }
| TypedExpr::Panic { .. }
| TypedExpr::Echo { .. }
Expand Down
2 changes: 1 addition & 1 deletion compiler-core/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> Erlang<'a> {
let line_numbers = LineNumbers::new(&module.code);
let output = erlang::module(&module.ast, &line_numbers, root);
tracing::debug!(name = ?name, "Generated Erlang module");
writer.write(&path, &output?)
writer.write(&path, &output)
}

fn erlang_record_headers<Writer: FileSystemWriter>(
Expand Down
Loading
Loading