Commit Graph

40 Commits

Author SHA1 Message Date
Robert Widmann
ee723cd953 Document Some Whys
* Document a number of legacy conditions and edge cases

* Add lexicon definitions for "dependency source", "dependency sink",
"cascading dependency" and "private dependency"
2020-03-31 16:19:13 -07:00
Robert Widmann
3d09a00a0a CacheKind -> RequestFlags 2020-03-31 16:16:53 -07:00
Robert Widmann
2b0ca2ae65 Add the active tracker to the dependency sink points 2020-03-31 16:16:53 -07:00
Robert Widmann
8c69814f5c Define Dependency Sinks
Convert most of the name lookup requests and a few other ancillary typechecking requests into dependency sinks.

Some requests are also combined sinks and sources in order to emulate the current scheme, which performs scope changes based on lookup flags. This is generally undesirable, since it means those requests cannot immediately be generalized to a purely context-based scheme because they depend on some client-provided entropy source. In particular, the few callers that are providing the "known private" name lookup flag need to be converted to perform lookups in the appropriate private context.

Clients that are passing "no known dependency" are currently considered universally incorrect and are outside the scope of the compatibility guarantees. This means that request-based dependency tracking registers strictly more edges than manual dependency tracking. It also means that once we fixup the clients that are passing "known private", we can completely remove these name lookup flags.

Finally, some tests had to change to accomodate the new scheme. Currently, we go out of our way to register a dependency edge for extensions that declare protocol conformances. However, we were also asserting in at least one test that extensions without protocol conformances weren't registering dependency edges. This is blatantly incorrect and has been undone now that the request-based scheme is automatically registering this edge.
2020-03-31 16:16:53 -07:00
Robert Widmann
3f8f3a89cb Teach the Evaluator about Incremental Dependencies
Formalize DependencyScope, DependencySource, and the incremental dependency stack.

Also specialize SimpleRequest to formalize dependency sources and dependency sinks. This allows the evaluator's internal entrypoints to specalize away the incremental dependency tracking infrastructure if a request is not actually dependency-relevant.
2020-03-31 15:40:04 -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
Mike Ash
cd2b54f74e Merge branch 'master' into master-rebranch 2020-01-24 11:30:32 -05:00
swift-ci
ec55ec0bb5 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-23 11:03:41 -08:00
Hamish Knight
f081ae51d4 Revert "Revert "Don't heap allocate for active requests""
f8a1ad22e1
2020-01-23 11:03:32 -08:00
Saleem Abdulrasool
f8a1ad22e1 Revert "Don't heap allocate for active requests" 2020-01-23 08:33:31 -08:00
swift-ci
cbd174c46f Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-23 07:23:42 -08:00
Hamish Knight
2b97bf8af4 [Evaluator] Stop canonicalizing requests
This is unnecessary given we now only create
AnyRequests when caching, or when building the
dependency graph.
2020-01-20 09:15:16 -08:00
Hamish Knight
4b698a5a31 [AST] Introduce ActiveRequest
This wrapper is used to type erase a reference to
a request on the stack, and can be converted into
an AnyRequest when persistent storage is required.

Switch the evaluator over to using ActiveRequest
for its stack of active requests, meaning it now
only needs to heap allocate requests when they
enter the cache, or if it's building the (disabled
by default) dependency graph.
2020-01-20 09:15:16 -08:00
Arnold Schwaighofer
358e72b689 Adjust for removal of llvm::make_unique in favor of std::make_unique 2020-01-10 08:02:16 -08:00
Slava Pestov
1ed5453019 AST: Look for cached request result before checking for a cycle
This improves performance in the common case where the result has
already been cached, because the cycle check constructs an
AnyRequest existential, which is expensive.
2020-01-08 22:39:27 -05: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
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -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
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