mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
better formatting
This commit is contained in:
parent
daf6de950e
commit
7f14f27ee4
4 changed files with 115 additions and 14 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2928,7 +2928,6 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
"indoc",
|
|
||||||
"inlinable_string",
|
"inlinable_string",
|
||||||
"maplit",
|
"maplit",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
|
@ -2950,6 +2949,7 @@ dependencies = [
|
||||||
"roc_types",
|
"roc_types",
|
||||||
"roc_unify",
|
"roc_unify",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"ven_pretty",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -135,8 +135,8 @@ pub fn build(target: &Triple, matches: &ArgMatches, run_after_build: bool) -> io
|
||||||
Err(LoadingProblem::ParsingFailedReport(report)) => {
|
Err(LoadingProblem::ParsingFailedReport(report)) => {
|
||||||
print!("{}", report);
|
print!("{}", report);
|
||||||
}
|
}
|
||||||
Err(LoadingProblem::NoPlatform) => {
|
Err(LoadingProblem::NoPlatform(report)) => {
|
||||||
print!("The file you ran did not provide a platform\nMaybe you are trying to run an Interface module?");
|
print!("{}", report);
|
||||||
}
|
}
|
||||||
Err(other) => {
|
Err(other) => {
|
||||||
panic!("build_file failed with error:\n{:?}", other);
|
panic!("build_file failed with error:\n{:?}", other);
|
||||||
|
|
|
@ -19,6 +19,7 @@ roc_parse = { path = "../parse" }
|
||||||
roc_solve = { path = "../solve" }
|
roc_solve = { path = "../solve" }
|
||||||
roc_mono = { path = "../mono" }
|
roc_mono = { path = "../mono" }
|
||||||
roc_reporting = { path = "../reporting" }
|
roc_reporting = { path = "../reporting" }
|
||||||
|
ven_pretty = { path = "../../vendor/pretty" }
|
||||||
bumpalo = { version = "3.2", features = ["collections"] }
|
bumpalo = { version = "3.2", features = ["collections"] }
|
||||||
inlinable_string = "0.1"
|
inlinable_string = "0.1"
|
||||||
parking_lot = { version = "0.11", features = ["deadlock_detection"] }
|
parking_lot = { version = "0.11", features = ["deadlock_detection"] }
|
||||||
|
@ -29,6 +30,5 @@ num_cpus = "1"
|
||||||
tempfile = "3.1.0"
|
tempfile = "3.1.0"
|
||||||
pretty_assertions = "0.5.1"
|
pretty_assertions = "0.5.1"
|
||||||
maplit = "1.0.1"
|
maplit = "1.0.1"
|
||||||
indoc = "0.3.3"
|
|
||||||
quickcheck = "0.8"
|
quickcheck = "0.8"
|
||||||
quickcheck_macros = "0.8"
|
quickcheck_macros = "0.8"
|
||||||
|
|
|
@ -616,6 +616,7 @@ struct ModuleHeader<'a> {
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
module_name: ModuleNameEnum<'a>,
|
module_name: ModuleNameEnum<'a>,
|
||||||
module_path: PathBuf,
|
module_path: PathBuf,
|
||||||
|
is_root_module: bool,
|
||||||
exposed_ident_ids: IdentIds,
|
exposed_ident_ids: IdentIds,
|
||||||
deps_by_name: MutMap<PQModuleName<'a>, ModuleId>,
|
deps_by_name: MutMap<PQModuleName<'a>, ModuleId>,
|
||||||
packages: MutMap<&'a str, PackageOrPath<'a>>,
|
packages: MutMap<&'a str, PackageOrPath<'a>>,
|
||||||
|
@ -767,6 +768,14 @@ enum Msg<'a> {
|
||||||
FailedToParse(ParseProblem<'a, SyntaxError<'a>>),
|
FailedToParse(ParseProblem<'a, SyntaxError<'a>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum PlatformPath<'a> {
|
||||||
|
NotSpecified,
|
||||||
|
Valid(To<'a>),
|
||||||
|
RootIsInterface,
|
||||||
|
RootIsPkgConfig,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct State<'a> {
|
struct State<'a> {
|
||||||
pub root_id: ModuleId,
|
pub root_id: ModuleId,
|
||||||
|
@ -775,7 +784,7 @@ struct State<'a> {
|
||||||
pub stdlib: &'a StdLib,
|
pub stdlib: &'a StdLib,
|
||||||
pub exposed_types: SubsByModule,
|
pub exposed_types: SubsByModule,
|
||||||
pub output_path: Option<&'a str>,
|
pub output_path: Option<&'a str>,
|
||||||
pub platform_path: Option<To<'a>>,
|
pub platform_path: PlatformPath<'a>,
|
||||||
|
|
||||||
pub headers_parsed: MutSet<ModuleId>,
|
pub headers_parsed: MutSet<ModuleId>,
|
||||||
|
|
||||||
|
@ -981,7 +990,7 @@ pub enum LoadingProblem<'a> {
|
||||||
ParsingFailed(ParseProblem<'a, SyntaxError<'a>>),
|
ParsingFailed(ParseProblem<'a, SyntaxError<'a>>),
|
||||||
UnexpectedHeader(String),
|
UnexpectedHeader(String),
|
||||||
/// there is no platform (likely running an Interface module)
|
/// there is no platform (likely running an Interface module)
|
||||||
NoPlatform,
|
NoPlatform(String),
|
||||||
|
|
||||||
MsgChannelDied,
|
MsgChannelDied,
|
||||||
ErrJoiningWorkerThreads,
|
ErrJoiningWorkerThreads,
|
||||||
|
@ -1135,6 +1144,7 @@ impl<'a> LoadStart<'a> {
|
||||||
load_filename(
|
load_filename(
|
||||||
arena,
|
arena,
|
||||||
filename,
|
filename,
|
||||||
|
true,
|
||||||
None,
|
None,
|
||||||
Arc::clone(&arc_modules),
|
Arc::clone(&arc_modules),
|
||||||
Arc::clone(&ident_ids_by_module),
|
Arc::clone(&ident_ids_by_module),
|
||||||
|
@ -1403,7 +1413,7 @@ where
|
||||||
goal_phase,
|
goal_phase,
|
||||||
stdlib,
|
stdlib,
|
||||||
output_path: None,
|
output_path: None,
|
||||||
platform_path: None,
|
platform_path: PlatformPath::NotSpecified,
|
||||||
module_cache: ModuleCache::default(),
|
module_cache: ModuleCache::default(),
|
||||||
dependencies: Dependencies::default(),
|
dependencies: Dependencies::default(),
|
||||||
procedures: MutMap::default(),
|
procedures: MutMap::default(),
|
||||||
|
@ -1612,16 +1622,27 @@ fn update<'a>(
|
||||||
|
|
||||||
match header_extra {
|
match header_extra {
|
||||||
App { to_platform } => {
|
App { to_platform } => {
|
||||||
debug_assert_eq!(state.platform_path, None);
|
debug_assert!(matches!(state.platform_path, PlatformPath::NotSpecified));
|
||||||
|
debug_assert!(header.is_root_module);
|
||||||
|
|
||||||
state.platform_path = Some(to_platform.clone());
|
state.platform_path = PlatformPath::Valid(to_platform.clone());
|
||||||
}
|
}
|
||||||
PkgConfig { .. } => {
|
PkgConfig { .. } => {
|
||||||
debug_assert_eq!(state.platform_id, None);
|
debug_assert_eq!(state.platform_id, None);
|
||||||
|
|
||||||
state.platform_id = Some(header.module_id);
|
state.platform_id = Some(header.module_id);
|
||||||
|
|
||||||
|
if header.is_root_module {
|
||||||
|
debug_assert!(matches!(state.platform_path, PlatformPath::NotSpecified));
|
||||||
|
state.platform_path = PlatformPath::RootIsPkgConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Interface => {
|
||||||
|
if header.is_root_module {
|
||||||
|
debug_assert!(matches!(state.platform_path, PlatformPath::NotSpecified));
|
||||||
|
state.platform_path = PlatformPath::RootIsInterface;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Interface => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// store an ID to name mapping, so we know the file to read when fetching dependencies' headers
|
// store an ID to name mapping, so we know the file to read when fetching dependencies' headers
|
||||||
|
@ -2073,21 +2094,89 @@ fn finish_specialization(
|
||||||
..
|
..
|
||||||
} = module_cache;
|
} = module_cache;
|
||||||
|
|
||||||
let sources = sources
|
let sources: MutMap<ModuleId, (PathBuf, Box<str>)> = sources
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(id, (path, src))| (id, (path, src.into())))
|
.map(|(id, (path, src))| (id, (path, src.into())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let path_to_platform = {
|
let path_to_platform = {
|
||||||
|
use PlatformPath::*;
|
||||||
let package_or_path = match platform_path {
|
let package_or_path = match platform_path {
|
||||||
Some(To::ExistingPackage(shorthand)) => {
|
Valid(To::ExistingPackage(shorthand)) => {
|
||||||
match (*state.arc_shorthands).lock().get(shorthand) {
|
match (*state.arc_shorthands).lock().get(shorthand) {
|
||||||
Some(p_or_p) => p_or_p.clone(),
|
Some(p_or_p) => p_or_p.clone(),
|
||||||
None => unreachable!(),
|
None => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(To::NewPackage(p_or_p)) => p_or_p,
|
Valid(To::NewPackage(p_or_p)) => p_or_p,
|
||||||
None => return Err(LoadingProblem::NoPlatform),
|
other => {
|
||||||
|
use roc_reporting::report::{Report, RocDocAllocator, DEFAULT_PALETTE};
|
||||||
|
use ven_pretty::DocAllocator;
|
||||||
|
|
||||||
|
let module_id = state.root_id;
|
||||||
|
|
||||||
|
let palette = DEFAULT_PALETTE;
|
||||||
|
|
||||||
|
// Report parsing and canonicalization problems
|
||||||
|
let alloc = RocDocAllocator::new(&[], module_id, &interns);
|
||||||
|
|
||||||
|
let report = {
|
||||||
|
match other {
|
||||||
|
Valid(_) => unreachable!(),
|
||||||
|
NotSpecified => {
|
||||||
|
let doc = alloc.stack(vec![
|
||||||
|
alloc.reflow("I could not find a platform based on your input file."),
|
||||||
|
alloc.reflow(r"Does the module header contain an entry that looks like this:"),
|
||||||
|
alloc
|
||||||
|
.parser_suggestion(" packages { base: \"platform\" }")
|
||||||
|
.indent(4),
|
||||||
|
alloc.reflow("See also TODO."),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Report {
|
||||||
|
filename: "UNKNOWN.roc".into(),
|
||||||
|
doc,
|
||||||
|
title: "NO PLATFORM".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RootIsInterface => {
|
||||||
|
let doc = alloc.stack(vec![
|
||||||
|
alloc.reflow(r"The input file is a interface file, but only app modules can be ran."),
|
||||||
|
alloc.concat(vec![
|
||||||
|
alloc.reflow(r"I will still parse and typecheck the input file and its dependencies,"),
|
||||||
|
alloc.reflow(r"but won't output any executable."),
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
|
||||||
|
Report {
|
||||||
|
filename: "UNKNOWN.roc".into(),
|
||||||
|
doc,
|
||||||
|
title: "NO PLATFORM".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RootIsPkgConfig => {
|
||||||
|
let doc = alloc.stack(vec![
|
||||||
|
alloc.reflow(r"The input file is a package config file, but only app modules can be ran."),
|
||||||
|
alloc.concat(vec![
|
||||||
|
alloc.reflow(r"I will still parse and typecheck the input file and its dependencies,"),
|
||||||
|
alloc.reflow(r"but won't output any executable."),
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
|
||||||
|
Report {
|
||||||
|
filename: "UNKNOWN.roc".into(),
|
||||||
|
doc,
|
||||||
|
title: "NO PLATFORM".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut buf = String::new();
|
||||||
|
|
||||||
|
report.render_color_terminal(&mut buf, &alloc, &palette);
|
||||||
|
|
||||||
|
return Err(LoadingProblem::NoPlatform(buf));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match package_or_path {
|
match package_or_path {
|
||||||
|
@ -2295,6 +2384,7 @@ fn load_module<'a>(
|
||||||
load_filename(
|
load_filename(
|
||||||
arena,
|
arena,
|
||||||
filename,
|
filename,
|
||||||
|
false,
|
||||||
opt_shorthand,
|
opt_shorthand,
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
|
@ -2334,6 +2424,7 @@ fn parse_header<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
read_file_duration: Duration,
|
read_file_duration: Duration,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
|
is_root_module: bool,
|
||||||
opt_shorthand: Option<&'a str>,
|
opt_shorthand: Option<&'a str>,
|
||||||
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
||||||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
|
@ -2359,6 +2450,7 @@ fn parse_header<'a>(
|
||||||
value: ModuleNameEnum::Interface(header.name.value),
|
value: ModuleNameEnum::Interface(header.name.value),
|
||||||
},
|
},
|
||||||
filename,
|
filename,
|
||||||
|
is_root_module,
|
||||||
opt_shorthand,
|
opt_shorthand,
|
||||||
&[],
|
&[],
|
||||||
header.exposes.into_bump_slice(),
|
header.exposes.into_bump_slice(),
|
||||||
|
@ -2381,6 +2473,7 @@ fn parse_header<'a>(
|
||||||
value: ModuleNameEnum::App(header.name.value),
|
value: ModuleNameEnum::App(header.name.value),
|
||||||
},
|
},
|
||||||
filename,
|
filename,
|
||||||
|
is_root_module,
|
||||||
opt_shorthand,
|
opt_shorthand,
|
||||||
packages,
|
packages,
|
||||||
header.provides.into_bump_slice(),
|
header.provides.into_bump_slice(),
|
||||||
|
@ -2486,6 +2579,7 @@ fn parse_header<'a>(
|
||||||
fn load_filename<'a>(
|
fn load_filename<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
|
is_root_module: bool,
|
||||||
opt_shorthand: Option<&'a str>,
|
opt_shorthand: Option<&'a str>,
|
||||||
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
||||||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
|
@ -2501,6 +2595,7 @@ fn load_filename<'a>(
|
||||||
arena,
|
arena,
|
||||||
file_io_duration,
|
file_io_duration,
|
||||||
filename,
|
filename,
|
||||||
|
is_root_module,
|
||||||
opt_shorthand,
|
opt_shorthand,
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
|
@ -2535,6 +2630,7 @@ fn load_from_str<'a>(
|
||||||
arena,
|
arena,
|
||||||
file_io_duration,
|
file_io_duration,
|
||||||
filename,
|
filename,
|
||||||
|
false,
|
||||||
None,
|
None,
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
|
@ -2556,6 +2652,7 @@ enum ModuleNameEnum<'a> {
|
||||||
fn send_header<'a>(
|
fn send_header<'a>(
|
||||||
loc_name: Located<ModuleNameEnum<'a>>,
|
loc_name: Located<ModuleNameEnum<'a>>,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
|
is_root_module: bool,
|
||||||
opt_shorthand: Option<&'a str>,
|
opt_shorthand: Option<&'a str>,
|
||||||
packages: &'a [Located<PackageEntry<'a>>],
|
packages: &'a [Located<PackageEntry<'a>>],
|
||||||
exposes: &'a [Located<ExposesEntry<'a, &'a str>>],
|
exposes: &'a [Located<ExposesEntry<'a, &'a str>>],
|
||||||
|
@ -2742,6 +2839,7 @@ fn send_header<'a>(
|
||||||
ModuleHeader {
|
ModuleHeader {
|
||||||
module_id: home,
|
module_id: home,
|
||||||
module_path: filename,
|
module_path: filename,
|
||||||
|
is_root_module,
|
||||||
exposed_ident_ids: ident_ids,
|
exposed_ident_ids: ident_ids,
|
||||||
module_name: loc_name.value,
|
module_name: loc_name.value,
|
||||||
packages: package_entries,
|
packages: package_entries,
|
||||||
|
@ -2763,6 +2861,7 @@ fn send_header<'a>(
|
||||||
fn send_header_two<'a>(
|
fn send_header_two<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
|
is_root_module: bool,
|
||||||
shorthand: &'a str,
|
shorthand: &'a str,
|
||||||
app_module_id: ModuleId,
|
app_module_id: ModuleId,
|
||||||
packages: &'a [Located<PackageEntry<'a>>],
|
packages: &'a [Located<PackageEntry<'a>>],
|
||||||
|
@ -2959,6 +3058,7 @@ fn send_header_two<'a>(
|
||||||
ModuleHeader {
|
ModuleHeader {
|
||||||
module_id: home,
|
module_id: home,
|
||||||
module_path: filename,
|
module_path: filename,
|
||||||
|
is_root_module,
|
||||||
exposed_ident_ids: ident_ids,
|
exposed_ident_ids: ident_ids,
|
||||||
module_name,
|
module_name,
|
||||||
packages: package_entries,
|
packages: package_entries,
|
||||||
|
@ -3102,6 +3202,7 @@ fn fabricate_pkg_config_module<'a>(
|
||||||
send_header_two(
|
send_header_two(
|
||||||
arena,
|
arena,
|
||||||
filename,
|
filename,
|
||||||
|
false,
|
||||||
shorthand,
|
shorthand,
|
||||||
app_module_id,
|
app_module_id,
|
||||||
&[],
|
&[],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue