Skip to content

Type alias#337

Merged
arthurpaulino merged 6 commits intomainfrom
type-alias
Mar 19, 2026
Merged

Type alias#337
arthurpaulino merged 6 commits intomainfrom
type-alias

Conversation

@gabriel-barrett
Copy link
Member

Adds type aliases to Aiur, for example, U64 = [G; 8]

@gabriel-barrett gabriel-barrett force-pushed the type-alias branch 5 times, most recently from fb8b6f0 to 1cf0414 Compare March 19, 2026 15:41
Copy link
Member

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

Looking mostly good!

Besides my comments below, I should say that the files where the new U64 type has most value are the hash-related ones, Blake3.lean and Sha256.lean.

These U64s on the kernel types will be soon replaced by single Gs anyways.

Comment on lines +377 to +397
fn alias_basic(x: U8) -> U8 {
x + x
}

fn alias_array(x: U64) -> G {
x[0] + x[7]
}

fn alias_tuple(p: Pair) -> G {
let (a, b) = p;
a * b
}

fn alias_nested(x: U32) -> U8 {
let ((a, _), _) = x;
a
}

fn alias_in_struct() -> Pair {
(3, 4)
}
Copy link
Member

Choose a reason for hiding this comment

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

Can these tests be merged into a single one? They're so simple I'm not sure it's worth paying their costs. The thing is: type aliases are eliminated on the simplification+compilation phase and don't result on novel bytecode operators. In that sense, it should suffice to have an unified, bulkier, test exercising such type expansions.

Comment on lines +43 to +46
-- The first check happens on the original terms (but with expanded types).
decls.foldlM (init := ()) fun _ (_, decl) => match decl with
| .function f => do let _ ← (checkFunction f) (getFunctionContext f decls); pure ()
| _ => pure ()
Copy link
Member

Choose a reason for hiding this comment

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

This is now slightly more cryptic. Can it be simplified towards what we have on main?

Copy link
Member Author

@gabriel-barrett gabriel-barrett Mar 19, 2026

Choose a reason for hiding this comment

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

It used to check the toplevel functions, but the declarations hold the functions with expanded types. But HashMap does not have forM, so it looks slightly uglier. Plus, toplevel functions are separated, and declarations have other stuff like datatypes and constructors, that's why it has a match statement now

@gabriel-barrett gabriel-barrett force-pushed the type-alias branch 2 times, most recently from 394d79c to 93c030c Compare March 19, 2026 18:23
gabriel-barrett and others added 6 commits March 19, 2026 19:38
Add IndexMap.forM and use it in checkAndSimplify for cleaner iteration
over declarations when only side effects (type-checking) are needed.
@arthurpaulino arthurpaulino merged commit 830ed7c into main Mar 19, 2026
14 checks passed
@arthurpaulino arthurpaulino deleted the type-alias branch March 19, 2026 23:50
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