Skip to content

Commit

Permalink
adding frontend flags
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jan 31, 2025
1 parent a2199ed commit 26f154a
Show file tree
Hide file tree
Showing 282 changed files with 969 additions and 6 deletions.
87 changes: 82 additions & 5 deletions Scripts/soundness/unsafeflags.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash

# Check if bash version < 4
if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
echo "This script requires bash version 4 or higher"
exit 1
fi

# Check if an output directory is provided as an argument
if [ $# -eq 0 ]; then
Expand All @@ -8,13 +14,20 @@ fi

output_directory="$1"

# Create the output directory if it doesn't exist
# Create the output directories
mkdir -p "$output_directory"
mkdir -p "$output_directory/Frontend"

# Get the help output from swiftc
# Get the regular help output from swiftc
help_output=$(swiftc --help-hidden)

# Use awk to handle both single-line and multi-line flag descriptions
# Get frontend help output separately
frontend_help=$(swiftc -frontend -help-hidden)

# Create an array to store unsafe flags
declare -A unsafe_flags

# Process regular flags first
filtered_flags=$(echo "$help_output" | awk '
/^ -[^<][^=]*$/ && !/-[a-zA-Z]+ <.*>/ {
if (NF > 1) {
Expand Down Expand Up @@ -44,12 +57,16 @@ filtered_flags=$(echo "$help_output" | awk '
}
')

# Loop through each flag and write it to a separate file
# Process regular flags and store them in the array
while IFS= read -r line; do
# Split the line into flag and description
original_flag=$(echo "$line" | cut -d'|' -f1)
description=$(echo "$line" | cut -d'|' -f2)

# Store the flag in the array (without the leading -)
flag_name=${original_flag#-}
unsafe_flags["$flag_name"]=1

# Convert the flag to CamelCase
camel_case_flag=$(echo "$original_flag" | awk '{gsub("-", " "); print $0}' | awk '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2)); print}' | sed 's/ //g')

Expand All @@ -66,3 +83,63 @@ while IFS= read -r line; do

echo "File '$output_directory/$camel_case_flag.swift' created."
done <<< "$filtered_flags"

# Process frontend flags, skipping any that exist as unsafe flags
filtered_frontend_flags=$(echo "$frontend_help" | awk '
/^ -[^<][^=]*$/ && !/-[a-zA-Z]+ <.*>/ {
if (NF > 1) {
# Single line case
flag = $1
$1 = ""
desc = substr($0, 2)
print flag "|" desc
} else {
# Multi-line case - store the flag and check next line
flag = $1
getline
if ($0 ~ /^ /) {
# Next line is indented description
desc = substr($0, 26) # 26 spaces indent
print flag "|" desc
} else {
# No description on next line
print flag "|"
# Move back one line since we might have skipped a flag
prev_line = $0
if (prev_line ~ /^ -/) {
print prev_line
}
}
}
}
')

# Process frontend flags
while IFS= read -r line; do
# Split the line into flag and description
original_flag=$(echo "$line" | cut -d'|' -f1)
description=$(echo "$line" | cut -d'|' -f2)

# Check if this flag already exists as an unsafe flag (without the leading -)
flag_name=${original_flag#-}
if [ "${unsafe_flags[$flag_name]}" = "1" ]; then
echo "Skipping frontend flag '$original_flag' as it already exists as an unsafe flag"
continue
fi

# Convert the flag to CamelCase
camel_case_flag=$(echo "$original_flag" | awk '{gsub("-", " "); print $0}' | awk '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2)); print}' | sed 's/ //g')

# Write the flag and its CamelCase version to a separate file in the Frontend directory
{
echo "/// Passes the flag \`$original_flag\`"
if [ ! -z "$description" ]; then
# Capitalize first letter and ensure space after ///
capitalized_desc=$(echo "$description" | sed 's/^[[:lower:]]/\U&/')
echo "/// $capitalized_desc"
fi
echo "struct $camel_case_flag: FrontendFlag { }"
} > "$output_directory/Frontend/$camel_case_flag.swift"

echo "File '$output_directory/Frontend/$camel_case_flag.swift' created."
done <<< "$filtered_frontend_flags"
2 changes: 1 addition & 1 deletion Sources/PackageDSL/GroupBuildable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension GroupBuildable where Output == Self {
///
/// - Parameter array: The array of `Self` to construct the `Output` from.
/// - Returns: An array of `Output` constructed from the given array of `Self`.
static func output(from array: [Self]) -> [Self.Output] {
public static func output(from array: [Self]) -> [Self.Output] {
array
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-alias-module-names-in-module-interface`
/// When emitting a module interface, disambiguate modules using distinct alias names
struct AliasModuleNamesInModuleInterface: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-always-compile-output-files`
/// Always compile output files even it might not change the results
struct AlwaysCompileOutputFiles: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-analyze-requirement-machine`
/// Print out requirement machine statistics at the end of the compilation job
struct AnalyzeRequirementMachine: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-bypass-batch-mode-checks`
/// Bypass checks for batch-mode errors.
struct BypassBatchModeChecks: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-bypass-resilience-checks`
/// Ignore all checks for module resilience.
struct BypassResilienceChecks: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-cas-backend`
/// Enable using CASBackend for object file output
struct CasBackend: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-cas-emit-casid-file`
/// Emit .casid file next to object file when CAS Backend is enabled
struct CasEmitCasidFile: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-check-onone-completeness`
/// Print errors if the compile OnoneSupport module is missing symbols
struct CheckOnoneCompleteness: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-code-complete-call-pattern-heuristics`
/// Use heuristics to guess whether we want call pattern completions
struct CodeCompleteCallPatternHeuristics: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-code-complete-inits-in-postfix-expr`
/// Include initializers when completing a postfix expression
struct CodeCompleteInitsInPostfixExpr: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Passes the flag `-compile-module-from-interface`
struct CompileModuleFromInterface: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-concurrency-model`
/// Ustandard
struct ConcurrencyModel: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-conditional-runtime-records`
/// Allow removal of runtime metadata records (public types, protocol conformances) based on whether they're used or unused
struct ConditionalRuntimeRecords: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-crosscheck-unqualified-lookup`
/// Compare legacy DeclContext- to ASTScope-based unqualified name lookup (for debugging)
struct CrosscheckUnqualifiedLookup: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-cxx-interop-getters-setters-as-properties`
/// Import getters and setters as computed properties in Swift
struct CxxInteropGettersSettersAsProperties: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-cxx-interop-use-opaque-pointer-for-moveonly`
/// Testing flag that will be eliminated soon. Do not use.
struct CxxInteropUseOpaquePointerForMoveonly: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-assert-after-parse`
/// Force an assertion failure after parsing
struct DebugAssertAfterParse: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-assert-immediately`
/// Force an assertion failure immediately
struct DebugAssertImmediately: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-constraints`
/// Debug the constraint-based type checker
struct DebugConstraints: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-crash-after-parse`
/// Force a crash after parsing
struct DebugCrashAfterParse: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-crash-immediately`
/// Force a crash immediately
struct DebugCrashImmediately: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-cycles`
/// Print out debug dumps when cycles are detected in evaluation
struct DebugCycles: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-emit-invalid-swiftinterface-syntax`
/// Write an invalid declaration into swiftinterface files
struct DebugEmitInvalidSwiftinterfaceSyntax: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-generic-signatures`
/// Debug generic signatures
struct DebugGenericSignatures: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-inverse-requirements`
/// Print real requirements in -debug_generic_signatures output
struct DebugInverseRequirements: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-time-expression-type-checking`
/// Dumps the time it takes to type-check each expression
struct DebugTimeExpressionTypeChecking: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debug-time-function-bodies`
/// Dumps the time it takes to type-check each function body
struct DebugTimeFunctionBodies: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debugger-support`
/// Process swift code as if running in the debugger
struct DebuggerSupport: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-debugger-testing-transform`
/// Instrument the code with calls to an intrinsic that record the expected values of local variables so they can be compared against the results from the debugger.
struct DebuggerTestingTransform: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-diagnostics-editor-mode`
/// Diagnostics will be used in editor
struct DiagnosticsEditorMode: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-direct-clang-cc1-module-build`
/// Use the specified -Xcc options to build a PCM by using Clang frontend directly, bypassing the Clang driver
struct DirectClangCc1ModuleBuild: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-access-control`
/// Don't respect access control restrictions
struct DisableAccessControl: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-alias-module-names-in-module-interface`
/// When emitting a module interface, disable disambiguating modules using distinct alias names
struct DisableAliasModuleNamesInModuleInterface: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-all-autolinking`
/// Disable all Swift autolink directives
struct DisableAllAutolinking: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-arc-opts`
/// Don't run SIL ARC optimization passes.
struct DisableArcOpts: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-ast-verifier`
/// Do not run the AST verifier during compilation. NOTE: This lets the user override the default behavior on whether or not the ASTVerifier is run. The default behavior is to run the verifier when asserts are enabled and not run it when asserts are disabled. NOTE: Can not be used if enable-ast-verifier is used as well
struct DisableAstVerifier: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-autolink-frameworks`
/// Disable autolinking against all frameworks
struct DisableAutolinkFrameworks: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-availability-checking`
/// Disable checking for potentially unavailable APIs
struct DisableAvailabilityChecking: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-building-interface`
/// Disallow building binary module from textual interface
struct DisableBuildingInterface: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-clang-spi`
/// Don't import Clang SPIs as Swift SPIs
struct DisableClangSpi: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-clangimporter-source-import`
/// Disable ClangImporter and forward all requests straight the DWARF importer.
struct DisableClangimporterSourceImport: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-collocate-metadata-functions`
/// Disable collocate metadata functions
struct DisableCollocateMetadataFunctions: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-colocate-type-descriptors`
/// Disable colocate type descriptors
struct DisableColocateTypeDescriptors: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-concrete-type-metadata-mangled-name-accessors`
/// Disable concrete type metadata access by mangled name
struct DisableConcreteTypeMetadataMangledNameAccessors: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-constraint-solver-performance-hacks`
/// Disable all the hacks in the constraint solver
struct DisableConstraintSolverPerformanceHacks: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-cross-import-overlay-search`
/// Disable searching for cross import overlay file
struct DisableCrossImportOverlaySearch: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-cross-import-overlays`
/// Do not automatically import declared cross-import overlays.
struct DisableCrossImportOverlays: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-cxx-interop-requirement-at-import`
/// Do not require C++ interoperability to be enabled when importing a Swift module that enables C++ interoperability
struct DisableCxxInteropRequirementAtImport: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-debugger-shadow-copies`
/// Disable debugger shadow copies of local variables.This option is only useful for testing the compiler.
struct DisableDebuggerShadowCopies: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-deserialization-recovery`
/// Don't attempt to recover from missing xrefs (etc) in swiftmodules
struct DisableDeserializationRecovery: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-deserialization-safety`
/// Don't avoid reading potentially unsafe decls in swiftmodules
struct DisableDeserializationSafety: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-diagnostic-passes`
/// Don't run diagnostic passes
struct DisableDiagnosticPasses: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-emit-generic-class-ro_t-list`
/// Disable emission of a section with references to class_ro_t of generic class patterns
struct DisableEmitGenericClassRo_tList: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-experimental-clang-importer-diagnostics`
/// Disable experimental diagnostics when importing C, C++, and Objective-C libraries
struct DisableExperimentalClangImporterDiagnostics: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-experimental-lifetime-dependence-inference`
/// Disable experimental lifetime dependence inference
struct DisableExperimentalLifetimeDependenceInference: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-experimental-opened-existential-types`
/// Disable experimental support for implicitly opened existentials
struct DisableExperimentalOpenedExistentialTypes: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-experimental-parser-round-trip`
/// Disable round trip through the new swift parser
struct DisableExperimentalParserRoundTrip: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-experimental-string-processing`
/// Disable experimental string processing
struct DisableExperimentalStringProcessing: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-fragile-relative-protocol-tables`
/// Disable relative protocol witness tables
struct DisableFragileRelativeProtocolTables: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-generic-metadata-prespecialization`
/// Do not statically specialize metadata for generic types at types that are known to be used in source.
struct DisableGenericMetadataPrespecialization: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-implicit-backtracing-module-import`
/// Disable the implicit import of the _Backtracing module.
struct DisableImplicitBacktracingModuleImport: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-implicit-concurrency-module-import`
/// Disable the implicit import of the _Concurrency module.
struct DisableImplicitConcurrencyModuleImport: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-implicit-cxx-module-import`
/// Disable the implicit import of the C++ Standard Library module.
struct DisableImplicitCxxModuleImport: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-implicit-string-processing-module-import`
/// Disable the implicit import of the _StringProcessing module.
struct DisableImplicitStringProcessingModuleImport: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-implicit-swift-modules`
/// Disable building Swift modules implicitly by the compiler
struct DisableImplicitSwiftModules: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-import-ptrauth-field-function-pointers`
/// Disable import of custom ptrauth qualified field function pointers
struct DisableImportPtrauthFieldFunctionPointers: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-incremental-llvm-codegen`
/// Disable incremental llvm code generation.
struct DisableIncrementalLlvmCodegen: FrontendFlag { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Passes the flag `-disable-infer-public-sendable`
/// Disable inference of Sendable conformances for public structs and enums
struct DisableInferPublicSendable: FrontendFlag { }
Loading

0 comments on commit 26f154a

Please sign in to comment.