Enable Chalk tracing in hir_ty tests

This commit is contained in:
Florian Diebold 2020-07-10 18:30:32 +02:00 committed by Florian Diebold
parent 209c492432
commit c82f5379de
6 changed files with 114 additions and 67 deletions

59
Cargo.lock generated
View file

@ -33,6 +33,15 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi 0.3.9",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.31" version = "1.0.31"
@ -51,6 +60,17 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.0.0" version = "1.0.0"
@ -971,6 +991,16 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "quanta"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7a1905379198075914bc93d32a5465c40474f90a078bb13439cb00c547bcc"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.7" version = "1.0.7"
@ -1120,6 +1150,9 @@ dependencies = [
"smallvec", "smallvec",
"stdx", "stdx",
"test_utils", "test_utils",
"tracing",
"tracing-subscriber",
"tracing-tree",
] ]
[[package]] [[package]]
@ -1722,6 +1755,15 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "termcolor"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "terminal_size" name = "terminal_size"
version = "0.1.13" version = "0.1.13"
@ -1856,7 +1898,7 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c72c8cf3ec4ed69fef614d011a5ae4274537a8a8c59133558029bd731eb71659" checksum = "c72c8cf3ec4ed69fef614d011a5ae4274537a8a8c59133558029bd731eb71659"
dependencies = [ dependencies = [
"ansi_term", "ansi_term 0.11.0",
"chrono", "chrono",
"lazy_static", "lazy_static",
"matchers", "matchers",
@ -1870,6 +1912,21 @@ dependencies = [
"tracing-serde", "tracing-serde",
] ]
[[package]]
name = "tracing-tree"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a389731c9e6c56fef11e438e5b6afae861d5bc301c8b4bdca8d19f0e830d82"
dependencies = [
"ansi_term 0.12.1",
"atty",
"chrono",
"quanta",
"termcolor",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.4" version = "0.3.4"

View file

@ -33,3 +33,7 @@ chalk-ir = { version = "0.15.0" }
[dev-dependencies] [dev-dependencies]
insta = "0.16.0" insta = "0.16.0"
expect = { path = "../expect" } expect = { path = "../expect" }
tracing = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
tracing-tree = { version = "0.1.3" }

View file

@ -37,6 +37,15 @@ use crate::{
// against snapshots of the expected results using insta. Use cargo-insta to // against snapshots of the expected results using insta. Use cargo-insta to
// update the snapshots. // update the snapshots.
fn setup_tracing() -> tracing::subscriber::DefaultGuard {
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
use tracing_tree::HierarchicalLayer;
let filter = EnvFilter::from_env("CHALK_DEBUG");
let layer = HierarchicalLayer::default().with_indent_amount(2).with_writer(std::io::stderr);
let subscriber = Registry::default().with(filter).with(layer);
tracing::subscriber::set_default(subscriber)
}
fn check_types(ra_fixture: &str) { fn check_types(ra_fixture: &str) {
check_types_impl(ra_fixture, false) check_types_impl(ra_fixture, false)
} }
@ -46,6 +55,7 @@ fn check_types_source_code(ra_fixture: &str) {
} }
fn check_types_impl(ra_fixture: &str, display_source: bool) { fn check_types_impl(ra_fixture: &str, display_source: bool) {
let _tracing = setup_tracing();
let db = TestDB::with_files(ra_fixture); let db = TestDB::with_files(ra_fixture);
let mut checked_one = false; let mut checked_one = false;
for (file_id, annotations) in db.extract_annotations() { for (file_id, annotations) in db.extract_annotations() {
@ -86,6 +96,7 @@ fn infer(ra_fixture: &str) -> String {
} }
fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
let _tracing = setup_tracing();
let (db, file_id) = TestDB::with_single_file(content); let (db, file_id) = TestDB::with_single_file(content);
let mut buf = String::new(); let mut buf = String::new();

View file

@ -3000,69 +3000,44 @@ fn infer_box_fn_arg() {
#[test] #[test]
fn infer_dyn_fn_output() { fn infer_dyn_fn_output() {
assert_snapshot!( check_types(
infer( r#"
r#" //- /lib.rs
//- /lib.rs deps:std #[lang = "fn_once"]
pub trait FnOnce<Args> {
type Output;
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}
#[lang = "fn_once"] #[lang = "fn"]
pub trait FnOnce<Args> { pub trait Fn<Args>: FnOnce<Args> {
type Output; extern "rust-call" fn call(&self, args: Args) -> Self::Output;
}
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; fn foo() {
} let f: &dyn Fn() -> i32;
f();
//^^^ i32
}"#,
);
}
#[lang = "fn"] #[test]
pub trait Fn<Args>:FnOnce<Args> { fn infer_dyn_fn_once_output() {
extern "rust-call" fn call(&self, args: Args) -> Self::Output; check_types(
} r#"
//- /lib.rs
#[lang = "fn_once"]
pub trait FnOnce<Args> {
type Output;
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}
#[lang = "deref"] fn foo() {
pub trait Deref { let f: dyn FnOnce() -> i32;
type Target: ?Sized; f();
//^^^ i32
fn deref(&self) -> &Self::Target; }"#,
}
#[lang = "owned_box"]
pub struct Box<T: ?Sized> {
inner: *mut T,
}
impl<T: ?Sized> Deref for Box<T> {
type Target = T;
fn deref(&self) -> &T {
&self.inner
}
}
fn foo() {
let f: Box<dyn Fn() -> i32> = box(|| 5);
let x = f();
}
"#
),
@r###"
100..104 'self': Self
106..110 'args': Args
219..223 'self': &Self
225..229 'args': Args
333..337 'self': &Self
503..507 'self': &Box<T>
515..542 '{ ... }': &T
525..536 '&self.inner': &*mut T
526..530 'self': &Box<T>
526..536 'self.inner': *mut T
555..620 '{ ...f(); }': ()
565..566 'f': Box<dyn Fn<(), Output = i32>>
591..600 'box(|| 5)': Box<|| -> i32>
595..599 '|| 5': || -> i32
598..599 '5': i32
610..611 'x': FnOnce::Output<dyn Fn<(), Output = i32>, ()>
614..615 'f': Box<dyn Fn<(), Output = i32>>
614..617 'f()': FnOnce::Output<dyn Fn<(), Output = i32>, ()>
"###
); );
} }

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use log::debug; use log::debug;
use chalk_ir::{fold::shift::Shift, GenericArg, TypeName, CanonicalVarKinds}; use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg, TypeName};
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
use hir_def::{ use hir_def::{
@ -377,16 +377,13 @@ pub(crate) fn struct_datum_query(
let variant = rust_ir::AdtVariantDatum { let variant = rust_ir::AdtVariantDatum {
fields: Vec::new(), // FIXME add fields (only relevant for auto traits), fields: Vec::new(), // FIXME add fields (only relevant for auto traits),
}; };
let struct_datum_bound = rust_ir::AdtDatumBound { let struct_datum_bound = rust_ir::AdtDatumBound { variants: vec![variant], where_clauses };
variants: vec![variant],
where_clauses,
};
let struct_datum = StructDatum { let struct_datum = StructDatum {
// FIXME set ADT kind // FIXME set ADT kind
kind: rust_ir::AdtKind::Struct, kind: rust_ir::AdtKind::Struct,
id: struct_id, id: struct_id,
binders: make_binders(struct_datum_bound, num_params), binders: make_binders(struct_datum_bound, num_params),
flags flags,
}; };
Arc::new(struct_datum) Arc::new(struct_datum)
} }

View file

@ -575,7 +575,10 @@ where
) )
}); });
let value = self.value.to_chalk(db); let value = self.value.to_chalk(db);
chalk_ir::Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) } chalk_ir::Canonical {
value,
binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds),
}
} }
fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {