FStarLang / FStarLang/karamel

Remove explicit casts from some integer constants, to improve readability

Open
#72 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
OCaml
Stars
519
Forks
73
Avg merge
2h 58m
Merged PRs (30d)
1

Description

Kremlin is careful to produce constant values with predictable behavior, despite ambiguities in C about integer promotion due to sizeof(int) and signed-ness of char.

Examples:

- (uint32_t)1U

- (uint32_t)0U

- (int32_t)1

- (int32_t)0

I think Kremlin could omit the casts in a number of cases, while still being certain that the ambiguous cases are well handled. I believe it is safe for constants < 16 bits in length, where it already emits the 'U' suffix for unsigned, or omits it for signed.

For larger constants, close to sizeof(int) on a 16-bit machine, the explicit casts will still be important.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing KaRaMeL's constant-emission logic for the listed signed and unsigned integer forms. Compare generated C for constants below 16 bits with larger constants near the stated 16-bit-machine boundary; done means safe small constants no longer use explicit casts while larger ambiguous constants retain them.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, ocaml
Domain
compilers
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.