Signed addition is refused with the unsigned-overflow diagnostic, even when bounded

Open
#276 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
compilers

Research direction

Start with tests/unsigned_addition.rs and the compile_to_core path used by tests/compiler_spine.rs; the issue says the existing tests cover only U32 and U64. Check how signed addition is classified and how the overflow diagnostic is selected. Done means signed bounded addition is either accepted with sufficient proof or refused with a diagnostic that accurately describes the unsupported case.

Written by the indexing model from the issue text.

Description

bug

What happens

I64 + I64 is refused at Core with "unsigned addition requires a dominating proof of no overflow". That happens even when the intent has the where bounds that make the same expression compile for U64. The message points to a fix that doesn't exist for signed operands.

Reproduction (origin/main 980c3ae3, compile_to_core with the pure_context() from tests/compiler_spine.rs)

package a.b@1;
type Input = { a: I64, b: I64, };
type Output = { value: I64, };
intent t(input: Input) returns Output
  profile p.read basis none budget <= p.tiny
  where input.a <= 100 && input.b <= 100 {
  let value: I64 = input.a + input.b;
  return { value };
}
Width where a <= 100 && b <= 100 Result
U64 yes CORE-OK
I64 yes UnsupportedSourceShape: "unsigned addition requires a dominating proof of no overflow"
I64 no the same message

I64 multiplication and negation are refused as "outside the initial lowerable subset", which is accurate. Signed addition is the odd one out: it gets the unsigned-proof diagnostic.

Expected

Either signed addition should be accepted with a sufficient proof, or it should be refused the way multiplication and negation are, with a message that doesn't name a proof the author can't supply. The tests in tests/unsigned_addition.rs cover only U32 and U64.

Related observation (question, not necessarily a bug)

A body require input.a <= 100u64 else ...; placed before the addition does not count as the "dominating proof". Only the header where clause does. If that is intended (where is the precondition and require is a runtime obstruction), the diagnostic could say "add a where bound", because a body guard that does dominate the expression is easy to read as satisfying the message.

Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flyingrobots/edict

All issues in flyingrobots/edict

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.