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

Configure Feed

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

remove implicit cast for ErlangModuleName

author
Giacomo Cavalieri
committer
Louis Pilfold
date (Jul 14, 2026, 12:57 PM +0100) commit 2bc8e971 parent 875e69da change-id llorsnrv
+62 -36
+23 -16
compiler-core/src/erlang.rs
··· 307 307 // it corresponds to in Erlang. 308 308 // In that case all type variables are phantom type variables! 309 309 ([], _) if let Some((module, type_name, _)) = external_erlang => { 310 - let type_ = 311 - eaf.start_remote_named_type(ErlangModuleName::new(module.clone()), type_name); 310 + let type_ = eaf.start_remote_named_type(ErlangModuleName::new(&module), type_name); 312 311 for type_variable in phantom_type_variables { 313 312 eaf.type_variable(&type_variable); 314 313 } ··· 625 624 .function_arguments_names(&function.arguments, true) 626 625 .collect_vec(); 627 626 let open_function = eaf.start_function(&function_name, arity, arguments.clone()); 628 - let call = eaf.start_remote_call(module.into(), external_function_name); 627 + let call = 628 + eaf.start_remote_call(ErlangModuleName::new(&module), external_function_name); 629 629 for argument in arguments { 630 630 eaf.variable(&argument); 631 631 } ··· 937 937 .. 938 938 } => match type_::collapse_links(type_.clone()).as_ref() { 939 939 Type::Fn { arguments, .. } => eaf.function_reference( 940 - Some(module.into()), 940 + Some(ErlangModuleName::new(&module)), 941 941 escape_erlang_existing_name(name), 942 942 arguments.len(), 943 943 ), 944 944 945 945 Type::Named { .. } | Type::Var { .. } | Type::Tuple { .. } => { 946 946 let name = escape_erlang_existing_name(name); 947 - let call = eaf.start_remote_call(module.into(), name); 947 + let call = eaf.start_remote_call(ErlangModuleName::new(&module), name); 948 948 eaf.end_call(call); 949 949 } 950 950 }, ··· 1078 1078 location: SrcSpan, 1079 1079 message: Option<&'a TypedExpr>, 1080 1080 ) -> RuntimeError { 1081 - let call = eaf.start_remote_call("erlang".into(), "error"); 1081 + let call = eaf.start_remote_call(ErlangModuleName::new("erlang"), "error"); 1082 1082 let map = eaf.start_map(); 1083 1083 1084 1084 eaf.map_field(); ··· 1863 1863 tuple: &'a TypedExpr, 1864 1864 index: u64, 1865 1865 ) { 1866 - let call = eaf.start_remote_call("erlang".into(), "element"); 1866 + let call = eaf.start_remote_call(ErlangModuleName::new("erlang"), "element"); 1867 1867 eaf.int((index + 1).into()); 1868 1868 self.maybe_block_expr(eaf, tuple); 1869 1869 eaf.end_call(call); ··· 1921 1921 if *module == self.module_generator.module.name { 1922 1922 eaf.function_reference(None, name, *arity) 1923 1923 } else { 1924 - eaf.function_reference(Some(module.into()), name, *arity) 1924 + eaf.function_reference(Some(ErlangModuleName::new(&module)), name, *arity) 1925 1925 } 1926 1926 } 1927 1927 ··· 1937 1937 name, 1938 1938 .. 1939 1939 } => eaf.function_reference( 1940 - Some(module.into()), 1940 + Some(ErlangModuleName::new(&module)), 1941 1941 escape_erlang_existing_name(name), 1942 1942 *arity, 1943 1943 ), ··· 1959 1959 // module name if it comes from a different module). 1960 1960 FunctionCall::Call { module, name } => { 1961 1961 let call = if module != self.module_generator.module.name { 1962 - eaf.start_remote_call(module.into(), escape_erlang_existing_name(name)) 1962 + eaf.start_remote_call( 1963 + ErlangModuleName::new(&module), 1964 + escape_erlang_existing_name(name), 1965 + ) 1963 1966 } else { 1964 1967 let call = eaf.start_call(); 1965 1968 eaf.atom(escape_erlang_existing_name(name)); ··· 2011 2014 // module name if it comes from a different module). 2012 2015 FunctionCall::Call { module, name } => { 2013 2016 let call = if module != self.module_generator.module.name { 2014 - eaf.start_remote_call(module.into(), escape_erlang_existing_name(name)) 2017 + eaf.start_remote_call( 2018 + ErlangModuleName::new(&module), 2019 + escape_erlang_existing_name(name), 2020 + ) 2015 2021 } else { 2016 2022 let call = eaf.start_call(); 2017 2023 eaf.atom(escape_erlang_existing_name(name)); ··· 2740 2746 // ```erl 2741 2747 // unicode:characters_to_binary(<segment_value>, utf8, {utf16, big}) 2742 2748 // ``` 2743 - let call = eaf.start_remote_call("unicode".into(), "characters_to_binary"); 2749 + let call = 2750 + eaf.start_remote_call(ErlangModuleName::new("unicode"), "characters_to_binary"); 2744 2751 { 2745 2752 self.maybe_block_expr(eaf, &segment.value); 2746 2753 eaf.atom("utf8"); ··· 2791 2798 eaf.int(int_value.clone()); 2792 2799 } 2793 2800 } else { 2794 - let call = eaf.start_remote_call("erlang".into(), "max"); 2801 + let call = eaf.start_remote_call(ErlangModuleName::new("erlang"), "max"); 2795 2802 eaf.int(BigInt::ZERO); 2796 2803 self.maybe_block_expr(eaf, size); 2797 2804 eaf.end_call(call); ··· 2888 2895 tuple: &'a TypedClauseGuard, 2889 2896 index: u64, 2890 2897 ) { 2891 - let call = eaf.start_remote_call("erlang".into(), "element"); 2898 + let call = eaf.start_remote_call(ErlangModuleName::new("erlang"), "element"); 2892 2899 eaf.int((index + 1).into()); 2893 2900 self.clause_guard(eaf, tuple, &HashMap::new()); 2894 2901 eaf.end_call(call); ··· 3278 3285 root: &'a Utf8Path, 3279 3286 ) -> String { 3280 3287 let mut generator = Generator::new(module, line_numbers, root); 3281 - let mut eaf = PrettyEaf::new(Some(ErlangModuleName::from(&module.name))); 3288 + let mut eaf = PrettyEaf::new(Some(ErlangModuleName::new(&module.name))); 3282 3289 generator.module_document(&mut eaf); 3283 3290 3284 3291 let mut output = eaf.into_output(); ··· 4007 4014 let type_ = if self.current_module == module { 4008 4015 eaf.start_named_type(&name) 4009 4016 } else { 4010 - eaf.start_remote_named_type(ErlangModuleName::new(module), &name) 4017 + eaf.start_remote_named_type(ErlangModuleName::new(&module), &name) 4011 4018 }; 4012 4019 4013 4020 for argument in arguments {
+2 -20
erlang-abstract-format/src/lib.rs
··· 32 32 impl ErlangModuleName { 33 33 #[inline] 34 34 /// Creates a new erlang module name from a Gleam module name. 35 - pub fn new(gleam_module_name: EcoString) -> Self { 36 - Self(gleam_module_name.replace("/", "@")) 37 - } 38 - } 39 - 40 - impl From<&EcoString> for ErlangModuleName { 41 - fn from(value: &EcoString) -> Self { 42 - Self::new(value.clone()) 43 - } 44 - } 45 - 46 - impl From<EcoString> for ErlangModuleName { 47 - fn from(value: EcoString) -> Self { 48 - Self::new(value) 49 - } 50 - } 51 - 52 - impl From<&str> for ErlangModuleName { 53 - fn from(value: &str) -> Self { 54 - Self::new(value.into()) 35 + pub fn new(gleam_module_name: &str) -> Self { 36 + Self(gleam_module_name.replace("/", "@").into()) 55 37 } 56 38 } 57 39
+37
erlang-term-format/src/lib.rs
··· 235 235 } 236 236 237 237 #[cfg(test)] 238 + /// We want to test all of these functions against the actual values produced by 239 + /// Erlang when turning some data into a binary. 240 + /// 241 + /// All the bytes you see in the assertions here were produced using the 242 + /// following bit of Erlang: 243 + /// 244 + /// ```erl 245 + /// Binary = term_to_binary(SomeErlangData), 246 + /// io:format("~w~n", [Binary]). 247 + /// ``` 248 + /// 249 + /// This will turn any data structure into its binary representation and print 250 + /// its bytes we can then copy paste in these tests. 251 + /// 252 + /// For example: if I were to test that a list of two atoms is correctly turned 253 + /// into its binary representation I would write the following: 254 + /// 255 + /// ```erl 256 + /// Binary = term_to_binary([nil, ok]), 257 + /// io:format("~w~n", [Binary]). 258 + /// ``` 259 + /// 260 + /// And write a test like this: 261 + /// 262 + /// ```ignore 263 + /// let mut etf = Builder::new(); 264 + /// let list = etf.start_list(); 265 + /// etf.atom("nil"); 266 + /// etf.atom("ok"); 267 + /// etf.end_list(list, 2); 268 + /// 269 + /// assert_eq!( 270 + /// etf.into_vec(), 271 + /// [... the bytes I got from the Erlang code ...] 272 + /// ) 273 + /// ``` 274 + /// 238 275 mod tests { 239 276 use std::{ops::Neg, str::FromStr}; 240 277