Skip to content

Luau Implementation #12

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ed8a98a
updated docs with Luau setup info :eyes:
dibrinsofor Jan 23, 2025
3b84dbc
init Luau dir, copied over datasheet
dibrinsofor Jan 23, 2025
6286569
luau benchmark :fire:
dibrinsofor Feb 4, 2025
0b6e139
updated docs, attempt to mod rkt script
dibrinsofor Feb 4, 2025
ddb23b0
typo benchmark fix
dibrinsofor Feb 5, 2025
d6b2b4f
modded script to include Luau
dibrinsofor Feb 9, 2025
50fb6e0
updated Luau benchmark, removed inexpressible bits
dibrinsofor Feb 9, 2025
5082311
modded script to include Luau
dibrinsofor Feb 9, 2025
5b1d99d
updated datasheet
dibrinsofor Feb 11, 2025
2618f09
removed inexpressible code samples
dibrinsofor Feb 11, 2025
3d0926c
removed merge messages
dibrinsofor Feb 11, 2025
3efef30
add `--- Code: ` line to Luau code
hanwenguo Feb 11, 2025
2e00579
undo linting
dibrinsofor Feb 12, 2025
0f9917e
undo linting
dibrinsofor Feb 12, 2025
7cbaa13
updated table with Luau info
dibrinsofor Feb 12, 2025
fca979d
updated table with Luau info
dibrinsofor Feb 12, 2025
ab2995b
undo lint
dibrinsofor Feb 12, 2025
957286e
fixed bench names
dibrinsofor Feb 12, 2025
a2fd4cb
code(main.rkt): update alist for luau
hanwenguo Feb 12, 2025
1cf0bc3
fix format nits
dibrinsofor Feb 13, 2025
4fd8bac
pr suggestions
dibrinsofor Feb 25, 2025
67cec98
more nits, fixed bad encoding, updated README with type function info
dibrinsofor Mar 2, 2025
00d49ec
updated benchmark table, tuples pass nesting fails
dibrinsofor Mar 2, 2025
c6dd1d9
reverting to not operator
dibrinsofor Mar 2, 2025
da09d05
updated docs with not, and _ operators
dibrinsofor Mar 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Luau/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Luau

Luau is a typed-sister variant of Lua (it breaks backwards compatibility after
v5.1).

- Language resources:
- <https://www.luau.org/>
- <https://github.com/luau-lang/luau/>
- If-T version: **1.0**
- Implementation: [main.luau](main.luau)

#### Type System Basics

> Q. What is the top type in this language? What is the bottom type? What is the
> dynamic type? If these types do not exist, explain the alternatives.

- Top = `unknown`
- Bottom = `never`
- Dynamic = `any`

> Q. What base types does this implementation use? Why?

It uses `string`,`number` and `boolean`.

> Q. What container types does this implementation use (for objects, tuples,
> etc)? Why?

A Table in Luau is the base data structure for constructing complex objects or
organizing data. This implementation adopts `tables` for Lists, Structs and to
construct aliases for `Pairs` and `Tuples`.

#### Type Narrowing

> Q. How do simple type tests work in this language?

Example: `typeof(x) == "number"`

> Q. Are there other forms of type test? If so, explain.

Yes, It also supports `IsA` and `is` for instance refinements. Assertions
(`assert`) can also trigger type refinement.

Example: `local x = Instance.new(Part); x:IsA("BasePart"); x:is("string")`\
Example: `assert(type(stringOrNumber) == "string")`

> Q. How do type casts work in this language?

Type casts are done with the double colon (`::`) syntax.

Example: `x::number`

> Q. What is the syntax for a symmetric (2-way) type-narrowing predicate?

Luau does not supports these predicates yet.

> Q. If the language supports other type-narrowing predicates, describe them
> below.

#### Benchmark Details

> Q. Are any benchmarks inexpressible? Why?

Luau is unable to express the type-narrowing predicate examples. The new solver
supports
[type functions](https://rfcs.luau.org/user-defined-type-functions.html), which
should be ideal for implementing this, however, parameters are not allowed to be
referenced in the return type.

```
type function isString(T)
return types.singleton(T:is("string"))
end

-- luau flags both instances of x in the signature as being in different scopes
function predicate_2way_success_f(x: string | number): isString<x>
return typeof(x) == "string"
end
```

> Q. Are any benchmarks expressed particularly well, or particularly poorly?
> Explain.

```
define f(x: String | Number | Boolean) -> x is String:
return x is String
```

Since Luau, does not currently provide a direct way to connect a function
parameter to its returned type information in this manner, all the related
examples (`predicate_checked`, `predicate_1way` and `predicate_2way`) are
currently inexpressible.

> Q. How direct (or complex) is the implementation compared to the pseudocode
> from If-T?

Very similar. Luau has some special syntax to get the length of some sequence or
iterable. Other notable mentions are `~=` for the not operator and `_` as a
prefix to silence warnings to unused definitions.

Example: `#x`

It also supports special syntax for string concatenation.

Example: `"Hello" .. "World"`

#### Advanced Examples

> Q. Are any examples inexpressible? Why?

No.

> Q. Are any examples expressed particularly well, or particularly poorly?
> Explain.

No.

> Q. How direct (or complex) is the implementation compared to the pseudocode
> from If-T?

Very similar.
Loading