Repository navigation
Add value bounds to loop index variable - #17201
Conversation
|
Test this change out locally with the following install scripts (Action run 15217573073) VSCode
Azure CLI
|
Dotnet Test Results 78 files - 39 78 suites - 39 35m 53s ⏱️ - 24m 36s Results for commit 46fa3fa. ± Comparison against base commit 8c3040a. This pull request removes 1896 and adds 642 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces value bounds for loop index variables to reflect actual usage constraints by replacing the general integer type with a bounded integer type. Key changes include:
- Changing the index variable type from LanguageConstants.Int to a bounded integer type using TypeFactory.CreateIntegerType.
- Refactoring logic by introducing a new helper method (GetParentFor) to determine the parent ForSyntax.
- Updating package lock files and modifying sample baselines and tests to reflect the new index type.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Bicep.Wasm/packages.lock.json | Updated ILLink.Tasks version to 8.0.16 |
| src/Bicep.Local.Extension.Mock/packages.lock.json | Updated ILLink.Tasks version to 8.0.16 |
| src/Bicep.Local.Deploy/packages.lock.json | Updated ILLink.Tasks version to 8.0.16 |
| src/Bicep.IO/packages.lock.json | Updated ILLink.Tasks version to 8.0.16 |
| src/Bicep.Decompiler/packages.lock.json | Updated ILLink.Tasks version to 8.0.16 |
| src/Bicep.Core/packages.lock.json | Updated ILLink.Tasks version to 8.0.16 |
| src/Bicep.Core/TypeSystem/TypeAssignmentVisitor.cs | Changed index type logic and added a helper method to determine loop parent |
| Sample baseline files (main.symbols.bicep) | Adjusted loop index type documentation from “int” to “0” reflecting the new bounded type |
| src/Bicep.Core.IntegrationTests/ScenarioTests.cs | Added a test for issue #17035 |
| src/Bicep.Cli/packages.lock.json | Updated ILLink.Tasks version to 8.0.16 |
| global.json | Updated SDK version to 8.0.409 |
Comments suppressed due to low confidence (2)
src/Bicep.Core/TypeSystem/TypeAssignmentVisitor.cs:215
- [nitpick] The extraction of parent lookup logic into a helper method enhances maintainability; verify that all caller contexts pass the appropriate SyntaxBase to avoid unexpected exceptions.
private ForSyntax GetParentFor(SyntaxBase syntax) => binder.GetParent(syntax) switch {
src/Bicep.Core/TypeSystem/TypeAssignmentVisitor.cs:189
- Ensure that the maximum value computed via GetEnumerationTargetLength properly mirrors the intended constraints for loop index variables, and that downstream code can correctly handle the new bounded integer type.
return TypeFactory.CreateIntegerType(
minValue: 0,
maxValue: GetEnumerationTargetLength(GetParentFor(syntax)));
This reverts commit 28f3384.
Resolves #17035
The min & max values of an integer-typed expression are used to determine how long its stringified representation would be. Loop index variables currently use
LanguageConstants.Int, which can be as long as 20 characters ("-9223372036854775808"), but an index variable will always be between 3 characters or fewer since the backend doesn't allow copy loops to exceed 800 iterations.Microsoft Reviewers: Open in CodeFlow