From 8bafdaa01854ef7c62e7159e230b3f7e2a9b471f Mon Sep 17 00:00:00 2001 From: gavinleroy Date: Tue, 3 Sep 2024 23:38:16 -0400 Subject: [PATCH] Supress Iterator bounds, out-of-control highlighting --- Cargo.lock | 8 ++++---- crates/argus-cli/Cargo.toml | 6 +++--- crates/argus-ext/Cargo.toml | 2 +- crates/argus-ser/Cargo.toml | 4 ++-- crates/argus/Cargo.toml | 8 ++++---- crates/argus/src/ext.rs | 19 +++++++++++++++++++ ide/packages/common/src/BodyInfo.ts | 16 ++++++++++++++++ ide/packages/extension/package.json | 2 +- ide/packages/extension/src/ctx.ts | 27 +++++++++++++-------------- 9 files changed, 63 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68cba59..35db49d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,7 @@ checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "argus-cli" -version = "0.1.11" +version = "0.1.12" dependencies = [ "anyhow", "argus-ext", @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "argus-ext" -version = "0.1.11" +version = "0.1.12" dependencies = [ "anyhow", "fluid-let", @@ -55,7 +55,7 @@ dependencies = [ [[package]] name = "argus-lib" -version = "0.1.11" +version = "0.1.12" dependencies = [ "anyhow", "argus-ext", @@ -80,7 +80,7 @@ dependencies = [ [[package]] name = "argus-ser" -version = "0.1.11" +version = "0.1.12" dependencies = [ "anyhow", "argus-ext", diff --git a/crates/argus-cli/Cargo.toml b/crates/argus-cli/Cargo.toml index 7a4cf18..a5fad65 100644 --- a/crates/argus-cli/Cargo.toml +++ b/crates/argus-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "argus-cli" -version = "0.1.11" +version = "0.1.12" edition = "2021" authors = ["Gavin Gray "] repository = "https://github.com/cognitive-engineering-lab/argus" @@ -10,8 +10,8 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -argus-lib = { version = "0.1.11", path = "../argus" } -argus-ext = { version = "0.1.11", path = "../argus-ext" } +argus-lib = { version = "0.1.12", path = "../argus" } +argus-ext = { version = "0.1.12", path = "../argus-ext" } rustc_plugin = "=0.10.0-nightly-2024-05-20" rustc_utils.workspace = true diff --git a/crates/argus-ext/Cargo.toml b/crates/argus-ext/Cargo.toml index 082af6c..bd2f422 100644 --- a/crates/argus-ext/Cargo.toml +++ b/crates/argus-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "argus-ext" -version = "0.1.11" +version = "0.1.12" edition = "2021" authors = ["Gavin Gray "] repository = "https://github.com/cognitive-engineering-lab/argus" diff --git a/crates/argus-ser/Cargo.toml b/crates/argus-ser/Cargo.toml index d58e92e..cfdda30 100644 --- a/crates/argus-ser/Cargo.toml +++ b/crates/argus-ser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "argus-ser" -version = "0.1.11" +version = "0.1.12" edition = "2021" authors = ["Gavin Gray "] repository = "https://github.com/cognitive-engineering-lab/argus" @@ -28,7 +28,7 @@ smallvec = "1.11.2" itertools = "0.12.0" ts-rs = { version = "7.1.1", features = ["indexmap-impl"], optional = true } index_vec = { version = "0.1.3", features = ["serde"] } -argus-ext = { version = "0.1.11", path = "../argus-ext" } +argus-ext = { version = "0.1.12", path = "../argus-ext" } [dev-dependencies] argus-ser = { path = ".", features = ["testing"] } diff --git a/crates/argus/Cargo.toml b/crates/argus/Cargo.toml index d0802ad..3c15564 100644 --- a/crates/argus/Cargo.toml +++ b/crates/argus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "argus-lib" -version = "0.1.11" +version = "0.1.12" edition = "2021" authors = ["Gavin Gray "] repository = "https://github.com/cognitive-engineering-lab/argus" @@ -21,8 +21,8 @@ fluid-let.workspace = true serde.workspace = true serde_json.workspace = true -argus-ext = { version = "0.1.11", path = "../argus-ext" } -argus-ser = { version = "0.1.11", path = "../argus-ser" } +argus-ext = { version = "0.1.12", path = "../argus-ext" } +argus-ser = { version = "0.1.12", path = "../argus-ser" } index_vec = { version = "0.1.3", features = ["serde"] } smallvec = "1.11.2" itertools = "0.12.0" @@ -35,7 +35,7 @@ ts-rs = { version = "7.1.1", features = ["indexmap-impl"], optional = true } [dev-dependencies] argus-lib = { path = ".", features = ["testing"] } -argus-ser = { version = "0.1.11", path = "../argus-ser", features = ["testing"] } +argus-ser = { version = "0.1.12", path = "../argus-ser", features = ["testing"] } rustc_utils = { version = "=0.10.0-nightly-2024-05-20", features = ["serde", "ts-rs"] } test-log = "0.2.11" env_logger = "0.9.3" diff --git a/crates/argus/src/ext.rs b/crates/argus/src/ext.rs index 36d0246..2f404f4 100644 --- a/crates/argus/src/ext.rs +++ b/crates/argus/src/ext.rs @@ -44,6 +44,23 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { ) -> ObligationNecessity { use ObligationNecessity as ON; + // HACK REMOVE: for the user study we want to reduce + // noise that otherwise shouldn't be there. Iterator / IntoIterator + // bounds are common when the solver is scrambling for diagnostic + // notes and we don't have any problems that "need" them. + let is_user_study_hack = || { + use rustc_hir::lang_items::LangItem as LI; + let items = vec![LI::Iterator, LI::Sized, LI::Deref]; + let lis = self.tcx.lang_items(); + for i in items { + if let Some(def_id) = lis.get(i) && p.is_trait_pred_rhs(def_id) { + return true; + } + } + + false + }; + let is_rhs_lang_item = || { self .tcx @@ -67,6 +84,8 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { if !is_writeable() || p.is_lhs_unit() { ON::No + } else if is_user_study_hack() { + ON::No } else if (p.is_trait_predicate() && is_rhs_lang_item()) || !p.is_trait_predicate() { diff --git a/ide/packages/common/src/BodyInfo.ts b/ide/packages/common/src/BodyInfo.ts index 411197d..8a72b4e 100644 --- a/ide/packages/common/src/BodyInfo.ts +++ b/ide/packages/common/src/BodyInfo.ts @@ -65,6 +65,22 @@ class BodyInfo { return this.oib.tys; } + traitErrors() { + return _.compact( + _.flatMap(this.oib.traitErrors, e => + this.hasVisibleObligations(e.idx) ? null : e + ) + ); + } + + ambiguityErrors() { + return _.compact( + _.flatMap(this.oib.ambiguityErrors, e => + this.hasVisibleObligations(e.idx) ? null : e + ) + ); + } + exprs(): ExprIdx[] { return _.range(0, this.oib.exprs.length); } diff --git a/ide/packages/extension/package.json b/ide/packages/extension/package.json index 3aabcbb..f7872f7 100644 --- a/ide/packages/extension/package.json +++ b/ide/packages/extension/package.json @@ -5,7 +5,7 @@ "description": "A trait debugger for Rust", "license": "MIT", "icon": "argus-logo-128.png", - "version": "0.1.11", + "version": "0.1.12", "engines": { "vscode": "^1.79.0" }, diff --git a/ide/packages/extension/src/ctx.ts b/ide/packages/extension/src/ctx.ts index 1f3f593..0655c8d 100644 --- a/ide/packages/extension/src/ctx.ts +++ b/ide/packages/extension/src/ctx.ts @@ -1,3 +1,4 @@ +import BodyInfo from "@argus/common/BodyInfo"; import type { BodyHash, CharRange, @@ -372,34 +373,32 @@ export class Ctx { private refreshDiagnostics(editor: RustEditor, info: ObligationsInBody[]) { this.diagnosticCollection.clear(); - const traitDiags = _.flatMap(info, ob => - _.map( - ob.traitErrors, + const diags = _.flatMap(info, ob => { + // NOTE: the false is to hide superfluous errors. + const body = new BodyInfo(ob, false); + const traitDiags = _.map( + body.traitErrors(), e => new vscode.Diagnostic( rustRangeToVscodeRange(e.range), diagnosticMessage("trait"), vscode.DiagnosticSeverity.Error ) - ) - ); + ); - const ambigDiags = _.flatMap(info, ob => - _.map( - ob.ambiguityErrors, + const ambigDiags = _.map( + body.ambiguityErrors(), e => new vscode.Diagnostic( rustRangeToVscodeRange(e.range), diagnosticMessage("ambig"), vscode.DiagnosticSeverity.Error ) - ) - ); + ); + return [...traitDiags, ...ambigDiags]; + }); - this.diagnosticCollection.set(editor.document.uri, [ - ...traitDiags, - ...ambigDiags - ]); + this.diagnosticCollection.set(editor.document.uri, diags); } private buildOpenErrorItemCmd(