Commit Graph

217 Commits

Author SHA1 Message Date
Slava Pestov
73f1990bc2 AST: Use getSelfInterfaceType() instead of getProtocolSelfType() where possible
The former appears in the code base a lot more frequently than the
latter, which returns a GenericTypeParamType *. Use it only in places
where the more specific type is intended.
2018-10-15 20:34:08 -07:00
Doug Gregor
ef0aeed788 [Runtime] Reimplement initialization of resilient witness tables.
Replace the quadratic algorithm (currently O(m*n) where m is the number of requirements and n is the number of witnesses) with an O(m+n) algorithm.
Harden the algorithm a against bad and unexpected inputs:
* Fail if the requirement descriptor is out-of-bounds for the protocol
* Skip the witness if the requirement descriptor is null; this can happen
when the witness table was compiled against a newer version of the
protocol, but is deployed to a library containing an older version of the
protocol. It is expected.
* In debug builds of the runtime, complain if an entry is initialized twice
* In debug builds of the runtime, complain if an entry is NULL

Fixes rdar://problem/44434793, which covers the second bullet (backward 
deployment).
2018-09-19 11:46:29 -07:00
Doug Gregor
d076e41f32 [IRGen] Put associated conformance accessors in resilient witness table
For a resilient conformance, emit the associated conformance accessor
functions into the resilient witness table (keyed on the associated
conformance descriptor) rather than in the fixed part of the witness
table. This is another part of resilience for associated conformances,
and a step toward defaults for associated conformances.
2018-09-17 21:58:56 -07:00
Doug Gregor
4549fcd673 [ABI] Add associated conformance descriptors.
Associated conformance descriptors are aliases that refer to associated
conformance requirements within a protocol descriptor’s list of
requirements. They will be used to provide protocol resilience against
the addition of new associated conformance requirements (which only makes 
sense for newly-introduced, defaulted associated types).
2018-09-17 16:32:29 -07:00
Doug Gregor
350391db9d [ABI] Use associated type descriptors for generic parameter references.
Generic parameter references, which occur in generic requirement
metadata, were hardcoding associated type indices. Instead, use
relative references to associated type descriptors and perform the
index calculation at runtime.

Associated types can now be reordered resiliently (without relying on 
sorting), which is the first main step toward rdar://problem/44167982.
2018-09-14 20:59:03 -07:00
Doug Gregor
bbe56b284a [ABI] Add protocol requirements base descriptor.
Introduce an alias that refers one element prior to the start of a
protocol descriptor’s protocol requirements. This can be subtracted from
an associated type descriptor address to determine the offset of the
associated type accessor within a corresponding witness table. The code
generation for the latter is not yet implemented.
2018-09-14 20:59:03 -07:00
Doug Gregor
9873d52814 [ABI] Emit associated type descriptors referencing each requirement.
Emit associated type descriptors (as aliases) to reference each associated
type requirement within a resilient protocol.
2018-09-14 20:59:03 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Saleem Abdulrasool
709395fa34 tapi: make it build on Windows
Since TAPI is currently built statically, just define away `TAPI_PUBLIC` on
Windows.  If tapi is to be built dynamic, we would need to annotate dllstorage
on the public interfaces.
2018-09-12 11:11:46 -07:00
Slava Pestov
9347a072e5 IRGen: Emit method lookup function 2018-09-07 21:50:58 -07:00
Slava Pestov
ee5deee374 TBDGen: Emit method descriptors 2018-08-31 00:20:40 -06:00
Harlan
096e6adb3f [TBDGen] Fix check for global accessors (#18883)
Previously, TBDGen skipped emitting lazy initializers for globals that
appeared in any file with an entry point. This breaks, however on files
that have an NSApplicationMain/UIApplicationMain class in them, where
the entry point is synthesized but top-level globals are not locally
scoped. This change re-uses SILGen's check and only skips variable
declarations that appear at top level in a script mode file.

Resolves rdar://43549749
2018-08-21 18:22:59 -07:00
Harlan Haskins
aa0d94feb1 [TBDGen] Respect app extension safety in TBD files 2018-08-20 13:07:35 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Harlan Haskins
14a7ae56db [TBDGen] Remove TBD options from FrontendOptions
This patch removes the duplication between FrontendOptions and
TBDGenOptions by parsing the TBDGenOptions up front similarly to IRGen
and SIL options.
2018-08-15 14:53:44 -07:00
Harlan
7318efe49d [TBDGen] Allow user-provided dylib version flags (#18716)
* [TBDGen] Allow user-provided dylib version flags

This patch adds two frontend arguments, -tbd-compatibility-version and
-tbd-current-version, both of which accept SemVer versions.

These will show up in the generated TBD file for a given module as

current-version: 2.7
compatibility-version: 2.0

These flags both default to `1.0.0`.

* Reword some comments

* Add test for invalid version string

* Expand on comments for TBD flags
2018-08-15 11:42:42 -07:00
Harlan
9648318f29 [TBDGen] Set tbd files to two-level namespace and explicitly set dylib compatibility version to 1 (#18632) 2018-08-13 10:23:55 -07:00
Harlan
1b57edfc68 [TBDGen] Skip @_silgen_name functions with no body (#18613)
`@_silgen_name` functions with no body are forward-declarations of
existing symbols, only to appease the typechecker. They don't show up in
the IR, so don't add them to the TBD file.
2018-08-10 10:38:55 -07:00
Huon Wilson
b7e513759c Merge pull request #18586 from huonw/tbd-abi-version
[TBDGen] Swift ABI Version can be a constant, not a magic number.
2018-08-10 00:18:01 +10:00
Huon Wilson
942320f8ac [TBDGen] Swift ABI Version can be a constant, not a magic number. 2018-08-09 15:24:22 +10:00
John McCall
ebed6afd59 Make it easy to iterate over all the opaque accessors of a declaration. 2018-08-08 22:44:47 -04:00
Huon Wilson
4dc5a5edee [TBDGen] Include the ObjC class names in the TBD file. 2018-08-08 12:07:34 +10:00
Huon Wilson
8c75e726c6 [TBDGen] Use tapi code for emitting a properly formatted TBD v3 file. 2018-08-08 12:07:34 +10:00
Huon Wilson
430ebc170d [TBDGen] Add tapi's TBD formatting code. 2018-08-07 20:00:31 +10:00
Huon Wilson
e57b332a82 [TBDGen] Look for @_hasInitialValue on variables rather than an initializer expression.
The initializer expression is lost in the public interface (in Swift modules and
the textual interface), but the attribute is preserved.
2018-08-07 09:54:35 +10:00
Huon Wilson
1c622fdced [TBDGen] Don't list symbols for non-public static/global stored variables. 2018-08-07 09:30:50 +10:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00
Joe Groff
7129745bf0 TBDGen: Include property descriptor in TBD output. 2018-07-25 11:09:04 -07:00
Slava Pestov
3a6fa6bb27 TBDGen: Remove use of AbstractFunctionDecl::getParameterLists() 2018-07-22 20:56:56 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
John McCall
69f4dd1ec9 Generalize accessor storage to preserve the original accessor list.
Only not NFC because it's detectable by source tools.
2018-06-16 18:16:31 -04:00
Huon Wilson
1399aeb2de [TBDGen] Consider -enable-testing for default arg generator symbols.
Fixes rdar://problem/40736382.
2018-06-01 15:18:24 -07:00
Huon Wilson
859d0a79ba [TBDGen] The non-deallocating destructor applies to some @objc classes.
The non-deallocating destructor doesn't exists when dealloc can be overriden,
which means any class that inherits from a class defined in Objective-C. This
isn't necessarily all @objc classes, because of the
-disable-objc-attr-requires-foundation-module flag.

Fixes rdar://problem/40542246.
2018-05-25 19:53:46 +10:00
Huon Wilson
33db2af99f [TBDGen] Walk accessors as part of their parent storage, not the main AST.
Sometimes, inconsistently, an accessor appears as a member of a parent
DeclContext, but other times it can seemingly only be accessed through the
storage decl. Instead of trying to conditionalise on this, just use the storage
decl as the canonical source, and ignore direct visits to accessors (i.e. the
membership route to ones that are members of other things).

Fixes rdar://problem/40476839.
2018-05-23 22:29:14 +10:00
Huon Wilson
34a5ce9044 [TBDGen] Handle conformance witnesses correctly.
We need to be looking at the linkage of the witness, but mangling the
requirement. Also, getGetter() gets the getter, not the setter (copy-paste
strikes again).

Fixes rdar://problem/40355657.
2018-05-23 15:36:27 +10:00
Huon Wilson
cfc5abdaa2 [TBDGen] Emit the symbol for autolink-force-load-ing.
Fixes rdar://problem/40356032.
2018-05-23 10:56:49 +10:00
Huon Wilson
38e45c4be5 [TBDGen] Take options as a struct instead of arguments. 2018-05-23 00:02:15 +10:00
Huon Wilson
4385d9042c [TBDGen] Types with resilient superclasses need special consideration for their metadata.
Fixes rdar://problem/40355432.
2018-05-21 22:45:31 +10:00
Huon Wilson
bf8288002d [TBDGen] @_cdecl still exists, and adds symbols.
Fixes rdar://problem/40405377.
2018-05-21 22:45:30 +10:00
Huon Wilson
27a72099eb [TBDGen] Enums are nominal types too.
Fixes rdar://problem/40235179&40353886&40355242 .
2018-05-21 22:45:30 +10:00
Arnold Schwaighofer
1bea36844e TBDGen: Use isResilient() api 2018-04-06 13:39:14 -07:00
Arnold Schwaighofer
c17829cd9d TBDGen: Add resilient enum case emission support
rdar://38707747
2018-04-06 11:57:49 -07:00
Slava Pestov
487754f080 TBD: Stored property initializers can be public 2018-03-14 19:17:36 -07:00
John McCall
dd99536d31 Move the metadata-pattern header into the type context descriptor.
This is yet another waypoint on the path towards the final
generic-metadata design.  The immediate goal is to make the
pattern a private implementation detail and to give the runtime
more visibility into the allocation and caching of generic types.
2018-02-26 12:10:24 -05:00
Doug Gregor
e766473ed9 [ABI] Emit separate symbols for protocol conformance descriptors.
Emit protocol conformance descriptors as separate symbols, rather than
inlining them within the section for protocol conformance records. We
want separate symbols for protocol conformances both because it is easier
to make them variable-length (as required for conditional
conformances) and because we want to reference them from witness
tables (both of which are coming up).
2018-01-17 10:35:16 -08:00
Slava Pestov
eeb6e21196 TBD: Stored property initializers are no longer ever public 2018-01-14 22:59:41 -08:00
Slava Pestov
f2b2cd4019 TBD: Test default argument behavior in Swift 3 and 4 mode
Also, bail out before emitting any default argument generators in Swift 4
mode. This is NFC, because we already check the linkage of the SILDeclRef
and skip it if its not public. But adding the check explicitly here
serves as a reminder that this entire code block can be deleted if we
ever decide to kill off Swift 3 compatibility.
2018-01-14 22:59:41 -08:00
Slava Pestov
4c979eb823 TBD: Clean up visitor logic 2018-01-12 23:30:15 -08:00
Slava Pestov
837ab4b76b TBD: Clean up witness thunk linkage computation 2018-01-12 23:30:15 -08:00
Slava Pestov
1b20bc3094 TBD: Use effectiveLinkageForClassMember() to calculate method linkage 2018-01-12 23:30:15 -08:00