Commit Graph

904 Commits

Author SHA1 Message Date
Artem Chikin
efdfceeb9b [Sema] Diagnose use of implementation-only property wrappers
We already ban all structs from declaring storage that comes from implementation-only imports. Until now we missed property wrappers, they were just dropped in deserialization.

Resolves rdar://problem/59403617
2020-04-10 11:19:42 -07:00
Robert Widmann
ba97afc138 Fix the gates on a test that needs statistics
rdar://61348443
2020-04-06 11:00:26 -07:00
Xi Ge
8d0e38e364 test: disable Serialization/multi-file-type-eraser.swift for failing in public CI
rdar://61348443
2020-04-06 10:39:25 -07:00
Robert Widmann
bce1dd6b49 Remove test that is incompatible with laziness
Going through sil-opt is going to print the contents of the module
without forcing the attribute which renders the test toothless. Now that
we have the multifile test, we're testing it can be round-tripped
through serialization anyhow.
2020-04-03 18:26:54 -07:00
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
Alexis Laferrière
9921cd7c1f Merge pull request #30614 from xymus/fix-deser-indexing
[Serialization] Recover from more failures when reading private declarations
2020-03-24 13:45:00 -07:00
Alexis Laferrière
4e0038f0df [Serialization] Recover from conformances with missing decls
Components of a requirement may be hidden behind an implementation-only
import. Attempts at deserializing them would fail on a 'module not
loaded' error. We only see failures in non-compilation paths, either in
indexing or with tools like ide-test as they try to deserialize
things that are private.
2020-03-24 10:25:02 -07:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Ted Kremenek
39c34c89ee Bump Swift version to 5.3 2020-03-17 13:54:32 -07:00
Kuba (Brecka) Mracek
5d918e5ee1 Merge branch 'master' into mracek/arm64e 2020-03-03 08:28:01 -08:00
Holly Borla
87bb7755c2 Merge pull request #30101 from hborla/dynamic-replacement-type-erasure
[Sema] Implement type erasure for dynamic replacement.
2020-02-28 09:37:33 -08:00
Kuba Mracek
1bd425da67 [arm64e] Test changes to support arm64e 2020-02-27 16:10:48 -08:00
Holly Borla
5ce5096633 [Test] Add more tests for @_typeEraser 2020-02-27 11:42:15 -08:00
swift-ci
cd4f3b03c7 Merge pull request #30017 from 3405691582/TestSerializationAndroidModules_RequiresCpuArm64 2020-02-22 23:39:36 -08:00
3405691582
f39b4b5d3f [test] REQUIRE cpu arm64 when testing arm64 flags.
If llvm-targets-to-build doesn't include AArch64, then this test fails
unhelpfully because architecture-specific flags are missing.
2020-02-22 23:42:18 -05:00
Alexis Laferrière
6dc9dce88b [Test] Reproducer for witness table deserialization failure with a enum_flag 2020-02-21 11:56:09 -08:00
Robert Widmann
53b368b34f Always write out nested types tables
Remove the option to switch off nested types tables. In a world where
re-entrant direct lookup will cause deserialization to fail (or worse),
disabling these tables will only lead to further instability in the
compiler.
2020-02-10 10:41:23 -08:00
Robert Widmann
a60ada1ce2 Gate a test that dumps stats on an asserts build 2020-02-09 21:22:32 -08:00
Robert Widmann
f56fee839b [ModuleInterface] Pass Through Flags for Nested Types Tables
When a swift module is generated from a swift interface file, we must
remember to setup the nested types tables. Plumb the flag down from the
frontend options.

In the future, we must remove the ability to turn this off. There's
literally zero reason to have this be a configuration option anymore.

Resolves rdar://59202687 and its many, many dupes.
2020-02-07 14:37:03 -08:00
John McCall
faee21b626 Implement Swift serialization and deserialization of Clang types.
As part of this, we have to change the type export rules to
prevent `@convention(c)` function types from being used in
exported interfaces if they aren't serializable.  This is a
more conservative version of the original rule I had, which
was to import such function-pointer types as opaque pointers.
That rule would've completely prevented importing function-pointer
types defined in bridging headers and so simply doesn't work,
so we're left trying to catch the unsupportable cases
retroactively.  This has the unfortunate consequence that we
can't necessarily serialize the internal state of the compiler,
but that was already true due to normal type uses of aggregate
types from bridging headers; if we can teach the compiler to
reliably serialize such types, we should be able to use the
same mechanisms for function types.

This PR doesn't flip the switch to use Clang function types
by default, so many of the clang-function-type-serialization
FIXMEs are still in place.
2020-02-06 22:09:00 -05:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00
Pavel Yaskevich
d24537f032 Merge pull request #29024 from xedin/diagnose-shadowing
[Diagnostics] Port name shadowing diagnostics
2020-01-31 10:39:58 -08:00
Robert Widmann
3375b362eb Search nested types tables in parent modules
Add another cross-cutting module configuration to the nested types table
search path. A module can have no overlay but also contain a nested
types table suitable for finding a given member name. UIKit is the
sharpest example of this state of affairs. UIKit currently defines an
overlay in Swift where we find some nested types.  But it also defines
an inner module that has some other nested types tables.

Resolves rdar://58940989
2020-01-30 14:26:27 -08:00
Adrian Prantl
15c1b4eca7 Compile libraries in testcases with -parse-as-library (NFC)
This is in preparation to a change in serialization of global variables where
this detail will matter.
2020-01-29 09:21:32 -08:00
adrian-prantl
9676625b96 Merge pull request #29522 from adrian-prantl/test-update
Compile libraries in testcases with -parse-as-library (NFC)
2020-01-29 09:12:46 -08:00
Adrian Prantl
37e403db78 Compile libraries in testcases with -parse-as-library (NFC)
This is in preparation to a change in serialization of global variables where
this detail will matter.
2020-01-28 17:37:52 -08:00
Robert Widmann
255b2cf860 [NFC] Improve Nested Types Table Test
To guard against the kind of complex failures seen in rdar://58690068,
improve this regression test with a copy of a shrunken version of
CocoaError.Code.

In that radar, CocoaError.Code was defined in one overlay and extended
in another translation unit.  When deserialization encountered this, it
failed to search the overlay's nested type tables and fell through to
re-enter lookupDirect.
2020-01-28 13:06:35 -08:00
Brent Royal-Gordon
e4c1de675a [NFC-ish] Simplify module loader filename handling (#29295)
* Remove dead ModuleSourceInfoFilename parameters

These were never actually used; we might find a way to bring them back later.

* Introduce SerializedModuleBaseName

This is intended to replace the _n_ filename parameters that tend to get passed around in the SerializedModuleLoader classes.

* Manipulate currPath in SerializedModuleLoader less often

* Don’t pass raw paths around SerializedModuleLoader

Only pass base names.

* Regularize module file opening functions
2020-01-21 13:02:20 -08:00
Arnold Schwaighofer
c9bd831004 DeserializeSIL: Fix two places where we want the SILType inside of the current function according to the TypeExpansionContext
rdar://58095210
2019-12-20 10:33:06 -08:00
Alexis Laferrière
c2c36d0769 [Serialization] Fix reporting a dependency cycle with a missing clang module
rdar://problem/57364033
2019-12-16 17:06:59 -08:00
najacque
32bc769c59 Merge pull request #28603 from najacque/master
bumping swift version number to 5.2
2019-12-06 15:47:10 -08:00
najacque
8b378626e4 bumping swift version number to 5.2 rdar://problem/56622958 2019-12-05 17:22:02 -08:00
Argyrios Kyrtzidis
31d567ee33 Merge pull request #28452 from nathawes/add-configuration-request-and-option-to-ignore-swiftsourceinfo
[SourceKit] Add global-configuration request to control SourceKit's behavior around .swiftsourceinfo files
2019-12-05 17:10:38 -08:00
Slava Pestov
1df3d1a33c Frontend: Don't interleave parsing and typechecking for the main file
SIL files still require this behavior; if we cleaned that up we
could simplify a fair bit of code here.

Fixes <https://bugs.swift.org/browse/SR-284>,
<https://bugs.swift.org/browse/SR-4426>.
2019-12-05 08:45:55 -05:00
Nathan Hawes
b9d5672ca1 [SourceKit] Add a global-configuration request to control SourceKit's behavior around .swiftsourceinfo files
SwiftSourceInfo files provide source location information for decls coming from
loaded modules. For most IDE use cases it either has an undesirable impact on
performance with no benefit (code completion), results in stale locations being
used instead of more up-to-date indexer locations (cursor info), or has no
observable effect (live diagnostics, which are filtered to just those with a
location in the primary file).

For non-IDE clients of SourceKit though, cursor info providing declaration
locations for symbols from other modules is useful, so add a global
configuration option (and a new request to set it) to control whether
.swiftsourceinfo files are loaded or not based on use case (they are loaded by
default).
2019-12-03 13:15:20 -08:00
Mishal Shah
e74c34c6a1 Bumping Swift version number to 5.1.2 2019-11-30 18:39:05 -08:00
Slava Pestov
53bfc767a3 SIL: Track target formal type for casts
SIL type lowering erases DynamicSelfType, so we generate
incorrect code when casting to DynamicSelfType. Fixing this
requires a fair amount of plumbing, but most of the
changes are mechanical.

Note that the textual SIL syntax for casts has changed
slightly; the target type is now a formal type without a '$',
not a SIL type.

Also, the unconditional_checked_cast_value and
checked_cast_value_br instructions now take the _source_
formal type as well, just like the *_addr forms they are
intended to replace.
2019-11-20 21:30:28 -05:00
Michael Gottesman
269762eee3 [ownership] Enable ownership lowering /after/ the diagnostic passes.
I also updated the last group of straggling tests.
2019-11-17 11:34:43 -08:00
Keith Smiley
bf4aaacb02 Remove @frozen without library evolution warning
This warning is produced if you annotate an enum with `@frozen` but
build without library evolution enabled. The problem is that if you
only build with library evolution enabled for release builds, this
leaves you with a warning for all debug builds. The downside of this
change is that if you never build with library evolution, you may have
this unnecessary annotation without noticing.
2019-11-12 19:35:05 -08:00
Luciano Almeida
1184492d25 [Diagnostics] SR-11419 Diagnose protocol stub note in editor mode only (#28101)
* [TypeChecker] Enclosing stubs protocol note within editor mode

* [test] Removing note from test where there is no -diagnostics-editor-mode flag

* Formatting modified code

* [tests] Fixing tests under validation-tests
2019-11-06 07:42:48 -08:00
Alexis Laferrière
ac28905926 [serialization] Recover from missing custom attribute
rdar://problem/56599179
2019-10-30 12:55:34 -07:00
Jordan Rose
a52fac4470 [Serialization] Store whether an override depends on its base for ABI (#27784)
In some circumstances, a Swift declaration in module A will depend on
another declaration (usually from Objective-C) that can't be loaded,
for whatever reason. If the Swift declaration is *overriding* the
missing declaration, this can present a problem, because the way
methods are dispatched in Swift can depend on knowing the original
class that introduced the method. However, if the compiler can prove
that the override can still be safely invoked/used in all cases, it
doesn't need to worry about the overridden declaration being missing.

This is especially relevant for property accessors, because there's
currently no logic to recover from a property being successfully
deserialized and then finding out that an accessor couldn't be.

The decision of whether or not an override can be safely invoked
without knowledge of the base method is something to be cautious
about---a mistaken analysis would effectively be a miscompile. So up
until now, this was limited to one case: when a method is known to be
`@objc dynamic`, i.e. always dispatched through objc_msgSend. (Even
this may become questionable if we have first-class method references,
like we do for key paths.) This worked particularly well because the
compiler infers 'dynamic' for any overload of an imported Objective-C
method or accessor, in case it imports differently in a different
-swift-version and a client ends up subclassing it.

However...that inference does not apply if the class is final, because
then there are no subclasses to worry about.

This commit changes the test to be more careful: if the /missing/
declaration was `@objc dynamic`, we know that it can't affect ABI,
because either the override is properly `@objc dynamic` as well, or
the override has introduced its own calling ABI (in practice, a direct
call for final methods) that doesn't depend on the superclass. Again,
this isn't 100% correct in the presence of first-class methods, but it
does fix the issue in practice where a property accessor in a parent
class goes missing. And since Objective-C allows adding property
setters separately from the original property declaration, that's
something that can happen even under normal circumstances. Sadly.

This approach could probably be extended to constructors as well. I'm
a little more cautious about throwing vars and subscripts into the mix
because of the presence of key paths, which do allow identity-based
comparison of overrides and bases.

rdar://problem/56388950
2019-10-21 15:53:25 -07:00
Xi Ge
dec878360f Driver: rename Name.swiftmodule/Private directory to Name.swiftmodule/Project
This directory should be excluded during installation since the content is only
used for local development. swiftsourceinfo file is currently emitted to this directory.
2019-10-09 15:29:52 -07:00
Xi Ge
ba6891d7c8 SerializeLoc: include source locations for double underscored symbols in .swiftsourceinfo file
For .swiftdoc file, we don't expose doc-comments for underscored symbols. But this
seems to be an unnecessary constraint on .swiftsourceinfo file since we put
these symbols in .swiftinterface files anyway.
2019-10-09 15:29:52 -07:00
Xi Ge
212fe43d79 SerializeLoc: ensure we can load serialized source locations when we are importing a module from a Swift interface file 2019-10-09 15:29:52 -07:00
Xi Ge
d6dc7c3331 test: add a test for source location serialization for wmo mode 2019-10-09 15:29:51 -07:00
Xi Ge
125e6ef4f1 test: add a test for serializing decl source locations under batch mode 2019-10-09 15:29:51 -07:00
Xi Ge
e9dfdea6fd SerializeLoc: serialize basic decl source location information to .swiftsourceinfo file
After setting up the .swiftsourceinfo file, this patch starts to actually serialize
and de-serialize source locations for declaration. The binary format of .swiftsourceinfo
currently contains these three records:

BasicDeclLocs: a hash table mapping from a USR ID to a list of basic source locations. The USR id
could be retrieved from the following DeclUSRs record using an actual decl USR. The basic source locations
include a file ID and the results from Decl::getLoc(), ValueDecl::getNameLoc(), Decl::getStartLoc() and Decl::getEndLoc().
The file ID could be used to retrieve the actual file name from the following SourceFilePaths record.
Each location is encoded as a line:column pair.

DeclUSRS: a hash table mapping from USR to a USR ID used by location records.

SourceFilePaths: a hash table mapping from a file ID to actual file name.

BasicDeclLocs should be sufficient for most diagnostic cases. If additional source locations
are needed, we could always add new source location records without breaking the backward compatibility.
When de-serializing the source location from a module-imported decl, we calculate its USR, retrieve the USR ID
from the DeclUSRS record, and use the USR ID to look up the basic location list in the BasicDeclLocs record.

For more details about .swiftsourceinfo file: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation
2019-10-09 15:29:51 -07:00
Mishal Shah
fff1a39364 [Version] Bump the Swift version to 5.1.1 2019-10-03 14:35:57 -07:00
Harlan Haskins
67683d8884 [Deserialization] Allow lookup into decls that don't have an interface type yet
Fixes rdar://55560962 and https://bugs.swift.org/browse/SR-11495

This bug was caused because we'd fail to lookup C in B, because we
hadn't computed its type yet and therefore B is filtered from lookup.
Just remove the filter for interface type.
2019-09-30 11:24:22 -07:00