Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding length to FunAsSeq #1450

Merged
merged 11 commits into from
Mar 9, 2022
Merged

adding length to FunAsSeq #1450

merged 11 commits into from
Mar 9, 2022

Conversation

konnov
Copy link
Collaborator

@konnov konnov commented Mar 8, 2022

After discussing FunAsSeq in #1442, I have added another parameter to this operator:

(**
 * As TLA+ is untyped, one can use function- and sequence-specific operators
 * interchangeably. However, to maintain correctness w.r.t. our type-system,
 * an explicit cast is needed when using functions as sequences.
 *
 * The parameters have the following meaning:
 *
 *  - fn is the function from 1..len that should be interpreted as a sequence.
 *  - len is the length of the sequence, len = Cardinality(DOMAIN fn),
 *    len may be a variable, a computable expression, etc.
 *  - capacity is a static upper bound on the length, that is, len <= capacity.
 *
 * @type: ((Int -> a), Int, Int) => Seq(a);
 *)
FunAsSeq(fn, len, capacity) ==
    LET __FunAsSeq_elem_ctor(i) == fn[i] IN
    SubSeq(MkSeq(capacity, __FunAsSeq_elem_ctor), 1, len)

This new form lets the user to specify the actual length of the sequence, which may be unknown in advance, while providing the tool with a statically known bound.

  • Tests added for any new code
  • Ran make fmt-fix (or had formatting run automatically on all files edited)
  • Documentation added for any new functionality
  • Entry added to UNRELEASED.md for any new functionality

@konnov konnov requested a review from Kukovec March 8, 2022 10:45
@codecov-commenter
Copy link

codecov-commenter commented Mar 8, 2022

Codecov Report

❗ No coverage uploaded for pull request base (unstable@386c1c8). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head bce2e91 differs from pull request most recent head 2aa752d. Consider uploading reports for the commit 2aa752d to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##             unstable    #1450   +/-   ##
===========================================
  Coverage            ?   74.58%           
===========================================
  Files               ?      359           
  Lines               ?    11440           
  Branches            ?      546           
===========================================
  Hits                ?     8533           
  Misses              ?     2907           
  Partials            ?        0           
Impacted Files Coverage Δ
...t/forsyte/apalache/tla/bmcmt/rules/MkSeqRule.scala 68.96% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 386c1c8...2aa752d. Read the comment docs.

@konnov
Copy link
Collaborator Author

konnov commented Mar 9, 2022

@Kukovec, what do you think?

Copy link
Collaborator

@Kukovec Kukovec left a comment

Choose a reason for hiding this comment

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

LGTM, assuming we're happy with the current error message for "constant" LET-INs

docs/src/lang/apalache-operators.md Outdated Show resolved Hide resolved
@konnov konnov merged commit 03b2e24 into unstable Mar 9, 2022
@konnov konnov deleted the ik/funAsSeq2 branch March 9, 2022 14:15
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.

3 participants