Skip to content

Preserve specialization default in function contract attributes - #5153

Open
Tiramisu-Cake wants to merge 1 commit into
model-checking:mainfrom
Tiramisu-Cake:fix/default-fn-contracts-5116-v2
Open

Tiramisu-Cake wants to merge 1 commit into
model-checking:mainfrom
Tiramisu-Cake:fix/default-fn-contracts-5116-v2

Conversation

@Tiramisu-Cake

Copy link
Copy Markdown

#[kani::requires], #[kani::ensures], and #[kani::modifies] fail to parse a specialization default fn because syn::ItemFn does not accept the default keyword. Parse the function with syn::ImplItemFn and preserve default through the initial and subsequent macro expansions. An override still needs its own contract to be a proof_for_contract target.

The regression tests reproduce the blanket SmallSort impl from #5116 and cover individual and stacked clauses, old, and generic methods with proof_for_contract and stub_verified. The expected-output tests check contract violations and the diagnostic for an override without a contract.

Testing

  • The regression suite passed on Ubuntu 22.04, Ubuntu 24.04, Ubuntu 24.04 ARM, and macOS 15 Intel in fork CI on the final commit. The macOS 14 job was cancelled because the runner image was retired.
  • An earlier revision of this change (before parsing directly into syn::ImplItemFn) also passed the nine new cases and ten existing tests in a targeted compiletest run on Linux with the patch applied to f046b70644.

Resolves #5116

Disclosure: this change and description were prepared with AI assistance.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

Parse annotated functions directly as syn::ImplItemFn and preserve default through initial and stacked contract expansions. Keep contracts attached to their annotated implementation.

Cover specialization contract clauses, both clause orders with verified stubs, generic methods, old expressions, and expected contract violations. Disable contract assertions in the invalid-caller regression so its expected precondition failure depends on the verified stub.

Resolves model-checking#5116
@Tiramisu-Cake
Tiramisu-Cake requested review from a team as code owners November 11, 2026 15:16
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Nov 11, 2026

This branch has not been deployed

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

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Contract attributes on a specialization default fn fail to parse ("expected fn")

1 participant