@@ -305,9 +305,12 @@ impl Inliner<'_> {
305
305
// See the `inline_variables` documentation for an explanation.
306
306
ValueConstructorVariant :: LocalVariable { .. } => {
307
307
// We remove the variable as inlined variables can only be
308
- // inlined once.
308
+ // inlined once. `inline_variables` only contains variables
309
+ // which we have already checked are possible to inline, as
310
+ // we check for variables which are only used once when converting
311
+ // to an `InlinableFunction`.
309
312
match self . inline_variables . remove ( name) {
310
- Some ( expression ) => expression ,
313
+ Some ( inlined_expression ) => inlined_expression ,
311
314
None => expression,
312
315
}
313
316
}
@@ -600,14 +603,7 @@ impl Inliner<'_> {
600
603
{
601
604
// First, we do the actual inlining, by converting it to
602
605
// an anonymous function.
603
- let TypedExpr :: Fn {
604
- args : parameters,
605
- body,
606
- ..
607
- } = function. to_anonymous_function ( )
608
- else {
609
- unreachable ! ( "to_anonymous_function always returns TypedExpr::fn" ) ;
610
- } ;
606
+ let ( parameters, body) = function. to_anonymous_function ( ) ;
611
607
// Then, we perform beta reduction, inlining the call to
612
608
// the anonymous function.
613
609
return self . inline_anonymous_function_call (
@@ -641,14 +637,7 @@ impl Inliner<'_> {
641
637
. get ( module_name)
642
638
. and_then ( |module| module. inline_functions . get ( name) )
643
639
{
644
- let TypedExpr :: Fn {
645
- args : parameters,
646
- body,
647
- ..
648
- } = function. to_anonymous_function ( )
649
- else {
650
- unreachable ! ( "to_anonymous_function always returns TypedExpr::fn" ) ;
651
- } ;
640
+ let ( parameters, body) = function. to_anonymous_function ( ) ;
652
641
return self . inline_anonymous_function_call (
653
642
& parameters,
654
643
arguments,
@@ -1059,10 +1048,7 @@ fn expand_block(expression: TypedExpr) -> TypedExpr {
1059
1048
location,
1060
1049
statements,
1061
1050
} if statements. len ( ) == 1 => {
1062
- let first = statements
1063
- . into_iter ( )
1064
- . next ( )
1065
- . expect ( "Vec1 always has a first element" ) ;
1051
+ let ( first, _rest) = statements. split_off_first ( ) ;
1066
1052
1067
1053
match first {
1068
1054
// If this is several blocks inside each other, we want to
@@ -1448,7 +1434,7 @@ const BLANK_LOCATION: SrcSpan = SrcSpan { start: 0, end: 0 };
1448
1434
impl InlinableFunction {
1449
1435
/// Converts an `InlinableFunction` to an anonymous function, which can then
1450
1436
/// be inlined within another function.
1451
- fn to_anonymous_function ( & self ) -> TypedExpr {
1437
+ fn to_anonymous_function ( & self ) -> ( Vec < TypedArg > , Vec1 < TypedStatement > ) {
1452
1438
let parameters = self
1453
1439
. parameters
1454
1440
. iter ( )
@@ -1461,19 +1447,11 @@ impl InlinableFunction {
1461
1447
. map ( |ast| Statement :: Expression ( ast. to_expression ( ) ) )
1462
1448
. collect_vec ( ) ;
1463
1449
1464
- TypedExpr :: Fn {
1465
- location : BLANK_LOCATION ,
1466
- type_ : unknown_type ( ) ,
1467
- kind : FunctionLiteralKind :: Anonymous {
1468
- head : BLANK_LOCATION ,
1469
- } ,
1470
- args : parameters,
1471
- body : body
1472
- . try_into ( )
1450
+ (
1451
+ parameters,
1452
+ body. try_into ( )
1473
1453
. expect ( "Type-checking ensured that the body has at least 1 statement" ) ,
1474
- return_annotation : None ,
1475
- purity : Purity :: Unknown ,
1476
- }
1454
+ )
1477
1455
}
1478
1456
}
1479
1457
0 commit comments