Commit Graph

2162 Commits

Author SHA1 Message Date
Saleem Abdulrasool
25d83bfb6b Basic: add explicit template parameters for disambiguation
When building with MSVC, this would fail to compile due to the `buffer`
type (`uint8_t [8]`) being treated as `unsigned char *`, which is
expecting to be SFINAE'd to fail find an overload for the hash
combination.
2021-01-23 13:32:20 -08:00
Michael Gottesman
1e039cce38 Merge pull request #35563 from gottesmm/pr-cd7c9e97e46a0141e37f10fbfb74c094e0576ff3-followups
[ownership] cd7c9e97e4 followups
2021-01-22 19:05:12 -08:00
Robert Widmann
73ac8d3531 Replace llvm::MD5 with StableHasher 2021-01-21 17:19:38 -08:00
Robert Widmann
f5cb08e3d1 Add a Stable Hash Algorithm
Use SipHash-2-4 to replace llvm::MD5 as the hashing implementation backing Fingerprints and the interface hash.
2021-01-21 17:19:38 -08:00
Michael Gottesman
47f76f175c [sil] Add a variant of SmallSetVector that uses SmallPtrSet internally instead of SmallDenseSet. 2021-01-21 13:06:14 -08:00
Slava Pestov
f641a266a8 Merge pull request #35495 from slavapestov/remove-obsolete-staging-flags
Frontend: Remove a couple of obsolete staging flags
2021-01-19 21:28:47 -05:00
Slava Pestov
c456748551 Frontend: Remove a couple of obsolete staging flags
-enable-subst-sil-function-types-for-function-values
-enable-large-loadable-types

These defaulted to on, and there were no corresponding flags for
turning them off, so the flags had no effect.
2021-01-19 17:47:53 -05:00
Robert Widmann
1fd5f0835a [NFC] Evict Mock Fingerprints Code From Interface 2021-01-19 11:44:41 -08:00
David Ungar
0c99379185 Merge pull request #35405 from davidungar/fingerprint-assert 2021-01-16 14:40:48 -08:00
David Ungar
dbe4b6df43 Fix fingerprints in unit tests of driver. 2021-01-16 11:47:59 -08:00
David Zarzycki
e9309cd30f [Basic] NFC: Named variadic macros are a GNU extension 2021-01-16 05:44:01 -05:00
Andrew Trick
1ba3066950 CanonicalOSSALifetime: Add support for overlapping access scopes.
Access scopes for enforcing exclusivity are currently the only
exception to our ability to canonicalize OSSA lifetime purely based on
the SSA value's known uses. This is because access scopes have
semantics relative to object deinitializers.

In general, deinitializers are asynchronous with respect to code that
is unrelated to the object's uses. Ignoring exclusivity, the optimizer
may always destroy objects as early as it wants, as long as the object
won't be used again. The optimizer may also extend the lifetime
(although in the future this lifetime extension should be limited by
"synchronization points").

The optimizer's freedom is however limited by exclusivity
enforcement. Optimization may never introduce new exclusivity
violations. Destroying an object within an access scope is an
exclusivity violation if the deinitializer accesses the same variable.

To handle this, OSSA canonicalization must detect access scopes that
overlap with the end of the pruned extended lifetime. Essentially:

    %def
    begin_access // access scope unrelated to def
    use %def     // pruned liveness ends here
    end_access
    destroy %def

Support for access scopes composes cleanly with the existing algorithm
without adding significant cost in the usual case. Overlapping access
scopes are unusual. A single CFG walk within the original extended
lifetime is normally sufficient. Only the blocks that are not already
LiveOut in the pruned liveness need to be visited. During this walk,
local overlapping access are detected by scanning for end_access
instructions after the last use point. Global overlapping accesses are
detected by checking NonLocalAccessBlockAnalysis. This avoids scanning
instructions in the common case. NonLocalAccessBlockAnalysis is a
trivial analysis that caches the rare occurence of nonlocal access
scopes. The analysis itself is a single linear scan over the
instruction stream. This analysis can be preserved across most
transformations and I expect it to be used to speed up other
optimizations related to access marker.

When an overlapping access is detected, pruned liveness is simply
extended to include the end_access as a new use point. Extending the
lifetime is iterative, but with each iteration, blocks that are now
marked LiveOut no longer need to be visited. Furthermore, interleaved
accessed scopes are not expected to happen in practice.
2021-01-15 19:48:33 -08:00
David Ungar
7f36ab171b Allow Fingerprint::fromString to fail, returning None on bad input. 2021-01-15 13:46:46 -08:00
Xi Ge
fcbc2b4d9d Merge pull request #35414 from nkcsgexi/volatile-open-input
Frontend: add an option -bad-file-descriptor-retry-count
2021-01-15 12:58:55 -08:00
Xi Ge
ae9d873009 Frontend: add an option -bad-file-descriptor-retry-count
This option allows the compiler to retry opening an input file if the previous
opening returns an error of bad file descriptor. Swift-driver will set this
argument in certain circumstances to walk-around such error.

rdar://73157185
2021-01-15 10:28:27 -08:00
Alex Hoppen
bfe0a00551 Merge pull request #35429 from ahoppen/remove-bytetree
Remove ByteTree serialization format
2021-01-15 09:28:19 +01:00
Alex Hoppen
8ec8516893 Remove ByteTree serialization format
It was originally designed for faster trasmission of syntax trees from
C++ to SwiftSyntax, but superceded by the CLibParseActions. There's no
deserializer for it anymore, so let's just remove it.
2021-01-14 20:37:49 +01:00
Robert Widmann
cc0d919653 Remove Compiled Source 2021-01-13 23:00:16 -08:00
Robert Widmann
2475095021 Remove Ranges File Type 2021-01-13 22:42:17 -08:00
Robert Widmann
0102c52d18 Remove OutputFileMap's Knowledge of Range Dependencies 2021-01-13 22:14:02 -08:00
Slava Pestov
28e7ed03d0 AST: Remove the 'legacy' request dependency graph implementation 2021-01-08 23:17:12 -05:00
Slava Pestov
5585cac9dd AST: Remove AnyValue type eraser now that it's no longer needed
I'm keeping AnyValue.h around, since it has some useful overloads of
hash_value() and simple_display() that don't have a good home at this
time.
2021-01-08 23:17:12 -05:00
Slava Pestov
60644295d3 Merge pull request #35307 from slavapestov/wmo-perf-fix
Frontend: Don't record request references in WMO builds
2021-01-08 21:29:44 -05:00
Alexis Laferrière
575b7fb26f Merge pull request #35296 from xymus/fix-define-avail-sourcekit
[Sema] Fix storage of availability macros definition for SourceKit
2021-01-08 16:36:21 -08:00
Slava Pestov
797813fda4 Frontend: Don't record request references in WMO builds
Part of <rdar://problem/72906325>.
2021-01-07 23:52:55 -05:00
Alexis Laferrière
03a8567fd2 [Sema] Fix storage of availability macros definition for SourceKit
rdar://72356584
2021-01-07 13:26:52 -08:00
Slava Pestov
be8f4cc87d Merge pull request #35206 from slavapestov/per-request-caches
Per-request caches and dependency maps
2021-01-06 16:47:29 -05:00
Slava Pestov
7257f2918d Basic: Introduce an x-macro for enumerating TypeIDZones 2021-01-05 17:56:38 -05:00
Andrew Trick
a6bce7e308 Move SWIFT_ASSERT_ONLY to Compiler.h 2021-01-05 09:28:55 -08:00
Slava Pestov
0fa84c14a0 ASTScope: Remove the ExpandASTScopeRequest
This doesn't really fit the request evaluator model since the
result of evaluating the request is the new insertion point,
but we don't have a way to get the insertion point of an
already-expanded scope.

Instead, let's change the callers of the now-removed
expandAndBeCurrentDetectingRecursion() to instead call
expandAndBeCurrent(), while checking first if the scope was
already expanded.

Also, set the expanded flag before calling expandSpecifically()
from inside expandAndBeCurrent(), to ensure that re-entrant
calls to expandAndBeCurrent() are flagged by the existing
assertion there.

Finally, replace a couple of existing counters, and the
now-gone request counter with a single ASTScopeExpansions
counter to track expansions.
2020-12-18 15:43:33 -05:00
Artem Chikin
47da04fd72 Merge pull request #34417 from artemcm/FrontendParseableOutput
Add support for parseable-output straight from the frontend
2020-12-16 12:59:40 -08:00
Robert Widmann
76a7ceea64 [NFC] Re-Core Fingerprint
Switch from a string core to a 128-bit integral core. This should make
Fingerprints much cheaper to copy around and sets us up for a future
where we can provide alternative implementations of the ambient hashing
algorithm.

rdar://72313506
2020-12-14 17:50:10 -08:00
Artem Chikin
915186ab47 Refactor Basic/Parseable-Output to remove dependency on Driver & Frontend
Introducing new entry-points that can be used from both Driver and Frontend clients, using an intermediary new type: `DetailedMessagePayload`, when needed.
2020-12-14 11:35:56 -08:00
Artem Chikin
942cb0855e Implement frontend parseable-output batch job quasi-PID assignment.
Starting at a crude -1000, each invocation primary input will get its own unique quasi-Pid.
Invocations with only one primary (non-batch) will get a real OS Pid.

The selection of the constant starting point matches what the driver does when outputting its parseable output.
2020-12-11 16:01:04 -08:00
Artem Chikin
23e374ce78 Add support for emitting parseable-output "finished" message and per-primary messages for batched jobs
Inside swift-frontend
2020-12-11 16:01:03 -08:00
Artem Chikin
f09ab5c52f Add support for emitting parseable-outpuit "began" message from swift-frontend 2020-12-11 16:01:03 -08:00
Artem Chikin
b827875c5e Sink the parseable-output library into Basic from Driver 2020-12-11 16:01:03 -08:00
Robert Widmann
859b87fd8c Move The Last Pieces for Cross-Module Incremental Builds
We're going to play a dirty, dirty trick - but it'll make our users'
lives better in the end so stick with me here.

In order to build up an incremental compilation, we need two sources of
dependency information:

1) "Priors" - Swiftdeps with dependency information from the past
   build(s)
2) "Posteriors" - Swiftdeps with dependencies from after we rebuild the
   file or module or whatever

With normal swift files built in incremental mode, the priors are given by the
swiftdeps files which are generated parallel to a swift file and usually
placed in the build directory alongside the object files. Because we
have entries in the output file map, we can always know where these
swiftdeps files are. The priors are integrated by the driver and then
the build is scheduled. As the build runs and jobs complete, their
swiftdeps are reloaded and re-integrated. The resulting changes are then
traversed and more jobs are scheduled if necessary. These give us the
posteriors we desire.

A module flips this on its head. The swiftdeps information serialized
in a module functions as the *posterior* since the driver consuming the
module has no way of knowing how to rebuild the module, and because its
dependencies are, for all intents and purposes, fixed in time. The
missing piece of the puzzle is the priors. That is, we need some way of
knowing what the "past" interface of the module looked like so we can
compare it to the "present" interface. Moreover, we need to always know
where to look for these priors.

We solve this problem by serializing a file alongside the build record:
the "external" build record. This is given by a... creative encoding
of multiple source file dependency graphs into a single source file
dependency graph. The rough structure of this is:

   SourceFile => interface <BUILD_RECORD>.external
   | - Incremental External Dependency => interface <MODULE_1>.swiftmodule
   | | - <dependency> ...
   | | - <dependency> ...
   | | - <dependency> ...
   | - Incremental External Dependency => interface <MODULE_2>.swiftmodule
   | | - <dependency> ...
   | | - <dependency> ...
   | - Incremental External Dependency => interface <MODULE_3>.swiftmodule
   | - ...

Sorta, `cat`'ing a bunch of source file dependency graphs together but
with incremental external dependency nodes acting as glue.

Now for the trick:

We have to unpack this structure and integrate it to get our priors.
This is easy. The tricky bit comes in integrate itself. Because the
top-level source file node points directly at the external build record,
not the original swift modules that defined these dependency nodes, we
swap the key it wants to use (the external build record) for the
incremental external dependency acting as the "parent" of the dependency
node. We do this by following the arc we carefully laid down in the
structure above.

For rdar://69595010
Goes a long way towards rdar://48955139, rdar://64238133
2020-12-10 18:45:21 -08:00
Robert Widmann
fe6dfbf458 Add an Implementation of std::erase_if for std::unordered_set. 2020-12-10 18:31:04 -08:00
Michael Gottesman
f0f78a1477 [sil] Templatize base class of FieldIndexCacheBase.
Previously FieldIndexCacheBase only had a parent class of
SingleValueInstruction. I need to be able to in certain cases shim in a
SingleValueInstruction subclass as a parent class instead. In my case it is to
imbue ownership forwarding on StructExtractInst.

This commit itself doesn't make that change and instead just always templatizes
using SingleValueInstruction.
2020-12-01 15:45:25 -08:00
Alexis Laferrière
2328132f4f Merge pull request #34832 from xymus/rmodule-loading
[Frontend] Intro flag to remark on loaded modules location
2020-11-30 12:58:20 -08:00
Arnold Schwaighofer
8346bf7e90 Pre-specialization: This is an experimental feature
Only enable if explicitly required.
2020-11-20 09:13:16 -08:00
Alexis Laferrière
de42b1f2fa [Frontend] Optional remarks on loaded modules location
Passing the frontend flag -Rmodule-loading makes the compiler emit
remarks with the path of every module loaded. The path for Swift modules
is either the swiftinterface file for modules built with library
evolution or the binary swiftmodule otherwise. The path for clangmodules
is always in the cache which could be improved as it may be less useful.

Here's an extract of the output for a simple SwiftUI app:

<unknown>:0: remark: loaded module from
/Users/xymus/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/2VJP7CNCGWRF0/SwiftShims-18ZF6992O9H75.pcm
<unknown>:0: remark: loaded module from
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/usr/lib/swift/Swift.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
<unknown>:0: remark: loaded module from
/Users/xymus/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/2VJP7CNCGWRF0/os-1HVC6DNXVU37C.pcm
<unknown>:0: remark: loaded module from
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/usr/lib/swift/os.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
<unknown>:0: remark: loaded module from
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
2020-11-19 20:06:23 -08:00
Daniel Rodríguez Troitiño
42e0d33f49 [windows][msvc2017] Avoid initializer list constructor ambiguity.
MSVC2017 seems to not fallback to the correct overloaded constructor
when an initializer list constructor seems to be used, but only fails
because the conversion rules. Using parenthesis instead of braces seems
to indicate MSVC2017 the right constructor to use, and should work in
the rest of the compilers as well.

Seems that MSVC2019 is more resilient to this ambiguity.

Introduced in #34808 and started failing https://ci-external.swift.org/job/oss-swift-windows-x86_64/5953/
2020-11-19 16:41:06 -08:00
Robert Widmann
d2a98f3b0f Address Review Comments 2020-11-18 17:12:09 -08:00
Robert Widmann
8e5d64fa55 Add a Fingerprint Currency Type
A fingerprint is a stable hash of a particular piece of compiler data. This formalizes the stable notion of identity that the dependency trackers use for type body fingerprints in iterable decl contexts and the file-level interface hash
2020-11-18 12:20:14 -08:00
Slava Pestov
6e0e87f9d2 Remove TreeScopedHashTable.h 2020-11-16 22:39:44 -05:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Alexis Laferrière
b72b0c30fa Merge pull request #34612 from xymus/dont-skip-nested-types
[Sema] Add flag to optimize building swiftmodule files preserving type info for LLDB
2020-11-12 19:16:21 -08:00
Alexis Laferrière
02c134372f [Sema] Add option to skip non-inlinable functions without types
This frontend flag can be used as an alternative to
-experimental-skip-non-inlinable-function-bodies that doesn’t skip
functions defining nested types. We want to keep these types as they are
used by LLDB. Other functions ares safe to skip parsing and
type-checking.

rdar://71130519
2020-11-12 14:28:09 -08:00