Commit Graph

573 Commits

Author SHA1 Message Date
Doug Gregor
6bdd24d1ac Merge pull request #16268 from DougGregor/substitution-map-ast-adoption
[AST] Adopt SubstitutionMap as the storage mechanism for substitutions
2018-04-30 20:36:02 -07:00
Doug Gregor
ab56fa3e9c [Serialization] Support (de-)serialization of SubstitutionMaps.
Allow substitution maps to be serialized directly (via an ID), writing out
the replacement types and conformances as appropriate. This is a more
efficient form of serialization than the current SubstitutionList approach,
because it maintains uniqueness of substitution maps within a module file,
and is a step toward eliminating SubstitutionList entirely.
2018-04-30 16:21:58 -07:00
swift-ci
71a7529f6b Merge remote-tracking branch 'origin/master' into master-next 2018-04-27 05:28:59 -07:00
Slava Pestov
4d7950a9b2 Serialization: Remove obsolete 'HasUnderlyingModule' hack 2018-04-26 23:37:17 -07:00
Slava Pestov
8408f8221d Serialization: Replace ModuleDecl::ImportFilter math with explicit switch statements
This one is particularly obnoxious.
2018-04-26 23:37:17 -07:00
Adrian Prantl
8fc5c364fe typo 2018-02-28 14:32:33 -08:00
Adrian Prantl
0747d9a339 Force the DJB hash seed to 0 for compatibility with HashString.
The obsolete llvm::HashString() was equivalent to
llvm::djbHash(seed=0) and was removed from llvm. This patch replaces
all occurences of llvm::HashString() with llvm::djbHash(seed=0), no
functional change.

The default seed of llvm::djbHash() is supposed to yield a higher
quality result that using seed=0, but changing it looks like it
affects the ordering of SIL serialization.
2018-02-28 14:10:25 -08:00
Saleem Abdulrasool
a0c6a70c31 upstream-update: adjust for SVN r326091 2018-02-27 12:36:15 -08:00
Andrew Trick
66a579cc77 Add ModuleFile::isSIB
We can't make the same assumptions about .sib files.

Ideally, we should serialize the module's stage and set WasDeserializedCanonical
based on that state. However, we probably still want the IsSIB flag for
assertions.
2018-02-09 09:55:47 -08:00
Doug Gregor
8c05278ef3 [Clang importer] Lazily load all named members with a matching base name.
When loading the named members for a given name, we want to load all
of the members with that base name... not only the ones that match the
full name, because the lookup table is indexed by base name and
filtering too early drops candidates.

Fixes rdar://problem/36085994.
2017-12-15 23:54:36 -08:00
Graydon Hoare
9d7b26fd40 [NamedLazyMemberLoading] Return empty vector rather than None on no-match. 2017-12-01 16:52:25 -08:00
Graydon Hoare
758a016024 [NamedLazyMemberLoading] Add "loading members" pretty stack trace when deserializing. 2017-12-01 16:52:24 -08:00
Arnold Schwaighofer
eba12a7c3e Revert "Finish and default-enable named lazy member loading" 2017-12-01 07:25:54 -08:00
Graydon Hoare
d3bcdfd8e6 [NamedLazyMemberLoading] Return empty vector rather than None on no-match. 2017-11-30 22:19:37 -08:00
Graydon Hoare
cafb596170 [NamedLazyMemberLoading] Add "loading members" pretty stack trace when deserializing. 2017-11-30 22:01:05 -08:00
Graydon Hoare
412bf0bff1 [NamedLazyMemberLoading] Eat errors properly with llvm::consumeError. 2017-11-30 22:01:05 -08:00
Doug Gregor
b1aa23a222 [Serialization] Allow clients to deserialize all generic signatures.
As a debugging aid, allow clients to deserialize all generic signatures
in a given module file.
2017-11-07 15:17:20 -08:00
Doug Gregor
82e1c98e46 [Serialize] Serialize uniqued generic signatures.
Rather than inlining generic signatures in a half dozen places throughout
the serialization format, serialize (uniqued) generic signatures with their
own GenericSignatureID. Update various layouts (generic function types,
SIL function types, generic environments, extension cross-references) to
use GenericSignatureID.

Shaves ~187k off the size of Swift.swiftmodule.
2017-11-07 13:36:22 -08:00
Graydon Hoare
ed0b43cbce [NamedLazyMemberLoading] Move SerialID to IDC, get extensions working. 2017-11-01 17:35:46 -07:00
Graydon Hoare
7163ebc357 [NamedLazyMemberLoading] Stop scanning DECL_MEMBER_TABLES_BLOCK_ID for abbrevs at first record. 2017-11-01 17:35:46 -07:00
Graydon Hoare
da32bb03ee [NamedLazyMemberLoading] Scan abbrevs out of DECL_MEMBER_TABLES_BLOCK_ID. 2017-11-01 17:35:46 -07:00
Graydon Hoare
f034114f58 [NamedLazyMemberLoading] Implement ModuleFile::loadNamedMembers using tables. 2017-11-01 17:35:46 -07:00
Graydon Hoare
5eca5f5161 [NamedLazyMemberLoading] Write serialized decl member tables. 2017-11-01 17:35:46 -07:00
Graydon Hoare
c78e04cd4f [NamedLazyMemberLoading] Add initial bits of serialized Decl member tables. 2017-11-01 17:35:46 -07:00
Graydon Hoare
7ba241dada [NamedLazyMemberLoading] Rename CLASS_MEMBERS{,_FOR_DYNAMIC_LOOKUP} for clarity 2017-11-01 17:34:56 -07:00
Doug Gregor
fc20debc36 Jump through hoops to avoid adding a new Serialization -> clang::Module dependency. 2017-09-15 14:42:36 -07:00
Doug Gregor
27c8c4a8a1 [Serialization] Rewrite cross-references to private frameworks.
When serializing cross-references to a (private) module that is
re-exported through another (public) module, record the
cross-reference as if the entity were found in named public module.

Finishes rdar://problem/34438586.
2017-09-14 15:09:18 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Jordan Rose
35f8e17e88 [Serialization] Drop extensions whose base type can't be deserialized. (#11323)
This shows up with swift_wrapper typedefs, which get imported into
Swift as structs. If someone makes an extension of a swift_wrapper
type, but the swift_wrapper is only applied in Swift 4 mode, that
extension will break any Swift 3 clients. Recover by just dropping
the extension entirely.

There's still more complexity around extensions---what if a
requirement can't be deserialized? what if something's depending on
the protocol conformance provided by the extension?---but the missing
base type case should be pretty safe. If you can't see the type at
all, things that depend on its conformances are already in trouble.

rdar://problem/33636733
2017-08-03 16:02:16 -07:00
Alex Hoppen
2eb36e41f5 Introduce special name for destructors
This name is not used yet
2017-07-28 10:46:50 +02:00
Jordan Rose
03e1e3b6e0 Lift nested type lookup fast-pathing up to FileUnit.
We use this to avoid circularity issues in serialization; we'd like to
extend that to the Clang importer. This is only necessary because we
can't look up a single member at a time, but it can still fix issues
in the short term.

This commit should have no effect on functionality.
2017-07-13 17:33:14 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Jordan Rose
7e043cf7ce [Serialization] Add extra counters and PrettyStackTraces.
And consolidate two slightly different subclasses of PrettyStackTrace
that mostly did the same thing.
2017-07-05 10:05:40 -07:00
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