Commit Graph

411 Commits

Author SHA1 Message Date
Suyash Srijan
d9c8ae4ce8 [AST] Remove isTypeContext() check from hasValueSemantics() and move the responsibility to the caller 2019-09-17 18:38:01 +01:00
Suyash Srijan
0d66b0c5df [AST] Fix indenation in hasValueSemantics() 2019-09-17 01:24:02 +01:00
David Ungar
5ee5dee2f3 Merge pull request #27171 from davidungar/memberCount-fix
[NameLookup ASTScope] Ensure memberCount includes unparsed members
2019-09-13 16:28:24 -07:00
Sasha Krassovsky
1e414f7fb6 Fix warnings in AST 2019-09-13 09:57:48 -07:00
David Ungar
f184f75bf0 Ensure memberCount includes unparsed members 2019-09-12 14:08:24 -07:00
Suyash Srijan
e8fe05d9bb [AST] hasValueSemantics() should check whether the current context is a type context before proceeding 2019-09-11 01:03:22 +01:00
Suyash Srijan
29ca8b0b38 [AST] Adds 'hasValueSemantics()' to DeclContext and uses 'getSelfTypeInContext()' instead 2019-09-09 21:17:27 +01:00
Robert Widmann
d4bb9a5cfe Define GenericParamListRequest
GenericParamListRequest formalizes the lazy generic parameter list construction pattern we were performing before.
2019-09-06 17:22:30 -07: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
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
b92918889f AST: Don't cache NominalTypeDecl::getDeclaredTypeInContext() 2019-08-22 01:46:50 -04:00
Slava Pestov
2d475a9ee9 AST: Simplify DeclContext::mayContainMembersAccessedByDynamicLookup() 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
Slava Pestov
bfe42f35c3 AST: Fix formatting nit 2019-08-09 19:08:47 -04:00
Alexis Laferrière
cb31d6cb13 AST: Move ResilienceExpansion to a request 2019-08-02 11:33:55 -07:00
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -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
Hamish Knight
b49f02c6b9 [AST][Sema] Add ValueDecl::hasParameterList 2019-05-31 15:53:27 +01:00
Alexis Laferrière
862432fd1b Explicitly request to createGenericParamsIfMissing as it will be lazy
Computing the requirement signature created the generic params as
a side effect. Making getRequirementSignature lazy means that users
of the generic params must make sure they are created before use.
2019-05-08 13:54:03 -07:00
Jordan Rose
a15dec8774 Diagnose typealiases of non-public types in inlinable functions (#23912)
...as a warning, since we didn't check this correctly in Swift 5.
For parseable interfaces, these typealiases won't work at all.
2019-04-10 09:21:44 -07:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04: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
John Holdsworth
dbe99d771e Make Self available to member functions (SE-0068?) (#22863)
* Make Self available to instance member functions (SE-0068?)

* Works for value types and static functions.

* Further experiments with TypeExpr

* Move Self processing off diagnostic path

* diagnostic instead of assertion fail

* TypeExpr of DynamicSelfType now working.

* Update tests for availability of Self

* Cast to Self fixed!

* Self not available as type in classes except for return type

* Could it be this simple?

* Nearly there

* Fix function decls using Self inside methods.

* Fix validation-test/compiler_crashers_2_fixed/0164-sr7989.swift

* Fix of ./validation-test/compiler_crashers_2_fixed/0179-rdar44963974.swift

* "Un-fix" validation-test/compiler_crashers_2_fixed/0164-sr7989.swift

* CHANGELOG entry

* Update CHANGELOG.md

Co-Authored-By: johnno1962 <github@johnholdsworth.com>

* Update CHANGELOG.md
2019-03-15 23:23:19 -04: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
Robert Widmann
944d8d06d7 [SE-0155] Default Arguments in Enum Cases
The bulk of the changes are to SILGenApply.  As we must now evaluate the
payload ArgumentSource to an RValue, we follow the example of subscripts
and lie to the argument emitter.  This evaluates arguments at +1 which
can lead to slightly worse codegen at -Onone.
2019-02-12 10:06:48 -05: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
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
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
Brent Royal-Gordon
2eed5374db Only generate domains for PrintAsObjC-able types
Otherwise we generate a call to String(reflecting:), which correctly handles many things we may not be able to (like private types), and which matches the default implementation of Error._domain.
2018-12-21 15:45:21 -08: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
d63debeb60 Experimental: Extend ClangImporter to import clang modules from DWARF
When debugging Objective-C or C++ code on Darwin, the debug info
collected by dsymutil in the .dSYM bundle is entirely
self-contained. It is possible to debug a program, set breakpoints and
print variables even without having the complete original source code
or a matching SDK available. With Swift, this is currently not the
case. Even though .dSYM bundles contain the binary .swiftmodule for
all Swift modules, any Clang modules that the Swift modules depend on,
still need to be imported from source to even get basic LLDB
functionality to work. If ClangImporter fails to import a Clang
module, effectively the entire Swift module depending on it gets
poisoned.

This patch is addressing this issue by introducing a ModuleLoader that
can ask queries about Clang Decls to LLDB, since LLDB knows how to
reconstruct Clang decls from DWARF and clang -gmodules producxes full
debug info for Clang modules that is embedded into the .dSYM budle.

This initial version does not contain any advanced functionality at
all, it merely produces an empty ModuleDecl. Intertestingly, even this
is a considerable improvement over the status quo. LLDB can now print
Swift-only variables in modules with failing Clang depenecies, and
becuase of fallback mechanisms that were implemented earlier, it can
even display the contents of pure Objective-C objects that are
imported into Swift. C structs obviously don't work yet.

rdar://problem/36032653
2018-12-05 13:54:13 -08:00
Slava Pestov
3e864b26aa AST: @inline(__always) no longer implies @inlinable
Fixes <rdar://problem/44657000>.
2018-11-12 21:00:15 -05:00
Slava Pestov
494201889e AST: Clean up DeclContext::getProtocolSelfType()
The lazy creation of the generic parameter list is not necessary.
2018-10-15 20:34:08 -07:00
Slava Pestov
d2cf701b3b AST: Remove Swift 3 access control checking 2018-10-08 17:21:32 -07:00
Slava Pestov
001a7489ae AST: Simpler implementation of DeclContext::getDeclaredInterfaceType() and getDeclaredTypeInContext() 2018-09-20 01:20:31 -07:00
Slava Pestov
ef82cd760c Sema: Merge bindExtensionDecl() into validateExtension() 2018-09-19 09:47:36 -07:00
Slava Pestov
8801aa67d3 Merge pull request #19133 from slavapestov/access-level-cleanup
Access level cleanup
2018-09-06 16:46:40 -07:00
Xi Ge
24b0eac9a4 Parser: parse members in extension decls incrementally. 2018-09-05 17:00:39 -07:00
Slava Pestov
840c97d794 AST: Remove hasAccess() checks 2018-09-05 16:45:31 -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
Jordan Rose
1958d7aea3 [AST] Add an AccessScope::dump helper (#18756)
And factor an existing getAccessLevelString out into a
generally-available swift::getAccessLevelSpelling.
2018-08-16 10:30:30 -07:00
Doug Gregor
36dc43a97d [AST] Use ProtocolDecl::createGenericParamsIfMissing() where appropriate.
Thanks to @slavapestov for noticing that I hard-coded this, badly.
2018-08-14 08:47:14 -07:00
Doug Gregor
7d3dd4983d [AST] Eliminate two simple uses of (NominalType|Extension)Decl::getInheritedType().
Simple checks for the presence of a protocol in the “inherited” list should only
require a scan through that list + name lookup; use those facilities instead of
recursing through the type checker.
2018-08-06 16:59:40 -07:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00