diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index b3d98098c8..b2d90626ff 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -178,7 +178,7 @@ mod cli_run { &example_file("benchmarks", "NQueens.roc"), "nqueens", &[], - "724\n", + "4\n", false, ); } @@ -219,6 +219,18 @@ mod cli_run { ); } + #[test] + #[serial(deriv)] + fn run_rbtree_delete_not_optimized() { + check_output( + &example_file("benchmarks", "RBTreeDel.roc"), + "rbtree-del", + &[], + "30\n", + false, + ); + } + // #[test] // #[serial(effect)] // fn run_effect_unoptimized() { diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index c082971270..82c9fb71c8 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -789,13 +789,19 @@ fn canonicalize_pending_def<'a>( let arity = typ.arity(); - let def_symbol = match &loc_can_pattern.value { - Pattern::Identifier(symbol) => *symbol, - _ => panic!("standalone annotations must be on identifiers"), + let problem = match &loc_can_pattern.value { + Pattern::Identifier(symbol) => RuntimeError::NoImplementationNamed { + def_symbol: *symbol, + }, + Pattern::Shadowed(region, loc_ident) => RuntimeError::Shadowing { + original_region: *region, + shadow: loc_ident.clone(), + }, + _ => RuntimeError::NoImplementation, }; // Fabricate a body for this annotation, that will error at runtime - let value = Expr::RuntimeError(RuntimeError::NoImplementation(def_symbol)); + let value = Expr::RuntimeError(problem); let is_closure = arity > 0; let loc_can_expr = if !is_closure { Located { diff --git a/compiler/problem/src/can.rs b/compiler/problem/src/can.rs index 2cb107b922..1173630fb3 100644 --- a/compiler/problem/src/can.rs +++ b/compiler/problem/src/can.rs @@ -145,7 +145,10 @@ pub enum RuntimeError { InvalidUnicodeCodePoint(Region), /// When the author specifies a type annotation but no implementation - NoImplementation(Symbol), + NoImplementationNamed { + def_symbol: Symbol, + }, + NoImplementation, /// cases where the `[]` value (or equivalently, `forall a. a`) pops up VoidValue, diff --git a/compiler/reporting/src/error/canonicalize.rs b/compiler/reporting/src/error/canonicalize.rs index f1b1281d08..8c12467eb0 100644 --- a/compiler/reporting/src/error/canonicalize.rs +++ b/compiler/reporting/src/error/canonicalize.rs @@ -635,7 +635,7 @@ fn pretty_runtime_error<'b>( region ); } - RuntimeError::NoImplementation(_) => todo!("no implementation, unreachable"), + RuntimeError::NoImplementation | RuntimeError::NoImplementationNamed { .. } => todo!("no implementation, unreachable"), RuntimeError::NonExhaustivePattern => { unreachable!("not currently reported (but can blow up at runtime)") } diff --git a/compiler/reporting/tests/test_reporting.rs b/compiler/reporting/tests/test_reporting.rs index 5b58ebe4d2..aeaf14b1d8 100644 --- a/compiler/reporting/tests/test_reporting.rs +++ b/compiler/reporting/tests/test_reporting.rs @@ -1129,7 +1129,7 @@ mod test_reporting { 3│> when True is 4│> _ -> 3.14 - This `when`expression produces: + This `when` expression produces: Float a diff --git a/examples/benchmarks/RBTreeDel.roc b/examples/benchmarks/RBTreeDel.roc index 745d26c9d1..31cf63b2fa 100644 --- a/examples/benchmarks/RBTreeDel.roc +++ b/examples/benchmarks/RBTreeDel.roc @@ -14,14 +14,18 @@ ConsList a : [ Nil, Cons a (ConsList a) ] main : Task.Task {} [] main = - m = makeMap 33 + # benchmarks use 4_200_000 + m = makeMap 420 + + val = fold (\_, v, r -> if v then r + 1 else r) m 0 - # val = fold (\_, v, r -> if v then r + 1 else r) m 0 - val = depth m val |> Str.fromInt |> Task.putLine +boom : Str -> a +boom = \_ -> boom "" + makeMap : I64 -> Map makeMap = \n -> makeMapHelp n n Leaf @@ -154,11 +158,13 @@ rebalanceLeft = \c, l, k, v, r -> when l is Node Black _ _ _ _ -> Del (balanceLeft (setRed l) k v r) (isBlack c) Node Red lx kx vx rx -> Del (Node Black lx kx vx (balanceLeft (setRed rx) k v r)) False + _ -> boom "unreachable" rebalanceRight = \c, l, k, v, r -> when r is Node Black _ _ _ _ -> Del (balanceRight l k v (setRed r)) (isBlack c) Node Red lx kx vx rx -> Del (Node Black (balanceRight l k v (setRed lx)) kx vx rx) False + _ -> boom "unreachable"