From 6e50f77e52f8e86dd117436610f911523f075eb0 Mon Sep 17 00:00:00 2001 From: aleksana Date: Thu, 1 Aug 2024 22:48:44 +0800 Subject: [PATCH 1/8] libnixf: split sema-unused-def into let, arg and formal --- libnixf/include/nixf/Sema/VariableLookup.h | 5 +++- libnixf/src/Basic/diagnostic.py | 24 +++++++++++++-- libnixf/src/Sema/VariableLookup.cpp | 34 +++++++++++++++++----- libnixf/test/Sema/VariableLookup.cpp | 25 +++++++++++----- 4 files changed, 70 insertions(+), 18 deletions(-) diff --git a/libnixf/include/nixf/Sema/VariableLookup.h b/libnixf/include/nixf/Sema/VariableLookup.h index e470415cd..8b0116172 100644 --- a/libnixf/include/nixf/Sema/VariableLookup.h +++ b/libnixf/include/nixf/Sema/VariableLookup.h @@ -39,9 +39,12 @@ class Definition { /// \brief From lambda formal, e.g. { a }: a + 1 DS_LambdaFormal, - /// \brief From lambda arg with formal, e.g. { foo, bar }@a: a + 1 + /// \brief From lambda arg with formal, e.g. `a` in `{ foo }@a: foo + 1` DS_LambdaArgWithFormal, + /// \brief From lambda formal with arg, e.g. `foo` in `{ foo }@a: foo + 1` + DS_LambdaFormalWithArg, + /// \brief From recursive attribute set. e.g. rec { } DS_Rec, diff --git a/libnixf/src/Basic/diagnostic.py b/libnixf/src/Basic/diagnostic.py index 57d4fe837..a24c6ab34 100644 --- a/libnixf/src/Basic/diagnostic.py +++ b/libnixf/src/Basic/diagnostic.py @@ -184,10 +184,28 @@ class Diagnostic(TypedDict): "message": "undefined variable `{}`", }, { - "sname": "sema-def-not-used", - "cname": "DefinitionNotUsed", + "sname": "sema-unused-def-let", + "cname": "UnusedDefLet", + "severity": "Warning", + "message": "variable `{}` in let-expression is not used", + }, + { + "sname": "sema-unused-def-formal", + "cname": "UnusedDefFormal", + "severity": "Warning", + "message": "attribute `{}` of argument is not used", + }, + { + "sname": "sema-unused-def-arg-with-formal", + "cname": "UnusedDefArgWithFormal", + "severity": "Warning", + "message": "argument `{}` in `@`-pattern is not used", + }, + { + "sname": "sema-unused-def-formal-with-arg", + "cname": "UnusedDefFormalWithArg", "severity": "Hint", - "message": "definition `{}` is not used", + "message": "attribute `{}` of `@`-pattern argument is not used, but may be referenced from the argument", }, { "sname": "sema-extra-rec", diff --git a/libnixf/src/Sema/VariableLookup.cpp b/libnixf/src/Sema/VariableLookup.cpp index d25d3c3d4..c39bca727 100644 --- a/libnixf/src/Sema/VariableLookup.cpp +++ b/libnixf/src/Sema/VariableLookup.cpp @@ -52,8 +52,24 @@ void VariableLookupAnalysis::emitEnvLivenessWarning( if (!Def->syntax()) continue; if (Def->uses().empty()) { - Diagnostic &D = Diags.emplace_back(Diagnostic::DK_DefinitionNotUsed, - Def->syntax()->range()); + Diagnostic::DiagnosticKind kind; + switch (Def->source()) { + case Definition::DS_Let: + kind = Diagnostic::DK_UnusedDefLet; + break; + case Definition::DS_LambdaFormal: + kind = Diagnostic::DK_UnusedDefFormal; + break; + case Definition::DS_LambdaFormalWithArg: + kind = Diagnostic::DK_UnusedDefFormalWithArg; + break; + case Definition::DS_LambdaArgWithFormal: + kind = Diagnostic::DK_UnusedDefArgWithFormal; + break; + default: + break; + } + Diagnostic &D = Diags.emplace_back(kind, Def->syntax()->range()); D << Name; D.tag(DiagnosticTag::Faded); } @@ -128,6 +144,9 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, // foo: body // ^~~<------- add function argument. + // { foo, bar, ... } : body + // ^~~~~~~~~<-------------- add function formals. + if (Arg.id()) { if (!Arg.formals()) { ToDef.insert_or_assign(Arg.id(), DBuilder.add(Arg.id()->name(), Arg.id(), @@ -138,16 +157,17 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, ToDef.insert_or_assign(Arg.id(), DBuilder.add(Arg.id()->name(), Arg.id(), Definition::DS_LambdaArgWithFormal)); + for (const auto &[Name, Formal] : Arg.formals()->dedup()) + ToDef.insert_or_assign( + Formal->id(), DBuilder.add(Name, Formal->id(), + Definition::DS_LambdaFormalWithArg)); } - } - - // { foo, bar, ... } : body - /// ^~~~~~~~~<-------------- add function formals. - if (Arg.formals()) + } else if (Arg.formals()) { for (const auto &[Name, Formal] : Arg.formals()->dedup()) ToDef.insert_or_assign( Formal->id(), DBuilder.add(Name, Formal->id(), Definition::DS_LambdaFormal)); + } auto NewEnv = std::make_shared(Env, DBuilder.finish(), &Lambda); diff --git a/libnixf/test/Sema/VariableLookup.cpp b/libnixf/test/Sema/VariableLookup.cpp index ef11bde0c..2f60a48ba 100644 --- a/libnixf/test/Sema/VariableLookup.cpp +++ b/libnixf/test/Sema/VariableLookup.cpp @@ -135,29 +135,27 @@ TEST_F(VLATest, LivenessRec) { ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_ExtraRecursive); } -TEST_F(VLATest, LivenessArg) { +TEST_F(VLATest, LivenessFormal) { std::shared_ptr AST = parse("{ foo }: 1", Diags); VariableLookupAnalysis VLA(Diags); VLA.runOnAST(*AST); ASSERT_EQ(Diags.size(), 1); - ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_DefinitionNotUsed); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefFormal); ASSERT_EQ(Diags[0].tags().size(), 1); - ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded); } -TEST_F(VLATest, LivenessNested) { +TEST_F(VLATest, LivenessLet) { std::shared_ptr AST = parse("let y = 1; in x: y: x + y", Diags); VariableLookupAnalysis VLA(Diags); VLA.runOnAST(*AST); ASSERT_EQ(Diags.size(), 1); - ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_DefinitionNotUsed); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefLet); ASSERT_EQ(Diags[0].range().lCur().column(), 4); ASSERT_EQ(Diags[0].tags().size(), 1); - ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded); } TEST_F(VLATest, LivenessDupSymbol) { @@ -179,12 +177,25 @@ TEST_F(VLATest, LivenessArgWithFormal) { ASSERT_EQ(Diags.size(), 1); - ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_DefinitionNotUsed); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefArgWithFormal); ASSERT_EQ(Diags[0].range().lCur().column(), 8); ASSERT_EQ(Diags[0].tags().size(), 1); +} + +TEST_F(VLATest, LivenessFormalWithArg) { + std::shared_ptr AST = parse("{ foo }@bar: bar", Diags); + VariableLookupAnalysis VLA(Diags); + VLA.runOnAST(*AST); + + ASSERT_EQ(Diags.size(), 1); + + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefFormalWithArg); + ASSERT_EQ(Diags[0].range().lCur().column(), 2); + ASSERT_EQ(Diags[0].tags().size(), 1); ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded); } + TEST_F(VLATest, ToDefAttrs) { std::shared_ptr AST = parse("rec { x = 1; y = x; z = x; }", Diags); VariableLookupAnalysis VLA(Diags); From 5c2cbfb1848a7dde452a67fd1fa90d47a145eef2 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 2 Aug 2024 14:59:50 +0800 Subject: [PATCH 2/8] fix undefined diagnostic kind, formal env creating, and the tests --- libnixf/src/Basic/diagnostic.py | 8 ++- libnixf/src/Sema/VariableLookup.cpp | 63 ++++++++++--------- .../nixd/test/diagnostic/liveness-formal.md | 6 +- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/libnixf/src/Basic/diagnostic.py b/libnixf/src/Basic/diagnostic.py index a24c6ab34..2880fc1b4 100644 --- a/libnixf/src/Basic/diagnostic.py +++ b/libnixf/src/Basic/diagnostic.py @@ -183,11 +183,17 @@ class Diagnostic(TypedDict): "severity": "Error", "message": "undefined variable `{}`", }, + { + "sname": "sema-unused-def-generic", + "cname": "UnusedDef", + "severity": "Warning", + "message": "undefined definition `{}`", + }, { "sname": "sema-unused-def-let", "cname": "UnusedDefLet", "severity": "Warning", - "message": "variable `{}` in let-expression is not used", + "message": "definition `{}` in let-expression is not used", }, { "sname": "sema-unused-def-formal", diff --git a/libnixf/src/Sema/VariableLookup.cpp b/libnixf/src/Sema/VariableLookup.cpp index c39bca727..9cb53945c 100644 --- a/libnixf/src/Sema/VariableLookup.cpp +++ b/libnixf/src/Sema/VariableLookup.cpp @@ -52,24 +52,21 @@ void VariableLookupAnalysis::emitEnvLivenessWarning( if (!Def->syntax()) continue; if (Def->uses().empty()) { - Diagnostic::DiagnosticKind kind; - switch (Def->source()) { - case Definition::DS_Let: - kind = Diagnostic::DK_UnusedDefLet; - break; - case Definition::DS_LambdaFormal: - kind = Diagnostic::DK_UnusedDefFormal; - break; - case Definition::DS_LambdaFormalWithArg: - kind = Diagnostic::DK_UnusedDefFormalWithArg; - break; - case Definition::DS_LambdaArgWithFormal: - kind = Diagnostic::DK_UnusedDefArgWithFormal; - break; - default: - break; - } - Diagnostic &D = Diags.emplace_back(kind, Def->syntax()->range()); + Diagnostic::DiagnosticKind Kind = [&]() { + switch (Def->source()) { + case Definition::DS_Let: + return Diagnostic::DK_UnusedDefLet; + case Definition::DS_LambdaFormal: + return Diagnostic::DK_UnusedDefFormal; + case Definition::DS_LambdaFormalWithArg: + return Diagnostic::DK_UnusedDefFormalWithArg; + case Definition::DS_LambdaArgWithFormal: + return Diagnostic::DK_UnusedDefArgWithFormal; + default: + return Diagnostic::DK_UnusedDef; + } + }(); + Diagnostic &D = Diags.emplace_back(Kind, Def->syntax()->range()); D << Name; D.tag(DiagnosticTag::Faded); } @@ -144,8 +141,6 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, // foo: body // ^~~<------- add function argument. - // { foo, bar, ... } : body - // ^~~~~~~~~<-------------- add function formals. if (Arg.id()) { if (!Arg.formals()) { @@ -157,16 +152,26 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, ToDef.insert_or_assign(Arg.id(), DBuilder.add(Arg.id()->name(), Arg.id(), Definition::DS_LambdaArgWithFormal)); - for (const auto &[Name, Formal] : Arg.formals()->dedup()) - ToDef.insert_or_assign( - Formal->id(), DBuilder.add(Name, Formal->id(), - Definition::DS_LambdaFormalWithArg)); } - } else if (Arg.formals()) { - for (const auto &[Name, Formal] : Arg.formals()->dedup()) - ToDef.insert_or_assign( - Formal->id(), - DBuilder.add(Name, Formal->id(), Definition::DS_LambdaFormal)); + } + + // { foo, bar, ... } : body + // ^~~~~~~~~<-------------- add function formals. + // Here it is distinguished between formal *with* an argument and without. + // Example: + // + // { foo }@arg : use arg + // + // In this case, definition `foo` is not used, however it might be used via + // arg.foo. So the serverity of unused formal is demoted in this case. + if (Arg.formals()) { + for (const auto &[Name, Formal] : Arg.formals()->dedup()) { + Definition::DefinitionSource Source = + Arg.id() ? Definition::DS_LambdaFormalWithArg + : Definition::DS_LambdaFormal; + ToDef.insert_or_assign(Formal->id(), + DBuilder.add(Name, Formal->id(), Source)); + } } auto NewEnv = std::make_shared(Env, DBuilder.finish(), &Lambda); diff --git a/nixd/tools/nixd/test/diagnostic/liveness-formal.md b/nixd/tools/nixd/test/diagnostic/liveness-formal.md index f90dd5b71..9f0f0ff55 100644 --- a/nixd/tools/nixd/test/diagnostic/liveness-formal.md +++ b/nixd/tools/nixd/test/diagnostic/liveness-formal.md @@ -38,8 +38,8 @@ ``` CHECK: "diagnostics": [ CHECK-NEXT: { -CHECK-NEXT: "code": "sema-def-not-used", -CHECK-NEXT: "message": "definition `y` is not used", +CHECK-NEXT: "code": "sema-unused-def-formal", +CHECK-NEXT: "message": "attribute `y` of argument is not used", CHECK-NEXT: "range": { CHECK-NEXT: "end": { CHECK-NEXT: "character": 5, @@ -51,7 +51,7 @@ CHECK-NEXT: "line": 0 CHECK-NEXT: } CHECK-NEXT: }, CHECK-NEXT: "relatedInformation": [], -CHECK-NEXT: "severity": 4, +CHECK-NEXT: "severity": 2, CHECK-NEXT: "source": "nixf", CHECK-NEXT: "tags": [ CHECK-NEXT: 1 From cccd5150add76d103f23ffa755c49587f051217f Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 2 Aug 2024 15:06:24 +0800 Subject: [PATCH 3/8] chatgpt comments --- libnixf/src/Sema/VariableLookup.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libnixf/src/Sema/VariableLookup.cpp b/libnixf/src/Sema/VariableLookup.cpp index 9cb53945c..f6feb887e 100644 --- a/libnixf/src/Sema/VariableLookup.cpp +++ b/libnixf/src/Sema/VariableLookup.cpp @@ -157,13 +157,15 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, // { foo, bar, ... } : body // ^~~~~~~~~<-------------- add function formals. - // Here it is distinguished between formal *with* an argument and without. - // Example: + + // This section differentiates between formal parameters with an argument and + // without. Example: // // { foo }@arg : use arg // - // In this case, definition `foo` is not used, however it might be used via - // arg.foo. So the serverity of unused formal is demoted in this case. + // In this case, the definition of `foo` is not used directly; however, it + // might be accessed via arg.foo. Therefore, the severity of an unused formal + // parameter is reduced in this scenario. if (Arg.formals()) { for (const auto &[Name, Formal] : Arg.formals()->dedup()) { Definition::DefinitionSource Source = From 58d654f38fd17a829bda294efe7ab61d53d6f29b Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 2 Aug 2024 15:07:20 +0800 Subject: [PATCH 4/8] Update libnixf/src/Basic/diagnostic.py --- libnixf/src/Basic/diagnostic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnixf/src/Basic/diagnostic.py b/libnixf/src/Basic/diagnostic.py index 2880fc1b4..9da9d0135 100644 --- a/libnixf/src/Basic/diagnostic.py +++ b/libnixf/src/Basic/diagnostic.py @@ -187,7 +187,7 @@ class Diagnostic(TypedDict): "sname": "sema-unused-def-generic", "cname": "UnusedDef", "severity": "Warning", - "message": "undefined definition `{}`", + "message": "definition `{}` is not used", }, { "sname": "sema-unused-def-let", From 6907c0fa39f484ec9e04b2ff8ada4c2eb1543cc5 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 2 Aug 2024 15:19:45 +0800 Subject: [PATCH 5/8] please fmt --- libnixf/test/Sema/VariableLookup.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libnixf/test/Sema/VariableLookup.cpp b/libnixf/test/Sema/VariableLookup.cpp index 2f60a48ba..838c53e03 100644 --- a/libnixf/test/Sema/VariableLookup.cpp +++ b/libnixf/test/Sema/VariableLookup.cpp @@ -195,7 +195,6 @@ TEST_F(VLATest, LivenessFormalWithArg) { ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded); } - TEST_F(VLATest, ToDefAttrs) { std::shared_ptr AST = parse("rec { x = 1; y = x; z = x; }", Diags); VariableLookupAnalysis VLA(Diags); From e21457ee3b630badb98bbdc6688655d86ecb3115 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 2 Aug 2024 15:24:36 +0800 Subject: [PATCH 6/8] fixup empty line --- libnixf/src/Sema/VariableLookup.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libnixf/src/Sema/VariableLookup.cpp b/libnixf/src/Sema/VariableLookup.cpp index f6feb887e..0e46703c2 100644 --- a/libnixf/src/Sema/VariableLookup.cpp +++ b/libnixf/src/Sema/VariableLookup.cpp @@ -141,7 +141,6 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, // foo: body // ^~~<------- add function argument. - if (Arg.id()) { if (!Arg.formals()) { ToDef.insert_or_assign(Arg.id(), DBuilder.add(Arg.id()->name(), Arg.id(), From 568e16e2dccba20831f1bdbc58b59b2d8c308693 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 2 Aug 2024 15:31:48 +0800 Subject: [PATCH 7/8] remove unreachable code --- libnixf/src/Basic/diagnostic.py | 6 ------ libnixf/src/Sema/VariableLookup.cpp | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/libnixf/src/Basic/diagnostic.py b/libnixf/src/Basic/diagnostic.py index 9da9d0135..71bf431b0 100644 --- a/libnixf/src/Basic/diagnostic.py +++ b/libnixf/src/Basic/diagnostic.py @@ -183,12 +183,6 @@ class Diagnostic(TypedDict): "severity": "Error", "message": "undefined variable `{}`", }, - { - "sname": "sema-unused-def-generic", - "cname": "UnusedDef", - "severity": "Warning", - "message": "definition `{}` is not used", - }, { "sname": "sema-unused-def-let", "cname": "UnusedDefLet", diff --git a/libnixf/src/Sema/VariableLookup.cpp b/libnixf/src/Sema/VariableLookup.cpp index 0e46703c2..168a1029c 100644 --- a/libnixf/src/Sema/VariableLookup.cpp +++ b/libnixf/src/Sema/VariableLookup.cpp @@ -63,7 +63,8 @@ void VariableLookupAnalysis::emitEnvLivenessWarning( case Definition::DS_LambdaArgWithFormal: return Diagnostic::DK_UnusedDefArgWithFormal; default: - return Diagnostic::DK_UnusedDef; + assert(false && "liveness diagnostic encountered an unknown source!"); + __builtin_unreachable(); } }(); Diagnostic &D = Diags.emplace_back(Kind, Def->syntax()->range()); From f204a12de0a5a5ae72e86a6152e697ebd6143c36 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 2 Aug 2024 15:39:16 +0800 Subject: [PATCH 8/8] rename somewhat --- libnixf/include/nixf/Sema/VariableLookup.h | 14 ++++++++------ libnixf/src/Basic/diagnostic.py | 12 ++++++------ libnixf/src/Sema/VariableLookup.cpp | 18 +++++++++--------- libnixf/test/Sema/VariableLookup.cpp | 6 +++--- .../nixd/test/diagnostic/liveness-formal.md | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/libnixf/include/nixf/Sema/VariableLookup.h b/libnixf/include/nixf/Sema/VariableLookup.h index 8b0116172..7b0843f3e 100644 --- a/libnixf/include/nixf/Sema/VariableLookup.h +++ b/libnixf/include/nixf/Sema/VariableLookup.h @@ -36,14 +36,16 @@ class Definition { /// \brief From ambda arg e.g. a: a + 1 DS_LambdaArg, - /// \brief From lambda formal, e.g. { a }: a + 1 - DS_LambdaFormal, + /// \brief From lambda (noarg) formal, e.g. { a }: a + 1 + DS_LambdaNoArg_Formal, - /// \brief From lambda arg with formal, e.g. `a` in `{ foo }@a: foo + 1` - DS_LambdaArgWithFormal, + /// \brief From lambda (with `@arg`) `arg`, + /// e.g. `a` in `{ foo }@a: foo + 1` + DS_LambdaWithArg_Arg, - /// \brief From lambda formal with arg, e.g. `foo` in `{ foo }@a: foo + 1` - DS_LambdaFormalWithArg, + /// \brief From lambda (with `@arg`) formal, + /// e.g. `foo` in `{ foo }@a: foo + 1` + DS_LambdaWithArg_Formal, /// \brief From recursive attribute set. e.g. rec { } DS_Rec, diff --git a/libnixf/src/Basic/diagnostic.py b/libnixf/src/Basic/diagnostic.py index 71bf431b0..ecaef03ea 100644 --- a/libnixf/src/Basic/diagnostic.py +++ b/libnixf/src/Basic/diagnostic.py @@ -190,20 +190,20 @@ class Diagnostic(TypedDict): "message": "definition `{}` in let-expression is not used", }, { - "sname": "sema-unused-def-formal", - "cname": "UnusedDefFormal", + "sname": "sema-unused-def-lambda-noarg-formal", + "cname": "UnusedDefLambdaNoArg_Formal", "severity": "Warning", "message": "attribute `{}` of argument is not used", }, { - "sname": "sema-unused-def-arg-with-formal", - "cname": "UnusedDefArgWithFormal", + "sname": "sema-unused-def-lambda-witharg-formal", + "cname": "UnusedDefLambdaWithArg_Formal", "severity": "Warning", "message": "argument `{}` in `@`-pattern is not used", }, { - "sname": "sema-unused-def-formal-with-arg", - "cname": "UnusedDefFormalWithArg", + "sname": "sema-unused-def-lambda-witharg-arg", + "cname": "UnusedDefLambdaWithArg_Arg", "severity": "Hint", "message": "attribute `{}` of `@`-pattern argument is not used, but may be referenced from the argument", }, diff --git a/libnixf/src/Sema/VariableLookup.cpp b/libnixf/src/Sema/VariableLookup.cpp index 168a1029c..9b3b38ab0 100644 --- a/libnixf/src/Sema/VariableLookup.cpp +++ b/libnixf/src/Sema/VariableLookup.cpp @@ -56,12 +56,12 @@ void VariableLookupAnalysis::emitEnvLivenessWarning( switch (Def->source()) { case Definition::DS_Let: return Diagnostic::DK_UnusedDefLet; - case Definition::DS_LambdaFormal: - return Diagnostic::DK_UnusedDefFormal; - case Definition::DS_LambdaFormalWithArg: - return Diagnostic::DK_UnusedDefFormalWithArg; - case Definition::DS_LambdaArgWithFormal: - return Diagnostic::DK_UnusedDefArgWithFormal; + case Definition::DS_LambdaNoArg_Formal: + return Diagnostic::DK_UnusedDefLambdaNoArg_Formal; + case Definition::DS_LambdaWithArg_Formal: + return Diagnostic::DK_UnusedDefLambdaWithArg_Formal; + case Definition::DS_LambdaWithArg_Arg: + return Diagnostic::DK_UnusedDefLambdaWithArg_Arg; default: assert(false && "liveness diagnostic encountered an unknown source!"); __builtin_unreachable(); @@ -151,7 +151,7 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, } else if (!Arg.formals()->dedup().contains(Arg.id()->name())) { ToDef.insert_or_assign(Arg.id(), DBuilder.add(Arg.id()->name(), Arg.id(), - Definition::DS_LambdaArgWithFormal)); + Definition::DS_LambdaWithArg_Arg)); } } @@ -169,8 +169,8 @@ void VariableLookupAnalysis::dfs(const ExprLambda &Lambda, if (Arg.formals()) { for (const auto &[Name, Formal] : Arg.formals()->dedup()) { Definition::DefinitionSource Source = - Arg.id() ? Definition::DS_LambdaFormalWithArg - : Definition::DS_LambdaFormal; + Arg.id() ? Definition::DS_LambdaWithArg_Formal + : Definition::DS_LambdaNoArg_Formal; ToDef.insert_or_assign(Formal->id(), DBuilder.add(Name, Formal->id(), Source)); } diff --git a/libnixf/test/Sema/VariableLookup.cpp b/libnixf/test/Sema/VariableLookup.cpp index 838c53e03..b48a78784 100644 --- a/libnixf/test/Sema/VariableLookup.cpp +++ b/libnixf/test/Sema/VariableLookup.cpp @@ -142,7 +142,7 @@ TEST_F(VLATest, LivenessFormal) { ASSERT_EQ(Diags.size(), 1); - ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefFormal); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefLambdaNoArg_Formal); ASSERT_EQ(Diags[0].tags().size(), 1); } @@ -177,7 +177,7 @@ TEST_F(VLATest, LivenessArgWithFormal) { ASSERT_EQ(Diags.size(), 1); - ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefArgWithFormal); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefLambdaWithArg_Arg); ASSERT_EQ(Diags[0].range().lCur().column(), 8); ASSERT_EQ(Diags[0].tags().size(), 1); } @@ -189,7 +189,7 @@ TEST_F(VLATest, LivenessFormalWithArg) { ASSERT_EQ(Diags.size(), 1); - ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefFormalWithArg); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_UnusedDefLambdaWithArg_Formal); ASSERT_EQ(Diags[0].range().lCur().column(), 2); ASSERT_EQ(Diags[0].tags().size(), 1); ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded); diff --git a/nixd/tools/nixd/test/diagnostic/liveness-formal.md b/nixd/tools/nixd/test/diagnostic/liveness-formal.md index 9f0f0ff55..6391524cb 100644 --- a/nixd/tools/nixd/test/diagnostic/liveness-formal.md +++ b/nixd/tools/nixd/test/diagnostic/liveness-formal.md @@ -38,7 +38,7 @@ ``` CHECK: "diagnostics": [ CHECK-NEXT: { -CHECK-NEXT: "code": "sema-unused-def-formal", +CHECK-NEXT: "code": "sema-unused-def-lambda-noarg-formal", CHECK-NEXT: "message": "attribute `y` of argument is not used", CHECK-NEXT: "range": { CHECK-NEXT: "end": {