From 87a279dc2cd0bfc4fc183bf7e2a268af3d1bd142 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Sat, 27 Apr 2024 22:27:50 -0300 Subject: [PATCH] Extract marking s builtin into header type method --- crates/compiler/load_internal/src/file.rs | 17 ++--------------- crates/compiler/parse/src/header.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index e69e78ecfd..5f96b49bd9 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -2350,6 +2350,7 @@ fn update<'a>( } Parsed(parsed) => { let module_id = parsed.module_id; + // store an ID to name mapping, so we know the file to read when fetching dependencies' headers for (name, id) in parsed.deps_by_name.iter() { state.module_cache.module_names.insert(*id, name.clone()); @@ -4248,20 +4249,6 @@ fn build_header<'a>( .map(|Loc { value: pkg, .. }| (pkg.shorthand, pkg.package_name.value)) .collect::>(); - // make sure when we run the bulitin modules in /compiler/builtins/roc that we - // mark these modules as Builtin. Otherwise the builtin functions are not instantiated - // and we just have a bunch of definitions with runtime errors in their bodies - let header_type = { - match header_type { - HeaderType::Interface { name, exposes } if home.is_builtin() => HeaderType::Builtin { - name, - exposes, - generates_with: &[], - }, - _ => header_type, - } - }; - Ok(( home, name, @@ -4271,7 +4258,7 @@ fn build_header<'a>( is_root_module, packages: package_entries, parse_state, - header_type, + header_type: header_type.to_maybe_builtin(home), header_comments, module_timing, opt_shorthand, diff --git a/crates/compiler/parse/src/header.rs b/crates/compiler/parse/src/header.rs index 9e13c50f55..8bfaf4cf13 100644 --- a/crates/compiler/parse/src/header.rs +++ b/crates/compiler/parse/src/header.rs @@ -103,6 +103,19 @@ impl<'a> HeaderType<'a> { } } } + + pub fn to_maybe_builtin(self, module_id: ModuleId) -> Self { + match self { + HeaderType::Interface { name, exposes } if module_id.is_builtin() => { + HeaderType::Builtin { + name, + exposes, + generates_with: &[], + } + } + _ => self, + } + } } #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]