improve type inferencing + fix bug in CallBlock suggestion priorities
This commit is contained in:
parent
24689b3783
commit
c45f19143b
6 changed files with 156 additions and 765 deletions
|
|
@ -17,11 +17,11 @@
|
||||||
"react-dom": "^19.1.0"
|
"react-dom": "^19.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.26.0",
|
"@eslint/js": "^9.27.0",
|
||||||
"@types/react": "^19.1.4",
|
"@types/react": "^19.1.4",
|
||||||
"@types/react-dom": "^19.1.5",
|
"@types/react-dom": "^19.1.5",
|
||||||
"@vitejs/plugin-react-swc": "^3.9.0",
|
"@vitejs/plugin-react-swc": "^3.9.0",
|
||||||
"eslint": "^9.26.0",
|
"eslint": "^9.27.0",
|
||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.20",
|
"eslint-plugin-react-refresh": "^0.4.20",
|
||||||
"globals": "^16.1.0",
|
"globals": "^16.1.0",
|
||||||
|
|
|
||||||
887
pnpm-lock.yaml
generated
887
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -79,7 +79,7 @@ function FunctionHeader({ state, setState, suggestionPriority }) {
|
||||||
setState={setFn}
|
setState={setFn}
|
||||||
suggestionPriority={(fnSuggestion: ResolvedType) => computePriority(
|
suggestionPriority={(fnSuggestion: ResolvedType) => computePriority(
|
||||||
fnSuggestion,
|
fnSuggestion,
|
||||||
evalEditorBlock(state.fn.input, env),
|
evalEditorBlock(state.input, env),
|
||||||
suggestionPriority,
|
suggestionPriority,
|
||||||
env,
|
env,
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*:hover:not(:has(> *:hover)) {
|
||||||
|
/* useful for debugging: */
|
||||||
|
/* border-width: 2px !important; */
|
||||||
|
}
|
||||||
|
|
||||||
.offending .error {
|
.offending .error {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ const computeSuggestions = (text, env, suggestionPriority: (s: ResolvedType) =>
|
||||||
}]),
|
}]),
|
||||||
]
|
]
|
||||||
// return ls;
|
// return ls;
|
||||||
|
// return [];
|
||||||
return ls
|
return ls
|
||||||
.map(suggestion => [suggestionPriority(suggestion[2]), ...suggestion] as PrioritizedSuggestionType)
|
.map(suggestion => [suggestionPriority(suggestion[2]), ...suggestion] as PrioritizedSuggestionType)
|
||||||
.sort(([priorityA], [priorityB]) => priorityB - priorityA)
|
.sort(([priorityA], [priorityB]) => priorityB - priorityA)
|
||||||
|
|
|
||||||
22
src/eval.ts
22
src/eval.ts
|
|
@ -97,11 +97,11 @@ export function evalCallBlock2(fnResolved: ResolvedType, inputResolved: Resolved
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// fn is a function...
|
// fn is a function...
|
||||||
const [outType, substitutions] = assignFnSubstitutions(fnResolved.t, inputResolved.t); // may throw
|
const [_inType, inSubst, outType, _outSubst] = assignFnSubstitutions(fnResolved.t, inputResolved.t, getUnusedTypeVarIdx(env)); // may throw
|
||||||
|
|
||||||
// console.log('assignFn...', prettyT(fnResolved.t), inputResolved.i, prettyT(inputResolved.t), '\nout =', prettyT(outType), substitutions);
|
// console.log('assignFn...', 'fn.t:', prettyT(fnResolved.t), 'input:', inputResolved, 'input.t:', prettyT(inputResolved.t), '\nout =', prettyT(outType), 'subst:', substitutions, substitutions.size);
|
||||||
|
|
||||||
const mergedSubstitutions = mergeMaps(substitutions, fnResolved.substitutions, inputResolved.substitutions);
|
const mergedSubstitutions = mergeMaps(inSubst, fnResolved.substitutions, inputResolved.substitutions);
|
||||||
|
|
||||||
if (inputResolved.kind === "error") {
|
if (inputResolved.kind === "error") {
|
||||||
return {
|
return {
|
||||||
|
|
@ -171,14 +171,18 @@ export function evalLetInBlock(value: EditorState, name: string, inner: EditorSt
|
||||||
return evalEditorBlock(inner, innerEnv);
|
return evalEditorBlock(inner, innerEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUnusedTypeVar(env) {
|
function getUnusedTypeVarIdx(env) {
|
||||||
for (let i=0; ; i++) {
|
for (let i=0; ; i++) {
|
||||||
if (!dict.has(env.typeDict)(TYPE_VARS[i])) {
|
if (!dict.has(env.typeDict)(TYPE_VARS[i])) {
|
||||||
return TYPE_VARS[i];
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUnusedTypeVar(env) {
|
||||||
|
return TYPE_VARS[getUnusedTypeVarIdx(env)];
|
||||||
|
}
|
||||||
|
|
||||||
export function evalLambdaBlock(paramName: string, expr: EditorState, env): ResolvedType {
|
export function evalLambdaBlock(paramName: string, expr: EditorState, env): ResolvedType {
|
||||||
const paramType = getUnusedTypeVar(env);
|
const paramType = getUnusedTypeVar(env);
|
||||||
// static env: we only know the name and the type
|
// static env: we only know the name and the type
|
||||||
|
|
@ -187,11 +191,6 @@ export function evalLambdaBlock(paramName: string, expr: EditorState, env): Reso
|
||||||
t: paramType,
|
t: paramType,
|
||||||
substitutions: new Map(),
|
substitutions: new Map(),
|
||||||
})
|
})
|
||||||
// const staticInnerEnv = makeInnerEnv(env, paramName, {
|
|
||||||
// kind: "unknown", // parameter value is not statically known
|
|
||||||
// t: paramType,
|
|
||||||
// substitutions: new Map(),
|
|
||||||
// });
|
|
||||||
const exprResolved = evalEditorBlock(expr, staticInnerEnv);
|
const exprResolved = evalEditorBlock(expr, staticInnerEnv);
|
||||||
const lambdaT = fnType(_ => paramType)(_ => exprResolved.t);
|
const lambdaT = fnType(_ => paramType)(_ => exprResolved.t);
|
||||||
const lambdaTSubstituted = substitute(lambdaT, exprResolved.substitutions, []);
|
const lambdaTSubstituted = substitute(lambdaT, exprResolved.substitutions, []);
|
||||||
|
|
@ -202,7 +201,8 @@ export function evalLambdaBlock(paramName: string, expr: EditorState, env): Reso
|
||||||
t: lambdaTSubstituted,
|
t: lambdaTSubstituted,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
e: exprResolved.e,
|
e: exprResolved.e,
|
||||||
substitutions: staticInnerEnv.substitutions,
|
// substitutions: new Map(),
|
||||||
|
substitutions: exprResolved.substitutions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const paramTypeSubstituted = lambdaTSubstituted.params[0](lambdaTSubstituted);
|
const paramTypeSubstituted = lambdaTSubstituted.params[0](lambdaTSubstituted);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue