Skip to content

Commit be86fb3

Browse files
author
Victor Ding
committed
Add some comments about CrateNum, CrateInfo and .rlink file format
1 parent 358ade9 commit be86fb3

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/librustc_codegen_llvm/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ impl CodegenBackend for LlvmCodegenBackend {
301301
}
302302

303303
if sess.opts.debugging_opts.no_link {
304+
// FIXME: use a binary format to encode the `.rlink` file
304305
let rlink_data = json::encode(&codegen_results).map_err(|err| {
305306
sess.fatal(&format!("failed to encode rlink: {}", err));
306307
})?;

src/librustc_codegen_ssa/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ bitflags::bitflags! {
117117
}
118118

119119
/// Misc info we load from metadata to persist beyond the tcx.
120+
/// Note: though `CrateNum` is only meaningful within the same tcx, information within `CrateInfo`
121+
/// is self-contained. `CrateNum` can be viewed as a unique identifier within a `CrateInfo`, where
122+
/// `used_crate_source` contains all `CrateSource` of the dependents, and maintains a mapping from
123+
/// identifiers (`CrateNum`) to `CrateSource`. The other fields map `CrateNum` to the crate's own
124+
/// additional properties, so that effectively we can retrieve each dependent crate's `CrateSource`
125+
/// and the corresponding properties without referencing information outside of a `CrateInfo`.
120126
#[derive(Debug, RustcEncodable, RustcDecodable)]
121127
pub struct CrateInfo {
122128
pub panic_runtime: Option<CrateNum>,

src/librustc_hir/def_id.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ impl fmt::Display for CrateNum {
8787
}
8888
}
8989

90+
/// As a local identifier, a `CrateNum` is only meaningful within its context, e.g. within a tcx.
91+
/// Therefore, make sure to include the context when encode a `CrateNum`.
9092
impl rustc_serialize::UseSpecializedEncodable for CrateNum {
9193
fn default_encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
9294
e.emit_u32(self.as_u32())

0 commit comments

Comments
 (0)