Commit Graph

26 Commits

Author SHA1 Message Date
Hamish Knight
57557dec8e [Evaluator] Enforce consistent results for cyclic requests
Record when we encounter a request cycle, and enforce that the outer
step of the cycle also returns the default value. This fixes a couple
of crashers where we were ending up with conflicting values depending
on whether the request was queried from within the cycle or from
outside it.
2025-10-08 21:16:02 +01:00
Hamish Knight
13023de4c4 [Evaluator] Avoid emitting duplicate "through reference here" notes
Filter out any duplicate notes to help cut down on the noise for
request cycle diagnostics. Some of the note locations here still aren't
great, but this at least stops us from repeating them for each
intermediate request.
2025-10-05 20:48:08 +01: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
Hamish Knight
61156e1e6b [Sema] Avoid diagnosing overrides for invalid decls
Invalid decls won't match any overrides in the
base class, so avoid diagnosing that they don't
override anything.
2024-07-15 12:47:50 +01:00
Slava Pestov
2764333fea Sema: Introduce ResolveTypeWitnessesRequest 2024-01-24 21:45:34 -05:00
Nishith Shah
8e2e625543 [Diagnostics] Use imperative msg for protocol conformance & switch-case fixits
This commit changes fixit messages from a question/suggestion to an
imperative message for protocol conformances and switch-case. Addresses
https://github.com/apple/swift/issues/67510.
2023-08-13 22:34:26 -07:00
Luciano Almeida
7300fb5836 [Sema] Improve diagnostic for closure return contextual mismatch 2022-09-04 22:28:49 -03:00
Anthony Latsis
cdded2ba9f Gardening: Migrate test suite to GH issues: decl 2022-08-26 03:26:23 +03:00
Luciano Almeida
11877d7a1b [Sema][Revert] Revert CTP to CTP_ReturnStmt for closure result in return stmt 2022-07-15 09:31:11 -03:00
Luciano Almeida
44f4eba6c5 [Sema] Add return context valid source loc to implicit tuple expr context for diagnostic 2022-07-11 20:57:54 -03:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Slava Pestov
02bfb79935 RequirementMachine: Concrete contraction discards errors from inferred requirements 2022-04-01 23:55:19 -04:00
Slava Pestov
7c29aaf3e2 Sema: Fix generics invariant violations in override checking
Override checking checks if the derived declaration's generic
signature is compatible with the base, but it does this after
doing a bunch of other checks which feed potentially invalid
type parameters to generic signature queries.

Now that the requirement machine is stricter about this kind
of this, re-organize some code to get around this.

Unfortunately this regresses a diagnostic, because we reject
candidates with mismatched generic requirements earlier in
the process.
2021-08-23 21:52:55 -04:00
Slava Pestov
07bd07926f AST: Implement extractNearestSourceLoc() for ProtocolConformance 2021-02-10 16:30:30 -05:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Slava Pestov
bd36100cb3 Update tests in preparation for disabling parser lookup
I created a second copy of each test where the output changes
after disabling parser lookup. The primary copy now explicitly
calls the frontend with -disable-parser-lookup and expects the
new diagnostics; the *_parser_lookup.swift version calls the
frontend with -enable-parser-lookup and has the old expectations.

This allows us to turn parser lookup on and off by default
without disturbing tests. Once parser lookup is completely
removed we can remove the *_parser_lookup.swift variants.
2020-10-03 09:37:55 -04:00
Robert Widmann
5dc060ee57 Define ResolveTypeRequest 2020-04-30 16:10:25 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Robert Widmann
f9d1f700e5 [SR-12236] Commit a regression test
This is technically a source break, but it was always a circularity
issue. It will compile fine in isolation, but all attempts to lookup
nested type via qualified lookup (e.g. witness matching) will re-enter
themselves and potentially produce inconsistent results.

Commit a regression test so we nail down this behavior to see if we can
revisit this.
2020-02-25 15:19:14 -08:00
Robert Widmann
e7170bd751 Add Qualified Lookup Requests 2019-12-16 15:36:09 -08:00
Hamish Knight
31570f3f5c Add another override circularity test case 2019-12-04 16:35:08 -08:00
Robert Widmann
01d272073a Requestify Witness Resolution
Witness matching is a source of a lot of ad-hoc cycles, and mixes the
logic that performs resolution, caching, validation, and cycle detection into one
place.  To make matters worse, some checkers kick off other checks in
order to cache work for further declarations, and access an internal
cache on their subject conformance for many requirements at once, or
sometimes just one requirement.

None of this fits into the request evaluator's central view of the
caching.  This is further evidenced by the fact that if you attempt to
move the caching step into the evaluator, it overcaches the same
witness and trips asserts.

As a start, define requests for the resolution steps, and flush some
hacks around forcing witness resolution. The caching logic is mostly
untouched (the requests don't actually cache anything), but some cycle
breaking is now handled in the evaluator itself.  Once witness matching
has been refactored to cache with the evaluator, all of these hacks can
go away.

My urge to destroy the LazyResolver outweighs the compromises here.
2019-11-05 13:28:07 -08:00
Slava Pestov
201c460772 AST: Fix crash in getContextSubstitutions() when a class has a malformed superclass type
It is possible for getSuperclassDecl() to return a non-null type, while
getSuperclass() returns an ErrorType. In this case, getContextSubstitutions()
could crash because the walk of the superclass chain via getSuperclass()
might not find the context class.

Instead of crashing in asserts builds, let getContextSubstitutions()
silently build an invalid substitution map here, just as it does in no-asserts
builds.
2019-10-24 00:00:36 -04:00
Slava Pestov
284fbf9983 Sema: Fix crash when override checking encounters circularity
getInterfaceType() will return an ErrorType if the declaration is currently
being validated, which can happen if override checking triggers associated
type inference.

I believe this is <rdar://problem/47220065>.
2019-10-24 00:00:29 -04:00
Robert Widmann
a537e04a12 Break Another Overload Resolution Cycle
Resolve a cycle caused by overload resolution considering recursive
static candidates where before it would silently reject them.  In
a world before the InterfaceTypeRequest, the overload resolution
machinery would attempt to validate the declaration and would recieve
a bad answer.  This caused circular candidates to be ignored as a side
effect.  This behavior was partially restored by the fixes in #27725 and #27668
but that isn't enough for recursive static variables.  Even if it were,
the constraint fix kind doesn't make sense.

Luckily, the right answer is to just reject recursive static VarDecl
candidates entirely.

Addresses rdar://56410015
2019-10-20 23:56:00 -07:00
Robert Widmann
63e3a0125c Memnber Type Lookups Shouldn't Recurse
When member type lookup is rooted at a typealias, it should not be possible for that
lookup to see the typealias itself. This prevents recursively trying
to resolve the underlying type, which used to be silently ignored when
validateDecl bounced the caller back with an error type or a null type.

Addresses rdar://56411408
2019-10-18 17:08:52 -07:00