Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add erlang docs #3729

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5d334f4
Define untyped echo
giacomocavalieri Oct 7, 2024
d247dc6
echo parsing
giacomocavalieri Oct 7, 2024
8b01895
echo format tests
giacomocavalieri Oct 7, 2024
0aca57d
tests to make sure echo is followed by an expression
giacomocavalieri Oct 8, 2024
155016b
handle echo not followed by an expression to print
giacomocavalieri Oct 8, 2024
0da2480
add echo typed node
giacomocavalieri Oct 8, 2024
5f1566b
make sure one cannot publish echo
giacomocavalieri Oct 10, 2024
80c4f6b
refactor pipe assignments to simplify echo code generation
giacomocavalieri Oct 10, 2024
5b5b168
first attempt at erlang code generation
giacomocavalieri Oct 10, 2024
4b24f86
first attempt at js code generation
giacomocavalieri Oct 10, 2024
ddbc1f6
some more tests
giacomocavalieri Oct 10, 2024
b6549d6
debug printing on js
giacomocavalieri Oct 11, 2024
d380a57
change parsing rules for echo in pipelines
giacomocavalieri Oct 11, 2024
3c61469
erlang and js
giacomocavalieri Oct 21, 2024
92f9ed3
rebase gone wrong
giacomocavalieri Oct 21, 2024
7070cf2
various fixes
giacomocavalieri Oct 21, 2024
bf099cc
snaps
giacomocavalieri Oct 21, 2024
7c857c5
warn for unreachable echo
giacomocavalieri Oct 21, 2024
69b2071
clippy!
giacomocavalieri Oct 21, 2024
850f1f1
improve js echo snapshots
giacomocavalieri Oct 21, 2024
4920aaf
improve erl snapshots
giacomocavalieri Oct 21, 2024
32eb65f
erlang snapshots again
giacomocavalieri Oct 21, 2024
0b0a147
snapshots
giacomocavalieri Oct 21, 2024
df1c688
snapshots one last time
giacomocavalieri Oct 21, 2024
5a297fa
Fix error message flipping 'expected' and 'found' type for values in …
MarkusPettersson98 Oct 11, 2024
b27e0a5
Add test for showing correct error message when using values in a pipe
MarkusPettersson98 Oct 11, 2024
09614e9
Simplify error handling in pipe type checking
MarkusPettersson98 Oct 11, 2024
b0be28c
Update changelog
MarkusPettersson98 Oct 21, 2024
3055386
Return error from WASM compiler when unsupported features are used
richard-viney Oct 20, 2024
a27a5de
Fix Changelog
GearsDatapacks Oct 21, 2024
7799fdc
wip
giacomocavalieri Oct 21, 2024
d16cf24
handle single line docs
giacomocavalieri Oct 21, 2024
e9b6db8
tests
giacomocavalieri Oct 21, 2024
30a7693
tests
giacomocavalieri Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@
unless explicitly specified.
([Gustavo Inacio](https://github.com/gusinacio))

- Fixes a bug where incorrect code would be generated for external function on
the Erlang target if any of their arguments were discarded.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Improve error message for using @deprecated with no deprecation message
- Improved the error message for using `@deprecated` with no deprecation message
([Jiangda Wang](https://github.com/frank-iii))

### Formatter
Expand Down Expand Up @@ -243,6 +239,18 @@
which was defined with duplicate fields in one of its variants.
([Surya Rose](https://github.com/GearsDatapacks))

- Fixed a bug where the WASM compiler would return incomplete JavaScript when
unsupported features were used. It now returns a compilation error.
([Richard Viney](https://github.com/richard-viney))

- Fixed a bug where incorrect code would be generated for external function on
the Erlang target if any of their arguments were discarded.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug in the error message when using wrong values in a pipe where the
message would swap the "Expected" and "Found" types.
([Markus Pettersson](https://github.com/MarkusPettersson98/))

## v1.5.1 - 2024-09-26

### Bug Fixes
Expand Down
33 changes: 21 additions & 12 deletions compiler-cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,27 @@ fn do_build_hex_tarball(paths: &ProjectPaths, config: &mut PackageConfig) -> Res
}
}

// If any of the modules in the package contain a todo then refuse to
// publish as the package is not yet finished.
let unfinished = built
.root_package
.modules
.iter()
.filter(|module| module.ast.type_info.contains_todo())
.map(|module| module.name.clone())
.sorted()
.collect_vec();
if !unfinished.is_empty() {
return Err(Error::CannotPublishTodo { unfinished });
// If any of the modules in the package contain a todo or an echo then
// refuse to publish as the package is not yet finished.
let mut modules_containing_todo = vec![];
let mut modules_containing_echo = vec![];

for module in built.root_package.modules.iter() {
if module.ast.type_info.contains_todo() {
modules_containing_todo.push(module.name.clone());
} else if module.ast.type_info.contains_echo {
modules_containing_echo.push(module.name.clone());
}
}

if !modules_containing_todo.is_empty() {
return Err(Error::CannotPublishTodo {
unfinished: modules_containing_todo,
});
} else if !modules_containing_echo.is_empty() {
return Err(Error::CannotPublishEcho {
unfinished: modules_containing_echo,
});
}

// TODO: If any of the modules in the package contain a leaked internal type then
Expand Down
12 changes: 12 additions & 0 deletions compiler-core/generated/schema_capnp.rs

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

1 change: 1 addition & 0 deletions compiler-core/schema.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct Module {
srcPath @7 :Text;
isInternal @8 :Bool;
requiredVersion @9 :Version;
containsEcho @10 :Bool;
}

struct Version {
Expand Down
2 changes: 2 additions & 0 deletions compiler-core/src/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
module_values: values,
accessors,
names: type_names,
echo_found,
..
} = env;

Expand Down Expand Up @@ -334,6 +335,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
src_path: self.src_path,
warnings,
minimum_required_version: self.minimum_required_version,
contains_echo: echo_found,
},
names: type_names,
};
Expand Down
19 changes: 19 additions & 0 deletions compiler-core/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2331,3 +2331,22 @@ pub struct UseAssignment {
pub pattern: UntypedPattern,
pub annotation: Option<TypeAst>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypedPipelineAssignment {
pub location: SrcSpan,
pub name: EcoString,
pub value: Box<TypedExpr>,
}

impl TypedPipelineAssignment {
pub fn find_node(&self, byte_index: u32) -> Option<Located<'_>> {
self.value
.find_node(byte_index)
.or_else(|| self.value.find_node(byte_index))
}

pub fn type_(&self) -> Arc<Type> {
self.value.type_()
}
}
23 changes: 21 additions & 2 deletions compiler-core/src/ast/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum TypedExpr {
/// locations when showing it in error messages, etc.
Pipeline {
location: SrcSpan,
assignments: Vec<TypedAssignment>,
assignments: Vec<TypedPipelineAssignment>,
finally: Box<Self>,
},

Expand Down Expand Up @@ -126,6 +126,12 @@ pub enum TypedExpr {
type_: Arc<Type>,
},

Echo {
location: SrcSpan,
type_: Arc<Type>,
expression: Option<Box<Self>>,
},

BitArray {
location: SrcSpan,
type_: Arc<Type>,
Expand Down Expand Up @@ -182,6 +188,11 @@ impl TypedExpr {
| Self::ModuleSelect { .. }
| Self::Invalid { .. } => self.self_if_contains_location(byte_index),

Self::Echo { expression, .. } => expression
.as_ref()
.and_then(|e| e.find_node(byte_index))
.or_else(|| self.self_if_contains_location(byte_index)),

Self::Todo { kind, .. } => match kind {
TodoKind::Keyword => self.self_if_contains_location(byte_index),
// We don't want to match on todos that were implicitly inserted
Expand Down Expand Up @@ -316,6 +327,7 @@ impl TypedExpr {
| Self::Int { location, .. }
| Self::Var { location, .. }
| Self::Todo { location, .. }
| Self::Echo { location, .. }
| Self::Case { location, .. }
| Self::Call { location, .. }
| Self::List { location, .. }
Expand Down Expand Up @@ -343,6 +355,7 @@ impl TypedExpr {
| Self::Int { location, .. }
| Self::Var { location, .. }
| Self::Todo { location, .. }
| Self::Echo { location, .. }
| Self::Case { location, .. }
| Self::Call { location, .. }
| Self::List { location, .. }
Expand Down Expand Up @@ -372,6 +385,7 @@ impl TypedExpr {
| TypedExpr::Call { .. }
| TypedExpr::Case { .. }
| TypedExpr::Todo { .. }
| TypedExpr::Echo { .. }
| TypedExpr::Panic { .. }
| TypedExpr::BinOp { .. }
| TypedExpr::Float { .. }
Expand Down Expand Up @@ -413,6 +427,7 @@ impl TypedExpr {
Self::Fn { type_, .. }
| Self::Int { type_, .. }
| Self::Todo { type_, .. }
| Self::Echo { type_, .. }
| Self::Case { type_, .. }
| Self::List { type_, .. }
| Self::Call { type_, .. }
Expand Down Expand Up @@ -473,6 +488,7 @@ impl TypedExpr {
| TypedExpr::Tuple { .. }
| TypedExpr::TupleIndex { .. }
| TypedExpr::Todo { .. }
| TypedExpr::Echo { .. }
| TypedExpr::Panic { .. }
| TypedExpr::BitArray { .. }
| TypedExpr::RecordUpdate { .. }
Expand Down Expand Up @@ -552,7 +568,10 @@ impl TypedExpr {
// `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::Invalid { .. } => false,
TypedExpr::Todo { .. }
| TypedExpr::Panic { .. }
| TypedExpr::Echo { .. }
| TypedExpr::Invalid { .. } => false,
}
}

Expand Down
6 changes: 6 additions & 0 deletions compiler-core/src/ast/untyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ pub enum UntypedExpr {
message: Option<Box<Self>>,
},

Echo {
location: SrcSpan,
expression: Option<Box<Self>>,
},

BitArray {
location: SrcSpan,
segments: Vec<UntypedExprBitArraySegment>,
Expand Down Expand Up @@ -148,6 +153,7 @@ impl UntypedExpr {
| Self::Var { location, .. }
| Self::Int { location, .. }
| Self::Todo { location, .. }
| Self::Echo { location, .. }
| Self::Case { location, .. }
| Self::Call { location, .. }
| Self::List { location, .. }
Expand Down
47 changes: 43 additions & 4 deletions compiler-core/src/ast/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ use super::{
AssignName, BinOp, BitArrayOption, CallArg, Definition, Pattern, SrcSpan, Statement, TodoKind,
TypeAst, TypedArg, TypedAssignment, TypedClause, TypedDefinition, TypedExpr,
TypedExprBitArraySegment, TypedFunction, TypedModule, TypedModuleConstant, TypedPattern,
TypedPatternBitArraySegment, TypedRecordUpdateArg, TypedStatement, Use,
TypedPatternBitArraySegment, TypedPipelineAssignment, TypedRecordUpdateArg, TypedStatement,
Use,
};

pub trait Visit<'ast> {
Expand All @@ -76,6 +77,15 @@ pub trait Visit<'ast> {
visit_typed_expr(self, expr);
}

fn visit_typed_expr_echo(
&mut self,
location: &'ast SrcSpan,
type_: &'ast Arc<Type>,
expression: &'ast Option<Box<TypedExpr>>,
) {
visit_typed_expr_echo(self, location, type_, expression);
}

fn visit_typed_expr_int(
&mut self,
location: &'ast SrcSpan,
Expand Down Expand Up @@ -114,7 +124,7 @@ pub trait Visit<'ast> {
fn visit_typed_expr_pipeline(
&mut self,
location: &'ast SrcSpan,
assignments: &'ast [TypedAssignment],
assignments: &'ast [TypedPipelineAssignment],
finally: &'ast TypedExpr,
) {
visit_typed_expr_pipeline(self, location, assignments, finally);
Expand Down Expand Up @@ -298,6 +308,10 @@ pub trait Visit<'ast> {
visit_typed_assignment(self, assignment);
}

fn visit_typed_pipeline_assignment(&mut self, assignment: &'ast TypedPipelineAssignment) {
visit_typed_pipeline_assignment(self, assignment);
}

fn visit_use(&mut self, use_: &'ast Use) {
visit_use(self, use_);
}
Expand Down Expand Up @@ -730,6 +744,11 @@ where
}
TypedExpr::NegateInt { location, value } => v.visit_typed_expr_negate_int(location, value),
TypedExpr::Invalid { location, type_ } => v.visit_typed_expr_invalid(location, type_),
TypedExpr::Echo {
location,
expression,
type_,
} => v.visit_typed_expr_echo(location, type_, expression),
}
}

Expand Down Expand Up @@ -778,18 +797,25 @@ pub fn visit_typed_expr_block<'a, V>(
pub fn visit_typed_expr_pipeline<'a, V>(
v: &mut V,
_location: &'a SrcSpan,
assignments: &'a [TypedAssignment],
assignments: &'a [TypedPipelineAssignment],
finally: &'a TypedExpr,
) where
V: Visit<'a> + ?Sized,
{
for assignment in assignments {
v.visit_typed_assignment(assignment);
v.visit_typed_pipeline_assignment(assignment);
}

v.visit_typed_expr(finally);
}

pub fn visit_typed_pipeline_assignment<'a, V>(v: &mut V, assignment: &'a TypedPipelineAssignment)
where
V: Visit<'a> + ?Sized,
{
v.visit_typed_expr(&assignment.value);
}

pub fn visit_typed_expr_var<'a, V>(
_v: &mut V,
_location: &'a SrcSpan,
Expand Down Expand Up @@ -948,6 +974,19 @@ pub fn visit_typed_expr_todo<'a, V>(
}
}

fn visit_typed_expr_echo<'a, V>(
v: &mut V,
_location: &'a SrcSpan,
_type_: &'a Arc<Type>,
expression: &'a Option<Box<TypedExpr>>,
) where
V: Visit<'a> + ?Sized,
{
if let Some(expression) = expression {
v.visit_typed_expr(expression)
}
}

pub fn visit_typed_expr_panic<'a, V>(
v: &mut V,
_location: &'a SrcSpan,
Expand Down
Loading
Loading