Commit Graph

194 Commits

Author SHA1 Message Date
Jordan Rose
c506747a9c [Serialization] Drop inherited conformances on classes (#23347)
These can be recreated if needed in a client library. To do this, I've
added a new ConformanceLookupKind::NonInherited, which can also be
used elsewhere in the project where we're already filtering out
inherited conformances some other way.

Note that this doesn't drop inherited conformances from the entire
serialized interface, just from the list that a class explicitly
declares. They still get referenced sometimes.

rdar://problem/50541451 and possibly others
2019-05-13 13:41:10 -07:00
Doug Gregor
d31ef61a28 Eliminate "sorting" of DeclContext-local protocols / conformances.
Sorting of DeclContext-local protocols and conformances shouldn't ever
be necessary, because the underlying data structures that produce
these lists should be deterministic. Sorting can hide any
non-determinism, so stop doing it and we can address the underlying
nondeterminism.
2019-02-15 14:16:48 -08:00
David Ungar
b7f3697387 Merge pull request #21907 from davidungar/A-defaultTypeReq-1-15-10
Use Request to getDefaultType & move cache to SourceFile.
2019-01-22 21:39:31 -08:00
David Ungar
ec1797659e Cosmetics. 2019-01-20 23:38:47 -08:00
David Ungar
fe999d9a47 Format. 2019-01-20 22:47:40 -08:00
David Ungar
ce17240781 Don’t output newline for simple_display of DeclContext. And clean up simple_display. 2019-01-20 22:46:13 -08:00
David Ungar
3573eb4f7c Don’t print enclosing contexts for simple_display. 2019-01-20 18:54:58 -08:00
David Ungar
b3d4ca6ee0 FIx SFINAE 2019-01-20 14:11:46 -08:00
David Ungar
15c5942077 Minor improvement 2019-01-18 17:09:16 -08:00
David Ungar
cb340af0f2 Format 2019-01-18 16:39:19 -08:00
David Ungar
d1fe7ca9a9 First cut at removing DeclContextWrapper 2019-01-18 16:38:46 -08:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Slava Pestov
a90d8a81c6 AST: Remove DeclContext::getGenericParamsOfContext() 2018-12-11 23:55:41 -05:00
Slava Pestov
544e0a02d5 AST: Don't link together GenericParamLists of nested generic types
GenericParamList::OuterParameters would mirror the nesting structure
of generic DeclContexts. This resulted in redundant code and caused
unnecessary complications for extensions and protocols, whose
GenericParamLists are constructed after parse time.

Instead, lets only use OuterParameters to link together the multiple
parameter lists of a single extension, or parameter lists in SIL
functions.
2018-12-11 23:55:41 -05:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Slava Pestov
564695d9bf AST: Remove DeclContext::isExtensionContext()
It's identical in every way to isa<ExtensionDecl>(), so
make code less confusing by only having one way of doing
that check.
2018-11-07 17:34:56 -05:00
Slava Pestov
673e167fac AST: Refactor lookupQualified() to take a vector of NominalTypeDecls
Previously you could pass in a vector of TypeDecls and it handled
module and AnyObject lookup for you. The AnyObject case was never
used and the module was was only needed in one place, so clean
things up to make them more direct here.
2018-10-12 03:06:52 -07:00
Xi Ge
24b0eac9a4 Parser: parse members in extension decls incrementally. 2018-09-05 17:00:39 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Doug Gregor
8a81ea45fb [Name lookup] Teach lookupQualified() to accept TypeDecls.
Rather than require clients of lookupQualified() to resolve
their type declarations to nominal type declarations (and
separately cope with modules), have lookupQualified() accept
an array of TypeDecls and handle the resolution to nominal
type declarations (where it can look directly) and module
declarations, combining the results.
2018-08-14 14:40:51 -07:00
Doug Gregor
2860557a77 [Name lookup] Use the declaration-based lookupQualified() where it’s easy.
Switch a number of callers of the Type-based lookupQualified() over to
the newer (and preferred) declaration-based lookupQualified(). These are
the easy ones; NFC.
2018-07-31 10:14:44 -07:00
Doug Gregor
48fb22716c [Name lookup] Factor out core “qualified lookup in a set of TypeDecls”.
Make the core lookupQualified() API accept an array of TypeDecls in which
it should look, rather than looking into a Type. This is in preparation
for breaking more type-checker dependencies in the name lookup code.
2018-07-27 23:22:01 -07:00
Doug Gregor
081a6af213 [Name lookup] Factor out qualified lookup into a module.
The “name lookup into a module” lookup is completely different from
performing name lookup into a type. Factor it out into its own
utility routine.
2018-07-27 21:50:44 -07:00
Doug Gregor
1cf6ef1914 [Name lookup] Factor out AnyObject lookup.
AnyObject lookup is a completely separate path from normal qualified
lookup, so separate it out and pull out the common bits.
2018-07-27 21:50:44 -07:00
Jordan Rose
07e56a4351 Sprinkle LLVM_READONLY on some potentially recursive accessors (#17913)
I picked accessors that not only return the same result every time,
but also do no interesting validation work with possible side effects.
We have a lot more accessors that return the same result but also
force a bunch of things to be loaded or diagnostics to be emitted, and
I didn't want to change the behavior of any of those.

No intended functionality change; this is just supposed to be a small
optimization hint.
2018-07-12 14:16:29 -07:00
Rintaro Ishizaki
29ae088723 [AST] Remove dead declaration of DeclContext::getCommonParentContext (#16855) 2018-05-26 10:05:37 +09:00
David Zarzycki
d3b004e423 [AST] NFC/perf: Bypass getContextKind() in more places
Many clients don't care about non-Decl DeclContexts, so there isn't any
need or reason to fully demux DeclContexts into precise DeclContextKinds.

This change improves the Swift.o optimized/no-assert build performance by
1.97% on Intel's Skylake processor on Linux.
2018-02-28 13:23:58 -05: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
David Zarzycki
f0c08a3010 [AST] NFC: Add Decl::getAsGenericContext()
Adding getAsGenericContext() cleans up some code, and improves the
Swift.swiftmodule build time by almost half a percent on LLVM
top-of-tree and with a simulated fix for LLVM PR35909.
2018-01-14 09:34:27 -05:00
David Zarzycki
887471d613 [AST] NFC: Feedback from Jordan; plus micro-optimizations 2018-01-08 17:01:52 -05:00
David Zarzycki
49ce2c3f35 [AST] NFC: Feedback from John; plus micro-optimization 2018-01-08 13:41:55 -05:00
David Zarzycki
0e1251648c [AST] NFC: DeclContext micro-optimizations 2018-01-08 13:33:49 -05:00
David Zarzycki
e9b643026b [AST] NFC: Stop over aligning DeclContexts
DeclContexts as they exist today are "over aligned" when compared to
their natural alignment boundary and therefore they can easily cause
adjacent padding when dropped into the middle of objects via C++
inheritance, or when the clang importer prefaces Swift AST allocations
with a pointer to the corresponding clang AST node.

With this change, we move DeclContexts to the front of the memory layout
of AST nodes. This allows us to restore natural alignment, save memory,
and as a side effect: more easily avoid "over alignment" in the future
because DeclContexts now only need to directly track which AST node
hierarchy they're associated with, not specific AST nodes within each
hierarchy.

Finally, as a word of caution, after this change one can no longer
assume that AST nodes safely convert back and forth with "void*". For
example, WitnessTableEntry needed fixing with this change.
2018-01-08 12:21:14 -05:00
David Zarzycki
7bede89a9b [AST] NFC: Repack misc IterableDeclContext bits 2017-12-10 20:38:01 -05:00
Graydon Hoare
c6ce01280d [NamedLazyMemberLoading] Handle partial population from extensions better. 2017-12-02 02:19:29 -08:00
Graydon Hoare
7a9bc26fd9 [NamedLazyMemberLoading] Handle nominals with mix of added/lazy members. 2017-12-01 16:52:26 -08:00
Graydon Hoare
464dc1bcc1 [NamedLazyMemberLoading] Use per-IDC recursion-breaking flag, not sentinel.
The empty sentinel in the lookup table caused recursion-breaking to bottom
out in slightly different order than the old eager code, making certain
order-sensitive tests fail.
2017-12-01 16:52:25 -08:00
Arnold Schwaighofer
eba12a7c3e Revert "Finish and default-enable named lazy member loading" 2017-12-01 07:25:54 -08:00
Graydon Hoare
9e1859469c [NamedLazyMemberLoading] Use per-IDC recursion-breaking flag, not sentinel.
The empty sentinel in the lookup table caused recursion-breaking to bottom
out in slightly different order than the old eager code, making certain
order-sensitive tests fail.
2017-11-30 22:18:25 -08:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Alex Hoppen
746bfc6d59 [Refactoring] Add refactoring action to move type members to extension (#12795)
This implements SR-6297.
2017-11-09 11:08:34 -08:00
Graydon Hoare
ed0b43cbce [NamedLazyMemberLoading] Move SerialID to IDC, get extensions working. 2017-11-01 17:35:46 -07:00
Tony Allevato
f2c434a038 Merge branch 'master' into synthesize-equatable-hashable 2017-09-21 22:54:36 -07:00
Slava Pestov
2fe8fea875 AST: Remove DeclContext::getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Tony Allevato
6dfa87d0ba [AST] Add DeclContext.getAsStructOrStructExtensionContext 2017-08-08 18:20:58 -07:00
Doug Gregor
ea20a1d137 [AST] Add DeclContext::get(Syntactic|Semantic)Depth.
Utilities functions used when comparing declaration contexts. Only the syntactic form is currently used (for the owning DC of a generic environment).
2017-06-01 08:25:42 -07:00
Doug Gregor
f792aeaf1a [AST] Teach the AST verifier not to deserialize generic environments.
The AST verifier was causing deserialization of generic environments,
which slows things down considerably and affects our ability to test
for laziness in deserialization. Prevent it from doing so---and only
do the extra checkig if something else deserialized the generic
environment already.

... except there are some cases where it happens through means that
are harder to control (e.g., the AST walker for patterns) that need
more thought.
2017-05-16 11:03:15 -07:00
Slava Pestov
2fe863266c AST: Fix crashes when name lookup finds declarations outside of a protocol or extension that's nested in another type
When performing a name lookup from inside of a protocol
or extension, skip directly to the source file context
when we are done visiting the protocol or extension.

Otherwise, if we have invalid code where the protocol
or extension is nested inside another type, we might
find a member whose type contains generic parameters
of the outer type; these parameters will not resolve,
since we do not model protocols or extensions nested
inside generic contexts (yet?).

This supercedes an earlier workaround for a similar
issue; the new workaround fixes more crashes.

This is needed to avoid crasher regressions with an
upcoming patch.
2017-05-07 03:01:47 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
2555135bbd AST: Remove DeclContext::isValidGenericContext()
This is intended to have no functional effect, but there was a
minor change to a diagnostic in invalid code in the tests for the
unfinished ASTScope code; I hope I didn't break anything more
fundamental there.
2017-01-04 01:08:28 -08:00