Skip to content

Fix/name resolution - #717

Merged
SuperFola merged 8 commits into
devfrom
fix/name-resolution
Dec 1, 2026
Merged

SuperFola merged 8 commits into
devfrom
fix/name-resolution

Conversation

@SuperFola

@SuperFola SuperFola commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Description

Rewrite the name resolution pass to split visit into two passes: register and qualify.

Use a new, better, and safer algorithm for name resolution, using the import lists of each namespace.

Closes #712

Checklist

  • I confirm that I am the author of this code and release it to the ArkScript project under the MPL-2.0 licence. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").
  • CHANGELOG.md is updated for new features, bug fixes or other significant changes
  • I have read the Contributor guide

Guidelines and best practices

  • Title of pull request is clear and informative
  • There are a small number of commits, each with an informative message, without any merge commit
  • Code is formatted to follow the style guidelines
  • Code is commented, particularly in hard-to-understand areas
  • Documentation has been updated, if needed (on https://github.com/ArkScript-lang/website, content/docs/)

Tests

  • I have added tests that prove my fix/feature is working
  • New and existing tests pass locally with my changes

… directly and indirectly) to a given package
two passes, now using a better name qualification algorithm.

The new algorithm tracks the import list of each namespace, to allow
precisely qualifying names, instead of merging all attributes of all
imports of a package into the single namespace it represents (which
could lead to a namespace being tagged as imported glob, imported
symbols and prefixed).
@codspeed

codspeed Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 0.02%

2 warnings

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 2 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 1 improved benchmark
❌ 1 (👁 1) regressed benchmark
✅ 16 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ Welder - Big - 665 nodes[2] 44.6 ms 43.8 ms +1.71%
👁 create_closure 4.7 ms 4.8 ms -1.63%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/name-resolution (43eb56f) with dev (5d223e8)

Open in CodSpeed

@coveralls

coveralls commented Dec 1, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 46704971716

Coverage increased (+0.04%) to 94.163%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: 17 uncovered changes across 5 files (370 of 387 lines covered, 95.61%).
  • 4 coverage regressions across 3 files.

Uncovered Changes

File Changed Covered %
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 213 205 96.24%
src/arkreactor/Compiler/Package/ImportSolver.cpp 59 55 93.22%
include/Ark/Compiler/NameResolution/StaticScope.hpp 6 3 50.0%
include/Ark/Compiler/AST/Namespace.hpp 1 0 0.0%
src/arkreactor/Compiler/NameResolution/ScopeResolver.cpp 60 59 98.33%
Total (12 files) 387 370 95.61%

Coverage Regressions

4 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 2 97.03%
src/arkreactor/Compiler/NameResolution/StaticScope.cpp 1 93.33%
src/arkreactor/Compiler/Package/ImportSolver.cpp 1 96.36%

Coverage Stats

Coverage Status
Relevant Lines: 11512
Covered Lines: 10840
Line Coverage: 94.16%
Coverage Strength: 1042512.14 hits per line

💛 - Coveralls

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

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 : 35 thousands
 Cumulative speed : 118 execs/sec
    Pending items : 162 faves, 1358 total
 Coverage reached : 9.71%
    Crashes saved : 0
      Hangs saved : 0

Cycles without finds : 0
Time without finds : 0

[+] Captured 47434 tuples (map size 286818, highest value 255, total values 494167151) in '/dev/null'.
[+] A coverage of 47434 edges were achieved out of 286848 existing (16.54%) with 1367 input files.

@SuperFola
SuperFola force-pushed the fix/name-resolution branch from 791916e to d4745f8 Compare December 1, 2026 13:42
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Super Instructions report

Some Super Instructions are under the usage threshold (25).

Super Instruction Uses in compiled code
APPEND_IN_PLACE_SYM_INDEX 23
INCREMENT 23
DECREMENT 15
STORE_FROM 12
LT_CONST_JUMP_IF_FALSE 8
NEQ_SYM_JUMP_IF_FALSE 4
CHECK_TYPE_OF 4
SET_VAL_TAIL 4
STORE_HEAD 2
NEQ_CONST_JUMP_IF_TRUE 2
SET_VAL_TAIL_BY_INDEX 1
SET_VAL_HEAD_BY_INDEX 1
MUL_SET_VAL 1
SET_VAL_HEAD 1
STORE_TAIL 1
Super Instructions over the threshold
Super Instruction Uses in compiled code
LOAD_CONST_LOAD_CONST 6006
CALL_SYMBOL 5580
LOAD_CONST_STORE 3310
CALL_BUILTIN_WITHOUT_RETURN_ADDRESS 1605
CALL_BUILTIN 994
LOAD_CONST_SET_VAL 992
INCREMENT_STORE 657
AT_SYM_SYM 618
GET_FIELD_FROM_SYMBOL_INDEX 512
STORE_LIST 390
LT_LEN_SYM_JUMP_IF_FALSE 373
GET_FIELD_FROM_SYMBOL 354
APPEND_IN_PLACE_SYM 350
CALL_SYMBOL_BY_INDEX 279
EQ_SYM_INDEX_JUMP_IF_TRUE 223
SET_VAL_FROM_INDEX 178
STORE_FROM_INDEX 166
FUSED_MATH 145
SET_VAL_FROM 136
LT_SYM_JUMP_IF_FALSE 126
DECREMENT_STORE 123
STORE_LEN 118
DECREMENT_BY_INDEX 117
GT_CONST_JUMP_IF_FALSE 115
LT_CONST_JUMP_IF_TRUE 98
GT_CONST_JUMP_IF_TRUE 91
AT_SYM_INDEX_SYM_INDEX 83
MUL_BY_INDEX 82
CALL_CURRENT_PAGE 77
AT_SYM_INDEX_CONST 65
EQ_CONST_JUMP_IF_TRUE 53
MUL_BY 47
GT_SYM_JUMP_IF_FALSE 40
STORE_HEAD_BY_INDEX 37
STORE_TAIL_BY_INDEX 36
INCREMENT_BY_INDEX 35
CHECK_TYPE_OF_BY_INDEX 30

@SuperFola
SuperFola force-pushed the fix/name-resolution branch from d4745f8 to 6acfa61 Compare December 1, 2026 13:47
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

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/Compiler/Macros/Processor.cpp 260:644 Ark::internal::MacroProcessor::evaluate 3 353 119
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 84:246 Ark::internal::NameResolutionPass::registerDeclarations 1 131 51
src/arkreactor/Compiler/AST/Parser.cpp 856:1006 Ark::internal::Parser::string 1 146 49
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 248:395 Ark::internal::NameResolutionPass::qualifyNames 1 127 42
src/arkreactor/Compiler/Macros/Processor.cpp 108:192 Ark::internal::MacroProcessor::processNode 3 63 29
src/arkreactor/Compiler/AST/Parser.cpp 301:432 Ark::internal::Parser::import_ 1 100 23
src/arkreactor/Compiler/NameResolution/ScopeResolver.cpp 104:167 Ark::internal::ScopeResolver::getFullyQualifiedNameInNearestScope 1 54 20
Report about files you didn't modify in this PR
Filename Start line:end line Function name Parameters NLOC CCN
src/arkreactor/VM/VM.cpp 458:2071 Ark::VM::unsafeRun 2 1338 171
src/arkreactor/Compiler/BytecodeReader.cpp 385:596 Ark::BytecodeReader::display 4 171 92
src/arkscript/main.cpp 24:394 main 2 320 46
src/arkreactor/Error/Diagnostics.cpp 45:192 Ark::Diagnostics::makeContext 4 109 44
src/arkscript/JsonCompiler.cpp 27:276 JsonCompiler::_compile 1 214 38
src/arkreactor/Builtins/Slice.cpp 9:81 Ark::internal::Builtins::slice 1 63 34
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 363:442 Ark::internal::ASTLowerer::compileListInstruction 3 64 32
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 212:324 Ark::internal::ASTLowerer::compileExpression 5 93 31
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 892:1040 Ark::internal::ASTLowerer::handleFunctionCall 3 116 31
src/arkreactor/Compiler/AST/Node.cpp 189:295 Ark::internal::Node::repr 0 90 31
src/arkreactor/Compiler/AST/Node.cpp 297:381 Ark::internal::Node::debugPrint 1 73 27
src/arkreactor/Compiler/BytecodeReader.cpp 612:713 Ark::BytecodeReader::printInstruction 7 98 25
src/arkreactor/TypeChecker.cpp 149:236 Ark::types::generateError 6 75 25
src/arkreactor/TypeChecker.cpp 32:147 Ark::types::displayContract 6 102 24
include/utf8.hpp 138:184 utf8::isValid 1 44 21
src/arkreactor/Compiler/IntermediateRepresentation/IRInliner.cpp 262:334 Ark::internal::IRInliner::extractPagesMetadata 1 63 21
src/arkreactor/VM/Value/Value.cpp 81:149 Ark::Value::toString 2 54 21
src/arkreactor/Compiler/AST/Optimizer.cpp 39:92 Ark::internal::Optimizer::countAndPruneDeadCode 1 45 20
src/arkreactor/VM/VM.cpp 2225:2319 Ark::VM::backtrace 3 81 20
src/arkscript/Formatter.cpp 212:274 Formatter::format 3 59 19
src/arkreactor/Compiler/IntermediateRepresentation/IRInliner.cpp 132:193 Ark::internal::IRInliner::isBuiltinProxy 1 48 19
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 522:615 Ark::internal::ASTLowerer::compileFunction 3 67 19
src/arkscript/Formatter.cpp 527:585 Formatter::formatCall 2 50 18
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 839:890 Ark::internal::ASTLowerer::handleOperator 3 42 18
src/arkreactor/Compiler/AST/Optimizer.cpp 94:148 Ark::internal::Optimizer::pruneUnusedGlobalVariables 1 49 18
src/arkreactor/Builtins/String.cpp 47:113 fmt::formatter::parse 1 59 18
src/arkreactor/Compiler/Macros/Executors/Function.cpp 16:89 Ark::internal::FunctionExecutor::applyMacro 2 56 17
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 107:129 Ark::internal::ASTLowerer::nodeProducesOutput 1 18 17
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 637:685 Ark::internal::ASTLowerer::compileLetMutSet 4 40 17
include/Ark/Compiler/AST/Predicates.hpp 142:166 Ark::internal::IsSymbol::operator ( ) 1 24 16
src/arkscript/Formatter.cpp 324:366 Formatter::formatFunction 2 36 16
src/arkreactor/Compiler/Macros/Executors/Function.cpp 99:156 Ark::internal::FunctionExecutor::unify 5 50 15
src/arkreactor/VM/VM.cpp 2083:2140 Ark::VM::throwArityError 4 47 15
src/arkreactor/Compiler/IntermediateRepresentation/IROptimizer.cpp 22:259 Ark::internal::IROptimizer::IROptimizer 2 215 12
src/arkreactor/Builtins/Time.cpp 72:92 Ark::internal::Builtins::Time::makeTimestamp 6 20 5
src/arkreactor/Error/Diagnostics.cpp 194:211 Ark::Diagnostics::helper 7 17 2

CppCheck report

Filename Line Type Description
src/arkreactor/Compiler/NameResolution/ScopeResolver.cpp 95 style Consider using std::find_if algorithm instead of a raw loop.
src/arkreactor/State.cpp 217 style Variable 'hash < Ark :: internal :: Declaration >' is assigned a value that is never used.
src/arkreactor/State.cpp 215 style Variable 'bytecode_hash' is assigned a value that is never used.
Report files about files you didn't modify in this PR
Filename Line Type Description
include/Ark/VM/VM.inl 138 style Parameter 'context' can be declared as reference to const
include/Ark/VM/VM.inl 254 style Parameter 'function_ptr' can be declared as pointer to const
include/Ark/VM/VM.inl 121 style The member function 'Ark::VM::loadSymbolFromIndex' can be static.
include/Ark/VM/VM.inl 138 style The member function 'Ark::VM::findNearestVariable' can be static.
include/Ark/VM/VM.inl 148 style The member function 'Ark::VM::store' can be static.
include/Ark/VM/VM.inl 176 style The member function 'Ark::VM::jump' can be static.
include/Ark/VM/VM.inl 218 style The member function 'Ark::VM::push' can be static.
include/Ark/VM/VM.inl 224 style The member function 'Ark::VM::push' can be static.
include/Ark/VM/VM.inl 230 style The member function 'Ark::VM::push' can be static.
include/Ark/VM/VM.inl 247 style The member function 'Ark::VM::returnFromFuncCall' can be static.
src/arkreactor/Builtins/Bytecode.cpp 23 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/List.cpp 60 style Parameter 'n' can be declared as reference to const
src/arkreactor/Builtins/Math.cpp 78 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Math.cpp 87 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 389 style Variable 'e' can be declared as reference to const
src/arkreactor/Builtins/Operators.cpp 13 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 53 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 74 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 159 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 171 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 183 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 195 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 207 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 219 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 231 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 243 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 269 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 299 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Operators.cpp 367 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/Time.cpp 32 style Parameter 'n' can be declared as reference to const
src/arkreactor/Compiler/BytecodeReader.cpp 20 performance Variable 'm_arg_kinds' is assigned in constructor body. Consider performing initialization in initialization list.
src/arkreactor/Compiler/BytecodeReader.cpp 362 style The member function 'Ark::BytecodeReader::findSourceLocation' can be static.
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 660 style Consider using std::count_if algorithm instead of a raw loop.
src/arkreactor/VM/SharedLibrary.cpp 0 information Too many #ifdef configurations - cppcheck only checks 12 of 13 configurations. Use --force to check all configurations.
src/arkreactor/VM/VM.cpp 0 information Too many #ifdef configurations - cppcheck only checks 12 of 13 configurations. Use --force to check all configurations.
src/arkreactor/VM/Value/Future.cpp 47 style Unused private function: 'Future::deleteSelfViaVM'
src/arkreactor/VM/Value/Future.cpp 23 performance Variable 'm_value' is assigned in constructor body. Consider performing initialization in initialization list.
src/arkscript/Formatter.cpp 173 style The member function 'Formatter::shouldAddNewLineBetweenNodes' can be static.
src/arkscript/Formatter.cpp 276 style The member function 'Formatter::formatComment' can be static.

@SuperFola
SuperFola force-pushed the fix/name-resolution branch 2 times, most recently from 2c41f9c to 6bf226b Compare December 1, 2026 16:55
@SuperFola
SuperFola force-pushed the fix/name-resolution branch from 6bf226b to 43eb56f Compare December 1, 2026 17:35
@SuperFola
SuperFola merged commit 3b821b9 into dev Dec 1, 2026
110 of 116 checks passed
@SuperFola
SuperFola deleted the fix/name-resolution branch December 1, 2026 21:20
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.

Unexpected module resolution

2 participants