Merge remote-tracking branch 'origin/main' into abilities-syntax

This commit is contained in:
Richard Feldman 2023-08-10 20:29:27 -04:00
commit 2da41be29f
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
524 changed files with 47536 additions and 15089 deletions

View file

@ -15,7 +15,9 @@ use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds};
use roc_parse::parser::{SourceError, SyntaxError};
use roc_problem::can::Problem;
use roc_region::all::Loc;
use roc_solve::solve::{self, Aliases};
use roc_solve::module::SolveConfig;
use roc_solve::solve::RunSolveOutput;
use roc_solve::{solve, Aliases, FunctionKind};
use roc_solve_problem::TypeError;
use roc_types::subs::{Content, Subs, VarStore, Variable};
use roc_types::types::Types;
@ -33,26 +35,28 @@ pub fn infer_expr(
problems: &mut Vec<TypeError>,
types: Types,
constraints: &Constraints,
constraint: &Constraint,
constraint: Constraint,
pending_derives: PendingDerives,
aliases: &mut Aliases,
abilities_store: &mut AbilitiesStore,
derived_module: SharedDerivedModule,
expr_var: Variable,
) -> (Content, Subs) {
let (solved, _) = solve::run(
ModuleId::ATTR,
let config = SolveConfig {
types,
constraints,
problems,
subs,
aliases,
constraint,
root_constraint: constraint,
home: ModuleId::ATTR,
pending_derives,
abilities_store,
&Default::default(),
exposed_by_module: &Default::default(),
derived_module,
);
function_kind: FunctionKind::LambdaSet,
#[cfg(debug_assertions)]
checkmate: None,
};
let RunSolveOutput { solved, .. } =
solve::run(config, problems, subs, aliases, abilities_store);
let content = *solved.inner().get_content_without_compacting(expr_var);

View file

@ -26,6 +26,7 @@ mod test_reporting {
DEFAULT_PALETTE,
};
use roc_reporting::report::{RocDocAllocator, RocDocBuilder};
use roc_solve::FunctionKind;
use roc_solve_problem::TypeError;
use roc_types::subs::Subs;
use std::path::PathBuf;
@ -86,7 +87,7 @@ mod test_reporting {
path.push("snapshots");
path.push("fail");
let kind = if is_expr { "expr" } else { "header" };
path.push(format!("{}.{}.roc", test_name, kind));
path.push(format!("{test_name}.{kind}.roc"));
std::fs::write(path, src).unwrap();
}
@ -113,20 +114,21 @@ mod test_reporting {
// Use a deterministic temporary directory.
// We can't have all tests use "tmp" because tests run in parallel,
// so append the test name to the tmp path.
let tmp = format!("tmp/{}", subdir);
let tmp = format!("tmp/{subdir}");
let dir = roc_test_utils::TmpDir::new(&tmp);
let filename = PathBuf::from("Test.roc");
let file_path = dir.path().join(filename);
let full_file_path = file_path.clone();
let mut file = File::create(file_path).unwrap();
writeln!(file, "{}", module_src).unwrap();
writeln!(file, "{module_src}").unwrap();
let load_config = LoadConfig {
target_info: roc_target::TargetInfo::default_x86_64(),
render: RenderTarget::Generic,
palette: DEFAULT_PALETTE,
threading: Threading::Single,
exec_mode: ExecutionMode::Check,
function_kind: FunctionKind::LambdaSet,
};
let result = roc_load::load_and_typecheck(
arena,
@ -218,7 +220,7 @@ mod test_reporting {
buf
}
Err(other) => {
panic!("failed to load: {:?}", other);
panic!("failed to load: {other:?}");
}
}
}
@ -258,7 +260,7 @@ mod test_reporting {
subs.rigid_var(var.value, "*".into());
}
let mut solve_aliases = roc_solve::solve::Aliases::default();
let mut solve_aliases = roc_solve::Aliases::default();
for (name, alias) in output.aliases {
solve_aliases.insert(&mut types, name, alias);
@ -271,7 +273,7 @@ mod test_reporting {
&mut unify_problems,
types,
&constraints,
&constraint,
constraint,
// Use `new_report_problem_as` in order to get proper derives.
// TODO: remove the non-new reporting test infra.
PendingDerives::default(),
@ -389,7 +391,7 @@ mod test_reporting {
// convenient to copy-paste the generated message
if buf != expected_rendering {
for line in buf.split('\n') {
println!(" {}", line);
println!(" {line}");
}
}
@ -5363,24 +5365,6 @@ Tab characters are not allowed."###,
"###
);
test_report!(
interpolate_not_identifier,
r#""abc\(32)def""#,
@r###"
SYNTAX PROBLEM /code/proj/Main.roc
This string interpolation is invalid:
4 "abc\(32)def"
^^
I was expecting an identifier, like \u(message) or
\u(LoremIpsum.text).
Learn more about string interpolation at TODO
"###
);
test_report!(
unicode_too_large,
r#""abc\u(110000)def""#,
@ -5642,8 +5626,8 @@ All branches in an `if` must have the same type!
Num.sin
Num.div
Num.abs
Num.neg
Num.min
Num.e
"###
);
@ -5938,6 +5922,40 @@ In roc, functions are always written as a lambda, like{}
)
}
#[test]
fn missing_provides_in_app_header() {
report_header_problem_as(
indoc!(
r#"
app "broken"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br",
}
imports [
pf.Stdout,
]
main =
Stdout.line "answer"
"#
),
indoc!(
r#"
WEIRD PROVIDES /code/proj/Main.roc
I am partway through parsing a header, but I got stuck here:
7 ]
^
I am expecting the `provides` keyword next, like
provides [Animal, default, tame]
"#
),
)
}
#[test]
fn platform_requires_rigids() {
report_header_problem_as(
@ -10304,7 +10322,7 @@ In roc, functions are always written as a lambda, like{}
optional_field_in_record_builder,
indoc!(
r#"
{
{
a: <- apply "a",
b,
c ? "optional"
@ -10320,7 +10338,7 @@ In roc, functions are always written as a lambda, like{}
1 app "test" provides [main] to "./platform"
2
3 main =
4 {
4 {
5 a: <- apply "a",
6 b,
7 c ? "optional"
@ -10409,7 +10427,7 @@ In roc, functions are always written as a lambda, like{}
r#"
succeed = \_ -> crash ""
succeed {
succeed {
a: <- "a",
}
"#
@ -13847,4 +13865,44 @@ In roc, functions are always written as a lambda, like{}
Tip: It looks like it takes too many arguments. I'm seeing 1 extra.
"###
);
test_report!(
pizza_parens_right,
indoc!(
r#"
2 |> (Num.sub 3)
"#
),
@r###"
TOO FEW ARGS /code/proj/Main.roc
The `sub` function expects 2 arguments, but it got only 1:
4 2 |> (Num.sub 3)
^^^^^^^
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"###
);
test_report!(
pizza_parens_middle,
indoc!(
r#"
2 |> (Num.sub 3) |> Num.sub 3
"#
),
@r###"
TOO FEW ARGS /code/proj/Main.roc
The `sub` function expects 2 arguments, but it got only 1:
4 2 |> (Num.sub 3) |> Num.sub 3
^^^^^^^
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"###
);
}