Commit Graph

311 Commits

Author SHA1 Message Date
Jordan Rose
7b0d081965 Remove IteratorRange in favor of llvm::iterator_range
Now that llvm::iterator_range has 'empty', there's not enough reason to
keep our own version of it in the Swift repo.

No functionality change.
2019-10-08 11:23:28 -07:00
Robert Widmann
75670c1727 Merge pull request #27436 from CodaFi/signed-sealed-delivered
[NFC] Adopt TypeBase-isms for GenericSignature
2019-09-30 15:50:42 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
David Ungar
ea81fdc7d8 Merge pull request #27313 from davidungar/generic-request-or-extended-nominal-assertion
Fail early if getExtendedNominal is called before extension has been bound.
2019-09-30 08:37:33 -07:00
David Ungar
4bc4030338 Catch failures earlier caused by premature requests for extended nominal 2019-09-28 15:19:32 -07:00
Harlan Haskins
b904133c42 [Modules] Add flag to skip non-inlinable function bodies
This flag, currently staged in as `-experimental-skip-non-inlinable-function-bodies`, will cause the typechecker to skip typechecking bodies of functions that will not be serialized in the resulting `.swiftmodule`. This patch also includes a SIL verifier that ensures that we don’t accidentally include a body that we should have skipped.

There is still some work left to make sure the emitted .swiftmodule is exactly the same as what’s emitted without the flag, which is what’s causing the benchmark noise above. I’ll be committing follow-up patches to address those, but for now I’m going to land the implementation behind a flag.
2019-09-26 10:40:11 -07:00
Suyash Srijan
c99facb48b Merge pull request #27057 from theblixguy/unrevert/SR-11298
Unrevert "[Sema] Setter has incorrect mutating-ness inside class-constrained protocol extension"
2019-09-18 01:15:07 +01:00
David Ungar
f184f75bf0 Ensure memberCount includes unparsed members 2019-09-12 14:08:24 -07:00
Suyash Srijan
29ca8b0b38 [AST] Adds 'hasValueSemantics()' to DeclContext and uses 'getSelfTypeInContext()' instead 2019-09-09 21:17:27 +01:00
Slava Pestov
0405ab5ffc AST: GenericContexts store a GenericSignature instead of a GenericEnvironment
This eliminates the entire 'lazy generic environment' concept;
essentially, all generic environments are now lazy, and since
each signature has exactly one environment, their construction
no longer needs to be co-ordinated with deserialization.
2019-09-06 17:16:04 -04:00
Doug Gregor
11969847c4 Simplify lazy parsing of nominal and extension members.
Lazy parsing for the members of nominal types and extensions depends
only on information already present in
`IterableDeclContext`. Eliminate the use of PersistentParserState as
an intermediary and have the member-parsing request construct a new
`Parser` instance itself to handle parsing. Make this possible even
for ill-formed nominal types/extensions to simplify the code path.

Eliminate `LazyMemberParser` and all of its uses, because it was only
present for lazy member parsing, which no longer needs it.
2019-08-30 08:29:43 -07:00
Doug Gregor
d8f7c9e72c [Parser] Introduce a request for parsing type and extension members.
Ensure that lazy parsing of the members of nominal type definitions
and extensions is handled through a request. Most of the effort here
is in establishing a new request zone for parser requests.
2019-08-28 21:39:56 -07:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
2019-08-19 23:00:57 -04:00
Slava Pestov
2f33356083 AST: Optimize construction of the AnyObject dispatch table
Instead of visiting all members of all types and extensions, bail out
early if the type is not a class or protocol, or the extension is not
extending a class. This means we don't visit structs, enums or
protocol extensions at all, which will avoid delayed parsing.

Also, we were evaluating isObjC() on each member, which is an expensive
operation; if the member does not have an explicit @objc we would still
have to check if it overrides an @objc method or witnesses an @objc
protocol requirement.

Since most members are not ever found by dynamic lookup, this is wasted
work. Instead, let's rely on AnyObject lookup filtering non-@objc
members at the call site, which it was already doing anyway.
2019-08-12 17:55:44 -04:00
Slava Pestov
94149db4ec Parse: Record which delayed type and extension bodies possibly contain operators and classes
To properly delay parsing type and extension bodies we need to know
which ones might contain nested operator and class definitions, since
they must be known upfront when building the global operator lookup
and AnyObject dispatch lookup tables, respectively.

To guess if the type contains operator definitions, we look for the
'func' keyword followed by an operator token.

To guess if the type contains class definitions, we look for the
'class' keyword.

For now, this information is recorded but not used. Subsequent commits
will make use of this information to delay parsing in more cases.
2019-08-12 17:15:51 -04:00
David Ungar
dee833ad39 Change explicit to localizable. 2019-07-25 09:46:47 -07:00
Doug Gregor
052068edb8 [Request-evaluator] Provide defaults for diagnoseCycle/noteCycleStep.
Introduce some template metaprogramming infrastructure to retrieve the
"nearest" source location to the inputs of a request, and use that to
provide default diagnoseCycle and noteCycleStep implementations. This
will help remove a bunch of boilerplate from new requests.
2019-07-10 17:25:51 -07:00
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