Skip to content

[claude-experiments] Add rem/Long support and fromEpochDays verification test#97

Open
jesyspa wants to merge 2 commits intomainfrom
claude/rem-long-support
Open

[claude-experiments] Add rem/Long support and fromEpochDays verification test#97
jesyspa wants to merge 2 commits intomainfrom
claude/rem-long-support

Conversation

@jesyspa
Copy link
Copy Markdown
Collaborator

@jesyspa jesyspa commented Apr 8, 2026

Summary

  • Register Int.rem() as a special Kotlin function — it was defined as RemIntInt but never wired up in SpecialKotlinFunctions.byName, so % in verified code compiled to an opaque method call instead of Viper's Mod.
  • Add Long type support: arithmetic operators, literals, type mapping, and Int↔Long conversions. Both map to Viper's unbounded Int.
  • Port kotlinx-datetime's fromEpochDays/toEpochDays as an expensive verification test with intermediate verify() assertions that guide the SMT solver through nonlinear arithmetic involving large constants (146097, 153, 306).

Details

The fromEpochDays test demonstrates both the power and limits of automated verification on real-world date arithmetic. The intermediate assertions (zeroDay >= 0 after cycle adjustment, doyEst >= 0 after year estimation) break the proof into pieces the solver can handle. Stronger postconditions (e.g. month in 1..12) remain out of reach because they require nonlinear modular arithmetic across packed integer representations.

Test plan

  • testFrom_epoch_days passes (golden file generated and verified)
  • testArithmetic passes (no regressions from rem/Long changes)
  • testFull_viper_dump passes

🤖 Generated with Claude Code

jesyspa and others added 2 commits April 8, 2026 16:12
- Register Int.rem() as a special Kotlin function (was defined but not wired up)
- Add Long arithmetic operators (plus, minus, times, div, rem, inc, dec, unaryMinus)
  mapped to the same Viper Int type, plus Int<->Long identity conversions
- Add Long literal support in StmtConversionVisitor and Long type mapping in ProgramConverter
- Port kotlinx-datetime's fromEpochDays/toEpochDays as an expensive verification test
  with intermediate verify() assertions to guide the SMT solver through nonlinear arithmetic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify properties from the source comments: adjustCycles <= -1, adjust <= 0,
zeroDay >= 0, doyEst >= 0, marchMonth0 in 0..11, month in 1..12, dom in 1..31,
yearEst >= 0.  These compose into a strong postcondition: res in 101..99991231.

The remaining gap is doyEst <= 365 (day-of-year upper bound), which requires
reasoning about the year-estimation division — too much nonlinear arithmetic
for the solver.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jesyspa jesyspa changed the title Add rem/Long support and fromEpochDays verification test [claude-experiments] Add rem/Long support and fromEpochDays verification test Apr 9, 2026
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.

1 participant