Skip to content

Conversation

@SuperFola
Copy link
Member

@SuperFola SuperFola commented Jul 12, 2025

Description

This adds a new instruction, GET_CURRENT_PAGE_ADDRESS that pushes the current page address to the stack, and CALL_CURRENT_PAGE super instruction, to call the current page (without popping from the stack) with a given number of arguments.

Both instructions set the context.last_symbol accordingly.

The ASTLowerer can now optimize those non-tailrec recursive calls, to remove the unneeded

  • load local variable on the stack
  • pop local variable when doing VM::call
  • resolve the type of the variable
  • do the actual call

We can just call VM::call without a pointer to a Value, passing a non-zero page address, and VM:call will skip superfluous checks and stack manipulation.

Checklist

  • I have read the Contributor guide
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation if needed
  • I have added tests that prove my fix/feature is working
  • New and existing tests pass locally with my changes

@github-actions
Copy link

github-actions bot commented Jul 12, 2025

Static analysis report

Lizard report

Listing only functions with cyclomatic complexity >= 15 or NLOC >= 100 or parameters >= 6.

Filename Start line:end line Function name Parameters NLOC CCN
src/arkreactor/VM/VM.cpp 450:1903 Ark::VM::safeRun 3 1217 249
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 539:710 Ark::internal::ASTLowerer::handleCalls 4 130 42
src/arkreactor/Compiler/AST/Node.cpp 189:287 Ark::internal::Node::repr 0 84 28
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 138:241 Ark::internal::ASTLowerer::compileExpression 4 85 27
src/arkreactor/Compiler/AST/Node.cpp 289:362 Ark::internal::Node::debugPrint 1 64 24
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 267:326 Ark::internal::ASTLowerer::compileListInstruction 3 49 22
src/arkreactor/VM/VM.cpp 2022:2131 Ark::VM::backtrace 3 94 22
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 78:94 Ark::internal::ASTLowerer::nodeProducesOutput 1 13 15
src/arkreactor/Compiler/IntermediateRepresentation/IROptimizer.cpp 12:198 Ark::internal::IROptimizer::IROptimizer 1 163 4
Report about files you didn't modify in this PR
Filename Start line:end line Function name Parameters NLOC CCN
src/arkreactor/Compiler/Macros/Processor.cpp 239:617 Ark::internal::MacroProcessor::evaluate 3 355 125
src/arkreactor/Compiler/BytecodeReader.cpp 274:557 Ark::BytecodeReader::display 4 241 95
src/arkreactor/Exceptions.cpp 87:297 Ark::Diagnostics::makeContext 9 152 61
src/arkscript/JsonCompiler.cpp 27:260 JsonCompiler::_compile 1 200 36
include/Ark/Compiler/AST/Parser.hpp 107:196 Ark::internal::ARK_APIParser::string 0 87 32
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 162:273 Ark::internal::NameResolutionPass::visitKeyword 3 93 32
src/arkscript/main.cpp 23:352 main 2 284 31
src/arkreactor/Compiler/Macros/Processor.cpp 102:185 Ark::internal::MacroProcessor::processNode 3 61 27
src/arkreactor/TypeChecker.cpp 110:194 Ark::types::generateError 5 72 24
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 54:160 Ark::internal::NameResolutionPass::visit 2 87 23
src/arkreactor/Compiler/AST/Parser.cpp 292:427 Ark::internal::Parser::import_ 0 109 23
include/utf8.hpp 138:184 utf8::isValid 1 44 21
src/arkreactor/Compiler/AST/Optimizer.cpp 33:83 Ark::internal::Optimizer::countAndPruneDeadCode 1 42 20
src/arkscript/REPL/Utils.cpp 52:184 Ark::internal::getColorPerKeyword 0 110 19
src/arkreactor/TypeChecker.cpp 28:108 Ark::types::displayContract 4 70 19
src/arkreactor/Compiler/NameResolution/StaticScope.cpp 68:109 Ark::internal::NamespaceScope::get 2 32 18
src/arkreactor/VM/Value.cpp 72:132 Ark::Value::toString 1 48 18
src/arkreactor/Compiler/Macros/Executors/Function.cpp 16:88 Ark::internal::FunctionExecutor::applyMacro 2 55 17
include/Ark/Compiler/AST/Predicates.hpp 132:156 Ark::internal::IsSymbol::operator ( ) 1 24 16
src/arkscript/Formatter.cpp 168:224 Formatter::format 3 53 16
src/arkreactor/Compiler/Macros/Processor.cpp 699:738 Ark::internal::MacroProcessor::isConstEval 1 35 16
src/arkscript/Formatter.cpp 274:315 Formatter::formatFunction 2 35 15
src/arkreactor/Exceptions.cpp 299:310 Ark::Diagnostics::helper 9 11 2

CppCheck report

Filename Line Type Description
include/Ark/VM/VM.inl 247 style Variable 'maybe_value_ptr' can be declared as pointer to const
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 243 style Parameter 'x' can be declared as reference to const
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 493 style Parameter 'x' can be declared as reference to const
Report files about files you didn't modify in this PR
Filename Line Type Description
include/Ark/VM/Value/Procedure.hpp 43 style Class 'Procedure' has a constructor with 1 argument that is not explicit.
include/Ark/VM/Value/Procedure.hpp 51 style Class 'Procedure' has a constructor with 1 argument that is not explicit.
include/Ark/Logger.hpp 77 performance Function parameter 'data' should be passed by const reference.
src/arkreactor/Builtins/IO.cpp 81 style Parameter 'n' can be declared as reference to const
src/arkreactor/Builtins/IO.cpp 105 style Parameter 'n' can be declared as reference to const
src/arkreactor/Compiler/BytecodeReader.cpp 440 style struct member 'Arg::kind' is never used.
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 142 style Consider using std::find_if algorithm instead of a raw loop.
src/arkreactor/VM/State.cpp 187 style Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.
src/arkreactor/VM/Value/Procedure.cpp 15 performance Variable 'm_procedure' is assigned in constructor body. Consider performing initialization in initialization list.

@coveralls
Copy link

coveralls commented Jul 12, 2025

Coverage Status

coverage: 86.717% (+0.04%) from 86.675%
when pulling 804553f on opti/self-calls
into 4f99b4e on dev.

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 12, 2025

CodSpeed Performance Report

Merging #561 will improve performances by 21.04%

Comparing opti/self-calls (804553f) with dev (4f99b4e)

Summary

⚡ 7 improvements
✅ 10 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
ackermann 347.2 ms 309.9 ms +12.04%
binary_trees 5.1 s 4.7 s +8.6%
create_closure 4.8 ms 4.5 ms +6.65%
create_list 6.7 ms 6.6 ms +2.37%
fibonacci 33.6 ms 27.8 ms +21.04%
n_queens 113.3 ms 110.8 ms +2.32%
quicksort 1.1 ms 1.1 ms +3.86%

@github-actions
Copy link

github-actions bot commented Jul 12, 2025

Fuzzing report

/usr/local/bin/afl-whatsup status check tool for afl-fuzz by Michal Zalewski

Summary stats

    Fuzzers alive : 0
   Dead or remote : 1 (included in stats)
   Total run time : 5 minutes, 0 seconds
      Total execs : 38 thousands
 Cumulative speed : 128 execs/sec
    Pending items : 147 faves, 1086 total
 Coverage reached : 14.15%
    Crashes saved : 0
      Hangs saved : 0

Cycles without finds : 0
Time without finds : 0

[+] Captured 47587 tuples (map size 215734, highest value 255, total values 375296925) in '/dev/null'.
[+] A coverage of 47587 edges were achieved out of 215744 existing (22.06%) with 1094 input files.

…_CURRENT_PAGE super instruction to avoid a local variable lookup when performing a recursive non-tail call
@SuperFola SuperFola merged commit 66d9c29 into dev Jul 12, 2025
26 checks passed
@SuperFola SuperFola deleted the opti/self-calls branch July 12, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants