Commit Graph

1923 Commits

Author SHA1 Message Date
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Pavel Yaskevich
53417f4aba [AST] Propagate @autoclosure flag to parameter decl and type flags 2018-11-10 11:59:28 -08:00
Slava Pestov
9c50867370 Move RemoteAST's RemoteASTTypeBuilder to lib/AST/ASTDemangler.cpp 2018-11-02 18:19:40 -04:00
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00
John McCall
4ea01224fd [NFC] Improve the interfaces for integer widths and parsing integers 2018-10-31 15:49:40 -04:00
Doug Gregor
599e07e5d9 [Type checker] Keep the type checker alive as long as the ASTContext is.
It is possible for the SIL optimizers, IRGen, etc. to request information
from the AST that only the type checker can provide, but the type checker
is typically torn down after the “type checking” phase. This can lead to
various crashes late in the compilation cycle.

Keep the type checker instance around as long as the ASTContext is alive
or until someone asks for it to be destroyed.

Fixes SR-285 / rdar://problem/23677338.
2018-10-10 16:44:42 -07:00
Joe Groff
5414747873 Merge pull request #19613 from jckarter/enable-consuming
Make `__consuming` meaningful for code generation.
2018-10-01 10:06:29 -07:00
Jordan Rose
36ca10f6f2 Merge pull request #19609 from jrose-apple/your-code-is-programmed-not-to-love-me-but-you-cant-pretend
[Stats] Track NumASTBytesAllocated continuously
2018-09-28 20:03:22 -07:00
Joe Groff
9c5432c0dd Make __consuming meaningful for code generation.
Previously, the `__consuming` decl modifier failed to get propagated to the value ownership of the
method's `self` parameter, causing it to effectively be a no-op. Fix this, and address some of the
downstream issues this exposes:

- `coerceCallArguments` in the type checker failing to handle the single `__owned` parameter case
- Various places in SILGen and optimizer passes that made inappropriate assertions that `self`
  was always passed guaranteed
2018-09-28 14:09:59 -07:00
Jordan Rose
91d1abf8b0 [Stats] Track NumASTBytesAllocated continuously
...so it can be used with flamegraphs.
2018-09-28 13:43:36 -07:00
Slava Pestov
ce770cdf4e AST: Introduce GenericSignature::forEachParam()
This replaces the inefficient pattern:

  for (auto param : sig->getGenericParams()) {
    if (sig->isCanonicalTypeInContext(param)) {
      ...
    } else {
      ...
    }
  }
2018-09-27 21:28:36 -07:00
Slava Pestov
3b60ae153d AST: Rename AnyFunctionType::Param::getType() to getOldType() 2018-09-26 11:05:23 -07:00
Slava Pestov
4975f3a15f AST: Remove FunctionType::getInput() 2018-09-26 11:05:23 -07:00
Slava Pestov
3554da1a18 AST: Redo FunctionType canonicalization and profiling
Use the parameter list instead of the input type.
2018-09-26 11:05:23 -07:00
Arnold Schwaighofer
7ba31e36e6 SIL: Profile the witnesMethodConformance as part of the SILFunctionType
We use to return a SILFunctionType with a wrong witness method protocol
conformance e.g when there were base protocols.

rdar://40149340
2018-09-21 13:23:27 -07:00
Doug Gregor
32fd274f5e Merge pull request #19391 from DougGregor/assoc-conformance-default-witnesses
[ABI] Associated conformance defaults
2018-09-19 13:15:46 -07:00
Doug Gregor
fde7eb5f3d [AST] Record default associated conformance witnesses directly.
Referencing associated conformance witnesses via the index of the
requirement in the requirement signature is inconvenient. Reference
them by CanType/ProtocolDecl* instead.
2018-09-19 10:53:46 -07:00
Jordan Rose
e1901fdad1 Replace explicit 'delete' calls with std::unique_ptr in AST (#19366) 2018-09-18 19:41:11 -07:00
Doug Gregor
89f3da6d28 [Sema] Start recording default associated conformances.
When forming the default witness table for a resilient protocol, look
for default associated conformances as well. These are identified by
associated conformance requirements whose root associated type has a
default type. For such requirements, we look for a conformance and
record it as a default associated conformance.

Emit a warning in cases where we don't find such a conformance,
because the associated type and conformance *may* have been added
with the intent of being resilient, and we can't know. This warning
might be a terrible idea, but it is only enabled under
-enable-resilience (which itself is hidden) and fires in one only
place in the standard library (which seems legitimate), so we'll try
it for now.
2018-09-18 15:49:43 -07:00
Doug Gregor
2ef9363bd1 [ABI] Add default associated type witnesses to resilient protocols.
When an associated type witness has a default, record that as part of
the protocol and emit a default associated type metadata accessor into the
default witness table. This allows a defaulted associated type to be
added to a protocol resiliently.

This is another part of rdar://problem/44167982, but it’s still very
limiting because the new associated type cannot have any conformances.
2018-09-15 22:04:46 -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
Jordan Rose
ac4a92a968 Merge pull request #19292 from jrose-apple/get-out-the-map
Minor improvements to the use of StringMap/StringSet
2018-09-14 10:52:59 -07:00
Jordan Rose
245b06b832 Use llvm::StringSet instead of StringMap where appropriate
That is, where we aren't using the value for anything.

No functionality change.
2018-09-13 15:15:24 -07:00
Xi Ge
033732b1e5 ASTVerifier: avoid verifying IterableDeclContext if it has unparsed members. 2018-09-12 14:11:41 -07:00
Xi Ge
e0c1fea21b Fix an unused variable warning in no-assertion build. 2018-09-11 16:30:57 -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
Xi Ge
24b0eac9a4 Parser: parse members in extension decls incrementally. 2018-09-05 17:00:39 -07:00
Slava Pestov
542ed54c79 Merge pull request #19042 from slavapestov/match-call-arguments
Refactor matchCallArguments() to take arrays of AnyFunctionType::Param instead of argument tuples
2018-08-29 17:16:05 -07:00
Xi Ge
3510f082e3 Merge pull request #19035 from nkcsgexi/refactor-graph-viz
[Evaluator] Refactor evaluator's GraphViz output to the destructor of the ASTContext. NFC
2018-08-29 10:49:54 -07:00
Slava Pestov
d4ee7138c4 AST: Introduce AnyFunctionType::relabelParams() 2018-08-28 22:36:02 -07:00
Xi Ge
ce29c64964 [Evaluator] Refactor evaluator's GraphViz output to the destructor of the evaluator. NFC
This allows us to output dependency-graph while using the compiler in
other tools, like swift-ide-test, sourcekitd-test, etc.
2018-08-28 18:16:44 -07:00
Slava Pestov
05c557a488 AST: Remove {Generic,}FunctionType::getOld() 2018-08-28 14:40:56 -07:00
Slava Pestov
b7f1a40e52 AST: Stop using FunctionType::getOld() in AnyFunctionType::withExtInfo() 2018-08-28 14:40:56 -07:00
Slava Pestov
2e5b398180 Merge pull request #18990 from slavapestov/func-type-arena-fix
AST: Allocate FunctionTypes containing type variables in the solver arena
2018-08-28 00:25:47 -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
dbf6c77623 AST: Allocate FunctionTypes containing type variables in the solver arena 2018-08-25 23:06:48 -07:00
John McCall
768450dd0e Add a convenience getter for a Param's parameter type; NFC. 2018-08-26 00:23:16 -04:00
Alex Hoppen
66374a14ea [libSyntax] Make RawSyntax nodes hold a strong reference to their arena
This allows an elegant design in which we can still allocate RawSyntax
nodes using a bump allocator but are able to automatically free that
buffer once the last RawSyntax node within that buffer is freed.

This also resolves a memory leak of RawSyntax nodes that was caused by
ParserUnit not freeing its underlying ASTContext.
2018-08-24 08:39:54 -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
Slava Pestov
1bbea4af55 AST: Clean up AnyFunctionType::Param API a bit 2018-08-17 19:26:40 -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
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
Slava Pestov
80a7ae100b SIL: Treat __shared and __owned just like inout when lowering function types
Even with an opaque abstraction pattern, we must explode a
parameter list containing __shared and __owned elements.

Otherwise, we produce invalid lowered SIL types.

Note that this is already an issue, because the stdlib has a
handful of declarations using __owned.
2018-08-12 01:09:45 -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
Doug Gregor
9eb9898321 Merge pull request #18364 from DougGregor/name-lookup-requests
[Name lookup] Introduce requests for several name lookup operations.
2018-07-31 13:23:38 -07:00
Doug Gregor
d07fa5ab69 Switch many callers of ClassDecl::getSuperclass() to ClassDecl::getSuperclassDecl().
ClassDecl::getSuperclass() produces a complete interface type describing the
superclass of a class, including any generic arguments (for a generic type).
Most callers only need the referenced ClassDecl, which is (now) cheaper
to compute: switch those callers over to ClassDecl::getSuperclassDecl().

Fixes an existing test for SR-5993.
2018-07-31 10:14:44 -07:00
Doug Gregor
cb7c2b4fce [Name lookup] Introduce requests for several name lookup operations.
Introduce three new requests for name lookup operations that avoid performing
type checking/semantic analysis. They work using syntactic information
(e.g., TypeReprs) and AST-level name lookup operations that will (eventually)
avoid and calls back into type checking. The new requests are:

* Retrieve the superclass declaration of a protocol or class declaration. Use
this request for ClassDecl::getSuperclassDecl() and
ProtocolDecl::getSuperclassDecl().
* Retrieve the types “directly referenced” by a particular location in
an inheritance clause. This query is based on looking at the TypeReprs
and performing fairly-minimal lookup, so it does not involve any Type
computations.
* Retrieve the types “directly referenced” by the underlying type of
a typealias. This query allows us to desugar a typealias without forming
a type.

Along with these is a core operation to transform a set of TypeDecl*s
into a set of NominalTypeDecl*s, looking through typealiases, and
without involving Type at all. The superclass-decl request does this
to find a ClassDecl; other requests will eventually do this to (e.g.)
find all of the protocols mentioned in an inheritance clause.
2018-07-31 10:14:44 -07:00
Slava Pestov
06f6809061 AST: Fix recursive properties of GenericFunctionType 2018-07-31 00:38:09 -07:00
Slava Pestov
53bcca2542 AST: Fix an unused variable warning 2018-07-30 18:38:55 -07:00