mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #60139 from artemcm/AddConstValueExtractionPathHandling
Add supplementary output path handling for extracted compile-time-known values
This commit is contained in:
@@ -143,6 +143,8 @@ ERROR(error_mode_cannot_emit_symbol_graph,none,
|
|||||||
"this mode does not support emitting symbol graph files", ())
|
"this mode does not support emitting symbol graph files", ())
|
||||||
ERROR(error_mode_cannot_emit_abi_descriptor,none,
|
ERROR(error_mode_cannot_emit_abi_descriptor,none,
|
||||||
"this mode does not support emitting ABI descriptor", ())
|
"this mode does not support emitting ABI descriptor", ())
|
||||||
|
ERROR(error_mode_cannot_emit_const_values,none,
|
||||||
|
"this mode does not support emitting extracted const values", ())
|
||||||
ERROR(error_mode_cannot_emit_module_semantic_info,none,
|
ERROR(error_mode_cannot_emit_module_semantic_info,none,
|
||||||
"this mode does not support emitting module semantic info", ())
|
"this mode does not support emitting module semantic info", ())
|
||||||
ERROR(cannot_emit_ir_skipping_function_bodies,none,
|
ERROR(cannot_emit_ir_skipping_function_bodies,none,
|
||||||
|
|||||||
@@ -339,6 +339,9 @@ public:
|
|||||||
/// A file containing modules we should perform batch scanning.
|
/// A file containing modules we should perform batch scanning.
|
||||||
std::string BatchScanInputFilePath;
|
std::string BatchScanInputFilePath;
|
||||||
|
|
||||||
|
/// A file containing a list of protocols whose conformances require const value extraction.
|
||||||
|
std::string ConstGatherProtocolListFilePath;
|
||||||
|
|
||||||
/// Debug path mappings to apply to serialized search paths. These are
|
/// Debug path mappings to apply to serialized search paths. These are
|
||||||
/// specified in LLDB from the target.source-map entries.
|
/// specified in LLDB from the target.source-map entries.
|
||||||
PathRemapper SearchPathRemapper;
|
PathRemapper SearchPathRemapper;
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ TYPE("json-dependencies", JSONDependencies, "dependencies.json",
|
|||||||
// Complete feature information for the given Swift compiler.
|
// Complete feature information for the given Swift compiler.
|
||||||
TYPE("json-features", JSONFeatures, "features.json", "")
|
TYPE("json-features", JSONFeatures, "features.json", "")
|
||||||
|
|
||||||
|
// Gathered compile-time-known value information for the given Swift input file as JSON.
|
||||||
|
TYPE("const-values", ConstValues, "swiftconstvalues", "")
|
||||||
|
|
||||||
TYPE("index-data", IndexData, "", "")
|
TYPE("index-data", IndexData, "", "")
|
||||||
TYPE("index-unit-output-path", IndexUnitOutputPath, "", "")
|
TYPE("index-unit-output-path", IndexUnitOutputPath, "", "")
|
||||||
|
|||||||
@@ -147,6 +147,9 @@ struct SupplementaryOutputPaths {
|
|||||||
/// The output path to generate ABI baseline.
|
/// The output path to generate ABI baseline.
|
||||||
std::string ABIDescriptorOutputPath;
|
std::string ABIDescriptorOutputPath;
|
||||||
|
|
||||||
|
/// The output path for extracted compile-time-known value information
|
||||||
|
std::string ConstValuesOutputPath;
|
||||||
|
|
||||||
/// The output path of Swift semantic info for this module.
|
/// The output path of Swift semantic info for this module.
|
||||||
std::string ModuleSemanticInfoOutputPath;
|
std::string ModuleSemanticInfoOutputPath;
|
||||||
|
|
||||||
@@ -188,6 +191,8 @@ struct SupplementaryOutputPaths {
|
|||||||
fn(ModuleSummaryOutputPath);
|
fn(ModuleSummaryOutputPath);
|
||||||
if (!ABIDescriptorOutputPath.empty())
|
if (!ABIDescriptorOutputPath.empty())
|
||||||
fn(ABIDescriptorOutputPath);
|
fn(ABIDescriptorOutputPath);
|
||||||
|
if (!ConstValuesOutputPath.empty())
|
||||||
|
fn(ConstValuesOutputPath);
|
||||||
if (!YAMLOptRecordPath.empty())
|
if (!YAMLOptRecordPath.empty())
|
||||||
fn(YAMLOptRecordPath);
|
fn(YAMLOptRecordPath);
|
||||||
if (!BitstreamOptRecordPath.empty())
|
if (!BitstreamOptRecordPath.empty())
|
||||||
@@ -204,6 +209,7 @@ struct SupplementaryOutputPaths {
|
|||||||
TBDPath.empty() && ModuleInterfaceOutputPath.empty() &&
|
TBDPath.empty() && ModuleInterfaceOutputPath.empty() &&
|
||||||
ModuleSourceInfoOutputPath.empty() &&
|
ModuleSourceInfoOutputPath.empty() &&
|
||||||
ABIDescriptorOutputPath.empty() &&
|
ABIDescriptorOutputPath.empty() &&
|
||||||
|
ConstValuesOutputPath.empty() &&
|
||||||
ModuleSemanticInfoOutputPath.empty() && YAMLOptRecordPath.empty() &&
|
ModuleSemanticInfoOutputPath.empty() && YAMLOptRecordPath.empty() &&
|
||||||
BitstreamOptRecordPath.empty();
|
BitstreamOptRecordPath.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,6 +396,7 @@ public:
|
|||||||
std::string getModuleOutputPathForAtMostOnePrimary() const;
|
std::string getModuleOutputPathForAtMostOnePrimary() const;
|
||||||
std::string
|
std::string
|
||||||
getReferenceDependenciesFilePathForPrimary(StringRef filename) const;
|
getReferenceDependenciesFilePathForPrimary(StringRef filename) const;
|
||||||
|
std::string getConstValuesFilePathForPrimary(StringRef filename) const;
|
||||||
std::string getSerializedDiagnosticsPathForAtMostOnePrimary() const;
|
std::string getSerializedDiagnosticsPathForAtMostOnePrimary() const;
|
||||||
|
|
||||||
/// TBDPath only makes sense in whole module compilation mode,
|
/// TBDPath only makes sense in whole module compilation mode,
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ public:
|
|||||||
bool hasModuleInterfaceOutputPath() const;
|
bool hasModuleInterfaceOutputPath() const;
|
||||||
bool hasPrivateModuleInterfaceOutputPath() const;
|
bool hasPrivateModuleInterfaceOutputPath() const;
|
||||||
bool hasABIDescriptorOutputPath() const;
|
bool hasABIDescriptorOutputPath() const;
|
||||||
|
bool hasConstValuesOutputPath() const;
|
||||||
bool hasModuleSemanticInfoOutputPath() const;
|
bool hasModuleSemanticInfoOutputPath() const;
|
||||||
bool hasModuleSummaryOutputPath() const;
|
bool hasModuleSummaryOutputPath() const;
|
||||||
bool hasTBDPath() const;
|
bool hasTBDPath() const;
|
||||||
|
|||||||
@@ -472,6 +472,7 @@ private:
|
|||||||
static bool canActionEmitModuleSummary(ActionType);
|
static bool canActionEmitModuleSummary(ActionType);
|
||||||
static bool canActionEmitInterface(ActionType);
|
static bool canActionEmitInterface(ActionType);
|
||||||
static bool canActionEmitABIDescriptor(ActionType);
|
static bool canActionEmitABIDescriptor(ActionType);
|
||||||
|
static bool canActionEmitConstValues(ActionType);
|
||||||
static bool canActionEmitModuleSemanticInfo(ActionType);
|
static bool canActionEmitModuleSemanticInfo(ActionType);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -192,6 +192,10 @@ def explicit_swift_module_map
|
|||||||
: Separate<["-"], "explicit-swift-module-map-file">, MetaVarName<"<path>">,
|
: Separate<["-"], "explicit-swift-module-map-file">, MetaVarName<"<path>">,
|
||||||
HelpText<"Specify a JSON file containing information of explicit Swift modules">;
|
HelpText<"Specify a JSON file containing information of explicit Swift modules">;
|
||||||
|
|
||||||
|
def const_gather_protocols_file
|
||||||
|
: Separate<["-"], "const-gather-protocols-file">, MetaVarName<"<path>">,
|
||||||
|
HelpText<"Specify a list of protocols for extraction of conformances' const values'">;
|
||||||
|
|
||||||
def placeholder_dependency_module_map
|
def placeholder_dependency_module_map
|
||||||
: Separate<["-"], "placeholder-dependency-module-map-file">, MetaVarName<"<path>">,
|
: Separate<["-"], "placeholder-dependency-module-map-file">, MetaVarName<"<path>">,
|
||||||
HelpText<"Specify a JSON file containing information of external Swift module dependencies">;
|
HelpText<"Specify a JSON file containing information of external Swift module dependencies">;
|
||||||
|
|||||||
@@ -524,6 +524,14 @@ def emit_parseable_module_interface_path :
|
|||||||
Flags<[FrontendOption, NoInteractiveOption, HelpHidden, ArgumentIsPath,
|
Flags<[FrontendOption, NoInteractiveOption, HelpHidden, ArgumentIsPath,
|
||||||
SupplementaryOutput]>;
|
SupplementaryOutput]>;
|
||||||
|
|
||||||
|
def emit_const_values :
|
||||||
|
Flag<["-"], "emit-const-values">,
|
||||||
|
Flags<[NoInteractiveOption, SupplementaryOutput]>;
|
||||||
|
def emit_const_values_path : Separate<["-"], "emit-const-values-path">,
|
||||||
|
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
|
||||||
|
SupplementaryOutput]>,
|
||||||
|
MetaVarName<"<path>">, HelpText<"Emit the extracted compile-time known values to <path>">;
|
||||||
|
|
||||||
def emit_objc_header : Flag<["-"], "emit-objc-header">,
|
def emit_objc_header : Flag<["-"], "emit-objc-header">,
|
||||||
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>,
|
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>,
|
||||||
HelpText<"Emit an Objective-C header file">;
|
HelpText<"Emit an Objective-C header file">;
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ bool file_types::isTextual(ID Id) {
|
|||||||
case file_types::TY_JSONDependencies:
|
case file_types::TY_JSONDependencies:
|
||||||
case file_types::TY_JSONFeatures:
|
case file_types::TY_JSONFeatures:
|
||||||
case file_types::TY_SwiftABIDescriptor:
|
case file_types::TY_SwiftABIDescriptor:
|
||||||
|
case file_types::TY_ConstValues:
|
||||||
return true;
|
return true;
|
||||||
case file_types::TY_Image:
|
case file_types::TY_Image:
|
||||||
case file_types::TY_Object:
|
case file_types::TY_Object:
|
||||||
@@ -160,6 +161,7 @@ bool file_types::isAfterLLVM(ID Id) {
|
|||||||
case file_types::TY_JSONFeatures:
|
case file_types::TY_JSONFeatures:
|
||||||
case file_types::TY_IndexUnitOutputPath:
|
case file_types::TY_IndexUnitOutputPath:
|
||||||
case file_types::TY_SwiftABIDescriptor:
|
case file_types::TY_SwiftABIDescriptor:
|
||||||
|
case file_types::TY_ConstValues:
|
||||||
return false;
|
return false;
|
||||||
case file_types::TY_INVALID:
|
case file_types::TY_INVALID:
|
||||||
llvm_unreachable("Invalid type ID.");
|
llvm_unreachable("Invalid type ID.");
|
||||||
@@ -212,6 +214,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
|
|||||||
case file_types::TY_JSONFeatures:
|
case file_types::TY_JSONFeatures:
|
||||||
case file_types::TY_IndexUnitOutputPath:
|
case file_types::TY_IndexUnitOutputPath:
|
||||||
case file_types::TY_SwiftABIDescriptor:
|
case file_types::TY_SwiftABIDescriptor:
|
||||||
|
case file_types::TY_ConstValues:
|
||||||
return false;
|
return false;
|
||||||
case file_types::TY_INVALID:
|
case file_types::TY_INVALID:
|
||||||
llvm_unreachable("Invalid type ID.");
|
llvm_unreachable("Invalid type ID.");
|
||||||
|
|||||||
@@ -2082,6 +2082,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
|
|||||||
case file_types::TY_JSONDependencies:
|
case file_types::TY_JSONDependencies:
|
||||||
case file_types::TY_JSONFeatures:
|
case file_types::TY_JSONFeatures:
|
||||||
case file_types::TY_SwiftABIDescriptor:
|
case file_types::TY_SwiftABIDescriptor:
|
||||||
|
case file_types::TY_ConstValues:
|
||||||
// We could in theory handle assembly or LLVM input, but let's not.
|
// We could in theory handle assembly or LLVM input, but let's not.
|
||||||
// FIXME: What about LTO?
|
// FIXME: What about LTO?
|
||||||
Diags.diagnose(SourceLoc(), diag::error_unexpected_input_file,
|
Diags.diagnose(SourceLoc(), diag::error_unexpected_input_file,
|
||||||
|
|||||||
@@ -698,6 +698,7 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
|
|||||||
case file_types::TY_SwiftOverlayFile:
|
case file_types::TY_SwiftOverlayFile:
|
||||||
case file_types::TY_IndexUnitOutputPath:
|
case file_types::TY_IndexUnitOutputPath:
|
||||||
case file_types::TY_SwiftABIDescriptor:
|
case file_types::TY_SwiftABIDescriptor:
|
||||||
|
case file_types::TY_ConstValues:
|
||||||
llvm_unreachable("Output type can never be primary output.");
|
llvm_unreachable("Output type can never be primary output.");
|
||||||
case file_types::TY_INVALID:
|
case file_types::TY_INVALID:
|
||||||
llvm_unreachable("Invalid type ID");
|
llvm_unreachable("Invalid type ID");
|
||||||
@@ -958,6 +959,7 @@ ToolChain::constructInvocation(const BackendJobAction &job,
|
|||||||
case file_types::TY_SwiftOverlayFile:
|
case file_types::TY_SwiftOverlayFile:
|
||||||
case file_types::TY_IndexUnitOutputPath:
|
case file_types::TY_IndexUnitOutputPath:
|
||||||
case file_types::TY_SwiftABIDescriptor:
|
case file_types::TY_SwiftABIDescriptor:
|
||||||
|
case file_types::TY_ConstValues:
|
||||||
llvm_unreachable("Output type can never be primary output.");
|
llvm_unreachable("Output type can never be primary output.");
|
||||||
case file_types::TY_INVALID:
|
case file_types::TY_INVALID:
|
||||||
llvm_unreachable("Invalid type ID");
|
llvm_unreachable("Invalid type ID");
|
||||||
|
|||||||
@@ -654,6 +654,11 @@ bool ArgsToFrontendOptionsConverter::checkUnusedSupplementaryOutputPaths()
|
|||||||
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_abi_descriptor);
|
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_abi_descriptor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!FrontendOptions::canActionEmitConstValues(Opts.RequestedAction) &&
|
||||||
|
Opts.InputsAndOutputs.hasConstValuesOutputPath()) {
|
||||||
|
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_const_values);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!FrontendOptions::canActionEmitModuleSemanticInfo(Opts.RequestedAction) &&
|
if (!FrontendOptions::canActionEmitModuleSemanticInfo(Opts.RequestedAction) &&
|
||||||
Opts.InputsAndOutputs.hasModuleSemanticInfoOutputPath()) {
|
Opts.InputsAndOutputs.hasModuleSemanticInfoOutputPath()) {
|
||||||
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module_semantic_info);
|
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module_semantic_info);
|
||||||
|
|||||||
@@ -335,6 +335,8 @@ SupplementaryOutputPathsComputer::getSupplementaryOutputPathsFromArguments()
|
|||||||
options::OPT_emit_module_summary_path);
|
options::OPT_emit_module_summary_path);
|
||||||
auto abiDescriptorOutput = getSupplementaryFilenamesFromArguments(
|
auto abiDescriptorOutput = getSupplementaryFilenamesFromArguments(
|
||||||
options::OPT_emit_abi_descriptor_path);
|
options::OPT_emit_abi_descriptor_path);
|
||||||
|
auto constValuesOutput = getSupplementaryFilenamesFromArguments(
|
||||||
|
options::OPT_emit_const_values_path);
|
||||||
auto moduleSemanticInfoOutput = getSupplementaryFilenamesFromArguments(
|
auto moduleSemanticInfoOutput = getSupplementaryFilenamesFromArguments(
|
||||||
options::OPT_emit_module_semantic_info_path);
|
options::OPT_emit_module_semantic_info_path);
|
||||||
auto optRecordOutput = getSupplementaryFilenamesFromArguments(
|
auto optRecordOutput = getSupplementaryFilenamesFromArguments(
|
||||||
@@ -367,6 +369,7 @@ SupplementaryOutputPathsComputer::getSupplementaryOutputPathsFromArguments()
|
|||||||
sop.ModuleSourceInfoOutputPath = (*moduleSourceInfoOutput)[i];
|
sop.ModuleSourceInfoOutputPath = (*moduleSourceInfoOutput)[i];
|
||||||
sop.ModuleSummaryOutputPath = (*moduleSummaryOutput)[i];
|
sop.ModuleSummaryOutputPath = (*moduleSummaryOutput)[i];
|
||||||
sop.ABIDescriptorOutputPath = (*abiDescriptorOutput)[i];
|
sop.ABIDescriptorOutputPath = (*abiDescriptorOutput)[i];
|
||||||
|
sop.ConstValuesOutputPath = (*constValuesOutput)[i];
|
||||||
sop.ModuleSemanticInfoOutputPath = (*moduleSemanticInfoOutput)[i];
|
sop.ModuleSemanticInfoOutputPath = (*moduleSemanticInfoOutput)[i];
|
||||||
sop.YAMLOptRecordPath = (*optRecordOutput)[i];
|
sop.YAMLOptRecordPath = (*optRecordOutput)[i];
|
||||||
sop.BitstreamOptRecordPath = (*optRecordOutput)[i];
|
sop.BitstreamOptRecordPath = (*optRecordOutput)[i];
|
||||||
@@ -426,6 +429,12 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
|
|||||||
file_types::TY_SwiftDeps, "",
|
file_types::TY_SwiftDeps, "",
|
||||||
defaultSupplementaryOutputPathExcludingExtension);
|
defaultSupplementaryOutputPathExcludingExtension);
|
||||||
|
|
||||||
|
auto constValuesOutputPath = determineSupplementaryOutputFilename(
|
||||||
|
OPT_emit_const_values,
|
||||||
|
pathsFromArguments.ConstValuesOutputPath,
|
||||||
|
file_types::TY_ConstValues, "",
|
||||||
|
defaultSupplementaryOutputPathExcludingExtension);
|
||||||
|
|
||||||
auto serializedDiagnosticsPath = determineSupplementaryOutputFilename(
|
auto serializedDiagnosticsPath = determineSupplementaryOutputFilename(
|
||||||
OPT_serialize_diagnostics, pathsFromArguments.SerializedDiagnosticsPath,
|
OPT_serialize_diagnostics, pathsFromArguments.SerializedDiagnosticsPath,
|
||||||
file_types::TY_SerializedDiagnostics, "",
|
file_types::TY_SerializedDiagnostics, "",
|
||||||
@@ -470,7 +479,9 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
|
|||||||
|
|
||||||
// There is no non-path form of -emit-abi-descriptor-path
|
// There is no non-path form of -emit-abi-descriptor-path
|
||||||
auto ABIDescriptorOutputPath = pathsFromArguments.ABIDescriptorOutputPath;
|
auto ABIDescriptorOutputPath = pathsFromArguments.ABIDescriptorOutputPath;
|
||||||
|
// There is no non-path form of -emit-module-semantic-info-path
|
||||||
auto ModuleSemanticInfoOutputPath = pathsFromArguments.ModuleSemanticInfoOutputPath;
|
auto ModuleSemanticInfoOutputPath = pathsFromArguments.ModuleSemanticInfoOutputPath;
|
||||||
|
|
||||||
ID emitModuleOption;
|
ID emitModuleOption;
|
||||||
std::string moduleExtension;
|
std::string moduleExtension;
|
||||||
std::string mainOutputIfUsableForModule;
|
std::string mainOutputIfUsableForModule;
|
||||||
@@ -506,6 +517,7 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
|
|||||||
sop.ModuleSourceInfoOutputPath = moduleSourceInfoOutputPath;
|
sop.ModuleSourceInfoOutputPath = moduleSourceInfoOutputPath;
|
||||||
sop.ModuleSummaryOutputPath = moduleSummaryOutputPath;
|
sop.ModuleSummaryOutputPath = moduleSummaryOutputPath;
|
||||||
sop.ABIDescriptorOutputPath = ABIDescriptorOutputPath;
|
sop.ABIDescriptorOutputPath = ABIDescriptorOutputPath;
|
||||||
|
sop.ConstValuesOutputPath = constValuesOutputPath;
|
||||||
sop.ModuleSemanticInfoOutputPath = ModuleSemanticInfoOutputPath;
|
sop.ModuleSemanticInfoOutputPath = ModuleSemanticInfoOutputPath;
|
||||||
sop.YAMLOptRecordPath = YAMLOptRecordPath;
|
sop.YAMLOptRecordPath = YAMLOptRecordPath;
|
||||||
sop.BitstreamOptRecordPath = bitstreamOptRecordPath;
|
sop.BitstreamOptRecordPath = bitstreamOptRecordPath;
|
||||||
@@ -594,6 +606,7 @@ createFromTypeToPathMap(const TypeToPathMap *map) {
|
|||||||
{file_types::TY_YAMLOptRecord, paths.YAMLOptRecordPath},
|
{file_types::TY_YAMLOptRecord, paths.YAMLOptRecordPath},
|
||||||
{file_types::TY_BitstreamOptRecord, paths.BitstreamOptRecordPath},
|
{file_types::TY_BitstreamOptRecord, paths.BitstreamOptRecordPath},
|
||||||
{file_types::TY_SwiftABIDescriptor, paths.ABIDescriptorOutputPath},
|
{file_types::TY_SwiftABIDescriptor, paths.ABIDescriptorOutputPath},
|
||||||
|
{file_types::TY_ConstValues, paths.ConstValuesOutputPath}
|
||||||
};
|
};
|
||||||
for (const std::pair<file_types::ID, std::string &> &typeAndString :
|
for (const std::pair<file_types::ID, std::string &> &typeAndString :
|
||||||
typesAndStrings) {
|
typesAndStrings) {
|
||||||
|
|||||||
@@ -1350,6 +1350,9 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
|
|||||||
if (const Arg *A = Args.getLastArg(OPT_batch_scan_input_file))
|
if (const Arg *A = Args.getLastArg(OPT_batch_scan_input_file))
|
||||||
Opts.BatchScanInputFilePath = A->getValue();
|
Opts.BatchScanInputFilePath = A->getValue();
|
||||||
|
|
||||||
|
if (const Arg *A = Args.getLastArg(OPT_const_gather_protocols_file))
|
||||||
|
Opts.ConstGatherProtocolListFilePath = A->getValue();
|
||||||
|
|
||||||
for (auto A : Args.getAllArgValues(options::OPT_serialized_path_obfuscate)) {
|
for (auto A : Args.getAllArgValues(options::OPT_serialized_path_obfuscate)) {
|
||||||
auto SplitMap = StringRef(A).split('=');
|
auto SplitMap = StringRef(A).split('=');
|
||||||
Opts.DeserializedPathRecoverer.addMapping(SplitMap.first, SplitMap.second);
|
Opts.DeserializedPathRecoverer.addMapping(SplitMap.first, SplitMap.second);
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ std::string CompilerInvocation::getReferenceDependenciesFilePathForPrimary(
|
|||||||
return getPrimarySpecificPathsForPrimary(filename)
|
return getPrimarySpecificPathsForPrimary(filename)
|
||||||
.SupplementaryOutputs.ReferenceDependenciesFilePath;
|
.SupplementaryOutputs.ReferenceDependenciesFilePath;
|
||||||
}
|
}
|
||||||
|
std::string CompilerInvocation::getConstValuesFilePathForPrimary(
|
||||||
|
StringRef filename) const {
|
||||||
|
return getPrimarySpecificPathsForPrimary(filename)
|
||||||
|
.SupplementaryOutputs.ConstValuesOutputPath;
|
||||||
|
}
|
||||||
std::string
|
std::string
|
||||||
CompilerInvocation::getSerializedDiagnosticsPathForAtMostOnePrimary() const {
|
CompilerInvocation::getSerializedDiagnosticsPathForAtMostOnePrimary() const {
|
||||||
return getPrimarySpecificPathsForAtMostOnePrimary()
|
return getPrimarySpecificPathsForAtMostOnePrimary()
|
||||||
|
|||||||
@@ -509,6 +509,12 @@ bool FrontendInputsAndOutputs::hasABIDescriptorOutputPath() const {
|
|||||||
return outs.ABIDescriptorOutputPath;
|
return outs.ABIDescriptorOutputPath;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
bool FrontendInputsAndOutputs::hasConstValuesOutputPath() const {
|
||||||
|
return hasSupplementaryOutputPath(
|
||||||
|
[](const SupplementaryOutputPaths &outs) -> const std::string & {
|
||||||
|
return outs.ConstValuesOutputPath;
|
||||||
|
});
|
||||||
|
}
|
||||||
bool FrontendInputsAndOutputs::hasModuleSemanticInfoOutputPath() const {
|
bool FrontendInputsAndOutputs::hasModuleSemanticInfoOutputPath() const {
|
||||||
return hasSupplementaryOutputPath(
|
return hasSupplementaryOutputPath(
|
||||||
[](const SupplementaryOutputPaths &outs) -> const std::string & {
|
[](const SupplementaryOutputPaths &outs) -> const std::string & {
|
||||||
|
|||||||
@@ -582,6 +582,48 @@ bool FrontendOptions::canActionEmitABIDescriptor(ActionType action) {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool FrontendOptions::canActionEmitConstValues(ActionType action) {
|
||||||
|
switch (action) {
|
||||||
|
case ActionType::NoneAction:
|
||||||
|
case ActionType::Parse:
|
||||||
|
case ActionType::ResolveImports:
|
||||||
|
case ActionType::DumpParse:
|
||||||
|
case ActionType::DumpInterfaceHash:
|
||||||
|
case ActionType::DumpAST:
|
||||||
|
case ActionType::EmitSyntax:
|
||||||
|
case ActionType::PrintAST:
|
||||||
|
case ActionType::PrintASTDecl:
|
||||||
|
case ActionType::DumpScopeMaps:
|
||||||
|
case ActionType::DumpTypeRefinementContexts:
|
||||||
|
case ActionType::DumpTypeInfo:
|
||||||
|
case ActionType::CompileModuleFromInterface:
|
||||||
|
case ActionType::TypecheckModuleFromInterface:
|
||||||
|
case ActionType::Immediate:
|
||||||
|
case ActionType::REPL:
|
||||||
|
case ActionType::EmitPCM:
|
||||||
|
case ActionType::DumpPCM:
|
||||||
|
case ActionType::ScanDependencies:
|
||||||
|
case ActionType::PrintVersion:
|
||||||
|
case ActionType::PrintFeature:
|
||||||
|
return false;
|
||||||
|
case ActionType::Typecheck:
|
||||||
|
case ActionType::MergeModules:
|
||||||
|
case ActionType::EmitModuleOnly:
|
||||||
|
case ActionType::EmitPCH:
|
||||||
|
case ActionType::EmitSILGen:
|
||||||
|
case ActionType::EmitSIL:
|
||||||
|
case ActionType::EmitSIBGen:
|
||||||
|
case ActionType::EmitSIB:
|
||||||
|
case ActionType::EmitIRGen:
|
||||||
|
case ActionType::EmitIR:
|
||||||
|
case ActionType::EmitBC:
|
||||||
|
case ActionType::EmitAssembly:
|
||||||
|
case ActionType::EmitObject:
|
||||||
|
case ActionType::EmitImportedModules:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
llvm_unreachable("unhandled action");
|
||||||
|
}
|
||||||
bool FrontendOptions::canActionEmitModule(ActionType action) {
|
bool FrontendOptions::canActionEmitModule(ActionType action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ActionType::NoneAction:
|
case ActionType::NoneAction:
|
||||||
|
|||||||
@@ -693,6 +693,42 @@ static void emitSwiftdepsForAllPrimaryInputsIfNeeded(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool emitConstValuesForWholeModuleIfNeeded(
|
||||||
|
CompilerInstance &Instance) {
|
||||||
|
const auto &Invocation = Instance.getInvocation();
|
||||||
|
const auto &frontendOpts = Invocation.getFrontendOptions();
|
||||||
|
if (!frontendOpts.InputsAndOutputs.hasConstValuesOutputPath())
|
||||||
|
return false;
|
||||||
|
std::error_code EC;
|
||||||
|
assert(frontendOpts.InputsAndOutputs.isWholeModule() &&
|
||||||
|
"'emitConstValuesForWholeModule' only makes sense when the whole module can be seen");
|
||||||
|
auto ConstValuesFilePath = frontendOpts.InputsAndOutputs
|
||||||
|
.getPrimarySpecificPathsForAtMostOnePrimary().SupplementaryOutputs
|
||||||
|
.ConstValuesOutputPath;
|
||||||
|
llvm::raw_fd_ostream OS(ConstValuesFilePath, EC, llvm::sys::fs::OF_None);
|
||||||
|
OS << "{}\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void emitConstValuesForAllPrimaryInputsIfNeeded(
|
||||||
|
CompilerInstance &Instance) {
|
||||||
|
const auto &Invocation = Instance.getInvocation();
|
||||||
|
|
||||||
|
for (auto *SF : Instance.getPrimarySourceFiles()) {
|
||||||
|
const std::string &ConstValuesFilePath =
|
||||||
|
Invocation.getConstValuesFilePathForPrimary(
|
||||||
|
SF->getFilename());
|
||||||
|
if (ConstValuesFilePath.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Emit extracted values
|
||||||
|
std::error_code EC;
|
||||||
|
llvm::raw_fd_ostream OS(ConstValuesFilePath, EC, llvm::sys::fs::OF_None);
|
||||||
|
OS << "{}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool writeModuleSemanticInfoIfNeeded(CompilerInstance &Instance) {
|
static bool writeModuleSemanticInfoIfNeeded(CompilerInstance &Instance) {
|
||||||
const auto &Invocation = Instance.getInvocation();
|
const auto &Invocation = Instance.getInvocation();
|
||||||
const auto &frontendOpts = Invocation.getFrontendOptions();
|
const auto &frontendOpts = Invocation.getFrontendOptions();
|
||||||
@@ -900,6 +936,10 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
|
|||||||
{
|
{
|
||||||
hadAnyError |= writeModuleSemanticInfoIfNeeded(Instance);
|
hadAnyError |= writeModuleSemanticInfoIfNeeded(Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
hadAnyError |= emitConstValuesForWholeModuleIfNeeded(Instance);
|
||||||
|
}
|
||||||
return hadAnyError;
|
return hadAnyError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1072,6 +1112,9 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
|
|||||||
// Emit Make-style dependencies.
|
// Emit Make-style dependencies.
|
||||||
emitMakeDependenciesIfNeeded(Instance.getDiags(),
|
emitMakeDependenciesIfNeeded(Instance.getDiags(),
|
||||||
Instance.getDependencyTracker(), opts);
|
Instance.getDependencyTracker(), opts);
|
||||||
|
|
||||||
|
// Emit extracted constant values for every file in the batch
|
||||||
|
emitConstValuesForAllPrimaryInputsIfNeeded(Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool printSwiftVersion(const CompilerInvocation &Invocation) {
|
static bool printSwiftVersion(const CompilerInvocation &Invocation) {
|
||||||
|
|||||||
17
test/Frontend/emit-const-values-file.swift
Normal file
17
test/Frontend/emit-const-values-file.swift
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// RUN: %empty-directory(%t)
|
||||||
|
// RUN: echo 'print("Hello, World!")' >%t/main.swift
|
||||||
|
// RUN: cd %t
|
||||||
|
|
||||||
|
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/main.swiftconstvalues -primary-file %t/main.swift
|
||||||
|
// RUN: test -f %t/main.swiftconstvalues
|
||||||
|
|
||||||
|
// RUN: echo '"%/t/main.swift": { const-values: "%/t/foo.swiftconstvalues" }' > %/t/filemap.json
|
||||||
|
// RUN: %target-swift-frontend -typecheck -supplementary-output-file-map %/t/filemap.json -primary-file %/t/main.swift
|
||||||
|
// RUN: test -f %t/foo.swiftconstvalues
|
||||||
|
|
||||||
|
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/main.module.swiftconstvalues %t/main.swift
|
||||||
|
// RUN: test -f %t/main.module.swiftconstvalues
|
||||||
|
|
||||||
|
// RUN: echo '{"%/t/main.swift": { const-values: "%/t/main.module.swiftconstvalues" }}' > %/t/filemap.json
|
||||||
|
// RUN: %target-swift-frontend -typecheck -supplementary-output-file-map %/t/filemap.json %/t/main.swift
|
||||||
|
// RUN: test -f %t/main.module.swiftconstvalues
|
||||||
@@ -33,3 +33,6 @@
|
|||||||
// PARSE_NO_PRIVATE_INTERFACE: error: this mode does not support emitting module interface files{{$}}
|
// PARSE_NO_PRIVATE_INTERFACE: error: this mode does not support emitting module interface files{{$}}
|
||||||
// RUN: not %target-swift-frontend -emit-silgen -emit-private-module-interface-path %t %s 2>&1 | %FileCheck -check-prefix=SILGEN_NO_PRIVATE_INTERFACE %s
|
// RUN: not %target-swift-frontend -emit-silgen -emit-private-module-interface-path %t %s 2>&1 | %FileCheck -check-prefix=SILGEN_NO_PRIVATE_INTERFACE %s
|
||||||
// SILGEN_NO_PRIVATE_INTERFACE: error: this mode does not support emitting module interface files{{$}}
|
// SILGEN_NO_PRIVATE_INTERFACE: error: this mode does not support emitting module interface files{{$}}
|
||||||
|
|
||||||
|
// RUN: not %target-swift-frontend -parse -emit-const-values-path %t %s 2>&1 | %FileCheck -check-prefix=PARSE_NO_CONST_VALUES %s
|
||||||
|
// PARSE_NO_CONST_VALUES: error: this mode does not support emitting extracted const values{{$}}
|
||||||
|
|||||||
Reference in New Issue
Block a user