Commit Graph

24822 Commits

Author SHA1 Message Date
Hamish Knight
2724cf6f65 [Parse] Check the SourceFile to see if bodies can be delayed
Remove the `DelayBodyParsing` flag from the parser
and instead query the source file.
2020-03-02 14:12:37 -08:00
Hamish Knight
2ec619caf7 [AST] Add a few parsing flags to SourceFile
Add flags for whether delayed body parsing or #if
condition evaluation is disabled, as well as
whether warnings should be suppressed. Then pass
down these flags from the frontend.

This is in preparation for the requestification of
source file parsing where the SourceFile will need
to be able to parse itself on demand.
2020-03-02 14:12:37 -08:00
Hamish Knight
a9870ac787 Merge pull request #29741 from hamishknight/moving-states
Move PersistentParserState onto SourceFile
2020-03-02 14:11:06 -08:00
Hamish Knight
d77cae6720 Move PersistentParserState onto SourceFile
Move the global PersistentParserState from
the CompilerInstance to the source file that code
completion is operating on, only hooking up the
state when it's needed. This will help make it
easier to requestify source file parsing.
2020-03-02 11:22:44 -08:00
Michael Gottesman
962b4ed633 [semantic-arc] Change StorageGuaranteesLoadVisitor::visitClassAccess to find borrow scope introducers using utilities from OwnershipUtils.h.
I added a new API into OwnershipUtils called
getSingleBorrowIntroducingValue. This API returns a single
BorrowScopeIntroducingValue for a passed in guaranteed value. If we can not find
such a BorrowScopeIntroducingValue or we find multiple such, we return None.

Using that, I refactored StorageGuaranteesLoadVisitor::visitClassAccess(...) to
use this new API which should make it significantly more robust since the
routine uses the definitions of "guaranteed forwarding" that the ownership
verifier uses when it verifies meaning that we can rely on the routine to be
exhaustive and correct. This means that we now promote load [copy] ->
load_borrow even if our borrow scope introducer feeds through a switch_enum or
checked_cast_br result (the main reason I looked into this change).

To create getSingleBorrowIntroducingValue, I refactored
getUnderlyingBorrowIntroucingValues to use a generator to find all of its
underlying values. Then in getSingleBorrowIntroducingValue, I just made it so
that we call the generator 1-2 times (as appropriate) to implement this query.
2020-03-02 00:35:41 -08:00
Michael Gottesman
b58ea4bb37 Merge pull request #30151 from gottesmm/pr-5d7a1ea2d4ae11d647fceb405a4c2307150f7b06
[ownership] Create a single introducer version of getUnderlyingBorrowIntroducingValues and rename it to getAllBorrowIntroducingValues(...).
2020-03-02 00:29:34 -08:00
Michael Gottesman
926f105413 Merge pull request #30087 from gottesmm/pr-7d5f0d45e4677ebbd92aeb1e261ab388a4ca5756
[ownership] Add simple support for concatenating together simple live ranges
2020-03-02 00:28:33 -08:00
Michael Gottesman
bdf6143df5 [ownership] Add simple support for concatenating together simple live ranges that do not need LiveRange analysis.
Specifically, this PR adds support for optimizing simple cases where we do not
need to compute LiveRanges with the idea of first doing simple transforms that
involve small numbers of instructions first. With that in mind, we only optimize
cases where our copy_value has a single consuming user and our owned value has a
single destroy_value. To understand the transform here, consider the following
SIL:

```
  %0 = ...
  %1 = copy_value %0                 (1)
  apply %guaranteedUser(%0)          (2)
  destroy_value %0                   (3)
  apply %cviConsumer(%1)             (4)
```

We want to eliminate (2) and (3), effectively joining the lifetimes of %0 and
%1, transforming the code to:

```
  %0 = ...
  apply %guaranteedUser(%0)          (2)
  apply %cviConsumer(%0)             (4)
```

Easily, we can always do this transform in this case since we know that %0's
lifetime ends strictly before the end of %1's due to (3) being before (4). This
means that any uses that require liveness of %0 must be before (4) and thus no
use-after-frees can result from removing (3) since we are not shrinking the
underlying object's lifetime. Lets consider a different case where (3) and (4)
are swapped.

```
  %0 = ...
  %1 = copy_value %0                 (1)
  apply %guaranteedUser(%0)          (2)
  apply %cviConsumer(%1)             (4)
  destroy_value %0                   (3)
```

In this case, since there aren't any liveness requiring uses of %0 in between
(4) and (3), we can still perform our transform. But what if there was a
liveness requiring user in between (4) and (3). To analyze this, lets swap (2)
and (4), yielding:

```
  %0 = ...
  %1 = copy_value %0                 (1)
  apply %cviConsumer(%1)             (4)
  apply %guaranteedUser(%0)          (2)
  destroy_value %0                   (3)
```

In this case, if we were to perform our transform, we would get a use-after-free
due do the transform shrinking the lifetime of the underlying object here from
ending at (3) to ending at (4):

```
  %0 = ...
  apply %cviConsumer(%1)             (4)
  apply %guaranteedUser(%0)          (2) // *kaboom*
```

So clearly, if (3) is after (4), clearly, we need to know that there aren't any
liveness requiring uses in between them to be able to perform this
optimization. But is this enough? Turns out no. There are two further issues
that we must consider:

1. If (4) is forwards owned ownership, it is not truly "consuming" the
underlying value in the sense of actually destroying the underlying value. This
can be worked with by using the LiveRange abstraction. That being said, this PR
is meant to contain simple transforms that do not need to use LiveRange. So, we
bail if we see a forwarding instruction.

2. At the current time, we may not be able to find all normal uses since all of
the instructions that are interior pointer constructs (e.x.: project_box) have
not been required yet to always be guarded by borrows (the eventual end
state). Thus we can not shrink lifetimes in general safely until that piece of
work is done.

Given all of those constraints, we only handle cases here where (3) is strictly
before (4) so we know 100% we are not shrinking any lifetimes. This effectively
is causing our correctness to rely on SILGen properly scoping lifetimes. Once
all interior pointers are properly guarded, we will be able to be more
aggressive here.

With that in mind, we perform this transform given the following conditions
noting that this pattern often times comes up around return values:

1. If the consuming user is a return inst. In such a case, we know that the
   destroy_value must be before the actual return inst.

2. If the consuming user is in the exit block and the destroy_value is not.

3. If the consuming user and destroy_value are in the same block and the
   consuming user is strictly later in that block than the destroy_value.

In all of these cases, we are able to optimize without the need for LiveRanges.
I am going to add support for this in a subsequent commit.
2020-03-01 19:59:54 -08:00
John McCall
9df969a627 Mangle coroutine information when mangling SILFunctionTypes. 2020-03-01 22:40:43 -05:00
Michael Gottesman
6e5f036bda [ownership] Create a single introducer version of getUnderlyingBorrowIntroducingValues and rename it to getAllBorrowIntroducingValues(...).
I also added a comment to getAllBorrowIntroducingValues(...) that explained the
situations where one could have multiple borrow introducing values:

1. True phi arguments.
2. Aggregate forming instructions.
2020-03-01 17:30:53 -08:00
3405691582
5847726f51 Preliminary support for OpenBSD in the stdlib.
These should hopefully all be uncontroversial, minimal changes to deal
with progressing the build to completion on OpenBSD or addressing minor
portability issues. This is not the full set of changes to get a
successful build; other portability issues will be addressed in future
commits.

Most of this is just adding the relevant clauses to the ifdefs, but of
note in this commit:

* StdlibUnittest.swift: the default conditional in _getOSVersion assumes
  an Apple platform, therefore the explicit conditional and the relevant
  enums need filling out. The default conditional should be #error, but
  we'll fix this in a different commit.

* tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r.
  Tests are updated correspondingly.

* ThreadLocalStorage.h: we use the pthread implementation, so it
  seems we should typedef __swift_thread_key_t as pthread_key_t.
  However, that's also a tweak for another commit.
2020-03-01 12:50:06 -05:00
David Ungar
72032493f9 Fix and test for extension body 2020-02-29 23:19:09 -08:00
Owen Voorhees
f0eb312594 Merge pull request #30116 from owenv/property-wrapper-note
[Diagnostics] Tweak @propertyWrapper diagnostic wording and add an educational note
2020-02-29 09:39:18 -08:00
swift-ci
e8dfdf3bc1 Merge pull request #30128 from CodaFi/doc-tiles 2020-02-28 14:53:03 -08:00
Pavel Yaskevich
389e84fc55 Merge pull request #30115 from LucianoPAlmeida/nfc-abstract-is-stdlib
[NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl
2020-02-28 13:32:32 -08:00
Robert Widmann
b9ebc96cdb [Gardening] Squelch a missing parameter warning 2020-02-28 13:09:57 -08:00
Hamish Knight
0d5a5e12d5 Move #if evaluation flag out of PersistentParserState
Move this flag onto the parser instead. Now the
only client of PersistentParserState is code
completion.
2020-02-28 10:51:12 -08:00
Joe Groff
4abb548adb IRGen: Invoke objc_opt_self directly when available.
We don't need swift_getInitializedObjCClass on new enough Apple OSes because
the ObjC runtime provides an equivalent call for us.
2020-02-28 10:36:42 -08:00
Robert Widmann
d494cc8dcb Merge pull request #30109 from CodaFi/lies-more-lies-and-statistics
[Frontend] Clean Up Usage of UnifiedStatsReporter
2020-02-28 10:24:02 -08:00
Holly Borla
87bb7755c2 Merge pull request #30101 from hborla/dynamic-replacement-type-erasure
[Sema] Implement type erasure for dynamic replacement.
2020-02-28 09:37:33 -08:00
Luciano Almeida
f4b530fb95 [NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl 2020-02-28 07:40:08 -03:00
Owen Voorhees
c75a363e1c Tweak @propertyWrapper diagnostics and add an educational note 2020-02-27 20:28:28 -08:00
Slava Pestov
ea9806d490 Merge pull request #30097 from slavapestov/sr-75-super-method
Sema: Diagnose unbound method references on 'super.'
2020-02-27 23:06:33 -05:00
Robert Widmann
a6651a920d Generalize and fix compiler resource freeing before LLVM
Centralize part of the routine that selects which resources to free. Then, add an additional condition for -dump-api-path.

Before, if this option were specified along with -emit-llvm or -c, the compiler would try to rebuild the torn-down ModuleDecl and crash trying to access the torn-down ASTContext.
2020-02-27 17:12:58 -08:00
Robert Widmann
ccf472d158 [NFC] Clean up performLLVM a bit
The only non-trivial bit is making the DiagnosticEngine parameter to swift::performLLVM required. No callers were taking advantage of this parameter allowing NULL.
2020-02-27 17:12:58 -08:00
Robert Widmann
535bb9bf8f [NFC] UnifiedStatsReporter is owned by CompilerInstance
The lifetime of the UnifiedStatsReporter was not entirely clear from context. Stick it in the CompilerInstance instead so it can live as long as the compile job.

It is critical that its lifetime be extended beyond that of the ASTContext, as the context may be torn down by the time code generation happens, but additional statistics are recorded during LLVM codegen.
2020-02-27 17:12:57 -08:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
AG
93d700001a Merge pull request #29874 from bitjammer/acgarland/rdar-58339492-sg-source-locations
SymbolGraph: Serialize source locations and doc comment ranges
2020-02-27 15:35:57 -08:00
Slava Pestov
019452f9af Sema: Diagnose unbound method references on 'super.'
This is something I noticed by inspection while working on
<https://bugs.swift.org/browse/SR-75>.

Inside a static method, 'self' is a metatype value, so
'self.instanceMethod' produces an unbound reference of type
(Self) -> (Args...) -> Results.

You might guess that 'super.instanceMethod' can similarly
be used to produce an unbound method reference that calls
the superclass method given any 'self' value, but unfortunately
it doesn't work.

Instead, 'super.instanceMethod' would produce the same
result as 'self.instanceMethod'. Maybe we can implement this
later, but for now, let's just diagnose the problem.

Note that partially-applied method references with 'super.'
-- namely, 'self.staticMethod' inside a static context, or
'self.instanceMethod' inside an instance context, continue
to work as before.

They have the type (Args...) -> Result; since the self value
has already been applied we don't hit the representational
issue.
2020-02-27 17:28:23 -05:00
Arnold Schwaighofer
869e579477 Merge pull request #30076 from aschwaighofer/silgen_fix_dynamic_replacement_before_original
SILGen: Fix dynamic replacement before original function
2020-02-27 12:03:09 -08:00
Robert Widmann
0984b1508f Merge pull request #30086 from CodaFi/constexpert-mode
[NFC] Mark The OptionSet API constexpr
2020-02-27 10:16:17 -08:00
Slava Pestov
00318732e1 Merge pull request #30084 from slavapestov/sr-75-prep
More Sema cleanups to prepare for curry thunks
2020-02-27 09:06:38 -05:00
eeckstein
7b2c8f1c87 Merge pull request #30074 from eeckstein/globalopt
GlobalOpt: improvements for constant folding global variables
2020-02-27 08:30:12 +01:00
Brent Royal-Gordon
222c459fb2 [SE-0274] Stage in #filePath (#29944)
* Stage in #filePath

To give users of #file time to transition, we are first adding #filePath without changing #file’s behavior. This commit makes that change.

Fixes <rdar://problem/58586626>.

* Correct swiftinterface test line
2020-02-27 00:03:13 -06:00
Slava Pestov
90ee606de7 Sema: Refactor CSApply in preparation for curry thunks 2020-02-26 23:10:07 -05:00
Slava Pestov
783ea28f1a AST: Change AutoClosureExpr::isThunk() to getThunkType() 2020-02-26 23:09:54 -05:00
Robert Widmann
581d0076f2 [NFC] Mark The OptionSet API constexpr
All of these bit manipulation primitives have been constexpr-able for
a while now.
2020-02-26 16:59:42 -08:00
Rintaro Ishizaki
c3c5fbc5a2 Merge pull request #30004 from rintaro/ide-completion-genericreq-rdar58580482
[CodeCompletion] Re-implement generic requirement completion
2020-02-26 14:53:00 -08:00
Joe Groff
0fb4ea1ec3 Merge pull request #30003 from NobodyNada/master
[SILOptimizer] Generalize optimization of static key paths, take 2
2020-02-26 12:13:43 -08:00
Rintaro Ishizaki
e5cdbb7fab [CodeCompletion] completeGenericRequirement to use the decl context
instead of the parsed type name for the extension.
Preparation for generalize this to other 'where' clause (e.g. functions)
2020-02-26 09:57:17 -08:00
Rintaro Ishizaki
5cf88a15cf [CodeCompletion] Rename GenericParam kind to GenericRequiremnt
NFC
2020-02-26 09:57:17 -08:00
Rintaro Ishizaki
75c36615e4 Merge pull request #29048 from rintaro/ide-completion-fasttoplevel-rdar58378157
[CodeCompletion] Fast completion for top-level code in single file script
2020-02-26 09:49:18 -08:00
Arnold Schwaighofer
cae695e81b SILGen: Fix dynamic replacement before original function
Creating a @_dynamicReplacement function requires the creation of a
reference to the original function. We need to call SILGenModule's
getFunction to satisfy all the assertions in place.

rdar://59774606
2020-02-26 09:47:36 -08:00
Erik Eckstein
43e8b07e3f GlobalOpt: improvements for constant folding global variables
* Simplified the logic for creating static initializers and constant folding for global variables: instead of creating a getter function, directly inline the constant value into the use-sites.
* Wired up the constant folder in GlobalOpt, so that a chains for global variables can be propagated, e.g.

  let a = 1
  let b = a + 10
  let c = b + 5

* Fixed a problem where we didn't create a static initializer if a global is not used in the same module. E.g. a public let variable.
* Simplified the code in general.

rdar://problem/31515927
2020-02-26 17:35:05 +01:00
Arnold Schwaighofer
c1edc2c31c Merge pull request #30050 from aschwaighofer/irgen_enable_type_layout_based_value_witnesses
IRGen: Enable TypeLayout based value witness generation
2020-02-26 06:59:10 -08:00
Holly Borla
3032dbd210 [Serialization] Implement serialization/deserialization for the typeEraser
attribute.
2020-02-25 19:53:25 -08:00
Hamish Knight
63e4ec6bdd Merge pull request #30038 from hamishknight/plenty-of-scope-for-requestification
Requestify scoped import validation
2020-02-25 16:40:00 -08:00
Rintaro Ishizaki
0a0cde92a4 [CodeCompletion] Fast completion for top-level code in single file script
e.g. Playground.
A single file script is like a single function body; the interface of
the file does not affect any other files.
So when a completion happens in a single file script, re-parse the whole
file. But we are still be able to reuse imported modules.

rdar://problem/58378157
2020-02-25 15:56:28 -08:00
Xi Ge
baa83f53d7 Merge pull request #30048 from nkcsgexi/disable-lock-file-interface-for-test
Front-end: add an option to not lock interface file when building module
2020-02-25 15:46:38 -08:00
Francis Visoiu Mistrih
e7b2850f52 [SIL][Remarks] Use camelCase for fields, arguments, and variables 2020-02-25 14:09:10 -08:00