mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
After setting up the .swiftsourceinfo file, this patch starts to actually serialize and de-serialize source locations for declaration. The binary format of .swiftsourceinfo currently contains these three records: BasicDeclLocs: a hash table mapping from a USR ID to a list of basic source locations. The USR id could be retrieved from the following DeclUSRs record using an actual decl USR. The basic source locations include a file ID and the results from Decl::getLoc(), ValueDecl::getNameLoc(), Decl::getStartLoc() and Decl::getEndLoc(). The file ID could be used to retrieve the actual file name from the following SourceFilePaths record. Each location is encoded as a line:column pair. DeclUSRS: a hash table mapping from USR to a USR ID used by location records. SourceFilePaths: a hash table mapping from a file ID to actual file name. BasicDeclLocs should be sufficient for most diagnostic cases. If additional source locations are needed, we could always add new source location records without breaking the backward compatibility. When de-serializing the source location from a module-imported decl, we calculate its USR, retrieve the USR ID from the DeclUSRS record, and use the USR ID to look up the basic location list in the BasicDeclLocs record. For more details about .swiftsourceinfo file: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation
96 lines
3.5 KiB
C++
96 lines
3.5 KiB
C++
//===---= SourceInfoFormat.h - The internals of swiftsourceinfo files ----===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file Contains various constants and helper types to deal with serialized
|
|
/// source information (.swiftsourceinfo files).
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SERIALIZATION_SOURCEINFOFORMAT_H
|
|
#define SWIFT_SERIALIZATION_SOURCEINFOFORMAT_H
|
|
|
|
#include "llvm/Bitcode/RecordLayout.h"
|
|
|
|
namespace swift {
|
|
namespace serialization {
|
|
|
|
using llvm::BCArray;
|
|
using llvm::BCBlob;
|
|
using llvm::BCFixed;
|
|
using llvm::BCGenericRecordLayout;
|
|
using llvm::BCRecordLayout;
|
|
using llvm::BCVBR;
|
|
|
|
/// Magic number for serialized source info files.
|
|
const unsigned char SWIFTSOURCEINFO_SIGNATURE[] = { 0xD6, 0x9C, 0xB7, 0x23 };
|
|
|
|
/// Serialized sourceinfo format major version number.
|
|
///
|
|
/// Increment this value when making a backwards-incompatible change, i.e. where
|
|
/// an \e old compiler will \e not be able to read the new format. This should
|
|
/// be rare. When incrementing this value, reset SWIFTDOC_VERSION_MINOR to 0.
|
|
///
|
|
/// See docs/StableBitcode.md for information on how to make
|
|
/// backwards-compatible changes using the LLVM bitcode format.
|
|
const uint16_t SWIFTSOURCEINFO_VERSION_MAJOR = 1;
|
|
|
|
/// Serialized swiftsourceinfo format minor version number.
|
|
///
|
|
/// Increment this value when making a backwards-compatible change that might be
|
|
/// interesting to test for. A backwards-compatible change is one where an \e
|
|
/// old compiler can read the new format without any problems (usually by
|
|
/// ignoring new information).
|
|
const uint16_t SWIFTSOURCEINFO_VERSION_MINOR = 1; // Last change: skipping 0 for testing purposes
|
|
|
|
/// The hash seed used for the string hashes(llvm::djbHash) in a .swiftsourceinfo file.
|
|
const uint32_t SWIFTSOURCEINFO_HASH_SEED = 5387;
|
|
|
|
/// The record types within the DECL_LOCS block.
|
|
///
|
|
/// Be very careful when changing this block; it must remain
|
|
/// backwards-compatible. Adding new records is okay---they will be ignored---
|
|
/// but modifying existing ones must be done carefully. You may need to update
|
|
/// the version when you do so. See docs/StableBitcode.md for information on how
|
|
/// to make backwards-compatible changes using the LLVM bitcode format.
|
|
///
|
|
/// \sa DECL_LOCS_BLOCK_ID
|
|
namespace sourceinfo_block {
|
|
enum RecordKind {
|
|
BASIC_DECL_LOCS = 1,
|
|
DECL_USRS = 96,
|
|
SOURCE_FILE_PATHS,
|
|
};
|
|
|
|
using BasicDeclLocsLayout = BCRecordLayout<
|
|
BASIC_DECL_LOCS, // record ID
|
|
BCVBR<16>, // table offset within the blob (an llvm::OnDiskHashTable)
|
|
BCBlob // map from Decl USR ID to basic source locations.
|
|
>;
|
|
|
|
using DeclUSRSLayout = BCRecordLayout<
|
|
DECL_USRS, // record ID
|
|
BCVBR<16>, // table offset within the blob (an llvm::OnDiskHashTable)
|
|
BCBlob // map from decl USR ID to actual USR
|
|
>;
|
|
|
|
using SourceFilePathsLayout = BCRecordLayout<
|
|
SOURCE_FILE_PATHS, // record ID
|
|
BCVBR<16>, // table offset within the blob (an llvm::OnDiskHashTable)
|
|
BCBlob // map from file ID to actual file path
|
|
>;
|
|
} // namespace sourceinfo_block
|
|
|
|
} // end namespace serialization
|
|
} // end namespace swift
|
|
|
|
#endif
|