Commit Graph

126 Commits

Author SHA1 Message Date
Doug Gregor
c7152f3576 [SIL] Don’t create witness table entries for overriding requirements.
SIL will not generate calls to protocol requirements that override
other protocol requirements, so all of the witness table entries for
the overriding arguments are dynamically dead. Remove them from the
witness tables entirely.

Implements rdar://problem/43870489, reducing the size of the standard
library binary by 196k.
2018-09-05 13:51:26 -07:00
Doug Gregor
0972111c60 [Type checker] Start tracking overrides of protocol requirements.
When a protocol that inherits another protocol restates a requirement
from its inherited protocol, track that as an override in the AST.
2018-09-04 16:42:06 -07: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
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
Michael Gottesman
fe97efcdbd [pass-manager] Missed one. notifyDeleteFunction => notifyWillDeleteFunction. 2018-07-17 10:00:27 -07:00
Joe Groff
849d9397d6 SIL: Generate external key path references with local candidate components.
The other side of #17404. Since we don't want to generate up front key path metadata for properties/subscripts with no withheld implementation details, the client should generate a key path component that can be used to represent a key path component based on its public interface.
2018-07-06 14:24:07 -07:00
Andrew Trick
7c4d15f96a SILModule::isVisibleExternally utility for VarDecls. (#16834)
* SILModule::isVisibleExternally utility for VarDecls.

* Fix the SIL parser so it doesn't drop global variable decls.

This information was getting lost in SIL printing/parsing.
Some passes rely on it. Regardless of whether passes should rely on it,
it is totally unacceptable for the SIL passes to have subtle differences
in behavior depending on the frontend mode. So, if we don't want passes
to rely on global variable decls, that needs to be enforced by the API
independent of how the frontend is invoked or how SIL is serialized.

* Use custom DemangleOptions to lookup global variable identifiers.
2018-06-26 12:27:26 -07:00
Michael Gottesman
27c5366f70 [dfe] Change Impl to be a stongly typed PointerUnion instead of a union. 2018-06-23 20:43:32 -07:00
Joe Groff
3e4e00c163 SILGen: Emit "trivial" property descriptors for properties that withhold no information about their implementation.
Client code can make a best effort at emitting a key path referencing a property with its publicly exposed API, which in the common case will match what the defining module would produce as the canonical key path component representation of the declaration. We can reduce the code size impact of these descriptors by not emitting them when there's no hidden or possibly-resiliently-changed-in-the-past information about a storage declaration, having the property descriptor symbol reference a sentinel value telling client key paths to use their definition of the key path component.
2018-06-21 15:18:24 -07:00
Slava Pestov
c35d1f5fc7 SIL: Remove unused code for optional (non-@objc) protocol requirements 2018-03-23 18:59:06 -06:00
Joe Groff
a84f7f175a SIL: Consider accessors from property descriptors to be used. 2018-03-22 13:46:50 -07:00
Joe Groff
d4e03f2ba3 SIL: Add an 'external' KeyPathPatternComponent kind.
This will allow key paths to resiliently reference public properties from other binaries by referencing a descriptor vended by the originating binary. NFC yet, this just provides printing/parsing/verification of the new component.
2018-02-14 10:48:24 -08:00
Slava Pestov
48d0407f43 SIL: Remove SILFunction::{is,set}KeepAsPublic() 2018-01-12 22:08:00 -08:00
Slava Pestov
8027e8108e DeadFunctionElimination: Serialized functions are not anchors 2018-01-12 21:56:17 -08:00
Slava Pestov
6c055652b6 DeadFunctionElimination: Fold shouldBeSerializedOrEmitted() into isAnchorFunction() 2018-01-12 21:56:17 -08:00
Slava Pestov
7f84ae5449 SILOptimizer: Remove special handling of transparent functions from dead function elimination
This is no longer sound after https://github.com/apple/swift/pull/12903.
We no longer special-case the linkage of transparent functions at all.
2017-11-20 00:21:49 -05:00
Joe Shajrawi
4d5949942d Merge branch 'master' into sil-serialization-before-optimizations5 2017-11-17 16:17:16 -08:00
Huon Wilson
99c4cddfca [SILGen] Store conditional conformances in SILWitnessTables. 2017-11-08 17:02:50 -08:00
Greg Parker
d6e1866344 [SIL] Make @_silgen_name and @_cdecl functions immune to some optimizations (#12696)
@_silgen_name and @_cdecl functions are assumed to be referenced from
C code. Public and internal functions marked as such must not be deleted
by the optimizer, and their C symbols must be public or hidden respectively.

rdar://33924873, SR-6209
2017-11-01 01:41:05 -07:00
Roman Levenstein
0fed27fefe [dead-function-elimination] Do not consider transparent functions as anchors
Transparent functions are emitted into the client in most cases, so there is no need to keep them alive in the defining module unless they are used there.

The only exception are transparent global initializers, because bodies of global initializer functions are never SIL serialized and are always IRGened into the defining module, so that clients can invoke them

This change results in small code size reductions of the binaries being produced after recent changes related to the early SIL serialization and the removal of -sil-serialize-all mode.

Fixes rdar://problem/35022861
2017-10-26 14:02:31 -07:00
Graydon Hoare
3ef686bf92 [DeadFunctionElimination] Pass on keypaths to foreign DeclRef properties.
These show up specifically when someone forms a keypath to an ObjC
property in a category. They're no-ops from the perspective of
DFE but the code has to intentionally skip the case if it wants to
avoid the subsequent llvm_unreachable.

rdar://34913689
2017-10-25 23:21:56 -07:00
Roman Levenstein
a7ee05dd48 Small code clean-up in DeadFunctionElimination 2017-10-11 13:36:59 -07:00
Roman Levenstein
6f3b326d12 IRGen should not emit bodies of public_external functions unless it is a transparent function.
Recent changes that eliminated the -sil-serialize-all mode and adding this check to IRGen allow us to get rid of ExternalFunctionDefinitionsElimination and ExternalDefsToDecls passes, which are not needed anymore.
2017-10-11 08:29:46 -07:00
Roman Levenstein
53a6d89a9d More fixes for pre-specializations
Since the bodies of pre-specializaitons are not serialized, do not use the `[serialized]` attribute for them.
2017-10-02 14:34:14 -07:00
Roman Levenstein
c15ffa0571 Some fixes for the Serialized attribute of pre-specializations
Pre-specializations need some special handling when it comes to the Serialized attribute. Their bodies should not be SIL serialized. Instead, only their declarations should be serialized.

And since their bodies are not serialized and cannot be imported by the client code, it is OK if pre-specializations reference non-fragile functions inside their bodies. Due to the same reason, it is fine if pre-specializations are referenced from fragile functions, even though these pre-specializations are not fragile in a usual sense.
2017-09-29 12:45:31 -07:00
Joe Groff
c1fcfa0003 SIL: Fix reference tracking for equals/hash helpers in KeyPath instructions with operands. 2017-09-18 11:59:20 -07:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Erik Eckstein
1ab582e121 SIL: A new representation of static initializers for global variables.
Static initializers are now represented by a list of literal and aggregate instructions in a SILGlobalVariable.
For details see SIL.rst.

This representation is cleaner than what we did so far (point to the initializer function and do some pattern matching).

One implication of that change is that now (a subset of) instructions not necessarily have a parent function.
Regarding the generated code it's a NFC.
Also the swift module format didn't change because so far we don't serializer global variables.
2017-08-23 09:15:01 -07:00
Joe Groff
3c82e981f9 KeyPaths: Add support for optional chaining/forcing components.
rdar://problem/31768715
2017-06-26 09:40:31 -07:00
practicalswift
ba5f81888b [gardening] Remove unused variables 2017-05-13 15:48:27 +02:00
Joe Groff
224120f54b SIL: Don't DFE functions referenced from KeyPath patterns.
Fixes rdar://problem/31776015.
2017-05-01 17:32:50 -07:00
Andrew Trick
be1881aa1f Remove redundant Transform.getName() definitions.
At some point, pass definitions were heavily macro-ized. Pass
descriptive names were added in two places. This is not only redundant
but a source of confusion. You could waste a lot of time grepping for
the wrong string. I removed all the getName() overrides which, at
around 90 passes, was a fairly significant amount of code bloat.

Any pass that we want to be able to invoke by name from a tool
(sil-opt) or pipeline plan *should* have unique type name, enum value,
commend-line string, and name string. I removed a comment about the
various inliner passes that contradicted that.

Side note: We should be consistent with the policy that a pass is
identified by its type. We have a couple passes, LICM and CSE, which
currently violate that convention.
2017-04-09 15:20:28 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Erik Eckstein
a16beaea3c Remove the now usused ConformanceCollector utility.
It was used for dead witness table elimination. But this is done now by lazy emission in IRGen.
Also update DeadFunctionElimination.
NFC.
2017-03-15 10:18:18 -07:00
Erik Eckstein
a0079ba5be SIL optimizations: Implement the new API for analysis invalidation.
There are now separate functions for function addition and deletion instead of InvalidationKind::Function.
Also, there is a new function for witness/vtable invalidations.

rdar://problem/29311657
2017-03-14 13:00:54 -07:00
Saleem Abdulrasool
0c56998576 SIL: IWYU cl edition
Include llvm/Support/CommandLine.h when using llvm::cl.
2017-03-04 14:20:51 -08:00
Erik Eckstein
7fb871a7c6 Disable dead conformance elimination for now.
There are still several open issues (e.g. asserts in IRGen) and it seems to be hard to fix them.
Most likely we’ll go for a different approach at all.
2017-02-01 10:30:30 -08:00
Roman Levenstein
a422f8af63 [sil-dead-funciton-elimination] Eliminate unused default methods implementations from default witness tables
We were missing this opportunity, because we forgot to update DeadFunctionElimination after default witness tables were introduced.

rdar://30264699
2017-01-30 11:57:34 -08:00
practicalswift
a9d6d8938c [gardening] Fix recently introduced typos 2017-01-22 20:40:45 +01:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Erik Eckstein
44f35b9160 Remove dead witness tables, including dead witness functions.
A witness table is dead if it is not used outside the module (private/internal) and it’s not used by any instruction or other witness table in the module.
Also the meta-type of the conforming type must not escape, because it’s possible to test any opaque type if it conforms to a protocol.

rdar://problem/23026019
2017-01-19 09:41:09 -08:00
Erik Eckstein
1eb3a0532b DeadFunctionElimination: don’t eliminate public methods which are called via a thunk.
For this we need to store the linkage of the “original” method implementation in the vtable.
Otherwise DeadFunctionElimination thinks that the method implementation is not public but private (which is the linkage of the thunk).

The big part of this change is to extend SILVTable to store the linkage (+ serialization, printing, etc.).

fixes rdar://problem/29841635
2017-01-06 16:06:32 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
f19d6b9074 SILOptimizer: Fix a warning 2016-12-22 06:39:43 -05:00
Roman Levenstein
d3b2336366 [sil-dead-function-elimination] Do not remove bodies of transparent functions referenced from vtables and witness tables.
Fixes rdar://28960061 and SR-3034
2016-12-20 19:21:45 -08:00
Michael Gottesman
be5ec6f990 [passmanager] Remove ExecutionKind::UntilFixPoint and all of ExecutionKind.
rdar://29650781
2016-12-19 13:38:46 -08:00
Michael Gottesman
f0705a87bf [dead-function-elimination-utility] Run for one iteration instead of until fix point.
When I created the utility function, I preserved the old behavior. There is no
reason to run until a fix point since we will not get more dead functions after
we run the pass (i.e. it is an idempotent transformation).

rdar://29650781
2016-12-19 13:05:13 -08:00
Michael Gottesman
62a744a9b9 [dead-function-elim] When deleting functions, use a vector instead of itereating over the module functions twice.
We already know the set of dead functions when we drop the bodies, so instead of
iterating over all of the modules in a function (which is a linked list btw),
just use a vector that we create as we drop the bodies. Then in cases where we
are only eliminating a small amount of functions, we only perform a small amount
of work when deleting function bodies.

This is just a small optimization that I saw as I read through the code to make
sure dead function elimination was an idempotent optimization [which it is].

rdar://29650781
2016-12-19 12:55:18 -08:00