Commit Graph

513 Commits

Author SHA1 Message Date
Slava Pestov
cece98b2ed AST: Generalize ClassDecl::checkObjCAncestry() to ClassDecl::checkAncestry()
This replaces ClassDecl::hasObjCMembers() and some hand-coded walks.
2019-03-26 18:42:59 -04:00
Azoy
dcedba73f0 fix lazy vars
clean up lazy vars

more docs
2019-03-20 23:01:38 -05:00
Azoy
2bd99eecae clean up subs
value interface type
2019-03-18 00:06:24 -05:00
Azoy
bc7cb332df Fix generic types
add tests

get parent init
2019-03-14 04:07:24 -05:00
Azoy
e8bc662b35 Cleanups from Slava's comments
update module format
2019-03-13 18:58:45 -05:00
Azoy
6d00a5758f Disallow default values for patterns binding multiple variables
lets not add !
2019-03-13 18:57:36 -05:00
Azoy
6f7d20b99e Synthesize default values for memberwise init
Introduce stored property default argument kind

Fix indent

Assign nil to optionals with no initializers

Don't emit generator for stored property default arg

Fix problem with rebase

Indentation

Serialize stored property default arg text

Fix some tests

Add missing constructor in test

Print stored property's initializer expression

cleanups

preserve switch

complete_constructor

formatting

fix conflict
2019-03-13 18:57:36 -05:00
Harlan Haskins
dd5a6772f4 [ParseableInterfaces] Handle lazy vars
For lazy vars, we need to make public the top-level entry point, and the fact
that the lazy storage contributes to the layout of a type (if it’s fixed
layout, or if the type is not resilient.) We also shouldn’t ever print `lazy`
in a parseable interface.

Since we need to parse these identifiers, give them a new name,
`$__lazy_storage_$_{propname}`, which is parseable only in parseable interfaces
so it doesn’t conflict with other properties.
2019-01-22 11:03:12 -08:00
Pavel Yaskevich
20b7c2a4ba [CodeSynthesis] Make sure that LazyInitializerExpr has a type
Currently when `LazyInitializerExpr` is added to the AST it's not
given an explicit type. Because of that constraint solver silently
fails in contraint generator without diagnostic. But since
sub-expression associated with `LazyInitializerExpr` is already
type-checked it makes sense to set its type explicitly.
2018-12-19 14:04:32 -08: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
Slava Pestov
392071e702 Sema: Peel off more code from the TypeChecker instance 2018-12-10 00:00:49 -05:00
Slava Pestov
06c2e980cb Merge pull request #21133 from slavapestov/lazy-implicit-inits
Lazy synthesis of implicit constructors in non-primary files
2018-12-07 22:45:40 -05:00
Slava Pestov
a55283d704 Sema: Lazy synthesis of implicit constructors in non-primary files 2018-12-07 20:39:27 -05:00
Slava Pestov
6c012b2aec AST: Remove some unnecessary LazyResolver * parameters from ASTContext methods 2018-12-07 20:39:27 -05:00
Slava Pestov
aa747dcd81 Remove property behaviors 2018-12-07 20:38:33 -05:00
Slava Pestov
a76012dc72 Sema: Tiny cleanup for createImplicitConstructor() 2018-12-07 17:11:30 -05:00
Slava Pestov
a6f6dc01bc Sema: Fix order dependency between lazy getter body synthesis and capture computation
If we computed captures before completing a lazy getter body, we would fail to
consider the 'self' capture properly. Instead make it resilient to such ordering
issues by checking in capture computation if the lazy property has a getter yet
or not.
2018-12-07 17:10:15 -05:00
Slava Pestov
7aed494bf3 Sema: Move accessor synthesis to the callback mechanism
Also change some TypeChecker usages to ASTContext.
2018-12-07 17:10:08 -05:00
Slava Pestov
77215ef5b7 Sema: Force SILGen emission of on-demand synthesized accessors
When an on-demand accessor is synthesized while checking a conformance,
make sure it ends up in the 'external declarations' list so that SILGen
can emit it.

Fixes <rdar://problem/46503121>, and part of <rdar://problem/46186045>.
2018-12-06 23:58:46 -05:00
swift-ci
39161d5b36 Merge pull request #20600 from adrian-prantl/36032653 2018-12-05 17:01:58 -08: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
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
John McCall
b9f4b17a33 Mark lazy properties as having mutating getters immediately.
We were trying to do this when synthesizing the getter prototype, but
we don't do that immediately when we're just type-checking a reference
to the storage, which could lead to the reference thinking that the
getter was non-mutating.

Fixes rdar://45712204.
2018-11-26 17:36:13 -05:00
Arnold Schwaighofer
40f0c43e31 Add isNativeDynamic() and use it 2018-11-14 12:04:41 -08:00
Arnold Schwaighofer
081bb95bee Synthesize accessors for dynamic global variables 2018-11-14 07:57:45 -08:00
Jordan Rose
40cfc458e2 Fix synthesis of 'override' and 'required' on initializers (#20548)
This is actually two separate problems:
- 'override' wasn't getting added to initializers in deserialization
- 'override' was getting added when inheriting a 'required' initializer,
  even though it's normally an error to write that

Needed for parseable interfaces.
2018-11-13 16:54:53 -08:00
Pavel Yaskevich
f462521078 [ConstraintSystem] Refactor arg/param matching to handle autoclosures
Make sure that presence of `@autoclosure` attribute handled
in one place - `matchCallArguments`, which makes it possible
to remove the rest of (now redundant) autoclosure related
logic scattered throughout solver.
2018-11-10 11:59:28 -08:00
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
John McCall
4758b2f58e Fix a bug with class vs. protocol @_borrowed mismatches. 2018-11-08 02:16:47 -05:00
Arnold Schwaighofer
c158106329 Allow dynamic without @objc in -swift-version 5
Dynamic functions will allow replacement of their implementation at
runtime.
2018-11-06 09:53:21 -08:00
John McCall
90ca9fe8b4 Fix a bunch of minor issues with read accessors. 2018-11-05 20:57:58 -05:00
Brent Royal-Gordon
9bd1a26089 Implementation for SE-0228: Fix ExpressibleByStringInterpolation (#20214)
* [CodeCompletion] Restrict ancestor search to brace

This change allows ExprParentFinder to restrict certain searches for parents to just AST nodes within the nearest surrounding BraceStmt. In the string interpolation rework, BraceStmts can appear in new places in the AST; this keeps code completion from looking at irrelevant context.

NFC in this commit, but keeps code completion from crashing once TapExpr is introduced.

* Remove test relying on ExpressibleByStringInterpolation being deprecated

Since soon enough, it won’t be anymore.

* [AST] Introduce TapExpr

TapExpr allows a block of code to to be inserted between two expressions, accessing and potentially mutating the result of its subexpression before giving it to its parent expression. It’s roughly equivalent to this function:

  func _tap<T>(_ value: T, do body: (inout T) throws -> Void) rethrows -> T {
    var copy = value
    try body(&copy)
    return copy
  }

Except that it doesn’t use a closure, so no variables are captured and no call frame is (even notionally) added.

This commit does not include tests because nothing in it actually uses TapExpr yet. It will be used by string interpolation.

* SE-0228: Fix ExpressibleByStringInterpolation

This is the bulk of the implementation of the string interpolation rework. It includes a redesigned AST node, new parsing logic, new constraints and post-typechecking code generation, and new standard library types and members.

* [Sema] Rip out typeCheckExpressionShallow()

With new string interpolation in place, it is no longer used by anything in the compiler.

* [Sema] Diagnose invalid StringInterpolationProtocols

StringInterpolationProtocol informally requires conforming types to provide at least one method with the base name “appendInterpolation” with no (or a discardable) return value and visibility at least as broad as the conforming type’s. This change diagnoses an error when a conforming type does not have a method that meets those criteria.

* [Stdlib] Fix map(String.init) source break

Some users, including some in the source compatibility suite, accidentally used init(stringInterpolationSegment:) by writing code like `map(String.init)`. Now that these intializers have been removed, the remaining initializers often end up tying during overload resolution. This change adds several overloads of `String.init(describing:)` which will break these ties in cases where the compiler previously selected `String.init(stringInterpolationSegment:)`.

* [Sema] Make callWitness() take non-mutable arrays

It doesn’t actually need to mutate them.

* [Stdlib] Improve floating-point interpolation performance

This change avoids constructing a String when interpolating a Float, Double, or Float80. Instead, we write the characters to a fixed-size buffer and then append them directly to the string’s storage.

This seems to improve performance for all three types, but especially for Double and Float80, which cannot always fit into a small string when stringified.

* [NameLookup] Improve MemberLookupTable invalidation

In rare cases usually involving generated code, an overload added by an extension in the middle of a file would not be visible below it if the type had lazy members and the same base name had already been referenced above the extension. This change essentially dirties a type’s member lookup table whenever an extension is added to it, ensuring the entries in it will be updated.

This change also includes some debugging improvements for NameLookup.

* [SILOptimizer] XFAIL dead object removal failure

The DeadObjectRemoval pass in SILOptimizer does not currently remove reworked string interpolations as well as the old design because their effects cannot be described by @_effects(readonly). That causes a test failure on Linux. This change temporarily silences that test. The SILOptimizer issue has been filed as SR-9008.

* Confess string interpolation’s source stability sins

* [Parser] Parse empty interpolations

Previously, the parser had an odd asymmetry which caused the same function to accept foo(), but reject “\()”. This change fixes the issue.

Already tested by test/Parse/try.swift, which uses this construct in one of its throwing interpolation tests.

* [Sema] Fix batch-mode-only lazy var bug

The temporary variable used by string interpolation needs to be recontextualized when it’s inserted into a synthesized getter. Fixes a compilation failure in Alamofire.

I’ll probably follow up on this bug a bit more after merging.
2018-11-02 19:16:03 -07:00
Doug Gregor
04e2f347bf [Type checker] Ensure that synthesized accessors get generic parameter lists.
When we synthesize the declaration for getters and setters from (e.g.) an
addressor, ensure that we clone the generic parameter list when we have a
generic subscript. Fixes rdar://problem/45046969.
2018-10-05 11:14:03 -07:00
MIZUNO Hiroki
f2bdce8251 [SR-8340]Improve fix-it for var and subscript in Protocol (#19660)
* [Parser] Improve fix-it for subscription in protocol
* [Sema] Add fix-it for property in protocol

https://bugs.swift.org/browse/SR-8340
2018-10-05 07:50:03 +09:00
Doug Gregor
56cfd84b6a [Type checker] Move accessor creation out of validateDecl().
Creating accessors for a storage declaration within validateDecl() caused
circular dependencies detected by the request-evaluator. Separate out
accessor creation to break the dependency.

Fixes SR-8656 / rdar://problem/43951634.
2018-09-11 16:20:12 -07:00
Harlan
eb75ad80dc [AST] Remove stored TypeLoc from TypedPattern (#19175)
* [AST] Remove stored TypeLoc from TypedPattern

TypedPattern was only using this TypeLoc as a means to a TypeRepr, which
caused it to store the pattern type twice (through the superclass and through
the TypeLoc itself.)

This also fixes a bug where deserializing a TypedPattern doesn't store
the type correctly and generally cleans up TypedPattern initialization.

Resolves rdar://44144435

* Address review comments
2018-09-07 21:14:04 -07:00
Slava Pestov
ec804a2d01 SIL: Accessors synthesized on-demand are serialized when visible outside the module
Second part of <https://bugs.swift.org/browse/SR-8657> /
<rdar://problem/43951732>.
2018-09-06 13:17:18 -07:00
Slava Pestov
71cafe46c9 Sema: Simplify accessor synthesis a bit 2018-09-06 11:59:20 -07:00
Harlan
ad7e1d0e67 [InterfaceGen] Print private/internal properties (#19127)
* [Interface] Print private/internal properties

All properties which contribute to the storage of a type should be
printed, and their names should be hidden from interfaces. Print them
with '_' as their name, and teach the parser to recognize these special
patterns when parsing interface files.

Partially resolves rdar://43810647

* Address review comments

* Disable accessor generation for nameless vars

* Test to ensure interface files preserve type layout

* Ignore attribute differences on Linux
2018-09-06 09:58:33 -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
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
John McCall
a30d91e3cb Implement vararg expansion well enough to support argument forwarding.
I needed this for materializeForSet remission, but it makes inherited
variadic initializers work, too.

I tried to make this a reasonable starting point for a real language
feature.  Here's what's still missing:

- syntax
- semantic restrictions to ensure that the expression isn't written in
  invalid places or arbitrarily converted
- SILGen support for expansions that aren't the only variadic argument

rdar://16331406
2018-08-22 06:46:08 -04:00
Doug Gregor
8dc20dfcac [Type checker] Move TypeChecker::resolveType() into TypeResolution.
Now that type resolution is (almost completely) separated from the type
checker instance, move resolveType() out to TypeResolution where it
belongs.
2018-08-20 22:31:59 -07:00
Doug Gregor
7fa4f1df54 Merge pull request #18859 from DougGregor/type-resolution-stage
[Type Checker] Add TypeResolution(Stage) to describe type computations.
2018-08-20 18:44:31 -07:00
Doug Gregor
79a55895de [Type Checker] Replace GenericTypeResolver with a TypeResolution.
Replace the GenericTypeResolver type hierarchy with TypeResolution,
which more simply encapsulates the information needed to resolve
dependent types and makes explicit those places where we are
using resolution to contextual types.
2018-08-20 16:53:44 -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
John McCall
5d8252b8c6 Pass around whether storage is mutable as an enum instead of a bool. 2018-08-16 02:13:54 -04:00
David Zarzycki
6b6ef5af24 [Sema] NFC: Refactor most TypeResolutionFlags into a traditional enum
TypeResolutionFlags is overly complicated at the moment because the vast
majority of flag combinations are impossible and nonsensical. With this
patch, we create a new TypeResolverContext type that is a classic enum
and far easier to reason about. It also enables "exhaustive enum"
checking, unlike the "flags" based approach.
2018-08-13 08:18:40 -04:00