Commit Graph

655 Commits

Author SHA1 Message Date
Allan Shortlidge
b97ec5bbe5 Sema: Improve MemberImportVisibility diags for for-in loops.
Ensure that source locations are attached to the implicit calls to
`makeIterator()` and `next()` for diagnostics.

Partially resolves rdar://144535697.
2025-04-05 09:47:56 -07:00
Anthony Latsis
08d46d2542 Merge pull request #80473 from AnthonyLatsis/diag_type_attr
DiagnosticEngine: Support `TypeAttribute` diagnostic arguments
2025-04-05 12:25:45 +01:00
Anthony Latsis
99f63ed933 DiagnosticEngine: Support TypeAttribute diagnostic arguments 2025-04-03 01:52:38 +01:00
Erik Eckstein
4d1df28de0 ConstantFolding: add constant folding for some floating point intrinsics
* `sitofp` signed integer to floating point
* `rint` round floating point to integral
* `bitcast` between integer and floating point

Constant folding `bitcast`s also made it necessary to rewrite constant folding for Nan and inf values, because the old code explicitly checked for `bitcast` intrinsics.
Relying on constant folded `bitcast`s makes the new version much simpler.

It is important to constant fold these intrinsics already in SIL because it enables other optimizations.
2025-04-01 18:13:01 +02:00
Anton Korobeynikov
42e530f9ab Add tests 2025-02-24 15:20:46 -08:00
Daniil Kovalev
83a028d105 [AutoDiff] Allow closure differentiation when used as default arg val (#78373)
If the default argument generator (and, consequently, the function taking this default argument) has public visibility, it's OK to have a closure (which always has private visibility) as the default value of the argument.
2025-02-19 22:34:56 -08:00
Daniil Kovalev
1a42a0ce5f [AutoDiff] Support curry thunks differentiation in fragile funcs (#77615)
Inside fragile functions, we expect function derivatives to be public, which could be achieved by either explicitly marking the functions as differentiable or having a public explicit derivative defined for them. This is obviously not
possible for single and double curry thunks which are a special case of `AutoClosureExpr`.

Instead of looking at the thunk itself, we unwrap it and look at the function being wrapped. While the thunk itself and its differentiability witness will not have public visibility, it's not an issue for the case where the function being wrapped (and its witness) have public visibility.

Fixes #54819
Fixes #75776
2025-02-17 14:43:50 -08:00
Joe Groff
27386786a0 Merge pull request #79161 from jckarter/end-apply-coroutine-iterator-invalidation
IRGen: Fix DenseMap interior pointer invalidation bug in IRGenSILFunction::visitEndApply.
2025-02-06 09:39:16 -08:00
Anton Korobeynikov
1e7a1d91fc Emit reabstraction thunks for implicit conversions between T.TangentType and Optional<T>.TangentType (#78076) 2025-02-05 20:57:52 -08:00
Joe Groff
3d779cd789 IRGen: Fix DenseMap interior pointer invalidation bug in IRGenSILFunction::visitEndApply.
Fixes rdar://144216380.
2025-02-05 15:50:09 -08:00
Arnold Schwaighofer
4a2d8dc6a5 Disable test that will block releasing toolchains AutoDiff/validation-test/modify_accessor.swift
Until folks look at whats wrong.

This triggered a use-after-free in IRGen while visiting end_apply on the ASAN bot.

https://ci.swift.org/job/oss-swift-incremental-ASAN-RA-macos/7721/

Likely triggered by the changes in https://github.com/swiftlang/swift/pull/79127 (based on blame list)

rdar://144216380
2025-02-05 07:18:45 -08:00
Erik Eckstein
830565b0f0 - test changes 2025-01-30 17:10:03 -08:00
Michael Gottesman
6058b1d9bd [silgen] Change SILGen to emit ignored_user for emitIgnoredExpr and black hole initialization. 2025-01-22 21:12:36 -08:00
Daniil Kovalev
ccdce9f514 [AutoDiff] Delete wrong FIXMEs (TF-284) from tests (#78663)
In AutoDiff/Sema/differentiable_attr_type_checking.swift, we have a
couple of following FIXMEs:

```
// FIXME(TF-284): Fix unexpected diagnostic.
```

However, the diagnostic is expected for the case of public protocol
requirements: see description https://github.com/swiftlang/swift/pull/30629.
This PR removed the diagnostic for less-than-public-visible requirements,
and the FIXME was initially related to them.

It looks like that the FIXMEs present now are a result of copy-paste and
have no meaning, and the diagnostic is expected and should be present and
does not need to be removed.

Fixes #78609
2025-01-15 20:36:46 -08:00
Daniil Kovalev
0ba886d409 [AutoDiff] Fix adjoint for move_value (#78286)
Since `move_value` is a destroying operation, the adjoint of `y = move_value x` should be `adj[x] += adj[y]; adj[y] = 0` instead of just `adj[x] += adj[y]`.
2025-01-08 00:42:54 -08:00
Daniil Kovalev
95f34ebaca [AutoDiff] Fix derivative for array literal with tuple_element_addr elts (#78355)
The `adjIndex` was not incremented due to missed `remapType`.

Fixes #54214
2025-01-06 16:11:54 -08:00
Anton Korobeynikov
216111172e Explicitly use minimal type expansion for autodiff-related types (e.g. parameters and pullback result types) (#77831)
As autodiff happens on function types it is not in general possible to determine the real expansion context of the function being differentiated. Use of minimal context is a conservative approach that should work even when libraty evolution mode is enabled.

Fixes #55179
2024-12-02 15:02:09 -08:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Daniil Kovalev
c50dcae216 [AutoDiff][test] Enable previously disabled tests related to issue 55492 (#77759)
A couple of tests were disabled due to crash described in
https://github.com/swiftlang/swift/issues/55492. Now the crash is fixed
and the issue is resolved, so tests could be enabled.
2024-11-21 08:02:09 -08:00
Dario Rexin
86377b32b1 Merge pull request #76743 from swiftlang/coro-pa-context
Fix partial apply forwarder emission for coroutines that are methods of structs with type parameters
2024-11-21 03:05:25 -08:00
Doug Gregor
cf68d28400 Merge pull request #76951 from kovdan01/issue60102
[AutoDiff] Enhance performance of custom derivatives lookup
2024-11-11 14:55:54 -08:00
Tony Allevato
97186b0738 Merge pull request #69460 from dylansturg/indexstore
Enable indexing for refs to implicit declarations.
2024-10-30 16:38:37 -04:00
Daniil Kovalev
0d7e37e4ec [AutoDiff] Enhance performance of custom derivatives lookup
In #58965, lookup for custom derivatives in non-primary source files was
introduced. It required triggering delayed members parsing of nominal types in
a file if the file was compiled with differential programming enabled.

This patch introduces `CustomDerivativesRequest` to address the issue.
We only parse delayed members if tokens `@` and `derivative` appear
together inside skipped nominal type body (similar to how member operators
are handled).

Resolves #60102
2024-10-29 12:45:14 +03:00
Daniil Kovalev
194199643f [AutoDiff] Fix assert on missing struct decl on cross-file derivative search (#77183)
Consider:

1. File struct.swift defining `struct Struct` with `static func max` member
2. File derivatives.swift defining `extension Struct` with custom derivative of the `max` function
3. File error.swift defining a differentiable function which uses `Struct.max`.

Previously, when passing error.swift as primary file and derivatives.swift as a secondary file to swift-frontend (and forgetting to pass struct.swift as a secondary file as well), an assertion failure was triggered.

This patch fixes the issue by adding a check against `ErrorType` in `findAutoDiffOriginalFunctionDecl` before calling `lookupMember`.

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
2024-10-29 02:20:50 -07:00
Dylan Sturgeon
a1e888785d Enable indexing for refs to synthesized declarations.
Based on feedback in PR https://github.com/swiftlang/swift/pull/69460, enabling indexing for synthesized decls because they are usable by users and make sense to appear in the indexstore.

Sets `synthesized` on some additional decls:

  - derived `hashInto(...)`
  - Objc properties and methods derived from Objc protocols

https://github.com/apple/swift/issues/67446
2024-10-28 10:07:27 -07:00
swift-ci
f8b387573c Merge remote-tracking branch 'origin/main' into rebranch 2024-10-19 23:34:52 -07:00
Allan Shortlidge
6f55aa4170 Tests: Remove -disable-availability-checking in tests that use opaque types.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of opaque types, instead
of disabling availability checking.
2024-10-19 19:39:18 -07:00
swift-ci
d0cbf2e64d Merge remote-tracking branch 'origin/main' into rebranch 2024-10-01 14:14:25 -07:00
Arnold Schwaighofer
abb065a702 Disable AutoDiff/validation-test/modify_accessor.swift on arm64e
We fail to sign a pointer and so this test currently fails on arm64e.

rdar://136835713
2024-10-01 08:03:49 -07:00
Anton Korobeynikov
6eefd963c6 Fix partial apply forwarder emission for coroutines that are methods
of structs with type parameters. Simplify the code while here
2024-09-26 21:52:17 -07:00
swift-ci
510063d805 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-16 15:56:10 -07:00
Ian Anderson
488c47b6be Import tgmath_h instead of Darwin.C.tgmath
Recent Apple SDKs moved tgmath.h from Darwin.C.tgmath to tgmath_h.

rdar://135982993
2024-09-13 17:56:58 -07:00
swift-ci
e27edcada1 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-21 16:49:14 -07:00
Slava Pestov
39b4bda1dc AST: Introduce SubstFlags::SubstituteLocalArchetypes 2024-08-21 14:23:37 -04:00
swift-ci
43bd40f4d7 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-08 19:11:05 -07:00
Andrew Savonichev
5aa9d3e29b Add partial_apply support for coroutines (#71653)
The patch adds lowering of partial_apply instructions for coroutines.

This pattern seems to trigger a lot of type mismatch errors in IRGen, because
coroutine functions are not substituted in the same way as regular functions
(see the patch 07f03bd2 "Use pattern substitutions to consistently abstract
yields" for more details). 

Other than that, lowering of partial_apply for coroutines is straightforward: we
generate another coroutine that captures arguments passed to the partial_apply
instructions. It calls the original coroutine for yields (first return) and
yields the resulting values. Then it calls the original function's continuation
for return or unwind, and forwards them to the caller as well.

After IRGen, LLVM's Coroutine pass transforms the generated coroutine (along with
all other coroutines) and eliminates llvm.coro.* intrinsics. LIT tests check
LLVM IR after this transformation.

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
Co-authored-by: Arnold Schwaighofer <aschwaighofer@apple.com>
2024-08-08 18:36:42 -07:00
swift-ci
6172e1dc44 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-07 17:34:15 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
swift-ci
0a99f57502 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-26 17:16:44 -07:00
Anton Korobeynikov
a751b076b6 Fixes inject_enum_addr handling: (#75459)
- Ensure it really accumulates the adjoint buffer
- Handle Optional.none case when there is no value to propagate to

Fixes #75280
2024-07-26 17:04:26 -07:00
swift-ci
8f7c33c6a1 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-26 16:33:56 -07:00
Andrew Trick
a1fe258692 Update tests for new trivial moves and extend_lifetimes. 2024-07-26 08:27:48 -07:00
Felipe de Azevedo Piovezan
a321b0afe0 [DebugInfo] Update tests to expect new LLVM debug format 2024-07-23 11:06:12 -07:00
swift-ci
237c10a444 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-11 21:54:45 -07:00
Anton Korobeynikov
9d63e0fa36 [AutoDiff] Correctly propagate optional adjoint through switch_enum (#74985)
Fixes #74978
2024-07-11 21:48:00 -07:00
swift-ci
9ea0f99aa3 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-04 22:33:35 -07:00
Anton Korobeynikov
97ba96b8d8 [AutoDiff] Implement active Optional differentiation (#74977)
Fixes #74972
2024-07-04 22:27:23 -07:00
swift-ci
e650b133a7 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-04 21:13:51 -07:00
Anton Korobeynikov
f8141e27b1 Ensure we are materializing adjoint value into buffer correctly for optionals: (#74964)
- Ue enum $Optional<T.TangentVector>, #Optional.some!enumelt, %wrappedAdjoint : $T for objects
- Use inject_enum_addr %optArgBuf : $*Optional<T.TangentVector>, #Optional.some!enumelt for addresses

Fixes #74841
2024-07-04 20:53:59 -07:00
swift-ci
e072d4635c Merge remote-tracking branch 'origin/main' into rebranch 2024-07-04 20:53:57 -07:00