Skip to content

Fix multi-output procedure handling: Unknown fallback and prelude withException detection#726

Merged
shigoel merged 11 commits intomainfrom
tautschnig/multi-output
Apr 6, 2026
Merged

Fix multi-output procedure handling: Unknown fallback and prelude withException detection#726
shigoel merged 11 commits intomainfrom
tautschnig/multi-output

Conversation

@tautschnig
Copy link
Copy Markdown
Contributor

@tautschnig tautschnig commented Apr 1, 2026

Problem

timedelta(days=7) caused a Core type checking error "Impossible to unify bool with Any" because:

  1. computeExprType returned TVoid for multi-output procedures (e.g., timedelta_func returning (delta: Any, maybe_except: Error)). TVoid translates to bool in Core, causing the confusing error.

  2. withException in PythonToLaurel only checked importedSymbols for multi-output procedures, missing prelude procedures like timedelta_func. This caused the translator to generate a single-target assignment instead of the required 2-target assignment call [delta, maybe_except] := timedelta_func(...).

Fix

computeExprType (LaurelTypes.lean): Return Unknown instead of TVoid for zero-output and multi-output procedures. Unknown translates to Any in Core, which avoids the type mismatch. Single-output procedures continue to return their declared output type.

withException (PythonToLaurel.lean): Add preludeProcedures field to TranslationContext and extend withException to check prelude procedure signatures. This ensures multi-output prelude procedures
like timedelta_func correctly generate 2-target assignments.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…edures

computeExprType returned TVoid for procedures with multiple outputs
(e.g., timedelta_func returning (delta : Any, maybe_except : Error)).
TVoid is translated to bool in Core, causing "Impossible to unify bool
with Any" when the lifted call result variable is used in an Any context.

Fix: match on firstOutput :: _ instead of [singleOutput], returning the
first output type for any non-empty output list.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig self-assigned this Apr 1, 2026
@tautschnig tautschnig requested review from a team and Copilot April 1, 2026 09:42
Copy link
Copy Markdown
Contributor

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

Fixes Laurel type computation for static calls to multi-output procedures by returning the first output type (instead of defaulting to TVoid), preventing downstream Core unification failures (e.g., bool vs Any) when the lifted call result is used as a value.

Changes:

  • Update computeExprType to return the first output type for any non-empty proc.outputs list.
  • Add a Python regression test covering datetime - timedelta usage.
  • Register the new Python test expectation in the CBMC pipeline expected-results list.

Reviewed changes

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

File Description
Strata/Languages/Laurel/LaurelTypes.lean Fixes static procedure call expression typing by using the first declared output type.
StrataTest/Languages/Python/tests/test_timedelta_expr.py Adds a regression test exercising datetime/timedelta expression typing/translation.
StrataTest/Languages/Python/tests/cbmc_expected.txt Marks the new test as expected PASS in the Python CBMC pipeline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Strata/Languages/Laurel/LaurelTypes.lean Outdated
Comment thread StrataTest/Languages/Python/tests/cbmc_expected.txt Outdated
tautschnig and others added 3 commits April 1, 2026 10:23
The comment said we don't track return types and fall back to TVoid,
but the implementation now returns the first declared output type
when available.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Exercise datetime/timedelta arithmetic through the full Python →
Laurel → Core → SMT pipeline, verifying that multi-output procedures
return the correct first output type instead of TVoid.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig enabled auto-merge April 1, 2026 10:39
@tautschnig tautschnig removed their assignment Apr 1, 2026
shigoel
shigoel previously approved these changes Apr 1, 2026
Comment thread Strata/Languages/Laurel/LaurelTypes.lean Outdated
@tautschnig tautschnig self-assigned this Apr 2, 2026
tautschnig and others added 3 commits April 3, 2026 20:33
Per keyboardDrummer's review: multi-output procedures used as
expressions don't have a meaningful single type. Return Unknown
instead of picking the first output or falling back to TVoid.

Unknown translates to Any in Core, which avoids the original
'Impossible to unify bool with Any' error (TVoid→bool was the cause).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
…eption

withException only checked importedSymbols for multi-output procedures,
missing prelude procedures like timedelta_func. Add preludeProcedures
field to TranslationContext and check it in withException so that calls
to multi-output prelude procedures correctly generate 2-target
assignments (result + maybe_except).

This is the root cause fix for the timedelta type mismatch: the
translator now generates 'call [delta, maybe_except] := timedelta_func()'
instead of 'call [delta] := timedelta_func()'.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig changed the title Fix computeExprType to return first output type for multi-output procedures Fix multi-output procedure handling: Unknown fallback and prelude withException detection Apr 3, 2026
Comment thread Strata/Languages/Python/PythonToLaurel.lean Outdated
Comment thread StrataTest/Languages/Python/VerifyPythonTest.lean Outdated
tautschnig and others added 2 commits April 3, 2026 21:23
- Deduplicate the output-check expression into hasErrorOutput helper
- Update test comment to make explicit that timedelta_func exercises
  the multi-output prelude procedure path (withException + computeExprType)

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
MikaelMayer
MikaelMayer previously approved these changes Apr 3, 2026
keyboardDrummer
keyboardDrummer previously approved these changes Apr 4, 2026
Copy link
Copy Markdown
Contributor

@keyboardDrummer keyboardDrummer left a comment

Choose a reason for hiding this comment

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

Thanks, this is great. Ideally we would also add error reporting to Laurel to detect the incorrect Laurel that was generated before, but it would be a bonus :)

@tautschnig tautschnig added this pull request to the merge queue Apr 4, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Apr 4, 2026
shigoel
shigoel previously approved these changes Apr 6, 2026
Copy link
Copy Markdown
Contributor

@shigoel shigoel left a comment

Choose a reason for hiding this comment

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

Happy to approve again when the merge conflicts are resolved.

# Conflicts:
#	StrataTest/Languages/Python/VerifyPythonTest.lean
#	StrataTest/Languages/Python/tests/cbmc_expected.txt
@tautschnig tautschnig dismissed stale reviews from shigoel, keyboardDrummer, and MikaelMayer via 4cab005 April 6, 2026 18:02
@shigoel shigoel enabled auto-merge April 6, 2026 18:24
@shigoel shigoel added this pull request to the merge queue Apr 6, 2026
Merged via the queue into main with commit d6e9641 Apr 6, 2026
15 checks passed
@shigoel shigoel deleted the tautschnig/multi-output branch April 6, 2026 18:42
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.

5 participants