Commit Graph

49 Commits

Author SHA1 Message Date
Hamish Knight
f643f3d990 [Evaluator] Add "through" to "declared here" request cycle notes
Make it a bit clearer that these are steps in the request cycle.
2025-10-05 20:48:08 +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
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
4d15fa0087 RequirementMachine: Don't diagnose trivial circularity 'protocol P : P' as redundant
Every protocol gets an 'identity conformance' rule [P].[P] => [P].
A trivially-stated circularity is always redundant because of this
rule, and we diagnose circular inheritance elsewhere as a hard
error, so just add a special case to skip adding such a rule here
to avoid the useless warning on top of the existing error.
2022-04-05 21:12:51 -04:00
Slava Pestov
4068c9d707 Pass -requirement-machine-{protocol,inferred}-signatures=verify in remaining tests that fail due to diagnostics 2022-04-01 23:55:34 -04:00
Slava Pestov
4337899ded Merge pull request #35334 from slavapestov/remove-evaluator-type-erasers
Remove request evaluator's AnyRequest and AnyValue type erasers
2021-01-11 14:44:54 -05:00
Doug Gregor
af948715d9 Fix test case 2021-01-11 09:00:27 -08:00
Slava Pestov
28e7ed03d0 AST: Remove the 'legacy' request dependency graph implementation 2021-01-08 23:17:12 -05:00
Doug Gregor
3a651a61b7 [Concurrency] Fix circular reference on isolation propagation. 2020-10-13 22:57:06 -07:00
Doug Gregor
6af690aaba Eliminate HasCircularInheritanceRequest.
This is now reliably detected by SuperclassDeclRequest.
2020-09-29 17:42:17 -07:00
Doug Gregor
4ddf6e565a Teach SuperclassDeclRequest to always diagnose circularity.
Rather than relying on clients to cope with the potential for circular
inheritance of superclass declarations, teach SuperclassDeclRequest to
establish whether circular inheritance has occurred and produce "null"
in such cases. This allows other clients to avoid having to think about

To benefit from this, have SuperclassTypeRequest evaluate
SuperclassDeclRequest first and, if null, produce a Type(). This
ensures that we don't get into an inconsistent situation where there
is a superclass type but no superclass declaration.
2020-09-29 17:42:17 -07:00
Anthony Latsis
4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Slava Pestov
0eb2484a93 AST: Only build request dependency graph if frontend is run with -build-request-dependency-graph
This adds a measurable amount of runtime overhead, but it's only
needed for debugging.
2020-01-08 22:35:55 -05:00
Robert Widmann
e7170bd751 Add Qualified Lookup Requests 2019-12-16 15:36:09 -08:00
Robert Widmann
371526bdea Add a high-level request to type check a file 2019-12-03 17:16:14 -08:00
Hamish Knight
eacca4ed0c Requestify circular inheritance checking
Add requests for checking whether a class,
protocol, or enum have circular references in
their inheritance lists.
2019-11-11 09:34:56 -08:00
Hamish Knight
16cff49e65 [Sema] Requestify inheritsSuperclassInitializers (#27936)
* [Sema] Factor out shouldAttemptInitializerSynthesis

This makes sure we don't attempt to synthesize
a memberwise or default initializer for an invalid
decl, or one in a module interface.

* [Sema] Requesify inheritsSuperclassInitializers

This commit introduces a request for computing
whether a class inherits both designated and
convenience initializers from its superclass.

The shared logic of finding initializers which the
subclass hasn't overriden has been factored out
into `collectNonOveriddenSuperclassInits`.

* Cleanup addImplicitInheritedConstructorsToClass

This commit removes some code that's no longer
needed. In addition, now that we've requestified
`inheritsSuperclassInitializers`, we can directly
diagnose on non-inherited required convenience
inits within the loop.

* Inherited init synthesis no longer deals with clang decls

Now that the computation of
`inheritsSuperclassInitializers` has been split off
into a request, we can avoid calling
`addImplicitInheritedConstructorsToClass` for clang
decls.

* Address review feedback

Continue to cache the InheritsSuperclassInits bit
on the AST.
2019-10-31 11:07:06 -07:00
Pavel Yaskevich
fbb55ce5bc [Diagnostics] Add a tailored diagnostic for no accessible initializers 2019-08-22 17:25:24 -07:00
Slava Pestov
3f5a06bc3e AST: Always diagnose request evaluator cycles 2019-04-22 22:22:23 -04:00
Doug Gregor
d07fa5ab69 Switch many callers of ClassDecl::getSuperclass() to ClassDecl::getSuperclassDecl().
ClassDecl::getSuperclass() produces a complete interface type describing the
superclass of a class, including any generic arguments (for a generic type).
Most callers only need the referenced ClassDecl, which is (now) cheaper
to compute: switch those callers over to ClassDecl::getSuperclassDecl().

Fixes an existing test for SR-5993.
2018-07-31 10:14:44 -07:00
Doug Gregor
dbe9cb6bd3 Loosen up a FileCheck test to cope with ObjC interop vs. not. 2018-07-18 19:46:23 -07:00
Doug Gregor
b70466dc63 [Type Checker] Add a request kind for computing 'ValueDecl::isObjC()'.
Still a WIP
2018-07-18 14:50:39 -07:00
Slava Pestov
00b3ce18ca AST: Fix crash when doing name lookup into class with circular inheritance 2018-07-10 17:01:12 -07:00
Slava Pestov
19de53f6cf Sema: Remove dead code from access level computation rework 2018-07-06 23:50:36 -07:00
Graydon Hoare
b67e8c3b51 [test] Update circular_inheritence.swift to handle AccessLevelRequests. 2018-07-04 16:56:27 -07:00
Slava Pestov
7ca9f865f5 Sema: Move checkInheritanceClause() calls to typeCheckDecl() 2018-06-30 00:20:36 -07:00
Slava Pestov
ba30de0f08 Sema: Re-word circular inheritance diagnostics 2018-06-28 16:54:28 -07:00
Doug Gregor
197642d37b [Request-evaluator] Track # of evaluations for each request kind.
Using the unified stats reporter, track the # of evaluations for each
type checking request kind.
2018-06-22 00:01:55 -07:00
Doug Gregor
81bee08369 [AST] Make ValueDecls displayable via their DeclRefs. 2018-06-21 06:39:03 -07:00
Doug Gregor
b6c5830277 [Request-evaluator] Add GraphViz output option -output-request-graphviz.
Introduce a command-line option to visualize the complete set of output
request dependencies evaluated by a particular compile action. This is
exposing existing visualization facilities to the (-frontend) command line.
2018-06-21 00:23:50 -07:00
Doug Gregor
7ac0a5be14 [Request-evaluator] Improve dumping of dependencies and cycles.
When dumping dependencies, clean up the output in two ways:

* Elide redundant but (non-cyclic) references to the same dependency.
* When dumping a cycle, highlight the path to the cycle so it stands out.
2018-06-16 10:29:52 -07:00
Doug Gregor
b1b3c43c59 [Request-evaluator] Add -debug-cycles flag to print cycles.
As a debugging aid, introduce a new frontend flag `-debug-cycles` that
will emit a debug dump whenever the request-evaluator encounters a cyclic
dependency, while otherwise allowing compilation to continue.
2018-06-16 10:29:52 -07:00
Doug Gregor
2b2e143f59 [Request-Evaluator] Introduce a request for getting an "inherited type". 2018-06-14 15:29:57 -07:00
Doug Gregor
f781b71d16 [Type checker] Produce diagnostics for each of the evaluator requests.
We were suppressing diagnostics for some request kinds; we shouldn't
do that.
2018-06-14 15:29:57 -07:00
Doug Gregor
ef337bb8ba [Evaluator] Use the request-evaluator for the superclass of a class.
Wire up the request-evaluator with an instance in ASTContext, and
introduce two request kinds: one to retrieve the superclass of a class
declaration, and one to compute the type of an entry in the
inheritance clause.

Teach ClassDecl::getSuperclass() to go through the request-evaluator,
centralizing the logic to compute and extract the superclass
type.

Fixes the crasher from rdar://problem/26498438.
2018-06-14 15:28:36 -07:00
Doug Gregor
8bd863e645 [GSB] Reimplement self-derived checking for conformance constraints.
The general self-derived check doesn't really make sense for
conformance constraints, because we want to distinguish among
different protocol conformances.
2017-03-23 23:45:43 -07:00
Doug Gregor
042e6510c3 [AST] Drop ProtocolDecl's "inherited protocols" list.
The list of directly inherited protocols of a ProtocolDecl is already
encoded in the requirement signature, as conformance constraints where
the subject is Self. Gather the list from there rather than separately
computing/storing the list of "inherited protocols".
2017-02-20 09:41:00 -08:00
Slava Pestov
4ed17f0f63 AST: Add a new 'isBeingValidated' flag to replace a couple of other flags
Previously, validateDecl() would check if the declaration had an
interface type and use that as an indication not to proceed.

However for functions we can only set an interface type after
checking the generic signature, so a recursive call to validateDecl()
on a function would "steal" the outer call and complete validation.

For generic types, this meant we could have a declaration with a
valid interface type but no generic signature.

Both cases were problematic, so narrow workarounds were put in
place with additional new flags. This made the code harder to
reason about.

This patch consolidates the flags and establishes new invariants:

- If validateDecl() returns and the declaration has no interface
  type and the isBeingValidated() flag is not set, it means one
  of the parent contexts is being validated by an outer recursive
  call.

- If validateDecl() returns and the declaration has the
  isBeingValidated() flag set, it may or may not have an interface
  type. In this case, the declaration itself is being validated
  by an outer recursive call.

- If validateDecl() returns and the declaration has an interface
  type and the isBeingValidated() flag is not set, it means the
  declaration and all of its parent contexts are fully validated
  and ready for use.

In general, we still want name lookup to find things that have an
interface type but are not in a valid generic context, so for this
reason nominal types and associated types get an interface type as
early as possible.

Most other code only wants to see fully formed decls, so a new
hasValidSignature() method returns true iff the interface type is
set and the isBeingValidated() flag is not set.

For example, while resolving a type, we can resolve an unqualified
reference to a nominal type without a valid signature. However, when
applying generic parameters, the hasValidSignature() flag is used
to ensure we error out instead of crashing if the generic signature
has not yet been formed.
2016-12-19 01:38:23 -08:00
Slava Pestov
4c0d1488e2 Sema: Don't add implicit constructors when checking inheritance clause
This leads to some bad recursion through validateDecl(), even
when called from the ITC. We already had machinery to add
implicit constructors later, it just had to be extended to
do it for the superclass as well.
2016-12-09 20:12:28 -08:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Pavel Yaskevich
72b5939612 [Diagnostics] SR-2193: Improve diagnostic when member exists but it's not a type 2016-10-14 10:34:32 -07:00
Slava Pestov
7b6736df29 Sema: When validating a nested type, only validate the parent, do not type check it
There's no need to walk the siblings of the nested type. This fixes
a class of infinite recursion issues when inheriting from nested
types.
2016-06-18 17:05:27 -07:00
Slava Pestov
65b317fa36 Sema: Fix infinite recursion when checking if class with circular inheritance has failable initializer
Fixes <rdar://problem/19919421>.

Swift SVN r30677
2015-07-27 00:40:45 +00:00
Slava Pestov
74c2cb7820 Sema: more robust diagnostic for circular inheritance
The code would generate different diagnosics depending on
the cycle having length 1 or longer. The length 1 case
was broken if the path had a prefix that wasn't part
of the cycle, eg if we have C : A, A : A and visit C
first.

Swift SVN r28317
2015-05-08 17:14:57 +00:00
Doug Gregor
480b6e9af4 Start using DeclContext::getLocalConformances() to decide which conformances get recorded.
Swift SVN r26320
2015-03-19 22:10:04 +00:00
Doug Gregor
940ba832e5 Use the conformance lookup table to find protocol conformances.
Replace the loop over all known protocols with a query into the
actual conformance lookup table, which more properly deals with
out-of-order conformance queries, inheritance of protocol
conformances, and conformance queries in multi-file situtations.

The SILGen test change is because we're no longer emitting redundant
conformances, while the slight diagnostic regression in
circular-inheritance cases is because we handle circular inheritance
very poorly throughout the compiler.

While not the end, this is a major step toward finishing
rdar://problem/18448811.

Swift SVN r26299
2015-03-19 06:35:28 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Joe Pamer
8502a7e203 The type checker was able to diagnose indirectly recursive inheritance cycles, but the simple direct case would result in a compiler crash. (rdar://problem/16712071)
Swift SVN r21816
2014-09-09 23:58:57 +00:00
Doug Gregor
6c80f64c6e Diagnostic circular class inheritance.
Break cycles agressively when we find circular class inheritance. The
stronger AST invariants prevent us from having to check for loops
everywhere in the front end.


Swift SVN r7325
2013-08-19 15:31:13 +00:00