Commit Graph

4003 Commits

Author SHA1 Message Date
Michael Ilseman
c3785e2f1a Merge pull request #20362 from gottesmm/pr-657153590cac7970ccbc5c7e03ccf477d42a24fc
Revert "Revert "Revert "[Build System: CMake] make add_swift_library …
2018-11-06 16:12:03 -08:00
Michael Gottesman
a761d7c0ba Revert "Revert "Revert "[Build System: CMake] make add_swift_library a wrapper to add_llvm_library"""
This reverts commit 121f5b64be.

Sorry to revert this again. This commit makes some pretty big changes. After
messing with the merge-conflict created by this internally, I did not feel
comfortable landing this now. I talked with Saleem and he agreed with me that
this was the right thing to do.
2018-11-06 13:24:00 -08:00
John McCall
95fe154cad [NFC] Don't hardcode how to read Hashable.hashValue in key paths. 2018-11-06 16:04:48 -05:00
Arnold Schwaighofer
b102c7f6b4 Parser/Sema/SILGen changes for @_dynamicReplacement(for:)
Dynamic replacements are currently written in extensions as

extension ExtendedType {
  @_dynamicReplacement(for: replacedFun())
  func replacement() { }
}

The runtime implementation allows an implementation in the future where
dynamic replacements are gather in a scope and can be dynamically
enabled and disabled.

For example:

dynamic_extension_scope CollectionOfReplacements {
  extension ExtentedType {
    func replacedFun() {}
  }

  extension ExtentedType2 {
    func replacedFun() {}
  }
}

CollectionOfReplacements.enable()
CollectionOfReplacements.disable()
2018-11-06 09:58:36 -08:00
Arnold Schwaighofer
5f4e183302 Add [dynamically_replacable] to SILFunctions
'dynamic' functions are marked as [dynamically_replaceable].
2018-11-06 09:53:21 -08: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
c1b31b4e2f Make the general path of emitRValueForStorageLoad use LValues.
Beyond just being better code, this also fixes problems where
the duplicate code didn't handle e.g. _read accessors.

I believe this finishes unblocking _read in the stdlib (rdar://45230566).
2018-11-06 01:58:59 -05:00
John McCall
71e2e8eae8 [NFC] Move some storage-access code into SILGenLValue. 2018-11-06 01:58:59 -05:00
John McCall
a98941e8e6 Merge pull request #20342 from rjmccall/read-accessor-fixes
Fix a bunch of minor issues with read accessors
2018-11-06 00:43:31 -05:00
Michael Gottesman
6a8b7534f4 Merge pull request #20325 from compnerd/cleanup-again
Revert "Revert "[Build System: CMake] make add_swift_library a wrappe…
2018-11-05 19:50:39 -08:00
John McCall
90ca9fe8b4 Fix a bunch of minor issues with read accessors. 2018-11-05 20:57:58 -05:00
Saleem Abdulrasool
121f5b64be Revert "Revert "[Build System: CMake] make add_swift_library a wrapper to add_llvm_library""
This reverts commit 103f9a8246.
2018-11-05 14:37:40 -08:00
John McCall
7da688d75a Always manage subobject projections with formal-access cleanups.
To make that work, enter appropriate scopes (ArgumentScopes and
FormalEvaluationScopes) at a bunch of places.  But note that l-value
emission generally can't enter such a scope, so in generic routines
like emitOpenExistentialExpr we have to just assert that we're
already in a scope.
2018-11-03 02:14:06 -04:00
John McCall
cbd2cd77d8 Strengthen assertions around cleanup and formal evaluation scopes.
I haven't actually tested this separately from the changes to scope
usage that are coming in the follow-up, but it's logically somewhat
separate.
2018-11-03 01:00:17 -04:00
John McCall
b08a3f35b0 [NFC] Add a utility to DiverseStack to simplify stable iteration 2018-11-03 01:00:17 -04:00
John McCall
b2e2b853ca [NFC] Pull CleanupBuffer up to DiverseStack 2018-11-03 01:00:17 -04:00
swift-ci
d1089c393e Merge pull request #20249 from Dante-Broggi/patch-10 2018-11-02 19:41:27 -07: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
Dante Broggi
e8a7cd635b Fix typo in comment "eit" to "emit" 2018-11-02 16:11:54 -04:00
Xi Ge
103f9a8246 Revert "[Build System: CMake] make add_swift_library a wrapper to add_llvm_library" 2018-11-02 12:49:07 -07:00
Saleem Abdulrasool
42772922e0 Merge pull request #19514 from compnerd/breakup
[Build System: CMake] make add_swift_library a wrapper to add_llvm_library
2018-11-02 09:56:17 -07:00
John McCall
1d764fd6b4 Synthesize modify accessors for resilient global variables.
rdar://32936947
2018-11-01 19:28:50 -04:00
Michael Gottesman
95e9646d4e Merge pull request #20196 from gottesmm/pr-287632bfd462700721e50c144278d5edb97f6b6a
[silgen] Scope conditionally emitted code by emitBoolDispatch.
2018-11-01 11:12:33 -07:00
John McCall
abdba1d3f4 Change the integer-literal type from Int2048 to IntLiteral.
Part of SR-290.
2018-10-31 23:14:58 -04:00
Michael Gottesman
b45bea8a03 [silgen] Scope conditionally emitted code by emitBoolDispatch.
rdar://45602910
2018-10-31 18:44:48 -07:00
Saleem Abdulrasool
39dde93c88 add_swift_host_library: rename LINK_LIBRARIES to LINK_LIBS 2018-10-31 12:46:31 -07:00
Slava Pestov
38ccddd24f Remove Swift 3 @objc behavior 2018-10-30 16:46:08 -04:00
Michael Gottesman
e96dcdf243 [silgen] Add a missing destroy_value in our code that emits UIApplicationMain.
This error slipped through... the ownership verifier catches this when the test
test/SILGen/UIApplicationMain is compiled.
2018-10-29 22:03:23 -07:00
Michael Gottesman
f8e27234fc Merge pull request #20033 from gottesmm/pr-aef61f8fa8d192698e4fe42ceef1bc68d72337e8
[silgen] When emitting a top level error, destroy the error after we …
2018-10-29 14:39:34 -07:00
Joe Groff
7b5e83de01 Merge pull request #19979 from mdiep/SR-8933
Fix assertion from empty switch over uninhabited enum
2018-10-29 09:46:55 -07:00
Michael Gottesman
3f17bb6ddf Carefully split the build's invocation of add_swift_library into host/target variants.
The key thing here is that all of the underlying code is exactly the same. I
purposely did not debride anything. This is to ensure that I am not touching too
much and increasing the probability of weird errors from occurring. Thus the
exact same code should be executed... just the routing changed.
2018-10-27 12:58:51 -07:00
John McCall
039f8d0914 Merge pull request #20063 from rjmccall/cleanup-scope-assertions
[NFC] Strengthen some assertions with cleanup scopes
2018-10-26 16:55:59 -07:00
John McCall
3162b513a9 Strengthen some assertions with cleanup scopes; NFC. 2018-10-25 21:50:00 -07:00
Michael Gottesman
88979f9c90 [silgen] When emitting a top level error, end_lifetime the error after we have logged it.
This is not strictly necessary since we are going to be exiting the program, but
the ownership verifier thinks that the error is leaked otherwise. By using the
end_lifetime we avoid having a small increase in code-size since it is a no-op
after ownership is removed.

rdar://29791263
2018-10-25 18:33:35 -07:00
Erik Eckstein
a60eafe472 Require Builtin.valueToBridgeObject to have a builtin integer as argument
Previously it was used with an UInt struct argument. But this is bad because UInt is a type defined in the stdlib.
2018-10-25 10:18:23 -07:00
Michael Gottesman
965d697c1a Merge pull request #20022 from gottesmm/pr-c8913074c7375798bf6ea153a3635e28ec248f06
[silgen] Only borrow args for coroutines rather than general applies …
2018-10-24 18:18:06 -07:00
Jordan Rose
dc3ff6c22b Merge pull request #19985 from vinivendra/ast-dump-cleanup
Cleans up calls to print/dump for the AST Dumper
2018-10-24 15:22:41 -07:00
Michael Gottesman
489910e483 [silgen] Only borrow args for coroutines rather than general applies and do not conditionalize based off of the ownership flag being set.
This is the last part of SILGen conditionalized on EnableSILOwnership being
set. It also (as you can tell from the diff) eliminates a bunch of code from the
tests.

rdar://29791263
2018-10-24 13:54:58 -07:00
Vinicius Vendramini
e9075344e3 Cleans up a few details. 2018-10-24 16:22:52 -03:00
Michael Gottesman
edfb86f09a Merge pull request #19988 from gottesmm/pr-06c8b35dac1dd99058fd565cad7fd824a0c1de92
[silgenpattern] Allow the initial switch value to be at +0 if it is loadable.
2018-10-23 11:24:48 -07:00
swift-ci
cbbc03a551 Merge pull request #19986 from gottesmm/pr-39aa50102d65c79c698d094c139faab143fa5bbe 2018-10-23 11:13:10 -07:00
Michael Gottesman
d8243c8b9b [silgenpattern] Allow the initial switch value to be at +0 if it is loadable.
This commit allows the initial switch subject value to be emitted at +0 if we
can emit it that way. As you can imagine since we have +0 normal function
arguments this should tighten up a lot of code around switches on arguments. So
I got to delete a bunch of code in the tests. = ).

Some things to note:

1. If the switch is given a +1 value, we will still try to let it through at +1
until we hit a part of the decision tree where previously we would need to use
TakeOnSuccess. This means that +1 values that go through irrefutable patterns
like tuple splitting should still be emitted at +1.

2. If we are returned an address only type without a cleanup, we copy it and
pass it down at +1 like the old code.

3. I also elided the last ownership check in SILGenPattern in this commit. After
this, there is only 1 specialization for ownership in the swift compiler that is
in Apply emission. Thats my next target.

rdar://29791263
2018-10-23 10:25:05 -07:00
Michael Gottesman
447a11a19a [silgenpattern] Change catch emission to not be conditional on ownership verification being enabled.
We were missing the code-coverage needed to show this so I added some examples
to test/SILGen/errors.swift.

rdar://29791263
2018-10-23 10:05:35 -07:00
Vinicius Vendramini
b61df445ae Cleans up calls to print/dump for the AST Dumper
The `Stmt` and `Expr` classes had both `dump` and `print` methods that behaved similarly, making it unclear what each method was for. Following a conversation in https://forums.swift.org/t/unifying-printing-logic-in-astdumper/15995/6 the `dump` methods will be used to print the S-Expression-like ASTs, and the `print` methods will be used to print the more textual ASTPrinter-based representations. The `Stmt` and `Expr` classes seem to be where this distinction was more ambiguous. These changes should fix that ambiguity.

A few other classes also have `print` methods used to print straightforward representations that are neither the S-Expressions nor ASTPrinters. These were left as they are, as they don't cause the same ambiguity.

It should be noted that the ASTPrinter implementations themselves haven't yet been finished and aren't a part of these changes.
2018-10-22 16:04:02 -03:00
Michael Gottesman
b8df997b3a [gardening] Re-organize Cleanup.cpp so that methods on the same class are together and not interleaved.
This code was organized such that one had first definitions for CleanupManager,
then CleanupStateRestorationScope, and then again CleanupManager. This is just
confusing/hard to read. This commit fixes that by creating contiguous sections
of definitions with comment flags to document said sections.
2018-10-22 11:37:17 -07:00
Matt Diephouse
cd2daa931f Fix assertion from empty switch over uninhabited enum
Fixes SR-8933.

Swift's uninhabited checking is conservative. An enum might not be found to be uninhabited, but all of its cases might. In that case, the switch can be empty even though the type isn't known to be uninhabited.

Fix an assertion that assumed there would always be at least one case for types that aren't known to be uninhabited.
2018-10-22 06:46:46 -04:00
Andrew Trick
c3fed985f0 Merge pull request #19886 from atrick/silgen-critedge
SILGen: simplify cleanups and avoid critical edges.
2018-10-20 01:54:06 -07:00
John McCall
d60af18ba3 Merge pull request #19964 from rjmccall/builtin-ownership
Emit certain builtin arguments as owned values
2018-10-20 02:34:55 -04:00
Andrew Trick
2ccc089b27 SILGenFunction::mergeCleanupBlocks.
Avoid emitting unnecessary basic block for cleanup chains. This is a
general approach that handles all cases while simplifying SILGen
emission and keeping the CFG in a valid state during SILGen.
2018-10-19 22:22:23 -07:00
Andrew Trick
c8e4d2b014 SILGen KeyPath: Create a basic block to split the critical edge.
This is the one place in SILGen where we need to explicitly split the
critical edge. createBasicBlockAndBranch is a simply utility for that.
2018-10-19 22:22:23 -07:00