From cc04638f1edfdbefe3af725694581dd80910e8dd Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:47:21 +0200 Subject: [PATCH] minor cleanup --- package.json | 2 +- src/ast.ts | 8 ++++++-- src/codegen.ts | 6 +++--- src/printer.ts | 2 +- src/resolve.ts | 10 +++++----- src/typeck.ts | 9 +++------ {ui-tests => ui-harness}/.gitignore | 0 {ui-tests => ui-harness}/Cargo.lock | 0 {ui-tests => ui-harness}/Cargo.toml | 0 {ui-tests => ui-harness}/src/bin/nilc-wrapper.rs | 0 {ui-tests => ui-harness}/src/main.rs | 6 +++--- ui-tests/{ui => }/function_calls_ok.nil | 0 ui-tests/{ui => }/hello_world.nil | 0 ui-tests/{ui => }/item_tys.nil | 0 ui-tests/{ui => }/type_alias.nil | 0 ui-tests/{ui => }/type_assignments.nil | 0 16 files changed, 22 insertions(+), 21 deletions(-) rename {ui-tests => ui-harness}/.gitignore (100%) rename {ui-tests => ui-harness}/Cargo.lock (100%) rename {ui-tests => ui-harness}/Cargo.toml (100%) rename {ui-tests => ui-harness}/src/bin/nilc-wrapper.rs (100%) rename {ui-tests => ui-harness}/src/main.rs (88%) rename ui-tests/{ui => }/function_calls_ok.nil (100%) rename ui-tests/{ui => }/hello_world.nil (100%) rename ui-tests/{ui => }/item_tys.nil (100%) rename ui-tests/{ui => }/type_alias.nil (100%) rename ui-tests/{ui => }/type_assignments.nil (100%) diff --git a/package.json b/package.json index c48e517..c724410 100644 --- a/package.json +++ b/package.json @@ -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": "", diff --git a/src/ast.ts b/src/ast.ts index a8f4ff0..826c64b 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -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

= { @@ -505,7 +509,7 @@ export type TyVar = { export type TyStruct = { kind: "struct"; - itemId: ItemId, + itemId: ItemId; _name: string; fields: [string, Ty][]; }; diff --git a/src/codegen.ts b/src/codegen.ts index 1d337e8..c05e37e 100644 --- a/src/codegen.ts +++ b/src/codegen.ts @@ -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"); diff --git a/src/printer.ts b/src/printer.ts index 6a02b56..ab3f496 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -149,7 +149,7 @@ function printExpr(expr: Expr, 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( diff --git a/src/resolve.ts b/src/resolve.ts index 738317f..36d1150 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -209,7 +209,7 @@ function resolveModule( return { ...superFoldItem(item, this), defPath }; }, - expr(expr) { + expr(expr): Expr { 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, }; } } diff --git a/src/typeck.ts b/src/typeck.ts index 4f79aa1..8f26653 100644 --- a/src/typeck.ts +++ b/src/typeck.ts @@ -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); } diff --git a/ui-tests/.gitignore b/ui-harness/.gitignore similarity index 100% rename from ui-tests/.gitignore rename to ui-harness/.gitignore diff --git a/ui-tests/Cargo.lock b/ui-harness/Cargo.lock similarity index 100% rename from ui-tests/Cargo.lock rename to ui-harness/Cargo.lock diff --git a/ui-tests/Cargo.toml b/ui-harness/Cargo.toml similarity index 100% rename from ui-tests/Cargo.toml rename to ui-harness/Cargo.toml diff --git a/ui-tests/src/bin/nilc-wrapper.rs b/ui-harness/src/bin/nilc-wrapper.rs similarity index 100% rename from ui-tests/src/bin/nilc-wrapper.rs rename to ui-harness/src/bin/nilc-wrapper.rs diff --git a/ui-tests/src/main.rs b/ui-harness/src/main.rs similarity index 88% rename from ui-tests/src/main.rs rename to ui-harness/src/main.rs index a4da45a..c6ee12d 100644 --- a/ui-tests/src/main.rs +++ b/ui-harness/src/main.rs @@ -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, }; diff --git a/ui-tests/ui/function_calls_ok.nil b/ui-tests/function_calls_ok.nil similarity index 100% rename from ui-tests/ui/function_calls_ok.nil rename to ui-tests/function_calls_ok.nil diff --git a/ui-tests/ui/hello_world.nil b/ui-tests/hello_world.nil similarity index 100% rename from ui-tests/ui/hello_world.nil rename to ui-tests/hello_world.nil diff --git a/ui-tests/ui/item_tys.nil b/ui-tests/item_tys.nil similarity index 100% rename from ui-tests/ui/item_tys.nil rename to ui-tests/item_tys.nil diff --git a/ui-tests/ui/type_alias.nil b/ui-tests/type_alias.nil similarity index 100% rename from ui-tests/ui/type_alias.nil rename to ui-tests/type_alias.nil diff --git a/ui-tests/ui/type_assignments.nil b/ui-tests/type_assignments.nil similarity index 100% rename from ui-tests/ui/type_assignments.nil rename to ui-tests/type_assignments.nil