Commit Graph

927 Commits

Author SHA1 Message Date
Allan Shortlidge
d5fecf19d0 Merge pull request #79976 from tshortli/unique-custom-availability-domains
AST: Unique `CustomAvailabilityDomain` instances
2025-03-13 10:49:22 -07:00
Allan Shortlidge
542986032f AST: Unique CustomAvailabilityDomain instances.
Store `CustomAvailabilityDomain` instances in a folding set on `ASTContext`.
This instances of custom domains to be created without needing to cache them in
disparate locations.
2025-03-12 18:30:45 -07:00
Artem Chikin
e96a690cc7 [Explicit Module Builds] Add '-clang-target-variant' flag
https://github.com/swiftlang/swift/pull/37774 added '-clang-target' which allows us to specify a target triple that only differs from '-target' by the OS version, when we want to provide a different OS version for API availability and type-checking, in order to set a common/unified target triple for the entire Clang module dependency graph, for presenting a unified API surface to the Swift client, serving as a maximum type-checking epoch.

This change adds an equivalent flag for the '-target-variant' configuration, as a mechanism to ensure that the entire module dependency graph presents a consistent os version.
2025-03-11 15:48:06 -07:00
Doug Gregor
b7b5a2a19d [SE-0458] Enable unsafe expressions / attributes / for..in effects by default
With the acceptance of SE-0458, allow the use of unsafe expressions, the
@safe and @unsafe attributes, and the `unsafe` effect on the for..in loop
in all Swift code.

Introduce the `-strict-memory-safety` flag detailed in the proposal to
enable strict memory safety checking. This enables a new class of
feature, an optional feature (that is *not* upcoming or experimental),
and which can be detected via `hasFeature(StrictMemorySafety)`.
2025-02-26 12:30:07 -08:00
Pavel Yaskevich
3cc24f7c19 [Serialization] Serialize a flag that indicates whether ExtensibleEnum feature is supported by a module
When `ExtensibleEnums` flag is set, it's going to be reflected in
the module file produced by the compiler to make sure that consumers
know that non-`@frozen` enumerations can gain new cases in the
future and switching cannot be exhaustive.
2025-02-25 00:05:21 -08:00
Becca Royal-Gordon
d8c8f6577b Merge pull request #79206 from beccadax/this-name-is-not-constructive
Diagnose and forbid invalid Swift names on inits
2025-02-17 20:17:56 -08:00
Steven Wu
719edaf7e2 [BridgingHeader] Fix auto-chaining when only dependency has bridging header
When enable bridging header auto chaining, it is possible for the
compilation to have a PCH file input for the bridging header from a
binary swift module dependency. In this case, we should not report a
bridging header for current module as bridging header can be leaking out
through swiftinterface file.

To fully distinguish the PCH files passed in through different
situation, here are the situations:
* If no chaining is used, only `-import-objc-header` option is used and
  it can be used to pass either a header file or a PCH file depending if
  GeneratePCH job is requested or not.
* If chaining is enabled, `-import-objc-header` is only used to pass the
  header file and `-import-pch` is used to pass PCH file. Chaining mode
  requires PCH generation if bridging header is used.

rdar://144623388
2025-02-12 07:30:14 -08:00
Becca Royal-Gordon
0466d5c0ca Handle diagnostic verifier locations concretely
This commit makes a number of adjustments to how the diagnostic verifier handles source buffers and source locations. Specifically:

• Files named by `-verify-additional-file` are read as late as possible so that if some other component of the compiler has already loaded the file, even in some exotic way (e.g. ClangImporter’s source buffer mirroring), it will use the same buffer.
• Expectation source locations now ignore virtual files and other trickery; they are based on the source buffer and physical location in the file.

Hopefully this will make `-verify-additional-file` work better on Windows. As an unintended side effect, it also changes how expectations work in tests that use `#sourceLocation()`.
2025-02-11 12:05:17 -08:00
Steven Wu
9d59044bb1 [BrdigingHeader] Auto bridging header chaining
Add ability to automatically chaining the bridging headers discovered from all
dependencies module when doing swift caching build. This will eliminate all
implicit bridging header imports from the build and make the bridging header
importing behavior much more reliable, while keep the compatibility at maximum.

For example, if the current module A depends on module B and C, and both B and
C are binary modules that uses bridging header, when building module A,
dependency scanner will construct a new header that chains three bridging
headers together with the option to build a PCH from it. This will make all
importing errors more obvious while improving the performance.
2025-02-05 09:41:04 -08:00
Allan Shortlidge
770ddad742 AST/Sema: Look up custom availability domains by name.
Store the domain definitions defined on the command line on the `ModuleDecl` for
the main module.
2025-01-31 17:31:13 -08:00
Alastair Houghton
18496c5626 [Backtracing] Remove support for implicit import of _Backtracing.
We're going to rename the module to Runtime, and it isn't going to be an
implicit import, so we don't need any of this.

rdar://124913332
2025-01-17 10:09:36 +00:00
Allan Shortlidge
4ea157efdb Frontend: Parse diagnostic options earlier.
Diagnostics may be emitted while parsing command line arguments. This implies
that the options which affect how diagnostics are emitted and presented need to
be parsed first.
2025-01-15 16:34:32 -08:00
Doug Gregor
d593442cc4 Add module trace information for strict memory safety
Extend the module trace format with a field indicating whether a given
module, or any module it depends on, was compiled with strict memory
safety enabled. This separate output from the compiler can be used as
part of an audit to determine what parts of Swift programs are built
with strict memory safety checking enabled.
2024-12-24 12:27:35 -08:00
Ben Langmuir
e7c37655e4 [CAS] Cache symbol graph outputs
The symbol graph output from a module can contain an arbitrary number of
files, depending on what extensions it contains, so cache a list of
symbol graph files with their base name and contents so that they can be
replayed.

rdar://140286819
2024-12-03 13:11:19 -08:00
Hamish Knight
23e3f5f5de Merge pull request #77666 from hamishknight/lets-try-this-again
[AST] Remove `ModuleDecl::addFile`
2024-11-21 20:15:58 +00:00
Pavel Yaskevich
7c8000b3a5 [Frontend] Switch -interface-compiler-version to Version
`SWIFT_COMPILER_VERSION` has more than 4 components and it's
easier to use `Version` API over `VersionTuple` as well.
2024-11-18 15:11:36 -08:00
Hamish Knight
4946c799af [AST] Remove ModuleDecl::addFile
Rather than exposing an `addFile` member on
ModuleDecl, have the `create` members take a
lambda that populates the files for the module.
Once module construction has finished, the files
are immutable.
2024-11-17 14:17:20 +00:00
Hamish Knight
e2ba36f7f4 Factor out ModuleDecl overload of import resolution
This resolves imports for the entire module.
2024-11-17 14:17:20 +00:00
Usama Hameed
305ac20716 Serialize and Deserialize Debug Scopes (#76934)
This patch adds support for serialization and deserialization of
debug scopes.

Debug scopes are serialized in post order and enablement is 
controlled through the experimental-serialize-debug-info flag which
is turned off by default. Functions only referred to by these debug
scopes are deserialized as zombie functions directly.
2024-11-05 11:01:35 -08:00
Meghana Gupta
1985b6cceb [NFC] Add SerializationOptions to ASTContext 2024-10-31 13:40:56 -07:00
Pavel Yaskevich
6cb4b59489 Merge pull request #77216 from xedin/add-swift-compiler-version
[Frontend/AST] Add `-interface-compiler-version` option to frontend/modules
2024-10-28 21:06:47 -07:00
Pavel Yaskevich
84a62fc170 [Frontend/Serialization] Narrow -swift-compiler-version to -interface-compiler-version
It might be unexpected to future users that `-swift-compiler-version`
would produce a version aligned to .swiftinterface instead of one used
to build the .swiftmodule file. To avoid this possible confusion, let's
scope down the version to `-interface-compiler-version` flag and
`SWIFT_INTERFACE_COMPILER_VERSION` option in the module.
2024-10-28 13:45:27 -07:00
Pavel Yaskevich
83995f2ae0 [Frontend] Don't set "current" compiler version for modules built from swiftinterface
If swiftinterface doesn't have `-swift-compiler-version` flag
it means that it was generated with an older version of the
Swift compiler. In such cases it would be incorrect to use
"current" compiler version because the field is intended to
indicate the compiler the swiftinterface was built with.
2024-10-25 17:05:16 -07:00
Slava Pestov
9cd5b03466 Frontend: Fix crash when -stats-output-dir used with -typecheck-module-from-interface
There's no ASTContext in this case, so we just skip initializing stats if
the driver passes this flag down to us.
2024-10-25 16:25:44 -04:00
Pavel Yaskevich
39fb638516 [Frontend/AST] Make it possible to determine Swift compiler version used to build a ModuleDecl 2024-10-24 17:06:15 -07:00
Hamish Knight
2fb72bb212 Merge pull request #76958 from rjmansfield/stats-assert-test
Add -print-zero-stats to fix ensure_no_astgen.swift in release mode
2024-10-16 22:17:30 +01:00
Steven Wu
1eab3b585b [ModuleCache] Prefer module cache passed on the command-line for checker
When setting up the ModuleInterfaceChecker, prefer using the module
cache path from command-line invocation `-module-cache-path` before
falling back to clang options.

Usually those two yield the same result, except for LLDB under direct
cc1 argument mode and explicit module build. Under such mode, the cc1
option for module cache path will be stripped since the output PCMs are
explicit passed as output. When LLDB attempted to do an implicit module
compilation for the swift interface, it will not be able to locate the
module cache path from cc1 arguments. On the other hand, the module
cache option has already be inherited by the sub-instance so it can just
directly be located there.

rdar://137610484
2024-10-16 09:14:47 -07:00
Ryan Mansfield
1001f9eb41 Add -print-zero-stats option and use it in ensure_no_astgen.swift
to verify ExportedSourceFileRequest == 0.

In release mode only non-zero stats are printed by default now.

Fix diagnostic when compiler is built without statistics support.
2024-10-15 23:11:15 -04:00
Steven Wu
cd07d532af [CAS] Use IncludeTreeFileList instead of full CASFS for caching
Use IncludeTreeFileList instead of full feature CASFS for swift
dependency filesystem. This allows smaller CAS based VFS that is smaller
and faster. This is enabled by the CAS enabled compilation does not
need to iterate file system.

rdar://136787368
2024-09-30 16:01:33 -07:00
Slava Pestov
c77fae3a2d Basic: Add -fine-grained-timers flag
By default, -stats-output-dir does not collect per-request timers and
counters, because of overhead.
2024-09-23 18:04:25 -04:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Ryan Mansfield
a097f9f660 Remove additonal unused diagnostics.
Also fix typo in diagnostics verifier error message.
2024-09-12 12:04:54 -04:00
Doug Gregor
b272a05ea9 Merge pull request #76363 from DmT021/wp/print-diagnostic-groups
[Diagnostics] Add -print-diagnostic-groups flag
2024-09-11 13:04:07 -07:00
Dmitrii Galimzianov
a8b71ea97f Add -print-diagnostic-groups flag
This change adds the `-print-diagnostic-groups` flag as described by SE-0443.
2024-09-11 13:34:42 +02:00
Alexis Laferrière
8d28ed4fa9 Merge pull request #76269 from xymus/public-module-name
Diagnostics: Intro the public module name concept to hide support modules from clients
2024-09-09 16:57:12 -07:00
Doug Gregor
08e339b7b4 Merge pull request #74466 from DmT021/wp/no-warning-as-error
[Diagnostics] Add -no-warning-as-error to except a specific warning from being treated as an error
2024-09-09 09:35:05 -07:00
Dmitrii Galimzianov
28883b6654 [Diagnostics] Add -[no-]warning-as-error flags for precise control over warning behavior
This commit adds new compiler options -no-warning-as-error/-warning-as-error which allows users to specify behavior for exact warnings and warning groups.
2024-09-07 01:14:43 +02:00
Dave Lee
d04cfeb44d Serialization: Indicate application extension mode via XCC (#76285)
This fixes the debugger's ability to perform expression evaluation when debugging an 
executable that was built with both under the following circumstances:

1. explicit module build
2. `-application-extension`

The fix is to include `-fapplication-extension` as an XCC field in the swiftmodule. 
This primes the debugger's ClangImporter with the correct flag needed to load the 
explicitly built pcm files generated at build time.
2024-09-06 15:19:34 -07:00
Alexis Laferrière
214da85183 Sema: Keep public module name in ModuleDecl 2024-09-04 16:20:12 -07:00
Steven Wu
6c97736577 [Caching] Do not embed extra ClangTarget in swiftmodule
When direct cc1 mode is used, the cc1 arguments are generated from extra
clang targets so there is no need to add this extra argument.
Furthermore, the `--target=` is a clang driver argument and is not valid
under cc1 mode.

Needed for: rdar://134090397
2024-08-19 12:31:04 -07:00
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
Saleem Abdulrasool
8d9c5e178c Merge pull request #75406 from z2oh/fix-sourcekitd-file-locks-windows
Fix sourcekitd persistent file-locks on Windows
2024-08-01 09:51:17 -07:00
Jeremy Day
221c7039bd Add explicit OpenSourcesAsVolatile option 2024-07-26 17:02:04 -07:00
Jeremy Day
a22419f1d0 Fix sourcekitd persistent file-locks on Windows 2024-07-23 09:59:41 -07:00
Artem Chikin
0d254174c6 Merge pull request #75146 from artemcm/DepScanNoGlobalLLVMOpts
[Dependency Scanning] Avoid configuration (and reset) of LLVM Options by the scanner
2024-07-11 09:45:13 -07:00
Shubham Sandeep Rastogi
d443fdd501 Merge pull request #74202 from rastogishubham/MCCASReplay
Add replay support for MCCAS in Swift.
2024-07-10 15:21:51 -07:00
Artem Chikin
6d0f52152a [Dependency Scanning] Avoid configuration (and reset) of LLVM Options by the scanner
The scanning action does not have any need for handling `-llvm` options, since it will never perform any code-gen. LLVM option processing relies on global option parsing structures, and the scanner has needed to carefully attempt to synchronize access to them. This change guards the configuration of LLVM options to not happen at all for dependency scanning actions, and removes calls to `llvm::cl::ResetAllOptionOccurrences()` that were previously needed.

Resolves rdar://120754696
2024-07-10 14:33:48 -07:00
Shubham Sandeep Rastogi
edae2e66d3 Filter object file from CASOutputBackend in MCCAS.
When MCCAS is used, filter the object file from the CASOutputBackend
because we do not want to write the object file in the CAS, we want
to associate the MCCAS top level CAS Object to the main output of the
CASOutputBackend.
2024-07-09 13:38:08 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00