Commit Graph

28941 Commits

Author SHA1 Message Date
Henrik G. Olsson
7fcc72f108 Merge pull request #81859 from swiftlang/swiftify-inherit-imports
[MacrosOnImports][Swiftify] Copy module imports from clang node's module to its Swift macro SourceFile
2025-09-19 21:21:09 -07:00
Alexis Laferrière
97002e1ee0 Merge pull request #84373 from xymus/le-import-warn
Sema: Limit errors on LE importing non-LE modules to SDK modules
2025-09-19 16:34:48 -07:00
Henrik G. Olsson
edb48dff8c [ImportResolution] Gracefully handle importing broken clang module
An assert checking the invariant of the module passed to
alreadyImportedTLM being a top-level module would dereference a null
pointer in the case where the clang module contained syntax errors,
since findUnderlyingClangModule would return null. Instead call the
bespoke isSubmodule function that already performs this null check.

This fixes the lldb test
lldb/test/API/lang/swift/clangimporter/expr_import/TestSwiftExprImport.py.
2025-09-19 15:49:44 -07:00
Hamish Knight
801cd646ad Merge pull request #84390 from hamishknight/out-of-place
[Sema] Reject placeholders in type resolution for param and result types
2025-09-19 23:19:48 +01:00
Slava Pestov
21e34e3189 Merge pull request #84400 from slavapestov/prepared-overloads-flag
Sema: Add -solver-{enable,disable}-prepared-overloads frontend flags
2025-09-19 17:13:23 -04:00
Hamish Knight
0b3747d7c4 Revert "[CS] Record fix when encountering decl reference with placeholder type"
This reverts commit 8102e39f39.
2025-09-19 14:22:39 +01:00
Hamish Knight
62798494ff Revert "[Sema] Handle PlaceholderTypes in associated type inference"
This reverts commit aa9aa58cea.
2025-09-19 14:22:39 +01:00
Hamish Knight
46df852610 [Sema] Reject placeholders in type resolution for param and result types
Not all clients can properly handle the presence of placeholders in
interface types and it doesn't seem worth the complexity for the 
type replacement diagnostic.
2025-09-19 14:22:39 +01:00
Doug Gregor
3e981b7d8f Merge pull request #84374 from DougGregor/embedded-swift-restrictions
Embedded swift restrictions
2025-09-19 01:09:19 -07:00
Slava Pestov
cf3dab10bb Merge pull request #84339 from slavapestov/better-prepared-overloads
Sema: Better prepared overloads
2025-09-18 21:47:06 -04:00
Kavon Farvardin
84cf0a3551 Merge pull request #81858 from kavon/kavon/manual-ownership
introduce @_manualOwnership performance attribute
2025-09-18 16:15:20 -07:00
Doug Gregor
9bdd7db739 Eliminate a null pointer dereference 2025-09-18 12:55:33 -07:00
Slava Pestov
2deb5ff0a5 Sema: Add -solver-{enable,disable}-prepared-overloads frontend flags 2025-09-18 15:05:43 -04:00
Slava Pestov
e9070cf229 Sema: Remove unused variable 2025-09-18 14:54:16 -04:00
Slava Pestov
7f8c4e08a8 Sema: Correctly thread PreparedOverloadBuilder through InferableTypeOpener 2025-09-18 14:54:16 -04:00
Slava Pestov
9dea72579a Sema: Record ASTNode type changes in PreparedOverload
Also, move some methods from ConstraintSystem.h to ConstraintSystem.cpp.
2025-09-18 14:54:16 -04:00
Slava Pestov
ad324b7c43 Sema: Clean up ConstraintSystem::resolveOverload() a bit 2025-09-18 14:54:16 -04:00
Slava Pestov
8744e8a3a0 Sema: Sink ModuleDecl handling back down into getTypeOfMemberReferencePre/Post() 2025-09-18 14:54:16 -04:00
Slava Pestov
a12c160d0b Sema: Replace calls to OverloadChoice constructor with two overloads of getDecl() 2025-09-18 14:54:16 -04:00
Slava Pestov
b181fcf0fd Sema: Get prepared overloads working again with the Pre()/Post() split 2025-09-18 14:54:16 -04:00
Alexis Laferrière
8b38d29333 Sema: Limit error on LE importing non-LE modules to SDK modules
Limit reporting as an error imports of a non-library-evolution module
from a library-evolution enabled module to sources that are part of the
SDK. The error also requires having enabled `InternalImportsByDefault`.
This should help prevent SDK breaking regressions while loosening the
restriction elsewhere.

Framework owners can enable `-library-level api` or `spi` to get this
check as an error, along with more sanity checks.

Other cases remain as a warning. We should look to silence it in some
cases or offer a flag to do so.

rdar://160414667
2025-09-18 11:31:36 -07:00
Doug Gregor
a16c9f7ab4 [Embedded] Diagnose dynamic casts to existentials
Embedded Swift doesn't have protocol conformance metadata, so it cannot
handle dynamic casts to existentials (nor should it).

Another part of rdar://119383905.
2025-09-18 10:05:35 -07:00
Doug Gregor
ade6e55b0c [Embedded] Diagnose uses of generic methods on existential values
Generic methods declared in protocols (and extensions thereof) cannot
be used on existential values, because there is no way to specialize
them for all potential types. Diagnose such cases in Embedded Swift
mode and via `-Wwarning EmbeddedRestrictions`.

This adds a bunch more warnings to the standard library that we'll
need to clean up, probably by `#if`'ing more code out.

Part of rdar://119383905.
2025-09-18 10:05:35 -07:00
Doug Gregor
844ba5f4f8 [Embedded] Diagnose non-final generic methods in class in the type checker
Move the diagnostic about non-final generic methods in classes up to
the type checker, so that it is available to `-Wwarning
EmbeddedRestrictions` and earlier in the pipeline. The SIL version of
this is still available as a backstop.

Yet another part of rdar://133874555.
2025-09-18 10:05:33 -07:00
Slava Pestov
c344d6b0eb Sema: Rename getTypeOf{Member,}ReferenceImpl() to Pre() and factor out Post() versions 2025-09-18 11:31:59 -04:00
Slava Pestov
182c38470b Sema: Remove replacementsPtr parameter from getTypeOfMemberReference() 2025-09-18 11:31:59 -04:00
Slava Pestov
4ea2f1706b Sema: Simplify getConcreteReplacementForProtocolSelfType() 2025-09-18 11:31:59 -04:00
Slava Pestov
a028eb36b7 Sema: Don't need to return new baseObjTy from getTypeOfMemberReferenceImpl() 2025-09-18 11:31:59 -04:00
Slava Pestov
d8ead6c5cc Sema: Refactor getTypeOf{Member,}Reference() to take the OverloadChoice 2025-09-18 11:31:59 -04:00
Slava Pestov
2fde4a50e7 Sema: Split off getTypeOfMemberReferenceImpl() from getTypeOfMemberReference() 2025-09-18 11:06:32 -04:00
Slava Pestov
8397c0826a Sema: Remove duplicate logic for throwing accessor witness matching
getTypeOfMemberReference() already opens the accessor's thrown error
type for us.
2025-09-18 11:06:32 -04:00
Slava Pestov
05d57692dd Sema: Pass baseObjTy instead of baseRValueTy to adjustFunctionTypeForConcurrency() 2025-09-18 11:06:32 -04:00
Slava Pestov
35a439de24 Sema: Remove replacements parameter from getMemberReferenceTypeFromOpenedType() 2025-09-18 11:06:31 -04:00
Slava Pestov
1efc9a6d0d Sema: Split off getTypeOfReferenceImpl() from getTypeOfReference() 2025-09-18 11:06:31 -04:00
Slava Pestov
d8ce7c32e2 Sema: Tweak VarDecl concurrency adjustment in getTypeOfReference() to look like FuncDecl case 2025-09-18 11:05:41 -04:00
Hamish Knight
deab5f7970 Merge pull request #84280 from hamishknight/csapply-cleanup
Reapply: [Sema] Remove some unreachable code from CSApply
2025-09-18 14:25:51 +01:00
Kavon Farvardin
61fe8a9b8e introduce @_manualOwnership performance attribute
This attribute forces programmers to acknowledge every
copy that is required to happen in the body of the
function. Only those copies that make sense according
to Swift's ownership rules should be "required".

The way this is implemented as of now is to flag each
non-explicit copy in a function, coming from SILGen, as
an error through PerformanceDiagnostics.
2025-09-17 13:51:57 -07:00
Hamish Knight
aa9aa58cea [Sema] Handle PlaceholderTypes in associated type inference
Avoid attempting to infer an associatedtype as a type that contains
placeholders.
2025-09-17 20:51:06 +01:00
Hamish Knight
d1b8084bc1 [Sema] Avoid resolving placeholders for protocol requirement params
We can't ever have default arguments in protocols anyway.
2025-09-17 20:51:06 +01:00
Hamish Knight
8102e39f39 [CS] Record fix when encountering decl reference with placeholder type
We allow placeholder types in interface types in certain cases to allow
better recovery since we can suggest the inferred type as a replacement.
When referencing those decls though we need to make sure we record a fix
since we cannot form a valid solution with them.
2025-09-17 20:51:06 +01:00
Hamish Knight
ab64e53b0c [Sema] Only resolve PlaceholderType result for FuncDecl with body
We allow resolving PlaceholderType here to allow MiscDiagnostics to
suggest replacing it with the inferred result type, but we won't run
that logic for non-FuncDecls and FuncDecls without bodies. Make sure
we reject placeholders in those cases.
2025-09-17 20:41:20 +01:00
Hamish Knight
9f5a754b77 [Sema] Ban placeholders in typed throws
This never worked correctly and would crash in SILGen, ban the use
of placeholder types. While here, ensure we replace any ErrorTypes
with holes when solving the closure in the constraint system.
2025-09-17 20:41:20 +01:00
Hamish Knight
71f8e68655 [Sema] Check for placeholders in extended type first
Avoid emitting a diagnostic about `<<hole>>` being a non-nominal type.
2025-09-17 20:41:20 +01:00
Hamish Knight
3484f63ca1 [CS] Strengthen a couple of CSApply assertions
Enforce that we don't ever encounter solutions that contain holes or
error types.
2025-09-17 16:11:53 +01:00
Slava Pestov
90bfc1676d Sema: Remove some unreachable code from CSApply
I believe these code paths could only be reached by re-typechecking
invalid code in the old CSDiag implementation.
2025-09-17 16:11:53 +01:00
Hamish Knight
a7c0460877 [CS] Record IgnoreInvalidASTNode for invalid key path component
And ensure we don't end up with invalid key paths in CSApply.
2025-09-17 16:11:53 +01:00
Hamish Knight
cdf0bfbaf7 [CS] Remove a couple uses of recordAnyTypeVarAsPotentialHole
It's not actually clear these are necessary anymore, and in one case
it actually makes a diagnostic worse.
2025-09-17 16:11:53 +01:00
Hamish Knight
75d60b3484 Merge pull request #84279 from hamishknight/preserve-fatal-score
[CS] Bail from conjunction for non-zero `SK_Hole`
2025-09-17 16:11:04 +01:00
Henrik G. Olsson
406cc1d1f5 [ImportResolution] Override module imports for macros in namespaces
Contents in namespaces are imported to the bridging header module
`__ObjC`. When macros attached to a decl imported from a namespace are
expanded, they also end up in `__ObjC`. This prevents them from
inheriting imports from the module they originated in. This patch
implements a workaround by adding an alternative constructor to
`ImportResolver` that takes an explicit origin module as input,
overriding which module counts as the "parent" module.
2025-09-16 21:10:08 -07:00
Henrik G. Olsson
da96079eb0 [ImportResolution] Don't deduplicate scoped imports
This fixes a few tests that were failing because scoped imports were
counted as having imported the module already, leading to later imports
of the same module being skipped. Since the scoped imports don't import
the full module, this would result in syntactically imported symbols not
being found by the compiler.
2025-09-16 21:10:07 -07:00