Commit Graph

13 Commits

Author SHA1 Message Date
Erik Eckstein
10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00
Rintaro Ishizaki
47f18d492e [ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
ASTGen always builds with the host Swift compiler, without requiring
bootstrapping, and is enabled in more places. Move the regex literal
parsing logic there so it is enabled in more host environments, and
makes use of CMake's Swift support. Enable all of the regex literal
tests when ASTGen is built, to ensure everything is working.

Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources,
because they are no longer needed.
2023-11-16 10:59:23 -08:00
Erik Eckstein
ea746479ad SIL Optimizer: rename directory InstructionPasses -> InstructionSimplification 2023-01-16 16:16:51 +01:00
Erik Eckstein
b2b44c0d83 Swift Optimizer: add the StackProtection optimization
It decides which functions need stack protection.

It sets the `needStackProtection` flags on all function which contain stack-allocated values for which an buffer overflow could occur.

Within safe swift code there shouldn't be any buffer overflows.
But if the address of a stack variable is converted to an unsafe pointer, it's not in the control of the compiler anymore.
This means, if there is any `address_to_pointer` instruction for an `alloc_stack`, such a function is marked for stack protection.
Another case is `index_addr` for non-tail allocated memory.
This pattern appears if pointer arithmetic is done with unsafe pointers in swift code.

If the origin of an unsafe pointer can only be tracked to a function argument, the pass tries to find the root stack allocation for such an argument by doing an inter-procedural analysis.
If this is not possible, the fallback is to move the argument into a temporary `alloc_stack` and do the unsafe pointer operations on the temporary.

rdar://93677524
2022-09-08 08:42:25 +02:00
Erik Eckstein
c2ef10661a Swift Optimizer: move function passes which are only used for unit testing to their own TestPasses directory. 2022-08-24 17:54:46 +02:00
Rintaro Ishizaki
d292a95296 [SwiftCompiler/Regex] Use bridged DiagnosticEngine for error reporting
This fixes:
 * An issue where the diagnostic messages were leaked
 * Diagnose at correct position inside the regex literal

To do this:
 * Introduce 'Parse' SwiftCompiler module that is a bridging layer
   between '_CompilerRegexParser' and C++ libParse
 * Move libswiftParseRegexLiteral and libswiftLexRegexLiteral to 'Parse'

Also this change makes 'SwiftCompilerSources/Package.swift' be configured
by CMake so it can actually be built with 'swift-build'.

rdar://92187284
2022-04-22 22:53:46 -07:00
Richard Wei
acca7cb891 Build regex parser by default.
Currently, SwiftCompilerSources' inclusion of the regex parser depends on CMake flag `SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING`. However, in some scenarios we want to build the regex parser as part of the compiler _without_ building the runtime modules. This patch makes building the regex parser the default regardless of `SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING`. Only when the build environment is missing the string processing repo, we skip building the regex parser by setting `SWIFT_BUILD_REGEX_PARSER_IN_COMPILER` to false.
2022-04-12 01:01:15 -07:00
Richard Wei
6022128f47 Rename compiler _RegexParser module to _CompilerRegexParser.
Work around a build failure due to this module having the same name as the runtime _RegexParser module.
2022-04-09 20:45:25 -07:00
Richard Wei
dd7610f2d2 Rename _MatchingEngine module to _RegexParser (#42081)
As the _MatchingEngine module no longer contains the matching engine, this patch renames this module to describe its role more accurately. Because this module primarily contains the AST and the regex parsing logic, I propose we rename it to "_RegexParser".

Also renames the ExperimentalRegex module in SwiftCompilerSources to _RegexParser for consistency. This would prevent errors if sources in _RegexParser used qualified lookup with the module name.
2022-03-31 11:13:18 -07:00
Rintaro Ishizaki
7486cd1c21 [SwiftCompiler] Move common bridging facilities to 'Basic'
A preparation for AST/DiagnosticEngine bridging
2022-02-20 22:06:39 -08:00
Erik Eckstein
40200d6544 Swift Optimizer: add BasicBlock utility data structures and rename StackList
* add `BasicBlockSet`
* add `BasicBlockWorklist`
* add `BasicBlockRange`, which defines a range of blocks from a common dominating “begin” block to a set of “end” blocks.
* add  `InstructionRange`, which is similar to `BasicBlockRange`, just on instruction level. It can be used for value lifetime analysis.
* rename `StackList` -> `Stack` and move it to `Optimizer/DataStructures`
* rename `PassContext.passContext` to `PassContext._bridged`
* add notify-functions to PassContext
2022-01-12 15:47:16 +01:00
Erik Eckstein
ba364a17ef libswift: rename cmake targets and functions
libswift -> swiftCompilerModules or swiftCompilerSources
2021-12-22 11:31:52 +01:00
Erik Eckstein
4beb94c2f9 Rename the libswift directory to SwiftCompilerSources 2021-12-22 09:46:25 +01:00