Commit Graph

3502 Commits

Author SHA1 Message Date
Slava Pestov
fcb52172fc AST: Change isResilient() to do the cheaper check first 2018-11-29 23:20:02 -05:00
Pavel Yaskevich
e18d390d18 Merge pull request #20663 from hamishknight/packing-up-the-flags
[AST] NFC: Pack @autoclosure parameter decl flag with the default value
2018-11-17 12:27:16 -08:00
Slava Pestov
e8e1f4f80d Merge pull request #20593 from slavapestov/keypath-resilience-fixes
Fix key paths for resilience and @inlinable
2018-11-17 13:13:53 -05:00
Hamish Knight
bec9a8c9cb [AST] NFC: Pack @autoclosure parameter decl flag with the default value 2018-11-17 13:31:40 +00:00
David Zarzycki
e4fb140355 Merge pull request #20501 from davezarzycki/fix_28870_crasher
[AST] NFC: Add reentrancy check to associated type anchor walk
2018-11-17 07:26:37 -05:00
John McCall
49ba9c59d1 Allow Error to conform to itself.
Most of the foundation for this was laid in earlier patches.
2018-11-17 02:51:45 -05:00
Slava Pestov
0e1b62dcad SILGen: Don't emit or reference property descriptors for overrides
We want removing a property override to be a resilient change, so
keypaths should not reference them, preferring to reference the
base declaration instead.
2018-11-16 23:18:30 -05:00
Slava Pestov
0a8ee10621 AST: Refactor AbstractStorageDecl::getAccessStrategy() for keypath resilience
Instead of passing in a DeclContext, which we don't have when emitting a keypath
accessor, pass in a ModuleDecl and ResilienceExpansion.

Keypaths now work well enough in inlinable contexts that we can check in an
end-to-end resilience test.
2018-11-16 23:18:30 -05:00
Slava Pestov
99c78894ef IRGen: Fix crash when emitting metadata for enum with @autoclosure case
Fixes <rdar://problem/45962425>, <https://bugs.swift.org/browse/SR-9169>.
2018-11-16 01:18:18 -05:00
Slava Pestov
558b517b08 AST: Fast path for requiresNewVTableEntry() when called on non-class members 2018-11-15 16:10:52 -05:00
Arnold Schwaighofer
40f0c43e31 Add isNativeDynamic() and use it 2018-11-14 12:04:41 -08:00
Arnold Schwaighofer
893318c114 Fix the AccessStrategy for dynamic (not @objc) storage
It needs to be opaque but not dispatched.
2018-11-13 15:20:27 -08:00
David Zarzycki
e8eabd7f47 [AST] NFC: Add reentrancy check to associated type anchor walk
This makes compiler crasher 28870 crash faster and reliably instead of
recursing off the end of the stack.

This reverts: 614cb48b63
2018-11-13 08:29:26 -05:00
Pavel Yaskevich
bce1ba5f37 [AST] Remove @autoclosure flag from function type ExtInfo 2018-11-10 11:59:29 -08:00
Pavel Yaskevich
d9504ef919 [TypeChecker] Add typeCheckParameterDefault method
`typeCheckParameterDefault` is used to type-check default value
expression associated with a given parameter. It makes it possible
to look-through `@autoclosure` function to use its result as
contextual type, and later build implicit autoclosure expression
if needed.
2018-11-10 11:59:28 -08:00
Pavel Yaskevich
4c1885b51b [AST] Register @autoclosure as parameter decl flag
It should become a declaration attribute instead,
but it can't be done at the moment because `@autoclosure`
is a type attribute.
2018-11-10 11:58:49 -08:00
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
Slava Pestov
a1ae75b2ba Merge pull request #20455 from slavapestov/fix-misc-regressions
Fix a handful of regressions
2018-11-09 13:20:44 -05:00
John McCall
e741147d70 Merge pull request #20459 from rjmccall/key-path-lvalue-emission
Always use the l-value logic for emitting key path applications
2018-11-09 12:08:27 -05:00
John McCall
c0285a744c Always use the l-value logic for emitting key path applications.
Not NFC because it also fixes an evaluation order bug (and reorders
some less-important stuff): the key-path expression needs to be
evaluated immediately during formal evaluation and cannot be delayed
until start-of-access.
2018-11-09 02:42:17 -05:00
Arnold Schwaighofer
6cc3d377ff Refactor part2 2018-11-08 18:16:17 -08:00
Slava Pestov
9dd63a4918 AST: Use resilient access pattern for stored properties of resilient types visible via -enable-testing
Fixes <rdar://problem/45919829>.
2018-11-08 19:43:31 -05:00
Arnold Schwaighofer
e4f4dfcf84 Address feedback 2018-11-08 11:13:42 -08:00
Arnold Schwaighofer
963c64e3e7 Add @_private(from: "SourceFile.swift") imports
A module compiled with `-enable-private-imports` allows other modules to
import private declarations if the importing source file uses an
``@_private(from: "SourceFile.swift") import statement.

rdar://29318654
2018-11-08 08:00:47 -08:00
Arnold Schwaighofer
44b3a47e56 Merge pull request #20333 from aschwaighofer/dynamic_function_replacement
Dynamic function replacement
2018-11-07 13:08:46 -08:00
David Zarzycki
614cb48b63 [AST] AssociatedTypeDecls cannot override itself 2018-11-07 10:04:57 -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
John McCall
1d764fd6b4 Synthesize modify accessors for resilient global variables.
rdar://32936947
2018-11-01 19:28:50 -04:00
Slava Pestov
57979d1f7c IRGen: Use @_weakLinked to test backward deployment of resilient protocols
Get the attribute working for more link entity kinds, which addresses
all the FIXME:s in the original test case.

Now the protocol resilience tests can be updated to use @_weakLinked
for all newly-added protocol requirements and default implementations.

This allows the tests to pass in the backward deployment test scenario
as well.

Eventually this will be based on availability instead of a special
attribute.

This completes <rdar://problem/29888071>.
2018-10-31 19:55:01 -04: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
73f1990bc2 AST: Use getSelfInterfaceType() instead of getProtocolSelfType() where possible
The former appears in the code base a lot more frequently than the
latter, which returns a GenericTypeParamType *. Use it only in places
where the more specific type is intended.
2018-10-15 20:34:08 -07:00
Slava Pestov
607ec2d8de Sema: Fix typo correction crash with invalid extension
Fixes <rdar://problem/45242943> / <https://bugs.swift.org/browse/SR-8984>.
2018-10-15 20:34:08 -07:00
Slava Pestov
9d131fd5f1 Merge pull request #18999 from hamishknight/location-by-association
[GSB] Avoid emitting associated type diagnostics on the protocol decl
2018-10-13 15:16:40 -07:00
Slava Pestov
36c8d94238 AST: Refactor SelfBoundsFromWhereClause to support ProtocolDecls 2018-10-12 03:06:52 -07:00
Anthony Latsis
f2ff87e652 Merge branch 'master' into code-compl-precedencegroups 2018-10-09 18:08:16 +03:00
swift-ci
1dfb979eaf Merge pull request #19789 from DougGregor/no-storage-for-old-classes 2018-10-08 23:08:14 -07:00
Doug Gregor
33109d8a8c [AST] Imported classes have no stored properties.
Avoid triggering the import of all of the members of an Objective-C
class to determine its stored properties, because we don't import
instance variables of Objective-C classes. rdar://problem/45060773
2018-10-08 22:06:54 -07:00
Harlan Haskins
5f9ff021d4 [Sema] Allow non-public static property initializers in @_fixed_layout types
Static properties are not subject to the same restrictions as properties
whose initializers are exposed to clients in @_fixed_layout types.

rdar://45080912
2018-10-08 18:02:30 -07:00
Doug Gregor
de18384d89 [AST] Don’t deserialize members of @objc protocol looking for associated types
Thanks to @slavapestov for pointing this out! The optimization to avoid
looking through the members of a protocol that can’t possibly have any
associated types was for both deserialized protocols and imported
protocols, but I only supported the former in my previous change. Check
both cases and make the reasons much more obvious.

Also, that change resolved an existing compiler crasher as well.
2018-10-06 22:08:45 -07:00
Doug Gregor
83e41daaa6 [AST] Ill-formed @objc protocols might have associated types.
As an optimization, we don't even look for associated types in @objc
protocols. However, this could lead to broken invariants like "every
associated type has a witness" in ill-formed @objc protocols that do
have associated types.

Implement this optimization by checking whether the protocol has a
Clang node. Fixes rdar://problem/41425828 / SR-8094.
2018-10-06 10:35:07 -07:00
Harlan
2c86e3249c [InterfaceGen] Print property initializers in resilient, fixed-layout types (#19619)
Augment the ASTPrinter to print the name and text of initializer expressions if
a property has an initializer and the type is @_fixed_layout and resides in a resilient module, and serialize the text for partial modules.

With this change, all .swiftinterface files in the project (except for SwiftLang) compile to swiftmodules on macOS.

rdar://43774580
rdar://43812188
2018-10-05 18:21:46 -07:00
Jordan Rose
df1ef05c4c Remove unwanted exceptions from @inlinable checking
- Treat protocol requirements just like associated types in how they
  inherit usable-from-inline-ness, rather than special-casing them in
  the check for inlinable code.

- Enum elements are already treated this way, so we can remove a
  redundant check for that.

- Finally, start enforcing that 'dynamic' declarations need to be
  '@usableFromInline' to be used in inlinable functions...in Swift 5
  mode or resilient code. I didn't even add a warning in Swift 4/4.2
  because it was illegal to use '@usableFromInline' on a 'dynamic'
  declaration in Swift 4.2. (Oops.)
2018-10-05 12:21:01 -07:00
fischertony
d2e7c785bb Create utility function for Associativity spelling 2018-10-04 00:38:20 +03:00
Jordan Rose
08d4a93896 [AST] More static_asserts for non-destroyed bump-allocated AST types (#19670)
Attributes, ParameterLists, GenericParamLists, Patterns, Types, and
TypeReprs. Thanks, Rintaro!
2018-10-02 14:58:18 -07:00
Jordan Rose
c22711a261 [AST] static_assert that Decls, Stmts, and Exprs don't need cleanup (#19667)
These types are all allocated on the ASTContext's BumpPtrAllocator,
and by default their destructors are never called. (ModuleDecl is the
exception; it registers its destructor with the ASTContext on
construction.)

No functionality change.
2018-10-02 10:42:42 -07:00
Slava Pestov
3b60ae153d AST: Rename AnyFunctionType::Param::getType() to getOldType() 2018-09-26 11:05:23 -07:00
Slava Pestov
34fd5fa6c4 AST: Replace remaining uses of FunctionType::getInput() with getParams() 2018-09-26 11:05:23 -07:00
Harlan
2aac8863f6 [InterfaceGen] Only print 'mutating' and 'nonmutating' on accessors (#19459)
* [InterfaceGen] Only print 'mutating' and 'nonmutating' on accessors

* Add SILGen test for usage of dynamic accessors in and out of interfaces

* Add -enable-objc-interop to dynamic_accessors test
2018-09-25 23:10:52 -07:00