Commit Graph

613 Commits

Author SHA1 Message Date
Doug Gregor 7d48e98f5e Replace the DeferredCodeGen feature with CodeGenerationModel=<model>
The default code generation model for Embedded Swift is "inlinable".
DeferredCodeGen made the default code generation model
"implementation", and there was no spelling for "interface".

Introduce the experimental feature CodeGenerationModel=<model>, which
can be any of those three options. The default remains "inlinable", but
one can now specify "implementation" (which keeps most everything in
SIL) or "interface" (which only keeps the generic things in SIL). The
"interface" mode is more like non-embedded Swift for non-generic
declarations, emitting them into the IR (only) but not SIL. Generic
declarations would remain in SIL.

Implements rdar://172433062.
2026-05-20 08:35:13 -07:00
Alejandro Alonso 389a6499f4 Merge pull request #86039 from airspeedswift/nonescapable-hashable
Allow Hashable: ~Escapable
2026-04-28 10:31:35 -07:00
Hiroshi Yamauchi 61ed6bd8e0 Use setOnlyIfDifferent for emit-pcm and emit-pch (#88467)
This is to extend https://github.com/swiftlang/swift/pull/87922 to
emit-pcm actions.

This fixes the issue of system modules getting rebuilt repeatedly on
Windows.

Issue: https://github.com/swiftlang/swift/issues/88449
2026-04-16 13:36:10 -07:00
Saleem Abdulrasool 2b8ee6e5a2 test: disallow llvm-bcanalyzer and use new macro
This ensures that we use the correct llvm-bcanalyzer from the just built
compiler tools.
2026-04-13 16:22:02 -07:00
Doug Gregor 7be87567fd Merge pull request #88185 from DougGregor/stdin-input-file-as-swift
Consistently classify "-" as a Swift input file
2026-03-30 14:22:42 -07:00
Doug Gregor 6e2eaee27a Consistently classify "-" as a Swift input file
Fixes rdar://171657301
2026-03-30 09:37:35 -07:00
Henrik G. Olsson 75f076b399 Merge pull request #87775 from Desel72/fix/issue-#87759
Support location markers in DiagnosticVerifier
2026-03-25 16:00:19 -07:00
Desel72 1842f73449 Support location markers in DiagnosticVerifier
Add support for named location markers in the diagnostic verifier's
-verify mode. A marker is defined by placing `// #name` in a comment
and referenced with `@#name` in expected-diagnostic comments.

This enables stable references to diagnostic locations that don't break
when lines are added or removed, and supports cross-file references
where an expected-error in one file references a marker in another.
2026-03-24 14:51:44 +01:00
Doug Gregor 7b2ae7a051 Make tests independent of whether the standard library module has source location info 2026-03-12 08:42:14 -07:00
Tony Allevato 5e68b7cbac Merge pull request #85845 from allevato/json-ast-conformance-modules
[ASTDumper] Print the USR for a protocol conformance's declaring context.
2026-02-11 20:17:07 -05:00
Anthony Latsis abf1ca69b4 Basic: Switch upcoming features to LanguageMode 2026-02-10 16:06:58 +00:00
Henrik G. Olsson f2f15db224 [DiagnosticVerifier] skip over unrelated diags in expansions
This adds support for the following case:
```
expected-expansion@:1:2{{
  expected-warning@3{{foo}}
  expected-sometimes-warning@4{{bar}}
  expected-warning@5{{foobar}}
}}
```
This would work when parsing the additional "sometimes-" prefix, but for
invokations that didn't parse that prefix the "}}" on that line would
close the expansion, and `expected-warning@5{{foobar}}` would be parsed
as a top level statement.
2026-01-30 22:24:14 -08:00
Ian Anderson fc628a8bfb [test][NFC] Add more keys to test SDKSettings files
Every time DarwinSDKInfo reads a new key out of SDKSettings, a boatload of test SDKSettings files need to be updated across several repositories and forks and branches. It’s tedious to be careful to update those with real values so that the tests are properly regression testing older SDKs. It’s important to be careful so that the tests are accurate, e.g. to prevent the scenario where DarwinSDKInfo starts reading a new key out of SDKSettings and assumes that it’s always available everywhere, when in reality it was only added a few releases ago and will break with older SDKs. If the test SDKSettings files continue to be updated ad hoc, it’s going to be really easy to copy/paste a default value everywhere, and then clients will see incorrect behaviors with the real SDKs, or even compiler crashes if the key is unconditionally read. Preemptively add all of the maybe-possibly-compiler relevant keys to the test SDKSettings files from the real SDKs so that the test files are an accurate representation and shouldn't need to be touched in the future. Where the test SDKSettings have intentionally doctored data, add a Comments key explaining what is changed from the real SDK, and alter the SDK name with a tag indicating the change.

rdar://168700857
2026-01-23 02:19:36 -08:00
Ian Anderson 48ab4b0595 [Frontend][Darwin] Use the system prefix from SDK when constructing the default search paths
Some Darwin platforms like DriverKit use a system prefix on all of their search paths. Even though DriverKit isn't supported, add support to get the system prefix from SDKSettings when constructing the default search paths.

This requires the DarwinSDKInfo to be gotten earlier in CompilerInvocation, pass that down to ASTContext through CompilerInstance.

-platform-availability-inheritance-map-path is no longer needed to support visionOS in tests, remove that and its supporting code that gets an alternative DarwinSDKInfo.

rdar://166277280
2026-01-09 12:41:32 -08:00
Ben Cohen 512d5efd55 Allow Hashable: ~Escapable 2025-12-14 16:39:26 -08:00
Ben Cohen 9dd9e96e1d Allow Hashable: ~Copyable (#85748)
Builds on #85746 which covers Equatable.
2025-12-11 14:47:36 -08:00
Ryan Mansfield e60ca698c6 Merge pull request #85440 from rjmansfield/fix-wmo-opt-record-paths
Fix optimization record paths in multi-threaded WMO mode
2025-12-08 16:14:53 -05:00
Henrik G. Olsson 4419ce5bbd Merge pull request #85528 from hnrklssn/diag-verify-fixes
[DiagnosticVerifier] improve output for expansions in clang attributes
2025-12-05 12:51:29 -08:00
Ryan Mansfield 1f5fb751b5 Fix per-file supplementary outputs in multi-threaded WMO mode
In multi-threaded WMO builds, the frontend didn't properly handle per-file
supplementary outputs specified via output file maps or command-line
arguments.

This enables swift-driver to use -supplementary-output-file-map for
per-file outputs in multi-threaded WMO, instead of generating multiple
individual flags that the frontend rejects.
2025-12-05 07:30:02 -05:00
Tony Allevato 770a6b2869 [ASTDumper] Print the USR for a protocol conformance's declaring context.
It's useful to know where a conformance is coming from when doing semantic
analysis. The main motivating use case is this: imagine a module that
declares a type:

```swift
// SomeTypeModule
struct SomeType {}
```

Then a second module that adds a conformance:

```swift
// SomeTypeConformanceModule
extension SomeType: @retroactive Codable {
  // implementation of requirements
}
```

Then a third module that uses that conformance:

```swift
import SomeTypeModule
import SomeTypeConformanceModule

func f() {
  _ = try? JSONEncoder().encode(SomeType())
}
```

There's currently nothing in the printed AST that indicates that the import
of `SomeTypeConformanceModule` is required. Printing the declaring context
for conformances lets us get that signal from the substitution map at the
call site in `f()`.

Also removed a place where we redundantly output `retroactive`.
2025-12-04 15:45:14 -05:00
Tony Allevato 7ec3789cf7 [ASTDumper] Fix malformed JSON for async let _ = ....
By calling `printCommon` twice, this inserts a JSON object into
another JSON object without a key. This asserts inside LLVM's
JSON helper, but only if the compiler is built with assertions
enabled (which Xcode's compiler doesn't).

This also fixes the S-expression version, which is similarly busted:

```
(pattern_entry
  (async_let  type="Int"              (pattern_any type="Int")
  (original_init=call_expr type="Int" ...
```
2025-12-02 16:26:09 -05:00
Tony Allevato 8805d94c79 [ASTDumper] Print decl-refs, not full decls, for function captures.
This avoids infinite recursion when a function captures itself; e.g.,

```swift
func foo() {
  func bar() {
    bar()
  }
  bar()
}
```

It also just avoids printing unnecessarily verbose information,
since those decls would have already been dumped elsewhere in the
tree.
2025-11-24 13:12:02 -05:00
Tony Allevato 7cca6d6a1a [ASTDumper] Don't attempt to compute type USR for ModuleTypes.
`ModuleType`s show up in some rare places, like the left-hand-side of
a `DotSyntaxBaseIgnoredExpr` for a module-qualified function call.
ASTMangler does not support these because they're not real types.
2025-11-24 12:51:08 -05:00
Henrik G. Olsson 62ba94ef12 [DiagnosticVerifier] don't repeat diagnostics in other files
`verifyUnknown()` and `verifyUnrelated()` would not remove the
diagnostics after reporting their errors, leading to the same
diagnostics then being emitted a second time. This removes them from the
list after emitting them, just like `verifyFile()` does.
2025-11-18 00:01:12 -08:00
Henrik G. Olsson b63abd860e [DiagnosticVerifier] emit placeholder when filename is empty
This makes it more explicit and consistent, which are good properties
for test output. It makes it easier both for humans and
update-verify-tests to see what exactly is going on. This does not
affect how diagnostics are displayed to users normally.
2025-11-18 00:00:22 -08:00
Henrik G. Olsson 703fc1c8df [ClangImporter] set zero-byte originalSourceRange for AttributeFromClang
This won't affect diagnostic printing, as the diagnostic engine checks
the GeneratedSourceInfoKind and stops expanding if it's an
AttributeFromClang kind. This helps the diagnostic verifier expand to
the original location in source code however.
2025-11-17 23:59:03 -08:00
Henrik G. Olsson 530588f53d [DiagnosticVerifier] suggest outermost buffername for...
...-verify-additional-file

It's not expected that users add macro expansion buffer names to
-verify-additional-file. The recommended approach is to add the actual
source file that the macro was expanded in, and use expected-expansion.
2025-11-17 23:58:59 -08:00
Henrik G. Olsson bbcba6a8f9 [DiagnosticVerifier] add test with diagnostics in unparsed clang attr 2025-11-17 23:57:33 -08:00
Henrik G. Olsson 040c9e6729 [macros] add -Rmacro-expansions
This adds the -Rmacro-expansions flag. It provides similar functionality
to -dump-macro-expansions, but instead of dumping the macro expansion to
stderr, it emits it line by line as remarks. This is useful for testing
with -verify, where both macro expansion content and warnings need to be
tested at the same time.
2025-11-05 18:45:34 -08:00
Tony Allevato 8c1e0c83ec Merge pull request #85242 from allevato/deterministic-json-ast
[AST] Replace pointers in JSON output with deterministic IDs.
2025-11-01 09:45:23 -04:00
Tony Allevato 5fd1cbb5c0 [AST] Replace pointers in JSON output with deterministic IDs.
There are a few places in the AST dumper where it prints hexadecimal
pointer addresses. This can be useful when dumping nodes in the
debugger, but it makes the output nondeterministic when can cause
problems for build systems that cache outputs.

In the JSON format only, replace these pointers with the string
`"replaced-pointer-XX"`, where `XX` is an increasing integer ID.
We keep track of the pointers that have been replaced so that the
same pointer always maps to the same ID; this means that those
nodes can still be related to each other when reading the AST
later, if needed.
2025-10-31 13:23:14 -04:00
Artem Chikin 4cdbcb8645 [Explicit Module Builds] Always rebuild the target module in explicit -compile-module-from-interface builds.
We have long switched to delegate the checking of whether a module is up-to-date to the build system (SwiftDriver) and stopped serializing file dependencies for interface-built binary modules.

Resolves rdar://162881032
2025-10-20 14:13:37 -07:00
Doug Gregor ce5b1a126d Merge pull request #84392 from rjmansfield/sil-ir-extra-outputs
Add frontend options to write SIL and LLVM IR as additional compilation output
2025-10-10 12:09:38 -07:00
Henrik G. Olsson f343289c45 [DiagnosticVerifier] Fix Twine use after free
`llvm::Twine` is not valid after the end of the statement. Pass it
directly as a parameter without storing it in a local variable to
prevent UAF. Also updates DiagnosticVerifier tests to capture all
relevant output.
2025-10-07 20:19:14 -07:00
Alejandro Alonso 9f2aec5286 Add -verify-ignore-unrelated to a few tests 2025-10-07 13:16:36 -07:00
Ryan Mansfield ba0ce8aea6 Add frontend options to write SIL and LLVM IR as additional compilation output.
This commit adds -sil-output-path and -ir-output-path frontend options that
allow generating SIL and LLVM IR files as supplementary outputs during normal
compilation.

These options can be useful for debugging and analysis tools
workflows that need access to intermediate compilation artifacts
without requiring separate compiler invocations.

Expected behaviour:

Primary File mode:
 - SIL: Generates one .sil file per source file
 - IR: Generates one .ll file per source file

Single-threaded WMO mode:
 - SIL: Generates one .sil file for the entire module
 - IR: Generates one .ll file for the entire module

Multi-threaded WMO mode:
 - SIL: Generates one .sil file for the entire module
 - IR: Generates separate .ll files per source file

File Maps with WMO:
 - Both SIL and IR outputs using first entry's naming, which is
   consistent with the behaviour of other supplementary outputs.

rdar://160297898
2025-10-06 15:45:49 -04:00
Henrik G. Olsson cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
John Hui e97fa2430b [DiagnosticVerifier] Do not capture 'fatal error encountered' errors (#84640)
When the diagnostic verifier encounters a fatal error, it reports:

    <unknown>:0: error: fatal error encountered while in -verify mode

If we capture this, and fail to match this against an expected-error,
the diagnostic verifier complains:

    <unknown>:0: error: unexpected error produced: fatal error encountered while in -verify mode
    <unknown>:0: error: diagnostic produced elsewhere: fatal error encountered while in -verify mode

The current workaround is to use -verify-ignore-unknown, but that in
turn may mask actual errors coming from unknown source locations.
Ignoring these errors about errors removes the need for that workaround.
2025-10-02 11:14:59 -07:00
Daniel Rodríguez Troitiño 4c3471aed5 [test] Allow custom conditions for non-standard compilations (#84632)
If someone has configured their build to add some vendor macro, for
example, the vendor macro will appear in `customConditions`, which will
make the test fail.

Modify the test slightly to check for `customConditions` containing
`"SOMETHING"`, instead of only being `["SOMETHING"]` and nothing else.
This should still allow the test to pass in Swift CI, but allows vendor
macros to work too.
2025-10-02 08:24:12 -07:00
Doug Gregor ae8f9d8234 Add -print-static-build-config to print a static build conformance
Introduce the ability to form a `StaticBuildConfiguration` from
language options. Add a frontend option `-print-static-build-config`
to then print that static build configuration as JSON in a manner that
can be decoded into a `StaticBuildConfiguration`.

Most of the change here is in sinking the bridged ASTContext queries
of language options into a new BridgedLangOptions. The printing of the
static build configuration only has a LangOptions (not an ASTContext),
so this refactoring is required for printing.
2025-09-29 18:42:14 -07:00
Doug Gregor bab1a9cf32 Update test for LibraryEvolution feature 2025-09-23 09:50:10 -07:00
Richard Howell 0b829bfab1 Add error messages for Swift module map parser
Parser errors with large Swift module map files can be hard to diagnose.
Refactor the parser to return an llvm::Error so clearer diagnostics can
be passed to the user.
2025-09-05 13:53:26 -07:00
Allan Shortlidge eb4b049c20 Basic: Fix -print-supported-features.
The check to only include experimental features that are available in
production was inverted.

Resolves rdar://158273047.
2025-08-13 21:33:11 -07:00
Hamish Knight fb7f2d0ff2 [CS] Limit the number of chained @dynamicMemberLookup lookups
Set an upper bound on the number of chained lookups we attempt to
avoid spinning while trying to recursively apply the same dynamic
member lookup to itself.

rdar://157288911
2025-08-01 19:08:04 +01:00
Erik Eckstein 5064297400 InstructionSimplification: simplify negated integer comparsions
Replaces a builtin "xor", which negates its operand comparison
```
  %3 = builtin "cmp_slt_Int64"(%1, %2) : $Builtin.Int1
  %4 = integer_literal $Builtin.Int1, -1
  %5 = builtin "xor_Int1"(%3, %4) : $Builtin.Int1
```
with the negated comparison
```
  %5 = builtin "cmp_ge_Int64"(%1, %2) : $Builtin.Int1
```

This makes LLVM's IPSCCP happy.

rdar://154950810
2025-07-18 07:43:51 +02:00
Arnold Schwaighofer 36f9a7514a Opt-remarks: Only set opt remarks supplementary output files if they are actually
requested via -save-optimization-remarks and we indeed produce them

rdar://154908721
2025-07-09 06:29:45 -07:00
Arnold Schwaighofer b30bd40b83 Add code to create llvm::RemarkStreamer objects for all the LLVMModules in WMO mode
rdar://154403078
2025-07-01 07:19:33 -07:00
Ian Anderson 1197e2ef2e [Frontend][test] Minor changes from "-nostdimport and -nostdlibimport should remove the default framework search paths"
Put the SDK path in a SmallString instead of a StringRef for ease of downstream merging.
Simplify the command lines for the search path test.
2025-05-23 23:02:51 -07:00
Doug Gregor 414adb55ca Add optional language features to the supported features output
Optional language features don't have a specific "-enable-*" flag, because
they're rare and don't fit the same upcoming/experimental distinction. Add
a flag_name field to provide the flag name as well.
2025-05-22 11:07:13 +01:00
Doug Gregor 7f2649ff33 Add the set of diagnostic categories to each migratable feature
The name of a migratable feature might differ from the names of the
diagnostic groups containing the diagnostics that are used to drive
migration for that feature. Provide the set of diagnostic categories
that are associated with each migratable feature as part of the
supported features list.
2025-05-22 11:07:13 +01:00