Skip to content

Commit

Permalink
Fix Ref printing, sanitize body spans
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Jul 9, 2024
1 parent 5148270 commit ae7afd9
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 97 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crates/argus-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-cli"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["Gavin Gray <[email protected]>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand All @@ -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.7", path = "../argus" }
argus-ext = { version = "0.1.7", path = "../argus-ext" }
argus-lib = { version = "0.1.8", path = "../argus" }
argus-ext = { version = "0.1.8", path = "../argus-ext" }
rustc_plugin = "=0.10.0-nightly-2024-05-20"

rustc_utils.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/argus-ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-ext"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["Gavin Gray <[email protected]>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand Down
4 changes: 2 additions & 2 deletions crates/argus-ser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-ser"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["Gavin Gray <[email protected]>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand Down Expand Up @@ -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.7", path = "../argus-ext" }
argus-ext = { version = "0.1.8", path = "../argus-ext" }

[dev-dependencies]
argus-ser = { path = ".", features = ["testing"] }
Expand Down
8 changes: 4 additions & 4 deletions crates/argus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "argus-lib"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["Gavin Gray <[email protected]>"]
repository = "https://github.com/cognitive-engineering-lab/argus"
Expand All @@ -21,8 +21,8 @@ fluid-let.workspace = true
serde.workspace = true
serde_json.workspace = true

argus-ext = { version = "0.1.7", path = "../argus-ext" }
argus-ser = { version = "0.1.7", path = "../argus-ser" }
argus-ext = { version = "0.1.8", path = "../argus-ext" }
argus-ser = { version = "0.1.8", path = "../argus-ser" }
index_vec = { version = "0.1.3", features = ["serde"] }
smallvec = "1.11.2"
itertools = "0.12.0"
Expand All @@ -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.7", path = "../argus-ser", features = ["testing"] }
argus-ser = { version = "0.1.8", 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"
Expand Down
38 changes: 17 additions & 21 deletions crates/argus/src/aadebug/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ enum Location {
enum GoalKind {
Trait { _self: Location, _trait: Location },
TyChange,
FnToTrait { _trait: Location },
FnToTrait { _trait: Location, arity: usize },
TyAsCallable { arity: usize },
FnParamDel { d: usize },
DeleteFnParams { delta: usize },
Misc,
}

Expand All @@ -77,31 +77,24 @@ impl GoalKind {
GK::Trait {
_self: L,
_trait: E,
} => 1,

// NOTE: if the failed predicate is fn(..): Trait then treat the
// function as an `External` type, because you can't implement traits
// for functions, that has to be done via blanket impls using Fn traits.
GK::Trait {
}
| GK::Trait {
_self: E,
_trait: L,
}
// You can't implement a trait for function, they have to be
// done by the crate exporting the trait.
| GK::FnToTrait { _trait: L } => 2,
| GK::FnToTrait { _trait: L, .. } => 1,

GK::Trait {
_self: E,
_trait: E,
} => 3,

GK::FnToTrait { _trait: E }
| GK::TyChange => 4,
GK::FnParamDel { d } => 4 * d,
} => 2,

GK::TyChange => 4,
GK::DeleteFnParams { delta } => 4 * delta,
GK::FnToTrait { _trait: E, arity }
// You could implement the unstable Fn traits for a type,
// we could thens suggest this if there's nothing else better.
GK::TyAsCallable { arity } => 10 + arity,
| GK::TyAsCallable { arity } => 4 + 4 * arity,
GK::Misc => 20,
}
}
Expand Down Expand Up @@ -280,8 +273,8 @@ impl<'a, 'tcx> Goal<'a, 'tcx> {
log::debug!("{} v {}", fn_arity, trait_arity);

if fn_arity > trait_arity {
GoalKind::FnParamDel {
d: fn_arity - trait_arity,
GoalKind::DeleteFnParams {
delta: fn_arity - trait_arity,
}
} else {
GoalKind::Misc
Expand All @@ -300,15 +293,18 @@ impl<'a, 'tcx> Goal<'a, 'tcx> {
// Self type is a function type but the trait isn't
ty::PredicateKind::Clause(ty::ClauseKind::Trait(t))
if t.polarity == ty::PredicatePolarity::Positive
&& let Some(_) = tcx.function_arity(t.self_ty()) =>
&& let Some(fn_arity) = tcx.function_arity(t.self_ty()) =>
{
let def_id = t.def_id();
let location = if def_id.is_local() {
Location::Local
} else {
Location::External
};
GoalKind::FnToTrait { _trait: location }
GoalKind::FnToTrait {
_trait: location,
arity: fn_arity,
}
}

ty::PredicateKind::Clause(ty::ClauseKind::Trait(t))
Expand Down
8 changes: 7 additions & 1 deletion crates/argus/src/analysis/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ pub fn transform<'a, 'tcx: 'a>(

let hir = tcx.hir();
let source_map = tcx.sess.source_map();
let body_span = hir.body(body_id).value.span;

let mut visible_body_span = hir.body(body_id).value.span;
while visible_body_span.from_expansion() {
visible_body_span = visible_body_span.source_callsite();
}

let body_span = tcx.to_local(body_id, visible_body_span);
let body_range = CharRange::from_span(body_span, source_map)
.expect("Couldn't get body range");

Expand Down
2 changes: 0 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
toolchain
] ++ lib.optional stdenv.isDarwin libiconv;

# FIXME: this is darwin specific vvv but the flake should work for all systems
RUSTC_LINKER = "${pkgs.llvmPackages.clangUseLLVM}/bin/clang";
RUSTFLAGS = "-Clink-arg=-fuse-ld=${pkgs.mold}/bin/mold";
};
});
}
2 changes: 1 addition & 1 deletion ide/packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "A trait debugger for Rust",
"license": "MIT",
"icon": "argus-logo-128.png",
"version": "0.1.7",
"version": "0.1.8",
"engines": {
"vscode": "^1.79.0"
},
Expand Down
Loading

0 comments on commit ae7afd9

Please sign in to comment.