Skip to content

Commit

Permalink
reintegrate implicit discrimination, begin updating docs, bugfixes (#965
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ssalbdivad authored May 22, 2024
1 parent 2633783 commit 6e39e69
Show file tree
Hide file tree
Showing 75 changed files with 1,425 additions and 1,059 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// too many overlapping names, easy to import in schema/arktype where we don't want it
// should just import as * as ts when we need it in attest
"typescript",
"./ark/type/api.ts",
"./ark/schema/api.ts"
"./ark/type/api.ts"
// "./ark/schema/api.ts"
],
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
// IF YOU UPDATE THE MOCHA CONFIG HERE, PLEASE ALSO UPDATE package.json/mocha AND ark/repo/mocha.jsonc
Expand Down
30 changes: 12 additions & 18 deletions ark/attest/__tests__/benchExpectedOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,39 @@ const fakeCallOptions = {

bench(
"bench call single stat median",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).median([2, "ms"])

bench(
"bench call single stat",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).mean([2, "ms"])

bench(
"bench call mark",
() => {
return /.*foo.*/.test("boofoozoo")
},
() => /.*foo.*/.test("boofoozoo"),
fakeCallOptions
).mark({ mean: [2, "ms"], median: [2, "ms"] })

type makeComplexType<S extends string> =
S extends `${infer head}${infer tail}` ? head | tail | makeComplexType<tail>
: S

bench("bench type", () => {
return {} as makeComplexType<"defenestration">
}).types([176, "instantiations"])
bench("bench type", () => ({}) as makeComplexType<"defenestration">).types([
176,
"instantiations"
])

bench("bench type from external module", () => {
return {} as externalmakeComplexType<"defenestration">
}).types([193, "instantiations"])
bench(
"bench type from external module",
() => ({}) as externalmakeComplexType<"defenestration">
).types([193, "instantiations"])

bench(
"bench call and type",
() => {
return {} as makeComplexType<"antidisestablishmentarianism">
},
() => ({}) as makeComplexType<"antidisestablishmentarianism">,
fakeCallOptions
)
.mean([2, "ms"])
Expand Down
27 changes: 9 additions & 18 deletions ark/attest/__tests__/benchTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,36 @@ const fakeCallOptions = {

bench(
"bench call single stat median",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).median()

bench(
"bench call single stat",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).mean()

bench(
"bench call mark",
() => {
return /.*foo.*/.test("boofoozoo")
},
() => /.*foo.*/.test("boofoozoo"),
fakeCallOptions
).mark()

type makeComplexType<S extends string> =
S extends `${infer head}${infer tail}` ? head | tail | makeComplexType<tail>
: S

bench("bench type", () => {
return {} as makeComplexType<"defenestration">
}).types()
bench("bench type", () => ({}) as makeComplexType<"defenestration">).types()

bench("bench type from external module", () => {
return {} as externalmakeComplexType<"defenestration">
}).types()
bench(
"bench type from external module",
() => ({}) as externalmakeComplexType<"defenestration">
).types()

bench(
"bench call and type",
() => {
return {} as makeComplexType<"antidisestablishmentarianism">
},
() => ({}) as makeComplexType<"antidisestablishmentarianism">,
fakeCallOptions
)
.mean()
Expand Down
7 changes: 3 additions & 4 deletions ark/attest/bench/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,13 @@ export const getBenchCtx = (
qualifiedPath: string[],
isAsync: boolean = false,
options: BenchOptions = {}
): BenchContext => {
return {
): BenchContext =>
({
qualifiedPath,
qualifiedName: qualifiedPath.join("/"),
options,
cfg: getConfig(),
benchCallPosition: caller(),
lastSnapCallPosition: undefined,
isAsync
} as BenchContext
}
}) as BenchContext
10 changes: 4 additions & 6 deletions ark/attest/bench/measure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ export type TypeUnit = (typeof TYPE_UNITS)[number]
export const createTypeComparison = (
value: number,
baseline: Measure<TypeUnit> | undefined
): MeasureComparison<TypeUnit> => {
return {
updated: [value, "instantiations"],
baseline
}
}
): MeasureComparison<TypeUnit> => ({
updated: [value, "instantiations"],
baseline
})

export const timeUnitRatios = {
ns: 0.000_001,
Expand Down
6 changes: 3 additions & 3 deletions ark/attest/cache/getCachedAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ const getAssertionsOfKindAtPosition = <kind extends TypeAssertionKind>(
`Found no assertion data for '${fileKey}' for TypeScript version ${version}.`
)
}
const matchingAssertion = assertions[fileKey].find(assertion => {
const matchingAssertion = assertions[fileKey].find(assertion =>
/**
* Depending on the environment, a trace can refer to any of these points
* attest(...)
* ^ ^ ^
* Because of this, it's safest to check if the call came from anywhere in the expected range.
*
*/
return isPositionWithinRange(position, assertion.location)
})
isPositionWithinRange(position, assertion.location)
)
if (!matchingAssertion) {
throw new Error(
`Found no assertion for TypeScript version ${version} at line ${position.line} char ${position.char} in '${fileKey}'.
Expand Down
8 changes: 6 additions & 2 deletions ark/attest/cache/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export class TsServer {

const tsLibPaths = getTsLibFiles(tsConfigInfo.parsed.options)

// TS represents windows paths as `C:/Users/ssalb/...`
const normalizedCwd = fromCwd().replaceAll(/\\/g, "/")

this.rootFiles = tsConfigInfo.parsed.fileNames.filter(path =>
path.startsWith(fromCwd())
path.startsWith(normalizedCwd)
)

const system = tsvfs.createFSBackedSystem(
Expand All @@ -41,7 +44,8 @@ export class TsServer {
}

getSourceFileOrThrow(path: string): ts.SourceFile {
const file = this.virtualEnv.getSourceFile(path)
const tsPath = path.replaceAll(/\\/g, "/")
const file = this.virtualEnv.getSourceFile(tsPath)
if (!file) throw new Error(`Could not find ${path}.`)

return file
Expand Down
34 changes: 15 additions & 19 deletions ark/attest/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,21 @@ type BaseAttestConfig = {

export type AttestConfig = Partial<BaseAttestConfig>

export const getDefaultAttestConfig = (): BaseAttestConfig => {
return {
tsconfig:
existsSync(fromCwd("tsconfig.json")) ?
fromCwd("tsconfig.json")
: undefined,
attestAliases: ["attest", "attestInternal"],
updateSnapshots: false,
skipTypes: false,
skipInlineInstantiations: false,
tsVersions: "typescript",
benchPercentThreshold: 20,
benchErrorOnThresholdExceeded: false,
filter: undefined,
testDeclarationAliases: ["bench", "it"],
formatter: `npm exec --no -- prettier --write`,
shouldFormat: true
}
}
export const getDefaultAttestConfig = (): BaseAttestConfig => ({
tsconfig:
existsSync(fromCwd("tsconfig.json")) ? fromCwd("tsconfig.json") : undefined,
attestAliases: ["attest", "attestInternal"],
updateSnapshots: false,
skipTypes: false,
skipInlineInstantiations: false,
tsVersions: "typescript",
benchPercentThreshold: 20,
benchErrorOnThresholdExceeded: false,
filter: undefined,
testDeclarationAliases: ["bench", "it"],
formatter: `npm exec --no -- prettier --write`,
shouldFormat: true
})

const hasFlag = (flag: keyof AttestConfig) =>
process.argv.some(arg => arg.includes(flag))
Expand Down
2 changes: 1 addition & 1 deletion ark/attest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"out"
],
"bin": {
"attest": "./out/cli/cli.js"
"attest": "out/cli/cli.js"
},
"scripts": {
"build": "tsx ../repo/build.ts",
Expand Down
45 changes: 23 additions & 22 deletions ark/dark/color-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,50 @@
"name": "functions",
"scope": [
"entity.name.function",
"meta.function-call",
"support.function",
"meta.function-call.python",
// We have this for Python in honor of contributor TizzySaurus.
// Will be removed for consistency once they allow it or the next time someone complains about it.
"meta.function.decorator punctuation",
"meta.function.decorator support.type"
],
"settings": {
"foreground": "#80cff8"
"foreground": "#80cff8",
"fontStyle": "italic"
}
},
{
"name": "types",
"scope": ["entity.name.type"],
"name": "types and decorators",
"scope": ["entity.name.type", "meta.decorator.ts variable"],
"settings": {
"foreground": "#40decc"
}
},
{
"name": "keywords and operators",
"scope": [
"keyword",
"storage",
"punctuation",
"constant.character.escape"
],
"scope": ["meta.type.declaration.ts entity.name.type"],
"settings": {
"foreground": "#eb9f2e"
"foreground": "#80cff8",
"fontStyle": "italic"
}
},
{
"name": "italics",
// italicize keywords that are not punctuation/symbols
"scope": ["keyword", "storage", "keyword.operator.expression"],
"scope": [
"meta.type.declaration.ts meta.type.parameters.ts entity.name.type"
],
"settings": {
"fontStyle": "italic"
"fontStyle": ""
}
},
{
"name": "unitalicized",
"scope": ["keyword.operator", "storage.type.function.arrow.ts"],
"name": "keywords and operators",
"scope": [
"keyword",
"storage",
"punctuation",
"constant.character.escape"
],
"settings": {
"fontStyle": ""
"foreground": "#ba7e41"
}
},
{
Expand Down Expand Up @@ -116,9 +117,9 @@
"list.errorForeground": "#9558f8",
"editorOverviewRuler.errorForeground": "#9558f8",
"editorBracketHighlight.foreground1": "#f5cf8f",
"editorBracketHighlight.foreground2": "#eb9f2e",
"editorBracketHighlight.foreground3": "#f5cf8f",
"editorBracketHighlight.unexpectedBracket.foreground": "#eb9f2e",
"editorBracketHighlight.foreground2": "#ba7e41",
"editorBracketHighlight.foreground3": "#eb9f2e",
"editorBracketHighlight.unexpectedBracket.foreground": "#ba7e41",
"editorCursor.foreground": "#408fde",
"terminalCursor.foreground": "#408fde",
"editorCodeLens.foreground": "#00ccff60",
Expand Down
2 changes: 1 addition & 1 deletion ark/dark/injected.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"repository": {
"arkDefinition": {
"contentName": "meta.embedded.arktype.definition",
"begin": "(([^\\)\\(\\s]*)?((\\.)?(type|scope|define|match|attest)|(\\.)(morph|and|or|when)))\\(",
"begin": "(([^\\)\\(\\s]*)?((\\.)?(type|scope|define|match|fn)|(\\.)(morph|and|or|when)))\\(",
"beginCaptures": {
"1": {
"name": "entity.name.function.ts"
Expand Down
2 changes: 1 addition & 1 deletion ark/dark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "arkdark",
"displayName": "ArkDark",
"description": "ArkType syntax highlighting and theme⛵",
"version": "5.0.2",
"version": "5.1.3",
"publisher": "arktypeio",
"type": "module",
"scripts": {
Expand Down
Binary file added ark/dark/theme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ark/dark/tsWithArkType.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"repository": {
"arkDefinition": {
"contentName": "meta.embedded.arktype.definition",
"begin": "(([^\\)\\(\\s]*)?((\\.)?(type|scope|define|match|attest)|(\\.)(morph|and|or|when)))\\(",
"begin": "(([^\\)\\(\\s]*)?((\\.)?(type|scope|define|match|fn)|(\\.)(morph|and|or|when)))\\(",
"beginCaptures": {
"1": {
"name": "entity.name.function.ts"
Expand Down
21 changes: 10 additions & 11 deletions ark/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
},
"dependencies": {
"@arktype/util": "workspace:*",
"@astrojs/starlight": "0.21.1",
"@astrojs/react": "3.0.10",
"@astrojs/starlight": "0.23.0",
"@astrojs/react": "3.3.4",
"@monaco-editor/react": "4.6.0",
"monaco-editor": "0.47.0",
"monaco-editor": "0.48.0",
"monaco-textmate": "3.0.1",
"monaco-editor-textmate": "4.0.0",
"onigasm": "2.2.5",
"@stackblitz/sdk": "1.9.0",
"astro": "4.4.15",
"sharp": "0.33.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"framer-motion": "11.0.8"
"astro": "4.8.6",
"sharp": "0.33.4",
"react": "18.3.1",
"react-dom": "18.3.1",
"framer-motion": "11.2.4"
},
"devDependencies": {
"@types/react": "18.2.64",
"@types/react-dom": "18.2.21"
"@types/react": "18.3.2",
"@types/react-dom": "18.3.0"
}
}
Binary file added ark/docs/src/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6e39e69

Please sign in to comment.