mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Bit more draft RFC about type normalization
This commit is contained in:
parent
bfe07ac261
commit
14a5ec4ca7
1 changed files with 10 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
Normalize types, for example removing redundant unions and
|
We should normalize types, for example removing redundant unions and
|
||||||
intersections, to minimize memory usage and make user-visible inferred
|
intersections, to minimize memory usage and make user-visible inferred
|
||||||
types easier to read.
|
types easier to read.
|
||||||
|
|
||||||
|
@ -59,7 +59,9 @@ or `Animal&Cat`.
|
||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
In this section, we outline a number of possible designs. These fall into two broad camps: syntactic subtyping uses rewrite rules on the syntax of types, whereas semantic subtyping uses semantic models of types.
|
In this section, we outline some possible designs. These fall into two
|
||||||
|
broad camps: syntactic subtyping uses rewrite rules on the syntax of
|
||||||
|
types, whereas semantic subtyping uses semantic models of types.
|
||||||
|
|
||||||
### Syntactic subtyping
|
### Syntactic subtyping
|
||||||
|
|
||||||
|
@ -74,6 +76,8 @@ Advantages: easy to implement; fast.
|
||||||
Disadvantage: pointer equality is a very brittle test; it is easy to still get
|
Disadvantage: pointer equality is a very brittle test; it is easy to still get
|
||||||
types `T|T`, caused by having two clones of `T`.
|
types `T|T`, caused by having two clones of `T`.
|
||||||
|
|
||||||
|
This is currently what we do.
|
||||||
|
|
||||||
#### Alternative: check for suptyping before adding to a union/intersection
|
#### Alternative: check for suptyping before adding to a union/intersection
|
||||||
|
|
||||||
Ditto, but don't add a type if there's already a supertype in the
|
Ditto, but don't add a type if there's already a supertype in the
|
||||||
|
@ -161,6 +165,10 @@ Tree automata have:
|
||||||
|
|
||||||
(Luau has namned properties rather than positional arguments, but otherwise this is standard).
|
(Luau has namned properties rather than positional arguments, but otherwise this is standard).
|
||||||
|
|
||||||
|
An automaton accepts a tree if its initial state does. A state `q` accepts a tree `t`
|
||||||
|
if there is a transition `q0 -> f(p1 = q1, ..., pN = qN)` where `t` has node label `f`,
|
||||||
|
and children `t -p1-> t1`,..., `t -pN-> tN` where each `qI` accepts `tI`.
|
||||||
|
|
||||||
Draw automata where the transition `q0 -> f(p1 = q1, ..., pN = qN)` as
|
Draw automata where the transition `q0 -> f(p1 = q1, ..., pN = qN)` as
|
||||||
```
|
```
|
||||||
◇
|
◇
|
||||||
|
|
Loading…
Add table
Reference in a new issue