mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Remove spaces from header 'Info' structs
This commit is contained in:
parent
0786e554c6
commit
63056eeeac
1 changed files with 30 additions and 27 deletions
|
@ -2553,8 +2553,8 @@ fn parse_header<'a>(
|
||||||
opt_shorthand,
|
opt_shorthand,
|
||||||
header_src,
|
header_src,
|
||||||
packages: &[],
|
packages: &[],
|
||||||
exposes: header.exposes.items,
|
exposes: unspace(arena, header.exposes.items),
|
||||||
imports: header.imports.items,
|
imports: unspace(arena, header.imports.items),
|
||||||
to_platform: None,
|
to_platform: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2575,7 +2575,7 @@ fn parse_header<'a>(
|
||||||
std::str::from_utf8_unchecked(&src_bytes[..chomped])
|
std::str::from_utf8_unchecked(&src_bytes[..chomped])
|
||||||
};
|
};
|
||||||
|
|
||||||
let packages = header.packages.items;
|
let packages = unspace(arena, header.packages.items);
|
||||||
|
|
||||||
let info = HeaderInfo {
|
let info = HeaderInfo {
|
||||||
loc_name: Located {
|
loc_name: Located {
|
||||||
|
@ -2587,8 +2587,8 @@ fn parse_header<'a>(
|
||||||
opt_shorthand,
|
opt_shorthand,
|
||||||
header_src,
|
header_src,
|
||||||
packages,
|
packages,
|
||||||
exposes: header.provides.items,
|
exposes: unspace(arena, header.provides.items),
|
||||||
imports: header.imports.items,
|
imports: unspace(arena, header.imports.items),
|
||||||
to_platform: Some(header.to.value),
|
to_platform: Some(header.to.value),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2605,9 +2605,8 @@ fn parse_header<'a>(
|
||||||
let opt_base_package = packages.iter().find_map(|loc_package_entry| {
|
let opt_base_package = packages.iter().find_map(|loc_package_entry| {
|
||||||
let Located { value, .. } = loc_package_entry;
|
let Located { value, .. } = loc_package_entry;
|
||||||
|
|
||||||
let item = value.extract_spaces().item;
|
if value.shorthand == existing_package {
|
||||||
if item.shorthand == existing_package {
|
Some(value)
|
||||||
Some(item)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -2759,9 +2758,9 @@ struct HeaderInfo<'a> {
|
||||||
is_root_module: bool,
|
is_root_module: bool,
|
||||||
opt_shorthand: Option<&'a str>,
|
opt_shorthand: Option<&'a str>,
|
||||||
header_src: &'a str,
|
header_src: &'a str,
|
||||||
packages: &'a [Located<Spaced<'a, PackageEntry<'a>>>],
|
packages: &'a [Located<PackageEntry<'a>>],
|
||||||
exposes: &'a [Located<Spaced<'a, ExposedName<'a>>>],
|
exposes: &'a [Located<ExposedName<'a>>],
|
||||||
imports: &'a [Located<Spaced<'a, ImportsEntry<'a>>>],
|
imports: &'a [Located<ImportsEntry<'a>>],
|
||||||
to_platform: Option<To<'a>>,
|
to_platform: Option<To<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2894,8 +2893,7 @@ fn send_header<'a>(
|
||||||
// For example, if module A has [ B.{ foo } ], then
|
// For example, if module A has [ B.{ foo } ], then
|
||||||
// when we get here for B, `foo` will already have
|
// when we get here for B, `foo` will already have
|
||||||
// an IdentId. We must reuse that!
|
// an IdentId. We must reuse that!
|
||||||
let ident_id =
|
let ident_id = ident_ids.get_or_insert(&loc_exposed.value.as_str().into());
|
||||||
ident_ids.get_or_insert(&loc_exposed.value.extract_spaces().item.as_str().into());
|
|
||||||
let symbol = Symbol::new(home, ident_id);
|
let symbol = Symbol::new(home, ident_id);
|
||||||
|
|
||||||
exposed.push(symbol);
|
exposed.push(symbol);
|
||||||
|
@ -2911,7 +2909,7 @@ fn send_header<'a>(
|
||||||
let package_entries = packages
|
let package_entries = packages
|
||||||
.iter()
|
.iter()
|
||||||
.map(|pkg| {
|
.map(|pkg| {
|
||||||
let pkg = pkg.value.extract_spaces().item;
|
let pkg = pkg.value;
|
||||||
(pkg.shorthand, pkg.package_or_path.value)
|
(pkg.shorthand, pkg.package_or_path.value)
|
||||||
})
|
})
|
||||||
.collect::<MutMap<_, _>>();
|
.collect::<MutMap<_, _>>();
|
||||||
|
@ -2973,9 +2971,9 @@ struct PlatformHeaderInfo<'a> {
|
||||||
header_src: &'a str,
|
header_src: &'a str,
|
||||||
app_module_id: ModuleId,
|
app_module_id: ModuleId,
|
||||||
packages: &'a [Located<PackageEntry<'a>>],
|
packages: &'a [Located<PackageEntry<'a>>],
|
||||||
provides: &'a [Located<Spaced<'a, ExposedName<'a>>>],
|
provides: &'a [Located<ExposedName<'a>>],
|
||||||
requires: &'a [Located<TypedIdent<'a>>],
|
requires: &'a [Located<TypedIdent<'a>>],
|
||||||
imports: &'a [Located<Spaced<'a, ImportsEntry<'a>>>],
|
imports: &'a [Located<ImportsEntry<'a>>],
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactor so more logic is shared with `send_header`
|
// TODO refactor so more logic is shared with `send_header`
|
||||||
|
@ -3118,8 +3116,7 @@ fn send_header_two<'a>(
|
||||||
// For example, if module A has [ B.{ foo } ], then
|
// For example, if module A has [ B.{ foo } ], then
|
||||||
// when we get here for B, `foo` will already have
|
// when we get here for B, `foo` will already have
|
||||||
// an IdentId. We must reuse that!
|
// an IdentId. We must reuse that!
|
||||||
let ident_id =
|
let ident_id = ident_ids.get_or_insert(&loc_exposed.value.as_str().into());
|
||||||
ident_ids.get_or_insert(&loc_exposed.value.extract_spaces().item.as_str().into());
|
|
||||||
let symbol = Symbol::new(home, ident_id);
|
let symbol = Symbol::new(home, ident_id);
|
||||||
|
|
||||||
exposed.push(symbol);
|
exposed.push(symbol);
|
||||||
|
@ -3146,7 +3143,7 @@ fn send_header_two<'a>(
|
||||||
let module_name = ModuleNameEnum::PkgConfig;
|
let module_name = ModuleNameEnum::PkgConfig;
|
||||||
|
|
||||||
let main_for_host = {
|
let main_for_host = {
|
||||||
let ident_str: Ident = provides[0].value.extract_spaces().item.as_str().into();
|
let ident_str: Ident = provides[0].value.as_str().into();
|
||||||
let ident_id = ident_ids.get_or_insert(&ident_str);
|
let ident_id = ident_ids.get_or_insert(&ident_str);
|
||||||
|
|
||||||
Symbol::new(home, ident_id)
|
Symbol::new(home, ident_id)
|
||||||
|
@ -3314,6 +3311,16 @@ fn run_solve<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unspace<'a, T: Copy>(arena: &'a Bump, items: &[Located<Spaced<'a, T>>]) -> &'a [Located<T>] {
|
||||||
|
bumpalo::collections::Vec::from_iter_in(
|
||||||
|
items
|
||||||
|
.iter()
|
||||||
|
.map(|item| Located::at(item.region, item.value.extract_spaces().item)),
|
||||||
|
arena,
|
||||||
|
)
|
||||||
|
.into_bump_slice()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn fabricate_pkg_config_module<'a>(
|
fn fabricate_pkg_config_module<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
|
@ -3327,8 +3334,6 @@ fn fabricate_pkg_config_module<'a>(
|
||||||
header_src: &'a str,
|
header_src: &'a str,
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
) -> (ModuleId, Msg<'a>) {
|
) -> (ModuleId, Msg<'a>) {
|
||||||
let provides: &'a [Located<Spaced<'a, ExposedName<'a>>>] = header.provides.items;
|
|
||||||
|
|
||||||
let info = PlatformHeaderInfo {
|
let info = PlatformHeaderInfo {
|
||||||
filename,
|
filename,
|
||||||
is_root_module: false,
|
is_root_module: false,
|
||||||
|
@ -3336,12 +3341,12 @@ fn fabricate_pkg_config_module<'a>(
|
||||||
header_src,
|
header_src,
|
||||||
app_module_id,
|
app_module_id,
|
||||||
packages: &[],
|
packages: &[],
|
||||||
provides,
|
provides: unspace(arena, header.provides.items),
|
||||||
requires: &*arena.alloc([Located::at(
|
requires: &*arena.alloc([Located::at(
|
||||||
header.requires.signature.region,
|
header.requires.signature.region,
|
||||||
header.requires.signature.extract_spaces().item,
|
header.requires.signature.extract_spaces().item,
|
||||||
)]),
|
)]),
|
||||||
imports: header.imports.items,
|
imports: unspace(arena, header.imports.items),
|
||||||
};
|
};
|
||||||
|
|
||||||
send_header_two(
|
send_header_two(
|
||||||
|
@ -3773,12 +3778,10 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, Loadi
|
||||||
Ok(Msg::Parsed(parsed))
|
Ok(Msg::Parsed(parsed))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exposed_from_import<'a>(
|
fn exposed_from_import<'a>(entry: &ImportsEntry<'a>) -> (QualifiedModuleName<'a>, Vec<Ident>) {
|
||||||
entry: &Spaced<'a, ImportsEntry<'a>>,
|
|
||||||
) -> (QualifiedModuleName<'a>, Vec<Ident>) {
|
|
||||||
use roc_parse::header::ImportsEntry::*;
|
use roc_parse::header::ImportsEntry::*;
|
||||||
|
|
||||||
match entry.extract_spaces().item {
|
match entry {
|
||||||
Module(module_name, exposes) => {
|
Module(module_name, exposes) => {
|
||||||
let mut exposed = Vec::with_capacity(exposes.len());
|
let mut exposed = Vec::with_capacity(exposes.len());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue