Commit Graph

34 Commits

Author SHA1 Message Date
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Slava Pestov
28e7ed03d0 AST: Remove the 'legacy' request dependency graph implementation 2021-01-08 23:17:12 -05:00
Slava Pestov
e4437d2187 AST: Don't print cached request values when dumping dependencies
This becomes tricky with the new per-request cache representation.

We can add it back later if we need it, but I feel like this code
path isn't particularly useful right now anyway.
2021-01-05 17:56:38 -05:00
Robert Widmann
8c913e385e Remove LegacyCascadingDependencies 2020-09-21 10:42:33 -06:00
Robert Widmann
3228a5903a [NFC] Rename Flags
-enable-experimental-private-intransitive-dependencies -> -enable-direct-intramodule-dependencies
-disable-experimental-private-intransitive-dependencies -> -disable-direct-intramodule-dependencies

While we're here, rename DependencyCollector::Mode's constants and clean
up the documentation.
2020-06-09 16:00:59 -07:00
Robert Widmann
e7f38db235 [NFC] Have Evaluator's Constructor Read LangOptions
It's a touch cleaner to do this than passing around a pile of bools.
2020-06-02 09:51:04 -07:00
Robert Widmann
b06211eac4 Initial plumbing for private dependencies
Add a mode bit to the dependency collector that respects the frontend flag in the previous commit.

Notably, we now write over the dependency files at the end of the compiler pipeline when this flag is on so that dependency from SILGen and IRGen are properly written to disk.
2020-05-05 13:48:25 -07:00
Robert Widmann
3d09a00a0a CacheKind -> RequestFlags 2020-03-31 16:16:53 -07:00
Robert Widmann
f1b12e154d [Gardening] Use std::isnan 2020-03-27 10:11:08 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07: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
087e2f2746 [Evaluator Ergonomics] Add location information options to the requests 2019-09-06 11:16:17 -07:00
Robert Widmann
7a51cfcb87 [Evaluator Ergonomics] Add Request Signatures
Also add their caching kinds.  This information will be used to remove
the need to define classes at all.
2019-09-05 13:15:02 -07:00
Robert Widmann
a19a70e5c9 Switch all request infrastructure to SWIFT_REQUEST
Formally define the Zones in the TypeID header.  This is not its final
resting place.
2019-08-27 17:38:14 -07:00
Doug Gregor
deb85ef586 [Request-evaluator] Fix ArithmeticEvaluator unit test. 2019-07-11 10:27:30 -07:00
Doug Gregor
46a220b9a1 [Evaluator] Simplify template signature for SimpleRequest.
Encode the input and output parameters for a SimpleRequest instance in a
function type and move the CacheKind to the end, making it easier to
sort out inputs from outputs:

```
  class DefaultTypeRequest
    : public SimpleRequest<DefaultTypeRequest,
                           Type(KnownProtocolKind, const DeclContext *),
                           CacheKind::SeparatelyCached>
```
2019-07-10 14:54:22 -07:00
Slava Pestov
3f5a06bc3e AST: Always diagnose request evaluator cycles 2019-04-22 22:22:23 -04:00
Harlan Haskins
5498e869c0 Use evaluator's dependency printing for cycles 2018-08-15 16:02:48 -07:00
Harlan Haskins
5a6985f39e Remove SimpleRequest::breakCycle
This patch removes the need for Request objects to provide a default
cycle-breaking value, instead opting to return llvm::Expected so clients
must handle a cycle failure explicitly.

Currently, all clients do the 'default' behavior, but this opens the
possibility for future requests to handle failures explicitly.
2018-08-15 11:01:12 -07:00
Doug Gregor
84273b2ba3 [Evaluator] Rename request’s operator() to evaluate() to make it more clear. 2018-06-29 15:45:15 -07:00
Doug Gregor
a6f46584ec [Evaluator] Indirect evaluation of uncached requests through a separate table.
The bundling of the form of a request (e.g., the storage that makes up a request)
with the function that evaluates the request value requires us to perform
ad hoc indirection to address the AST —> Sema layering violation. For
example, ClassDecl::getSuperclass() calls through the LazyResolver (when
available) to form the appropriate request. This means that we cannot
use the the request-evaluator’s cache when LazyResolver is null, forcing
all cached state into the AST.

Provide the evaluator with a zone-based registration system, where each
request “zone” (e.g., the type checker’s requests) registers
callbacks to evaluate each kind of request within that zone. The
evaluator indirects through this table of function pointers, allowing
the request classes themselves to be available at a lower level (AST)
than the functions that perform the computation when the value isn’t
in the cache (e.g., Sema).

We are not taking advantage of the indirection yet; that’ll come in a
follow-up commit.
2018-06-29 15:41:55 -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
9843190300 [Request-evaluator] Disable cycle diagnostics when used in the type checker.
The type checker has *lots* cycles, and producing diagnostics for them
at this point in the development of the request-evaluator is not
productive because it breaks currently-working code. Disable cycle
diagnostics for now when using the request-evaluator in the type
checker. We'll enable it later as things improve, or as a separate
logging mode in the interim.
2018-06-14 15:29:57 -07:00
Doug Gregor
ca7bbe1c5e [Unit test] Qualify uses of std::isnan.
C++ shouldn't be this hard.
2018-06-12 15:10:51 -07:00
Doug Gregor
f9db209c72 [Evaluator test] Pull in std::isnan. 2018-06-12 09:42:10 -07:00
Doug Gregor
798d60ca9e [Evaluator] Add a Caching template parameter to SimpleRequest.
Simplify the definition of new request kinds by pulling the parameterization
of caching logic into SimpleRequest itself, so that the caching-related
parts of the contract cannot easily be forgotten.
2018-06-01 14:58:56 -07:00
Doug Gregor
44099adeb9 [Evaluator] Simplify the definition of cycle diagnostics for a SimpleRequest.
The arithmetic evaluator cannot really make use of the new diagnostics
machinery, but put it in place for other request kinds.
2018-06-01 14:47:07 -07:00
Doug Gregor
b12d319c44 [Evaluator] Print cached value as part of dependency tree printing. 2018-06-01 08:56:18 -07:00
Doug Gregor
346bb99f73 [Evaluator] GraphViz printing for all of the dependencies.
Introduce another form of debugging dump for the evaluator, rendering the
complete dependency graph using GraphViz, including all dependencies and
values cached within the evaluator.
2018-06-01 08:56:18 -07:00
Doug Gregor
8822b2edbc [Evaluator] Track dependencies of each request.
Perform online tracking of the (direct) dependencies of each request made
to the evaluator, and introduce debugging code to print these dependencies
as a tree (from a particular request).
2018-06-01 08:56:18 -07:00
Doug Gregor
d687446e06 [Evaluator] Simplify the definition of new requests and make them printable.
Introduce a CRTP base class, SimpleRequest, which simplifies the task of
defining a new request kind by handling the storage of the values (in a
std::tuple), their hashing, equality, printing, etc. The values are passed
along to the subclass’s operator() so they’re mostly treated as (const)
parameters, making mutation of the request state impossible.

Extend AnyValue and AnyRequest with printing logic, so we can print any
request for debugging purposes, and
2018-06-01 08:56:18 -07:00
Doug Gregor
cbc6289962 [TypeID] Use .def files to introduce TypeID specializations.
Simplify the static registration of types for use with TypeID by introducing
a more declarative approach. Each zone provides a .def file listing the
types and templates defined by that zone. The .def file is processed by
include/swift/Basic/DefineTypeIDZone.h with its zone number, which assigns
values to each of the types/templates and introduces the TypeID
specializations.
2018-06-01 08:56:18 -07:00
Doug Gregor
4b9e3ea84b [Evaluator] Detect cycles via the active-requests stack rather than the cache.
Turn the `activeRequests` stack into a `SetVector` and use it to detect
cycles. This approach works for uncached requests, and lets us simplify
the external-caching protocol quite a bit because we no longer record
“in-flight” states. Simplify the cache as well.

Thanks to Graydon for the suggestion.
2018-06-01 08:56:18 -07:00
Doug Gregor
4ac125f41f [Evaluator] Introduce a simple request evaluator.
Meant as a replacement for the barely-started iterative type checker,
introduce a simpler "evaluator" that can evaluate individual requests
(essentially, function objects with some additional API), caching
results as appropriate and detecting cycles.
2018-06-01 08:56:18 -07:00