Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions apps/type-benchmark/.attest/assertions/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"index.test.ts": [
{
"location": {
"start": {
"line": 114,
"char": 3
},
"end": {
"line": 114,
"char": 15
}
},
"args": [
{
"type": "() => Vec3f",
"relationships": {
"args": [
"equality"
],
"typeArgs": []
}
}
],
"typeArgs": [],
"errors": [],
"completions": {}
},
{
"location": {
"start": {
"line": 125,
"char": 3
},
"end": {
"line": 125,
"char": 17
}
},
"args": [
{
"type": "(a: Vec2f | Vec3f) => Vec2f | Vec3f",
"relationships": {
"args": [
"equality"
],
"typeArgs": []
}
}
],
"typeArgs": [],
"errors": [],
"completions": {}
},
{
"location": {
"start": {
"line": 116,
"char": 3
},
"end": {
"line": 116,
"char": 49
}
},
"count": 210
},
{
"location": {
"start": {
"line": 127,
"char": 3
},
"end": {
"line": 127,
"char": 49
}
},
"count": 200
}
]
}
82 changes: 82 additions & 0 deletions apps/type-benchmark/.attest/assertions/vanilla.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"index.test.ts": [
{
"location": {
"start": {
"line": 114,
"char": 3
},
"end": {
"line": 114,
"char": 15
}
},
"args": [
{
"type": "() => Vec3f",
"relationships": {
"args": [
"equality"
],
"typeArgs": []
}
}
],
"typeArgs": [],
"errors": [],
"completions": {}
},
{
"location": {
"start": {
"line": 125,
"char": 3
},
"end": {
"line": 125,
"char": 17
}
},
"args": [
{
"type": "(a: Vec2f | Vec3f) => Vec2f | Vec3f",
"relationships": {
"args": [
"equality"
],
"typeArgs": []
}
}
],
"typeArgs": [],
"errors": [],
"completions": {}
},
{
"location": {
"start": {
"line": 116,
"char": 3
},
"end": {
"line": 116,
"char": 49
}
},
"count": 210
},
{
"location": {
"start": {
"line": 127,
"char": 3
},
"end": {
"line": 127,
"char": 49
}
},
"count": 200
}
]
}
128 changes: 128 additions & 0 deletions apps/type-benchmark/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { attest } from "@ark/attest";
import { expect, test } from "vitest";

import { Operator } from 'tsover-runtime';

class Vec2f {
x: number;
y: number;

constructor(x: number, y: number) {
this.x = x;
this.y = y;
}

[Operator.plus](lhs: Vec2f, rhs: Vec2f): Vec2f {
return new Vec2f(lhs.x + rhs.x, lhs.y + rhs.y);
}

[Operator.star](lhs: Vec2f | number, rhs: Vec2f | number): Vec2f;
[Operator.star](
lhs: Vec2f | number,
rhs: Vec2f | number,
): Vec2f | typeof Operator.deferOperation {
if (typeof lhs === 'number' && rhs instanceof Vec2f) {
return new Vec2f(lhs * rhs.x, lhs * rhs.y);
} else if (typeof rhs === 'number' && lhs instanceof Vec2f) {
return new Vec2f(lhs.x * rhs, lhs.y * rhs);
} else if (lhs instanceof Vec2f && rhs instanceof Vec2f) {
return new Vec2f(lhs.x * rhs.x, lhs.y * rhs.y);
}
return Operator.deferOperation;
}

[Operator.starStar](lhs: Vec2f, rhs: Vec2f | number): Vec2f;
[Operator.starStar](lhs: Vec2f, rhs: Vec2f | number): Vec2f | typeof Operator.deferOperation {
if (!(lhs instanceof Vec2f)) {
return Operator.deferOperation;
}

if (typeof rhs === 'number') {
return new Vec2f(lhs.x ** rhs, lhs.y ** rhs);
} else if (rhs instanceof Vec2f) {
return new Vec2f(lhs.x ** rhs.x, lhs.y ** rhs.y);
}

return Operator.deferOperation;
}

[Operator.percent](lhs: Vec2f | number, rhs: Vec2f | number): Vec2f;
[Operator.percent](
lhs: Vec2f | number,
rhs: Vec2f | number,
): Vec2f | typeof Operator.deferOperation {
if (typeof lhs === 'number' && rhs instanceof Vec2f) {
return new Vec2f(lhs % rhs.x, lhs % rhs.y);
} else if (typeof rhs === 'number' && lhs instanceof Vec2f) {
return new Vec2f(lhs.x % rhs, lhs.y % rhs);
} else if (lhs instanceof Vec2f && rhs instanceof Vec2f) {
return new Vec2f(lhs.x % rhs.x, lhs.y % rhs.y);
}
return Operator.deferOperation;
}

toString(): string {
return `(${this.x}, ${this.y})`;
}
}

class Vec3f {
x: number;
y: number;
z: number;

constructor(x: number, y: number, z: number) {
this.x = x;
this.y = y;
this.z = z;
}

[Operator.plus](lhs: Vec3f, rhs: Vec3f): Vec3f {
return new Vec3f(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
}

[Operator.star](lhs: Vec3f | number, rhs: Vec3f | number): Vec3f;
[Operator.star](
lhs: Vec3f | number,
rhs: Vec3f | number,
): Vec3f | typeof Operator.deferOperation {
if (typeof lhs === 'number' && rhs instanceof Vec3f) {
return new Vec3f(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
} else if (typeof rhs === 'number' && lhs instanceof Vec3f) {
return new Vec3f(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs);
} else if (lhs instanceof Vec3f && rhs instanceof Vec3f) {
return new Vec3f(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z);
}
return Operator.deferOperation;
}

toString(): string {
return `(${this.x}, ${this.y})`;
}
}


test("bruh", () => {
function main() {
'use tsover';
const a = new Vec3f(1, 2, 2);
const b = new Vec3f(1, 2, 3);

return a + b * 54;
}

attest(main).type.toString.snap("() => Vec3f");

attest.instantiations([224, "instantiations"]);
});

test("bruh", () => {
function double(a: Vec3f | Vec2f) {
'use gpu';
return a * 2;
}

attest(double).type.toString.snap("(a: Vec2f | Vec3f) => Vec2f | Vec3f");

attest.instantiations([224, "instantiations"]);
});
17 changes: 17 additions & 0 deletions apps/type-benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "type-benchmark",
"version": "0.0.0",
"private": true,
"main": "index.js",
"scripts": {
"test": "pnpm --filter tsover build && vitest run",
"test:watch": "ATTEST_skipTypes=1 vitest run"
},
"dependencies": {
"@ark/attest": "^0.56.0",
"tsover-runtime": "workspace:^",
"typescript": "workspace:tsover@*",
"typescript-vanilla": "npm:typescript@6.0.3",
"vitest": "^4.0.18"
}
}
6 changes: 6 additions & 0 deletions apps/type-benchmark/setupVitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { setup } from "@ark/attest"

// config options can be passed here
export default () => setup({
tsVersions: ['default', 'vanilla'],
})
29 changes: 29 additions & 0 deletions apps/type-benchmark/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext", "tsover"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions apps/type-benchmark/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globalSetup: "./setupVitest.ts"
}
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"pnpm": {
"overrides": {
"fumadocs-twoslash>typescript": "workspace:tsover@*"
},
"patchedDependencies": {
"@ark/attest": "patches/@ark__attest.patch"
}
}
}
Loading