Commit Graph

339 Commits

Author SHA1 Message Date
Alex Hoppen
1fcac0e4f4 [Serialization] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Jordan Rose
f30800ca49 [Serialization] Handle operators that can't be deserialized.
We were already doing this for top-level declarations; just use the
same recovery code for operators.

More rdar://problem/31920901
2017-05-17 17:31:54 -07:00
Doug Gregor
f5b99c75f4 [Serialization] Stop pre-loading generic environments.
Make generic environment deserialization lazy, which eliminates a
significant amount of up-front work. Most clients only need the
generic signature, not the full generic environment.
2017-05-16 11:06:17 -07:00
Jordan Rose
48fca56342 Specifically mention version mismatches for non-subclassable classes.
That is, if a Swift 4 class has members that cannot be loaded in Swift
3 mode and that's why it can't be subclassed, mention that in the
diagnostic.
2017-05-10 17:03:32 -07:00
Joe Groff
e3e0f440a1 Serialization: Recovery for protocol conformances with changed witness or requirement signatures.
Deserializing a witness record in a conformance may fail if either of the requirement or witness changed name or type, most likely due to SDK modernization changes across Swift versions. When this happens, leave an opaque placeholder in the conformance to indicate that the witness exists but we don't get to see it. For expedience, right now this just witnesses the requirement to itself, so that code in the type checker or elsewhere that tries to ad-hoc devirtualize references to the requirement just gets the requirement back. Arguably, we shouldn't include the witness at all in imported conformances, since they should be an implementation detail, but that's a bigger, riskier change. This patch as is should be enough to address rdar://problem/31185053.
2017-05-09 09:15:04 -07:00
Jordan Rose
1168cacf4f [Serialization] Drop decls whose types can't be deserialized.
Proof-of-concept for the above. This shouldn't be common---renames are
far more likely, and those we can track---but occurs when the
swift_wrapper attribute (the implementation of NS_STRING_ENUM) is
active in Swift 4 but not in Swift 3.

Note that this only checks the canonical interface type of the
declaration, because the non-canonical type may contain references to
the declaration's generic parameters.
2017-04-27 18:30:34 -07:00
Doug Gregor
f6f547469d [Serialization] Filter Objective-C methods by mangled name rather than type ID.
Module files store all of the Objective-C method entrypoints in a
central table indexed by selector, then filter the results based on
the specific class being requested. Rather than storing the class as
a TypeID---which requires a bunch of deserialization---store its
mangled name. This allows us to deserialize less, and causes circular
deserialization in rdar://problem/31615640.
2017-04-18 11:53:17 -07:00
Jordan Rose
7e8d642e8e [Serialization] When crashing, note if mix-and-match may be to blame.
That is, a Swift 3 target imported into a Swift 4 context or vice
versa. This requires serializing the compatibility mode explicitly,
instead of including it in the textual version string that's only
for debugging.
2017-04-10 16:38:58 -07:00
Erik Eckstein
d70bfc5de2 rename namespace NewMangling -> Mangle 2017-03-20 10:09:30 -07:00
Jordan Rose
a8e4e72270 [Serialization] Delay all actions in the same module together. (#8123)
Back in December DougG added code to delay the formation of generic
environments until all declarations from a particular module had been
deserialized, to avoid circular dependencies caused by too-eager
deserialization of protocol members. This worked great for fully-built
modules, but still had some problems with module merging, the phase of
multi-file compilation where the "partial" swiftmodules that
correspond to each source file in a target are loaded and remitted as
a single swiftmodule. Fix this by picking one of the partial
swiftmodules as the representative one for delayed actions, and wait
until deserialization is complete for /all/ of the serialized ASTs in
the same target to form the generic environments.

rdar://problem/30984417
2017-03-16 15:22:06 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Argyrios Kyrtzidis
ca906d1e99 Add '-Fsystem' framework search option to indicate path for frameworks that should be treated as 'system'
This has the effect of propagating the search path to the clang importer as '-iframework'.
It doesn't affect whether a swift module is treated as system or not, this can be done as follow-up enhancement.
2017-02-14 16:13:25 -08:00
Jordan Rose
c86f8e7089 [Serialization] Improve extensions of nested types with the same name (#7397)
Previously looking up an extension would result in all extensions for
types with the same name (nested or not) being deserialized; this
could even bring in base types that had not been deserialized yet. Add
in a string to distinguish an extension's base type; in the top-level
case this is just a module name, but for nested types it's a full
mangled name.

This is a little heavier than I'd like it to be, since it means we
mangle names and then throw them away, and since it means there's a
whole bunch of extra string data in the module just for uniquely
identifying a declaration. But it's correct, and does less work than
before, and fixes a circularity issue with a nested type A.B.A that
apparently used to work.

https://bugs.swift.org/browse/SR-3915
2017-02-13 12:42:12 -08:00
Hugh Bellamy
a2c0e301a7 Work around MSVC bug for equality check of implicit operator conversion of class to base-class pointer with const subclass pointer 2017-02-11 14:34:11 +07:00
Jordan Rose
99d47619e6 Merge pull request #7067 from jrose-apple/nested-type-lookup-table
[Serialization] Add a "nested types" lookup table for partial modules
2017-01-27 08:55:41 -08:00
Saleem Abdulrasool
078b5b2506 Serialization: fix previous changes for upstream update
We would previously get an error for an unexpected EOF.  However, we no
longer were checking that case, and would fall through to the end of the
function, without a return value.  Return the proper failure indicator.
2017-01-26 21:06:37 -08:00
Jordan Rose
8145cd0b22 [Serialization] Add a "nested types" lookup table for partial modules.
There's a class of errors in Serialization called "circularity
issues", where declaration A in file A.swift depends on declaration B
in file B.swift, and B also depends on A. In some cases we can manage
to type-check each of these files individually due to the laziness of
'validateDecl', but then fail to merge the "partial modules" generated
from A.swift and B.swift to form a single swiftmodule for the library
(because deserialization is a little less lazy for some things). A
common case of this is when at least one of the declarations is
nested, in which case a lookup to find that declaration needs to load
all the members of the parent type. This gets even worse when the
nested type is defined in an extension.

This commit sidesteps that issue specifically for nested types by
creating a top-level, per-file table of nested types in the "partial
modules". When a type is in the same module, we can then look it up
/without/ importing all other members of the parent type.

The long-term solution is to allow accessing any members of a type
without having to load them all, something we should support not just
for module-merging while building a single target but when reading
from imported modules as well. This should improve both compile time
and memory usage, though I'm not sure to what extent. (Unfortunately,
too many things still depend on the whole members list being loaded.)

Because this is a new code path, I put in a switch to turn it off:
frontend flag -disable-serialization-nested-type-lookup-table

https://bugs.swift.org/browse/SR-3707 (and possibly others)
2017-01-26 15:04:42 -08:00
Bob Wilson
37e7d1c627 Merge remote-tracking branch 'origin/master' into master-next 2017-01-08 17:07:46 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Bob Wilson
78b28243ff Merge remote-tracking branch 'origin/master' into master-next 2017-01-03 14:22:59 -08:00
Michael Gottesman
96c63e9e76 Merge pull request #6324 from practicalswift/cpp-gardening
[gardening] C++ gardening: Terminate namespaces, fix argument names, …
2016-12-16 23:30:33 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Doug Gregor
821965dee4 [Serialization] Give generic environments identitity.
Serialize generic environments via a generic environment ID with a
separte offset table, so we have identity for the generic environments
and will share generic environments on deserialization.
2016-12-16 08:41:43 -08:00
Bob Wilson
deddf19aae Merge remote-tracking branch 'origin/master' into master-next 2016-12-13 10:23:03 -08:00
Joe Groff
0308ecf89f Serialize SILBoxTypes using their layout. 2016-12-08 15:59:34 -08:00
Bob Wilson
13da3fa8b1 Merge remote-tracking branch 'origin/master' into master-next 2016-12-04 18:16:09 -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
Bob Wilson
343fe88f3a Fix up compnerd's change 46d684f to stop using BitstreamReader.
The more important fix here is to remove a duplicated call to advance the
cursor, which led to module import being completely broken. I also added
back the AF_DontPopBlockAtEnd flags that were dropped. I am not certain
if they are needed but without clear indication otherwise, we should keep
them.
2016-11-17 17:24:15 -08:00
Saleem Abdulrasool
46d684f35f remove usage of BitstreamReader
LLVM SVN r286207 removed the BitstreamReader interface.  Remove the usage of the
type, updating the cursor constructor accordingly.
2016-11-15 17:39:37 -08:00
Bob Wilson
198cb095a8 Merge pull request #5233 from bob-wilson/module-file-undefined-behavior
Avoid undefined behavior with std::minmax and rvalues.
2016-10-11 13:08:42 -07:00
Bob Wilson
3d67d824ed Avoid undefined behavior with std::minmax and rvalues.
The behavior of std::minmax with rvalue arguments is undefined after the
end of the expression that contains the call to minmax. This code to
special-case the comparisons for ARM vs. Thumb and macOS vs. Darwin was a
little overly clever anyway. Rewrite it to use straightforward comparisons.
This fixes a test failure in Serialization/target-incompatible.swift when
building with a recent version of clang, because these checks were completely
optimized away due to the undefined behavior. rdar://problem/28700005
2016-10-11 11:04:52 -07:00
Jordan Rose
5d3a7f7c23 [serialization] Yet Another Misuse of ArrayRef (#5216)
I wonder if we can assert that the lifetime is valid or something.

rdar://problem/28699599
2016-10-10 16:24:25 -07:00
Jordan Rose
16c61bbbba [Serialization] Add some asserts to catch giant method lists.
This would have allowed us to triage rdar://problem/28305755 much
sooner. The actual problem is pretty bad: if you have too many methods
with the same selector, serialization just falls over.  "Too many" is
in the thousands, which seems unlikely, but 'dealloc' can actually get
there if there are a lot of little classes, and 'init' might as well,
so we really should do better here.
2016-10-06 14:07:04 -07:00
Argyrios Kyrtzidis
3bc81f7df4 [Serialization] Fix deserialization crash occurring when a mixed framework fails to load its ObjC part.
rdar://27709042
2016-08-04 15:59:05 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Roman Levenstein
89c41ca2d4 [sil-serializer] Do not use RPOT order for serializing SIL basic blocks
My earlier patch started serializing SIL basic blocks using the RPOT order. While it works, changing the existing order of BBs during the serialization may be very surprising for users. After all, serialization is not supposed to transform the code.

Therefore, this patch follows a different approach. It uses the existing order of BBs during the serialization. When it deserializes/parses SIL and detects a use of an opened archetype before its definition, it basically introduced a forward definition of this opened archetype. Later on, when the actual definition of the opened archetype is found, it replaces the forward definition. There is a correctness check at the end of a SIL function deserialization, which verifies that there are no forward definitions of opened archetypes left unresolved.
2016-07-19 13:04:40 -07:00
practicalswift
57bccc8b06 [gardening] Fix inconsistent formatting. 2016-06-04 00:37:15 +02:00
Argyrios Kyrtzidis
8ce372dca9 [IDE] Move determination of the decl group at the Decl::getGroupName() caller. 2016-05-08 16:27:46 -07:00
Jordan Rose
8f820dea2b [serialization] Diagnose loading modules from older Swifts.
...with a better message than the generic "older version of the
compiler" one, when we know it's actually a different version of
Swift proper.

This still uses the same internal module version numbers to check
if the module is compatible; the presentation of language versions
is a diagnostic thing only.

Speaking of module version numbers, this deliberately does NOT
increment VERSION_MINOR; it's implemented in a backwards-compatible
way.

This will only work going forwards, of course; all existing modules
don't have a short version string, and I don't feel comfortable
assuming all older modules we might encounter are "Swift 2.2".

rdar://problem/25680392
2016-04-29 16:25:33 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Slava Pestov
1ce1e78951 AST: Record -sil-serialize-all in the ModuleDecl
We want to distinguish the special case of a library built with
-sil-serialize-all, from a SIL function that is [fragile] because
of an explicitly @_transparent or @inline(__always).

For now, NFC.
2016-03-28 14:14:49 -07:00
Xi Ge
fda0751cae [SourceKit] In interface-gen request, allow clients to send SourceKit an interested USR from which we can infer the group name. 2016-03-23 17:26:44 -07:00
Xi Ge
3dd149ab99 [SourceKit] CursorInfo: The result of cursor info for a module name starts to include group names in that module. 2016-03-21 17:20:18 -07:00
Xi Ge
d0e176810f [Serialization] Serialize doc comments for extensions. Need this for rdar://25157796
We did not serialize them because getting USR for extensions is tricky (USRs are
usually for value decls). This commit starts to make up an USR for an extension by combining
the extended nominal's USR with the USR of the first value member of the extension. We use
this made-up USR to associate doc comments when (de)serializing them.
2016-03-15 13:35:07 -07:00
Xi Ge
09cd9c1f9d ModulePrinting: Fix several issues pointed by Ben. 2016-03-08 18:34:38 -08:00
Ben Langmuir
92a91810e4 Make getGroupDecl static 2016-03-08 18:04:55 -08:00
Xi Ge
c84f667676 [Serialization] Serialize the source order of Decls appearing in their original source file.
We used to think the source order is preserved after de-serialization; however, this seems to be
not the case.
2016-03-08 12:18:10 -08:00
Xi Ge
7a3276738b Re-apply "ModulePrinter: Print decls from the same source file near each other."
This reverts commit 1db83907e3.
2016-03-08 12:18:10 -08:00
Xi Ge
1db83907e3 Revert "ModulePrinter: Print decls from the same source file near each other."
This reverts commit a5c9072344 for mysterious bot test failure.
2016-03-07 23:33:23 -08:00