Commit Graph

1168 Commits

Author SHA1 Message Date
Jordan Rose
ff7c6f6702 [Serialization] Drop a class if the superclass can't be found
...instead of crashing. Also drop the class if its generic
requirements depend on a type that can't be loaded (instead of
crashing).

rdar://problem/50125674
2019-05-17 10:25:01 -07:00
eeckstein
cfc2dda69a Merge pull request #24705 from eeckstein/fix-vtable-serialization
Serialization: use the mangled class name for serializing vtables.
2019-05-13 12:47:03 -07:00
Jordan Rose
6cca050fd9 [Serialization] Retire "shadowed module" in favor of "underlying" (#24711)
Similar to 517f5d6b6a, the "shadowed" terminology didn't end up
describing the most common use of the feature; there is pretty much no
intended case where a Swift module shadows a Clang module without also
re-exporting it. Switch to "underlying", which was already in use in a
few places, and which better parallels "overlay".

No intended functionality change.
2019-05-13 10:20:03 -07:00
Erik Eckstein
c957c50e28 Serialization: use the mangled class name for serializing vtables.
To distinguish between classes which have the same name (but are in different contexts).
Fixes a miscompile if classes with the same name are used from a different module.

SR-10634
rdar://problem/50538534
2019-05-11 08:30:15 -07:00
Rintaro Ishizaki
d3d30ee246 [Serialization] Support Swift only system module
Previously 'isSystemModule()' returns true only if the module is:
- Standard library
- Clang module and that is `IsSystem`
- Swift overlay for clang `IsSystem` module

Now:
- Clang module and that is `IsSystem`; or
- Swift overlay for clang `IsSystem` module
- Swift module found in either of these directories:
  - Runtime library directoris (including stdlib)
  - Frameworks in `-Fsystem` directories
  - Frameworks in `$SDKROOT/System/Library/Frameworks/` (Darwin)
  - Frameworks in `$SDKROOT/Library/Frameworks/` (Darwin)

rdar://problem/50516314
2019-05-08 17:03:06 -07:00
Rintaro Ishizaki
6956089b0b [CodeCompletion] Complete Swift only module name after 'import'
rdar://problem/39392446
2019-05-08 10:11:52 -07:00
Jordan Rose
6720a7cb74 Merge branch 'master' into artiodactyla 2019-05-06 09:32:56 -07:00
Doug Gregor
7092be6a28 [Property delegates] (De-)serialize property delegates attached to properties
Serialize the relationship between a property that has an attached delegate
and its backing variable, so deserialization can reestablish that link.

Fixes rdar://problem/50447022.
2019-05-05 21:44:54 -07:00
Jordan Rose
b3c5a68acf [Serialization] Reduce file size by splitting dep dirnames from basenames
Dependency tracking for cached compiled modules (compiled from
swiftinterfaces) can lead to a high percentage of the module being
SDK-relative paths when -track-system-dependencies is on. Cut down on
this by storing directory names in a separate record that gets
referenced from each file dependency. (Since a lot of per-file
dependencies are header files in a common directory, this is a win.)

We can do something more clever in the future, but this is a
reasonable start for, say, the overlays.

rdar://problem/50449802
2019-05-04 10:47:46 -07:00
Slava Pestov
fa12d85739 AST: Clean up associated type default representation a bit 2019-04-26 21:47:02 -04:00
Erik Eckstein
2e01b0edeb SIL: add assign_by_delegate instruction
Used for property delegates.
2019-04-23 11:32:28 -07:00
Doug Gregor
a97a51956f Merge pull request #24209 from DougGregor/opaque-result-types-mangling-fixes
[Opaque result types] Fix mangling issues with opaque result types.
2019-04-23 06:26:39 -07:00
Doug Gregor
e29469b9c0 [Opaque result types] Fix mangling issues with opaque result types.
Fix a trio of issues involving mangling for opaque result types:
* Symbolic references to opaque type descriptors are not substitutions
* Mangle protocol extension contexts correctly
* Mangle generic arguments for opaque result types of generic functions

The (de-)serialization of generic parameter lists for opaque type
declarations is important for the last bullet, to ensure that the
mangling of generic arguments of opaque result types works across
module boundaries.

Fixes the rest of rdar://problem/50038754.
2019-04-22 17:10:45 -07:00
adrian-prantl
ecebf70745 Merge pull request #24173 from adrian-prantl/memorybufferloader
Factor out the pre-registered MemoryBuffer functionality
2019-04-22 11:32:06 -07:00
Adrian Prantl
b244b0928e Factor out the pre-registered MemoryBuffer functionality
form SerializedModuleLoader into its own ModuleLoader class. (NFC-ish)

This gives better control over the order in which the various module
load mechanisms are applied.
2019-04-22 09:17:08 -07:00
adrian-prantl
f75dea49df Merge pull request #23910 from adrian-prantl/49751363
Record parseable interface imports in the debug info.
2019-04-19 14:23:57 -07:00
Joe Groff
5215290f25 Serialization: Cross-reference opaque return types by mangled name. rdar://problem/50005972 2019-04-18 14:41:26 -07:00
Joe Groff
b57f35220e Serialize opaque return type of var/subscript decls. 2019-04-17 14:46:22 -07:00
Joe Groff
399332b75b Parsable interface and type reconstruction support for opaque types.
When printing a swiftinterface, represent opaque result types using an attribute that refers to
the mangled name of the defining decl for the opaque type. To turn this back into a reference
to the right decl's implicit OpaqueTypeDecl, use type reconstruction. Since type reconstruction
doesn't normally concern itself with non-type decls, set up a lookup table in SourceFiles and
ModuleFiles to let us handle the mapping from mangled name to opaque type decl in type
reconstruction.

(Since we're invoking type reconstruction during type checking, when the module hasn't yet been
fully validated, we need to plumb a LazyResolver into the ASTBuilder in an unsightly way. Maybe
there's a better way to do this... Longer term, at least, this surface design gives space for
doing things more the right way--a more request-ified decl validator ought to be able to naturally
lazily service this request without the LazyResolver reference, and if type reconstruction in
the future learns how to reconstruct non-type decls, then the lookup tables can go away.)
2019-04-17 14:46:22 -07:00
Joe Groff
2d19110e38 Serialization: Serialize opaque types and their decls. 2019-04-17 14:43:32 -07:00
Slava Pestov
39a22f3d6a AST: Remove ParameterTypeFlags::Escaping
Escapingness is a property of the type of a value, not a property of a function
parameter. Having it as a separate parameter flag just meant one more piece of
state that could get out of sync and cause weird problems.

Instead, always look at the noescape bit in a function type as the canonical
source of truth.

This does mean that '@escaping' is now printed in a few diagnostics where it was
not printed before; we can investigate these as separate issues, but it is
correct to print it there because the function types in question are, in fact,
escaping.

Fixes <https://bugs.swift.org/browse/SR-10256>, <rdar://problem/49522774>.
2019-04-15 00:25:03 -04:00
Adrian Prantl
8d03cb7a61 Record parseable interface imports in the debug info.
When a Swift module built with debug info imports a library without
debug info from a textual interface, the textual interface is
necessary to reconstruct types defined in the library's interface.  By
recording the Swift interface files in DWARF dsymutil can collect them
and LLDB can find them.

rdar://problem/49751363
2019-04-11 14:50:07 -07:00
Harlan Haskins
149367e5d5 [ParseableInterfaces] Short-circuit module loading
Previously, the ParseableInterfaceModuleLoader relied on the assumption
that, if it returned `errc::not_supported`, it would fall through the
search paths and then move on to the SerializedModuleLoader. This did
not anticipate the possibility of a valid .swiftinterface coming later
in the search paths, which can cause issues for the standard library
which is in the resource-dir and should always be loaded from there.

Instead, make the module loading explicitly short-circuit when seeing
`errc::not_supported`, and document it.

Also add some more logging throughout `discoverLoadableModule` so we can
more easily catch issues like this in the future.

Fixes rdar://49479386
2019-04-08 10:07:11 -07:00
Nathan Hawes
58d622d796 [ParseableInterface] Don't serialize resource directory deps and stop adding cached modules to the dependency tracker
This patch modifies ParseableInterfaceBuilder::CollectDepsForSerialization to
avoid serializing dependencies from the runtime resource path into the
swiftmodules generated from .swiftinterface files. This means the module cache
should now be relocatable across machines.

It also modifies ParseableInterfaceModuleLoader to never add any dependencies
from the module cache and prebuilt cache to the dependency tracker (in addition
to the existing behaviour of not serializing them in the generated
swiftmodules). As a result, CollectDepsForSerialization no longer checks if the
dependencies it is given come from the cache as they are provided by the
dependency tracker. It now asserts that's the case instead.
2019-04-03 06:35:11 -07:00
Nathan Hawes
58d0ee0888 [ParseableInterface] Distinguish SDK and non-SDK dependencies
This allows the SDK to be relocated without automatically resulting in a
rebuild.

Based on an old patch from Jordan Rose.
2019-04-03 06:35:11 -07:00
Slava Pestov
8292cbe3b3 AST: Remove 'default argument resilience expansion'
This was a Swift 3 mode holdover.
2019-04-02 20:37:01 -04:00
Brent Royal-Gordon
972eda2316 [NFC] AST-level support for static subscripts
* Moves the IsStatic flag from VarDecl to AbstractStorageDecl.
* Adds a StaticSubscriptKind to SubscriptDecl.
* Updates serialization for these changes.
* Updates SubscriptDecl constructor call sites for these changes.
2019-04-01 18:04:00 -07:00
Doug Gregor
a848d12665 Parse unknown attributes as "custom" attributes.
Parse custom attributes with the grammar:

```
'@' type-identifier expr-paren?
```
2019-03-29 23:10:36 -07:00
Jordan Rose
526ea54f43 [Serialization] Preserve @_implementationOnly through module merging
When we build incrementally, we produce "partial swiftmodules" for
each input source file, then merge them together into the final
compiled module that, among other things, gets used for debugging.
Without this, we'd drop @_implementationOnly imports and any types
from the modules that were imported during the module-merging step
and then be unable to debug those types
2019-03-28 16:04:35 -07:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Harlan Haskins
ca4f129a3f [Serialization] Increment module format version
Unblocking the bots

rdar://49239686
2019-03-25 18:23:40 -07:00
Ted Kremenek
fe215edb9b Merge pull request #19743 from Azoy/smarter-struct-init
[Sema] Synthesize default values for memberwise init
2019-03-25 17:31:01 -07:00
Harlan Haskins
f4da34f363 [ParseableInterface] Only open module buffers once while loading
In addition to being wasteful, this is a correctness issue -- the
compiler should only ever have one view of this file, and it should not
read a potentially different file after validating dependencies.

rdar://48654608
2019-03-21 18:17:07 -07:00
Azoy
e8bc662b35 Cleanups from Slava's comments
update module format
2019-03-13 18:58:45 -05:00
Azoy
6f7d20b99e Synthesize default values for memberwise init
Introduce stored property default argument kind

Fix indent

Assign nil to optionals with no initializers

Don't emit generator for stored property default arg

Fix problem with rebase

Indentation

Serialize stored property default arg text

Fix some tests

Add missing constructor in test

Print stored property's initializer expression

cleanups

preserve switch

complete_constructor

formatting

fix conflict
2019-03-13 18:57:36 -05:00
Slava Pestov
c791c4a137 SIL: SILUndef must be aware of the resilience expansion
The ownership kind is Any for trivial types, or Owned otherwise, but
whether a type is trivial or not will soon depend on the resilience
expansion.

This means that a SILModule now uniques two SILUndefs per type instead
of one, and serialization uses two distinct sentinel IDs for this
purpose as well.

For now, the resilience expansion is not actually used here, so this
change is NFC, other than changing the module format.
2019-03-12 00:30:35 -04:00
Harlan Haskins
7d71579950 [Serialization] Allow either hash-based or mtime-based deps
Add a bit to the module to determine whether the dependency’s stored bit pattern is a hash or an mtime.

Prebuilt modules store a hash of their dependencies because we can’t be sure their dependencies will have the same modtime as when they were built.
2019-03-05 11:46:21 -08:00
Brent Royal-Gordon
f1d1df3b30 Merge pull request #22842 from brentdax/target-practice
Name platform-specific module files using a normalized target triple
2019-02-28 16:07:37 -08:00
Brent Royal-Gordon
3f58a79174 Import error now mentions the target, not the arch 2019-02-27 11:43:12 -08:00
Jordan Rose
23fdccc373 [Serialization] Start getTypeChecked() -> TypeDeserializer
Like I just did for DeclDeserializer. This one adds the new class and
moves most of getTypeChecked() into it, but doesn't yet split anything
up.
2019-02-22 08:59:33 -08:00
Joe Groff
64488b19f9 Serialization: Rework serialization of nested archetypes.
Explicitly serialize the parent archetype so that it can be any kind of root archetype.
2019-02-20 12:53:18 -08:00
Slava Pestov
bd6490b391 SIL: Introduce '@_alwaysEmitIntoClient' attribute for use by standard library
This is like '@inlinable', except that the symbol does not have a public
entry point in the generated binary at all; it is deserialized and a copy
is always emitted into the client binary, with shared linkage.

Just like '@inlinable', if you apply this to an internal declaration it
becomes '@usableFromInline' automatically.

This uses the same mechanism as default arguments ever since Swift 4, so
it should work reasonably well, but there are rough edges with diagnostics
and such. Don't use this if you are not the standard library.

Fixes <rdar://problem/33767512>, <https://bugs.swift.org/browse/SR-5646>.
2019-02-18 17:10:57 -05:00
Jordan Rose
f637c75488 Merge pull request #22610 from jrose-apple/DeclDeserializer
[Serialization] Break up getDeclCheckedImpl into a helper class

No intended functionality change.
2019-02-15 16:09:47 -08:00
Jordan Rose
8c062232c5 [Serialization] Make ASTDeserializer stateful, and use that state
...for decl attributes. Also, rename to DeclDeserializer.
2019-02-13 20:23:39 -08:00
Jordan Rose
3273f06879 [Serialization] Pull decl deserialization out to a helper class
In preparation for splitting up one big switch into many small
methods. Well, medium-sized methods.

No functionality change.
2019-02-13 20:23:38 -08:00
Azoy
5af2663c57 Textualize assign init kind
Rename [assign] to [reassign]

fix some tests

AssignOwnershipQualifier

formatting

moar formatting
2019-02-12 20:16:25 -06:00
Harlan Haskins
6ae20a959b [ParseableInterface] Refine cache key for cached swiftmodules
Previously, we included the PCH hash components in the cache key. While they didn’t do any harm, they didn’t contribute any unique information about the module in question.

Additionally, passing the effective language version in means that each dependency that uses a different -swift-version would re-compile all of its dependencies. This is unfortunate, as that means the standard library is recompiled potentially several times.
2019-02-04 14:39:46 -08:00
Harlan Haskins
6f94720b01 [Serialization] Use mtime instead of hash for file dependencies
Hashing the contents of the interface files is overkill. In practice, size and last modification time are enough to determine if a file has changed on disk, and therefore should be rebuilt.
2019-02-04 13:26:38 -08:00
Arnold Schwaighofer
f664b16010 SIL: Add an on stack version of partial_apply
It does not take ownership of its non-trivial arguments, is a trivial
function type and therefore must not be destroyed. The compiler must
make sure to extend the lifetime of non-trivial arguments beyond the
last use of the closure.

  %objc = copy_value %0 : $AnObject
  %closure = partial_apply [stack] [callee_guaranteed] %16(%obj) : $@convention(thin) (@guaranteed AnObject) -> ()
  %closure2 = mark_dependence %closure : $@noescape @callee_guaranteed () -> () on %obj : $AnObject
  %user = function_ref @useClosure : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %user(%closure2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  dealloc_stack %closure : $() ->()
  destroy_value %obj : $AnObject // noescape closure does not take ownership

SR-904
rdar://35590578
2019-01-15 11:20:33 -08:00
Slava Pestov
81c5a67489 Merge pull request #21758 from pschuh/s-1
Rename NameAliasType to TypeAliasType.
2019-01-10 15:20:41 -05:00