Commit Graph

29258 Commits

Author SHA1 Message Date
Hamish Knight
05e3d15955 [CS] Propagate CSApply failures in a few more places
We had some cases where we weren't propagating failures to apply the
solution, and as such weren't invalidating the resulting AST. Fix up
these cases.
2025-10-26 14:49:17 +00:00
Hamish Knight
dc9f28f14b [CS] Avoid setting hadError for diagnoseUnhandledThrowsInAsyncContext
We can still apply the solution even if we emit an error here. No
test since it's already covered in the test suite once the next commit
is applied.
2025-10-26 14:48:07 +00:00
Hamish Knight
62f0926d25 [CS] Invalidate nested unresolved VarDecls when ignoring completion argument
Make sure we set types for any nested VarDecls in UnresolvedPatternExprs
to ensure we don't crash when attempting to solve the body.
2025-10-26 12:33:29 +00:00
Hamish Knight
55ebd0774e [AST] Avoid exposing lazy local storage var to name lookup
We already reject attempts to reference this for `lazy` properties.
For `lazy` locals let's just not expose it to name lookup to begin
with. This ensures we don't attempt to prematurely kick the interface
type computation for the var, fixing a couple of crashers.
2025-10-25 15:07:11 +01:00
Hamish Knight
a341c86f3c [AST] NFC: Rename VarDecl::visitAuxiliaryDecls -> visitAuxiliaryVars
Make it more obvious it's different to `Decl::visitAuxiliaryDecls`.
2025-10-25 15:07:11 +01:00
Allan Shortlidge
17a87065b7 Merge pull request #85130 from tshortli/refactor-version-remap
AST: Refactor availability version remapping
2025-10-25 01:40:42 -07:00
Kavon Farvardin
03d61ed75a Merge pull request #85090 from kavon/manual-ownership/usability-fixes-6
ManualOwnership: provide ability to apply to entire compilation unit
2025-10-25 00:15:03 -07:00
Kavon Farvardin
2d881bdc9c ManualOwnership: provide ability to apply to entire compilation unit
With this patch, I'm flipping the polarity of things.

The flag `-enable-experimental-feature ManualOwnership` now turns on the diagnostics,
but they're all silenced by default. So, you need to add -Wwarning or -Werror to
your build settings to turn on the specific diagnostics you care about.

These are the diagnostic groups relevant to the feature:

- SemanticCopies aka "explicit copies mode"
- DynamicExclusivity

For example, the build setting `-Werror SemanticCopies` now gives you errors about
explicit copies, just as before, but now you can make them just warnings with -Wwarning.

To opt-out a declaration from everything when using the feature, use @_noManualOwnership.

@_manualOwnership is no longer an attribute as a result.

resolves rdar://163372569
2025-10-24 18:54:07 -07:00
Slava Pestov
3b1960eb9a Merge pull request #85016 from slavapestov/prepared-fuzz
Sema: Fix a fuzzer crash
2025-10-24 21:46:34 -04:00
Allan Shortlidge
05f7cb7017 AST: Refactor availability version remapping.
Availability version remapping currently only applies to code built for
visionOS. We plan to introduce more platform kinds and standalone availability
domains that will require version remapping, though, so it's time to
rearchitect and simplify the code to make it easier to generalize.

`AvailabilityDomain` is now responsible for version remapping and much of the
previously duplicated utilities have been consolidated.
2025-10-24 17:22:07 -07:00
Becca Royal-Gordon
e3495f5fe7 Forbid module selectors on dependent member types
In code like the following:

```
protocol P { associatedtype A: Hashable }
protocol Q { associatedtype A: Comparable }

func fn<T: P & Q>(_: T) where T.A == Int { … }
```

`T.A` is actually the union of `P.A` and `Q.A`—it satisfies both associated types and has both of their constraints. This means it doesn’t actually make sense to apply a module selector to `A`—even if `P` and `Q` are in different modules, `T.A` always represents both of the declarations, not one or the other. We therefore now ban module selectors in this position, since they don’t actually jibe with the nature of a generic signature.

This justification technically doesn’t hold for *every* member type of a generic parameter—a member type can refer to a concrete typealias in a protocol extension, for instance—but in those situations, you can disambiguate (and add module selectors) by writing `P.A` or `Q.A` instead of `T.A`, so we’re not really worried about this limitation.
2025-10-24 16:23:50 -07:00
Becca Royal-Gordon
ec92be4955 Support module selectors for cross-import overlays 2025-10-24 16:23:50 -07:00
Becca Royal-Gordon
42fdd1d30c Improve module selector macro diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon
b65e3c9c15 Improve module selector @_dynamicReplacement diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon
60cc537f70 Improve module selector constraint solver diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon
d1e391094d Improve module selector expr lookup diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon
7949224b69 Improve module selector type lookup diagnostics 2025-10-24 16:23:48 -07:00
Becca Royal-Gordon
ffaa35810c Handle lookup into Builtin with module selector
Lookups like Builtin::Int64 were failing because BuiltinUnit rejected all unqualified lookups. Make it allow unqualified lookups with a module selector.
2025-10-24 16:23:48 -07:00
Becca Royal-Gordon
7bf14de2e6 Handle module selectors with local vars right 2025-10-24 16:23:34 -07:00
Becca Royal-Gordon
b35aaef526 Handle module selectors in macro lookups 2025-10-24 16:23:34 -07:00
Becca Royal-Gordon
f43bd72207 Handle module selectors in UDRE lookups 2025-10-24 16:23:34 -07:00
Becca Royal-Gordon
e662993a08 [NFC] Audit some DeclName➡️DeclNameRef conversions
Adds comments explaining why these conversions aren’t lossy.
2025-10-24 16:23:33 -07:00
Becca Royal-Gordon
64d8b70942 Make DeclNameRef able to store a module selector
In this commit, this change affects certain diagnostics but doesn’t actually alter name lookup behavior yet.
2025-10-24 16:23:33 -07:00
Allan Shortlidge
88bc79f6af AST: Remove unnecessary ASTContext argument.
There's no need to take one as input to a method on `Decl`. NFC.
2025-10-24 16:20:02 -07:00
Allan Shortlidge
9b7c531fd8 AST/IDE/Sema: Remove unnecessary AvailabilityInference.h includes.
NFC.
2025-10-24 16:14:49 -07:00
Meghana Gupta
7e8d8b671f Merge pull request #85097 from meg-gupta/withdiagpr
Update borrow accessor diagnostics and synthesis
2025-10-24 15:06:19 -07:00
Slava Pestov
69c8d15570 Sema: Fix a fuzzer crash
This test case crashes when prepared overloads are disabled, but passes
when enabled. To avoid messing up tests if we have to turn the flag on
and off, fix the crash.
2025-10-24 16:20:21 -04:00
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00
Hamish Knight
bafd04d647 Merge pull request #85113 from jamieQ/try-never-discard-diags
[Sema]: minor improvements to unused expression result diagnostics
2025-10-24 20:03:39 +01:00
Hamish Knight
b8cbb225db Merge pull request #85115 from hamishknight/fix-crash 2025-10-24 19:58:40 +01:00
John Hui
781489f067 Merge pull request #85021 from j-hui/return-frt-diagnostics
[cxx-interop] Put RETURNS_RETAINED warnings in a diagnostic group

rdar://161932849
rdar://144976203
2025-10-24 12:05:48 -04:00
Hamish Knight
f15fae4737 Merge pull request #84822 from hamishknight/just-a-phase
[CS] Remove `ConstraintSystemPhase`
2025-10-24 16:05:08 +01:00
Hamish Knight
8397a7a61d Merge pull request #84907 from hamishknight/fixed-point
[CS] Penalize implicit pointer conversions to generic parameter types
2025-10-24 15:56:07 +01:00
Hamish Knight
41b47f48cb [Sema] Fix crash in CheckRedeclarationRequest for IUO mismatch check
Make sure we only check this if both declarations have parameter lists.
While here, clean up the logic a bit such that we just iterate over
the parameter lists.

rdar://156874925
2025-10-24 14:32:05 +01:00
Pavel Yaskevich
65599ce1f1 [AST/Sema] Allow Sendable suppression on Objective-C class declarations
Expressed as `__swift_attr__("~Sendable")` this acts like `: ~Sendable`
on Swift type declarations and supersedes `@_nonSendable(_assumed)`.

Resolves: rdar://140928937
2025-10-24 20:36:24 +09:00
Jamie
9a0f165036 [Sema]: minor improvements to unused expression result diagnostics
Previously we would emit a diagnostic in cases in which a throwing
function returning a structurally-unihabited type was called within an
optional try expression. Such cases can never produce a return value, so
suppress the existing diagnostic.
2025-10-24 06:31:03 -05:00
Meghana Gupta
c85e214369 Fix synthesis of get/set protocol constraints when borrow/mutate accessors are present 2025-10-24 04:29:46 -07:00
Kuba Mracek
f41ce336cf Drop unused MemberRefExpr handling in LegalConstExprVerifier, adjust tests 2025-10-23 17:02:15 -07:00
Slava Pestov
da49310116 Sema: Fix findMissingGenericRequirementForSolutionFix() to set SubstFlags::PreservePackExpansionLevel 2025-10-23 15:36:53 -04:00
Meghana Gupta
f44d7e53be Add diagnostics for ownership modifiers on borrow/mutate accessors 2025-10-23 11:49:10 -07:00
Kuba Mracek
19f3320f20 Better handling of metatypes and operators in LegalConstExprVerifier.cpp 2025-10-23 09:27:01 -07:00
Kuba Mracek
adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
John Hui
e5c863c7ff [NFC] Capitalize FIXME comment to make it more discoverable 2025-10-22 14:53:11 -07:00
Alexis Laferrière
4c9a9ca9ad Merge pull request #85039 from xymus/exportability-var-diag
Sema: Custom diagnostic for var decls referencing a restricted type
2025-10-22 10:01:09 -07:00
Allan Shortlidge
463bf91f68 AST: Rename Swift runtime availability domain to StandaloneSwiftRuntime.
This name will distinguish the standalone Swift runtime availability domain
from the domain for the built-in Swift runtime on supported targets.
2025-10-21 21:55:25 -07:00
Becca Royal-Gordon
78a7df8d4a Merge pull request #85018 from beccadax/this-is-the-key-path 2025-10-21 16:27:38 -07:00
Slava Pestov
50cea0af11 Merge pull request #85011 from slavapestov/prepared-leading-dot-fix
Fix "failed to produce diagnostic" with invalid leading dot usage when prepared overloads are enabled
2025-10-21 14:44:40 -04:00
Alexis Laferrière
2d339c1260 Sema: Custom diagnostic for var decls referencing a restricted type
Replace the `here` part of the generic exportability diagnostic for
variables with: `in a property declaration marked public or in a
'@frozen' or '@usableFromInline' context`.

The full diagnostic now looks like:
```
error: cannot use struct 'ImportedType' in a property declaration marked
public or in a '@frozen' or '@usableFromInline' context;
'HiddenDependency' has been imported as implementation-only
```

This should be improved further to support implicitly exported memory
layouts in non-library-evolution and embedded.
2025-10-21 11:30:52 -07:00
Steven Wu
cb7ddbe9ea Merge pull request #84959 from cachemeifyoucan/PrunedLiveness-warning
Fix -Wdangling-assignment-gsl warnings
2025-10-21 01:47:59 -07:00
Slava Pestov
1b6ac2c1d8 Sema: Clean up leading dot fix logic in simplifyConformsToConstraint()
Tests still pass without this code, including the tests I just
added in the previous commit.
2025-10-20 21:50:41 -04:00