Commit Graph

2768 Commits

Author SHA1 Message Date
swift-ci
b76e9ec111 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 19:49:09 -07:00
Ravi Kandhadai
22861ec0fd [Constant Evaluator] Pass assert configuartion option to the
evaluator to precisely evaluate Builtin.assert_configuration.

Unify UnknownReason::Trap and UnknownReason::AssertionFailure error
values in the constant evaluator, now that we have 'condfail_message'
SIL instruction, which provides an error message for the traps.
2019-09-18 17:35:46 -07:00
swift-ci
06e6ab4b60 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 16:09:50 -07:00
Ravi Kandhadai
61fd4b1431 [OSLog][Test] Update the new oslog overlay implementation to use
@_semantics("constant_evaluable") annotation to denote constant
evaluable functions.

Add a test suite that uses the sil-opt pass ConstantEvaluableSubsetChecker.cpp
to check the constant evaluability of function in the OSLog
overlay.
2019-09-18 10:44:48 -07:00
swift-ci
1fdda8eaa8 Merge remote-tracking branch 'origin/master' into master-next 2019-09-17 19:09:48 -07:00
Ravi Kandhadai
032442da93 [Constant Evaluator] Add a new sil-opt pass to check constant evaluability
of Swift code snippets. Add a new test: constant_evaluable_subset_test.swift
that tests Swift code snippets that are expected to be constant evaluable and
those that are not.
2019-09-16 18:49:19 -07:00
Ravi Kandhadai
b59cc7ad6a [Constant Evaluator] Add support to the constant evaluator for:
1. builtin "int_expect", which makes the evaluator work on more
integer operations such as left/right shift (with traps) and
integer conversions.

2. builtin "_assertConfiguration", which enables the evaluator
to work with debug stdlib.

3. builtin "ptrtoint", which enables the evaluator to track
StaticString

4. _assertionFailure API, which enables the evaluator to report
stdlib assertion failures encountered during constant evaluation.

Also, enable attaching auxiliary data with the enum "UnknownReason"
and use it to improve diagnostics for UnknownSymbolicValues,
which represent failures during constant evaluation.
2019-09-16 15:12:22 -07:00
swift-ci
40040f74dc Merge remote-tracking branch 'origin/master' into master-next 2019-09-13 18:30:39 -07:00
Joe Groff
413100be33 Merge pull request #27181 from jckarter/demangler-symbolic-reference-api-refactor
Demangler: Make symbolic reference resolver part of `demangle(Symbol|Type)` calls.
2019-09-13 18:12:04 -07:00
Joe Groff
f1e84994ed Demangler: Make symbolic reference resolver part of demangle(Symbol|Type) calls.
This makes for a cleaner and less implicit-context-heavy API, and makes it easier for symbolic
reference resolvers to do context-dependent things (like map the in-memory base address back to a
remote address in MetadataReader).
2019-09-13 15:47:08 -07:00
swift-ci
0ef2397dab Merge remote-tracking branch 'origin/master' into master-next 2019-09-12 07:50:20 -07:00
Erik Eckstein
8cdeb45284 StackNesting: fix a corner case crash related to unreachable blocks
When deallocs are inserted at block boundaries, it's necessary to recompute the data flow.

rdar://problem/55249524
2019-09-12 13:08:31 +02:00
swift-ci
b2a97c7cb9 Merge remote-tracking branch 'origin/master' into master-next 2019-09-10 01:50:39 -07:00
Erik Eckstein
d07593b352 PerformanceInliner: enable generic inlining of co-routines
Co-routines are so expensive (e.g. Array.subscript.read) that it makes sense to enable generic inlining of co-routines.
This will speed up array iteration (e.g. for elem in array { }) in a generic context significantly.
Another example is ManagedBuffer.header.read, which gets much faster.
In both cases, the speedup is mainly because there is no malloc happening anymore.

https://bugs.swift.org/browse/SR-11231
rdar://problem/53777612
2019-09-09 19:18:31 +02:00
Mike Ash
f5e7ab866c Merge branch 'master' into master-next 2019-09-09 12:11:25 -04:00
Slava Pestov
d434188157 SIL: Refactor TypeConverter to not require a SILModule
This mostly requires changing various entry points to pass around a
TypeConverter instead of a SILModule. I've left behind entry points
that take a SILModule for a few methods like SILType::subst() to
avoid creating even more churn.
2019-09-06 21:50:15 -04:00
Slava Pestov
1e94466bcc AST: Replace GenericSignature::createGenericEnvironment() with getGenericEnvironment()
This memoizes the result, which is fine for all callers; the only
exception is open existential types where each new open existential
now explicitly gets a unique generic environment, allocated by
calling GenericEnvironment::getIncomplete().
2019-09-06 17:16:03 -04:00
swift-ci
29220ca204 Merge remote-tracking branch 'origin/master' into master-next 2019-09-04 15:29:49 -07:00
Slava Pestov
22cb6f1176 AST: Introduce ProtocolDecl::get{AssociatedType,ProtocolRequirement}() 2019-09-03 22:39:35 -04:00
swift-ci
333320679f Merge remote-tracking branch 'origin/master' into master-next 2019-08-28 19:30:21 -07:00
Nikolai Vazquez
931ab4633b Remove unused call to constantFoldIsConcrete 2019-08-27 16:51:10 -07:00
Nikolai Vazquez
c4cd641cbf Fix variable reference in ConstantFolding phase 2019-08-27 16:51:09 -07:00
Nikolai Vazquez
ba0612f2e9 Add Builtin.isConcrete<T>(T.Type) -> Int1
Returns `true` if `T.Type` is known to refer to a concrete type. The
implementation allows for the optimizer to specialize this at -O and
eliminate conditional code.

Includes `Swift._isConcrete<T>(T.Type) -> Bool` wrapper function.
2019-08-27 16:51:09 -07:00
Arnold Schwaighofer
20efacf2d6 Merge remote-tracking branch 'upstream/master' into master-next 2019-08-26 13:30:41 -07:00
Doug Gregor
c8ac000fbb Record specialized signature in (SIL)SpecializeAttr.
Rather than storing the set of input requirements in a
(SIL)SpecializeAttr, store the specialized generic signature. This
prevents clients from having to rebuild the same specialized generic
signature on every use.
2019-08-26 09:54:56 -07:00
Doug Gregor
0e2bb0fbe2 Prune includes of GenericSignatureBuilder.h. 2019-08-26 09:54:20 -07:00
Doug Gregor
845ce11e57 [SIL Optimizer] Switch partial specialization to a request.
Partial specialization had its own form of generic signature builder
use, which maps well to the new abstract generic signature
request. Use it.
2019-08-26 09:54:19 -07:00
Doug Gregor
9f35ce5945 [SIL Optimizer] Use the abstract generic signature request.
Eliminates another hardcoded, non-cached use of the generic signature
builder.
2019-08-26 09:54:19 -07:00
swift-ci
892aeaa634 Merge remote-tracking branch 'origin/master' into master-next 2019-08-26 09:29:54 -07:00
Michael Gottesman
5fc1d1d349 [ownership] Define a new instruction copy_unmanaged_value.
This provides a singular instruction for convert an unmanaged value to a ref,
then strong_retain it. I expanded the definition of UNCHECKED_REF_STORAGE to
include these copy like instructions. This instruction is valid in all SIL.

The reason why I am adding this instruction is that currently when we emit an
access to an unowned (unsafe) ivar, we use an unmanaged_to_ref and a strong
retain. This can look to the optimizer like a strong retain that can potentially
be optimized. By combining the two together into a new instruction, we can avoid
this potential problem since the pattern matching will break.
2019-08-25 21:26:40 -07:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Erik Eckstein
b58f54c311 CastOptimizer: fix a minor bug with memory lifetime.
This was not a real leak, because it only happened in an error condition where the block ends in an trap instructon anyway.
But it must be fixed to make the MemoryLifetimeVerifier happy.
2019-08-13 09:29:05 +02:00
Michael Gottesman
7e6b07c307 [constant-folding] Visit struct, tuple when we initialize our worklist as well as when we are processing the worklist.
This simplifies the IR and eliminates in a certain sense "constant information"
from the IR by allowing us to remove extract, nominal literal round trips.

NOTE: I had to modify the pound_assert test slightly on the location of a note
that it emits. The reason that I did this is that the test output is technically
correct. The instruction we are interpreting when we error is (after this
commit), a debug_value in the prelude of the function (and thus has the new
location). I am going to talk with Ravi and others on what to do with this.
2019-08-12 03:32:59 -07:00
Michael Gottesman
297f48a7c2 [constant-folding] Fix asan error. 2019-08-12 01:51:43 -07:00
Michael Gottesman
dff965f912 [constant-folding] Teach constant folding how to transform Builtin.cond_fail => cond_fail.
When this was originally implemented, this transform was put into
SILCombine. This patch also puts it into constant folding so we can also perform
the transform at -Onone.

My hunch is that the reason why this isn't happening with the -Onone
serialization change is that we were relying only this code being specialized
before serialization in the stdlib. But transparent functions are now not
optimized until after serialization, so it isn't done. Rather than mess with
that, I just added the support here.
2019-08-11 17:21:42 -07:00
Michael Gottesman
70666486c6 [constant-folding] Teach constant folding how to remove (int_to_ptr (ptr_to_int)).
I put in a little bit of infrastructure that should provide the appropriate
places for adding information about other cases where we can run into this with
other casts.

The reason I added this is that the codegen around condfail_message has changed
slightly and thus has this round trip in it, messing with various pattern
matching routines.

Example:

```
%x = string_literal
%x1 = ptr_to_int %x    // <=== This messes with pattern matching from
%x2 = int_to_ptr %x1   // <=== the cond_fail to %x.
cond_fail(%x2)
```

=>

```
%x = string_literal    // <=== Happiness = ).
cond_fail(%x)
```
2019-08-11 14:43:28 -07:00
Jordan Rose
844ae38722 Remove some Swift STLExtras that LLVM now provides (#26443)
No functionality change.
2019-07-31 18:34:52 -07:00
Michael Gottesman
096eda29ab [simplify-cfg] Use a SmallSetVector instead of a vector + sortUnique.
This originally used a SmallSetVector before a refactoring that I did. I changed
it to a vector + sortUnique since AFAIKT it only needed uniqueness, not
insertion order... turns out I was wrong. I added a comment here explaining that
this has to be a SetVector to preserve both uniqueness and insertion order.

rdar://53401018
2019-07-22 15:42:15 -07:00
Michael Gottesman
819a56e680 [cfg] Extract out erasePhiArgument utility from SimplifyCFG -> CFG.h.
I needed this functionality to fix an edge case bug in closure lifetime fixup.
2019-07-19 16:01:54 -07:00
Slava Pestov
83c90b6b2a AST: Turn NominalTypeDecl::getStoredProperties() into a request
This improves on the previous situation:

- The request ensures that the backing storage for lazy properties
  and property wrappers gets synthesized first; previously it was
  only somewhat guaranteed by callers.

- Instead of returning a range this just returns an ArrayRef,
  which simplifies clients.

- Indexing into the ArrayRef is O(1), which addresses some FIXMEs
  in the SIL optimizer.
2019-07-16 16:38:38 -04:00
Ravi Kandhadai
37f524e647 [Constant Folding][OSLogOptimization] Fold the uses of the builtin
"globalStringTablePointer": String -> Builtin.RawPointer` to a
string_literal instruction if the string that is passed is constructed
from a literal. Otherwise, emit diagnostics.
2019-07-03 16:47:34 -07:00
Michael Gottesman
591482114d [gardening] Re-flow a small comment. NFC. 2019-07-01 13:12:57 -07:00
Joe Groff
acee7c2a18 Merge pull request #25856 from jckarter/demangler-reentrance
Demangler: Save state to allow reentrant demangling.
2019-06-28 13:23:11 -07:00
Joe Groff
df46a144b5 Demangler: Save state to allow reentrant demangling.
If somebody called `demangleType` or `demangleSymbol` using a demangler that was already
in the middle of demangling a string, then the state for the new demangler would clobber the old
demangler. This manifested in rdar://problem/50380275 because, as part of demangling a
string with a symbolic reference to a private type's context, we would demangle the debug string
for the referenced context using the same demangler. If there were additional operators in the
original string after the symbolic reference, these never got demangled because the demangler
was now in the state of having completed demangling the other string, so we would drop nesting,
and incorrectly report field types of, for instance, `Array<PrivateStruct>` or
`(PrivateStruct, OtherStruct)` as just being `PrivateStruct`.

This is a likely situation to be in, especially now that `Demangler` objects also serve as
arena allocators for their demangled nodes, so change the top-level demangler entry points
to use an RAII object to push and pop the existing state instead of unilaterally clobbering
the existing state.
2019-06-28 10:00:16 -07:00
Michael Gottesman
5d9675392e [cast-opt] Improve handling of arguments when optimizing Swift -> ObjC bridging casts.
Specifically:

1. I removed an extra defensive copy that we put in place some time ago that
isn't really warranted. We know that we have an @owned value, so can safely just
pass the value as a @guaranteed parameter. This also eliminates an ownership
error that would occur due to my not having updated this code for ownership in
tree.

2. I also ensured that if we are performing a loadable address bridging cast ->
value bridging cast that we store the loadable value back into memory after we
perform the cast. Otherwise, it appears to leak to the ownership verifier.

I also centralized the non-ownership tests for this into one place
(const_fold_objc_bridge.sil => constant_propagation_objc.sil).
2019-06-23 13:17:10 -07:00
ravikandhadai
bcdd46cdfe Merge pull request #25677 from ravikandhadai/constexpr-intliteral-trunc
[Const Evaluator] Make compile-time constant evaluator correctly handle s_to_s_checked_trunc_IntLiteral_IntNN where the bit width of the source symbolic value (an APInt) could be smaller than the destination bits
2019-06-23 10:45:01 -07:00
Michael Gottesman
4b31d37307 [cast-opt] Rename misnamed variable.
This is actually an out parameter of the apply that we are then switching upon.
2019-06-22 22:12:00 -07:00
Ravi Kandhadai
11efa58a6c [Const Evaluator] Make compile-time constant evaluator correctly handle
s_to_s_checked_trunc_IntLiteral_IntNN where the bit width of the source
symbolic value (an APInt) could be smaller than the destination bits.
2019-06-21 19:35:06 -07:00
Davidino Italiano
12ee5d3b48 [CastOptimizer] Set the correct debug scope for the SILBuilder.
This is a recommit with a change to only run the test for
optimized stdlib [as the bug reproduces only there [as the bug reproduces only there]
2019-06-17 08:33:29 -07:00
Ben Langmuir
3ac3ff0a6b Revert " [CastOptimizer] Set the correct debug scope for the SILBuilder. " 2019-06-17 07:18:06 -07:00