mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
add ListIsUnique lowlevel operation
This commit is contained in:
parent
fcfe66f84d
commit
5755475b3a
9 changed files with 29 additions and 0 deletions
|
@ -1355,3 +1355,9 @@ pub fn listFindUnsafe(
|
|||
return .{ .value = null, .found = false };
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listIsUnique(
|
||||
list: RocList,
|
||||
) callconv(.C) bool {
|
||||
return list.isEmpty() or list.isUnique();
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ comptime {
|
|||
exportListFn(list.listAny, "any");
|
||||
exportListFn(list.listAll, "all");
|
||||
exportListFn(list.listFindUnsafe, "find_unsafe");
|
||||
exportListFn(list.listIsUnique, "is_unique");
|
||||
}
|
||||
|
||||
// Dict Module
|
||||
|
|
|
@ -345,6 +345,7 @@ pub const LIST_REPLACE_IN_PLACE: &str = "roc_builtins.list.replace_in_place";
|
|||
pub const LIST_ANY: &str = "roc_builtins.list.any";
|
||||
pub const LIST_ALL: &str = "roc_builtins.list.all";
|
||||
pub const LIST_FIND_UNSAFE: &str = "roc_builtins.list.find_unsafe";
|
||||
pub const LIST_IS_UNIQUE: &str = "roc_builtins.list.is_unique";
|
||||
|
||||
pub const DEC_FROM_STR: &str = "roc_builtins.dec.from_str";
|
||||
pub const DEC_FROM_F64: &str = "roc_builtins.dec.from_f64";
|
||||
|
|
|
@ -150,6 +150,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
|
|||
LIST_ANY => list_any,
|
||||
LIST_ALL => list_all,
|
||||
LIST_FIND => list_find,
|
||||
LIST_IS_UNIQUE => list_is_unique,
|
||||
DICT_LEN => dict_len,
|
||||
DICT_EMPTY => dict_empty,
|
||||
DICT_SINGLE => dict_single,
|
||||
|
@ -3773,6 +3774,11 @@ fn list_find(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
)
|
||||
}
|
||||
|
||||
/// List.isUnique : List * -> Bool
|
||||
fn list_is_unique(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
lowlevel_1(symbol, LowLevel::ListIsUnique, var_store)
|
||||
}
|
||||
|
||||
/// Dict.len : Dict * * -> Nat
|
||||
fn dict_len(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let arg1_var = var_store.fresh();
|
||||
|
|
|
@ -5667,6 +5667,15 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
update_mode,
|
||||
)
|
||||
}
|
||||
ListIsUnique => {
|
||||
// List.isUnique : List a -> Bool
|
||||
debug_assert_eq!(args.len(), 1);
|
||||
|
||||
let list = load_symbol(scope, &args[0]);
|
||||
let list = list_to_c_abi(env, list).into();
|
||||
|
||||
call_bitcode_fn(env, &[list], bitcode::LIST_IS_UNIQUE)
|
||||
}
|
||||
NumToStr => {
|
||||
// Num.toStr : Num a -> Str
|
||||
debug_assert_eq!(args.len(), 1);
|
||||
|
|
|
@ -277,6 +277,8 @@ impl<'a> LowLevelCall<'a> {
|
|||
_ => internal_error!("invalid storage for List"),
|
||||
},
|
||||
|
||||
ListIsUnique => self.load_args_and_call_zig(backend, bitcode::LIST_IS_UNIQUE),
|
||||
|
||||
ListMap | ListMap2 | ListMap3 | ListMap4 | ListMapWithIndex | ListKeepIf | ListWalk
|
||||
| ListWalkUntil | ListWalkBackwards | ListKeepOks | ListKeepErrs | ListSortWith
|
||||
| ListAny | ListAll | ListFindUnsafe | DictWalk => {
|
||||
|
|
|
@ -53,6 +53,7 @@ pub enum LowLevel {
|
|||
ListAny,
|
||||
ListAll,
|
||||
ListFindUnsafe,
|
||||
ListIsUnique,
|
||||
DictSize,
|
||||
DictEmpty,
|
||||
DictInsert,
|
||||
|
|
|
@ -1252,6 +1252,7 @@ define_builtins! {
|
|||
55 LIST_SORT_DESC: "sortDesc"
|
||||
56 LIST_SORT_DESC_COMPARE: "#sortDescCompare"
|
||||
57 LIST_REPLACE: "replace"
|
||||
58 LIST_IS_UNIQUE: "#isUnique"
|
||||
}
|
||||
5 RESULT: "Result" => {
|
||||
0 RESULT_RESULT: "Result" // the Result.Result type alias
|
||||
|
|
|
@ -1031,6 +1031,8 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
|||
|
||||
ExpectTrue => arena.alloc_slice_copy(&[irrelevant]),
|
||||
|
||||
ListIsUnique => arena.alloc_slice_copy(&[borrowed]),
|
||||
|
||||
BoxExpr | UnboxExpr => {
|
||||
unreachable!("These lowlevel operations are turned into mono Expr's")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue