diff --git a/compiler-core/generated/schema_capnp.rs b/compiler-core/generated/schema_capnp.rs index 6d1958808c4..898911d45b0 100644 --- a/compiler-core/generated/schema_capnp.rs +++ b/compiler-core/generated/schema_capnp.rs @@ -497,6 +497,22 @@ pub mod module { pub fn has_required_version(&self) -> bool { !self.reader.get_pointer_field(8).is_null() } + #[inline] + pub fn get_documentation(self) -> ::capnp::Result<::capnp::text_list::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(9), ::core::option::Option::None) + } + #[inline] + pub fn has_documentation(&self) -> bool { + !self.reader.get_pointer_field(9).is_null() + } + #[inline] + pub fn get_type_aliases(self) -> ::capnp::Result<::capnp::struct_list::Reader<'a,crate::schema_capnp::property::Owned>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(10), ::core::option::Option::None) + } + #[inline] + pub fn has_type_aliases(&self) -> bool { + !self.reader.get_pointer_field(10).is_null() + } } pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } @@ -699,6 +715,38 @@ pub mod module { pub fn has_required_version(&self) -> bool { !self.builder.get_pointer_field(8).is_null() } + #[inline] + pub fn get_documentation(self) -> ::capnp::Result<::capnp::text_list::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(9), ::core::option::Option::None) + } + #[inline] + pub fn set_documentation(&mut self, value: ::capnp::text_list::Reader<'a>) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(9), value, false) + } + #[inline] + pub fn init_documentation(self, size: u32) -> ::capnp::text_list::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(9), size) + } + #[inline] + pub fn has_documentation(&self) -> bool { + !self.builder.get_pointer_field(9).is_null() + } + #[inline] + pub fn get_type_aliases(self) -> ::capnp::Result<::capnp::struct_list::Builder<'a,crate::schema_capnp::property::Owned>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(10), ::core::option::Option::None) + } + #[inline] + pub fn set_type_aliases(&mut self, value: ::capnp::struct_list::Reader<'a,crate::schema_capnp::property::Owned>) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(10), value, false) + } + #[inline] + pub fn init_type_aliases(self, size: u32) -> ::capnp::struct_list::Builder<'a,crate::schema_capnp::property::Owned> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(10), size) + } + #[inline] + pub fn has_type_aliases(&self) -> bool { + !self.builder.get_pointer_field(10).is_null() + } } pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } @@ -717,7 +765,7 @@ pub mod module { } mod _private { use capnp::private::layout; - pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 9 }; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 11 }; pub const TYPE_ID: u64 = 0x9a52_9544_50db_0581; } } @@ -1247,6 +1295,14 @@ pub mod type_value_constructor_parameter { pub fn has_type(&self) -> bool { !self.reader.get_pointer_field(0).is_null() } + #[inline] + pub fn get_label(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(1), ::core::option::Option::None) + } + #[inline] + pub fn has_label(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } } pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } @@ -1313,6 +1369,22 @@ pub mod type_value_constructor_parameter { pub fn has_type(&self) -> bool { !self.builder.get_pointer_field(0).is_null() } + #[inline] + pub fn get_label(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None) + } + #[inline] + pub fn set_label(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(1).set_text(value); + } + #[inline] + pub fn init_label(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(1).init_text(size) + } + #[inline] + pub fn has_label(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } } pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } @@ -1328,7 +1400,7 @@ pub mod type_value_constructor_parameter { } mod _private { use capnp::private::layout; - pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 1 }; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 2 }; pub const TYPE_ID: u64 = 0xa195_30b0_13c1_53ea; } } @@ -1435,6 +1507,10 @@ pub mod type_constructor { pub fn has_documentation(&self) -> bool { !self.reader.get_pointer_field(6).is_null() } + #[inline] + pub fn get_opaque(self) -> bool { + self.reader.get_bool_field(0) + } } pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } @@ -1597,6 +1673,14 @@ pub mod type_constructor { pub fn has_documentation(&self) -> bool { !self.builder.get_pointer_field(6).is_null() } + #[inline] + pub fn get_opaque(self) -> bool { + self.builder.get_bool_field(0) + } + #[inline] + pub fn set_opaque(&mut self, value: bool) { + self.builder.set_bool_field(0, value); + } } pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } @@ -1618,11 +1702,289 @@ pub mod type_constructor { } mod _private { use capnp::private::layout; - pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 7 }; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 7 }; pub const TYPE_ID: u64 = 0xb1fb_6d62_e00b_6d7a; } } +pub mod type_alias_constructor { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl <'a> ::capnp::traits::OwnedStruct<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl ::capnp::traits::Pipelined for Owned { type Pipeline = Pipeline; } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { reader: ::capnp::private::layout::StructReader<'a> } + + impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> { + Reader { reader, } + } + } + + impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> { + fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?)) + } + } + + impl <'a,> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a,> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl <'a,> ::capnp::traits::Imbue<'a> for Reader<'a,> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader.imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl <'a,> Reader<'a,> { + pub fn reborrow(&self) -> Reader<'_,> { + Reader { .. *self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_publicity(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) + } + #[inline] + pub fn has_publicity(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_module(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(1), ::core::option::Option::None) + } + #[inline] + pub fn has_module(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_origin(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(2), ::core::option::Option::None) + } + #[inline] + pub fn has_origin(&self) -> bool { + !self.reader.get_pointer_field(2).is_null() + } + #[inline] + pub fn get_type(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(3), ::core::option::Option::None) + } + #[inline] + pub fn has_type(&self) -> bool { + !self.reader.get_pointer_field(3).is_null() + } + #[inline] + pub fn get_arity(self) -> u16 { + self.reader.get_data_field::(0) + } + #[inline] + pub fn get_deprecated(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(4), ::core::option::Option::None) + } + #[inline] + pub fn has_deprecated(&self) -> bool { + !self.reader.get_pointer_field(4).is_null() + } + #[inline] + pub fn get_documentation(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(5), ::core::option::Option::None) + } + #[inline] + pub fn has_documentation(&self) -> bool { + !self.reader.get_pointer_field(5).is_null() + } + } + + pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } + impl <'a,> ::capnp::traits::HasStructSize for Builder<'a,> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { _private::STRUCT_SIZE } + } + impl <'a,> ::capnp::traits::HasTypeId for Builder<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructBuilder<'a> for Builder<'a,> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, > { + Builder { builder, } + } + } + + impl <'a,> ::capnp::traits::ImbueMut<'a> for Builder<'a,> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder.imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl <'a,> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a,> { + fn init_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, _size: u32) -> Builder<'a,> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, default)?)) + } + } + + impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> { + fn set_pointer_builder<'b>(pointer: ::capnp::private::layout::PointerBuilder<'b>, value: Reader<'a,>, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } + } + + impl <'a,> Builder<'a,> { + pub fn into_reader(self) -> Reader<'a,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_,> { + Builder { .. *self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_publicity(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) + } + #[inline] + pub fn set_publicity(&mut self, value: crate::schema_capnp::publicity::Reader<'_>) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(0), value, false) + } + #[inline] + pub fn init_publicity(self, ) -> crate::schema_capnp::publicity::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) + } + #[inline] + pub fn has_publicity(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_module(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None) + } + #[inline] + pub fn set_module(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(1).set_text(value); + } + #[inline] + pub fn init_module(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(1).init_text(size) + } + #[inline] + pub fn has_module(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_origin(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(2), ::core::option::Option::None) + } + #[inline] + pub fn set_origin(&mut self, value: crate::schema_capnp::src_span::Reader<'_>) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(2), value, false) + } + #[inline] + pub fn init_origin(self, ) -> crate::schema_capnp::src_span::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(2), 0) + } + #[inline] + pub fn has_origin(&self) -> bool { + !self.builder.get_pointer_field(2).is_null() + } + #[inline] + pub fn get_type(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(3), ::core::option::Option::None) + } + #[inline] + pub fn set_type(&mut self, value: crate::schema_capnp::type_::Reader<'_>) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(3), value, false) + } + #[inline] + pub fn init_type(self, ) -> crate::schema_capnp::type_::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(3), 0) + } + #[inline] + pub fn has_type(&self) -> bool { + !self.builder.get_pointer_field(3).is_null() + } + #[inline] + pub fn get_arity(self) -> u16 { + self.builder.get_data_field::(0) + } + #[inline] + pub fn set_arity(&mut self, value: u16) { + self.builder.set_data_field::(0, value); + } + #[inline] + pub fn get_deprecated(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(4), ::core::option::Option::None) + } + #[inline] + pub fn set_deprecated(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(4).set_text(value); + } + #[inline] + pub fn init_deprecated(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(4).init_text(size) + } + #[inline] + pub fn has_deprecated(&self) -> bool { + !self.builder.get_pointer_field(4).is_null() + } + #[inline] + pub fn get_documentation(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(5), ::core::option::Option::None) + } + #[inline] + pub fn set_documentation(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(5).set_text(value); + } + #[inline] + pub fn init_documentation(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(5).init_text(size) + } + #[inline] + pub fn has_documentation(&self) -> bool { + !self.builder.get_pointer_field(5).is_null() + } + } + + pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { _typeless: typeless, } + } + } + impl Pipeline { + pub fn get_publicity(&self) -> crate::schema_capnp::publicity::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(0)) + } + pub fn get_origin(&self) -> crate::schema_capnp::src_span::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(2)) + } + pub fn get_type(&self) -> crate::schema_capnp::type_::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(3)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 6 }; + pub const TYPE_ID: u64 = 0xac58_4722_b0c2_444d; + } +} + pub mod accessors_map { #[derive(Copy, Clone)] pub struct Owned(()); @@ -1963,6 +2325,170 @@ pub mod record_accessor { } } +pub mod function_argument { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl <'a> ::capnp::traits::OwnedStruct<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl ::capnp::traits::Pipelined for Owned { type Pipeline = Pipeline; } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { reader: ::capnp::private::layout::StructReader<'a> } + + impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> { + Reader { reader, } + } + } + + impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> { + fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?)) + } + } + + impl <'a,> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a,> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl <'a,> ::capnp::traits::Imbue<'a> for Reader<'a,> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader.imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl <'a,> Reader<'a,> { + pub fn reborrow(&self) -> Reader<'_,> { + Reader { .. *self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_name(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) + } + #[inline] + pub fn has_name(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_type(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(1), ::core::option::Option::None) + } + #[inline] + pub fn has_type(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + } + + pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } + impl <'a,> ::capnp::traits::HasStructSize for Builder<'a,> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { _private::STRUCT_SIZE } + } + impl <'a,> ::capnp::traits::HasTypeId for Builder<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructBuilder<'a> for Builder<'a,> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, > { + Builder { builder, } + } + } + + impl <'a,> ::capnp::traits::ImbueMut<'a> for Builder<'a,> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder.imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl <'a,> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a,> { + fn init_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, _size: u32) -> Builder<'a,> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, default)?)) + } + } + + impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> { + fn set_pointer_builder<'b>(pointer: ::capnp::private::layout::PointerBuilder<'b>, value: Reader<'a,>, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } + } + + impl <'a,> Builder<'a,> { + pub fn into_reader(self) -> Reader<'a,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_,> { + Builder { .. *self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_name(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) + } + #[inline] + pub fn set_name(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_name(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(0).init_text(size) + } + #[inline] + pub fn has_name(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_type(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None) + } + #[inline] + pub fn set_type(&mut self, value: crate::schema_capnp::type_::Reader<'_>) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(1), value, false) + } + #[inline] + pub fn init_type(self, ) -> crate::schema_capnp::type_::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(1), 0) + } + #[inline] + pub fn has_type(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + } + + pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { _typeless: typeless, } + } + } + impl Pipeline { + pub fn get_type(&self) -> crate::schema_capnp::type_::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(1)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 2 }; + pub const TYPE_ID: u64 = 0x8186_fa95_8dce_799d; + } +} + pub mod type_ { pub use self::Which::{App,Fn,Var,Tuple}; @@ -2421,7 +2947,7 @@ pub mod type_ { self.reader.total_size() } #[inline] - pub fn get_arguments(self) -> ::capnp::Result<::capnp::struct_list::Reader<'a,crate::schema_capnp::type_::Owned>> { + pub fn get_arguments(self) -> ::capnp::Result<::capnp::struct_list::Reader<'a,crate::schema_capnp::function_argument::Owned>> { ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) } #[inline] @@ -2487,15 +3013,15 @@ pub mod type_ { self.builder.into_reader().total_size() } #[inline] - pub fn get_arguments(self) -> ::capnp::Result<::capnp::struct_list::Builder<'a,crate::schema_capnp::type_::Owned>> { + pub fn get_arguments(self) -> ::capnp::Result<::capnp::struct_list::Builder<'a,crate::schema_capnp::function_argument::Owned>> { ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) } #[inline] - pub fn set_arguments(&mut self, value: ::capnp::struct_list::Reader<'a,crate::schema_capnp::type_::Owned>) -> ::capnp::Result<()> { + pub fn set_arguments(&mut self, value: ::capnp::struct_list::Reader<'a,crate::schema_capnp::function_argument::Owned>) -> ::capnp::Result<()> { ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(0), value, false) } #[inline] - pub fn init_arguments(self, size: u32) -> ::capnp::struct_list::Builder<'a,crate::schema_capnp::type_::Owned> { + pub fn init_arguments(self, size: u32) -> ::capnp::struct_list::Builder<'a,crate::schema_capnp::function_argument::Owned> { ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), size) } #[inline] diff --git a/compiler-core/schema.capnp b/compiler-core/schema.capnp index 4a349e6877c..2a9733278b7 100644 --- a/compiler-core/schema.capnp +++ b/compiler-core/schema.capnp @@ -21,11 +21,13 @@ struct Option(Value) { struct Module { name @0 :Text; + documentation @10 :List(Text); types @1 :List(Property(TypeConstructor)); + typeAliases @11 :List(Property(TypeAliasConstructor)); values @2 :List(Property(ValueConstructor)); accessors @3 :List(Property(AccessorsMap)); package @4 :Text; - typesConstructors @5 :List(Property(TypesVariantConstructors)); + typesConstructors @5 :List(Property(TypesVariantConstructors)); lineNumbers @6 :LineNumbers; srcPath @7 :Text; isInternal @8 :Bool; @@ -50,6 +52,7 @@ struct TypeValueConstructor { struct TypeValueConstructorParameter { type @0 :Type; + label @1 :Text; } struct TypeConstructor { @@ -60,11 +63,22 @@ struct TypeConstructor { parameters @1 :List(Type); module @2 :Text; publicity @3 :Publicity; + opaque @7 :Bool; deprecated @4 :Text; origin @5 :SrcSpan; documentation @6 :Text; } +struct TypeAliasConstructor { + publicity @0 :Publicity; + module @1 :Text; + origin @2 :SrcSpan; + type @3 :Type; + arity @4 :UInt16; + deprecated @5 :Text; + documentation @6 :Text; +} + struct AccessorsMap { type @0 :Type; accessors @1 :List(Property(RecordAccessor)); @@ -76,6 +90,11 @@ struct RecordAccessor { label @2 :Text; } +struct FunctionArgument { + name @0 :Text; + type @1 :Type; +} + struct Type { union { app :group { @@ -86,7 +105,7 @@ struct Type { } fn :group { - arguments @3 :List(Type); + arguments @3 :List(FunctionArgument); return @4 :Type; } diff --git a/compiler-core/src/analyse.rs b/compiler-core/src/analyse.rs index 7a5bff7d7ff..b3284867381 100644 --- a/compiler-core/src/analyse.rs +++ b/compiler-core/src/analyse.rs @@ -27,9 +27,10 @@ use crate::{ fields::{FieldMap, FieldMapBuilder}, hydrator::Hydrator, prelude::*, - AccessorsMap, Deprecation, ModuleInterface, PatternConstructor, RecordAccessor, Type, - 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, @@ -296,6 +297,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> { let Environment { module_types: types, module_types_constructors: types_constructors, + module_type_aliases: type_aliases, module_values: values, accessors, names: type_names, @@ -318,13 +320,15 @@ impl<'a, A> ModuleAnalyzer<'a, A> { } let module = ast::Module { - documentation, + documentation: documentation.clone(), name: self.module_name.clone(), definitions: typed_statements, type_info: ModuleInterface { name: self.module_name, + documentation, types, types_value_constructors: types_constructors, + type_aliases, values, accessors, origin: self.origin, @@ -523,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_, @@ -965,10 +975,18 @@ impl<'a, A> ModuleAnalyzer<'a, A> { } }; - fields.push(TypeValueConstructorField { type_: t.clone() }); + fields.push(TypeValueConstructorField { + label: label + .as_ref() + .map_or(None, |(_, label)| Some(label.clone())), + type_: t.clone(), + }); // 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 { @@ -984,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 @@ -1121,6 +1139,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> { deprecation: deprecation.clone(), parameters, publicity, + opaque: *opaque, type_, documentation: documentation.as_ref().map(|(_, doc)| doc.clone()), }, @@ -1177,13 +1196,16 @@ impl<'a, A> ModuleAnalyzer<'a, A> { // in some fashion. let mut hydrator = Hydrator::new(); let parameters = self.make_type_vars(args, &mut hydrator, environment); - let tryblock = || { + let mut tryblock = || { hydrator.disallow_new_type_variables(); - let type_ = hydrator.type_from_ast(resolved_type, environment, &mut self.problems)?; + let type_ref = + hydrator.type_from_ast(resolved_type, environment, &mut self.problems)?; + let type_ = type_ref.as_ref().clone(); + let arity = parameters.len(); environment .names - .type_in_scope(name.clone(), type_.as_ref()); + .type_in_scope(name.clone(), type_ref.as_ref()); // Insert the alias so that it can be used by other code. environment.insert_type_constructor( @@ -1192,9 +1214,24 @@ impl<'a, A> ModuleAnalyzer<'a, A> { origin: *location, module: self.module_name.clone(), parameters, - type_, + type_: type_ref, deprecation: deprecation.clone(), publicity: *publicity, + // TODO: Find if the type is opaque + opaque: false, + documentation: documentation.as_ref().map(|(_, doc)| doc.clone()), + }, + )?; + + environment.insert_type_alias( + name.clone(), + TypeAliasConstructor { + origin: *location, + module: self.module_name.clone(), + type_, + arity, + publicity: *publicity, + deprecation: deprecation.clone(), documentation: documentation.as_ref().map(|(_, doc)| doc.clone()), }, )?; @@ -1294,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 = diff --git a/compiler-core/src/ast/tests.rs b/compiler-core/src/ast/tests.rs index 4aebb57720c..158abb59744 100644 --- a/compiler-core/src/ast/tests.rs +++ b/compiler-core/src/ast/tests.rs @@ -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, @@ -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, ); diff --git a/compiler-core/src/build.rs b/compiler-core/src/build.rs index 6132d0e7c9c..8d1df5d3f4c 100644 --- a/compiler-core/src/build.rs +++ b/compiler-core/src/build.rs @@ -20,6 +20,7 @@ use crate::ast::{ CallArg, CustomType, DefinitionLocation, Pattern, TypeAst, TypedArg, TypedDefinition, TypedExpr, TypedFunction, TypedPattern, TypedStatement, }; +use crate::package_interface; use crate::type_::Type; use crate::{ ast::{Definition, SrcSpan, TypedModule}, @@ -208,6 +209,7 @@ fn mode_includes_tests() { pub struct Package { pub config: PackageConfig, pub modules: Vec, + pub cached_modules: Vec, } impl Package { @@ -261,6 +263,8 @@ impl Module { .map(|span| Comment::from((span, self.code.as_str())).content.into()) .collect(); + self.ast.type_info.documentation = self.ast.documentation.clone(); + // Order statements to avoid misassociating doc comments after the // order has changed during compilation. let mut statements: Vec<_> = self.ast.definitions.iter_mut().collect(); diff --git a/compiler-core/src/build/module_loader/tests.rs b/compiler-core/src/build/module_loader/tests.rs index 19b296e2873..411dddd5cdc 100644 --- a/compiler-core/src/build/module_loader/tests.rs +++ b/compiler-core/src/build/module_loader/tests.rs @@ -3,6 +3,7 @@ use crate::{ build::SourceFingerprint, io::{memory::InMemoryFileSystem, FileSystemWriter}, line_numbers::LineNumbers, + package_interface, }; use std::time::Duration; diff --git a/compiler-core/src/build/package_compiler.rs b/compiler-core/src/build/package_compiler.rs index 76546ff5e5a..8c682177889 100644 --- a/compiler-core/src/build/package_compiler.rs +++ b/compiler-core/src/build/package_compiler.rs @@ -1,5 +1,6 @@ use crate::analyse::{ModuleAnalyzerConstructor, TargetSupport}; use crate::line_numbers::{self, LineNumbers}; +use crate::package_interface::{self, ModuleInterface}; use crate::type_::PRELUDE_MODULE_NAME; use crate::{ ast::{SrcSpan, TypedModule, UntypedModule}, @@ -22,6 +23,7 @@ use crate::{ }; use askama::Template; use ecow::EcoString; +use std::borrow::BorrowMut; use std::collections::HashSet; use std::{collections::HashMap, fmt::write, time::SystemTime}; use vec1::Vec1; @@ -30,6 +32,11 @@ use camino::{Utf8Path, Utf8PathBuf}; use super::{ErlangAppCodegenConfiguration, TargetCodegenConfiguration, Telemetry}; +pub struct Compiled { + pub modules: Vec, + pub cached_modules: Vec, +} + #[derive(Debug)] pub struct PackageCompiler<'a, IO> { pub io: IO, @@ -104,7 +111,7 @@ where stale_modules: &mut StaleTracker, incomplete_modules: &mut HashSet, telemetry: &dyn Telemetry, - ) -> Outcome, Error> { + ) -> Outcome { let span = tracing::info_span!("compile", package = %self.config.name.as_str()); let _enter = span.enter(); @@ -146,7 +153,7 @@ where }; // Load the cached modules that have previously been compiled - for module in loaded.cached.into_iter() { + for module in loaded.cached.clone().into_iter() { // Emit any cached warnings. // Note that `self.cached_warnings` is set to `Ignore` (such as for // dependency packages) then this field will not be populated. @@ -182,9 +189,18 @@ where incomplete_modules, ); - let modules = match outcome { + let mut modules = match outcome { Outcome::Ok(modules) => modules, - Outcome::PartialFailure(_, _) | Outcome::TotalFailure(_) => return outcome, + Outcome::PartialFailure(modules, err) => { + return Outcome::PartialFailure( + Compiled { + modules, + cached_modules: loaded.cached, + }, + err, + ) + } + Outcome::TotalFailure(err) => return Outcome::TotalFailure(err), }; tracing::debug!("performing_code_generation"); @@ -193,11 +209,18 @@ where return error.into(); } + for mut module in modules.iter_mut() { + module.ast.type_info.remove_duplicated_type_aliases(); + module.attach_doc_and_module_comments(); + } + if let Err(error) = self.encode_and_write_metadata(&modules) { return error.into(); } - - Outcome::Ok(modules) + Outcome::Ok(Compiled { + modules, + cached_modules: loaded.cached, + }) } fn compile_erlang_to_beam(&mut self, modules: &HashSet) -> Result<(), Error> { @@ -513,12 +536,15 @@ fn analyse( .infer_module(ast, line_numbers, path.clone()); match analysis { - Outcome::Ok(ast) => { + Outcome::Ok(mut ast) => { // Module has compiled successfully. Make sure it isn't marked as incomplete. let _ = incomplete_modules.remove(&name.clone()); // Register the types from this module so they can be imported into // other modules. let _ = module_types.insert(name.clone(), ast.type_info.clone()); + + ast.type_info.remove_duplicated_type_aliases(); + // Register the successfully type checked module data so that it can be // used for code generation and in the language server. modules.push(Module { @@ -533,7 +559,7 @@ fn analyse( }); } - Outcome::PartialFailure(ast, errors) => { + Outcome::PartialFailure(mut ast, errors) => { let error = Error::Type { names: ast.names.clone(), path: path.clone(), @@ -542,6 +568,9 @@ fn analyse( }; // Mark as incomplete so that this module isn't reloaded from cache. let _ = incomplete_modules.insert(name.clone()); + + ast.type_info.remove_duplicated_type_aliases(); + // Register the partially type checked module data so that it can be // used in the language server. modules.push(Module { diff --git a/compiler-core/src/build/package_loader/tests.rs b/compiler-core/src/build/package_loader/tests.rs index a29ec58bad5..b9e4bf83811 100644 --- a/compiler-core/src/build/package_loader/tests.rs +++ b/compiler-core/src/build/package_loader/tests.rs @@ -52,8 +52,10 @@ fn write_cache( name: name.into(), origin: Origin::Src, package: "my_package".into(), + documentation: vec![], types: Default::default(), types_value_constructors: Default::default(), + type_aliases: Default::default(), values: Default::default(), accessors: Default::default(), line_numbers: line_numbers.clone(), diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs index 95554558e71..92f1494d4c9 100644 --- a/compiler-core/src/build/project_compiler.rs +++ b/compiler-core/src/build/project_compiler.rs @@ -33,8 +33,9 @@ use std::{ }; use super::{ - elixir_libraries::ElixirLibraries, package_compiler::CachedWarnings, Codegen, Compile, - ErlangAppCodegenConfiguration, Outcome, + elixir_libraries::ElixirLibraries, + package_compiler::{CachedWarnings, Compiled}, + Codegen, Compile, ErlangAppCodegenConfiguration, Outcome, }; use camino::{Utf8Path, Utf8PathBuf}; @@ -208,7 +209,16 @@ where pub fn compile_root_package(&mut self) -> Outcome { let config = self.config.clone(); self.compile_gleam_package(&config, true, self.paths.root().to_path_buf()) - .map(|modules| Package { config, modules }) + .map( + |Compiled { + modules, + cached_modules, + }| Package { + config, + modules, + cached_modules, + }, + ) } /// Checks that version file found in the build directory matches the @@ -248,7 +258,10 @@ where let mut modules = vec![]; for name in sequence { - let compiled = self.load_cache_or_compile_package(&name)?; + let mut compiled = self.load_cache_or_compile_package(&name)?; + compiled.iter_mut().for_each(|module| { + module.ast.type_info.remove_duplicated_type_aliases(); + }); modules.extend(compiled); } @@ -288,7 +301,12 @@ where // longer need to have the package borrowed from self.packages. let package = self.packages.get(name).expect("Missing package").clone(); let result = match usable_build_tools(&package)?.as_slice() { - &[BuildTool::Gleam] => self.compile_gleam_dep_package(&package), + &[BuildTool::Gleam] => self.compile_gleam_dep_package(&package).map( + |Compiled { + modules, + cached_modules: _, + }| modules, + ), &[BuildTool::Rebar3] => self.compile_rebar3_dep_package(&package).map(|_| vec![]), &[BuildTool::Mix] => self.compile_mix_dep_package(&package).map(|_| vec![]), &[BuildTool::Mix, BuildTool::Rebar3] => self @@ -486,10 +504,7 @@ where } } - fn compile_gleam_dep_package( - &mut self, - package: &ManifestPackage, - ) -> Result, Error> { + fn compile_gleam_dep_package(&mut self, package: &ManifestPackage) -> Result { // TODO: Test let package_root = match &package.source { // If the path is relative it is relative to the root of the @@ -520,7 +535,7 @@ where config: &PackageConfig, is_root: bool, root_path: Utf8PathBuf, - ) -> Outcome, Error> { + ) -> Outcome { let out_path = self.paths .build_directory_for_package(self.mode(), self.target(), &config.name); diff --git a/compiler-core/src/docs/tests.rs b/compiler-core/src/docs/tests.rs index 8469cea2be1..20e8bc9837f 100644 --- a/compiler-core/src/docs/tests.rs +++ b/compiler-core/src/docs/tests.rs @@ -61,7 +61,8 @@ fn compile_with_markdown_pages( &mut HashSet::new(), &NullTelemetry, ) - .unwrap(); + .unwrap() + .modules; for module in &mut modules { module.attach_doc_and_module_comments(); diff --git a/compiler-core/src/erlang.rs b/compiler-core/src/erlang.rs index 5301c1252fd..1dd257e50cb 100644 --- a/compiler-core/src/erlang.rs +++ b/compiler-core/src/erlang.rs @@ -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, }; @@ -2140,7 +2140,7 @@ fn type_var_ids(type_: &Type, ids: &mut HashMap) { }, Type::Fn { args, retrn } => { for arg in args { - type_var_ids(arg, ids) + type_var_ids(&arg.type_, ids) } type_var_ids(retrn, ids); } @@ -2293,8 +2293,8 @@ impl<'a> TypePrinter<'a> { } } - fn print_fn(&self, args: &[Arc], 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() diff --git a/compiler-core/src/exhaustiveness.rs b/compiler-core/src/exhaustiveness.rs index dac96b8c8c7..608cac78ce1 100644 --- a/compiler-core/src/exhaustiveness.rs +++ b/compiler-core/src/exhaustiveness.rs @@ -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; @@ -878,6 +878,7 @@ impl ConstructorSpecialiser { let parameters = parameters .iter() .map(|p| TypeValueConstructorField { + label: None, type_: self.specialise_type(p.type_.as_ref()), }) .collect_vec(); @@ -904,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(), }, diff --git a/compiler-core/src/javascript/typescript.rs b/compiler-core/src/javascript/typescript.rs index 22e605caba3..8821c454284 100644 --- a/compiler-core/src/javascript/typescript.rs +++ b/compiler-core/src/javascript/typescript.rs @@ -106,7 +106,7 @@ fn generic_ids(type_: &Type, ids: &mut HashMap) { } Type::Fn { args, retrn } => { for arg in args { - generic_ids(arg, ids) + generic_ids(&arg.type_, ids) } generic_ids(retrn, ids); } @@ -561,7 +561,14 @@ impl<'a> TypeScriptGenerator<'a> { name, args, module, .. } => self.print_type_app(name, args, module, generic_usages), - Type::Fn { args, retrn } => self.print_fn(args, retrn, generic_usages), + Type::Fn { args, retrn } => self.print_fn( + args.iter() + .map(|a| a.type_.clone()) + .collect_vec() + .as_slice(), + retrn, + generic_usages, + ), Type::Tuple { elems } => tuple(elems.iter().map(|e| self.do_print(e, generic_usages))), } @@ -579,7 +586,14 @@ impl<'a> TypeScriptGenerator<'a> { name, args, module, .. } => self.print_type_app(name, args, module, None), - Type::Fn { args, retrn } => self.print_fn(args, retrn, None), + Type::Fn { args, retrn } => self.print_fn( + args.iter() + .map(|a| a.type_.clone()) + .collect_vec() + .as_slice(), + retrn, + None, + ), Type::Tuple { elems } => tuple(elems.iter().map(|e| self.do_print(e, None))), } diff --git a/compiler-core/src/language_server/compiler.rs b/compiler-core/src/language_server/compiler.rs index ab5b6ea5696..517672fe8f8 100644 --- a/compiler-core/src/language_server/compiler.rs +++ b/compiler-core/src/language_server/compiler.rs @@ -166,7 +166,9 @@ where .collect_vec(); // Store the compiled module information - for module in modules { + for mut module in modules { + module.ast.type_info.remove_duplicated_type_aliases(); + let path = module.input_path.as_os_str().to_string_lossy().to_string(); let line_numbers = LineNumbers::new(&module.code); let source = ModuleSourceInformation { path, line_numbers }; diff --git a/compiler-core/src/language_server/completer.rs b/compiler-core/src/language_server/completer.rs index c2d535894b7..458df149f95 100644 --- a/compiler-core/src/language_server/completer.rs +++ b/compiler-core/src/language_server/completer.rs @@ -16,7 +16,8 @@ use crate::{ line_numbers::LineNumbers, type_::{ self, collapse_links, pretty::Printer, AccessorsMap, FieldMap, ModuleInterface, - PreludeType, Type, TypeConstructor, ValueConstructorVariant, PRELUDE_MODULE_NAME, + PreludeType, Type, TypeAliasConstructor, TypeConstructor, ValueConstructorVariant, + PRELUDE_MODULE_NAME, }, Result, }; @@ -397,11 +398,18 @@ where }); } - // Module types + // Module types and type aliases // Do not complete direct module types if the user has already started typing a module select. // e.x. when the user has typed mymodule.| we know local module types are no longer relevant if module_select.is_none() { - for (name, type_) in &self.module.ast.type_info.types { + for (name, type_) in self + .module + .ast + .type_info + .types + .iter() + .filter(|(name, _)| !self.module.ast.type_info.type_aliases.contains_key(*name)) + { completions.push(type_completion( None, name, @@ -411,6 +419,16 @@ where CompletionKind::LocallyDefined, )); } + for (name, type_) in &self.module.ast.type_info.type_aliases { + completions.push(type_alias_completion( + None, + name, + type_, + insert_range, + TypeCompletionForm::Default, + CompletionKind::LocallyDefined, + )); + } } // Imported modules @@ -422,7 +440,11 @@ where }; // Qualified types - for (name, type_) in &module.types { + for (name, type_) in module + .types + .iter() + .filter(|(name, _)| !module.type_aliases.contains_key(*name)) + { if !self.is_suggestable_import(&type_.publicity, module.package.as_str()) { continue; } @@ -446,7 +468,32 @@ where } } - // Unqualified types + // Qualified type aliases + for (name, type_) in &module.type_aliases { + if !self.is_suggestable_import(&type_.publicity, module.package.as_str()) { + continue; + } + + if let Some(module) = import.used_name() { + // If the user has already started a module select then don't show irrelevant modules. + // e.x. when the user has typed mymodule.| we should only show items from mymodule. + if let Some(input_mod_name) = &module_select { + if &module != input_mod_name { + continue; + } + } + completions.push(type_alias_completion( + Some(&module), + name, + type_, + insert_range, + TypeCompletionForm::Default, + CompletionKind::ImportedModule, + )); + } + } + + // Unqualified types and type aliases // Do not complete unqualified types if the user has already started typing a module select. // e.x. when the user has typed mymodule.| we know unqualified module types are no longer relevant. if module_select.is_none() { @@ -498,7 +545,11 @@ where } // Qualified types - for (name, type_) in &module.types { + for (name, type_) in module + .types + .iter() + .filter(|(name, _)| !module.type_aliases.contains_key(*name)) + { if !self.is_suggestable_import(&type_.publicity, module.package.as_str()) { continue; } @@ -519,6 +570,29 @@ where ); completions.push(completion); } + + // Qualified type aliases + for (name, type_) in &module.type_aliases { + if !self.is_suggestable_import(&type_.publicity, module.package.as_str()) { + continue; + } + + let mut completion = type_alias_completion( + Some(qualifier), + name, + type_, + insert_range, + TypeCompletionForm::Default, + CompletionKind::ImportableModule, + ); + add_import_to_completion( + &mut completion, + import_location, + module_full_name, + &after_import_newlines, + ); + completions.push(completion); + } } completions @@ -872,6 +946,41 @@ fn type_completion( } } +fn type_alias_completion( + module: Option<&str>, + name: &str, + type_: &TypeAliasConstructor, + insert_range: Range, + include_type_in_completion: TypeCompletionForm, + priority: CompletionKind, +) -> CompletionItem { + let label = match module { + Some(module) => format!("{module}.{name}"), + None => name.to_string(), + }; + + let kind = Some(if type_.type_.is_variable() { + CompletionItemKind::VARIABLE + } else { + CompletionItemKind::CLASS + }); + + CompletionItem { + label: label.clone(), + kind, + detail: Some("Type".into()), + sort_text: Some(sort_text(priority, &label)), + text_edit: Some(CompletionTextEdit::Edit(TextEdit { + range: insert_range, + new_text: match include_type_in_completion { + TypeCompletionForm::UnqualifiedImport => format!("type {label}"), + TypeCompletionForm::Default => label.clone(), + }, + })), + ..Default::default() + } +} + fn value_completion( module_qualifier: Option<&str>, module_name: &str, diff --git a/compiler-core/src/language_server/engine.rs b/compiler-core/src/language_server/engine.rs index c3377e7d39b..164c71d42ae 100644 --- a/compiler-core/src/language_server/engine.rs +++ b/compiler-core/src/language_server/engine.rs @@ -790,7 +790,14 @@ fn hover_for_pattern(pattern: &TypedPattern, line_numbers: LineNumbers, module: fn get_function_type(fun: &TypedFunction) -> Type { Type::Fn { - args: fun.arguments.iter().map(|arg| arg.type_.clone()).collect(), + args: fun + .arguments + .iter() + .map(|arg| type_::FunctionArgument { + name: arg.names.get_variable_name().cloned(), + type_: arg.type_.clone(), + }) + .collect(), retrn: fun.return_type.clone(), } } diff --git a/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_function_definition_with_docs.snap b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_function_definition_with_docs.snap index 2cc8a9f13f6..8f699f6d13c 100644 --- a/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_function_definition_with_docs.snap +++ b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_function_definition_with_docs.snap @@ -13,6 +13,6 @@ fn append(x, y) { ----- Hover content ----- Scalar( String( - "```gleam\nfn(String, String) -> String\n```\n Exciting documentation\n Maybe even multiple lines\n", + "```gleam\nfn(String, String) -> String\n```\n Exciting documentation\n Maybe even multiple lines", ), ) diff --git a/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_module_constant.snap b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_module_constant.snap index be57c67f1c9..8c1170d7869 100644 --- a/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_module_constant.snap +++ b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__hover__hover_module_constant.snap @@ -11,6 +11,6 @@ const one = 1 ----- Hover content ----- Scalar( String( - "```gleam\nInt\n```\n Exciting documentation\n Maybe even multiple lines\n", + "```gleam\nInt\n```\n Exciting documentation\n Maybe even multiple lines", ), ) diff --git a/compiler-core/src/metadata/module_decoder.rs b/compiler-core/src/metadata/module_decoder.rs index e9f2a863622..665bca7c1d5 100755 --- a/compiler-core/src/metadata/module_decoder.rs +++ b/compiler-core/src/metadata/module_decoder.rs @@ -13,8 +13,9 @@ use crate::{ schema_capnp::{self as schema, *}, type_::{ self, expression::Implementations, AccessorsMap, Deprecation, FieldMap, ModuleInterface, - RecordAccessor, Type, TypeConstructor, TypeValueConstructor, TypeValueConstructorField, - TypeVariantConstructors, ValueConstructor, ValueConstructorVariant, + RecordAccessor, Type, TypeAliasConstructor, TypeConstructor, TypeValueConstructor, + TypeValueConstructorField, TypeVariantConstructors, ValueConstructor, + ValueConstructorVariant, }, uid::UniqueIdGenerator, Result, @@ -64,10 +65,14 @@ impl ModuleDecoder { let message_reader = capnp::serialize_packed::read_message(reader, capnp::message::ReaderOptions::new())?; let reader = message_reader.get_root::>()?; - Ok(ModuleInterface { name: reader.get_name()?.into(), package: reader.get_package()?.into(), + documentation: reader + .get_documentation()? + .iter() + .filter_map(|s| s.ok().map(|s| s.into())) + .collect(), is_internal: reader.get_is_internal(), origin: Origin::Src, values: read_hashmap!(reader.get_values()?, self, value_constructor), @@ -77,6 +82,7 @@ impl ModuleDecoder { self, type_variants_constructors ), + type_aliases: read_hashmap!(reader.get_type_aliases()?, self, type_alias_constructor), accessors: read_hashmap!(reader.get_accessors()?, self, accessors_map), line_numbers: self.line_numbers(&reader.get_line_numbers()?)?, src_path: reader.get_src_path()?.into(), @@ -98,6 +104,7 @@ impl ModuleDecoder { }; Ok(TypeConstructor { publicity: self.publicity(reader.get_publicity()?)?, + opaque: reader.get_opaque(), origin: self.src_span(&reader.get_origin()?)?, module: reader.get_module()?.into(), parameters: read_vec!(reader.get_parameters()?, self, type_), @@ -133,10 +140,19 @@ impl ModuleDecoder { fn type_fn(&mut self, reader: &schema::type_::fn_::Reader<'_>) -> Result> { let retrn = self.type_(&reader.get_return()?)?; - let args = read_vec!(&reader.get_arguments()?, self, type_); + let args = read_vec!(&reader.get_arguments()?, self, function_argument); Ok(Arc::new(Type::Fn { args, retrn })) } + fn function_argument( + &mut self, + reader: &function_argument::Reader<'_>, + ) -> Result { + let name = self.optional_string(reader.get_name()?); + let type_ = self.type_(&reader.get_type()?)?; + Ok(type_::FunctionArgument { name, type_ }) + } + fn type_tuple(&mut self, reader: &schema::type_::tuple::Reader<'_>) -> Result> { let elems = read_vec!(&reader.get_elements()?, self, type_); Ok(Arc::new(Type::Tuple { elems })) @@ -202,8 +218,32 @@ impl ModuleDecoder { reader: &type_value_constructor_parameter::Reader<'_>, ) -> Result { Ok(TypeValueConstructorField { + label: self.optional_string(reader.get_label()?), type_: self.type_(&reader.get_type()?)?, }) + // unimplemented!() + } + + fn type_alias_constructor( + &mut self, + reader: &type_alias_constructor::Reader<'_>, + ) -> Result { + let type_ = self.type_(&reader.get_type()?)?.as_ref().clone(); + let deprecation = match reader.get_deprecated()? { + "" => Deprecation::NotDeprecated, + message => Deprecation::Deprecated { + message: message.into(), + }, + }; + Ok(TypeAliasConstructor { + publicity: self.publicity(reader.get_publicity()?)?, + module: reader.get_module()?.into(), + origin: self.src_span(&reader.get_origin()?)?, + type_, + arity: reader.get_arity().into(), + deprecation, + documentation: self.optional_string(reader.get_documentation()?), + }) } fn value_constructor( diff --git a/compiler-core/src/metadata/module_encoder.rs b/compiler-core/src/metadata/module_encoder.rs index 2e30090659e..ae414a0f6e4 100644 --- a/compiler-core/src/metadata/module_encoder.rs +++ b/compiler-core/src/metadata/module_encoder.rs @@ -7,9 +7,9 @@ use crate::{ }, schema_capnp::{self as schema, *}, type_::{ - self, expression::Implementations, AccessorsMap, Deprecation, FieldMap, RecordAccessor, - Type, TypeConstructor, TypeValueConstructor, TypeVar, TypeVariantConstructors, - ValueConstructor, ValueConstructorVariant, + self, expression::Implementations, AccessorsMap, Deprecation, FieldMap, FunctionArgument, + RecordAccessor, Type, TypeAliasConstructor, TypeConstructor, TypeValueConstructor, TypeVar, + TypeVariantConstructors, ValueConstructor, ValueConstructorVariant, }, }; use std::{collections::HashMap, ops::Deref, sync::Arc}; @@ -38,11 +38,14 @@ impl<'a> ModuleEncoder<'a> { let mut message = capnp::message::Builder::new_default(); let mut module = message.init_root::>(); + module.set_name(&self.data.name); module.set_package(&self.data.package); module.set_src_path(self.data.src_path.as_str()); module.set_is_internal(self.data.is_internal); + self.set_documentation(&mut module); self.set_module_types(&mut module); + self.set_module_type_aliases(&mut module); self.set_module_values(&mut module); self.set_module_accessors(&mut module); self.set_module_types_constructors(&mut module); @@ -53,6 +56,15 @@ impl<'a> ModuleEncoder<'a> { Ok(buffer) } + fn set_documentation(&mut self, module: &mut module::Builder<'_>) { + let mut documentation = module + .reborrow() + .init_documentation(self.data.documentation.len() as u32); + for (i, doc) in self.data.documentation.iter().enumerate() { + documentation.reborrow().set(i as u32, doc); + } + } + fn set_line_numbers(&mut self, module: &mut module::Builder<'_>) { let mut line_numbers = module.reborrow().init_line_numbers(); line_numbers.set_length(self.data.line_numbers.length); @@ -121,6 +133,18 @@ impl<'a> ModuleEncoder<'a> { } } + fn set_module_type_aliases(&mut self, module: &mut module::Builder<'_>) { + tracing::trace!("Writing module metadata type aliases"); + let mut type_aliases = module + .reborrow() + .init_type_aliases(self.data.type_aliases.len() as u32); + for (i, (name, data)) in self.data.type_aliases.iter().enumerate() { + let mut property = type_aliases.reborrow().get(i as u32); + property.set_key(name); + self.build_type_aliases(property.init_value(), data) + } + } + fn build_type_variant_constructors( &mut self, mut builder: types_variant_constructors::Builder<'_>, @@ -169,6 +193,7 @@ impl<'a> ModuleEncoder<'a> { Deprecation::Deprecated { message } => message, }); self.build_publicity(builder.reborrow().init_publicity(), constructor.publicity); + builder.set_opaque(constructor.opaque); let type_builder = builder.reborrow().init_type(); self.build_type(type_builder, &constructor.type_); self.build_types( @@ -187,6 +212,29 @@ impl<'a> ModuleEncoder<'a> { ); } + fn build_type_aliases( + &mut self, + mut builder: type_alias_constructor::Builder<'_>, + constructor: &TypeAliasConstructor, + ) { + builder.set_module(&constructor.module); + builder.set_deprecated(match &constructor.deprecation { + Deprecation::NotDeprecated => "", + Deprecation::Deprecated { message } => message, + }); + self.build_publicity(builder.reborrow().init_publicity(), constructor.publicity); + let type_builder = builder.reborrow().init_type(); + self.build_type(type_builder, &constructor.type_); + builder.set_arity(constructor.arity as u16); + builder.set_documentation( + constructor + .documentation + .as_ref() + .map(EcoString::as_str) + .unwrap_or_default(), + ); + } + fn build_type_value_constructor( &mut self, mut builder: type_value_constructor::Builder<'_>, @@ -204,9 +252,16 @@ impl<'a> ModuleEncoder<'a> { fn build_type_value_constructor_parameter( &mut self, - builder: type_value_constructor_parameter::Builder<'_>, + mut builder: type_value_constructor_parameter::Builder<'_>, parameter: &type_::TypeValueConstructorField, ) { + builder.set_label( + parameter + .label + .as_ref() + .map(EcoString::as_str) + .unwrap_or_default(), + ); self.build_type(builder.init_type(), parameter.type_.as_ref()); } @@ -490,11 +545,36 @@ impl<'a> ModuleEncoder<'a> { } } + fn build_function_argument( + &mut self, + mut builder: function_argument::Builder<'_>, + arg: &FunctionArgument, + ) { + match &arg.name { + Some(name) => builder.set_name(name), + None => builder.set_name(""), + } + self.build_type(builder.init_type(), arg.type_.as_ref()); + } + + fn build_function_arguments( + &mut self, + mut builder: capnp::struct_list::Builder<'_, function_argument::Owned>, + args: &[FunctionArgument], + ) { + for (i, arg) in args.iter().enumerate() { + self.build_function_argument(builder.reborrow().get(i as u32), arg); + } + } + fn build_type(&mut self, builder: schema::type_::Builder<'_>, type_: &Type) { match type_ { Type::Fn { args, retrn } => { let mut fun = builder.init_fn(); - self.build_types(fun.reborrow().init_arguments(args.len() as u32), args); + self.build_function_arguments( + fun.reborrow().init_arguments(args.len() as u32), + args, + ); self.build_type(fun.init_return(), retrn) } diff --git a/compiler-core/src/metadata/tests.rs b/compiler-core/src/metadata/tests.rs index eef3a863700..533ad3999a6 100644 --- a/compiler-core/src/metadata/tests.rs +++ b/compiler-core/src/metadata/tests.rs @@ -11,9 +11,9 @@ use crate::{ build::Origin, line_numbers::LineNumbers, type_::{ - self, expression::Implementations, Deprecation, ModuleInterface, Type, TypeConstructor, - TypeValueConstructor, TypeValueConstructorField, TypeVariantConstructors, ValueConstructor, - ValueConstructorVariant, + self, expression::Implementations, Deprecation, FunctionArgument, ModuleInterface, Type, + TypeConstructor, TypeValueConstructor, TypeValueConstructorField, TypeVariantConstructors, + ValueConstructor, ValueConstructorVariant, }, uid::UniqueIdGenerator, }; @@ -35,9 +35,11 @@ fn constant_module(constant: TypedConstant) -> ModuleInterface { is_internal: true, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -89,9 +91,11 @@ fn empty_module() { is_internal: true, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "one/two".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -108,9 +112,11 @@ fn with_line_numbers() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "one/two".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new( @@ -131,12 +137,14 @@ fn module_with_private_type() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b".into(), types: [( "ListIntType".into(), TypeConstructor { type_: type_::list(type_::int()), publicity: Publicity::Private, + opaque: false, origin: Default::default(), module: "the/module".into(), parameters: vec![], @@ -146,6 +154,7 @@ fn module_with_private_type() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -162,12 +171,14 @@ fn module_with_app_type() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b".into(), types: [( "ListIntType".into(), TypeConstructor { type_: type_::list(type_::int()), publicity: Publicity::Public, + opaque: false, origin: Default::default(), module: "the/module".into(), parameters: vec![], @@ -177,6 +188,7 @@ fn module_with_app_type() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -193,12 +205,26 @@ fn module_with_fn_type() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b".into(), types: [( "FnType".into(), TypeConstructor { - type_: type_::fn_(vec![type_::nil(), type_::float()], type_::int()), + type_: type_::fn_( + vec![ + FunctionArgument { + name: None, + type_: type_::nil(), + }, + FunctionArgument { + name: None, + type_: type_::float(), + }, + ], + type_::int(), + ), publicity: Publicity::Public, + opaque: false, origin: Default::default(), module: "the/module".into(), parameters: vec![], @@ -208,6 +234,7 @@ fn module_with_fn_type() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -224,12 +251,14 @@ fn module_with_tuple_type() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b".into(), types: [( "TupleType".into(), TypeConstructor { type_: type_::tuple(vec![type_::nil(), type_::float(), type_::int()]), publicity: Publicity::Public, + opaque: false, origin: Default::default(), module: "the/module".into(), parameters: vec![], @@ -239,6 +268,7 @@ fn module_with_tuple_type() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -261,12 +291,14 @@ fn module_with_generic_type() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b".into(), types: [( "TupleType".into(), TypeConstructor { type_: type_::tuple(vec![t1.clone(), t1.clone(), t2.clone()]), publicity: Publicity::Public, + opaque: false, origin: Default::default(), module: "the/module".into(), parameters: vec![t1, t2], @@ -276,6 +308,7 @@ fn module_with_generic_type() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -298,12 +331,14 @@ fn module_with_type_links() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: [( "SomeType".into(), TypeConstructor { type_, publicity: Publicity::Public, + opaque: false, origin: Default::default(), module: "a".into(), parameters: vec![], @@ -313,6 +348,7 @@ fn module_with_type_links() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -335,12 +371,14 @@ fn module_with_type_constructor_documentation() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: [( "SomeType".into(), TypeConstructor { type_, publicity: Publicity::Public, + opaque: false, origin: Default::default(), module: "a".into(), parameters: vec![], @@ -350,6 +388,7 @@ fn module_with_type_constructor_documentation() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -372,12 +411,14 @@ fn module_with_type_constructor_origin() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: [( "SomeType".into(), TypeConstructor { type_, publicity: Publicity::Public, + opaque: false, origin: SrcSpan { start: 535, end: 543, @@ -390,6 +431,7 @@ fn module_with_type_constructor_origin() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -408,6 +450,7 @@ fn module_type_to_constructors_mapping() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: [( @@ -421,6 +464,7 @@ fn module_type_to_constructors_mapping() { }, )] .into(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -438,9 +482,11 @@ fn module_fn_value() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -485,9 +531,11 @@ fn deprecated_module_fn_value() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -534,9 +582,11 @@ fn private_module_fn_value() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -583,9 +633,11 @@ fn module_fn_value_regression() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b/c".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -631,9 +683,11 @@ fn module_fn_value_with_field_map() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -681,9 +735,11 @@ fn record_value() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -724,9 +780,11 @@ fn record_value_with_field_map() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -768,9 +826,11 @@ fn accessors() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: [ ( @@ -982,9 +1042,11 @@ fn constant_var() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [ ( @@ -1202,12 +1264,14 @@ fn deprecated_type() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b".into(), types: [( "ListIntType".into(), TypeConstructor { type_: type_::list(type_::int()), publicity: Publicity::Public, + opaque: false, origin: Default::default(), module: "the/module".into(), parameters: vec![], @@ -1219,6 +1283,7 @@ fn deprecated_type() { )] .into(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), @@ -1235,9 +1300,11 @@ fn module_fn_value_with_external_implementations() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b/c".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -1283,9 +1350,11 @@ fn internal_module_fn() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b/c".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -1333,9 +1402,11 @@ fn internal_annotated_module_fn() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b/c".into(), types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [( "one".into(), @@ -1387,6 +1458,7 @@ fn type_variable_ids_in_constructors_are_shared() { is_internal: false, package: "some_package".into(), origin: Origin::Src, + documentation: vec![], name: "a/b/c".into(), types: HashMap::new(), types_value_constructors: HashMap::from([( @@ -1397,18 +1469,22 @@ fn type_variable_ids_in_constructors_are_shared() { name: "One".into(), parameters: vec![ TypeValueConstructorField { + label: None, type_: type_::generic_var(6), }, TypeValueConstructorField { + label: None, type_: type_::int(), }, TypeValueConstructorField { + label: None, type_: type_::tuple(vec![type_::generic_var(4), type_::generic_var(5)]), }, ], }], }, )]), + type_aliases: HashMap::new(), accessors: HashMap::new(), values: [].into(), line_numbers: LineNumbers::new(""), @@ -1424,12 +1500,15 @@ fn type_variable_ids_in_constructors_are_shared() { name: "One".into(), parameters: vec![ TypeValueConstructorField { + label: None, type_: type_::generic_var(0), }, TypeValueConstructorField { + label: None, type_: type_::int(), }, TypeValueConstructorField { + label: None, type_: type_::tuple(vec![type_::generic_var(1), type_::generic_var(2)]), }, ], diff --git a/compiler-core/src/package_interface.rs b/compiler-core/src/package_interface.rs index 936902ddb82..3608232ff88 100644 --- a/compiler-core/src/package_interface.rs +++ b/compiler-core/src/package_interface.rs @@ -1,19 +1,20 @@ use std::{collections::HashMap, ops::Deref}; use ecow::EcoString; -use itertools::Itertools; use serde::Serialize; #[cfg(test)] mod tests; use crate::{ - ast::{CustomType, Definition, Function, ModuleConstant, Publicity, TypeAlias}, io::ordered_map, - type_::{expression::Implementations, Deprecation, Type, TypeVar}, + type_::{ + self, expression::Implementations, Deprecation, Type, TypeConstructor, TypeVar, + ValueConstructorVariant, + }, }; -use crate::build::{Module, Package}; +use crate::build::Package; /// The public interface of a package that gets serialised as a json object. #[derive(Serialize, Debug)] @@ -370,162 +371,133 @@ impl PackageInterface { modules: package .modules .iter() + .map(|module| &module.ast.type_info) + .chain(package.cached_modules.iter()) .filter(|module| !package.config.is_internal_module(module.name.as_str())) - .map(|module| (module.name.clone(), ModuleInterface::from_module(module))) + .map(|interface| { + ( + interface.name.clone(), + ModuleInterface::from_interface(interface), + ) + }) .collect(), } } } impl ModuleInterface { - fn from_module(module: &Module) -> ModuleInterface { + pub fn from_interface(interface: &type_::ModuleInterface) -> ModuleInterface { let mut types = HashMap::new(); let mut type_aliases = HashMap::new(); let mut constants = HashMap::new(); let mut functions = HashMap::new(); - for statement in &module.ast.definitions { - match statement { - // A public type definition. - Definition::CustomType(CustomType { - publicity: Publicity::Public, - name, - constructors, - documentation, - opaque, - deprecation, - typed_parameters, - parameters: _, - location: _, - name_location: _, - end_position: _, - }) => { - let mut id_map = IdMap::new(); + for (name, constructor) in interface + .types + .iter() + .filter(|(_, c)| c.publicity.is_public()) + { + let mut id_map = IdMap::new(); - // Let's first add all the types that appear in the type parameters so those are - // taken into account when assigning incremental numbers to the constructor's - // type variables. - for typed_parameter in typed_parameters { - id_map.add_type_variable_id(typed_parameter.as_ref()); - } + let TypeConstructor { + deprecation, + documentation, + .. + } = constructor; - let _ = types.insert( - name.clone(), - TypeDefinitionInterface { - documentation: documentation.as_ref().map(|(_, doc)| doc.clone()), - deprecation: DeprecationInterface::from_deprecation(deprecation), - parameters: typed_parameters.len(), - constructors: if *opaque { - vec![] - } else { - constructors - .iter() - .map(|constructor| TypeConstructorInterface { - documentation: constructor - .documentation - .as_ref() - .map(|(_, doc)| doc.clone()), - name: constructor.name.clone(), - parameters: constructor - .arguments - .iter() - .map(|arg| ParameterInterface { - label: arg - .label - .as_ref() - .map(|(_, label)| label.clone()), - // We share the same id_map between each step so that the - // incremental ids assigned are consisten with each other - type_: from_type_helper(&arg.type_, &mut id_map), - }) - .collect_vec(), - }) - .collect() - }, - }, - ); - } + for typed_parameter in &constructor.parameters { + id_map.add_type_variable_id(typed_parameter.as_ref()); + } - // A public type alias definition - Definition::TypeAlias(TypeAlias { - publicity: Publicity::Public, - alias, - parameters, - type_, - documentation, - deprecation, - location: _, - name_location: _, - type_ast: _, - }) => { - let _ = type_aliases.insert( - alias.clone(), - TypeAliasInterface { - documentation: documentation.as_ref().map(|(_, doc)| doc.clone()), - deprecation: DeprecationInterface::from_deprecation(deprecation), - parameters: parameters.len(), - alias: TypeInterface::from_type(type_.as_ref()), - }, - ); - } + let _ = types.insert( + name.clone(), + TypeDefinitionInterface { + documentation: documentation.clone(), + deprecation: DeprecationInterface::from_deprecation(&deprecation), + parameters: interface + .types + .get(&name.clone()) + .map_or(vec![], |t| t.parameters.clone()) + .len(), + constructors: if constructor.opaque { + vec![] + } else { + match interface.types_value_constructors.get(&name.clone()) { + Some(constructors) => constructors + .variants + .iter() + .map(|constructor| TypeConstructorInterface { + // TODO: Find documentation + documentation: None, + name: constructor.name.clone(), + parameters: constructor + .parameters + .iter() + .map(|arg| ParameterInterface { + label: arg.label.clone(), + // We share the same id_map between each step so that the + // incremental ids assigned are consisten with each other + type_: from_type_helper( + arg.type_.as_ref(), + &mut id_map, + ), + }) + .collect(), + }) + .collect(), + None => vec![], + } + }, + }, + ); + } - // A public module constant. - Definition::ModuleConstant(ModuleConstant { - publicity: Publicity::Public, - name, - type_, - documentation, - implementations, - deprecation, - location: _, - name_location: _, - annotation: _, - value: _, - }) => { - let _ = constants.insert( - name.clone(), - ConstantInterface { - implementations: ImplementationsInterface::from_implementations( - implementations, - ), - type_: TypeInterface::from_type(type_.as_ref()), - deprecation: DeprecationInterface::from_deprecation(deprecation), - documentation: documentation.as_ref().map(|(_, doc)| doc.clone()), - }, - ); - } + for (name, alias) in interface + .type_aliases + .iter() + .filter(|(_, v)| v.publicity.is_public()) + { + let _ = type_aliases.insert( + name.clone(), + TypeAliasInterface { + documentation: alias.documentation.clone(), + deprecation: DeprecationInterface::from_deprecation(&alias.deprecation), + parameters: alias.arity, + alias: TypeInterface::from_type(&alias.type_), + }, + ); + } - // A public top-level function. - Definition::Function(Function { - publicity: Publicity::Public, - name, - arguments, - deprecation, - return_type, - documentation, - implementations, - location: _, - end_position: _, - body: _, - return_annotation: _, - external_erlang: _, - external_javascript: _, - }) => { + for (name, value) in interface + .values + .iter() + .filter(|(_, v)| v.publicity.is_public()) + { + match (value.type_.as_ref(), value.variant.clone()) { + ( + Type::Fn { + args: arguments, + retrn: return_type, + }, + ValueConstructorVariant::ModuleFn { + documentation, + implementations, + .. + }, + ) => { let mut id_map = IdMap::new(); - let (_, name) = name - .as_ref() - .expect("Function in a definition must be named"); + let _ = functions.insert( name.clone(), FunctionInterface { implementations: ImplementationsInterface::from_implementations( - implementations, + &implementations, ), - deprecation: DeprecationInterface::from_deprecation(deprecation), - documentation: documentation.as_ref().map(|(_, doc)| doc.clone()), + deprecation: DeprecationInterface::from_deprecation(&value.deprecation), + documentation, parameters: arguments .iter() .map(|arg| ParameterInterface { - label: arg.names.get_label().cloned(), + label: arg.name.clone(), type_: from_type_helper(arg.type_.as_ref(), &mut id_map), }) .collect(), @@ -534,19 +506,33 @@ impl ModuleInterface { ); } - // Private or internal definitions are not included. - Definition::Function(_) => {} - Definition::CustomType(_) => {} - Definition::ModuleConstant(_) => {} - Definition::TypeAlias(_) => {} + ( + type_, + ValueConstructorVariant::ModuleConstant { + documentation, + implementations, + .. + }, + ) => { + let _ = constants.insert( + name.clone(), + ConstantInterface { + implementations: ImplementationsInterface::from_implementations( + &implementations, + ), + type_: TypeInterface::from_type(type_), + deprecation: DeprecationInterface::from_deprecation(&value.deprecation), + documentation, + }, + ); + } - // Imports are ignored. - Definition::Import(_) => {} + _ => {} } } ModuleInterface { - documentation: module.ast.documentation.clone(), + documentation: interface.documentation.clone(), types, type_aliases, constants, @@ -570,7 +556,7 @@ fn from_type_helper(type_: &Type, id_map: &mut IdMap) -> TypeInterface { Type::Fn { args, retrn } => TypeInterface::Fn { parameters: args .iter() - .map(|arg| from_type_helper(arg.as_ref(), id_map)) + .map(|arg| from_type_helper(arg.type_.as_ref(), id_map)) .collect(), return_: Box::new(from_type_helper(retrn, id_map)), }, diff --git a/compiler-core/src/package_interface/snapshots/gleam_core__package_interface__tests__type_definition.snap b/compiler-core/src/package_interface/snapshots/gleam_core__package_interface__tests__type_definition.snap index dc114d48457..cacf1cc9868 100644 --- a/compiler-core/src/package_interface/snapshots/gleam_core__package_interface__tests__type_definition.snap +++ b/compiler-core/src/package_interface/snapshots/gleam_core__package_interface__tests__type_definition.snap @@ -12,7 +12,7 @@ expression: "\n/// Wibble's documentation\npub type Wibble(a, b) {\n Wibble\n "type-aliases": {}, "types": { "Wibble": { - "documentation": " Wibble's documentation", + "documentation": " Wibble's documentation\n", "deprecation": null, "parameters": 2, "constructors": [ diff --git a/compiler-core/src/package_interface/tests.rs b/compiler-core/src/package_interface/tests.rs index 5495a848db9..54e57d0868c 100644 --- a/compiler-core/src/package_interface/tests.rs +++ b/compiler-core/src/package_interface/tests.rs @@ -133,6 +133,7 @@ pub fn compile_package( extra: parsed.extra, dependencies: vec![], }; + module.ast.type_info.remove_duplicated_type_aliases(); module.attach_doc_and_module_comments(); let package: Package = package_from_module(module); serde_json::to_string_pretty(&PackageInterface::from_package(&package)).expect("to json") @@ -172,6 +173,7 @@ fn package_from_module(module: Module) -> Package { .expect("internals glob")]), }, modules: vec![module], + cached_modules: vec![], } } diff --git a/compiler-core/src/parse/extra.rs b/compiler-core/src/parse/extra.rs index b6e2cb6a060..72003014daf 100644 --- a/compiler-core/src/parse/extra.rs +++ b/compiler-core/src/parse/extra.rs @@ -4,7 +4,7 @@ use ecow::EcoString; use crate::ast::SrcSpan; -#[derive(Debug, PartialEq, Eq, Default)] +#[derive(Debug, PartialEq, Eq, Default, Clone)] pub struct ModuleExtra { pub module_comments: Vec, pub doc_comments: Vec, diff --git a/compiler-core/src/type_.rs b/compiler-core/src/type_.rs index 38b3369e0a4..ef5518c64b8 100644 --- a/compiler-core/src/type_.rs +++ b/compiler-core/src/type_.rs @@ -68,7 +68,7 @@ pub enum Type { /// The type of a function. It takes arguments and returns a value. /// Fn { - args: Vec>, + args: Vec, retrn: Arc, }, @@ -141,7 +141,10 @@ impl Type { pub fn fn_types(&self) -> Option<(Vec>, Arc)> { match self { - Self::Fn { args, retrn, .. } => Some((args.clone(), retrn.clone())), + Self::Fn { args, retrn, .. } => Some(( + args.iter().map(|a| a.type_.clone()).collect(), + retrn.clone(), + )), Self::Var { type_ } => type_.borrow().fn_types(), _ => None, } @@ -316,7 +319,7 @@ impl Type { Self::Fn { retrn, args, .. } => retrn .find_private_type() - .or_else(|| args.iter().find_map(|t| t.find_private_type())), + .or_else(|| args.iter().find_map(|t| t.type_.find_private_type())), Self::Var { type_, .. } => match type_.borrow().deref() { TypeVar::Unbound { .. } => None, @@ -338,7 +341,7 @@ impl Type { Self::Fn { retrn, args, .. } => retrn .find_internal_type() - .or_else(|| args.iter().find_map(|t| t.find_internal_type())), + .or_else(|| args.iter().find_map(|t| t.type_.find_internal_type())), Self::Var { type_, .. } => match type_.borrow().deref() { TypeVar::Unbound { .. } | TypeVar::Generic { .. } => None, @@ -364,6 +367,12 @@ pub fn collapse_links(t: Arc) -> Arc { t } +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct FunctionArgument { + pub name: Option, + pub type_: Arc, +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct AccessorsMap { pub publicity: Publicity, @@ -619,8 +628,10 @@ pub struct ModuleInterface { pub name: EcoString, pub origin: Origin, pub package: EcoString, + pub documentation: Vec, pub types: HashMap, pub types_value_constructors: HashMap, + pub type_aliases: HashMap, pub values: HashMap, pub accessors: HashMap, /// Used for mapping to original source locations on disk @@ -641,6 +652,11 @@ impl ModuleInterface { pub fn contains_todo(&self) -> bool { self.warnings.iter().any(|warning| warning.is_todo()) } + + pub fn remove_duplicated_type_aliases(&mut self) { + self.types + .retain(|name, _| !self.type_aliases.contains_key(name)); + } } /// Information on the constructors of a custom type. @@ -701,6 +717,7 @@ pub struct TypeValueConstructor { #[derive(Debug, Clone, PartialEq, Eq)] pub struct TypeValueConstructorField { + pub label: Option, /// This type of this parameter pub type_: Arc, } @@ -915,6 +932,7 @@ impl TypeVar { #[derive(Debug, Clone, PartialEq, Eq)] pub struct TypeConstructor { pub publicity: Publicity, + pub opaque: bool, pub origin: SrcSpan, pub module: EcoString, pub parameters: Vec>, @@ -1009,8 +1027,11 @@ impl ValueConstructor { pub struct TypeAliasConstructor { pub publicity: Publicity, pub module: EcoString, + pub origin: SrcSpan, pub type_: Type, pub arity: usize, + pub deprecation: Deprecation, + pub documentation: Option, } impl ValueConstructor { @@ -1075,7 +1096,7 @@ fn unify_unbound_type(type_: Arc, own_id: u64) -> Result<(), UnifyError> { Type::Fn { args, retrn } => { for arg in args { - unify_unbound_type(arg.clone(), own_id)?; + unify_unbound_type(arg.type_.clone(), own_id)?; } unify_unbound_type(retrn.clone(), own_id) } @@ -1113,7 +1134,15 @@ fn match_fun_type( if let Some((args, retrn)) = new_value { *type_.borrow_mut() = TypeVar::Link { - type_: fn_(args.clone(), retrn.clone()), + type_: fn_( + args.iter() + .map(|t| FunctionArgument { + name: None, + type_: t.clone(), + }) + .collect(), + retrn.clone(), + ), }; return Ok((args, retrn)); } @@ -1124,11 +1153,14 @@ fn match_fun_type( Err(MatchFunTypeError::IncorrectArity { expected: args.len(), given: arity, - args: args.clone(), + args: args.iter().map(|a| a.type_.clone()).collect(), return_type: retrn.clone(), }) } else { - Ok((args.clone(), retrn.clone())) + Ok(( + args.iter().map(|a| a.type_.clone()).collect(), + retrn.clone(), + )) }; } @@ -1163,7 +1195,12 @@ pub fn generalise(t: Arc) -> Arc { } Type::Fn { args, retrn } => fn_( - args.iter().map(|t| generalise(t.clone())).collect(), + args.iter() + .map(|t| FunctionArgument { + name: t.name.clone(), + type_: generalise(t.type_.clone()), + }) + .collect(), generalise(retrn.clone()), ), diff --git a/compiler-core/src/type_/environment.rs b/compiler-core/src/type_/environment.rs index 9129bb1d856..a99c2eb73da 100644 --- a/compiler-core/src/type_/environment.rs +++ b/compiler-core/src/type_/environment.rs @@ -47,6 +47,9 @@ pub struct Environment<'a> { /// Mapping from types to constructor names in the current module (or the prelude) pub module_types_constructors: HashMap, + /// Mapping from type aliases to constructor names in the current module (or the prelude) + pub module_type_aliases: HashMap, + /// Values defined in the current module (or the prelude) pub module_values: HashMap, @@ -101,6 +104,7 @@ impl<'a> Environment<'a> { target, module_types: prelude.types.clone(), module_types_constructors: prelude.types_value_constructors.clone(), + module_type_aliases: prelude.type_aliases.clone(), module_values: HashMap::new(), imported_modules: HashMap::new(), unused_modules: HashMap::new(), @@ -314,6 +318,28 @@ impl<'a> Environment<'a> { } } + /// Map a type alias in the current scope. + /// Errors if the module already has a type with that name, unless the type is from the + /// prelude. + /// + pub fn insert_type_alias( + &mut self, + type_name: EcoString, + info: TypeAliasConstructor, + ) -> Result<(), Error> { + let name = type_name.clone(); + let location = info.origin; + match self.module_type_aliases.insert(type_name, info) { + None => Ok(()), + Some(prelude_type) if is_prelude_module(&prelude_type.module) => Ok(()), + Some(previous) => Err(Error::DuplicateTypeName { + name, + location, + previous_location: previous.origin, + }), + } + } + pub fn assert_unique_type_name( &mut self, name: &EcoString, @@ -353,6 +379,19 @@ impl<'a> Environment<'a> { None => self .module_types .get(name) + // .or_else(|| { + // self.module_type_aliases + // .get(name) + // .map(|t| &TypeConstructor { + // opaque: false, + // type_: Arc::new(t.type_.clone()), + // deprecation: t.deprecation, + // origin: t.origin, + // module: t.module.clone(), + // parameters: t.parameters.clone(), + // publicity: t.publicity, + // }) + // }) .ok_or_else(|| UnknownTypeConstructorError::Type { name: name.clone(), hint: self.unknown_type_hint(name), @@ -371,6 +410,12 @@ impl<'a> Environment<'a> { module .types .get(name) + // .map(|t| t.type_.clone()) + // .or_else(|| { + // self.module_type_aliases + // .get(name) + // .map(|t| Arc::new(t.type_.clone())) + // }) .ok_or_else(|| UnknownTypeConstructorError::ModuleType { name: name.clone(), module_name: module.name.clone(), @@ -532,7 +577,10 @@ impl<'a> Environment<'a> { Type::Fn { args, retrn, .. } => fn_( args.iter() - .map(|t| self.instantiate(t.clone(), ids, hydrator)) + .map(|t| FunctionArgument { + name: None, + type_: self.instantiate(t.type_.clone(), ids, hydrator), + }) .collect(), self.instantiate(retrn.clone(), ids, hydrator), ), @@ -847,8 +895,8 @@ pub fn unify(t1: Arc, t2: Arc) -> Result<(), UnifyError> { } for (i, (a, b)) in args1.iter().zip(args2).enumerate() { - unify(a.clone(), b.clone()) - .map_err(|_| unify_wrong_arguments(&t1, a, &t2, b, i))?; + unify(a.type_.clone(), b.type_.clone()) + .map_err(|_| unify_wrong_arguments(&t1, &a.type_, &t2, &b.type_, i))?; } unify(retrn1.clone(), retrn2.clone()) diff --git a/compiler-core/src/type_/expression.rs b/compiler-core/src/type_/expression.rs index 0785f72710e..9c4016c5db8 100644 --- a/compiler-core/src/type_/expression.rs +++ b/compiler-core/src/type_/expression.rs @@ -745,7 +745,13 @@ impl<'a, 'b> ExprTyper<'a, 'b> { self.previous_panics = false; let (args, body) = self.do_infer_fn(args, expected_args, body, &return_annotation)?; - let args_types = args.iter().map(|a| a.type_.clone()).collect(); + let args_types = args + .iter() + .map(|a| FunctionArgument { + name: None, + type_: a.type_.clone(), + }) + .collect(); let type_ = fn_(args_types, body.last().type_()); // Defining an anonymous function never panics. @@ -3245,7 +3251,11 @@ impl<'a, 'b> ExprTyper<'a, 'b> { }, ) if expected_arguments.len() == arguments.len() => self.infer_fn( arguments, - expected_arguments, + expected_arguments + .iter() + .map(|a| a.type_.clone()) + .collect_vec() + .as_slice(), body, false, return_annotation, diff --git a/compiler-core/src/type_/hydrator.rs b/compiler-core/src/type_/hydrator.rs index 772de1e16d3..b3561e86802 100644 --- a/compiler-core/src/type_/hydrator.rs +++ b/compiler-core/src/type_/hydrator.rs @@ -204,7 +204,12 @@ impl Hydrator { }) => { let args = args .iter() - .map(|t| self.type_from_ast(t, environment, problems)) + .map(|t| { + Ok(FunctionArgument { + name: None, + type_: self.type_from_ast(t, environment, problems)?, + }) + }) .try_collect()?; let retrn = self.type_from_ast(retrn, environment, problems)?; Ok(fn_(args, retrn)) diff --git a/compiler-core/src/type_/pattern.rs b/compiler-core/src/type_/pattern.rs index b6913e20ecc..09fb476159a 100644 --- a/compiler-core/src/type_/pattern.rs +++ b/compiler-core/src/type_/pattern.rs @@ -646,7 +646,7 @@ impl<'a, 'b> PatternTyper<'a, 'b> { implicit, label, } = arg; - let value = self.unify(value, type_.clone())?; + let value = self.unify(value, type_.type_.clone())?; Ok(CallArg { value, location, diff --git a/compiler-core/src/type_/pipe.rs b/compiler-core/src/type_/pipe.rs index 7f055e28974..3e0e94e256a 100644 --- a/compiler-core/src/type_/pipe.rs +++ b/compiler-core/src/type_/pipe.rs @@ -292,7 +292,13 @@ impl<'a, 'b, 'c> PipeTyper<'a, 'b, 'c> { // Ensure that the function accepts one argument of the correct type unify( function.type_(), - fn_(vec![self.argument_type.clone()], return_type.clone()), + fn_( + vec![FunctionArgument { + name: None, + type_: self.argument_type.clone(), + }], + return_type.clone(), + ), ) .map_err(|e| { if self.check_if_pipe_function_mismatch(&e) { @@ -326,7 +332,7 @@ impl<'a, 'b, 'c> PipeTyper<'a, 'b, 'c> { match types { (Type::Fn { args: a, .. }, Type::Fn { args: b, .. }) if a.len() == b.len() => { match (a.first(), b.first()) { - (Some(a), Some(b)) => unify(a.clone(), b.clone()).is_err(), + (Some(a), Some(b)) => unify(a.type_.clone(), b.type_.clone()).is_err(), _ => false, } } diff --git a/compiler-core/src/type_/prelude.rs b/compiler-core/src/type_/prelude.rs index b67595577a8..40472c8cf4d 100644 --- a/compiler-core/src/type_/prelude.rs +++ b/compiler-core/src/type_/prelude.rs @@ -9,8 +9,9 @@ use crate::{ }; use super::{ - ModuleInterface, Type, TypeConstructor, TypeValueConstructor, TypeValueConstructorField, - TypeVar, TypeVariantConstructors, ValueConstructor, ValueConstructorVariant, + FunctionArgument, ModuleInterface, Type, TypeConstructor, TypeValueConstructor, + TypeValueConstructorField, TypeVar, TypeVariantConstructors, ValueConstructor, + ValueConstructorVariant, }; use crate::type_::Deprecation::NotDeprecated; use std::{cell::RefCell, collections::HashMap, sync::Arc}; @@ -135,7 +136,7 @@ pub fn tuple(elems: Vec>) -> Arc { Arc::new(Type::Tuple { elems }) } -pub fn fn_(args: Vec>, retrn: Arc) -> Arc { +pub fn fn_(args: Vec, retrn: Arc) -> Arc { Arc::new(Type::Fn { retrn, args }) } @@ -206,8 +207,10 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { name: PRELUDE_MODULE_NAME.into(), package: "".into(), origin: Origin::Src, + documentation: vec![], types: HashMap::new(), types_value_constructors: HashMap::new(), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), is_internal: false, @@ -228,6 +231,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: bits(), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }; @@ -291,6 +295,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: bool(), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, @@ -306,6 +311,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: float(), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, @@ -321,6 +327,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { origin: Default::default(), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, @@ -337,6 +344,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: list(list_parameter), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, @@ -368,6 +376,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: nil(), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, @@ -397,6 +406,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: result(result_value.clone(), result_error.clone()), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, @@ -409,12 +419,14 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { TypeValueConstructor { name: "Ok".into(), parameters: vec![TypeValueConstructorField { + label: None, type_: result_value, }], }, TypeValueConstructor { name: "Error".into(), parameters: vec![TypeValueConstructorField { + label: None, type_: result_error, }], }, @@ -436,7 +448,13 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { constructors_count: 2, constructor_index: 0, }, - fn_(vec![ok.clone()], result(ok, error)), + fn_( + vec![FunctionArgument { + name: None, + type_: ok.clone(), + }], + result(ok, error), + ), ), ); let ok = generic_var(ids.next()); @@ -454,7 +472,13 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { constructors_count: 2, constructor_index: 1, }, - fn_(vec![error.clone()], result(ok, error)), + fn_( + vec![FunctionArgument { + name: None, + type_: error.clone(), + }], + result(ok, error), + ), ), ); } @@ -468,6 +492,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: string(), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, @@ -483,6 +508,7 @@ pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { type_: utf_codepoint(), module: PRELUDE_MODULE_NAME.into(), publicity: Publicity::Public, + opaque: false, deprecation: NotDeprecated, documentation: None, }, diff --git a/compiler-core/src/type_/pretty.rs b/compiler-core/src/type_/pretty.rs index 13a0e3985f8..a5709ad312d 100644 --- a/compiler-core/src/type_/pretty.rs +++ b/compiler-core/src/type_/pretty.rs @@ -1,4 +1,4 @@ -use super::{Type, TypeVar}; +use super::{FunctionArgument, Type, TypeVar}; use crate::{ docvec, pretty::{nil, *}, @@ -72,7 +72,7 @@ impl Printer { Type::Fn { args, retrn } => "fn(" .to_doc() - .append(self.args_to_gleam_doc(args)) + .append(self.function_args_to_gleam_doc(args)) .append(") ->") .append( break_("", " ") @@ -139,6 +139,22 @@ impl Printer { chars.into_iter().rev().collect() } + fn function_args_to_gleam_doc(&mut self, args: &[FunctionArgument]) -> Document<'static> { + if args.is_empty() { + return nil(); + } + + let args = join( + args.iter().map(|t| self.print(&t.type_).group()), + break_(",", ", "), + ); + break_("", "") + .append(args) + .nest(INDENT) + .append(break_(",", "")) + .group() + } + fn args_to_gleam_doc(&mut self, args: &[Arc]) -> Document<'static> { if args.is_empty() { return nil(); @@ -290,20 +306,26 @@ fn pretty_print_test() { assert_string!( Type::Fn { args: vec![ - Arc::new(Type::Named { - args: vec![], - module: "whatever".into(), - package: "whatever".into(), - name: "Int".into(), - publicity: Publicity::Public, - }), - Arc::new(Type::Named { - args: vec![], - module: "whatever".into(), - package: "whatever".into(), - name: "Bool".into(), - publicity: Publicity::Public, - }), + FunctionArgument { + name: None, + type_: Arc::new(Type::Named { + args: vec![], + module: "whatever".into(), + package: "whatever".into(), + name: "Int".into(), + publicity: Publicity::Public, + }) + }, + FunctionArgument { + name: None, + type_: Arc::new(Type::Named { + args: vec![], + module: "whatever".into(), + package: "whatever".into(), + name: "Bool".into(), + publicity: Publicity::Public, + }) + }, ], retrn: Arc::new(Type::Named { args: vec![], @@ -337,9 +359,12 @@ fn pretty_print_test() { ); assert_string!( fn_( - vec![Arc::new(Type::Var { - type_: Arc::new(RefCell::new(TypeVar::Unbound { id: 78 })), - })], + vec![FunctionArgument { + name: None, + type_: Arc::new(Type::Var { + type_: Arc::new(RefCell::new(TypeVar::Unbound { id: 78 })), + }) + }], Arc::new(Type::Var { type_: Arc::new(RefCell::new(TypeVar::Unbound { id: 2 })), }), @@ -348,9 +373,12 @@ fn pretty_print_test() { ); assert_string!( fn_( - vec![Arc::new(Type::Var { - type_: Arc::new(RefCell::new(TypeVar::Generic { id: 78 })), - })], + vec![FunctionArgument { + name: None, + type_: Arc::new(Type::Var { + type_: Arc::new(RefCell::new(TypeVar::Generic { id: 78 })), + }) + }], Arc::new(Type::Var { type_: Arc::new(RefCell::new(TypeVar::Generic { id: 2 })), }), @@ -364,7 +392,16 @@ fn function_test() { assert_eq!(pretty_print(fn_(vec![], int())), "fn() -> Int"); assert_eq!( - pretty_print(fn_(vec![int(), int(), int()], int())), + pretty_print(fn_( + vec![int(), int(), int()] + .into_iter() + .map(|t| FunctionArgument { + name: None, + type_: t, + }) + .collect(), + int() + )), "fn(Int, Int, Int) -> Int" ); @@ -384,7 +421,13 @@ fn function_test() { float(), float(), float() - ], + ] + .into_iter() + .map(|t| FunctionArgument { + name: None, + type_: t, + }) + .collect(), float() )), "fn( @@ -415,7 +458,13 @@ fn function_test() { float(), float(), float() - ], + ] + .into_iter() + .map(|t| FunctionArgument { + name: None, + type_: t, + }) + .collect(), float() )), "fn( @@ -439,7 +488,13 @@ fn function_test() { float(), float(), float() - ]),], + ]),] + .into_iter() + .map(|t| FunctionArgument { + name: None, + type_: t, + }) + .collect(), tuple(vec![ tuple(vec![float(), float(), float(), float(), float(), float()]), tuple(vec![float(), float(), float(), float(), float(), float()]), diff --git a/compiler-core/src/type_/printer.rs b/compiler-core/src/type_/printer.rs index 91b50d3d501..fb921314169 100644 --- a/compiler-core/src/type_/printer.rs +++ b/compiler-core/src/type_/printer.rs @@ -3,7 +3,10 @@ use ecow::EcoString; use im::HashMap; use std::{collections::HashSet, sync::Arc}; -use crate::type_::{Type, TypeVar}; +use crate::{ + analyse::name, + type_::{FunctionArgument, Type, TypeVar}, +}; /// This class keeps track of what names are used for modules in the current /// scope, so they can be printed in errors, etc. @@ -332,7 +335,7 @@ impl<'a> Printer<'a> { Type::Fn { args, retrn } => { buffer.push_str("fn("); - self.print_arguments(args, buffer, print_mode); + self.print_function_arguments(args, buffer, print_mode); buffer.push_str(") -> "); self.print(retrn, buffer, print_mode); } @@ -352,6 +355,20 @@ impl<'a> Printer<'a> { } } + fn print_function_arguments( + &mut self, + args: &[FunctionArgument], + typ_str: &mut EcoString, + print_mode: PrintMode, + ) { + for (i, arg) in args.iter().enumerate() { + self.print(&arg.type_, typ_str, print_mode); + if i < args.len() - 1 { + typ_str.push_str(", "); + } + } + } + fn print_arguments( &mut self, args: &[Arc], @@ -529,20 +546,26 @@ fn test_fn_type() { let type_ = Type::Fn { args: vec![ - Arc::new(Type::Named { - name: "Int".into(), - args: vec![], - module: "gleam".into(), - publicity: crate::ast::Publicity::Public, - package: "".into(), - }), - Arc::new(Type::Named { - name: "String".into(), - args: vec![], - module: "gleam".into(), - publicity: crate::ast::Publicity::Public, - package: "".into(), - }), + FunctionArgument { + name: None, + type_: Arc::new(Type::Named { + name: "Int".into(), + args: vec![], + module: "gleam".into(), + publicity: crate::ast::Publicity::Public, + package: "".into(), + }), + }, + FunctionArgument { + name: None, + type_: Arc::new(Type::Named { + name: "String".into(), + args: vec![], + module: "gleam".into(), + publicity: crate::ast::Publicity::Public, + package: "".into(), + }), + }, ], retrn: Arc::new(Type::Named { name: "Bool".into(), diff --git a/compiler-core/src/type_/tests.rs b/compiler-core/src/type_/tests.rs index 6b1d6c0e57a..465a1a5bba9 100644 --- a/compiler-core/src/type_/tests.rs +++ b/compiler-core/src/type_/tests.rs @@ -702,6 +702,7 @@ fn infer_module_type_retention_test() { warnings: vec![], origin: Origin::Src, package: "thepackage".into(), + documentation: vec![], name: "ok".into(), is_internal: false, // Core type constructors like String and Int are not included @@ -731,12 +732,14 @@ fn infer_module_type_retention_test() { TypeValueConstructor { name: "Ok".into(), parameters: vec![TypeValueConstructorField { + label: None, type_: generic_var(1), }] }, TypeValueConstructor { name: "Error".into(), parameters: vec![TypeValueConstructorField { + label: None, type_: generic_var(2), }] } @@ -754,6 +757,7 @@ fn infer_module_type_retention_test() { } ) ]), + type_aliases: HashMap::new(), values: HashMap::new(), accessors: HashMap::new(), line_numbers: LineNumbers::new(""), diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__alias_unqualified_import.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__alias_unqualified_import.snap index fdcb22afa7b..c86ee2fdc42 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__alias_unqualified_import.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__alias_unqualified_import.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 8 expression: "./cases/alias_unqualified_import" --- //// /out/lib/the_package/_gleam_artefacts/one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_escape_names.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_escape_names.snap index 8ec302b788d..e78455ffbf8 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_escape_names.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_escape_names.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 63 expression: "./cases/erlang_escape_names" --- //// /out/lib/the_package/_gleam_artefacts/one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import.snap index 92a86d91ff2..0b4119957e4 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 74 expression: "./cases/erlang_import" --- //// /out/lib/the_package/_gleam_artefacts/one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import_shadowing_prelude.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import_shadowing_prelude.snap index ee8b537bf47..5fe05f608a9 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import_shadowing_prelude.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_import_shadowing_prelude.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 85 expression: "./cases/erlang_import_shadowing_prelude" --- //// /out/lib/the_package/_gleam_artefacts/one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_nested.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_nested.snap index 2e4120d7dc7..fd4bcc12afd 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_nested.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_nested.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 96 expression: "./cases/erlang_nested" --- //// /out/lib/the_package/_gleam_artefacts/one@two.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__hello_joe.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__hello_joe.snap index b083da9fc15..b41af80b864 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__hello_joe.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__hello_joe.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 118 expression: "./cases/hello_joe" --- //// /out/lib/the_package/_gleam_artefacts/hello_joe.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_shadowed_name_warning.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_shadowed_name_warning.snap index d11b9f3c9fe..5cf6a2adfc3 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_shadowed_name_warning.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_shadowed_name_warning.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 151 expression: "./cases/import_shadowed_name_warning" --- //// /out/lib/the_package/_gleam_artefacts/one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_constants.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_constants.snap index 7e75585172b..dc0b482e048 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_constants.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_constants.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 162 expression: "./cases/imported_constants" --- //// /out/lib/the_package/_gleam_artefacts/one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_external_fns.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_external_fns.snap index addd2e3dc03..ef082865fe7 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_external_fns.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_external_fns.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 173 expression: "./cases/imported_external_fns" --- //// /out/lib/the_package/_gleam_artefacts/one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_record_constructors.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_record_constructors.snap index b78b38fdd5c..b5832c1f7d6 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_record_constructors.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__imported_record_constructors.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 184 expression: "./cases/imported_record_constructors" --- //// /out/lib/the_package/_gleam_artefacts/one@one.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__not_overwriting_erlang_module.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__not_overwriting_erlang_module.snap index 3c66525567f..afd26eee2a6 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__not_overwriting_erlang_module.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__not_overwriting_erlang_module.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 237 expression: "./cases/not_overwriting_erlang_module" --- //// /out/lib/the_package/_gleam_artefacts/app@code.cache diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__variable_or_module.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__variable_or_module.snap index 4613c8e0385..9d2270e288b 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__variable_or_module.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__variable_or_module.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/src/generated_tests.rs -assertion_line: 316 expression: "./cases/variable_or_module" --- //// /out/lib/the_package/_gleam_artefacts/main.cache