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", "build": "tsc",
"fmt": "prettier -w .", "fmt": "prettier -w .",
"test": "jest", "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 ." "lint": "eslint ."
}, },
"author": "", "author": "",

View file

@ -225,8 +225,12 @@ export type ExprPath = {
segments: string[]; segments: string[];
/** /**
* Since this only exists after resolve, we always have a res. * 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> = { export type ExprBinary<P extends Phase> = {
@ -505,7 +509,7 @@ export type TyVar = {
export type TyStruct = { export type TyStruct = {
kind: "struct"; kind: "struct";
itemId: ItemId, itemId: ItemId;
_name: string; _name: string;
fields: [string, Ty][]; fields: [string, Ty][];
}; };

View file

@ -428,7 +428,7 @@ function lowerExpr(
switch (lhs.kind) { switch (lhs.kind) {
case "ident": case "ident":
case "path": { case "path": {
const res = lhs.kind === "path" ? lhs.res : lhs.value.res; const { res } = lhs.value;
switch (res.kind) { switch (res.kind) {
case "local": { case "local": {
@ -510,7 +510,7 @@ function lowerExpr(
} }
case "path": case "path":
case "ident": { case "ident": {
const res = expr.kind === "ident" ? expr.value.res : expr.res; const { res } = expr.value;
switch (res.kind) { switch (res.kind) {
case "local": { case "local": {
@ -690,7 +690,7 @@ function lowerExpr(
todo("non constant calls"); 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") { if (res.kind === "builtin") {
const assertArgs = (n: number) => { const assertArgs = (n: number) => {
if (expr.args.length !== n) throw new Error("nope"); 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); return printIdent(expr.value);
} }
case "path": { case "path": {
return `<${expr.segments.join(".")}>${printRes(expr.res)}`; return `<${expr.segments.join(".")}>${printRes(expr.value.res)}`;
} }
case "binary": { case "binary": {
return `${printExpr(expr.lhs, indent)} ${expr.binaryKind} ${printExpr( return `${printExpr(expr.lhs, indent)} ${expr.binaryKind} ${printExpr(

View file

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

View file

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

View file

@ -8,7 +8,7 @@ fn main() {
.args(&[ .args(&[
"build", "build",
"--manifest-path", "--manifest-path",
"ui-tests/Cargo.toml", "ui-harness/Cargo.toml",
"--bin", "--bin",
"nilc-wrapper", "nilc-wrapper",
]) ])
@ -20,9 +20,9 @@ fn main() {
.then_some(()) .then_some(())
.unwrap_or_else(|| std::process::exit(1)); .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.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 { config.mode = Mode::Fail {
require_patterns: false, require_patterns: false,
}; };