Commit Graph

792 Commits

Author SHA1 Message Date
Anthony Latsis
2cd90bdd69 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-22 18:23:36 +01:00
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
Slava Pestov
c200b0ba44 Add regression test for fixed crasher
This was fixed by 89f5066fb4.
2025-03-26 10:55:46 -04:00
Slava Pestov
7f6a8c6804 Add regression test for fixed crasher 2025-02-10 14:07:32 -05:00
Slava Pestov
302b163edc AST: Optimize TypeAliasType representation 2024-12-06 17:39:55 -05:00
Anthony Latsis
ec5bee8bc9 Merge pull request #77873 from AnthonyLatsis/day-10
test: Add regression test for #74545
2024-12-04 02:43:41 +00:00
Anthony Latsis
ea18b4b53c test: Add regression test for #74545 2024-12-03 20:59:20 +00:00
Pavel Yaskevich
8a0a083a45 Merge pull request #77797 from xedin/locatable-types
[AST/Sema]  Introduce a new type that has associated location in source
2024-12-02 16:33:43 -08:00
Pavel Yaskevich
e3b1f341f0 [CSDiagnostics] Adjust conformance failure diagnostic to check for locatable types
If conformance failure is associated with a `LocatableType`, use
its location to anchor the failure.
2024-11-21 14:13:16 -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
Slava Pestov
1acb61d23a SIL: Fix SILType::isLoweringOf() to correctly handle opaque archetypes
This predicate is meant to ask if the loweredType is equal to
`getLoweredType(pattern, formalType)` for *some* abstraction pattern.

If the formal type contained an opaque archetype, we performed a
different check, because we asked if loweredEqual is equal to
`getLoweredType(AbstractionPattern(formalType), formalType)`.

This caused a spurious SIL verifier failure when the payload of an
existential contained an opaque archetype, because we lower the
payload with the most general AbstractionPattern, so that
@thin metatypes become @thick, etc.

The regression test exercises this bug, and also another bug that was
present in 6.0 but was already fixed on main by one of my earlier
refactorings.

Fixes rdar://problem/138655637.
2024-10-30 13:19:46 -04:00
Rintaro Ishizaki
8e8e4d0193 [Parse/Sema] Move OptionalEvaluationExpr wrapping to PreCheckTarget
This simplify the Parser diagnostics and some type checker logic.
2024-10-11 13:12:48 -07:00
Slava Pestov
5a43d2403e Sema: Simplify opened existential types in solution 2024-09-04 10:42:19 -04:00
Alex Hoppen
8edb57c756 Merge pull request #75667 from ahoppen/build-issues-live-issues
[Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
2024-08-07 17:24:47 -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
Slava Pestov
de16ed8d27 SIL: Fix signature of reabstraction thunk involving parameterized existential
Fixes https://github.com/swiftlang/swift/issues/74569
Fixes rdar://problem/130402282
2024-08-07 15:25:52 -04:00
Slava Pestov
293a36c052 SIL: Pass SubstFlags::PreservePackExpansionLevel in a spot in SILVerifier 2024-08-03 22:40:49 -04:00
Slava Pestov
ccc206d8c4 Add regression test for bug already fixed 2024-08-03 15:06:43 -04:00
Slava Pestov
7a8a56254a AST: Fix substitution map composition edge case
Adding `T == Int` to

    G1 := <T where T: Equatable>

gives us

    G2 := <T where T == Int>

which means that if I have this substitution map for G2:

    S2 := { Int }

then `SubstitutionMap::get(G1, S2)` should give me this substitution map
for G1:

    S2 := { Int, [Int: Equatable] }

But it didn't, instead returning a substitution map with an invalid
conformance.

The problem is that local conformance lookup alone cannot recover
`[Int: Equatable]` in this case, because there is no "concrete
conformance requirement" `[T == Int: Equatable]` recorded anywhere
in G2.

This is of course a legacy of the GenericSignatureBuilder. It would have
been better to not drop conformance requirements made concrete. But oh
well.

Fixes https://github.com/swiftlang/swift/issues/74465
Fixes rdar://130404629.
2024-07-01 14:15:41 -04:00
Slava Pestov
e4d6108e11 SIL: Fix lowering for 'var's whose types contain local archetypes
A mutable 'var' becomes a SILBoxType, and we need to plumb the
correct generic signature through here too.

Fixes https://github.com/apple/swift/issues/71921.
2024-06-18 11:45:41 -04:00
Slava Pestov
8a7f0b8e58 Add regression test for fixed crasher 2024-05-30 16:39:49 -04:00
Slava Pestov
23be369c0e SILGen: Update for PackElementExpr captures
Fixes https://github.com/apple/swift/issues/68941.
Fixes https://github.com/apple/swift/issues/69282.
Fixes https://github.com/apple/swift/issues/72153.
Fixes rdar://110711746.
Fixes rdar://119212867.
Fixes rdar://124202697.
2024-05-30 16:39:49 -04:00
Slava Pestov
4aa0008d74 SILGen: Rewrite captured local archetypes into primary archetypes
This implements support for autoclosures, closures and local functions
nested within a pack iteration for loop.

The combination of explicit closure expressions and pack expansion
expressions still needs some work.

Fixes #66917.
Fixes #69947.
Fixes rdar://113505724.
Fixes rdar://122293832.
Fixes rdar://124329076.
2024-05-17 17:45:05 -04:00
Slava Pestov
ae73cd4637 RequirementMachine: Fix an incorrect assertion
We don't expect to see type parameters that are not generic parameters
here, but dependent member types that wrap an ErrorType are fine, they
show up when a conformance had an invalid type witness.

Fixes the remaining example from https://github.com/apple/swift/issues/59384.
2024-04-03 19:37:20 -04:00
Slava Pestov
c1dc44643c Add regression test for rdar://111991454 2024-04-03 15:11:59 -04:00
Slava Pestov
5afdb987e2 Merge pull request #72146 from slavapestov/ncgenerics-fixes-9
Non-copyable generics fixes, part 9
2024-03-07 22:14:33 -05:00
Slava Pestov
af8c8f1671 Sema: Remove non-experimental associated type inference 2024-03-07 17:30:17 -05:00
Slava Pestov
41df661160 AST: Use a builtin conformance for unconditional Copyable/Escapable
This generalizes what we were already doing for classes.
2024-03-07 15:07:47 -05:00
Slava Pestov
3662bb2a28 Remove REQUIRES: asserts from fixed crashers 2024-03-06 21:38:28 -05:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Slava Pestov
2f4ed5a949 Sema: Clean up diagnoseMissingOwnership()
- Pass down the TypeResolution instance so we can get the generic
  signature. This ensures we always use the correct signature in
  SIL mode.

- Don't diagnose if the type contains error types.
2024-02-29 18:13:28 -05:00
Slava Pestov
d3aa3a8db9 Adjust XFAILs 2024-02-29 13:55:48 -05:00
Slava Pestov
f2bd764381 AST: Fix crash with circular raw value
Fixes rdar://problem/123543175.
2024-02-26 19:56:19 -05:00
Slava Pestov
e7d7f6f69f RequirementMachine: Add Copyable/Escapable requirements to 'placeholder' generic signatures
If we fail to build a generic signature (or requirement signature of a
protocol) because of a request cycle or because Knuth-Bendix completion
failed, we would create a placeholder signature with no requirements.

However in a move-only world, a completely unconstrained generic
parameter might generate spurious diagnostics when used in a copyable
way. For this reason, let's outfit these placeholder signatures with
a default set of conformance requirements to Copyable and Escapable.
2024-02-20 18:26:05 -05:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
Slava Pestov
70c9f8a47e RequirementMachine: Leave behind conflicting requirements in the minimized signature
Requirement lowering only expects that it won't see two requirements
of the same kind (except for conformance requirements). So only mark
those as conflicting.

This addresses a crash-on-invalid and improves diagnostics for
move-only generics, because a conflict won't drop the copyability
of a generic parameter and expose a move-only-naive user to
confusing error messages.

Fixes #61031.
Fixes #63997.
Fixes rdar://problem/111991454.
2024-02-15 14:32:31 -05:00
Slava Pestov
06b1aee360 Evaluator: Cache circular evaluation to avoid redundant diagnostics
Previously, if a request R evaluated itself N times, we would emit N
"circular reference" diagnostics. These add no value, so instead let's
cache the user-provided default value on the first circular evaluation.

This changes things slightly so that instead of returning an
llvm::Expected<Request::OutputType>, various evaluator methods take
a callback which can produce the default value.

The existing evaluateOrDefault() interface is unchanged, and a new
evaluateOrFatal() entry point replaces
llvm::cantFail(ctx.evaluator(...)).

Direct callers of the evaluator's operator() were updated to pass in
the callback. The benefit of the callback over evaluateOrDefault() is
that if the default value is expensive to constuct, like a dummy
generic signature, we will only construct it in the case where a
cycle actually happened, otherwise we just delete the callback.

(cherry picked from commit b8fcf1c709efa6cd28e1217bd0efe876f7c0d2b7)
2024-02-09 16:02:24 -08:00
Slava Pestov
387156ae11 Merge pull request #71354 from slavapestov/check-type-witness-fix
Sema: Fix problems with checkTypeWitness()
2024-02-03 08:28:14 -05:00
Slava Pestov
477e0572c2 Sema: Tighten invariants in associated type inference 2024-02-02 23:30:44 -05:00
Slava Pestov
ea15d9f9b2 Stop passing -warn-redundant-requirements in tests 2024-02-02 14:57:19 -05:00
Slava Pestov
991a6de207 Merge pull request #71131 from slavapestov/conformance-checker-vs-type-witnesses-untangling
Sema: Decouple type witness resolution from the ConformanceChecker
2024-01-25 20:06:01 -05:00
Slava Pestov
2764333fea Sema: Introduce ResolveTypeWitnessesRequest 2024-01-24 21:45:34 -05:00
Kavon Farvardin
ba2f05cce2 NCGenerics: adjust number of diagnostics
Something I changed in the implementation of NoncopyableGenerics has
gotten the number back down to 6, where it was before I started :)
2024-01-23 22:42:38 -08:00
Slava Pestov
0b0ad738dd AST: Record a HadError bit in DelayedConformanceDiags 2024-01-20 19:16:58 -05:00
Slava Pestov
5d58a634ad Sema: Clean up openType() and openUnboundGenericType()
Fixes:
- rdar://112785081
- https://github.com/apple/swift/issues/67906
- https://github.com/apple/swift/issues/68160
2024-01-09 15:23:42 -05:00
Slava Pestov
335d6ffea1 Frontend: Add -disable-experimental-associated-type-inference flag 2023-12-08 13:39:10 -05:00
Slava Pestov
e29c3a90aa AST: Lazily populate associated conformances with -enable-experimental-associated-type-inference 2023-12-07 19:27:59 -05:00
Slava Pestov
b1ed3c270c Add regression tests for rdar://116434843 and #59772 2023-12-07 19:27:59 -05:00
Slava Pestov
e65290c2bd Sema: Associated type inference skips witnesses that might trigger a request cycle
This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / https://github.com/apple/swift/issues/48680
- rdar://38913692 / https://github.com/apple/swift/issues/49066
- rdar://56672411
- https://github.com/apple/swift/issues/50010
- rdar://81587765 / https://github.com/apple/swift/issues/57355
- rdar://117442510
2023-11-14 12:08:59 -05:00
Kavon Farvardin
0f2a8d5ea7 bump number of diags in 0161-issue-49119.swift
Seems we already emit 6 duplicate diagnostics for this test, so what's
one more?

I'm not sure what change I made triggered this additional diagnostic.
2023-10-18 20:02:17 -07:00