Commit Graph

3502 Commits

Author SHA1 Message Date
Graydon Hoare
14db5d2285 [AST] Add and use NominalTypeDecl::LookupDirectFlags rather than booleans. 2018-09-21 14:34:26 -07:00
Slava Pestov
001a7489ae AST: Simpler implementation of DeclContext::getDeclaredInterfaceType() and getDeclaredTypeInContext() 2018-09-20 01:20:31 -07:00
Davide Italiano
e1c715c3f8 [AST] Don't lose the parent type in setUnderlyingType. 2018-09-17 15:35:42 -07:00
Davide Italiano
4fed893d74 [AST] Preserve sugar for generic typealiases.
<rdar://problem/43110802>
2018-09-17 15:34:37 -07:00
Doug Gregor
4f544f965a [AST] Kill rarely-used DenseMap from ProtocolDecl.
Put a DenseMap onto the ASTContext’s implementation instead.
2018-09-15 22:04:46 -07:00
Harlan
665db876ea [InterfaceGen] Print bodies of inlinable functions in textual interfaces (#19224)
* Introduce stored inlinable function bodies

* Remove serialization changes

* [InterfaceGen] Print inlinable function bodies

* Clean up a little bit and add test

* Undo changes to InlinableText

* Add serialization and deserialization for inlinable body text

* Allow parser to parse accessor bodies in interfaces

* Fix some tests

* Fix remaining tests

* Add tests for usableFromInline decls

* Add comments

* Clean up function body printing throughout

* Add tests for subscripts

* Remove comment about subscript inlinable text

* Address some comments

* Handle lack of @objc on Linux
2018-09-14 10:23:15 -07:00
Saleem Abdulrasool
4baa775726 Merge pull request #19297 from compnerd/unreachable
litter the tree with `llvm_unreachable`
2018-09-14 09:04:56 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Joe Groff
8665342877 Merge pull request #19151 from jckarter/allocating-convenience-initializers
Dispatch initializers by their allocating entry point
2018-09-13 15:17:34 -07:00
Joe Groff
77a0923ca6 SILGen: Emit convenience initializers as allocating entry points.
And only dispatch designated inits by their allocating entry points. rdar://problem/29634243
2018-09-13 12:31:23 -07:00
Doug Gregor
ac37747c78 [Type checker] Break isObjC/getObjCSelector cycle.
When we're marking a declaration as @objc and recording it in the
class and source-file lookup tables (for @objc collision detection),
don't cause a cycle by querying `getObjCSelector()`. This is somewhat
of a hack: a better long-term approach would be to move the recording
much later, and request'ify the name computation. That'll be follow-up
work.
2018-09-10 17:30:17 -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
Slava Pestov
0503e5a1ac AST: Fix getAccessSemanticsFromContext() for 'modify' coroutines of 'dynamic' properties
Normally we want accessors to perform direct-to-storage access on
their own storage, otherwise we can't ever implement the accessor;
but one special case is the 'modify' coroutine of a 'dynamic'
property, which has to dynamically dispatch to the getter and
setter methods, since they may be replaced at runtime.

First part of <https://bugs.swift.org/browse/SR-8657> /
<rdar://problem/43951732>.
2018-09-06 12:21:16 -07:00
Hamish Knight
42dc4ca342 [GSB] Remove getColonLoc() and getEqualLoc() in favour of getSeparatorLoc()
Most callers aren't concerned about the difference between the two (and those that are are already exercising the appropriate assertions with e.g the use of `getFirstType()`).
2018-09-06 16:40:07 +01:00
Slava Pestov
840c97d794 AST: Remove hasAccess() checks 2018-09-05 16:45:31 -07:00
Slava Pestov
36c25c167a AST: Remove AbstractStorageDecl::configureAccessor() 2018-09-05 16:25:51 -07:00
Slava Pestov
5730d3582b AST: Fix getAccessScopeForFormalAccess() to do the right thing for TopLevelCodeDecls
If we found a declaration in local context, it might be inside a
TopLevelCodeDecl and we're trying to use it from another
TopLevelCodeDecl. In this case, checkAccessUsingAccessScopes() would
produce the wrong result.

I only hit this after removing some hasAccess() checks from code
completion tests.
2018-09-05 16:20:00 -07:00
Slava Pestov
bb2df6e17d AST: Fix ValueDecl::isUsableFromInline() for destructors
We should make the isUsableFromInline() query a proper request.
For now though, given a DestructorDecl it has to check the class
itself, because we don't always propagate the @usableFromInline
attribute from the class to the destructor.
2018-09-05 12:59:05 -07:00
Harlan
dc1bc823e6 [InterfaceGen] Remove #ifs from default arguments (#19075)
* [InterfaceGen] Remove #ifs from default args

This patch removes all #if configs form the bodies of default arguments,
which can contain multiline closures, while preserving the bodies of the
clauses that are active.

This code is generalized and should "just work" for inlinable function
bodies, which will come in a later patch.

* Address review comments

* Fix and test CharSourceRange.overlaps

* Fix CharSourceRange::print to respect half-open ranges
2018-08-31 20:18:48 -07:00
Slava Pestov
53d82f7c49 AST: Remove SubscriptDecl::getIndicesInterfaceType() 2018-08-27 21:15:38 -07:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04:00
Slava Pestov
95c035fe3f Merge pull request #18985 from slavapestov/lazy-self-param
Consolidate code for creating 'self' parameter and only create it when needed
2018-08-25 12:23:32 -07:00
Slava Pestov
c360c82850 AST: Automatically create the 'self' parameter when needed
Parsed declarations would create an untyped 'self' parameter;
synthesized, imported and deserialized declarations would get a
typed one.

In reality the type, if any, depends completely on the properties
of the function in question, so we can just lazily create the
'self' parameter when needed.

If the function already has a type, we give it a type right there;
otherwise, we check if a 'self' was already created when we
compute a function's type and set the type of 'self' then.
2018-08-25 10:44:55 -07:00
Slava Pestov
7f2787eece AST: Lazily compute initializer interface type 2018-08-25 02:58:49 -07:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Doug Gregor
fcfd4c8a8c [Type checker] Introduce a request to evaluate “where” clause requirements.
Introduce a new form of request that produces the ith Requirement of the
where clause of a given entity, which could be a protocol, associated type,
or anything with generic parameters. The requirement can be evaluated
at any type resolution stage; the “interface” type stage will be cached
in the existing RequirementReprs.

Fixes SR-8119 / rdar://problem/41498944.
2018-08-23 09:25:58 -07:00
Doug Gregor
8c58f2629d Merge pull request #18913 from DougGregor/inherited-type-stages
[Type checker] Introduce resolution stages for "inherited type" requests
2018-08-22 19:57:13 -07:00
Doug Gregor
4b80872d48 [Type checker] Introduce stages for inherited type requests.
Extend the inputs to InheritedTypeRequest, SuperclassTypeRequest, and
EnumRawTypeRequest to also take a TypeResolutionStage, describing what
level of type checking is required. The GenericSignatureBuilder relies
only on structural information, while other clients care about the
full interface type.

Only the full interface type will be cached, and the contextual type
(if requested) will depend on that.
2018-08-22 15:29:08 -07:00
Harlan
096e6adb3f [TBDGen] Fix check for global accessors (#18883)
Previously, TBDGen skipped emitting lazy initializers for globals that
appeared in any file with an entry point. This breaks, however on files
that have an NSApplicationMain/UIApplicationMain class in them, where
the entry point is synthesized but top-level globals are not locally
scoped. This change re-uses SILGen's check and only skips variable
declarations that appear at top level in a script mode file.

Resolves rdar://43549749
2018-08-21 18:22:59 -07:00
Slava Pestov
4069fa68db Sema: Lift restriction on @objc categories of concrete subclasses of generic classes
In-place initialization means the class has a symbol we can reference
from the category, so there's nothing to do on the IRGen side.

For JIT mode, we just need to realize the class metadata by calling an
accessor instead of directly referencing the symbol though.
2018-08-20 16:23:07 -07:00
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Slava Pestov
a54251074c AST: ExtInfo just wraps an unsigned integer, no need to pass it by reference 2018-08-17 19:27:43 -04: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
Harlan
9b29e8dc91 Merge pull request #18454 from harlanhaskins/requests-ive-had-a-few
Remove SimpleRequest::breakCycle
2018-08-16 11:03:22 -07:00
Jordan Rose
53e0fad181 Assume it's okay for decls in a cross-module extension to be public (#18741)
...even if the base decl isn't.

This isn't normally possible, but it can come up when an imported type
is import-as-member'd onto an internal Swift declaration. This isn't
even such an unreasonable thing to do, since internal Swift
declarations are exposed in the generated header for an app.

rdar://problem/43312660
2018-08-16 10:06:54 -07:00
John McCall
5d8252b8c6 Pass around whether storage is mutable as an enum instead of a bool. 2018-08-16 02:13:54 -04:00
Harlan Haskins
5a6985f39e Remove SimpleRequest::breakCycle
This patch removes the need for Request objects to provide a default
cycle-breaking value, instead opting to return llvm::Expected so clients
must handle a cycle failure explicitly.

Currently, all clients do the 'default' behavior, but this opens the
possibility for future requests to handle failures explicitly.
2018-08-15 11:01:12 -07:00
Jordan Rose
a5f84ec2f6 [AST] Drop redundant ProtocolDecl::TrailingWhereClause
There's already a field for this in GenericContext, which ProtocolDecl
indirectly inherits. Protocols may have slightly different treatment
of their where-clauses, but not enough to justify a separate field.

No functionality change.
2018-08-14 23:17:57 -07:00
Doug Gregor
6384d080b1 Merge pull request #18539 from DougGregor/unqualified-lookup-via-decls
[Name lookup] Use decl-based name lookup more regularly
2018-08-14 05:18:59 -04:00
Slava Pestov
d31d35a788 AST: Remove a few usages of TypeBase::getInOutObjectType() 2018-08-13 21:13:10 -07:00
Doug Gregor
09c46ad101 [AST] Eliminate the unused by ComputingInheritedProtocols in ProtocolDecl. 2018-08-13 19:03:35 -07:00
Slava Pestov
f44ff38db4 AST: Remove unused ParamDecl::getParameterFlags() 2018-08-11 03:29:16 -07:00
Slava Pestov
d48c8ab67a AST: Convert computeType() methods to use ParameterList::getParams()
This is mostly NFC; the output of the api-digester test changed because
the interface type of an enum element now has parentheses around the
'Self' parameter type. This is more consistent with everything else
(and in the future, all function types will have "parentheses").
2018-08-11 03:29:16 -07:00
Robert Widmann
fe8873a5d0 Merge pull request #18641 from hamishknight/objc-subscript-cleanup
[AST] NFC: Remove ObjCSubscriptKind::None
2018-08-10 18:43:13 -07:00
Hamish Knight
523992c848 [AST] NFC: Remove ObjCSubscriptKind::None
This enum case, and associated diagnostic hasn't been used since id-as-Any.
2018-08-10 23:10:52 +01:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00
Slava Pestov
f11b6200b1 AST: Set invalid bit in ValueDecl::setInterfaceType()
The verifier asserts that declarations whose interface type contains an error
are invalid, so let's just mark them invalid when we set the interface type,
instead of needlessly duplicating this logic all over the declaration checker.
2018-08-10 13:33:12 -07:00
Jordan Rose
0e10f89964 Preserve default argument text through serialization (#18579)
This allows us to dump it in the generated interface, though it's
still not syntax-highlighted. This is necessary for textual module
interfaces, but it's also just a longstanding request for Xcode's
"Generated Interface" / "Jump to Definition" feature.

rdar://problem/18675831
2018-08-09 11:06:22 -07:00
John McCall
ebed6afd59 Make it easy to iterate over all the opaque accessors of a declaration. 2018-08-08 22:44:47 -04:00
Slava Pestov
3ef0991826 AST: Remove TypeBase::getWithoutImmediateLabel()
Again, it appears that looking through one-element tuples is
no longer a thing we need to do.
2018-08-08 10:18:52 -07:00