Skip to content

Commit 52c6ba8

Browse files
erlang abstract form
1 parent e8b7f51 commit 52c6ba8

511 files changed

Lines changed: 10892 additions & 5726 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ members = [
1818
"pretty-arena",
1919
"format",
2020
"erlang-term-format",
21+
"erlang-abstract-format",
2122
]
2223

2324
# common dependencies

compiler-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ flate2.workspace = true
6060
futures.workspace = true
6161
hexpm = { path = "../hexpm" }
6262
pretty-arena = { path = "../pretty-arena" }
63+
erlang-abstract-format = { path = "../erlang-abstract-format" }
6364
http.workspace = true
6465
im.workspace = true
6566
itertools.workspace = true

compiler-core/src/ast/typed.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ impl TypedExpr {
10211021
matches!(self, Self::Pipeline { .. })
10221022
}
10231023

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

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

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

1094-
// `panic`, `todo`, and placeholders are never considered pure value constructors,
1095-
// we don't want to raise a warning for an unused value if it's one
1096-
// of those.
1097+
// `panic`, `todo`, and placeholders are never considered pure value
1098+
// constructors, we don't want to raise a warning for an unused
1099+
// value if it's one of those.
10971100
TypedExpr::Todo { .. }
10981101
| TypedExpr::Panic { .. }
10991102
| TypedExpr::Echo { .. }

compiler-core/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'a> Erlang<'a> {
6161
let line_numbers = LineNumbers::new(&module.code);
6262
let output = erlang::module(&module.ast, &line_numbers, root);
6363
tracing::debug!(name = ?name, "Generated Erlang module");
64-
writer.write(&path, &output?)
64+
writer.write(&path, &output)
6565
}
6666

6767
fn erlang_record_headers<Writer: FileSystemWriter>(

0 commit comments

Comments
 (0)