Commit Graph

28234 Commits

Author SHA1 Message Date
Hamish Knight
805f25d50c [Sema] Try limit kicking interface type in filterForEnumElement
Kicking the interface type request of the base decl here is wrong
if the decl is e.g a `self` capture in a closure, since we'll be in
the middle of type-checking the closure. I'm planning on properly
fixing this by folding the lookup into the constraint system, but for
now let's at least avoid kicking the request if we don't have an enum
case or enum var. That at least prevents it from affecting cases where
e.g you're pattern matching against a property in a class.

We could potentially tighten up the checking here even further, but
that could potentially impact source compatibility for ambiguous
cases. I'd like to keep this patch low risk, and then deal with any
fallout as part of the pattern type-checking work.

rdar://146952007
2025-04-09 14:56:49 +01:00
Hamish Knight
5674b6e047 Merge pull request #80583 from hamishknight/macro-arg-apply
[CS] Make sure macro arguments go through `coerceCallArguments`
2025-04-08 11:51:32 +01:00
Becca Royal-Gordon
93188f81cc Stub fix-its for missing objcImpl requirements
Changes the diagnostics emitted when an `@objc @implementation` extension is missing some of the members required by the extension:

• We now emit one error on the extension, plus a note for each missing member.
• Where possible, we also emit a note with a fix-it adding stubs.

For example:

```
  9 | @objc @implementation extension ObjCClass {
    |                       |- error: extension for main class interface does not provide all required implementations
    |                       |- note: missing instance method 'method(fromHeader3:)'
    |                       |- note: missing instance method 'method(fromHeader4:)'
    |                       |- note: missing property 'propertyFromHeader7'
    |                       |- note: missing property 'propertyFromHeader8'
    |                       |- note: missing property 'propertyFromHeader9'
    |                       |- note: missing instance method 'extensionMethod(fromHeader2:)'
    |                       `- note: add stubs for missing '@implementation' requirements
```

With a fix-it on the last note to insert the following after the open brace:

```

  @objc(methodFromHeader3:)
  open func method(fromHeader3 param: Int32) {
      <#code#>
  }

  @objc(methodFromHeader4:)
  open func method(fromHeader4 param: Int32) {
      <#code#>
  }

  @objc(propertyFromHeader7)
  open var propertyFromHeader7: Int32 {
      get {
          <#code#>
      }
      set {
          <#code#>
      }
  }

  @objc(propertyFromHeader8)
  open var propertyFromHeader8: Int32 {
      get {
          <#code#>
      }
      set {
          <#code#>
      }
  }

  @objc(propertyFromHeader9)
  open var propertyFromHeader9: Int32 {
      get {
          <#code#>
      }
      set {
          <#code#>
      }
  }

  @objc(extensionMethodFromHeader2:)
  open func extensionMethod(fromHeader2 param: Int32) {
      <#code#>
  }

```

Fixes rdar://130038221.
2025-04-07 17:53:15 -07:00
Allan Shortlidge
6fd1cfc593 Sema: Fix another -require-explicit-availability regression.
Extensions that extend non-public types should never be required to have
explicit availability, even if they declare conformances to public protocols.

Resolves rdar://148697770.
2025-04-07 14:50:48 -07:00
Michael Gottesman
77a86a525b Merge pull request #79891 from gottesmm/pr-9df6772bb44656cbd85cad72ee5c3637caab8956
Make Feature a struct enum so we can put methods on it.
2025-04-07 10:32:23 -07:00
Hamish Knight
cc23c25979 Merge pull request #80535 from hamishknight/cap-req
[Sema] Requestify PatternBindingDecl capture computation
2025-04-07 17:28:18 +01:00
Hamish Knight
b82f95b508 [CS] Make sure macro arguments go through coerceCallArguments
Previously we would avoid rewriting the arguments in CSApply, but
that can result in incorrect behavior in MiscDiagnostics passes, e.g
incorrectly treating all closure arguments as escaping. Make sure
we rewrite the arguments as we would in regular type-checking.

rdar://148665502
2025-04-07 16:29:50 +01:00
Allan Shortlidge
c5e5311cc8 Merge pull request #80560 from tshortli/member-import-visibility-diags-implicit
Parse/Sema: Add source locations to implicit code for `MemberImportVisibility` diagnostics
2025-04-05 18:07:55 -07:00
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
2d899d0e73 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def 2025-04-05 12:31:20 +01:00
Anthony Latsis
a0930dec31 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSema.def 2025-04-05 12:31:19 +01: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
Michael Gottesman
3ff9463957 Make Feature a struct enum so we can put methods on it.
Just noticed this as I was looking at making other changes.
2025-04-05 10:08:29 +01:00
Anthony Latsis
3fd8f0a008 [NFC] Sema: Factor out derived conformance sources into subdirectory 2025-04-05 05:32:37 +01:00
Pavel Yaskevich
8bf8c24bf9 Merge pull request #80503 from xedin/extensible-attr
[AST/Sema] Add `@extensible` attribute on `enum` declarations
2025-04-04 09:17:56 -07:00
Hamish Knight
0a78fb3636 [Sema] Remove redundant check
The initializer for a lazy property is always subsumed, so we should
have already bailed.
2025-04-04 16:01:39 +01:00
Hamish Knight
4676eaa110 [Sema] Requestify PatternBindingDecl capture computation
Introduce `PatternBindingCaptureInfoRequest`, and kick it after
contextualizing a property initializer. This ensures it gets run
for stored properties added by macro expansions.

rdar://143429551
2025-04-04 16:01:39 +01:00
Slava Pestov
9148ae32bd Merge pull request #80482 from slavapestov/abstract-conformance-cleanup
AST: Simplify ProtocolConformanceRef operations a little bit
2025-04-04 10:37:49 -04:00
Pavel Yaskevich
a0ae93d3a8 [AST/Sema] Add @extensible attribute on enum declarations
This attribute controls whether cross-module access to the declaration
needs `@unknown default:` because it's allowed to gain new cases even
if the module is non-resilient.
2025-04-03 16:30:19 -07:00
Slava Pestov
ea05708716 AST: Eliminate GenericEnvironment::mapConformanceRefIntoContext() 2025-04-03 17:35:34 -04:00
Slava Pestov
ec0dfc8716 AST: Add new form of SubstitutionMap::getProtocolSubstitutions() 2025-04-03 17:35:33 -04:00
Slava Pestov
a209ff8869 AST: Remove origType parameter from ProtocolConformanceRef::subst() 2025-04-03 17:35:33 -04:00
Slava Pestov
7399eeb602 AST: Remove type parameter from ProtocolConformanceRef::getWitnessByName() 2025-04-03 17:35:33 -04:00
Slava Pestov
00766f7deb AST: Remove type parameter from ProtocolConformanceRef::getTypeWitnessByName() 2025-04-03 17:35:32 -04:00
Slava Pestov
91503710bc AST: Remove origType parameter from ProtocolConformanceRef::getTypeWitness() 2025-04-03 17:35:32 -04:00
Slava Pestov
7c7caa2088 Sema: Fix regression with 'Failure' type witness inference hack
We have a special hack to infer the 'Failure' type witness in
'AsyncIteratorProtocol' by considering the type of 'next()'
witness.

In eaf06eae0e I added a check to
fix some assertions that could happen if 'next()' was witnessed
by a declaration in a protocol extension or superclass, which
has a different generic signature.

However my check was too narrow, because it also prohibited
this form of inference when 'next()' was in a different
extension of the same nominal type.

Allow this again.

Fixes https://github.com/swiftlang/swift/issues/79367.
Fixes rdar://problem/145341658.
2025-04-03 17:34:31 -04:00
Hamish Knight
918d4b54cf Merge pull request #80461 from hamishknight/in-sequence
[ASTScope] Allow `try` in unfolded sequence to cover following elements
2025-04-03 20:23:51 +01:00
Anthony Latsis
99f63ed933 DiagnosticEngine: Support TypeAttribute diagnostic arguments 2025-04-03 01:52:38 +01:00
Allan Shortlidge
5cd5f31c9c Sema: Fix a regression in -require-explicit-availability diagnostics.
The changes in https://github.com/swiftlang/swift/pull/80040 caused the
compiler to start diagnosing extensions containing only members that are
either `@_spi`, `@_alwaysEmitIntoClient`, or unavailable when the
`-require-explicit-availability` flag is passed. Extensions should not be
diagnosed when they only contain members that would not be diagnosed
themselves.

Resolves rdar://148275432.
2025-04-02 17:12:38 -07:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Pavel Yaskevich
f61a3c941b Merge pull request #80443 from xedin/rdar-148256978
[CSBindings] Avoid delaying leading-dot inference only if chain is di…
2025-04-02 11:08:44 -07:00
Allan Shortlidge
192da54004 Merge pull request #80450 from tshortli/fix-parentheses-warning 2025-04-02 10:40:17 -07:00
Pavel Yaskevich
75f4ca78ce Merge pull request #80397 from jameesbrown/pack-exp-overload
[CS] Dont wrap packexp in extra layer of expansion
2025-04-02 09:45:01 -07:00
Joe Groff
6b605f41cb Type substitution eliminates dependencies with Escapable targets.
When a generic function has potentially Escapable outputs, those outputs
declare lifetime dependencies, which have no effect when substitution
leads to those types becoming `Escapable` in a concrete context.
This means that type substitution should canonically eliminate lifetime
dependencies targeting Escapable parameters or returns, and that
type checking should allow a function value with potentially-Escapable
lifetime dependencies to bind to a function type without those dependencies
when the target of the dependencies is Escapable.

Fixes rdar://147533059.
2025-04-02 08:54:45 -07:00
Slava Pestov
03d8fd7ceb Merge pull request #80445 from slavapestov/fix-issue-80288
Sema: Fix handling of getter typed throws in witness matching
2025-04-02 08:01:10 -04:00
Hamish Knight
d958c0e080 [AST] Introduce Expr::isAlwaysLeftFolded
Use this to query for `try`-like expressions when it comes to binary
operator folding.
2025-04-02 12:29:45 +01:00
Pavel Yaskevich
bf2d01e562 Merge pull request #80419 from xedin/revert-pr-79397
Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
2025-04-02 00:10:23 -07:00
Allan Shortlidge
8819d6db9e Distributed: Squash a -Wparentheses warning.
The following warning was being  emitted by newer versions of clang:

```
comparisons like 'X<=Y<=Z' don't have their mathematical meaning [-Wparentheses]
```

This code needs to be reworked to ensure that the conditions that are meant to
be asserted are true.
2025-04-01 16:47:56 -07:00
Allan Shortlidge
14147bf87d Merge pull request #80428 from tshortli/custom-availability-domain-scopes
AST: Build availability scopes for custom domain conditionals
2025-04-01 16:43:19 -07:00
Slava Pestov
b26c59962b Sema: Fix handling of getter typed throws in associated type inference
We must replace type parameters with archetypes in the thrown error type
of the witness. The requirement type remains an interface type.
2025-04-01 17:21:32 -04:00
Slava Pestov
de3cf4d982 Sema: Visit getter throws type in ReferencedAssociatedTypesRequest 2025-04-01 14:53:49 -04:00
Slava Pestov
b30006837e Sema: Fix handling of getter typed throws in witness matching
Witness matching didn't handle the case where either the
requirement or the witness is a property with a throwing
getter, and the thrown error type contains a type parameter.

We must open the thrown error types first, replacing type
parameters with type variables, for the matching to work.

Associated type inference needs a similar fix. I'll land a
combined test case for both once I fix that.

Fixes https://github.com/swiftlang/swift/issues/80288.
Fixes rdar://problem/147874955.
2025-04-01 14:53:49 -04:00
Anthony Latsis
4bddb3a705 Merge pull request #80427 from AnthonyLatsis/alcer-americanus
[SE-0461] Consistently diagnose protocol requirements in migration (adoption) mode
2025-04-01 19:53:22 +01:00
Pavel Yaskevich
d34222d461 [CSBindings] Avoid delaying leading-dot inference only if chain is directly connected to a contextual type
Additional restrictions on when protocol inference could be considered
viable. If the chain is connected directly to a contextual type there
cannot be any other inference sources for the base type.

Resolves: rdar://148256978
2025-04-01 10:33:30 -07:00
Allan Shortlidge
cce02961f9 AST/SILGen: Make availability ranges stored by PoundAvailableInfo optional.
Rather than representing a missing availability range on `PoundAvailableInfo`
with a default-constructed `AvailabilityRange` (empty), store the ranges as
optionals instead. This allows an empty range to represent an availability
condition which is known to be false at compile time, which will be necessary
when generating SIL for `if #available` queries that check custom availability
domains.
2025-04-01 07:46:46 -07:00
Allan Shortlidge
b6a425ab6a Sema: Avoid diagnosing required availability in swiftinterface files.
The `-require-explicit-availability` compiler flag is designed to help
developers find declarations that they've written with missing availability.
The flag is not printed in swiftinterface files, though, so if a module has
both `-library-level=api` and also has `-require-explicity-availability=ignore`
(as the Swift stdlib does) then the result is that superfluous diagnostics are
emitted when typechecking the emitted module interface that should have been
suppressed by the `ignore` flag. Suppress these diagnostics when typechecking
swiftinterface files since they are only designed to be seen by the owner of
the module when they are building the module from source and they don't have
much value in the context of interface verification.
2025-04-01 07:12:50 -07:00
Artem Chikin
66334f8f1b Merge pull request #79290 from artemcm/ConstProtoSIL
[Compile Time Values] Implement a mandatory SIL pass to verify '@const' values
2025-04-01 00:12:27 -07:00
Anthony Latsis
e9406e04e5 [SE-0461] Consistently diagnose protocol requirements in migration (adoption) mode 2025-04-01 04:03:55 +01:00
Pavel Yaskevich
05798e5f45 Revert "Sema: Remove dead diagnostic"
This reverts commit d56d7045a2.
2025-03-31 14:39:44 -07:00
Pavel Yaskevich
35077a01d1 Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
This reverts commit f0f5ffcebf.
2025-03-31 13:58:38 -07:00