Commit Graph

103491 Commits

Author SHA1 Message Date
Alex Hoppen
c6c40de73d [IDE] Pass a SourceRange instead of a CharSourceRange in SemaAnnotator::passReference
Most `SemaAnnotator`s don’t actually care about the char source range. Instead, they only care about the start location of the reference, which is also included in `SourceRange`. Computing a `CharSourceRange` from a `SourceRange` is kind of expensive because it needs to start a new lexer.

To avoid this overhead, pass `SourceRange` to `SemaAnnotator::passReference` and related functions and let the clients compute the `CharSourceRange` when needed.

This reduces the overhead of index-while-building by about 10%.
2025-06-04 18:01:47 +02:00
Slava Pestov
c61a4fe333 Merge pull request #81949 from slavapestov/missing-part-of-se-0346
Sema: Implement missing part of SE-0346
2025-06-04 09:24:19 -04:00
Konrad `ktoso` Malawski
84c2c38556 Merge pull request #81958 from ktoso/wip-distributed-irgenmangler-more 2025-06-04 21:02:52 +09:00
Gabor Horvath
d5faddaa9b [cxx-interop] Support Swiftifying C++ constructors
Unfortunately, there is no common abstraction for initializers and
functions in SwiftSyntax, so this PR rolls our own. Alternatively, we
could probably achieve something similar with a new protocol, but we
only needed a handful of fields so this change keeps it simple.

rdar://152112660
2025-06-04 10:06:16 +01:00
Ian Anderson
ae7f9c2266 [Option] Add a feature flag for -Isystem
swift-build needs a flag to know if -Isystem is available.

rdar://152540225
2025-06-03 17:23:44 -07:00
Konrad 'ktoso' Malawski
cc532fbbd9 [Distributed] More IRGenMangler fixes for distributed thunks
We also need to mangle the dispatch thunks to distributed thunks
uniquely.
2025-06-04 08:40:19 +09:00
Nate Chandler
c41fd47f1f [DestroyAddrHoisting] Skip init_enum_data_addrs.
A destroy of an `init_enum_data_addr` is not equivalent to a destroy of
the whole enum's address.  Treat such destroys just like destroys of
`struct_element_addr`s are treated: by bailing out.

rdar://152431332
2025-06-03 15:32:42 -07:00
Nate Chandler
f3c28515b1 [Gardening] Tweaked comments. 2025-06-03 15:32:26 -07:00
Doug Gregor
9957f5240f Merge pull request #81933 from DougGregor/break-isolated-conformance-reference-cycle 2025-06-03 14:54:16 -07:00
Allan Shortlidge
17fa8b9cb5 Merge pull request #81946 from tshortli/warnings
Fix various warnings
2025-06-03 14:37:40 -07:00
Slava Pestov
185a91d955 Sema: Handle nested compositions and parameterized protocols in diagnoseRetroactiveConformances() 2025-06-03 17:28:19 -04:00
Slava Pestov
cd5ecbee16 Sema: Implement missing part of SE-0346
The proposal states that this should work, but this was never
implemented:

    protocol P<A> {
      associatedtype A
    }

    struct S: P<Int> {}

- Fixes https://github.com/swiftlang/swift/issues/62906.
- Fixes rdar://91842338.
2025-06-03 17:28:19 -04:00
eeckstein
50c6824263 Merge pull request #81935 from eeckstein/min-pointer-value-option
IRGen: add an option `-min-valid-pointer-value` to override the target's LeastValidPointerValue
2025-06-03 19:21:58 +02:00
Allan Shortlidge
14341285cb Parse: Fix unused variable warning. 2025-06-03 09:45:46 -07:00
Allan Shortlidge
3914b35623 AST: Fix unused variable warning. 2025-06-03 09:45:25 -07:00
Allan Shortlidge
453f99e929 ASTGen: Fix 'never mutated' warnings. 2025-06-03 09:44:57 -07:00
Pavel Yaskevich
b189b8a320 Merge pull request #81936 from xedin/improve-optional-wrappedValue-mismatch-diagnostics
[CSSimplify] Fix `matchDeepEqualityTypes` to allow fixing of optionals
2025-06-03 09:19:50 -07:00
Meghana Gupta
d1a97f1b0d Merge pull request #81879 from meg-gupta/fixdeserialization
Fix deserialization of lifetime dependencies on ast function types
2025-06-03 08:56:54 -07:00
Saleem Abdulrasool
51645d00a3 Merge pull request #81754 from compnerd/closed
IRGen: honour `-static-libclosure` in block creation
2025-06-03 08:35:07 -07:00
Susana Monteiro
e910d9b2f8 Merge pull request #81709 from swiftlang/susmonteiro/ambiguous-use-of-method
[cxx-interop] Fix ambiguous methods in long chains of inheritance
2025-06-03 15:50:28 +01:00
Allan Shortlidge
adedf15270 Merge pull request #81922 from tshortli/visionos-availability-remap-regression
AST/Sema: Fix remapping of iOS availability in diagnostics for visionOS
2025-06-03 04:58:31 -07:00
Hamish Knight
d00a3b5764 Merge pull request #81901 from hamishknight/hastype
[CS] Check `hasType` in `isPlaceholderVar`
2025-06-03 11:01:54 +01:00
Konrad `ktoso` Malawski
78c68ee069 Merge pull request #81805 from ktoso/wip-distributed-fixes 2025-06-03 18:22:22 +09:00
Pavel Yaskevich
7305275dbd [CSSimplify] Produce tailored fixes for a few generic argument mismatches
- Mismatch in tuple element position should reference whole tuple
  with a note for mismatch position;
- Situations where optional object type is not a class but matched
  against `AnyObject` have a tailored fix.
2025-06-03 00:49:06 -07:00
Pavel Yaskevich
27c28d4d64 [CSSimplify] Fix matchDeepEqualityTypes to allow fixing of optionals
Attempting to propagate generic argument failures up is not always
reliable, `matchDeepEqualityTypes` should avoid using `TMF_ApplyingFix`
while dealing with optionals and instead let `repairFailures` decide
whether to use generic arguments mismatch fix to a more general one.
2025-06-03 00:48:59 -07:00
Erik Eckstein
c02bc2d421 IRGen: add an option -min-valid-pointer-value to override the target's LeastValidPointerValue
The LeastValidPointerValue is hard-coded in the runtime.
Therefore this option is only available in embedded swift - which doesn't have a runtime.

rdar://151755654
2025-06-03 09:27:35 +02:00
Pavel Yaskevich
65e83a8bb1 [CSSimplify] Increase impact of a generic argument mismatch if mismatch is contextual
If generic arguments mismatch ends up being recorded on the result
of the chain or `try` expression it means that there is a contextual
conversion mismatch.

For optional conversions the solver currently generates a disjunction
with two choices - bind and optional-to-optional conversion which is
anchored on the contextual expression. If we can get a fix recorded
there that would result in a better diagnostic. It's only possible
for optional-to-optional choice because it doesn't bind the
variable immediately, so we need to downgrade direct fixes to prevent
`bind` choice from considered better.
2025-06-02 23:49:52 -07:00
Doug Gregor
7472a0ca38 Split conformance isolation request to eliminate a reference cycle
Inference of conformance isolation needs to check whether all of the
witnesses are nonisolated. However, witness checking looks at
conformance isolation. To break this reference cycle, split the
conformance isolation request into two requests: a "raw" request that
looks at explicitly-specified isolation, and the existing one that
also performs inference. The existing one builds on the "raw" one, as
does a separate path for the conformance checker.

Fixes rdar://152461344.
2025-06-02 23:37:58 -07:00
Artem Chikin
4fb4945ab9 Merge pull request #81908 from artemcm/FixImplicitBuildCXXInteropCycle
[C++Interop] Do not query C++ Standard Library Swift overlays when building Swift modules which were built without C++ interop
2025-06-02 23:26:27 -07:00
Slava Pestov
10f0f6108c Merge pull request #81913 from slavapestov/fix-rdar151479861
AST: Fix crash when type parameter is fixed to an existential
2025-06-03 00:00:03 -04:00
Ian Anderson
9a4ba6f5e3 Merge pull request #81914 from ian-twilightcoder/Isystem-fix
[Frontend] -Isystem doesn't work everywhere -I does
2025-06-02 20:02:09 -07:00
Allan Shortlidge
f4b4dc9889 AST/Sema: Fix remapping of iOS availability in diagnostics for visionOS.
When compiling for visionOS, iOS availability attributes are remapped into the
visionOS availability domain automatically. While the version remapping was
being performed correctly, there was a regression that caused the platform name
to be printed incorrectly in many diagnostics. Whenever an iOS version is
remapped to a visionOS version, availability diagnostics will now present
those versions as visionOS versions instead of iOS versions.

Resolves rdar://146293165.
2025-06-02 17:55:38 -07:00
Pavel Yaskevich
71a8d8d8a4 [CSDiagnostics] Attempt fix-its for contextual generic argument mismatches 2025-06-02 17:39:56 -07:00
Meghana Gupta
36f3574f9c Fix deserialization of lifetime dependencies on ast function types
While deserializing AST function types FunctionType and GenericFunctionType which include
lifetime dependencies and an implicit self parameter, we don't correctly populate
ASTExtInfoBuilder.lifetimeDependencies.  We end up reading one dependency less due to
incorrect index calculation.

Unlike SILFunctionType, AST function types FunctionType and GenericFunctionType
do not include implicit self in their param list. They represent methods with
implicit self as like: `(Self) -> (Args...) -> Result` and don't have any information
to indicate they may have implicit self. Since we use number of parameters while
deserializing lifetime dependencies, we go wrong for such function types.

Serialize the length of parameter indices, so that lifetime dependencies can be
deserialized to that length.

rdar://151768216
2025-06-02 17:29:05 -07:00
Doug Gregor
bfa991d5b3 Merge pull request #81910 from DougGregor/unsafe-string-interpolation
[Strict memory safety] Adjust "unsafe" location for string interpolations
2025-06-02 17:16:10 -07:00
Michael Gottesman
7d82d72b22 Merge pull request #81909 from gottesmm/pr-775f782ff711827a2a0dce73a522b6eb9bc2d484
[rbi] Lookthrough an invocation of DistributedActor.asLocalActor when determining actor instances.
2025-06-02 17:04:18 -07:00
Slava Pestov
d8e418a0f9 AST: Fix crash when type parameter is substituted with an existential
getContextSubstitutionMap() didn't handle the case where getAnyNominal()
returns a ProtocolDecl. This should not take the "fast path", which is
only suitable for concrete nominals.

This manifested as a crash-on-invalid -- the user probably meant to write
"T.Value: Collection" rather than "T.Value == Collection".

Fixes rdar://151479861.
2025-06-02 19:17:21 -04:00
Meghana Gupta
ba678b5518 Merge pull request #81893 from meg-gupta/lifetimediagnostics
Fix diagnostic messages for some cases of invalid lifetime dependencies
2025-06-02 16:01:00 -07:00
Ian Anderson
a1d10ed6e7 [Frontend] -Isystem doesn't work everywhere -I does
We missed a spot where we need to pass -Isystem along with -I.

rdar://152267441
2025-06-02 15:06:32 -07:00
Artem Chikin
5b501ad2c5 Hard-code the 'Darwin' module as having been built without C++ interop
Textual interfaces for 'Darwin' built with recent compilers specify that it is built witout C++ interop enabled. However, to ensure compatibility with versions of the 'Darwin' module built with older compilers, we hard-code this fact. This is required to break the module cycle that occurs when building the 'Darwin' module with C++ interop enabled, where the underlying 'Darwin' clang module depends on C++ standard library for which the compiler brings in the 'CxxStdlib' Swift overlay, which depends on 'Darwin'.
2025-06-02 14:16:57 -07:00
Michael Gottesman
ec48e41d42 Merge pull request #81851 from gottesmm/pr-400c59de66fe5c91648aedb348d84cb7bd8d09f4
[flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits
2025-06-02 13:21:21 -07:00
Doug Gregor
6ba48f2738 [Strict memory safety] Adjust "unsafe" location for string interpolations
String interpolations can end up being unsafe in the call to
appendInterpolation when it's provided with unsafe types. Move the
location of the proposed "unsafe" out to the string interpolation
itself in these cases, which properly suppresses the warning.

Fixes rdar://151799777.
2025-06-02 12:36:36 -07:00
Artem Chikin
5577df7115 [Implicit Module Builds] Do not query CxxStdlib Swift overlay for textual modules which were not built with c++interop
When the compiler is building a module without a defined formal C++ interop mode (e.g. building a textual interface which specifies it was built without C++ interop enabled), avoid looking up the C++ standard library Swift overlay for it. This is required for the case of the Darwin module, for example, which includes headers which map to C++ stdlib headers when the compiler is operating in C++ interop mode, but the C++ standard library Swift overlay module itself depends on 'Darwin', which results in a cycle. To resolve such situations, we can rely on the fact that Swift textual interfaces of modules which were not built with C++ interop must be able to build without importing the C++ standard library Swift overlay, so we avoid specifying it as a dependency for such modules. The primary source module, as well as Swift textual module dependencies which were built with C++ interop will continue getting a direct depedency of the 'CxxStdlib' Swift module.

This was previously fixed in the dependency scanner for explicitly-built modules in https://github.com/swiftlang/swift/pull/81415.
2025-06-02 12:25:59 -07:00
Michael Gottesman
331626e6fa [rbi] Lookthrough an invocation of DistributedActor.asLocalActor when determining actor instances.
In this case, what is happening is that in SILGen, we insert implicit
DistributedActor.asLocalActor calls to convert a distributed actor to its local
any Actor typed form. The intention is that the actor parameter and result are
considered the same... but there is nothing at the SIL level to enforce that. In
this commit, I change ActorInstance (the utility that defines actor identity at
a value level) to look through such a call.

I implemented this by just recognizing the decl directly. We already do this in
parts of SILGen, so I don't really see a problem with doing this. It also
provides a nice benefit that we do not have to modify SILFunctionType to
represent this or put a @_semantic attribute on the getter.

NOTE: Generally, Sema prevents us from mixing together different actors. In this
case, Sema does not help us since this call is inserted implicitly by the
distributed actor implementation in SILGen. So this is not a problem in general.

rdar://152436817
2025-06-02 12:21:55 -07:00
Michael Chiu
7bbafc599d Merge branch 'main' into mchiu/freebsd 2025-06-02 13:33:18 -04:00
Pavel Yaskevich
e1e9f04398 Merge pull request #81863 from xedin/using-for-default-isolation-in-file-context
[AST/Sema] SE-0478:  Implement `using` declaration under an experimental flag
2025-06-02 09:56:29 -07:00
susmonteiro
79227e7a09 [cxx-interop] Fix ambiguous methods in long chains of inheritance 2025-06-02 16:51:58 +01:00
Michael Gottesman
501bad55a8 [flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits
This just involved loosening some checks in the type checker so we stopped
erroring in the type checker and instead deferred to SIL level checks.

rdar://131136194
2025-06-02 08:37:05 -07:00
Joe Groff
209a7a2ef5 Merge pull request #81878 from jckarter/addressable-scope-for-captures
SILGen: Establish an addressability scope for closure captures.
2025-06-02 07:36:46 -07:00
Hamish Knight
9cad10ddcd [CS] Check hasType in isPlaceholderVar
Patterns assert that a type is set in `getType`, check `hasType`
before querying.

rdar://146383201
2025-06-02 14:33:10 +01:00