Commit Graph

58361 Commits

Author SHA1 Message Date
Michael Gottesman
e9896fb3da [ownership] Change init_existential_ref to be forwarding for both guaranteed and owned.
Otherwise in call frames like the one in the test in this commit get unneeded
ARC traffic. We should never pessimize read only code that doesnt need
side-effects with side-effects if we can avoid it.

I am seeing this a bunch when I look at SIL from projects that use a lot of
protocols. Specifically, one has a sort of trampoline code that wraps a ref
counted object in an existential ref container (which from an ARC perspective
doesn't imply ownership) and then calls a method on it or passes it off to some
other code.

Because of this requirement, there is a copy/destroy that can not be eliminated
unless we can devirt/inline/eliminate the init_existential_ref box, inline
enough that the low level ARC optimizer can hit it. We shouldn't rely on such
properties if we do not need to.
2020-03-08 23:21:57 -07:00
Michael Gottesman
dae4c0b015 [temp-rvalue] Teach how to optimize unchecked_take_enum_data_addr of an Optional type.
unchecked_take_enum_data_addr only writes to memory in certain cases. Optional
is not one of those cases luckily.

Given that I am adding support here just for optionals so that we can get rid of
temporaries that are used with a switch_enum_addr. This is an example of a case
where we need to eliminate temporary allocations to allow for Semantic ARC Opts
to eliminate further traffic.
2020-03-08 19:54:19 -07:00
Saleem Abdulrasool
29c00f6969 IRGen: improve DLLStorage computation for Windows
This slightly regresses the standard library build (intentionally) while
generally improving the build of dispatch, foundation, xctest.

Rather than continuing to rely on the short-term hack of special casing
the standard library, identify the module where the decl originates
from.  If the module is the current module, then assume that the symbol
need not be imported (static linking does not currently work on Windows
anyways).  This allows for properly identifying the module where the
symbol will be homed.

Because we no longer special case the standard library here, a few known
metadata types will be incorrectly marked as being imported rather than
local.

Since linked entities which have `Shared` SILLinkage should be module
local, special case them to always be local.  Without this the metadata
access function is still marked incorrectly.

With this computation we now get nearly all the cases correct.  Dispatch
no longer has to rely on the linker relaxing the import to a local
binding.  XCTest is also clean.  Foundation misses the following case:
- `$sSS10FoundationE19_bridgeToObjectiveCAA8NSStringCyF`

The regressed cases in swiftCore are:
- `$sBi64_WV`
- `$sBi8_WV`
- `$sBi16_WV`
- `$sBi32_WV`
- `$sBpWV`
- `$syycWV`
- `$sBoWV`
- `$sBOWV`
- `$sBbWV`
- `$sytWV`
2020-03-08 19:24:29 -07:00
Luciano Almeida
6ca7e383a9 [tests] Add more test cases for SR-12019 dynamic callable 2020-03-08 22:56:26 -03:00
Michael Gottesman
cb9b64f169 [temp-rvalueopt] Extract out visiting projections from loads into a helper and use that instead of LLVM_FALLTHROUGH.
Using fallthroughs in general can lead to easy mistakes. This PR changes the
relevant code to use a helper instead. The reason why is that I am about to add
another instance of needing this exact helper and having to fall through
multiple switch cases will just make this even worse.
2020-03-08 18:08:52 -07:00
Luciano Almeida
f796e27b65 [TypeChecker] Requestify DynamicCallableAttribute check 2020-03-08 20:44:23 -03:00
John McCall
3a9969ce0c Merge pull request #30284 from rjmccall/contextually-canonical-abstraction-patterns
Require types to be contextually canonical in AbstractionPatterns
2020-03-08 11:59:36 -04:00
John McCall
be576c6246 Require types to be contextually canonical in AbstractionPatterns.
Because violations of this might have made an AbstractionPattern incorrectly show up as abstract, it's possible that this will cause an ABI change.  However, I haven't been able to find any examples where it does, and certainly there's no way we can promise to maintain the old behavior, especially since it's not done consistently.
2020-03-08 01:37:49 -05:00
Pavel Yaskevich
a1987ec274 Merge pull request #30283 from xedin/rdar-60185506
Revert "[ConstraintSystem] Make it possible to infer subtype bindings…
2020-03-07 22:34:10 -08:00
Kuba (Brecka) Mracek
b2edf20a81 Merge pull request #30112 from apple/mracek/arm64e
Add arm64e and pointer authentication support for Swift
2020-03-07 20:38:36 -08:00
Pavel Yaskevich
0ecedfa5ea Revert "[ConstraintSystem] Make it possible to infer subtype bindings through argument conversions"
Reverts apple/swift#30006. It caused a regression that we'd like to address before re-landing:

```swift
struct X {
  var cgf: CGFloat
}

func test(x: X?) {
  let _ = (x?.cgf ?? 0) <= 0.5
}
```

This reverts commit 0a6b444b49.
This reverts commit ed255596a6.
This reverts commit 3e01160a2f.
This reverts commit 96297b7e39.

Resolves: rdar://problem/60185506
2020-03-07 20:16:56 -08:00
John McCall
1f62fe591f Merge pull request #30272 from rjmccall/invocation-sil-function-subs
Distinguish invocation and pattern substitutions on SILFunctionType
2020-03-07 18:45:29 -05:00
Kuba Mracek
8a4a226cd6 Undo unintentional llvm::MaybeAlign changes 2020-03-07 13:44:16 -08:00
John McCall
ceff414820 Distinguish invocation and pattern substitutions on SILFunctionType.
In order to allow this, I've had to rework the syntax of substituted function types; what was previously spelled `<T> in () -> T for <X>` is now spelled `@substituted <T> () -> T for <X>`.  I think this is a nice improvement for readability, but it did require me to churn a lot of test cases.

Distinguishing the substitutions has two chief advantages over the existing representation.  First, the semantics seem quite a bit clearer at use points; the `implicit` bit was very subtle and not always obvious how to use.  More importantly, it allows the expression of generic function types that must satisfy a particular generic abstraction pattern, which was otherwise impossible to express.

As an example of the latter, consider the following protocol conformance:

```
protocol P { func foo() }
struct A<T> : P { func foo() {} }
```

The lowered signature of `P.foo` is `<Self: P> (@in_guaranteed Self) -> ()`.  Without this change, the lowered signature of `A.foo`'s witness would be `<T> (@in_guaranteed A<T>) -> ()`, which does not preserve information about the conformance substitution in any useful way.  With this change, the lowered signature of this witness could be `<T> @substituted <Self: P> (@in_guaranteed Self) -> () for <A<T>>`, which nicely preserves the exact substitutions which relate the witness to the requirement.

When we adopt this, it will both obviate the need for the special witness-table conformance field in SILFunctionType and make it far simpler for the SILOptimizer to devirtualize witness methods.  This patch does not actually take that step, however; it merely makes it possible to do so.

As another piece of unfinished business, while `SILFunctionType::substGenericArgs()` conceptually ought to simply set the given substitutions as the invocation substitutions, that would disturb a number of places that expect that method to produce an unsubstituted type.  This patch only set invocation arguments when the generic type is a substituted type, which we currently never produce in type-lowering.

My plan is to start by producing substituted function types for accessors.  Accessors are an important case because the coroutine continuation function is essentially an implicit component of the function type which the current substitution rules simply erase the intended abstraction of.  They're also used in narrower ways that should exercise less of the optimizer.
2020-03-07 16:25:59 -05:00
zoecarver
ad7fed0855 Eager specilization shouldn't optimize functions with ownership (yet) 2020-03-07 12:12:15 -08:00
Luciano Almeida
6df132de1a [ConstraintSystem] Make getCalleLocator to support an apply involving an dynamicCallable 2020-03-07 16:43:37 -03:00
Robert Widmann
9046799a2c Merge pull request #30274 from CodaFi/the-mac-in-the-mirror
[ObjC] Only Diagnose Selector Conflicts From Classes
2020-03-06 22:19:49 -08:00
Xi Ge
a09b6418a0 Merge pull request #30267 from nkcsgexi/tbd-category
TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes
2020-03-06 18:48:52 -08:00
Robert Widmann
bf6fe033ad [ObjC] Only Diagnose Selector Conflicts From Classes
Clang 1200 appears to be returning us results from protocol
declarations when we run lookup for an Objective-C selector. This code
path can therefore see protocol requirements, and would erroneously
diagnose witnesses from Swift subclasses of Objective-C classes
as an attempt to conflict with the requirement in the
protocol itself.

This fix is super narrow to try to unblock our builds. Tests will follow
once I can reduce the issue.

Resolves rdar://60005962
2020-03-06 18:30:15 -08:00
Xi Ge
699e05712f TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes
rdar://60057489
2020-03-06 16:07:57 -08:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
Slava Pestov
adbf8da7c2 Merge pull request #23489 from AnthonyLatsis/where-clause-nongeneric-decl
[SE] Allow where clauses on non-generic declarations in generic contexts
2020-03-06 17:53:14 -05:00
Michael Gottesman
491f826263 [ownership] Implement getSingleOwnedValueIntroducer and getAllOwnedValueIntroducers().
These enable robust walking up the def-use ossa graph to find the value that
introduces an independent underlying owned value, looking through forwarding
insts.
2020-03-06 12:01:13 -08:00
Pavel Yaskevich
c825ed8481 Merge pull request #30262 from xedin/remove-basecs
ConstraintSystem] Remove `baseCS` since CSDiag has been removed
2020-03-06 11:48:46 -08:00
Pavel Yaskevich
e4d3eaaf2a [ConstraintSystem] Don't store base constraint system in shrink candidate
Since there is no more sub-expression re-typechecking solver wouldn't
be trying to ran shrink on sub-expressions.
2020-03-06 09:46:12 -08:00
Pavel Yaskevich
7c19d1ccd1 [ConstraintSystem] Remove baseCS since CSDiag has been removed
There is no more sub-expression re-typechecking so no need to keep
parent constraint systems around.
2020-03-06 09:35:52 -08:00
lhames
1d5c008f97 Merge pull request #29863 from lhames/switch-imm-to-lljit
[Immediate] Switch immediate mode from MCJIT to LLJIT.
2020-03-06 09:12:27 -08:00
Doug Gregor
b2facd0331 Merge pull request #30258 from DougGregor/constraint-pattern-locators
[Constraint system] Clean up constraints associated with patterns.
2020-03-06 09:11:15 -08:00
Joe Groff
58950a576a Merge pull request #30250 from jckarter/mangle-objc-runtime-names
IRGen: Generate runtime type manglings using ObjC runtime names.
2020-03-06 07:33:19 -08:00
Brent Royal-Gordon
2cc9446482 Merge pull request #29412 from brentdax/two-revisions-for-slashing
[SE-0274] Update concise #file implementation in response to first round of review
2020-03-06 02:56:16 -08:00
Michael Gottesman
c4ed7bd0be Merge pull request #30249 from gottesmm/pr-1c59567660f53bc35248d864c54d25e2760a74d0
[ownership] Implement InteriorPointer abstraction/validate current recognized ones addresses are not used outside of parent object's borrowed lifetime.
2020-03-06 02:54:29 -08:00
Brent Royal-Gordon
d590823f3c Warn about conflicts between #file strings 2020-03-05 23:30:37 -08:00
Doug Gregor
1a981f917c [Constraint system] Clean up constraints associated with patterns.
Wherever we have constraints that involve pattern matching, use the
PatternMatch locator element. Additionally, don't use the TupleElement
locator element for tuple patterns, because it violates assumptions used
for diagnostics.

The new test was crashing; now it has a terrible diagnostic for which I
need to think harder about a fix.
2020-03-05 23:06:21 -08:00
Michael Gottesman
7942cbfe17 Merge pull request #30256 from gottesmm/pr-e7fa33950f580ee9f3bec78206e04a430971107d
[silargument] Implement getIncomingPhiOperand methods and reimplement getIncomingPhiValue methods ontop.
2020-03-05 23:01:38 -08:00
Doug Gregor
60cf68fcfe Merge pull request #30254 from DougGregor/cursed-dual-identities
[Clang importer] Suppress method imports found via selector lookup.
2020-03-05 22:59:21 -08:00
Doug Gregor
6a5069d017 Merge pull request #30245 from xedin/rdar-60061646
[ConstraintSystem] Make sure pattern matching tuple destructuring works both ways
2020-03-05 21:48:30 -08:00
Michael Gottesman
0aec5a7f43 [ownership] Implement InteriorPointer abstraction/validate current recognized ones addresses are not used outside of parent object's borrowed lifetime.
Currently, we only classify ref_element_addr and ref_tail_addr. But we should
expand this to project_box, project_existential_box and open_existential_box as
well.
2020-03-05 20:28:59 -08:00
Michael Gottesman
bd68964c41 [silargument] Implement getIncomingPhiOperand methods and reimplement getIncomingPhiValue methods ontop.
Operands are generally better to return than values since the operand also
enables you to get to the terminator instruction as well. Since so much code in
the compiler already uses the getIncomingPhiValue methods, I reimplemented them
on top of the operand methods.
2020-03-05 19:47:41 -08:00
Ravi Kandhadai
fd77ae9a9c [Constant Evaluator] Make the constant evaluator skip tsan
instrumentation builtin: tsanInoutAccess
2020-03-05 18:52:30 -08:00
Doug Gregor
c84bec752f [Clang importer] Suppress method imports found via selector lookup.
When we found Objective-C methods via selector lookup, we would skip the
“should we even try to import this?” check. If the Swift-name-as-derived-
from-Objective-C is different from the actual Swift name, we might try to
(redundantly) import something from the generated Objective-C header,
which can lead to crashes. The specific method causing problems was defined
like this in Swift:

    @objc public class func using(index: AnyObject) -> AnyObject? { return nil }

which produced an Objective-C method like this:

    + (id _Nullable)usingIndex:(id _Nonnull)index;

The Swift name derived from the Objective-C method is `usingIndex(_:)`, which
of course does not match `using(index:)`, meaning that we think these two
methods are different (they aren’t).

The safe fix is to check whether we should import a given Objective-C method
declaration along the found-via-Objective-C-selector path, like we do with
normal name lookup. A longer term fix is to emit swift_name attributes for
such methods.

Fixes the fiendish Clang importer crash in rdar://problem/60046206.
2020-03-05 18:34:29 -08:00
Owen Voorhees
d68089dcf9 [Diagnostics] Add a basic terminal markdown printer for educational notes
Currently the printer only supports the subset of markdown used by
educational notes. It bolds headers, improves the appearance of lists
and horizontal rules, and does basic indenting of blockquotes and
code blocks.
2020-03-05 18:04:32 -08:00
Brent Royal-Gordon
54f5967d48 Include #file -> #filePath table in printed SIL
A proof of concept for tools providing this information in more useful forms.
2020-03-05 17:23:44 -08:00
Brent Royal-Gordon
8e5ca8abdf [NFC] Generate #file -> #filePath table ahead of time 2020-03-05 17:23:44 -08:00
Joe Groff
fe1186447b IRGen: Generate runtime type manglings using ObjC runtime names.
In order for the runtime demangler to be able to find ObjC classes and protocols, it needs to
have the runtime name of the declaration be in the mangled name. Only do this for runtime manglings,
to minimize the potential ABI impact for symbol names that already have the source-level names of
ObjC entities baked in. Fixes SR-12169 | rdar://59306590.
2020-03-05 16:55:00 -08:00
Holly Borla
f8de43b63b Merge pull request #30251 from hborla/invalid-optional-chaining
[ConstraintSystem] Don't assume the lhs type is for a generic parameter in simplifyConformsToConstraint.
2020-03-05 16:45:37 -08:00
Brent Royal-Gordon
f34fa7ffcd Match prototype’s #file string format to upcoming SE-0274 revision 2020-03-05 16:01:13 -08:00
Holly Borla
f77ea028b8 Merge pull request #30248 from hborla/unnamed-closure-param
[Parse] Mark closure parameters as definitively not destructured in parseClosureSignatureIfPresent.
2020-03-05 15:35:25 -08:00
Xi Ge
683d13d44d Merge pull request #30241 from nkcsgexi/reapply-zippered
Re-apply "TBDGen: pass-down target variant when generating textual interface stubs"
2020-03-05 15:22:04 -08:00
Holly Borla
6898fbb0ef [ConstraintSystem] Don't assume the lhs type is for a
generic parameter in simplifyConformsToConstraint.
2020-03-05 14:39:30 -08:00
Robert Widmann
16c01fedea Merge pull request #30246 from owenv/dependency-verifier-diags
[DependencyVerifier] Route DependencyVerifier diags through DiagnosticEngine
2020-03-05 14:39:20 -08:00