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

Fixed export package-definitions not including cached modules #3669

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
172 changes: 168 additions & 4 deletions compiler-core/generated/schema_capnp.rs

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

7 changes: 6 additions & 1 deletion compiler-core/schema.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ struct RecordAccessor {
label @2 :Text;
}

struct FunctionArgument {
name @0 :Text;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function types don't contain names! Please remove this.

It would also be called a parameter. Things have parameters, and for those parameters they accept arguments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you mean that a parameter has a name/label, while an argument doesn't? In that case, I'd reuse the TypeValueConstructorParameter struct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair I wasn't happy with the approach I took 😅 . Tomorrow I'll try tackling this again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither has names at the type level, but parameters can have names locally within a definition.

type @1 :Type;
}

struct Type {
union {
app :group {
Expand All @@ -100,7 +105,7 @@ struct Type {
}

fn :group {
arguments @3 :List(Type);
arguments @3 :List(FunctionArgument);
return @4 :Type;
}

Expand Down
31 changes: 24 additions & 7 deletions compiler-core/src/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ use crate::{
fields::{FieldMap, FieldMapBuilder},
hydrator::Hydrator,
prelude::*,
AccessorsMap, Deprecation, ModuleInterface, PatternConstructor, RecordAccessor, Type,
TypeAliasConstructor, TypeConstructor, TypeValueConstructor, TypeValueConstructorField,
TypeVariantConstructors, ValueConstructor, ValueConstructorVariant, Warning,
AccessorsMap, Deprecation, FunctionArgument, ModuleInterface, PatternConstructor,
RecordAccessor, Type, TypeAliasConstructor, TypeConstructor, TypeValueConstructor,
TypeValueConstructorField, TypeVariantConstructors, ValueConstructor,
ValueConstructorVariant, Warning,
},
uid::UniqueIdGenerator,
warning::TypeWarningEmitter,
Expand Down Expand Up @@ -526,7 +527,13 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
body,
Some(prereg_return_type.clone()),
)?;
let args_types = args.iter().map(|a| a.type_.clone()).collect();
let args_types = args
.iter()
.map(|a| FunctionArgument {
name: a.get_variable_name().cloned(),
type_: a.type_.clone(),
})
.collect();
let type_ = fn_(args_types, body.last().type_());
Ok((
type_,
Expand Down Expand Up @@ -976,7 +983,10 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
});

// Register the type for this parameter
args_types.push(t);
args_types.push(FunctionArgument {
name: None,
type_: t,
});

// Register the label for this parameter, if there is one
if let Some((_, label)) = label {
Expand All @@ -992,7 +1002,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
// Insert constructor function into module scope
let type_ = match constructor.arguments.len() {
0 => type_.clone(),
_ => fn_(args_types.clone(), type_.clone()),
_ => fn_(args_types, type_.clone()),
};
let constructor_info = ValueConstructorVariant::Record {
documentation: constructor
Expand Down Expand Up @@ -1321,7 +1331,14 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
let arg_types = args
.iter()
.map(|arg| {
hydrator.type_from_option_ast(&arg.annotation, environment, &mut self.problems)
Ok(FunctionArgument {
name: None,
type_: hydrator.type_from_option_ast(
&arg.annotation,
environment,
&mut self.problems,
)?,
})
})
.try_collect()?;
let return_type =
Expand Down
18 changes: 15 additions & 3 deletions compiler-core/src/ast/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
ast::{SrcSpan, TypedExpr},
build::Located,
type_::{
self, AccessorsMap, Environment, ExprTyper, FieldMap, ModuleValueConstructor,
RecordAccessor, Type, ValueConstructor, ValueConstructorVariant,
self, AccessorsMap, Environment, ExprTyper, FieldMap, FunctionArgument,
ModuleValueConstructor, RecordAccessor, Type, ValueConstructor, ValueConstructorVariant,
},
uid::UniqueIdGenerator,
warning::TypeWarningEmitter,
Expand Down Expand Up @@ -108,7 +108,19 @@ fn compile_expression(src: &str) -> TypedStatement {
environment.insert_variable(
"Cat".into(),
variant,
type_::fn_(vec![type_::string(), type_::int()], cat_type.clone()),
type_::fn_(
vec![
FunctionArgument {
name: None,
type_: type_::string(),
},
FunctionArgument {
name: None,
type_: type_::int(),
},
],
cat_type.clone(),
),
Publicity::Public,
Deprecation::NotDeprecated,
);
Expand Down
10 changes: 5 additions & 5 deletions compiler-core/src/erlang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{
line_numbers::LineNumbers,
pretty::*,
type_::{
ModuleValueConstructor, PatternConstructor, Type, TypeVar, ValueConstructor,
ValueConstructorVariant,
FunctionArgument, ModuleValueConstructor, PatternConstructor, Type, TypeVar,
ValueConstructor, ValueConstructorVariant,
},
Result,
};
Expand Down Expand Up @@ -2140,7 +2140,7 @@ fn type_var_ids(type_: &Type, ids: &mut HashMap<u64, u64>) {
},
Type::Fn { args, retrn } => {
for arg in args {
type_var_ids(arg, ids)
type_var_ids(&arg.type_, ids)
}
type_var_ids(retrn, ids);
}
Expand Down Expand Up @@ -2293,8 +2293,8 @@ impl<'a> TypePrinter<'a> {
}
}

fn print_fn(&self, args: &[Arc<Type>], retrn: &Type) -> Document<'static> {
let args = join(args.iter().map(|a| self.print(a)), ", ".to_doc());
fn print_fn(&self, args: &[FunctionArgument], retrn: &Type) -> Document<'static> {
let args = join(args.iter().map(|a| self.print(&a.type_)), ", ".to_doc());
let retrn = self.print(retrn);
"fun(("
.to_doc()
Expand Down
12 changes: 9 additions & 3 deletions compiler-core/src/exhaustiveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use self::pattern::{Constructor, Pattern, PatternId};
use crate::{
ast::AssignName,
type_::{
collapse_links, error::UnknownTypeConstructorError, is_prelude_module, Environment, Type,
TypeValueConstructor, TypeValueConstructorField, TypeVar,
collapse_links, error::UnknownTypeConstructorError, is_prelude_module, Environment,
FunctionArgument, Type, TypeValueConstructor, TypeValueConstructorField, TypeVar,
},
};
use ecow::EcoString;
Expand Down Expand Up @@ -905,7 +905,13 @@ impl ConstructorSpecialiser {
},

Type::Fn { args, retrn } => Type::Fn {
args: args.iter().map(|a| self.specialise_type(a)).collect(),
args: args
.iter()
.map(|a| FunctionArgument {
name: a.name.clone(),
type_: self.specialise_type(&a.type_),
})
.collect(),
retrn: retrn.clone(),
},

Expand Down
Loading