Skip to content

Commit

Permalink
Rust: attach empty locations to types in the crate graph
Browse files Browse the repository at this point in the history
  • Loading branch information
aibaars committed Dec 9, 2024
1 parent 9337f4f commit 48783f3
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions rust/extractor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ struct Extractor<'a> {
steps: Vec<ExtractionStep>,
}

fn emit_empty_location<E: trap::TrapClass>(trap: &mut TrapFile, entity_label: trap::Label<E>) {
let (file_label, fresh) = trap.writer.global_id("empty;sourcefile");
if fresh {
panic!("empty file not populated");
}
let (location_label, fresh) = trap
.writer
.global_id(&format!("loc,{{{}}},{},{},{},{}", file_label, 0, 0, 0, 0));
if fresh {
panic!("empty location not populated");
}
trap.writer.add_tuple(
"locatable_locations",
vec![entity_label.into(), location_label.into()],
);
}
fn emit_hir_path(
trap: &mut TrapFile,
path: &ra_ap_hir_def::path::Path,
Expand All @@ -49,7 +65,9 @@ fn emit_hir_path(
id: trap::TrapId::Star,
text: Some(segment.name.as_str().to_owned()),
});
trap.emit(generated::PathSegment {
emit_empty_location(trap, name_ref);

let label = trap.emit(generated::PathSegment {
id: trap::TrapId::Star,
generic_arg_list: None,
name_ref: Some(name_ref),
Expand All @@ -58,17 +76,21 @@ fn emit_hir_path(
ret_type: None,
return_type_syntax: None,
type_repr: None,
})
});
emit_empty_location(trap, label);
label
});
let qualifier = path
.mod_path()
.filter(|p| !p.segments().is_empty())
.and_then(|_| path.qualifier().as_ref().map(|p| emit_hir_path(trap, p)));
trap.emit(generated::Path {
let label = trap.emit(generated::Path {
id: trap::TrapId::Star,
qualifier,
part,
})
});
emit_empty_location(trap, label);
label
}
fn emit_hir_fn(
trap: &mut TrapFile,
Expand All @@ -85,46 +107,55 @@ fn emit_hir_fn(
id: trap::TrapId::Star,
type_repr: ret,
});
emit_empty_location(trap, ret);

let self_param = self_type.map(|ty| {
let type_repr = emit_hir_typeref(trap, ty);
trap.emit(generated::SelfParam {
let label = trap.emit(generated::SelfParam {
id: trap::TrapId::Star,
attrs: vec![],
type_repr,
is_mut: false,
lifetime: None,
name: None,
})
});
emit_empty_location(trap, label);
label
});
let params = params
.iter()
.map(|t| {
let type_repr = emit_hir_typeref(trap, t);
trap.emit(generated::Param {
let label = trap.emit(generated::Param {
id: trap::TrapId::Star,
attrs: vec![],
type_repr,
pat: None,
})
});
emit_empty_location(trap, label);
label
})
.collect();
let params = trap.emit(generated::ParamList {
id: trap::TrapId::Star,
params,
self_param,
});
trap.emit(generated::FnPtrTypeRepr {
emit_empty_location(trap, params);
let label = trap.emit(generated::FnPtrTypeRepr {
id: trap::TrapId::Star,
abi: None,
is_async,
is_const,
is_unsafe,
param_list: Some(params),
ret_type: Some(ret),
})
});
emit_empty_location(trap, label);
label
}
fn emit_hir_typeref(trap: &mut TrapFile, ty: &TypeRef) -> Option<trap::Label<generated::TypeRepr>> {
match ty {
let maybe_label = match ty {
TypeRef::Never => Some(
trap.emit(generated::NeverTypeRepr {
id: trap::TrapId::Star,
Expand Down Expand Up @@ -234,7 +265,10 @@ fn emit_hir_typeref(trap: &mut TrapFile, ty: &TypeRef) -> Option<trap::Label<gen
TypeRef::DynTrait(_) => None, // TODO handle dyn
TypeRef::Macro(_) => None,
TypeRef::Error => None,
}
};
maybe_label.inspect(|&label| {
emit_empty_location(trap, label);
})
}

fn emit_variant_data(
Expand Down

0 comments on commit 48783f3

Please sign in to comment.