Merge branch 'main' into get-pointer

This commit is contained in:
HajagosNorbert 2023-11-21 11:15:28 +01:00
commit d71b386715
No known key found for this signature in database
GPG key ID: 807F4444870DB673
121 changed files with 3601 additions and 17076 deletions

View file

@ -1,3 +1,3 @@
package "builtins"
exposes [Str, Num, Bool, Result, List, Dict, Set, Decode, Encode, Hash, Set, Box, TotallyNotJson]
exposes [Str, Num, Bool, Result, List, Dict, Set, Decode, Encode, Hash, Box, TotallyNotJson]
packages {}

View file

@ -502,6 +502,7 @@ pub fn constrain_expr(
let reason = Reason::FnArg {
name: opt_symbol,
arg_index: HumanIndex::zero_based(index),
called_via: *called_via,
};
let expected_arg =
constraints.push_expected_type(ForReason(reason, arg_type_index, region));

View file

@ -2447,7 +2447,7 @@ mod test_reporting {
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `add` has an unexpected type:
This 2nd argument to + has an unexpected type:
4 0x4 + "foo"
^^^^^
@ -2456,7 +2456,7 @@ mod test_reporting {
Str
But `add` needs its 2nd argument to be:
But + needs its 2nd argument to be:
Int *
"###
@ -2472,7 +2472,7 @@ mod test_reporting {
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `add` has an unexpected type:
This 2nd argument to + has an unexpected type:
4 0x4 + 3.14
^^^^
@ -2481,7 +2481,7 @@ mod test_reporting {
Frac *
But `add` needs its 2nd argument to be:
But + needs its 2nd argument to be:
Int *
@ -2500,7 +2500,7 @@ mod test_reporting {
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `add` has an unexpected type:
This 2nd argument to + has an unexpected type:
4 42 + True
^^^^
@ -2509,7 +2509,7 @@ mod test_reporting {
[True]
But `add` needs its 2nd argument to be:
But + needs its 2nd argument to be:
Num *
"###
@ -3556,7 +3556,7 @@ mod test_reporting {
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `add` has an unexpected type:
This 2nd argument to + has an unexpected type:
14 x + y + h + l + minlit + maxlit
^^^^^^
@ -3565,7 +3565,7 @@ mod test_reporting {
U128
But `add` needs its 2nd argument to be:
But + needs its 2nd argument to be:
I128 or Dec
"###
@ -3843,7 +3843,7 @@ mod test_reporting {
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `add` has an unexpected type:
This 2nd argument to + has an unexpected type:
4 \{ x, y ? True } -> x + y
^
@ -3852,7 +3852,7 @@ mod test_reporting {
[True]
But `add` needs its 2nd argument to be:
But + needs its 2nd argument to be:
Num a
"###
@ -6377,7 +6377,7 @@ In roc, functions are always written as a lambda, like{}
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `mul` has an unexpected type:
This 2nd argument to * has an unexpected type:
5 mult = \a, b -> a * b
^
@ -6386,7 +6386,7 @@ In roc, functions are always written as a lambda, like{}
F64
But `mul` needs its 2nd argument to be:
But * needs its 2nd argument to be:
Num *
@ -6421,7 +6421,7 @@ In roc, functions are always written as a lambda, like{}
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `mul` has an unexpected type:
This 2nd argument to * has an unexpected type:
5 mult = \a, b -> a * b
^
@ -6430,7 +6430,7 @@ In roc, functions are always written as a lambda, like{}
F64
But `mul` needs its 2nd argument to be:
But * needs its 2nd argument to be:
Num a
@ -9234,7 +9234,7 @@ In roc, functions are always written as a lambda, like{}
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `isEq` has an unexpected type:
This 2nd argument to == has an unexpected type:
9 Job lst -> lst == ""
^^
@ -9243,7 +9243,7 @@ In roc, functions are always written as a lambda, like{}
Str
But `isEq` needs its 2nd argument to be:
But == needs its 2nd argument to be:
List [Job ] as
"###
@ -10013,7 +10013,7 @@ In roc, functions are always written as a lambda, like{}
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `isEq` has an unexpected type:
This 2nd argument to == has an unexpected type:
4 0x80000000000000000000000000000000 == -0x80000000000000000000000000000000
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -10022,7 +10022,7 @@ In roc, functions are always written as a lambda, like{}
I128
But `isEq` needs its 2nd argument to be:
But == needs its 2nd argument to be:
U128
"###
@ -10038,7 +10038,7 @@ In roc, functions are always written as a lambda, like{}
@r###"
TYPE MISMATCH /code/proj/Main.roc
This 2nd argument to `isEq` has an unexpected type:
This 2nd argument to == has an unexpected type:
4 170141183460469231731687303715884105728 == -170141183460469231731687303715884105728
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -10047,7 +10047,7 @@ In roc, functions are always written as a lambda, like{}
I128 or Dec
But `isEq` needs its 2nd argument to be:
But == needs its 2nd argument to be:
U128
"###

View file

@ -3291,7 +3291,7 @@ fn finish(
exposed_types_storage: ExposedTypesStorageSubs,
resolved_implementations: ResolvedImplementations,
dep_idents: IdentIdsByModule,
documentation: VecMap<ModuleId, ModuleDocumentation>,
mut documentation: VecMap<ModuleId, ModuleDocumentation>,
abilities_store: AbilitiesStore,
//
#[cfg(debug_assertions)] checkmate: Option<roc_checkmate::Collector>,
@ -3330,6 +3330,18 @@ fn finish(
roc_checkmate::dump_checkmate!(checkmate);
let mut docs_by_module = Vec::with_capacity(state.exposed_modules.len());
for module_id in state.exposed_modules.iter() {
let docs = documentation.remove(module_id).unwrap_or_else(|| {
panic!("A module was exposed but didn't have an entry in `documentation` somehow: {module_id:?}");
});
docs_by_module.push(docs);
}
debug_assert_eq!(documentation.len(), 0);
LoadedModule {
module_id: state.root_id,
interns,
@ -3346,7 +3358,7 @@ fn finish(
resolved_implementations,
sources,
timings: state.timings,
docs_by_module: documentation,
docs_by_module,
abilities_store,
}
}

View file

@ -43,7 +43,7 @@ pub struct LoadedModule {
pub resolved_implementations: ResolvedImplementations,
pub sources: MutMap<ModuleId, (PathBuf, Box<str>)>,
pub timings: MutMap<ModuleId, ModuleTiming>,
pub docs_by_module: VecMap<ModuleId, ModuleDocumentation>,
pub docs_by_module: Vec<(ModuleId, ModuleDocumentation)>,
pub abilities_store: AbilitiesStore,
pub typechecked: MutMap<ModuleId, CheckedModule>,
}

View file

@ -102,6 +102,15 @@ pub enum UnaryOp {
Not,
}
impl std::fmt::Display for UnaryOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
UnaryOp::Negate => write!(f, "-"),
UnaryOp::Not => write!(f, "!"),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BinOp {
// highest precedence

View file

@ -4270,35 +4270,50 @@ pub fn with_hole<'a>(
let arena = env.arena;
match can_expr {
Int(_, _, int_str, int, _bound) => assign_num_literal_expr(
env,
layout_cache,
assigned,
variable,
&int_str,
IntOrFloatValue::Int(int),
hole,
),
Int(_, _, int_str, int, _bound) => {
match assign_num_literal_expr(
env,
layout_cache,
assigned,
variable,
&int_str,
IntOrFloatValue::Int(int),
hole,
) {
Ok(stmt) => stmt,
Err(_) => hole.clone(),
}
}
Float(_, _, float_str, float, _bound) => assign_num_literal_expr(
env,
layout_cache,
assigned,
variable,
&float_str,
IntOrFloatValue::Float(float),
hole,
),
Float(_, _, float_str, float, _bound) => {
match assign_num_literal_expr(
env,
layout_cache,
assigned,
variable,
&float_str,
IntOrFloatValue::Float(float),
hole,
) {
Ok(stmt) => stmt,
Err(_) => hole.clone(),
}
}
Num(_, num_str, num, _bound) => assign_num_literal_expr(
env,
layout_cache,
assigned,
variable,
&num_str,
IntOrFloatValue::Int(num),
hole,
),
Num(_, num_str, num, _bound) => {
match assign_num_literal_expr(
env,
layout_cache,
assigned,
variable,
&num_str,
IntOrFloatValue::Int(num),
hole,
) {
Ok(stmt) => stmt,
Err(_) => hole.clone(),
}
}
Str(string) => Stmt::Let(
assigned,
@ -9267,14 +9282,12 @@ fn assign_num_literal_expr<'a>(
num_str: &str,
num_value: IntOrFloatValue,
hole: &'a Stmt<'a>,
) -> Stmt<'a> {
let layout = layout_cache
.from_var(env.arena, variable, env.subs)
.unwrap();
) -> Result<Stmt<'a>, RuntimeError> {
let layout = layout_cache.from_var(env.arena, variable, env.subs)?;
let literal =
make_num_literal(&layout_cache.interner, layout, num_str, num_value).to_expr_literal();
Stmt::Let(assigned, Expr::Literal(literal), layout, hole)
Ok(Stmt::Let(assigned, Expr::Literal(literal), layout, hole))
}
type ToLowLevelCallArguments<'a> = (

View file

@ -3370,6 +3370,7 @@ pub enum Reason {
FnArg {
name: Option<Symbol>,
arg_index: HumanIndex,
called_via: CalledVia,
},
TypedArg {
name: Option<Symbol>,