Skip to content

Commit 8dd86bd

Browse files
committed
Add even more observability
1 parent 01cf7d5 commit 8dd86bd

File tree

7 files changed

+156
-20
lines changed

7 files changed

+156
-20
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-core/checking/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ indexmap = "2.12.1"
1616
interner = { version = "0.1.0", path = "../interner" }
1717
itertools = "0.14.0"
1818
lowering = { version = "0.1.0", path = "../lowering" }
19+
parsing = { version = "0.1.0", path = "../parsing" }
1920
petgraph = "0.8.3"
2021
pretty = "0.12"
2122
resolving = { version = "0.1.0", path = "../resolving" }
2223
rustc-hash = "2.1.1"
2324
smol_str = "0.3.4"
25+
stabilizing = { version = "0.1.0", path = "../stabilizing" }
2426
sugar = { version = "0.1.0", path = "../sugar" }

compiler-core/checking/src/algorithm/state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use lowering::{
1515
};
1616
use resolving::ResolvedModule;
1717
use rustc_hash::FxHashMap;
18+
use stabilizing::StabilizedModule;
1819
use sugar::{Bracketed, Sectioned};
1920

2021
use crate::algorithm::{constraint, transfer};
@@ -343,6 +344,7 @@ where
343344
pub known_generic: Option<KnownGeneric>,
344345

345346
pub id: FileId,
347+
pub stabilized: Arc<StabilizedModule>,
346348
pub indexed: Arc<IndexedModule>,
347349
pub lowered: Arc<LoweredModule>,
348350
pub grouped: Arc<GroupedModule>,
@@ -363,6 +365,7 @@ where
363365
state: &mut CheckState,
364366
id: FileId,
365367
) -> QueryResult<CheckContext<'a, Q>> {
368+
let stabilized = queries.stabilized(id)?;
366369
let indexed = queries.indexed(id)?;
367370
let lowered = queries.lowered(id)?;
368371
let grouped = queries.grouped(id)?;
@@ -399,6 +402,7 @@ where
399402
known_reflectable,
400403
known_generic,
401404
id,
405+
stabilized,
402406
indexed,
403407
lowered,
404408
grouped,

compiler-core/checking/src/algorithm/term_item.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ where
3939
Q: ExternalQueries,
4040
{
4141
state.with_error_step(ErrorStep::TermDeclaration(item_id), |state| {
42+
let _span = tracing::debug_span!("check_term_signature").entered();
43+
4244
let Some(item) = context.lowered.info.get_term_item(item_id) else {
4345
return Ok(());
4446
};
@@ -57,6 +59,8 @@ where
5759
.map(|(quantified_type, _)| quantified_type)
5860
.unwrap_or(inferred_type);
5961

62+
crate::debug_fields!(state, context, { quantified_type = quantified_type });
63+
6064
let global_type = transfer::globalize(state, context, quantified_type);
6165
state.checked.terms.insert(item_id, global_type);
6266
}
@@ -106,10 +110,14 @@ where
106110
{
107111
let CheckInstance { item_id, constraints, arguments, resolution } = input;
108112
state.with_error_step(ErrorStep::TermDeclaration(item_id), |state| {
113+
let _span = tracing::debug_span!("check_instance").entered();
114+
109115
let Some((class_file, class_item)) = *resolution else {
110116
return Ok(());
111117
};
112118

119+
crate::debug_fields!(state, context, { ?class_file = class_file, ?class_item = class_item });
120+
113121
let TermItemKind::Instance { id: instance_id } = context.indexed.items[item_id].kind else {
114122
return Ok(());
115123
};
@@ -252,6 +260,7 @@ where
252260
{
253261
let CheckValueGroup { item_id, signature, equations } = input;
254262
state.with_error_step(ErrorStep::TermDeclaration(item_id), |state| {
263+
let _span = tracing::debug_span!("check_value_group").entered();
255264
if let Some(signature_id) = signature {
256265
let group_type = term::lookup_file_term(state, context, context.id, item_id)?;
257266

@@ -262,10 +271,12 @@ where
262271
inspect::inspect_signature_core(state, context, group_type, surface_bindings)?;
263272

264273
term::check_equations(state, context, *signature_id, signature, equations)?;
274+
crate::debug_fields!(state, context, { group_type = group_type }, "checking");
265275
Ok(None)
266276
} else {
267277
let (inferred_type, residual_constraints) =
268278
term::infer_equations(state, context, item_id, equations)?;
279+
crate::debug_fields!(state, context, { inferred_type = inferred_type }, "inferring");
269280
Ok(Some(InferredValueGroup { inferred_type, residual_constraints }))
270281
}
271282
})
@@ -290,6 +301,7 @@ where
290301
};
291302

292303
state.with_error_step(ErrorStep::TermDeclaration(item_id), |state| {
304+
let _span = tracing::debug_span!("commit_value_group").entered();
293305
for constraint in result.ambiguous {
294306
let constraint = transfer::globalize(state, context, constraint);
295307
state.insert_error(ErrorKind::AmbiguousConstraint { constraint });
@@ -298,6 +310,7 @@ where
298310
let constraint = transfer::globalize(state, context, constraint);
299311
state.insert_error(ErrorKind::NoInstanceFound { constraint });
300312
}
313+
crate::debug_fields!(state, context, { quantified = result.quantified });
301314
});
302315

303316
let type_id = transfer::globalize(state, context, result.quantified);
@@ -435,6 +448,8 @@ where
435448
} = input;
436449

437450
state.with_error_step(ErrorStep::TermDeclaration(instance_id), |state| {
451+
let _span = tracing::debug_span!("check_instance_member_group").entered();
452+
438453
// Save the current size of the environment for unbinding.
439454
let size = state.type_scope.size();
440455

compiler-core/checking/src/algorithm/type_item.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ where
7373
Q: ExternalQueries,
7474
{
7575
state.with_error_step(ErrorStep::TypeDeclaration(item_id), |state| {
76+
let _span = tracing::debug_span!("check_type_item").entered();
77+
7678
let Some(item) = context.lowered.info.get_type_item(item_id) else {
7779
return Ok(None);
7880
};
@@ -168,6 +170,8 @@ where
168170
state.type_scope.unbind(level);
169171
}
170172

173+
crate::debug_fields!(state, context, { inferred_kind = inferred_kind });
174+
171175
Ok(Some(CheckedTypeItem::Data(CheckedData {
172176
inferred_kind,
173177
kind_variables,
@@ -216,6 +220,8 @@ where
216220
state.type_scope.unbind(variable.level);
217221
}
218222

223+
crate::debug_fields!(state, context, { synonym_type = synonym_type });
224+
219225
Ok(Some(CheckedTypeItem::Synonym(CheckedSynonym {
220226
inferred_kind,
221227
kind_variables,
@@ -287,6 +293,8 @@ where
287293
state.type_scope.unbind(variable.level);
288294
}
289295

296+
crate::debug_fields!(state, context, { ?superclass_count = superclasses.len(), ?member_count = members.len() });
297+
290298
Ok(Some(CheckedTypeItem::Class(CheckedClass {
291299
inferred_kind,
292300
kind_variables,
@@ -630,6 +638,8 @@ where
630638
Q: ExternalQueries,
631639
{
632640
state.with_error_step(ErrorStep::TypeDeclaration(item_id), |state| {
641+
let _span = tracing::debug_span!("check_type_signature").entered();
642+
633643
let Some(item) = context.lowered.info.get_type_item(item_id) else {
634644
return Ok(());
635645
};
@@ -831,6 +841,7 @@ fn check_constructor_arguments<Q>(
831841
where
832842
Q: ExternalQueries,
833843
{
844+
let _span = tracing::debug_span!("check_constructor_arguments").entered();
834845
let mut constructors = vec![];
835846

836847
for item_id in context.indexed.pairs.data_constructors(item_id) {
@@ -840,24 +851,33 @@ where
840851
continue;
841852
};
842853

843-
let mut inferred_arguments = vec![];
844-
845-
for &argument in arguments.iter() {
846-
let inferred_type =
847-
state.with_error_step(ErrorStep::ConstructorArgument(argument), |state| {
848-
let (inferred_type, _) =
849-
kind::check_surface_kind(state, context, argument, context.prim.t)?;
850-
Ok(inferred_type)
851-
})?;
852-
inferred_arguments.push(inferred_type);
853-
}
854+
let arguments = arguments
855+
.iter()
856+
.map(|argument| infer_constructor_argument(state, context, *argument))
857+
.try_collect()?;
854858

855-
constructors.push(CheckedConstructor { item_id, arguments: inferred_arguments });
859+
constructors.push(CheckedConstructor { item_id, arguments });
856860
}
857861

858862
Ok(constructors)
859863
}
860864

865+
fn infer_constructor_argument<Q>(
866+
state: &mut CheckState,
867+
context: &CheckContext<Q>,
868+
argument: lowering::TypeId,
869+
) -> Result<interner::Id<Type>, building_types::QueryError>
870+
where
871+
Q: ExternalQueries,
872+
{
873+
state.with_error_step(ErrorStep::ConstructorArgument(argument), |state| {
874+
let _span = tracing::debug_span!("infer_constructor_argument").entered();
875+
let (inferred_type, _) =
876+
kind::check_surface_kind(state, context, argument, context.prim.t)?;
877+
Ok(inferred_type)
878+
})
879+
}
880+
861881
/// Infers roles for type parameters based on their usage in constructors.
862882
fn infer_roles(
863883
state: &mut CheckState,

compiler-core/checking/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ use indexing::{DeriveId, IndexedModule, InstanceId, TermItemId, TypeItemId};
1313
use lowering::{GroupedModule, LoweredModule};
1414
use resolving::ResolvedModule;
1515
use rustc_hash::FxHashMap;
16+
use stabilizing::StabilizedModule;
1617

1718
use crate::error::CheckError;
1819

1920
pub trait ExternalQueries:
2021
QueryProxy<
22+
Parsed = parsing::FullParsedModule,
23+
Stabilized = Arc<StabilizedModule>,
2124
Indexed = Arc<IndexedModule>,
2225
Lowered = Arc<LoweredModule>,
2326
Grouped = Arc<GroupedModule>,
@@ -76,6 +79,7 @@ impl CheckedModule {
7679
}
7780

7881
pub fn check_module(queries: &impl ExternalQueries, file_id: FileId) -> QueryResult<CheckedModule> {
82+
let _span = trace::check_module(queries, file_id)?;
7983
let prim_id = queries.prim_id();
8084
if file_id == prim_id {
8185
algorithm::check_prim(queries, prim_id)

0 commit comments

Comments
 (0)