@@ -833,12 +833,10 @@ fn quoted_as_module(
833
833
parse ( interpreter. elaborator , argument, Parser :: parse_path_no_turbofish_or_error, "a path" )
834
834
. ok ( ) ;
835
835
let option_value = path. and_then ( |path| {
836
+ let reason = Some ( ElaborateReason :: EvaluatingComptimeCall ( "Quoted::as_module" , location) ) ;
836
837
let module =
837
- interpreter. elaborate_in_function ( interpreter. current_function , |elaborator| {
838
- let reason = ElaborateReason :: EvaluatingComptimeCall ( "Quoted::as_module" , location) ;
839
- elaborator. with_elaborate_reason ( reason, |elaborator| {
840
- elaborator. resolve_module_by_path ( path)
841
- } )
838
+ interpreter. elaborate_in_function ( interpreter. current_function , reason, |elaborator| {
839
+ elaborator. resolve_module_by_path ( path)
842
840
} ) ;
843
841
module. map ( Value :: ModuleDefinition )
844
842
} ) ;
@@ -859,13 +857,11 @@ fn quoted_as_trait_constraint(
859
857
Parser :: parse_trait_bound_or_error,
860
858
"a trait constraint" ,
861
859
) ?;
860
+ let reason =
861
+ Some ( ElaborateReason :: EvaluatingComptimeCall ( "Quoted::as_trait_constraint" , location) ) ;
862
862
let bound = interpreter
863
- . elaborate_in_function ( interpreter. current_function , |elaborator| {
864
- let reason =
865
- ElaborateReason :: EvaluatingComptimeCall ( "Quoted::as_trait_constraint" , location) ;
866
- elaborator. with_elaborate_reason ( reason, |elaborator| {
867
- elaborator. resolve_trait_bound ( & trait_bound)
868
- } )
863
+ . elaborate_in_function ( interpreter. current_function , reason, |elaborator| {
864
+ elaborator. resolve_trait_bound ( & trait_bound)
869
865
} )
870
866
. ok_or ( InterpreterError :: FailedToResolveTraitBound { trait_bound, location } ) ?;
871
867
@@ -880,10 +876,11 @@ fn quoted_as_type(
880
876
) -> IResult < Value > {
881
877
let argument = check_one_argument ( arguments, location) ?;
882
878
let typ = parse ( interpreter. elaborator , argument, Parser :: parse_type_or_error, "a type" ) ?;
883
- let typ = interpreter. elaborate_in_function ( interpreter. current_function , |elaborator| {
884
- let reason = ElaborateReason :: EvaluatingComptimeCall ( "Quoted::as_type" , location) ;
885
- elaborator. with_elaborate_reason ( reason, |elaborator| elaborator. resolve_type ( typ) )
886
- } ) ;
879
+ let reason = Some ( ElaborateReason :: EvaluatingComptimeCall ( "Quoted::as_type" , location) ) ;
880
+ let typ =
881
+ interpreter. elaborate_in_function ( interpreter. current_function , reason, |elaborator| {
882
+ elaborator. resolve_type ( typ)
883
+ } ) ;
887
884
Ok ( Value :: Type ( typ) )
888
885
}
889
886
@@ -2301,37 +2298,34 @@ fn expr_resolve(
2301
2298
interpreter. current_function
2302
2299
} ;
2303
2300
2304
- interpreter. elaborate_in_function ( function_to_resolve_in, |elaborator| {
2305
- let reason = ElaborateReason :: EvaluatingComptimeCall ( "Expr::resolve" , location) ;
2306
- elaborator. with_elaborate_reason ( reason, |elaborator| match expr_value {
2307
- ExprValue :: Expression ( expression_kind) => {
2308
- let expr = Expression { kind : expression_kind, location : self_argument_location } ;
2309
- let ( expr_id, _) = elaborator. elaborate_expression ( expr) ;
2310
- Ok ( Value :: TypedExpr ( TypedExpr :: ExprId ( expr_id) ) )
2311
- }
2312
- ExprValue :: Statement ( statement_kind) => {
2313
- let statement =
2314
- Statement { kind : statement_kind, location : self_argument_location } ;
2315
- let ( stmt_id, _) = elaborator. elaborate_statement ( statement) ;
2316
- Ok ( Value :: TypedExpr ( TypedExpr :: StmtId ( stmt_id) ) )
2317
- }
2318
- ExprValue :: LValue ( lvalue) => {
2319
- let expr = lvalue. as_expression ( ) ;
2320
- let ( expr_id, _) = elaborator. elaborate_expression ( expr) ;
2301
+ let reason = Some ( ElaborateReason :: EvaluatingComptimeCall ( "Expr::resolve" , location) ) ;
2302
+ interpreter. elaborate_in_function ( function_to_resolve_in, reason, |elaborator| match expr_value
2303
+ {
2304
+ ExprValue :: Expression ( expression_kind) => {
2305
+ let expr = Expression { kind : expression_kind, location : self_argument_location } ;
2306
+ let ( expr_id, _) = elaborator. elaborate_expression ( expr) ;
2307
+ Ok ( Value :: TypedExpr ( TypedExpr :: ExprId ( expr_id) ) )
2308
+ }
2309
+ ExprValue :: Statement ( statement_kind) => {
2310
+ let statement = Statement { kind : statement_kind, location : self_argument_location } ;
2311
+ let ( stmt_id, _) = elaborator. elaborate_statement ( statement) ;
2312
+ Ok ( Value :: TypedExpr ( TypedExpr :: StmtId ( stmt_id) ) )
2313
+ }
2314
+ ExprValue :: LValue ( lvalue) => {
2315
+ let expr = lvalue. as_expression ( ) ;
2316
+ let ( expr_id, _) = elaborator. elaborate_expression ( expr) ;
2317
+ Ok ( Value :: TypedExpr ( TypedExpr :: ExprId ( expr_id) ) )
2318
+ }
2319
+ ExprValue :: Pattern ( pattern) => {
2320
+ if let Some ( expression) = pattern. try_as_expression ( elaborator. interner ) {
2321
+ let ( expr_id, _) = elaborator. elaborate_expression ( expression) ;
2321
2322
Ok ( Value :: TypedExpr ( TypedExpr :: ExprId ( expr_id) ) )
2323
+ } else {
2324
+ let expression = Value :: pattern ( pattern) . display ( elaborator. interner ) . to_string ( ) ;
2325
+ let location = self_argument_location;
2326
+ Err ( InterpreterError :: CannotResolveExpression { location, expression } )
2322
2327
}
2323
- ExprValue :: Pattern ( pattern) => {
2324
- if let Some ( expression) = pattern. try_as_expression ( elaborator. interner ) {
2325
- let ( expr_id, _) = elaborator. elaborate_expression ( expression) ;
2326
- Ok ( Value :: TypedExpr ( TypedExpr :: ExprId ( expr_id) ) )
2327
- } else {
2328
- let expression =
2329
- Value :: pattern ( pattern) . display ( elaborator. interner ) . to_string ( ) ;
2330
- let location = self_argument_location;
2331
- Err ( InterpreterError :: CannotResolveExpression { location, expression } )
2332
- }
2333
- }
2334
- } )
2328
+ }
2335
2329
} )
2336
2330
}
2337
2331
@@ -2440,13 +2434,14 @@ fn function_def_as_typed_expr(
2440
2434
let hir_expr = HirExpression :: Ident ( hir_ident. clone ( ) , generics. clone ( ) ) ;
2441
2435
let expr_id = interpreter. elaborator . interner . push_expr ( hir_expr) ;
2442
2436
interpreter. elaborator . interner . push_expr_location ( expr_id, location) ;
2443
- let typ = interpreter. elaborate_in_function ( interpreter. current_function , |elaborator| {
2444
- let reason =
2445
- ElaborateReason :: EvaluatingComptimeCall ( "FunctionDefinition::as_typed_expr" , location) ;
2446
- elaborator. with_elaborate_reason ( reason, |elaborator| {
2437
+ let reason = Some ( ElaborateReason :: EvaluatingComptimeCall (
2438
+ "FunctionDefinition::as_typed_expr" ,
2439
+ location,
2440
+ ) ) ;
2441
+ let typ =
2442
+ interpreter. elaborate_in_function ( interpreter. current_function , reason, |elaborator| {
2447
2443
elaborator. type_check_variable ( hir_ident, expr_id, generics)
2448
- } )
2449
- } ) ;
2444
+ } ) ;
2450
2445
interpreter. elaborator . interner . push_expr_type ( expr_id, typ) ;
2451
2446
Ok ( Value :: TypedExpr ( TypedExpr :: ExprId ( expr_id) ) )
2452
2447
}
@@ -2652,20 +2647,17 @@ fn function_def_set_parameters(
2652
2647
"a pattern" ,
2653
2648
) ?;
2654
2649
2655
- let hir_pattern = interpreter. elaborate_in_function ( Some ( func_id) , |elaborator| {
2656
- let reason = ElaborateReason :: EvaluatingComptimeCall (
2657
- "FunctionDefinition::set_parameters" ,
2658
- location,
2659
- ) ;
2660
- elaborator. with_elaborate_reason ( reason, |elaborator| {
2661
- elaborator. elaborate_pattern_and_store_ids (
2662
- parameter_pattern,
2663
- parameter_type. clone ( ) ,
2664
- DefinitionKind :: Local ( None ) ,
2665
- & mut parameter_idents,
2666
- true , // warn_if_unused
2667
- )
2668
- } )
2650
+ let reason =
2651
+ ElaborateReason :: EvaluatingComptimeCall ( "FunctionDefinition::set_parameters" , location) ;
2652
+ let reason = Some ( reason) ;
2653
+ let hir_pattern = interpreter. elaborate_in_function ( Some ( func_id) , reason, |elaborator| {
2654
+ elaborator. elaborate_pattern_and_store_ids (
2655
+ parameter_pattern,
2656
+ parameter_type. clone ( ) ,
2657
+ DefinitionKind :: Local ( None ) ,
2658
+ & mut parameter_idents,
2659
+ true , // warn_if_unused
2660
+ )
2669
2661
} ) ;
2670
2662
2671
2663
parameters. push ( ( hir_pattern, parameter_type. clone ( ) , Visibility :: Private ) ) ;
@@ -2773,19 +2765,17 @@ fn module_add_item(
2773
2765
let parser = Parser :: parse_top_level_items;
2774
2766
let top_level_statements = parse ( interpreter. elaborator , item, parser, "a top-level item" ) ?;
2775
2767
2776
- interpreter. elaborate_in_module ( module_id, |elaborator| {
2777
- let reason = ElaborateReason :: EvaluatingComptimeCall ( "Module::add_item" , location) ;
2778
- elaborator. with_elaborate_reason ( reason, |elaborator| {
2779
- let mut generated_items = CollectedItems :: default ( ) ;
2768
+ let reason = Some ( ElaborateReason :: EvaluatingComptimeCall ( "Module::add_item" , location) ) ;
2769
+ interpreter. elaborate_in_module ( module_id, reason, |elaborator| {
2770
+ let mut generated_items = CollectedItems :: default ( ) ;
2780
2771
2781
- for top_level_statement in top_level_statements {
2782
- elaborator. add_item ( top_level_statement, & mut generated_items, location) ;
2783
- }
2772
+ for top_level_statement in top_level_statements {
2773
+ elaborator. add_item ( top_level_statement, & mut generated_items, location) ;
2774
+ }
2784
2775
2785
- if !generated_items. is_empty ( ) {
2786
- elaborator. elaborate_items ( generated_items) ;
2787
- }
2788
- } ) ;
2776
+ if !generated_items. is_empty ( ) {
2777
+ elaborator. elaborate_items ( generated_items) ;
2778
+ }
2789
2779
} ) ;
2790
2780
2791
2781
Ok ( Value :: Unit )
0 commit comments