Files
swift-mirror/include/swift/ConstExtract/ConstExtract.h
T
Steven Wu 1852967fcf [Caching] Support -const-gather-protocols-file correctly
Previously, const-values output is not supported correctly as it is not
captured correctly as a dependency. The load of the input JSON file is
loaded via file system directly, that can cause issues like:
* False cache hit when the file is changed
* Cannot be prefix mapped to allow distributed caching

Try to support the input file by:
* Correctly capture the input
* Create a new driver flag `-const-gather-protocols-list` that can do
  path remapping correctly in swift-driver

rdar://169109358
2026-01-30 13:14:33 -08:00

66 lines
2.2 KiB
C++

//===---- ConstExtract.h -- Gather Compile-Time-Known Values ----*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_CONST_EXTRACT_H
#define SWIFT_CONST_EXTRACT_H
#include "swift/AST/ConstTypeInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include <string>
#include <unordered_set>
#include <vector>
namespace llvm {
class StringRef;
class raw_fd_ostream;
namespace vfs{
class FileSystem;
} // namespace vfs
} // namespace llvm
namespace swift {
class SourceFile;
class DiagnosticEngine;
class ModuleDecl;
} // namespace swift
namespace swift {
/// Parse a list of string identifiers from a file at the given path,
/// representing names of protocols.
bool
parseProtocolListFromFile(llvm::StringRef protocolListFilePath,
DiagnosticEngine &diags,
llvm::vfs::FileSystem &fs,
std::unordered_set<std::string> &protocols);
/// Gather compile-time-known values of properties in nominal type declarations
/// in this file, of types which conform to one of the protocols listed in
/// \c Protocols
std::vector<ConstValueTypeInfo>
gatherConstValuesForPrimary(const std::unordered_set<std::string> &Protocols,
const SourceFile *File);
/// Gather compile-time-known values of properties in nominal type declarations
/// in this module, of types which conform to one of the protocols listed in
/// \c Protocols
std::vector<ConstValueTypeInfo>
gatherConstValuesForModule(const std::unordered_set<std::string> &Protocols,
ModuleDecl *Module);
/// Serialize a collection of \c ConstValueInfos to JSON at the
/// provided output stream.
bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
llvm::raw_ostream &OS);
} // namespace swift
#endif