Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

change implementation of the type spec method to be opened and closed

author
Giacomo Cavalieri
committer
Louis Pilfold
date (Jul 22, 2026, 8:34 AM +0100) commit cefe18f8 parent 055bd0c8 change-id swtqyvmz
+23 -6
+3 -1
compiler-core/src/erlang.rs
··· 290 290 let name = erl_safe_type_name(to_snake_case(name)); 291 291 292 292 // We start the type spec. 293 - builder.type_spec( 293 + let type_spec = builder.start_type_spec( 294 294 *opaque, 295 295 &name, 296 296 typed_parameters ··· 349 349 builder.end_union_type(union); 350 350 } 351 351 } 352 + 353 + builder.end_type_spec(type_spec); 352 354 } 353 355 354 356 /// Given a constructor this generates its type. For example:
+20 -5
erlang-generation/src/lib.rs
··· 152 152 /// that has yet to be closed. 153 153 type FunctionTypeArguments; 154 154 155 + /// Represents an open type spec attribute that has yet to be closed after 156 + /// generating the type it stands for. 157 + type TypeSpec; 158 + 155 159 /// Creates a new `ErlangBuilder` data structure to generate Erlang code. 156 160 /// If a module name is provided this will also automatically take care of 157 161 /// generating the appropriate `-module` annotation at the very beginning. ··· 339 343 /// This starts an Erlang type spec. 340 344 /// After this call you're expected to generate a single type; that's going 341 345 /// to be the definition of the type. 346 + /// After that is done you should call `end_type_spec`. 342 347 /// 343 348 /// For example: 344 349 /// ··· 352 357 /// builder.type_variable("A") 353 358 /// builder.close_named_type(); 354 359 /// 355 - /// builder.end_uniont_type(union); 360 + /// builder.end_union_type(union); 361 + /// builder.end_type_spec(spec); 356 362 /// ``` 357 363 /// 358 364 /// Corresponds to: ··· 361 367 /// -spec wibble(A) :: nil | list(A). 362 368 /// ``` 363 369 /// 364 - fn type_spec<Name: AsRef<str>>( 370 + fn start_type_spec<Name: AsRef<str>>( 365 371 &mut self, 366 372 opaque: bool, 367 373 name: &str, 368 374 type_parameters: impl IntoIterator<Item = Name>, 369 - ); 375 + ) -> Self::TypeSpec; 376 + 377 + fn end_type_spec(&mut self, type_spec: Self::TypeSpec); 370 378 371 379 /// This starts a function type. 372 380 /// Any code generated after this is gonna be an argument type of the open ··· 1686 1694 type TuplePattern = (); 1687 1695 type TupleType = (); 1688 1696 type UnionType = (); 1697 + type TypeSpec = (); 1689 1698 1690 1699 fn new(module: Option<ErlangModuleName>) -> Self { 1691 1700 Self { ··· 1836 1845 self.close_currently_open_item(); 1837 1846 } 1838 1847 1839 - fn type_spec<Name: AsRef<str>>( 1848 + fn start_type_spec<Name: AsRef<str>>( 1840 1849 &mut self, 1841 1850 opaque: bool, 1842 1851 name: &str, 1843 1852 type_variables: impl IntoIterator<Item = Name>, 1844 - ) { 1853 + ) -> Self::TypeSpec { 1845 1854 self.new_top_level_form(); 1846 1855 self.code.push('\n'); 1847 1856 self.code ··· 1862 1871 self.position.push(ErlangSourceBuilderPosition::TypeSpec { 1863 1872 expected: TypeSpecExpectedItem::TypeDefinition, 1864 1873 }); 1874 + } 1875 + 1876 + fn end_type_spec(&mut self, _type_spec: Self::TypeSpec) { 1877 + // For the pretty printer type specs do not need any extra book keeping. 1878 + // Ending one does nothing because the spec is already over and doesn't 1879 + // change the builder's position. 1865 1880 } 1866 1881 1867 1882 fn start_function_type(&mut self) -> Self::FunctionTypeArguments {