Commit Graph

55 Commits

Author SHA1 Message Date
Erik Eckstein
5502373018 SIL: rename AssociatedTypeProtocolWitness -> AssociatedConformanceWitness in SILWitnessTable
To be consistent with the naming convention in the AST
2024-10-02 07:10:30 +02:00
Erik Eckstein
2950e4521e SIL: representation for specialized witness tables
The main change here is to associate a witness table with a `ProtocolConformance` instead of a `RootProtocolConformance`.
A `ProtocolConformance` is the base class and can be a `RootProtocolConformance` or a `SpecializedProtocolConformance`.
2024-09-25 19:32:08 +02:00
Ellie Shin
4ecfc96578 [SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions during SIL
inlining, generic/closure specialization, and devirtualization optimization passes.

SILFunction::canBeInlinedIntoCaller now exlicitly requires a caller's SerializedKind_t arg.
isAnySerialized() is added as a convenience function that checks if [serialized] or [serialized_for_pkg].

Resolves rdar://128704752
2024-05-27 23:05:56 -07:00
Ellie Shin
5ccc4cd394 SIL function can be serialized with different kinds: [serialized] or
[serialized_for_package] if Package CMO is enabled. The latter kind
allows a function to be serialized even if it contains loadable types,
if Package CMO is enabled. Renamed IsSerialized_t as SerializedKind_t.

The tri-state serialization kind requires validating inlinability
depending on the serialization kinds of callee vs caller; e.g. if the
callee is [serialized_for_package], the caller must be _not_ [serialized].
Renamed `hasValidLinkageForFragileInline` as `canBeInlinedIntoCaller`
that takes in its caller's SerializedKind as an argument. Another argument
`assumeFragileCaller` is also added to ensure that the calle sites of
this function know the caller is serialized unless it's called for SIL
inlining optimization passes.

The [serialized_for_package] attribute is allowed for SIL function, global var,
v-table, and witness-table.

Resolves rdar://128406520
2024-05-23 15:53:02 -07:00
Slava Pestov
99d68ba14c IRGen: Some progress toward tuple conformances 2023-08-18 12:12:50 -04:00
Egor Zhdan
94ec683ba5 Revert "Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift""
This reverts commit 69431f00
2022-10-18 18:55:57 +01:00
eeckstein
69431f00e8 Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift" 2022-09-22 11:45:41 +02:00
Egor Zhdan
5f2a641513 [cxx-interop][SwiftCompilerSources] Use swift::SILWitnessTable::WitnessKind instead of `
SILWitnessTableEntryKind`

rdar://83361087
2022-09-20 12:03:48 +01:00
Erik Eckstein
fbb694bcde Swift SIL: add bridging for witness and default witness tables 2022-08-24 17:55:02 +02:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Erik Eckstein
b4966a4efa SIL: Don't serialize SILFunction declarations in witness tables if they don't have a valid linkage for "fragile ref".
E.g. a serialized witness table must not reference a private function. Just like a serialized function must not reference a private function.
2021-10-10 19:52:40 +02:00
Varun Gandhi
4028222107 [NFC] Remove redundant includes for <string>. 2020-05-31 13:05:46 -07:00
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Jordan Rose
d3edf7c9ff [SILGen] Always serialize witness tables in non-resilient modules (#20390)
...even if the conforming nominal type is resilient. It's the owner
of the conformance whose resilience matters.

I also factored this part out into a separate check at the AST level
so we can tweak it, and also so I can use it to (slightly) speed up
compiling a resilient swiftinterface.
2018-11-08 15:34:00 -08:00
Doug Gregor
4ed973329a [SIL] Unify default witness table entries with witness table entries.
SILWitnessTable::Entry already contains a superset of what was supported
by SILDefaultWitnessTable::Entry, the latter of which only had “no entry”
and “method” states. Make SILDefaultWitnessTable::Entry an alias for
SILWitnessTable::Entry, and unify all of the parsing/printing/
(de)serialization logic.
2018-09-15 22:04:46 -07:00
Jordan Rose
5fe5391dae [Serialization] Remove the last use of Identifiers for SIL names
The string-keyed tables don't actually need Identifier keys on the
serialization side -- no reason to persist these in the ASTContext's
string table either.
2018-09-13 09:01:08 -07:00
Bob Wilson
9dc02e67a2 master-next: Stop using ilist_default_traits
LLVM r330736 removed ilist_default_traits. Apparently it is not needed
and ilist_node_traits works just as well.
2018-04-25 22:44:58 -07:00
Sho Ikeda
03fbd4a6de [gardening][SIL] Replace typedef with using 2018-04-05 13:53:20 +09:00
Slava Pestov
d1c6e1d24a SIL: Generalize default witness tables now that defaulted witnesses don't have to go at the end
NFC until the new witness table instantiation mechanism is enabled.
2018-03-29 14:03:58 -07:00
Slava Pestov
c35d1f5fc7 SIL: Remove unused code for optional (non-@objc) protocol requirements 2018-03-23 18:59:06 -06:00
Slava Pestov
1831b5471e SIL: Clean up 'early serialization' a bit
- Clear the 'serialized' flag on witness tables and vtables
  after serialization, not just functions. This fixes SIL
  verifier failures if post-serialization SIL is printed
  out and parsed back in.

- Clear the 'serialized' flag when deserializing functions,
  witness tables and vtables in a module that has already
  been serialized. This fixes SIL verifier failures if
  we deserialize more declarations after serializing SIL.

We were seeing SIL verifier failures on bots that run the
tests with the stdlib built with non-standard flags.

Unfortunately I don't have a reduced test case that would
fail in PR testing without these fixes.

Fixes <rdar://problem/36682929>.
2018-01-21 01:35:13 -08:00
Huon Wilson
99c4cddfca [SILGen] Store conditional conformances in SILWitnessTables. 2017-11-08 17:02:50 -08:00
Slava Pestov
3392b6d8b9 SIL: Remove unused parameter from SILWitnessTable::conformanceIsSerialized() 2017-10-26 23:58:50 -07:00
Roman Levenstein
48d9b99675 Remove -sil-serialize-witness-tables flag completely
The functionality is always enabled now and there is no need to have a dedicated flag for it.
2017-10-20 19:45:29 -07:00
Huon Wilson
a0bc3bd0b6 [AST] Move getEffectiveAccess calls into SIL. 2017-06-20 17:34:48 -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
John McCall
fe7915d09e Rework a number of SIL and IRGen witness-table abstractions
to correctly handle generalized protocol requirements.

The major missing pieces here are that the conformance search
algorithms in both the AST (type substitution) and IRGen
(witness table reference emission) need to be rewritten to
back-track requirement sources, and the AST needs to actually
represent this stuff in NormalProtocolConformances instead
of just doing ???.

The new generality isn't tested yet; I'm looking into that,
but I wanted to get the abstractions in place first.
2017-03-02 01:34:13 -05: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
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Bob Wilson
2c21ef586d Update to match llvm r279473: remove ilist_*sentinel_traits.
(cherry picked from commit 391e7d8b60)
2016-12-01 10:46:38 -08:00
Bob Wilson
26a62b912a Update to match llvm r278513: share code for embedded sentinel traits.
Nothing at all should be changing here, this is just rearranging code.

(cherry picked from commit 9964697f22)
2016-12-01 10:42:59 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
bbbe307980 SIL: Introduce SILDefaultWitnessTable and start plumbing
This will be used to help IRGen record protocol requirements
with resilient default implementations in protocol metadata.

To enable testing before all the Sema support is in place, this
patch adds SIL parser, printer and verifier support for default
witness tables.

For now, SILGen emits empty default witness tables for protocol
declarations in resilient modules, and IRGen ignores them when
emitting protocol metadata.
2016-02-05 20:57:11 -08:00
Slava Pestov
b9951ade1b SIL: Rename some identifiers, NFC
"VTableLookupTable" just doesn't look right to me.
2016-02-04 17:34:55 -08:00
John McCall
2df6880617 Introduce ProtocolConformanceRef. NFC.
The main idea here is that we really, really want to be
able to recover the protocol requirement of a conformance
reference even if it's abstract due to the conforming type
being abstract (e.g. an archetype).  I've made the conversion
from ProtocolConformance* explicit to discourage casual
contamination of the Ref with a null value.

As part of this change, always make conformance arrays in
Substitutions fully parallel to the requirements, as opposed
to occasionally being empty when the conformances are abstract.

As another part of this, I've tried to proactively fix
prospective bugs with partially-concrete conformances, which I
believe can happen with concretely-bound archetypes.

In addition to just giving us stronger invariants, this is
progress towards the removal of the archetype from Substitution.
2016-01-08 00:19:59 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
37e7187508 Fix typo: entires → entries 2015-12-14 00:11:42 +01:00
Erik Eckstein
f40f3a93a0 New implementation of dead function elimination, which includes dead method elimination.
If vtable or witness methods are never called, e.g. because they are completely devirtualized,
then they are removed from the tables and eliminated.

Another improvement of the new algorithm is that it is able to eliminate dead function cycles
(e.g. A() calls B() and vice versa).



Swift SVN r22969
2014-10-27 16:41:02 +00:00
Erik Eckstein
60cb1a619a Support for eliminated witness methods in SILWitnessTable.
A method entry in SILWitnessTable can now be null.
This will be needed by dead method elimination.



Swift SVN r22914
2014-10-24 16:26:12 +00:00
Erik Eckstein
3eea8e3052 Set SILLinkage of witness tables according to the protocol visibility.
This is the same change as already done for functions and globals
(for details see <rdar://problem/18201785>).




Swift SVN r22907
2014-10-24 09:02:05 +00:00
Chris Lattner
50979a2ff4 implement SILGen and IRGen support for witness table generation of non-objc optional
protocol requirements.  Not testable because sema doesn't allow these to exist.


Swift SVN r21513
2014-08-28 04:20:02 +00:00
Michael Gottesman
67351cf0a2 Since SILVTables and SILWitnessTables are bump ptr allocated, we need to call their destructor when we remove them so that the functions they reference have a decremented ref count.
Swift SVN r16171
2014-04-10 22:10:59 +00:00
Michael Gottesman
f4bb049bfc [deserialization] Enable lazy deserialization of witness tables.
This patch adds in the necessary infrastructure for lazily deserializing
witness tables. This is done by following the same approach as the
deserialization/serialization of SILFunction.

Now if one calls SILModule::lookUpWitnessTable and the given witness table is a
definition, the SILModule will attempt to deserialize it from one of the other
modules.

Swift SVN r15403
2014-03-24 09:16:09 +00:00
Michael Gottesman
59a44ca1f2 [deserialization] Add SILWitnessTable::convertToDefinition for converting SILWitnessTable declarations -> definitions.
This will be used for lazy deserialization of witness tables.

Swift SVN r15402
2014-03-24 05:07:21 +00:00
Michael Gottesman
f807249aa8 [deserialization] Store the mangled name of a SILWitnessTable on the instance itself.
The importance of this is that we will be able to use this name during
SIL serialization/deserialization to lookup partially deserialized
witness tables.

I left IRGen's original code alone until I can discuss with Joe/John
combining the logic together.

Swift SVN r15400
2014-03-24 05:07:20 +00:00
Michael Gottesman
e03f52638e Add in some documentation/comments to SILWitnessTable. Fix some whitespace issues.
Swift SVN r15380
2014-03-23 06:32:59 +00:00
Michael Gottesman
5b88963e78 [SIL] Implement external SIL Witness Table declarations.
This will help with ensuring that we do not create multiple witness
table "definitions" one of which is null. That situtation yields an
IRGen assertion to be hit since the external declaration (in the guise
of a definition) has a different type from the actual deserialized
definition.

Swift SVN r14999
2014-03-13 19:52:59 +00:00
Joe Groff
945fbaf167 SIL: Add a linkage specifier to SILWitnessTables.
In the short term, we need to be able to emit shared symbols for SILWitnessTables corresponding to Clang-imported modules, and soon, the generic specializer will need to be able to reference *_external witness tables deserialized from library modules.

Swift SVN r14887
2014-03-10 23:14:16 +00:00
Michael Gottesman
fafe76240e [external-witnesstables] Store the entries of a witness table in bump-ptr allocated memory referenced via an ArrayRef instead of a tail allocated array.
This will enable the creation of external witness tables whose entries
can be initialized after the witness table itself has been constructed.
This can occur if the table is deserialized later from a different
module.

Swift SVN r14715
2014-03-06 01:59:15 +00:00
Joe Groff
59d2a169f6 SIL: Rename 'archetype_method' to 'witness_method'.
It has been generalized to get a witness out of an arbitrary protocol conformance, not just for archetypes.

Swift SVN r14497
2014-02-28 05:09:11 +00:00