-
Notifications
You must be signed in to change notification settings - Fork 62
Add dynamic mode to type projector #1858
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
base: dev
Are you sure you want to change the base?
Changes from all commits
a649815
1a40403
0216699
65d1851
3d15477
36d615c
85c2b4d
7909c30
88e8d76
1e5f9ca
db3a420
3961c95
853e029
be3aa4d
72e8101
a82b64c
b7c2577
0dd5810
173a5f4
6e4de9c
353b0e2
4c6658c
4d386e8
d8efcfd
9a8e9f6
9ab6e0c
ff67c1f
2ea4c26
930e42f
e1539bc
75666d3
2585f43
bbf9abf
10a2850
bd8fd25
d1e8ce3
c9d7cf2
b0b4285
b08f6a1
2e5350a
941e249
d6c64e2
e4a0034
06902fc
e08aa02
3c3eac3
bf5a0d2
a3cf6dc
2dbf027
df49af0
8e2a70a
5b1c7d3
5ff56a7
7b34b49
c76a164
995b9af
4ec5c6d
30f5593
698e981
64d6aa6
c270918
e4e1a7c
f1eea2e
222abd1
d5a0291
9b1af01
ff5523b
0f20fd1
c7d0ce2
52d2a2c
15a8df2
c2b73ee
1d1ff55
a324d73
7e12fdd
5c85788
e4b95b2
10c26b3
79cf327
c733274
aa26613
f6d3975
7f821c9
d8b16b2
4e6c1ae
ee65e54
94ab61a
14c1ed0
5c4fcb2
5d94433
9ab851d
457534b
e50c2c5
c37c8e0
23e38c3
2620112
4ae0e2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| open Language; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Number of IDs required for ExpToSegment compatibility per type constructor */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let necessary_ids: Typ.t => int = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ty => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (ty.term) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | Prod([]) => 1 /* Empty product (unit-like) */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | Prod(tys) => List.length(tys) - 1 /* One ID per separator */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | Sum(tys) => List.length(tys) + 1 /* Constructors + prefix */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7h3kk1d marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | _ => 1 /* Default for other type constructors */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+10
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Number of IDs required for ExpToSegment compatibility per type constructor */ | |
| let necessary_ids: Typ.t => int = | |
| ty => { | |
| switch (ty.term) { | |
| | Prod([]) => 1 /* Empty product (unit-like) */ | |
| | Prod(tys) => List.length(tys) - 1 /* One ID per separator */ | |
| | Sum(tys) => List.length(tys) + 1 /* Constructors + prefix */ | |
| | _ => 1 /* Default for other type constructors */ | |
| /** | |
| * Compute how many IDs are needed on a type so that ExpToSegment can reuse | |
| * them instead of allocating fresh IDs while segmenting an expression. | |
| * | |
| * The number depends on the shape of the type constructor: | |
| * - Prod([]): | |
| * Empty product (unit-like). We treat the whole value as a single | |
| * segment and allocate a single ID for it. | |
| * - Prod(tys): | |
| * Non-empty product. ExpToSegment represents products as a sequence of | |
| * fields separated by "separators" (e.g. commas). Only separators are | |
| * styled via IDs, so we need one ID per separator: length(tys) - 1. | |
| * - Sum(tys): | |
| * Sum / variant type. ExpToSegment assigns: | |
| * - one ID per constructor branch, and | |
| * - one additional ID for the *shared prefix* of the sum, i.e. the | |
| * common discriminator / prefix segment that is rendered before any | |
| * particular constructor (for example, the "tag" position or a | |
| * leading bar or keyword that is shared across all branches). | |
| * Hence we need length(tys) constructor IDs + 1 prefix ID. | |
| * - _ (other constructors): | |
| * For all other type constructors we conservatively require a single ID. | |
| */ | |
| let necessary_ids: Typ.t => int = | |
| ty => { | |
| switch (ty.term) { | |
| | Prod([]) => 1 /* Empty product (unit-like): whole value gets one ID */ | |
| | Prod(tys) => | |
| List.length(tys) - 1 /* One ID per separator between product fields */ | |
| | Sum(tys) => | |
| List.length(tys) + 1 | |
| /* One ID per constructor branch + one shared prefix/discriminator ID */ | |
| | _ => 1 /* Default: a single ID for other type constructors */ |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation needed_ids - List.length(current_ids) could be negative if current_ids has more elements than needed_ids. While List.init would fail with a negative value, this should be handled more gracefully. Consider using max(0, needed_ids - List.length(current_ids)) to prevent potential issues.
| let ids = | |
| current_ids | |
| @ List.init(needed_ids - List.length(current_ids), _ => Id.mk()); | |
| let missing_ids = max(0, needed_ids - List.length(current_ids)); | |
| let ids = | |
| current_ids | |
| @ List.init(missing_ids, _ => Id.mk()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
raise_if_paddingsetting is added to detect when padding is needed, but the raised exception uses a genericFailurewith a string message. Consider defining a specific exception type for padding failures to make error handling more explicit and type-safe.