minor cleanup

This commit is contained in:
nora 2023-08-03 14:47:21 +02:00
parent ba3a199249
commit cc04638f1e
16 changed files with 22 additions and 21 deletions

View file

@ -8,7 +8,7 @@
"build": "tsc",
"fmt": "prettier -w .",
"test": "jest",
"ui-test": "npm run build && cargo run --manifest-path ui-tests/Cargo.toml --bin ui-tests",
"ui-test": "npm run build && cargo run --manifest-path ui-harness/Cargo.toml --bin ui-tests",
"lint": "eslint ."
},
"author": "",

View file

@ -225,8 +225,12 @@ export type ExprPath = {
segments: string[];
/**
* Since this only exists after resolve, we always have a res.
* The nested field is for symmetry with Ident.
*/
res: Resolution;
value: {
res: Resolution;
span: Span;
};
};
export type ExprBinary<P extends Phase> = {
@ -505,7 +509,7 @@ export type TyVar = {
export type TyStruct = {
kind: "struct";
itemId: ItemId,
itemId: ItemId;
_name: string;
fields: [string, Ty][];
};

View file

@ -428,7 +428,7 @@ function lowerExpr(
switch (lhs.kind) {
case "ident":
case "path": {
const res = lhs.kind === "path" ? lhs.res : lhs.value.res;
const { res } = lhs.value;
switch (res.kind) {
case "local": {
@ -510,7 +510,7 @@ function lowerExpr(
}
case "path":
case "ident": {
const res = expr.kind === "ident" ? expr.value.res : expr.res;
const { res } = expr.value;
switch (res.kind) {
case "local": {
@ -690,7 +690,7 @@ function lowerExpr(
todo("non constant calls");
}
const res = expr.lhs.kind === "ident" ? expr.lhs.value.res : expr.lhs.res;
const { res } = expr.lhs.value;
if (res.kind === "builtin") {
const assertArgs = (n: number) => {
if (expr.args.length !== n) throw new Error("nope");

View file

@ -149,7 +149,7 @@ function printExpr(expr: Expr<AnyPhase>, indent: number): string {
return printIdent(expr.value);
}
case "path": {
return `<${expr.segments.join(".")}>${printRes(expr.res)}`;
return `<${expr.segments.join(".")}>${printRes(expr.value.res)}`;
}
case "binary": {
return `${printExpr(expr.lhs, indent)} ${expr.binaryKind} ${printExpr(

View file

@ -209,7 +209,7 @@ function resolveModule(
return { ...superFoldItem(item, this), defPath };
},
expr(expr) {
expr(expr): Expr<Resolved> {
switch (expr.kind) {
case "block": {
const prevScopeLength = scopes.length;
@ -252,7 +252,7 @@ function resolveModule(
if (lhs.kind === "ident" || lhs.kind === "path") {
const res =
lhs.kind === "ident" ? resolveIdent(lhs.value) : lhs.res;
lhs.kind === "ident" ? resolveIdent(lhs.value) : lhs.value.res;
const segments =
lhs.kind === "ident" ? [lhs.value.name] : lhs.segments;
@ -280,12 +280,12 @@ function resolveModule(
}
const pathRes: Resolution = { kind: "item", id: pathResItem };
const span = lhs.span.merge(expr.field.span);
return {
kind: "path",
segments: [...segments, expr.field.value],
res: pathRes,
span: lhs.span.merge(expr.field.span),
value: { res: pathRes, span },
span,
};
}
}

View file

@ -657,7 +657,7 @@ export function checkBody(
switch (lhs.kind) {
case "ident":
case "path": {
const { res } = lhs.kind === "path" ? lhs : lhs.value;
const { res } = lhs.value;
switch (res.kind) {
case "local":
break;
@ -729,15 +729,12 @@ export function checkBody(
return { ...expr, ty };
}
case "ident": {
case "ident":
case "path": {
const ty = typeOfValue(fcx, expr.value.res, expr.value.span);
return { ...expr, ty };
}
case "path": {
const ty = typeOfValue(fcx, expr.res, expr.span);
return { ...expr, ty };
}
case "binary": {
return checkBinary(fcx, expr);
}

View file

@ -8,7 +8,7 @@ fn main() {
.args(&[
"build",
"--manifest-path",
"ui-tests/Cargo.toml",
"ui-harness/Cargo.toml",
"--bin",
"nilc-wrapper",
])
@ -20,9 +20,9 @@ fn main() {
.then_some(())
.unwrap_or_else(|| std::process::exit(1));
let mut config = Config::rustc("ui-tests/ui");
let mut config = Config::rustc("./ui-tests");
config.host = Some("wasm :3".into());
config.program = CommandBuilder::cmd("ui-tests/target/debug/nilc-wrapper");
config.program = CommandBuilder::cmd("ui-harness/target/debug/nilc-wrapper");
config.mode = Mode::Fail {
require_patterns: false,
};