Skip to content

Feat: The Mamba-style indexing of collections - #498

Draft
JSAbrahams wants to merge 2 commits into
developfrom
feat-some-mamba-examples
Draft

Feat: The Mamba-style indexing of collections#498
JSAbrahams wants to merge 2 commits into
developfrom
feat-some-mamba-examples

Conversation

@JSAbrahams

@JSAbrahams JSAbrahams commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

Unlike C-style languages, we index collections using round brackets regardless of collection type.
E.g. we don't distinguish between lists and maps.
We had wanted to implement this for some time, but now we actually implemented this.

This feature essentially fully leverages the type checker to detect if we are indexing a collection, and passes this information to the (Python) backend.
This means that collection indexing is decoupled from our syntax.
Concretely, this means that mamba style indexing ( and ) is still desugared to Pythons [] C-style indexing.

def my_collection = [1, 2, 3]
print(my_collection(2)) # prints 3

Becomes

my_collection = [1, 2, 3]
print(my_collection[2]) # prints 3

In general, we also try to expand the code example section.
The README elaborates a bit more on why we opted for this perhaps unusual syntax which deviates from the C-style which dominates all languages.

The advantage of this decoupling is that it can work either way. If in future we opt to change our syntax (back/again), we can leave our backend untouched. We mainly need to change the type checker then to reject function calls and augment the grammar (if necessary) for indexes.

Added Tests

  • Tested for regressions.
  • And also tested the list indexing results in the Python code we expect.

Joel Abrahams added 2 commits August 28, 2026 14:08
If collection, mark as so.
This allows us to:

- First generate Python code were we style use C-style
  collection access if necessary (for lists).
- And down the line also allows us to generate machine code
  where we distinguish between the two.
@JSAbrahams JSAbrahams self-assigned this Aug 28, 2026
@JSAbrahams JSAbrahams added enhancement: check New feature in the type check module documentation Update or fix documentation enhancement: generate New feature in the core module labels Aug 28, 2026
@JSAbrahams
JSAbrahams deployed to development August 28, 2026 14:00 — with GitHub Actions Active
@JSAbrahams
JSAbrahams deployed to development August 28, 2026 14:00 — with GitHub Actions Active
@JSAbrahams
JSAbrahams deployed to development August 28, 2026 14:00 — with GitHub Actions Active
@JSAbrahams
JSAbrahams deployed to development August 28, 2026 14:00 — with GitHub Actions Active
@JSAbrahams
JSAbrahams deployed to development August 28, 2026 14:00 — with GitHub Actions Active
@JSAbrahams
JSAbrahams marked this pull request as draft August 28, 2026 14:00
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.63102% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.33%. Comparing base (8155000) to head (e3edf1c).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
src/check/constrain/constraint/expected.rs 0.00% 9 Missing ⚠️
src/check/constrain/generate/call.rs 86.15% 9 Missing ⚠️
src/check/constrain/unify/function.rs 92.04% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #498      +/-   ##
===========================================
- Coverage    92.50%   92.33%   -0.17%     
===========================================
  Files          113      113              
  Lines        15709    15911     +202     
===========================================
+ Hits         14531    14692     +161     
- Misses        1178     1219      +41     
Files with missing lines Coverage Δ
src/backend/cranelift/convert/call.rs 90.07% <100.00%> (+0.15%) ⬆️
src/backend/python/convert/call.rs 81.25% <100.00%> (+6.25%) ⬆️
src/backend/python/convert/mod.rs 95.50% <100.00%> (+0.02%) ⬆️
src/check/ast/mod.rs 100.00% <100.00%> (ø)
src/check/ast/node.rs 99.16% <ø> (ø)
src/check/constrain/unify/expression.rs 100.00% <100.00%> (ø)
src/check/constrain/unify/finished.rs 100.00% <ø> (ø)
src/check/constrain/unify/ty.rs 95.96% <100.00%> (+0.13%) ⬆️
src/check/context/function/python.rs 96.00% <ø> (ø)
src/check/constrain/unify/function.rs 82.20% <92.04%> (-2.39%) ⬇️
... and 2 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

documentation Update or fix documentation enhancement: check New feature in the type check module enhancement: generate New feature in the core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant