Commit Graph

22 Commits

Author SHA1 Message Date
Alexis Laferrière
3cb1b6a96f Intro Evaluator::hasActiveRequest to prevent request cycles 2019-05-09 10:46:30 -07:00
Doug Gregor
eaf22c2661 [Request-evaluator] Add cacheOutput() operation to populate the cache.
Allow one to cache the output for a particular request when it is known
a priori, such as when the known result is deserialized.
2019-05-05 21:41:07 -07:00
Slava Pestov
3f5a06bc3e AST: Always diagnose request evaluator cycles 2019-04-22 22:22:23 -04:00
Jordan Rose
bcc4ba9e66 Request Evaluator: save malloc traffic by canonicalizing AnyRequests (#20999)
Use the Dependencies map to standardize on a single allocation for
any particular Request. We could probably go all the way to unique
ownership here, but I didn't want to rock the boat.

Results in minor speedups compiling the stdlib. (I was experimenting
with using a new, auto-cached Request for a hot lookup path, which may
or may not turn out to be worth it, but even without that we can take
this.)
2018-12-04 08:14:39 -08:00
Graydon Hoare
388e357218 [Stats] Add UnifiedStatsReporter tracing/profiling machinery to request-evaluator. 2018-09-02 02:00:07 -07:00
Xi Ge
ce29c64964 [Evaluator] Refactor evaluator's GraphViz output to the destructor of the evaluator. NFC
This allows us to output dependency-graph while using the compiler in
other tools, like swift-ide-test, sourcekitd-test, etc.
2018-08-28 18:16:44 -07:00
Harlan Haskins
5498e869c0 Use evaluator's dependency printing for cycles 2018-08-15 16:02:48 -07:00
Harlan Haskins
c31d7f808a Rebase on master and resolve conflicts 2018-08-15 11:22:09 -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
Jordan Rose
c56f3c6a76 Request evaluator: Use DenseMap::find_as to look up Requests
...when we don't need to store them, to avoid copying the Request into
an AnyRequest heap box.
2018-08-10 10:23:40 -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
0418ae4f81 [Evaluator] Centralize the evaluation of a request under getResultUncached().
We had duplicated logic for stats recording and pretty stack traces, including
missing one pretty stack trace. Eliminate duplication.
2018-06-29 14:26:31 -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
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
2deea3cbd3 [Request-evaluator] Add PrettyStackTrace support.
Print out the stack of requests being evaluated when we crash, so we can see
the dependency chain the triggered the crash.
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
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
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
8886fca400 Address the simple issues raised by Graydon and Huon 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