Skip to content

Add checking for functions in Prelude that may return Any of exception type#715

Merged
tautschnig merged 20 commits intostrata-org:mainfrom
thanhnguyen-aws:anyexception
Apr 8, 2026
Merged

Add checking for functions in Prelude that may return Any of exception type#715
tautschnig merged 20 commits intostrata-org:mainfrom
thanhnguyen-aws:anyexception

Conversation

@thanhnguyen-aws
Copy link
Copy Markdown
Contributor

Issue #, if available: Some functions in Python prelude that returns an exception as a value of Any type, such as PAdd, PMul,... Those exceptions are not currently caught and checked in Python to Laurel translation.

Description of changes:

  • Add a suffix "!AnyMaybeException" to the names of those functions to recognize them.
  • Make sure that those functions propagate the exceptions of their arguments (check and return Exceptions if any of their inputs are exception).
  • Add an assertion : !Any..isexception(expr) for each outermost expr that is a StaticCall of a function whose name ends with "!AnyMaybeException".

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

@thanhnguyen-aws thanhnguyen-aws requested a review from a team March 30, 2026 22:22
@thanhnguyen-aws thanhnguyen-aws marked this pull request as draft March 30, 2026 22:22
@thanhnguyen-aws thanhnguyen-aws marked this pull request as ready for review March 30, 2026 22:58
Copy link
Copy Markdown
Contributor

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

1. The !AnyMaybeExcept suffix convention is fragile. Using string suffix matching (funcName.endsWith "!AnyMaybeExcept") as a semantic marker is error-prone — it's easy to forget the suffix when adding new functions, and the ! character in identifiers could cause issues with parsers or tools that treat it specially. A more robust approach would be a metadata annotation or a registry (similar to how withException already checks function signatures).

2. Exception checks are duplicated at every use site. For x = a + b + c, the translation generates PAdd!AnyMaybeExcept(PAdd!AnyMaybeExcept(a, b), c). The getMaybeExceptionExprs function recursively finds both calls, generating two assertions. But the inner PAdd already propagates exceptions (its body checks isexception on inputs), so the outer assertion on the full expression would catch any inner exception too. The inner assertion is redundant — it increases the number of VCs without adding verification power.

3. getMaybeExceptionExprs only traverses StaticCall and IfThenElse. Other expression forms that could contain !AnyMaybeExcept calls (e.g., nested in Assign RHS, While conditions via Any_to_bool) are handled at the statement level but not within arbitrary expression trees. This seems intentional but could miss cases.

See inline comments.

Comment thread Strata/Languages/Python/PythonToLaurel.lean Outdated
Comment thread Strata/Languages/Python/PythonToLaurel.lean
tautschnig
tautschnig previously approved these changes Apr 3, 2026
tautschnig
tautschnig previously approved these changes Apr 6, 2026
Comment thread Strata/Languages/Python/PythonToLaurel.lean
Comment thread Strata/Languages/Python/PythonToLaurel.lean
Comment thread Strata/Languages/Python/PythonRuntimeLaurelPart.lean
Comment thread Strata/Languages/Python/PythonToLaurel.lean Outdated
Comment thread Strata/Languages/Python/PythonToLaurel.lean Outdated
Comment thread Strata/Languages/Python/PythonToLaurel.lean
Comment thread Strata/Languages/Python/PythonToLaurel.lean Outdated
Comment thread Strata/Languages/Python/PythonToLaurel.lean
Comment thread Strata/Languages/Python/PythonRuntimeLaurelPart.lean
@thanhnguyen-aws thanhnguyen-aws requested review from MikaelMayer, ssomayyajula and tautschnig and removed request for MikaelMayer April 7, 2026 19:35
MikaelMayer
MikaelMayer previously approved these changes Apr 7, 2026
ssomayyajula
ssomayyajula previously approved these changes Apr 8, 2026
@thanhnguyen-aws thanhnguyen-aws dismissed stale reviews from ssomayyajula and MikaelMayer via 5623019 April 8, 2026 16:34
@tautschnig tautschnig added this pull request to the merge queue Apr 8, 2026
Merged via the queue into strata-org:main with commit 4f3e2ff Apr 8, 2026
9 checks passed
olivier-aws pushed a commit that referenced this pull request Apr 9, 2026
…n type (#715)

*Issue #, if available:* Some functions in Python prelude that returns
an exception as a value of Any type, such as PAdd, PMul,... Those
exceptions are not currently caught and checked in Python to Laurel
translation.

*Description of changes:*
- Add a suffix "!AnyMaybeException" to the names of those functions to
recognize them.
- Make sure that those functions propagate the exceptions of their
arguments (check and return Exceptions if any of their inputs are
exception).
- Add an assertion : `!Any..isexception(expr)` for each outermost `expr`
that is a StaticCall of a function whose name ends with
"!AnyMaybeException".



By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
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.

4 participants