Skip to content

Commit

Permalink
Fixes to assignments, added FinalEvents + other tidy ups
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Jan 1, 2024
1 parent c8790bb commit 8b038cd
Show file tree
Hide file tree
Showing 45 changed files with 685 additions and 477 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/performance-and-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ jobs:
# Generate a file which contains everything that Ezno currently implements
cargo run -p ezno-parser --example code_blocks_to_script ./checker/specification/specification.md demo.ts
echo "### Checking">> $GITHUB_STEP_SUMMARY
echo "\`\`\`ts">> $GITHUB_STEP_SUMMARY
echo "<details><summary>Input</summary>\`\`\`ts" >> $GITHUB_STEP_SUMMARY
cat demo.ts >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "### Output">> $GITHUB_STEP_SUMMARY
echo "\`\`\`shell">> $GITHUB_STEP_SUMMARY
./target/release/ezno check demo.ts >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`</details>" >> $GITHUB_STEP_SUMMARY
echo "<details><summary>Diagnostics</summary>\`\`\`shell" >> $GITHUB_STEP_SUMMARY
./target/release/ezno check demo.ts &>> $GITHUB_STEP_SUMMARY
echo "\`\`\`</details>" >> $GITHUB_STEP_SUMMARY
echo "### Performance">> $GITHUB_STEP_SUMMARY
echo "\`\`\`shell">> $GITHUB_STEP_SUMMARY
echo "### Checking" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`shell" >> $GITHUB_STEP_SUMMARY
hyperfine './target/release/ezno check demo.ts' >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
Expand Down
1 change: 1 addition & 0 deletions checker/examples/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn main() {
}
},
None,
(),
);

let args: Vec<_> = env::args().collect();
Expand Down
129 changes: 126 additions & 3 deletions checker/specification/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const b: string = a
```ts
let a = 2
a = "not a number"
let b: number = a
let b: boolean = a
```

- Type "not a number" is not assignable to type number
- Type "not a number" is not assignable to type boolean

#### Variable references does not exist

Expand Down Expand Up @@ -222,6 +222,20 @@ const x: (a: string) => number = a => a.to;

- No property 'to' on string

#### Assignment to parameter

```ts
function alterParameter(a: number, b: { prop: string }) {
a = 2;
a = "hi";
b.prop = 6;
}
```

> Assigning straight to `a` might be disallowed by an option in the future. Right now it is allowed by JavaScript and so is allowed
- Type \"hi\" is not assignable to type number

### Function calling

#### Argument type against parameter
Expand Down Expand Up @@ -420,7 +434,8 @@ value.getValue() satisfies 6
let a: number = 0
function func() {
a = 4;
// Important that subsequent reads use the new value, not the same free variable
// Important that subsequent reads use the
// new value, not the same free variable
a satisfies 4;
}

Expand Down Expand Up @@ -529,6 +544,20 @@ setAtoString(myObject);
- Assignment mismatch

#### Property assignment from conditional

```ts
function getObject(condition: boolean) {
const mainObject = { a: 2 };
const object = condition ? mainObject : { b: 3 };
object.c = 4;
mainObject.c satisfies string;
return mainObject
}
```

- Expected string, found 4

#### Mutating an object by a function

> This is where the object loses its constant-ness
Expand Down Expand Up @@ -979,6 +1008,20 @@ while (a < i) {

> Important that type is widened to 'number' (think it is an open poly in this case)
#### Limit to iterations

```ts
let a: number = 0;
while (a++ < 1_000_000) {}

a satisfies string;
```

> The important part is that it doesn't run the loop. Eventually this might be run in a way that is not calling the assign to variable
> function that evaluates `a = a + 1` a million times. There also should be per project, per module, per loop configuration
- Expected string, found number

#### While loop unrolling as an effect

```ts
Expand Down Expand Up @@ -1013,6 +1056,29 @@ while (i++ < 10) {

- Expected 2, found 8

#### Break with label

```ts
let a: number = 0;
let result;

top: while (a++ < 10) {
let b: number = 0;
while (b++ < 10) {
if (a === 3 && b === 2) {
result = a * b;
break top
}
}
}

a satisfies string;
result satisfies boolean;
```

- Expected string, found 3
- Expected boolean, found 6

#### Continue in a while loop

> With the continue the update to `a` only happens on even runs (5 times)
Expand Down Expand Up @@ -1089,6 +1155,35 @@ interface X {
- Expected 4, found 5
- Type { a: 3 } is not assignable to type X

#### RegExp

> RegExp = Regular expression
> In the future, their definition could be considered and evaluated at runtime
```ts
/hi/ satisfies string;
```

- Expected string, found /hi/

#### Null and undefined

```ts
undefined satisfies null;
null satisfies undefined;
```

- Expected null, found undefined
- Expected undefined, found null

#### void operator

```ts
(void 2) satisfies string;
```

- Expected string, found undefined

#### (untagged) Template literal

```ts
Expand Down Expand Up @@ -1437,6 +1532,34 @@ const y: (a: number | string) => string = (p: number) => "hi"

> I think reasons contains more information
#### Function return type subtyping

```ts
const x: (a: number) => number = p => 4
const y: (a: number) => number = p => "a number"
```

- Type (p: number) => "a number" is not assignable to type (a: number) => number

#### `void` return type

> This works similarly to undefined except that it accepts any function return type
```ts
function runWithCallback(cb: () => void): void {
cb() satisfies string;

return 5;
}

runWithCallback(() => 3)
```

> Here argument is fine. In the body the return type is `any` (inferred constraint, but doesn't matter)
- Expected string, found any
- Cannot return 5 because the function is expected to return void

#### Indexing into (fixed) type

```ts
Expand Down
105 changes: 13 additions & 92 deletions checker/specification/staging.md
Original file line number Diff line number Diff line change
@@ -1,96 +1,5 @@
Currently implementing:

### Iterations

#### Limit to iterations

```ts
let a: number = 0;
while (a++ < 1_000_000) {}

a satisfies string;
```

> The important part is that it doesn't run the loop. Eventually this might be run in a way that is not calling the assign to variable
> function that evaluates `a = a + 1` a million times. There also should be per project, per module, per loop configuration
- Expected string, found number

### Functions

#### Assignment to parameter

```ts
function alterParameter(a: number, b: { prop: string }) {
a = 2;
a = "hi";
b.prop = 6;
}
```

> Assigning straight to `a` might be disallowed by an option in the future. Right now it is allowed by JavaScript and so is allowed
- Type \"hi\" is not assignable to type number

### Statements

#### RegExp

> RegExp = Regular expression
> In the future, their definition could be considered and evaluated at runtime
```ts
/hi/ satisfies string;
```

- Expected string, found /hi/

#### Null and undefined

```ts
undefined satisfies null;
null satisfies undefined;
```

- Expected null, found undefined
- Expected undefined, found null

#### void operator

```ts
(void 2) satisfies string;
```

- Expected string, found undefined

#### Function return type subtyping

```ts
const x: (a: number) => number = p => 4
const y: (a: number) => number = p => "a number"
```

- Type (p: number) => "a number" is not assignable to type (a: number) => number

#### void return type

> This works similarly to undefined except that it accepts any function return type
```ts
function runWithCallback(cb: () => void): void {
cb() satisfies string;

return 5;
}

runWithCallback(() => 3)
```

> Here argument is fine. In the body the return type is `any` (inferred constraint, but doesn't matter)
- Expected string, found any
- Cannot return 5 because the function is expected to return void

### Not sure

#### Set property on dependent observed
Expand All @@ -110,7 +19,7 @@ function add_property(obj: { prop: number }) {

#### Constant call and operation with a parameter

> An example of the generic constructor type (namely call and operation)
> An example of the generic constructor type (namely call and operation)
```ts
function floorPlusB(a: number, b: number) {
Expand All @@ -121,3 +30,15 @@ floorPlusB(100.22, 5) satisfies 8
```

- Expected 8, found 105

#### Calling new on a function

```ts
function MyClass(value) {
this.value = value
}

new MyClass("hi").value satisfies "hello"
```

- Expected "hello", found "hi"
1 change: 1 addition & 0 deletions checker/specification/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn check_errors(
}
},
type_check_options,
(),
);
// });

Expand Down
12 changes: 0 additions & 12 deletions checker/specification/to_implement.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,6 @@ join(["a", "b", "c"]) satisfies "cba"

### This

#### Calling new on a function

```ts
function MyClass(value) {
this.value = value
}

new MyClass("hi").value satisfies "hello"
```

- Expected "hello", found "hi"

#### Bind function

```ts
Expand Down
Loading

0 comments on commit 8b038cd

Please sign in to comment.