Skip to content

Conversation

mountEvarus
Copy link

Context

Implementing the handling of circular dependencies/references with a flag.

How did you test your changes?

I have created a test file with several scenarios, and matched the results to what should happen in 100 cycles.

Types of changes

  • Breaking change (a fix or a feature because of which an existing functionality doesn't work as expected anymore)
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Checklist:

  • I have reviewed the guidelines about Contributing to HyperFormula and I confirm that my code follows the code style of this project.
  • I have signed the Contributor License Agreement.
  • My change is compliant with the OpenDocument standard.
  • My change is compatible with Microsoft Excel.
  • My change is compatible with Google Sheets.
  • I described my changes in the CHANGELOG.md file.
  • My changes require a documentation update.
  • My changes require a migration guide.

@Copilot Copilot AI review requested due to automatic review settings September 16, 2025 09:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a new configuration parameter allowCircularReferences that enables handling of circular dependencies in formulas with iterative computation instead of throwing CYCLE errors. When enabled, the system performs up to 100 iterations to resolve circular references to stable values.

Key changes:

  • Adds allowCircularReferences boolean configuration parameter with proper validation
  • Implements iterative circular dependency resolution algorithm in the Evaluator
  • Adds comprehensive test coverage for various circular reference scenarios

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/ConfigParams.ts Adds allowCircularReferences parameter interface definition
src/Config.ts Implements configuration parameter with validation and default value
src/Evaluator.ts Adds circular dependency resolution logic with 100-iteration limit
test/circular-dependencies.spec.ts Comprehensive test suite covering circular reference scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@AMBudnik
Copy link
Contributor

Thank you for sharing the pull request and signing our CLA.

P.S. You have an impressive GitHub activity!

@AMBudnik AMBudnik added the CLA signed Required for PR label Sep 18, 2025
Copy link
Contributor

@sequba sequba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mountEvarus, thank you for a solid implementation and many good-quality unit tests. It's almost ready to merge, but there are a few details that need to be tweaked.

* @default false
* @category Engine
*/
allowCircularReferences: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allowCircularReferences: boolean,
enableIterativeCalculation: boolean,

I'd rename this option to make it similar to the analogues feature in other spreadsheet software.

import {Statistics, StatType} from './statistics'

export class Evaluator {
private readonly iterationCount = 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be configurable. I'd introduce a new flag iterativeCalculationLimit

}
})

for (let i = 0; i < cycles; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop should stop early if the cycle diverges, similarly to the analogues feature in Google Sheets.

image

I'd introduce a new flag iterativeCalculationThreshold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA signed Required for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants