Commit Graph

190 Commits

Author SHA1 Message Date
Doug Gregor
1fc57ad667 [Test] Add test case for now-fixed rdar://problem/39805133 2018-10-10 21:53:20 -07:00
Doug Gregor
599e07e5d9 [Type checker] Keep the type checker alive as long as the ASTContext is.
It is possible for the SIL optimizers, IRGen, etc. to request information
from the AST that only the type checker can provide, but the type checker
is typically torn down after the “type checking” phase. This can lead to
various crashes late in the compilation cycle.

Keep the type checker instance around as long as the ASTContext is alive
or until someone asks for it to be destroyed.

Fixes SR-285 / rdar://problem/23677338.
2018-10-10 16:44:42 -07:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Davide Italiano
ef46ec08fc [AST] Update tests now that we preserve sugar. 2018-09-18 09:23:02 -07:00
Doug Gregor
8af269aca5 [Type checker] Make sure we have a generic signature when inheriting initializers.
Before adding implicit initializers synthesizes a new initializer, make sure that
we’ve validated the current class declaration to determine it’s generic signature.

Fixes rdar://problem/44235762.
2018-09-08 10:21:55 -07:00
Slava Pestov
cdadee8173 AST: Fix layering violations in DefaultAndMaxAccessLevelRequest
Our walk over the requirement interface types meant that
computing the access level of an extension member depended
on type resolution and the GSB.

Fix this by adding a new request that simply collects all
TypeDecls referenced from a TypeRepr, and compute the
extension's maximum access level using that.

If we use Structural rather than Interface type resolution when
walking the extension's requirements, we don't have to build its
generic signature first.
2018-09-05 16:18:54 -07:00
Slava Pestov
432644ad20 These tests require the ability to execute code 2018-08-29 14:47:50 -07:00
Slava Pestov
a1ea56b20f Add test case for https://bugs.swift.org/browse/SR-8643 which is now fixed 2018-08-25 01:14:49 -07:00
Slava Pestov
120be251db IRGen: Metadata patterns are always true-const
They were, already, but remove the isConstant parameter to
getAddrOfTypeMetadataPattern(), and just assert that its true for
patterns in defineTypeMetadata() instead.

Also, metadata patterns are i8*, not i8**. In fact they don't contain any
absolute pointers at all.

Should be NFC other than the LLVM type change.
2018-08-23 23:40:08 -07:00
Doug Gregor
e15f67e453 [Type checker] Marking a class as @objc doesn’t require an interface type.
Fixes the crash in SR-8540 / rdar://problem/43383512.
2018-08-20 10:05:13 -07:00
Doug Gregor
bb6272b194 [Type checker] Finalize witnesses when we finish checking a conformance.
This ensures that SILGen can build the witness table.
2018-08-18 10:44:12 -07:00
Doug Gregor
cb972072a6 [Type checker] Request nominal layout for all potential metadata sources.
Fixes the non-WMO crash in ReactiveCocoa (SR-8530), where IRGen was
attempting to fulfill a metadata request based on a nominal type whose
layout was not checked.
2018-08-17 15:03:02 -07:00
Arnold Schwaighofer
cddf20baee Codesign test/multifile 2018-08-10 06:58:40 -07:00
Doug Gregor
76eb767b97 [Type checker] Request nominal layout for the result types of function calls.
Once you’ve called a function and retrieved a result, IRGen will want
layout information for the result type. Make sure that the type checker
precomputes it.
2018-07-26 15:46:29 -07:00
Doug Gregor
c2bc23e734 [Type checker] Finalize referenced members of class extensions.
When we reference a member of a class extension, we need to
compute its overrides, @objc bit, and ‘dynamic’ status because SILGen
may rely on them. Do that consistently by adding such members to the
list of declarations to “finalize”.

Rework the finalization logic to handle the computation of each of those
bits, and never remove a finalized declaration from the set: rather,
process new declarations as they enter the set, to avoid looping or
extra state bits.

Fixes rdar://problem/42440686.
2018-07-24 16:51:25 -07:00
Doug Gregor
9939834a76 [Type checker] Validate potentially-overridden decls when needed.
When computing the type of a potentially-overriden declaration, make sure
we have an interface type. Add a test to ensure that we validate
overrides cross-file correctly.
2018-07-04 22:45:10 -07:00
Slava Pestov
31ab93b82c Remove Swift 3-specific tests 2018-07-02 21:14:22 -07:00
Doug Gregor
a66df57aaf [Mangling] Update SILGen and IRGen tests for mangling change. 2018-06-19 23:24:38 -07:00
Arnold Schwaighofer
eaef4f2016 Fix the test case to work on the simulator 2018-05-16 10:16:59 -07:00
Arnold Schwaighofer
6bb13b7cfa Add codesign 2018-05-15 08:40:45 -07:00
Arnold Schwaighofer
e78c840647 Witness table pointers shall now be part of the metadata cache key
rdar://24958043
2018-05-14 13:53:54 -07:00
Arnold Schwaighofer
1f65ee25f6 Distinguish between withoutActuallyEscaping and passing @noescape
Objective C closures when reporting that a closure has escaped

rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
9048e97e83 Executable test case for passing a noescape closure to Objective-c which
escapes the closure.

We expect the program to crash with an explanation.

rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
75bf101204 IRGen: Also handle nested types inside of extensions
rdar://39648725
2018-04-24 13:53:01 -07:00
Arnold Schwaighofer
a830acdbee IRGen: We need to make not of any parent decl in nested type decls
Such that we emit the parent's type metadata

rdar://39648725
2018-04-24 10:45:25 -07:00
Slava Pestov
39a65abf85 IRGen: Outlined thunks don't need to receive fixed-size metadata
They're not used inside the thunk so it's a waste passing them in, and
if they involve private types from a different translation unit we will
get a linking error from referencing the metadata accessor function.

Fixes the test case in <rdar://problem/39470607>, but the more general
problem remains.
2018-04-17 16:11:21 -07:00
Doug Gregor
80bb4505e4 Add crashing test case for rdar://problem/34584596. 2018-04-11 16:09:32 -07:00
Doug Gregor
2c9790ed1a Add crashing test case from SR-285 / rdar://problem/23677338. 2018-04-11 16:09:32 -07:00
Arnold Schwaighofer
ae0f98d601 IRGen: Ensure collocation of relative pointers in resilient witness tables
Ensure collocation by recording the dependence between witness table and
witness before functions are processed. Debug info of inlined function
scopes can reference the witness and will cause the wrong IRGenModule to
be associated before lazy witness tables are processed.

No, I am not sure that this is the only instance of this but the same
solution can apply to other instances if we find them.

rdar://39116991
2018-04-06 10:03:54 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
John McCall
31f2eec044 Change type metadata accessors to support incomplete metadata.
This includes global generic and non-generic global access
functions, protocol associated type access functions,
swift_getGenericMetadata, and generic type completion functions.

The main part of this change is that the functions now need to take
a MetadataRequest and return a MetadataResponse, which is capable
of expressing that the request can fail.  The state of the returned
metadata is reported as an second, independent return value; this
allows the caller to easily check the possibility of failure without
having to mask it out from the returned metadata pointer, as well
as allowing it to be easily ignored.

Also, change metadata access functions to use swiftcc to ensure that
this return value is indeed returned in two separate registers.

Also, change protocol associated conformance access functions to use
swiftcc.  This isn't really related, but for some reason it snuck in.
Since it's clearly the right thing to do, and since I really didn't
want to retroactively tease that back out from all the rest of the
test changes, I've left it in.

Also, change generic metadata access functions to either pass all
the generic arguments directly or pass them all indirectly.  I don't
know how we ended up with the hybrid approach.  I needed to change all
the code-generation and calls here anyway in order to pass the request
parameter, and I figured I might as well change the ABI to something
sensible.
2018-03-18 21:38:08 -04:00
John McCall
1d4fc1933b Let the runtime copy generic arguments into place. 2018-03-17 11:40:31 -04:00
Graydon Hoare
eed7cc7e5b [BatchMode] Test that some external definitions are adequately (but lazily) emitted. 2018-03-14 19:47:45 -07:00
John McCall
dff0031b02 Apply generic metadata patterns to all types and change their layout.
The layout changes to become relative-address based.  For this to be
truly immutable (at least on Darwin), things like the RO data patterns
must be moved out of the pattern header.  Additionally, compress the
pattern header so that we do not include metadata about patterns that
are not needed for the type.

Value metadata patterns just include the metadata kind and VWT.

The design here is meant to accomodate non-default instantiation
patterns should that become an interesting thing to support in the
future, e.g. for v-table specialization.
2018-03-05 19:05:41 -05: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
Arnold Schwaighofer
d981bb1d96 Mangling: noescape functions will be trivial and no longer compatible with escape function types.
Mangle escapeness as part of the type.

Part of:
SR-5441
rdar://36116691
2018-02-06 08:51:43 -08:00
Arnold Schwaighofer
14a3530442 Fix test on linux 2018-02-05 12:48:12 -08:00
Arnold Schwaighofer
ea6308994d Sema: Request the layout for generic parameters if there is a body
Generic parameters can become sources of metadata types and
conformances. To access them the layout needs to be available to IRGen.

rdar://37086144
SR-6879
2018-02-05 10:12:47 -08:00
Doug Gregor
2f6cb21079 [AST] Prefer 'synthesized' conformances to 'implied' ones consistently.
When determining which declaration context should own a particular
protocol conformance that was not explicitly spelled out, prefer
"synthesized" contexts (i.e., which is always the nominal type itself)
for automatically-generated conformances (such as a raw-valued enum's
conformance to RawRepresentable) to conformances that are "implied" by
conformance to a more-refined protocol. Previously, we biased the
other way---but because conformances due to more-refined protocols can
be discovered later, we could get into a problem where two files
disagreed on which context would own the conformance---and neither
would emit the corresponding witness table.

Biasing toward "synthesized" contexts, which are always trivially
discoverable from the nominal type declaration itself, eliminates the
issue.

Fixes SR-6839 / rdar://problem/36911943.
2018-02-02 21:46:22 -08:00
Slava Pestov
7dc7a1fc4c Serialization: When deserializing a SIL function in the merge-modules step, update linkage
Consider a module with two files, one of which references a
function in the other file. If the function had PublicNonABI
linkage, the forward reference has HiddenExternal linkage.

If we saw the forward reference first in the merge modules
process, we would not update the linkage of the function
when we later deserialized its body.

This would result in it being dropped from the final merged
SIL module. Previously this did not cause any problems
because all inlineable functions had public linkage, but now
that default argument generators no longer have public entry
points, this could cause linker errors.
2018-01-21 01:31:44 -08:00
Slava Pestov
bfe24472ea SIL: Use PublicNonABI linkage for default argument generators in Swift 4 mode
Fixes <rdar://problem/33767513>, <https://bugs.swift.org/browse/SR-5647>.
2018-01-14 22:59:41 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Slava Pestov
bc990d38a8 Sema: Fix keypaths vs. lazy member validation
Constructing a keypath expression that references a class member
needs to validate all other members of the class (or a protocol,
but I couldn't reproduce a crash with that case -- added a test
anyway).

Fixes <rdar://problem/36083061>.
2017-12-17 19:10:18 -08:00
Slava Pestov
fc3cf2863a Sema: Infer default witnesses before finishing conformance checking
Otherwise, we'll never get a chance to drain the TypeChecker's
UsedConformances list.

Fixes <https://bugs.swift.org/browse/SR-6565>, <rdar://problem/35949729>.
2017-12-10 20:30:48 -08:00
Slava Pestov
0f2da217a4 Sema: Fix some issues with overrides of materializeForSet
When overriding storage with a forced static dispatch materializeForSet,
the override's materializeForSet should not override the base
materializeForSet.

This is the case where a dynamic property witnesses a protocol
requirement, and Sema synthesizes a materializeForSet for it.

In this case, the synthesized materializeForSet dynamically dispatches
to the dynamic property's getter and setter, and the protocol witness
thunk directly calls the synthesized materializeForSet.

The subclass only needs to override the getter and setter in this case,
since the base class's materializeForSet will already do the right
thing.

In fact, marking it as an override exposes a problem where we cannot
serialize an xref to an imported property's materializeForSet, since
it was not created by the importer.
2017-10-26 17:11:09 -07:00
Slava Pestov
a0c014698d Re-organize multi-file tests a bit
- Put input files in directories named Inputs/ to eliminate bogus 'RUN: true' lines
- Remove executable_test requirement since they're not executable
2017-10-26 15:17:27 -07:00
Slava Pestov
31176d713a Sema: Only validate all members of a class if we access one of its members
... Or if we subclass it, or define an extension of it.
2017-10-22 20:05:01 -07:00
Ben Cohen
c81e115812 reenable disabled Error test (#12028) 2017-09-21 14:38:26 -07:00
Slava Pestov
da2fb2ff30 Add test case for imported conformance usage after Sema tear-down
This test used to fail because we would look up an associated type
in an incomplete conformance after Sema was torn down, causing a
crash.

Now, the ClangImporter is able to correctly complete the conformance.
2017-09-15 00:24:52 -07:00