Skip to content

Adding argument attributes 'mut' and 'ref'#613

Merged
SuperFola merged 9 commits into
devfrom
feat/ref
Dec 9, 2025
Merged

Adding argument attributes 'mut' and 'ref'#613
SuperFola merged 9 commits into
devfrom
feat/ref

Conversation

@SuperFola
Copy link
Copy Markdown
Member

@SuperFola SuperFola commented Dec 7, 2025

Description

This allows setting function arguments as mut or ref (read-only). All function arguments are now, by default, immutable.

I still need to add way more tests for the ref attribute, to ensure nothing is breaking, and document everything. It basically avoids a reference unboxing when storing arguments inside functions.

Closes #612

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 (on https://github.com/ArkScript-lang/website, content/docs/)
  • I have added tests that prove my fix/feature is working
  • New and existing tests pass locally with my changes

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 7, 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 493:2030 Ark::VM::safeRun 3 1284 259
src/arkreactor/Compiler/Macros/Processor.cpp 253:637 Ark::internal::MacroProcessor::evaluate 3 354 122
src/arkreactor/Compiler/BytecodeReader.cpp 297:710 Ark::BytecodeReader::display 4 364 112
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 568:743 Ark::internal::ASTLowerer::handleCalls 4 133 43
src/arkscript/JsonCompiler.cpp 27:276 JsonCompiler::_compile 1 214 38
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 161:266 Ark::internal::NameResolutionPass::visitKeyword 3 85 35
src/arkreactor/Compiler/AST/Parser.cpp 837:928 Ark::internal::Parser::string 1 88 32
src/arkreactor/Compiler/AST/Node.cpp 179:285 Ark::internal::Node::repr 0 90 30
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 138:241 Ark::internal::ASTLowerer::compileExpression 4 85 27
src/arkreactor/Compiler/Macros/Processor.cpp 102:185 Ark::internal::MacroProcessor::processNode 3 61 27
src/arkreactor/Compiler/AST/Node.cpp 287:368 Ark::internal::Node::debugPrint 1 70 26
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 55:159 Ark::internal::NameResolutionPass::visit 2 83 23
src/arkreactor/Compiler/AST/Parser.cpp 288:416 Ark::internal::Parser::import_ 1 98 23
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 270:329 Ark::internal::ASTLowerer::compileListInstruction 3 49 22
src/arkreactor/VM/VM.cpp 2150:2254 Ark::VM::backtrace 3 89 22
src/arkscript/Formatter.cpp 173:235 Formatter::format 3 59 18
src/arkscript/Formatter.cpp 488:534 Formatter::formatCall 2 42 18
src/arkreactor/Compiler/Macros/Processor.cpp 719:760 Ark::internal::MacroProcessor::isConstEval 1 37 18
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 370:449 Ark::internal::ASTLowerer::compileFunction 3 57 16
src/arkscript/Formatter.cpp 285:326 Formatter::formatFunction 2 35 15
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 78:94 Ark::internal::ASTLowerer::nodeProducesOutput 1 13 15
Report about files you didn't modify in this PR
Filename Start line:end line Function name Parameters NLOC CCN
src/arkreactor/Error/Diagnostics.cpp 43:187 Ark::Diagnostics::makeContext 4 105 43
src/arkscript/main.cpp 23:323 main 2 255 29
src/arkreactor/TypeChecker.cpp 110:194 Ark::types::generateError 5 72 24
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/Compiler/NameResolution/StaticScope.cpp 68:109 Ark::internal::NamespaceScope::get 3 32 19
src/arkreactor/VM/Value.cpp 77:140 Ark::Value::toString 1 50 19
src/arkreactor/TypeChecker.cpp 28:108 Ark::types::displayContract 4 70 19
src/arkreactor/Compiler/Macros/Executors/Function.cpp 16:91 Ark::internal::FunctionExecutor::applyMacro 2 55 17
include/Ark/Compiler/AST/Predicates.hpp 132:156 Ark::internal::IsSymbol::operator ( ) 1 24 16
src/arkreactor/Compiler/Macros/Executors/Function.cpp 101:158 Ark::internal::FunctionExecutor::unify 5 50 15
src/arkreactor/Compiler/IntermediateRepresentation/IROptimizer.cpp 12:206 Ark::internal::IROptimizer::IROptimizer 1 170 4
src/arkreactor/Error/Diagnostics.cpp 189:202 Ark::Diagnostics::helper 6 13 2

CppCheck report

Filename Line Type Description
include/Ark/VM/VM.inl 255 style Variable 'maybe_value_ptr' can be declared as pointer to const
src/arkreactor/Builtins/IO.cpp 165 style Consider using std::transform algorithm instead of a raw loop.
src/arkreactor/Compiler/BytecodeReader.cpp 476 style struct member 'Arg::kind' is never used.
src/arkreactor/VM/VM.cpp 494 information Limiting ValueFlow analysis in function 'safeRun' since it is too complex. Please specify --check-level=exhaustive to perform full analysis.
src/arkreactor/VM/VM.cpp 713 style Variable 'tmp' can be declared as pointer to const
src/arkreactor/VM/VM.cpp 372 error Iterators of different containers 'm_execution_contexts.emplace_back(std::make_unique())' and 'm_execution_contexts.front()' are used together.
Report files about files you didn't modify in this PR
Filename Line Type Description
src/arkreactor/Builtins/Bytecode.cpp 22 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Compiler/NameResolution/ScopeResolver.cpp 134 style Consider using std::find_if algorithm instead of a raw loop.
include/Ark/VM/Future.hpp 50 style Unused private function: 'Future::deleteSelfViaVM'
src/arkreactor/VM/Future.cpp 23 performance Variable 'm_value' is assigned in constructor body. Consider performing initialization in initialization list.
src/arkreactor/VM/State.cpp 190 style Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 7, 2025

Coverage Status

coverage: 90.564% (+0.008%) from 90.556%
when pulling 673cbc5 on feat/ref
into 0bb7859 on dev.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 7, 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 : 40 thousands
 Cumulative speed : 135 execs/sec
    Pending items : 152 faves, 1230 total
 Coverage reached : 11.89%
    Crashes saved : 0
      Hangs saved : 0

Cycles without finds : 0
Time without finds : 0

[+] Captured 41941 tuples (map size 221738, highest value 255, total values 398486968) in '/dev/null'.
[+] A coverage of 41941 edges were achieved out of 221760 existing (18.91%) with 1239 input files.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Dec 8, 2025

CodSpeed Performance Report

Merging #613 will degrade performances by 1.34%

Comparing feat/ref (673cbc5) with dev (0bb7859)

Summary

❌ 1 (👁 1) regression
✅ 16 untouched
🆕 1 new

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 create_list_with_ref N/A 6 ms N/A
👁 Welder - Big - 665 nodes[2] 39.4 ms 39.9 ms -1.34%

@SuperFola SuperFola merged commit efef346 into dev Dec 9, 2025
27 checks passed
@SuperFola SuperFola deleted the feat/ref branch December 9, 2025 13:49
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.

Allow adding modifiers to function arguments, like mut and ref

2 participants