Commit Graph

2036 Commits

Author SHA1 Message Date
Robert Widmann
c5a27efe56 Merge pull request #27351 from CodaFi/not-a-good-start-boris
Requestify Operator Precedence Groups and Precedence Group Lookup
2019-09-25 13:30:18 -07:00
Adrian Prantl
ff22da20c3 Debug Info: Encode let-bindings using DW_TAG_const_type.
This allows the debugger to distinguish constant "let" values from
mutable "var" variables.

rdar://problem/16042546
2019-09-25 08:51:05 -07:00
Slava Pestov
98aa47c078 Merge pull request #27357 from slavapestov/circular-validation-cleanups
Circular validation cleanups, part 1
2019-09-25 09:40:03 -04:00
Doug Gregor
9b20012ee1 Merge pull request #27322 from DougGregor/property-wrapper-composition-di
[DI] Support definite initialization for composed property wrappers.
2019-09-24 21:22:43 -07:00
Slava Pestov
040be292e5 AST: TypeDecl::getDeclaredInterfaceType() always returns a non-empty Type
In the case of circular type aliases, this now returns ErrorType
instead of Type().
2019-09-24 22:38:59 -04:00
Slava Pestov
645fc20df7 AST: TypeAliasDecl::get{Structural,Underlying}Type() always return non-empty Type
Return an ErrorType on circularity instead of Type().
2019-09-24 22:38:59 -04:00
Robert Widmann
5964ce47b0 Use OperatorPrecedenceGroupRequest to clean up InfixOperatorDecl a bit 2019-09-24 17:45:50 -07:00
Slava Pestov
6a9b566517 AST: Fix parent type of protocol type alias types
To preserve correct behavior under substitution, the parent type
of a protocol type alias must be the 'Self' generic parameter and
not the protocol's existential type.
2019-09-24 17:39:53 -04:00
Doug Gregor
ab5d161c05 [SILGen] Separate the initialization of a wrapped property from a wrapped value
Teach SILGen to emit a separate SIL function to capture the
initialization of the backing storage type for a wrapped property
based on the wrapped value. This eliminates manual code expansion at
every use site.
2019-09-24 09:11:53 -07:00
Robert Widmann
ed18f47d05 Port getInterfaceType() patterns in libAST 2019-09-23 16:49:09 -07:00
Robert Widmann
8d9629ec43 Requestify getInterfaceType() in Name Only
Make getInterfaceType() call validateDecl on behalf of its clients.  In effect, this makes the interface type behave like a request.  It also means that its clients no longer need to perform a number of undesirable anti-patterns in order to sidestep the bizarre API contract validateDecl has at the moment

In particular, the following things are no longer necessary:

- Checking for a missing interface type then validating
- Validating the interface type then retrieving it
- Validating the interface type then retrieving a derived value

These anti-patterns will be removed in follow-up commits
2019-09-23 16:48:35 -07:00
Robert Widmann
b135928125 Drop CheckingWithValidSignature from the validation state machine
Now that the generic signature is computable on demand, this predicate is doubly useless.  All of the callers intended to ask "hasInterfaceType" anyways.
2019-09-20 22:22:49 -07:00
Robert Widmann
e7fccde40c Directly detect the cyclic case while computing conditional requirement
The general class of cycle here is when validation asks for the generic signature which triggers requirement checking which forces us to ask for the generic signature of the extension again.  We should look into a more principled solution.

See rdar://55263708
2019-09-20 20:38:38 -07:00
Robert Widmann
38bde33067 Merge pull request #27172 from CodaFi/aliasing-artifacts-and-noise-reduction-techniques
Kill validateDeclForNameLookup Harder
2019-09-18 15:00:51 -07:00
Slava Pestov
67c668200a Sema: Compute and store captures for default argument expressions 2019-09-18 14:26:01 -04:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -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
Suyash Srijan
d9c8ae4ce8 [AST] Remove isTypeContext() check from hasValueSemantics() and move the responsibility to the caller 2019-09-17 18:38:01 +01:00
Robert Widmann
c254f4d2f8 Setting the underlying type should set the structural type too
This avoids making the structural type dependent on whether the interface type has been computed and neatly avoids special-casing non-parsed declarations which set their underlying type up front.
2019-09-17 08:49:03 -07:00
Robert Widmann
5e34169aca Separate computing interface types and underlying types
Computing the interface type of a typealias used to push validation forward and recompute the interface type on the fly.  This was fragile and inconsistent with the way interface types are computed in the rest of the decls.  Separate these two notions, and plumb through explicit interface type computations with the same "computeType" idiom.  This will better allow us to identify the places where we have to force an interface type computation.

Also remove access to the underlying type loc.  It's now just a cache location the underlying type request will use.  Push a type repr accessor to the places that need it, and push the underlying type accessor for everywhere else.  Getting the structural type is still preferred for pre-validated computations.

This required the resetting of a number of places where we were - in many cases tacitly - asking the question "does the interface type exist".  This enables the removal of validateDeclForNameLookup
2019-09-17 08:20:55 -07:00
Robert Widmann
d097c8186d Requestify generic signatures
Define a request that provides the generic signature for a given generic context.  This unblocks a ton of cleanup and will allow us to remove validateExtension, validateDeclForNameLookup, and a lot of the surrounding infrastructure.

Being more honest about which declarations actually have a generic signature computed has naturally introduced more cycles in requests.  hasComputedGenericSignature() now acts as a recursion breaker.  In the future, we should purge any uses of this accessor that specifically head-off cycles as the cycle itself is probably part of a larger structural problem.
2019-09-16 11:41:53 -07:00
Sasha Krassovsky
1e414f7fb6 Fix warnings in AST 2019-09-13 09:57:48 -07:00
Suyash Srijan
29ca8b0b38 [AST] Adds 'hasValueSemantics()' to DeclContext and uses 'getSelfTypeInContext()' instead 2019-09-09 21:17:27 +01:00
Suyash Srijan
f676dde802 [Typechecker] Use a 'is Self class-bound?' check instead 2019-09-09 19:41:51 +01:00
Robert Widmann
edf2e3ba77 Merge pull request #27048 from CodaFi/chicken-param
Define GenericParamListRequest
2019-09-06 19:55:16 -07: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
a0e160e215 AST: Refactor Decl::isWeakImported() API a little bit
First, remove the AvailabilityContext parameter; it was confusing because
we actually always want to use the deployment target here.

Then, split this method up into three methods:

- isAlwaysWeakImported(): simply checks for a @_weakLinked attribute, either
  on the declaration itself or one of its parent contexts.

- getAvailabilityForLinkage(): returns the OS version availability when
  this declaration was introduced, or if the declaration does not have
  explicit availability, check it's storage (if its an accessor), or its
  parent contexts.

- isWeakImported(ModuleDecl *fromModule): combines these two checks to
  determine if the declaration should be weak linked when referenced from
  the given module, or if it might be weak referenced from some module
  (if the module parameter is null).
2019-09-06 20:08:40 -04:00
Suyash Srijan
54a4615e6f [Diagnostics] Do not offer a mutating fix-it if we have a mutating protocol requirement
Do not offer a mutating fix-it if we have a mutating protocol requirement and we're assigning to it from an implicitly nonmutating setter inside a protocol extension
2019-09-06 23:40:07 +01:00
Slava Pestov
f292c1b240 AST: Remove GenericContext::setGenericEnvironment()
This was a transitional step before converting all callers to
store a generic signature instead of an environment.
2019-09-06 17:16:04 -04: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
Slava Pestov
1e94466bcc AST: Replace GenericSignature::createGenericEnvironment() with getGenericEnvironment()
This memoizes the result, which is fine for all callers; the only
exception is open existential types where each new open existential
now explicitly gets a unique generic environment, allocated by
calling GenericEnvironment::getIncomplete().
2019-09-06 17:16:03 -04:00
Slava Pestov
e9bcd00bc2 AST: Remove GenericEnvironment::OwningDC 2019-09-06 17:16:03 -04:00
Robert Widmann
07bcf5a579 Merge pull request #26995 from CodaFi/a-sign-from-on-high
Requestify Inferring Generic Requirements
2019-09-04 17:19:09 -07:00
Slava Pestov
a09382ce2b AST: Completely remove NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions 2019-09-03 22:53:52 -04:00
Slava Pestov
c87e1a23db Sema: Try harder not to page in all members of imported classes 2019-09-03 22:39:35 -04:00
Slava Pestov
22cb6f1176 AST: Introduce ProtocolDecl::get{AssociatedType,ProtocolRequirement}() 2019-09-03 22:39:35 -04:00
Robert Widmann
2d836f45be Drop a superfluous NULL write
Storing NULL here on failure is brittle and was only necessary when the
typechecker was leaking type variables in expressions.  Now that we're
better about this, it's best to preserve the damaged AST.
2019-09-03 13:01:30 -07:00
Robert Widmann
87047d067e Requestify Inferring Generic Requirements
Unify a bunch of quasi-independent callsites into a single request that
builds up a generic signature from a variety of inference sources.  This
draws the extension typealias workaround for SE-0229 into TypeCheckDecl
where we can better work on refactoring it.  The goal is to use this as
a springboard to requests that compute generic environments for various
and sundry decls.
2019-09-03 09:56:21 -07:00
Doug Gregor
d8b745db77 Add a request to lazily parse function bodies.
Rework the lazy function body parsing mechanism to use the
request-evaluator, so that asking for the body of a function will
initiate parsing. Clean up a number of callers to
AbstractFunctionDecl::getBody() that don't actually need the body, so
we don't perform unnecessary parsing.

This change does not delay parsing of function bodies in the general
case; rather, it sets up the infrastructure to always delay parsing of
function bodies.
2019-08-31 16:23:08 -07:00
eeckstein
903eeb220b Revert "Add a request to lazily parse function bodies." 2019-08-31 12:29:01 +02:00
Doug Gregor
2ab05a6835 Add a request to lazily parse function bodies.
Rework the lazy function body parsing mechanism to use the
request-evaluator, so that asking for the body of a function will
initiate parsing. Clean up a number of callers to
AbstractFunctionDecl::getBody() that don't actually need the body, so
we don't perform unnecessary parsing.

This change does not delay parsing of function bodies in the general
case; rather, it sets up the infrastructure to always delay parsing of
function bodies.
2019-08-30 16:48:23 -07:00
Robert Widmann
441eba1e19 Requestify Operator Decl Attachment 2019-08-27 11:29:22 -07:00
Robert Widmann
36765687b9 Merge pull request #26844 from CodaFi/extension-intervention
Requestify Extension Type Validation
2019-08-27 11:23:18 -07:00
Dan Zheng
f44064cbbc [SE-0253] Introduce callables. (#24299)
Introduce callables: values of types that declare `func callAsFunction`
methods can be called like functions. The call syntax is shorthand for
applying `func callAsFunction` methods.

```swift
struct Adder {
  var base: Int
  func callAsFunction(_ x: Int) -> Int {
    return x + base
  }
}
var adder = Adder(base: 3)
adder(10) // desugars to `adder.callAsFunction(10)`
```

`func callAsFunction` argument labels are required at call sites.
Multiple `func callAsFunction` methods on a single type are supported.
`mutating func callAsFunction` is supported.

SR-11378 tracks improving `callAsFunction` diagnostics.
2019-08-26 23:56:36 -07:00
Robert Widmann
8d22702a22 Use Integrated Caching
Replumb the TypeLoc for the extended type as a TypeRepr instead. Fixup
the myriad callsites this touches in the process.
2019-08-26 11:48:29 -07:00
Doug Gregor
0e2bb0fbe2 Prune includes of GenericSignatureBuilder.h. 2019-08-26 09:54:20 -07:00
Suyash Srijan
bb85ecb8b5 [Typechecker] Diagnose @dynamicMemberLookup subscript when it lacks an explicit argument label 2019-08-25 00:03:07 +01:00
Robert Widmann
2187fb20d5 Merge pull request #26794 from apple/whats-old-is-new-again
Requestify Class Ancestry Flags
2019-08-23 11:11:14 -07:00
Robert Widmann
6297a596aa Requestify Class Ancestry Flags 2019-08-22 15:22:48 -07:00