Commit Graph

597 Commits

Author SHA1 Message Date
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
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
Finagolfin
188a16adcb [android][test] Fix failing Frontend test on Android AArch64 CI 2025-05-19 14:33:46 +05:30
finagolfin
35ee368bb9 [android][test] Fix or disable the remaining failing tests on the Android CI (#81398)
Also, fix and enable `IRGen/lto_autolink` for all non-Wasm targets and
`IRGen/static_initializer` for aarch64.


This should get [the community Android
CI](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-24.04-android-build/)
green
[again](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-24.04-android-arm64/).
2025-05-17 13:27:33 +05:30
Ian Anderson
a6e517e943 [Driver][Frontend] -nostdimport and -nostdlibimport should remove the default framework search paths
-nostdimport and -nostdlibimport only remove the toolchain and usr/lib/swift search paths, and they leave the framework search paths intact. That makes it impossible to get a fully custom SDK environment. Make their behavior match clang's -nostdinc/-nostdlibinc behavior: treat framework and non-framework paths the same. In other words, -nostdinc removes *all* compiler provided search paths, and -nostdlibinc removes *all* SDK search paths.

Rename SkipRuntimeLibraryImportPaths to SkipAllImportPaths, and ExcludeSDKPathsFromRuntimeLibraryImportPaths to SkipSDKImportPaths to reflect their updated behavior.

Move the DarwinImplicitFrameworkSearchPaths handling from SearchPathOptions to CompilerInvocation, where RuntimeLibraryImportPaths is managed. Rename it to just ImplicitFrameworkSearchPaths, and filter for Darwin when it's set up so that all of the clients don't have to do Darwin filtering themselves later.

rdar://150557632
2025-05-12 22:33:48 -07:00
Anthony Latsis
b0b0cff317 [NFC][test] Move scattered DiagnosticVerifier tests into subdirectory 2025-05-07 02:34:46 +01:00
Pavel Yaskevich
1ba077d922 [Feature] Switch migration postfix from :adoption to :migrate 2025-04-28 13:08:24 -07:00
Tony Allevato
a3993f972a Merge pull request #80498 from allevato/json-usr-fixes
[AST] More JSON AST dump improvements.
2025-04-23 15:35:17 -04:00
Pavel Yaskevich
92184584eb Merge pull request #80981 from xedin/supported-features-enabled-in-tweak
[Frontend] SupportedFeatures: print "enabled_in" as a string
2025-04-23 00:18:10 -07:00
Pavel Yaskevich
4909b9baed [Frontend] SupportedFeatures: print "enabled_in" as a string
This is future-proofing the version part of the upcoming
feature. There currently no features that require that
but it's possible that they'd be added in the future.
2025-04-22 00:09:28 -07:00
Pavel Yaskevich
a3d35d54e5 [Frontend] Mark AsyncCallerExecution as an upcoming feature in Swift 7 2025-04-21 11:45:48 -07:00
Pavel Yaskevich
18703d64d6 [Frontend] Rework -emit-supported-features mode into -emit-supported-arguments
The "featues" part was never actually implemented and Swift Driver
is replying on information about arguments, so instead of removing
this mode, let's scope it down to "arguments" to be deprecated in
the future.
2025-04-17 12:33:23 -07:00
Pavel Yaskevich
55bd906906 [Frontend] Add -print-supported-features option
This is a replacement for `-emit-supported-features` that prints
all of the upcoming/experimental features supported by the compiler
with some additional meta information in JSON format to stdout.
2025-04-16 16:34:47 -07:00
Steven Wu
dfa4a27ec8 [SymbolGraph] Make symbol-graph output deterministic
SymbolGraph generation iterating over llvm::DenseSet, which makes the
symbols and relationship fields appear in non-deterministic ordering.
Switch to use llvm::SetVector to preserve the insertion order from
SourceEntityWalker to make order deterministic.

Resolves: https://github.com/swiftlang/swift/issues/59602
2025-04-08 13:39:15 -07:00
Anthony Latsis
2d899d0e73 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def 2025-04-05 12:31:20 +01:00
Tony Allevato
5be2498632 Address review feedback. 2025-04-04 09:12:02 -04:00
Tony Allevato
fa1f82967f Also show the new conformance details in the default dump. 2025-04-03 12:37:15 -04:00
Tony Allevato
718f9f0e9c Improve type USR generation and inheritance dumps.
- For type USRs, use `mapTypeOutOfContext()` to replace primary
  archetypes with type parameters. If the type contains local
  archetypes, replace them with their existential upper bounds.
- For inheritance of types, print the derived semantic information
  instead of the inheritance list as it is written.
- Dump conformance requirements as protocol decl USRs instead of
  type USRs, since the latter involves an existential conversion
  that loses suppressed protocols.
- Fix a small bug in conformance dumping where the `MemberLoading`
  field wasn't propagated to the nested printer, which caused
  protocols to be dumped as simple names instead of USRs.
2025-04-02 08:55:04 -04:00