Commit Graph

58361 Commits

Author SHA1 Message Date
Nathan Hawes
a368434432 [SourceKit/CodeFormat] Re-work and improve the indentation implementation.
This restructures the indentation logic around producing a single IndentContext
for the line being indented. An IndentContext has:
- a ContextLoc, which points to a source location to indent relative to,
- a Kind, indicating whether we should align with that location exactly, or
  with the start of the content on its containing line, and
- an IndentLevel with the relative number of levels to indent by.

It also improves the handling of:
- chained and nested parens, braces, square brackets and angle brackets, and
  how those interact with the exact alignment of parameters, call arguments,
  and tuple, array and dictionary elements.
- Indenting to the correct level after an incomplete expression, statement or
  decl.

Resolves:
rdar://problem/59135010
rdar://problem/25519439
rdar://problem/50137394
rdar://problem/48410444
rdar://problem/48643521
rdar://problem/42171947
rdar://problem/40130724
rdar://problem/41405163
rdar://problem/39367027
rdar://problem/36332430
rdar://problem/34464828
rdar://problem/33113738
rdar://problem/32314354
rdar://problem/30106520
rdar://problem/29773848
rdar://problem/27301544
rdar://problem/27776466
rdar://problem/27230819
rdar://problem/25490868
rdar://problem/23482354
rdar://problem/20193017
rdar://problem/47117735
rdar://problem/55950781
rdar://problem/55939440
rdar://problem/53247352
rdar://problem/54326612
rdar://problem/53131527
rdar://problem/48399673
rdar://problem/51361639
rdar://problem/58285950
rdar://problem/58286076
rdar://problem/53828204
rdar://problem/58286182
rdar://problem/58504167
rdar://problem/58286327
rdar://problem/53828026
rdar://problem/57623821
rdar://problem/56965360
rdar://problem/54470937
rdar://problem/55580761
rdar://problem/46928002
rdar://problem/35807378
rdar://problem/39397252
rdar://problem/26692035
rdar://problem/33760223
rdar://problem/48934744
rdar://problem/43315903
rdar://problem/24630624
2020-03-10 21:04:21 -07:00
Michael Gottesman
e3f2bb74d2 [inliner] Add a new Inliner that only inlines AlwaysInline functions (but do not put it in the pass pipeline).
We need this anyways for -Onone and I want to do some experiments with running
this very early so I can expose more of the stdlib (modulo inlining) to the new
ownership optimizing passes.

I also changed how the inliner handles inlining around OSSA by changing it to
check early that if the caller is in ossa, then we only inline if all of the
callees that the caller calls are in ossa. The intention is to hopefully avoid
weird swings in code-size/perf due to the inliner heuristic's calculation being
artificially manipulated due to some callees not being available to inline (due
to this difference) when others are already available.
2020-03-10 19:53:18 -07:00
Ashley Garland
5b6becf186 [SymbolGraph] Omit empty docComment fields
rdar://59500543
2020-03-10 19:37:39 -07:00
Rintaro Ishizaki
04c20b8b62 Merge pull request #30340 from apple/revert-29812-captureconv
Revert "Use in_guaranteed for let captures"
2020-03-10 18:35:45 -07:00
swift-ci
8e39711b35 Merge pull request #30338 from ravikandhadai/oslog-crash-in-unreachable-code 2020-03-10 17:50:48 -07:00
Michael Gottesman
7323ea95ea [semantic-arc-opts] Eliminate unneeded use of bisection that caused ASAN to fire.
I was being too clever here and in the process of "foot-gunned"
myself. Specifically, I was hoping to use bisection to do some is contained in
list tests. But the list that I actually bisected upon was not the original list
and was just based on the original sorted list! So the pointer comparison for
the bisect no longer worked. Since the bisection was on pointer addresses, if we
were lucky and the new addresses in the new array were sorted the same as the
original array, we wouldn't hit anything.

rdar://60262326
2020-03-10 16:52:58 -07:00
Michael Gottesman
6b88599412 Revert "Merge pull request #30327 from rintaro/revert-30289"
This reverts commit 0a6ccd802f, reversing
changes made to 7c5d74e86b.
2020-03-10 16:52:58 -07:00
Saleem Abdulrasool
e229468fd0 Merge pull request #30292 from compnerd/sr-9138
IRGen: improve DLLStorage computation for Windows
2020-03-10 16:50:07 -07:00
Rintaro Ishizaki
ccbc26d947 Revert "Use in_guaranteed for let captures (#29812)"
This reverts commit 13b9915c6f.
2020-03-10 16:08:08 -07:00
Ravi Kandhadai
020c8281c2 [OSLogOptimization] Prevent the OSLogOptimization pass from crashing
when the log calls are invoked in unreachable code.

<rdar://problem/60014600>
2020-03-10 15:48:56 -07:00
Joe Groff
9e12b3749e Dump component types of SILFunctionType 2020-03-10 15:19:56 -07:00
Xi Ge
411833d931 PrintAsObjc: strip Headers and PrivateHeaders component in header paths explicitly
We use Header::NameAsWritten to collect the path of a header belongs to a module. Due
to an unclear clang-side issue, the path may contain "Headers/" and "PrivateHeaders/". To
walk-around this potential issue, we explicit check and remove these path components
from the Swift side.

rdar://problem/60249751
2020-03-10 14:30:09 -07:00
Pavel Yaskevich
f1f3b60713 [CSGen] Clarify locators for some of the patterns
- optional object type of `.some` pattern ends with `OptionalPayload`
- type of sub-pattern used in a cast points to underlying sub-pattern declaration
- Enum element:
  - parent type locator ends with `ParentType`
  - member lookup constraint locator ends at `Member`
2020-03-10 13:56:32 -07:00
Meghana Gupta
13b9915c6f Use in_guaranteed for let captures (#29812)
* Use in_guaranteed for let captures

With this all let values will be captured with in_guaranteed convention
by the closure. Following are the main changes :

SILGen changes:
- A new CaptureKind::Immutable is introduced, to capture let values as in_guaranteed.
- SILGen of in_guaranteed capture had to be fixed.
  in_guaranteed captures as per convention are consumed by the closure. And so SILGen should not generate a destroy_addr for an in_guaranteed capture.
  But LetValueInitialization can push Dealloc and Release states of the captured arg in the Cleanup stack, and there is no way to access the CleanupHandle and disable the emission of destroy_addr while emitting the captures in SILGenFunction::emitCaptures.
  So we now create, temporary allocation of the in_guaranteed capture iduring SILGenFunction::emitCaptures without emitting destroy_addr for it.

SILOptimizer changes:
- Handle in_guaranteed in CopyForwarding.
- Adjust dealloc_stack of in_guaranteed capture to occur after destroy_addr for on_stack closures in ClosureLifetimeFixup.

IRGen changes :
  - Since HeapLayout can be non-fixed now, make sure emitSize is used conditionally
  - Don't consider ClassPointerSource kind parameter type for fulfillments while generating code for partial apply forwarder.
    The TypeMetadata of ClassPointSource kind sources are not populated in HeapLayout's NecessaryBindings. If we have a generic parameter on the HeapLayout which can be fulfilled by a ClassPointerSource, its TypeMetaData will not be found while constructing the dtor function of the HeapLayout.
    So it is important to skip considering sources of ClassPointerSource kind, so that TypeMetadata of a dependent generic parameters gets populated in HeapLayout's NecessaryBindings.
2020-03-10 12:23:02 -07:00
AG
aeabe2884e Merge pull request #30317 from bitjammer/acgarland/rdar-60091161-conditional-conformance
[SymbolGraph] Track conditional conformance
2020-03-10 12:05:41 -07:00
Kuba (Brecka) Mracek
c728d7a4d2 Fix failing IRGen arm64e tests (#30296) 2020-03-10 11:22:54 -07:00
Pavel Yaskevich
aa35a500a8 Merge pull request #30328 from apple/revert-30164-fix/SR-12290
Revert "[Typechecker] Diagnose key paths with contextual root type but no leading dot"
2020-03-10 11:00:24 -07:00
John McCall
81ba9fd223 Merge pull request #30309 from rjmccall/accessor-subst-function-types
Use pattern substitutions to consistently abstract yields
2020-03-10 13:05:28 -04:00
Holly Borla
b12bd4e919 Merge pull request #30307 from hborla/merge-partial-solutions-too-complex
[ConstraintSystem] Respect the constraint solver performance thresholds,
2020-03-10 09:44:32 -07:00
Rintaro Ishizaki
1046516844 Merge pull request #30310 from rintaro/ide-completion-typeexprcall-rdar53516588
[CodeCompletion] Re-typecheck TypeExpr without call arguments
2020-03-10 09:38:18 -07:00
Pavel Yaskevich
e86558fe4f Merge pull request #30277 from LucianoPAlmeida/SR-12019-dynamically-call-generic-constraint
[SR-12019] Fix assert when dynamicallyCall parameter does not satisfy generic constraint
2020-03-10 09:12:33 -07:00
Pavel Yaskevich
2374502a04 Revert "[Typechecker] Diagnose key paths with contextual type but no leading dot (#30164)"
This reverts commit 13487edd09.
2020-03-10 09:06:50 -07:00
Rintaro Ishizaki
fad1b431c2 Revert "[semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers."
This reverts commit 6fee59bd6a.
2020-03-10 08:43:46 -07:00
Rintaro Ishizaki
7f426d15a8 Revert "[semantic-arc-opts] Refactor out reinitializing the worklist into method drainVisitedSinceLastMutationIntoWorklist and add some types/comments."
This reverts commit d0d31f7d0d.
2020-03-10 08:43:20 -07:00
Dmitri Gribenko
6813762642 [SILGen] Remove incomplete support for generic bridging functions in getBridgingFn
getBridgingFn was implementing some incomplete support for generic
bridging functions, but it was not used anyway.
2020-03-10 14:44:23 +01:00
swift-ci
1a7e4397bd Merge pull request #30320 from gottesmm/pr-29b49f7445fdc16950dbb3bcdbb7d3a503a6b3a5 2020-03-10 00:13:12 -07:00
Michael Gottesman
ab9416b068 Merge pull request #30314 from gottesmm/pr-fd797f09f7fb277ea2c75a81fc46eb41b059bc38
[ownership] Now that cond_br only takes trivial operands in ossa, eliminate all special code for handling it.
2020-03-09 23:57:43 -07:00
Michael Gottesman
d0d31f7d0d [semantic-arc-opts] Refactor out reinitializing the worklist into method drainVisitedSinceLastMutationIntoWorklist and add some types/comments.
I was doing this in two places. It makes sense to refactor it out as such.
2020-03-09 22:30:28 -07:00
John McCall
07f03bd287 Use pattern substitutions to consistently abstract yields.
The design implemented in this patch is that we lower the types of accessors with pattern substitutions when lowering them against a different accessor, which happens with class overrides and protocol witnesses, and that we introduce pattern substitutions when substituting into a non-patterned coroutine type.  This seems to achieve consistent abstraction without introduce a ton of new complexity.

An earlier version of this patch tried to define witness thunks (conservatively, just for accessors) by simply applying the requirement substitutions directly to the requirement.  Conceptually that should work, but I ran into a lot of trouble with things that assumed that pattern substitutions didn't conceal significant substitution work.  for example, resolving a dependent member in a component type could find a new use of an opaque archetype when the code assumed that such types had already been substituted away.  So while I think that is definiteely a promising direction, I had to back that out in order to make the number of changes manageable for a single PR.

As part of this, I had to fix a number of little bugs here and there, some of which I just introduced.  One of these bugfixes is a place where the substitution code was trying to improperly abstract function types when substituting them in for a type parameter, and it's been in the code for a really long time, and I'm really not sure how it's never blown up before.

I'm increasingly of the opinion that invocation substitutions are not actually necessary, but that --- after we've solved the substitution issues above --- we may want the ability to build multiple levels of pattern substitution so that we can guarantee that e.g. witness thunks always have the exact component structure of the requirement before a certain level of substitution, thus allowing the witness substitutions to be easily extracted.
2020-03-10 01:26:31 -04:00
Michael Gottesman
cee2af0ac9 Merge pull request #30289 from gottesmm/pr-645bd01cfa67ffe64ed23d74e1ee1333fce6ba8a
[semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers.
2020-03-09 21:55:28 -07:00
Doug Gregor
f0530d0a77 [Function builders] Support buildOptional(_:) in lieu of buildIf(_:).
Line up with the function builders pitch, which uses buildOptional(_:)
to build optional values.
2020-03-09 21:48:15 -07:00
Ashley Garland
7ce6753231 [SymbolGraph] Track conditional conformance
Requirements on extensions were only being gathered indirectly. This adds a new
optional field to `conformsTo` relationship edges, `swiftConstraints`, which
provides the requirements there.

rdar://60091161
2020-03-09 20:06:49 -07:00
Argyrios Kyrtzidis
21e1fc4039 [AST/ASTMangler] Fix linker error for SWIFT_BUILD_ONLY_SYNTAXPARSERLIB build
With such a build we avoid linking the `clangAST` library.
2020-03-09 19:43:37 -07:00
John McCall
eea07b318d Preserve PrettyStackTrace context in the interface worker thread.
Because we block the calling thread, this should be safe for the existing
implementation of PrettyStackTrace; however, it would be much nicer if
LLVM provided direct support for this.

The most important thing from the trace that we want to print is the
original command line, so an alternative would be to just make a
PrettyStackTrace that printed all of the CompilerInvocation context;
I think that's accessible somewhere.  But this is a nice, simple
improvement.
2020-03-09 22:13:36 -04:00
Luciano Almeida
01145c04aa [Type] Return early on hasDynamicCallable/DynamicMemberLookup if it may not have members 2020-03-09 22:59:59 -03:00
Michael Gottesman
5d52fd2def [ownership] Now that cond_br only takes trivial operands in ossa, eliminate all special code for handling it.
I banned this in an earlier commit since it wasn't really useful and introduced
a bunch of unneeded complexity into the ownership system (namely the name for
BranchPropagatedUser). Now that we are free of that, we can clean up the
ownership code and just treat cond_br simply! I left in a special section in
OperandOwnership so I could put in a nice comment there.
2020-03-09 18:52:57 -07:00
Alexis Laferrière
685d35b7d1 Merge pull request #30306 from xymus/print-objc-ext
[PrintAsObjC] Don't print imports for empty extensions
2020-03-09 16:52:18 -07:00
Andrew Trick
c34625779b Disable LetPropertiesOpt on struct 'let's.
This pass makes assumptions about the visibility of a type's memory
based on the visibility of its properties. This is the wrong way to
think about memory visibility.

Fixes <rdar://57564377> Struct component with 'let', unexpected
behavior

This pass wants assume that the contents of a property is known based
on whether the property is declared as a 'let' and the visibility of
the initializers that access the property. For example:

```
public struct X<T> {
  public let hidden: T

  init(t: T) { self.hidden = t }
}
```

The pass currently assumes that `X` only takes on values that are
assigned by the invocations of `X.init`, which is only visible in `X`s
module. This is wrong if the layout of `Impl` is exposed to other
modules. A struct's memory may be initialized by any module with
access to the struct's layout.

In fact, this assumption is wrong even if the struct, and it's let
property cannot be accessed externally by name. In this next example,
external modules cannot access `Impl` or `Impl.hidden` by name, but
can still access the memory.

```
internal struct Impl<T> {
  let hidden: T

  init(t: T) { self.hidden = t }
}

public struct Wrapper<T> {
  var impl: Impl<T>

  public var property: T {
    get {
      return impl.hidden
    }
  }
}
```

As long as `Wrapper`s layout is exposed to other modules, the contents
of `Wrapper`, `Impl`, and `hidden' can all be initialized in another
module

```
// Legal as long Wrapper's home module is *not* built with library evolution
// (or if Wrapper is declared `@frozen`).
func inExternalModule(buffer: UnsafeRawPointer) -> Wrapper<Int64> {
  return buffer.load(as: Wrapper<Int64>.self)
}
```

If library evolution is enabled and a `public` struct is not declared
`@frozen` then external modules cannot assume its layout, and therefore
cannot initialize the struct memory. In that case, it is possible to optimize
`X.hidden` and `Impl.hidden` as if the properties are only initialized inside
their home module.

The right way to view a type's memory visibility is to consider whether
external modules have access to the layout of the type. If not, then the
property can still be optimized As long as a struct is never enclosed in a
public effectively-`@frozen` type. However, finding all places where a struct
is explicitly created is still insufficient. Instead, the optimization needs
to find all uses of enclosing types and determine if every use has a known
constant initialization, or is simply copied from another value. If an
escaping unsafe pointer to any enclosing type is created, then the
optimization is not valid.

When viewed this way, the fact that a property is declared 'let' is mostly
irrelevant to this optimization--it can be expanded to handle non-'let'
properties. The more salient feature is whether the propery has a public
setter.

For now, this optimization only recognizes class properties because class
properties are only accessibly via a ref_element_addr instruction. This is a
side effect of the fact that accessing a class property requires a "formal
access". This means that begin_access marker must be emitted directly on the
address produced by a ref_element_addr. Struct properties are not handled, as
explained above, because they can be indirectly accessed via addresses of
outer types.
2020-03-09 16:20:01 -07:00
Michael Gottesman
6fee59bd6a [semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers.
This is the most simple initial version that I can commit. The hope is that this will help to bring this up in a nice way.

I am going to handle the multiple phi node and load [copy] case later to reduce
code churn.

<rdar://problem/56720436>
2020-03-09 16:04:48 -07:00
Michael Gottesman
20c026767a Merge pull request #30299 from gottesmm/pr-59c23cc931f2998f402e6f70662ccf3f70922c3b
[temp-rvalueopt] Teach how to promote fix_lifetime.
2020-03-09 15:56:11 -07:00
Rintaro Ishizaki
8f7340cd6e [CodeCompletion] Re-typecheck TypeExpr without call arguments
Call arguments sometimes affect the inference for the generic parameters of the
type expression. When we want to show all initializers from all
extensions, we do not want to infer any generic arguments.

rdar://problem/53516588
2020-03-09 15:48:54 -07:00
Pavel Yaskevich
9ce4b60fef Merge pull request #30297 from xedin/diagnose-gp-conflicts-for-reprs
[ConstraintSystem] Diagnose argument conflicts only for "representati…
2020-03-09 14:49:59 -07:00
Holly Borla
c1c6a884a4 [ConstraintSystem] Respect the constraint solver performance thresholds,
including time and allocated memory, in mergePartialSolutions.
2020-03-09 14:44:12 -07:00
Alexis Laferrière
8f01b2c8f8 [PrintAsObjC] Don't include the module for empty extensions
rdar://problem/57133517
2020-03-09 14:10:44 -07:00
Alexis Laferrière
d11232b96e [PrintAsObjC] NFC Document and make isEmptyExtensionDecl public 2020-03-09 14:09:21 -07:00
swift-ci
be61002ad2 Merge pull request #30279 from zoecarver/fix/eager-spec-no-ownership 2020-03-09 14:05:49 -07:00
Michael Gottesman
7c403ed4df [temp-rvalueopt] Teach how to promote fix_lifetime.
In the case of copy_addr, we move it onto the source address and in the case of
a store, put it on the source object.

I just noted this pattern happening a bunch in the stdlib when I was looking
through it for ownership patterns.
2020-03-09 12:29:56 -07:00
Pavel Yaskevich
4a06b13abf [ConstraintSystem] Diagnose argument conflicts only for "representative" generic parameters
Consider following example:

```swift
struct MyType<TyA, TyB> {
  var a : TyA, b : TyB
}

typealias B<T1> = MyType<T1, T1>

_ = B(a: "foo", b: 42)
```

Here `T1` is equal to `TyA` and `TyB` so diagnostic about
conflicting arguments ('String' vs. 'Int') should only be
produced for "representative" `T1`.
2020-03-09 12:10:29 -07:00
swift-ci
883d546dda Merge pull request #30291 from gottesmm/pr-20d3a11a596c39f79b461a829ff03722b9755ec9 2020-03-09 01:02:03 -07:00
Doug Gregor
ce97d22f21 [Function builders] Add support for buildFinalResult().
When present in a function builder, buildFinalResult() will be called on
the value of the outermost block to form the final result of the closure.
This allows one to collapse the full function builder computation into
a single result without having to do it in each buildBlock() call.
2020-03-09 00:10:07 -07:00