Commit Graph

2777 Commits

Author SHA1 Message Date
Adrian Prantl
91f6f34119 Add debug info support for inlined and specialized generic variables.
This patch adds SIL-level debug info support for variables whose
static type is rewritten by an optimizer transformation. When a
function is (generic-)specialized or inlined, the static types of
inlined variables my change as they are remapped into the generic
environment of the inlined call site. With this patch all inlined
SILDebugScopes that point to functions with a generic signature are
recursively rewritten to point to clones of the original function with
new unique mangled names. The new mangled names consist of the old
mangled names plus the new substituions, similar (or exactly,
respectively) to how generic specialization is handled.

On libSwiftCore.dylib (x86_64), this yields a 17% increase in unique
source vars and a ~24% increase in variables with a debug location.

rdar://problem/28859432
rdar://problem/34526036
2018-07-06 22:06:48 -07:00
swift-ci
1bf3a6d42f Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 13:09:47 -07:00
swift-ci
99858b71a5 Merge pull request #17759 from CodaFi/SILly-inputs 2018-07-05 13:09:22 -07:00
swift-ci
decf2b1130 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 11:49:26 -07:00
Robert Widmann
a79c11f5d8 Drop more uses of getInput() from SIL 2018-07-05 10:52:41 -07:00
David Zarzycki
03b7eae9ed [SILOptimizer] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
swift-ci
b739b4a189 Merge remote-tracking branch 'origin/master' into master-next 2018-06-29 18:09:14 -07:00
Andrew Trick
6ed43afcf8 Fix checks and assertions in -enable-verify-exclusivity mode.
Now that access marker verification is strict and exhaustive, adjust some code
to handle the extra markers and extra checks produced by -enable-verify-exclusivity.
2018-06-29 15:56:02 -07:00
swift-ci
3af5e3ba49 Merge remote-tracking branch 'origin/master' into master-next 2018-06-27 19:29:27 -07:00
Michael Gottesman
9e70b855e4 [cmake] Use a helper macro to simplify adding sources to the SILOptimizer library.
All this does is automate the creation of the ${DIRNAME}_SOURCES variables that we already create and allows for the author to avoid having to prefix with the directory name, i.e.:

set(FOOBAR_SOURCES
  FooBar/Source.cpp
  PARENT_SCOPE)

=>

silopt_register_sources(
  Source.cpp)

Much easier and cleaner to read. I put the code that implements this in the
CMakeLists.txt file just for the SILOptimizer.
2018-06-27 17:48:59 -07:00
swift-ci
ff7e1a9aa9 Merge remote-tracking branch 'origin/master' into master-next 2018-06-27 15:49:33 -07:00
Adrian Prantl
7680ac03d2 Fix the missing inlined-at field of function-level SILDebugScopes.
rdar://problem/28859432
2018-06-27 13:49:18 -07:00
swift-ci
5e49ce352a Merge remote-tracking branch 'origin/master' into master-next 2018-06-26 19:50:13 -07:00
Andrew Trick
9d4b4c755c Rewrite SILCombiner::propagateConcreteTypeOfInitExistential. (#17315)
Fixes <rdar://40555427> [SR-7773]:
SILCombiner::propagateConcreteTypeOfInitExistential fails to full propagate type
substitutions.

Fixes <rdar://problem/40923849>
SILCombiner::propagateConcreteTypeOfInitExistential crashes on protocol
compositions.

This rewrite fixes several fundamental bugs in the SILCombiner optimization that
propagates concrete types. In particular, the pass needs to handle:

- Arguments of callee Self type in non-self position.
- Indirect and direct return values of Self type.
- Types that indirectly depend on Self within callee function signature.
- Protocol composition existentials.
- All of the above need to work for protocol extensions as well as witness methods.
- For protocol extensions, conformance lookup should be based on the existential's conformance list.

Additionally, the optimization should not depend on a SILFunction's DeclContext,
which is not serialized. (In fact, we should prevent SIL passes from using
DeclContext). Furthermore, the code needs to be expressed in a way that one can
reason about correctness and invariants.

The root cause of these bugs is that SIL passes are written based on untested
assumptions of Swift type system. A SIL pass needs to handle all verifiable SIL
input because passes need to be composable. Bail-out logic can be added to
simplify the design; however, _the bail-out logic itself cannot make any
assumptions about the language or type system_ that aren't clearly and
explicitly enforced in the SIL verifier. This is a common mistake and major
source of bugs.

I created as many unit tests as I reasonably could to prevent this code from
regressing. Creating enough unit tests to cover all corner cases that were
broken in the original code would be intractable. But the code has been
simplified such that many corner cases disappear.

This opens up some oportunity for generalizing the optimization and eliminating
special cases. However, I want this PR to be limited to fixing correctness
issues only. In the long term, it would be preferable to replace this
optimization entirely with a much more powerful general type propagation pass.
2018-06-26 19:33:31 -07:00
swift-ci
adcaa7eafc Merge remote-tracking branch 'origin/master' into master-next 2018-06-26 06:09:27 -07:00
Huon Wilson
ed64fadb28 [SIL]/[SILOpt] Thunks and specializations shouldn't be connected to their parent class.
The "subclass scope" is meant to represent a connection to a vtable (and how
public something needs to be), for things that end up in class
vtables. Specializations and thunks are mostly internal implementation details
and do not end up there, so subclass scope is not applicable to them. This stops
the thunks and specializations being incorrectly public.

(Note, there are some thunks that _are_ public facing: if a function has its
signature optimized, the original entry point becomes a thunk, and this entry
point is what ends up in vtables etc., so needs to remain around, which means
keeping the same hacks for `private` members of an `open` class.)

Fixes rdar://problem/40738913.
2018-06-26 16:25:42 +10:00
Bob Wilson
44712233c3 Merge remote-tracking branch 'origin/master' into master-next 2018-06-21 23:36:03 -07:00
swift-ci
395aa00c16 Merge pull request #17274 from ravikandhadai/IntToFloatPR 2018-06-21 17:44:56 -07:00
Raj Barik
392469a336 Extend findInitExistential for cases with global_addr and ApplySite argument 2018-06-21 13:49:28 -07:00
Ravi Kandhadai
193407bf23 [SIL Diagnostics] Warn when assigning an integer literal to a
variable of floating-point type results in loss of precision.
<rdar://15224041>
2018-06-21 10:56:19 -07:00
Bob Wilson
ea055fcbdc Merge remote-tracking branch 'origin/master' into master-next 2018-06-19 22:47:54 -07:00
Joe Shajrawi
95dfa8b697 Devirtualizer: enable inline an inlinable function into a non-inlinable function
See https://github.com/apple/swift/pull/17327#discussion_r196589673
2018-06-19 15:35:27 -07:00
swift-ci
7d2a75dc1e Merge pull request #17327 from shajrawi/devirt_inline 2018-06-19 13:15:32 -07:00
Joe Shajrawi
adb53c44a1 Devirtualizer: disable the “effectively final” optimization if the caller is serialized
Improve the check done in https://github.com/apple/swift/pull/14740

The class_method being devirtualized might be OK for most call sites, i.e. we are allowed to devirtualize it, however, the caller itself might have been marked with inlinable
2018-06-19 10:53:16 -07:00
swift-ci
77c7101033 Merge remote-tracking branch 'origin/master' into master-next 2018-06-18 20:51:08 -07:00
swift-ci
eaa3d2c565 Merge pull request #16738 from ravikandhadai/FPTruncPR 2018-06-18 20:41:09 -07:00
Ravi Kandhadai
addae9bae4 [SIL Diagnostics] Add warnings for imprecision during assignment of
floating-point literals to variables of floating-point type.
2018-06-18 12:02:23 -07:00
Bob Wilson
225bc732b4 Merge remote-tracking branch 'origin/master' into master-next 2018-06-15 17:26:12 -07:00
swift-ci
13dfae7be5 Merge pull request #17258 from aschwaighofer/cleanup_cfg_after_noreturn_folding 2018-06-15 16:55:33 -07:00
Arnold Schwaighofer
73d3b37c94 Move RemoveUnreachable from SimplifyCFG into a utility function
The utility function will be used in a follow-up commit by a different
pass.

rdar://41139395
2018-06-15 13:52:17 -07:00
swift-ci
7a9a19c111 Merge remote-tracking branch 'origin/master' into master-next 2018-06-12 17:09:16 -07:00
Arnold Schwaighofer
d6b13f99f6 Add documentation to the cast optimizer change 2018-06-12 16:02:33 -07:00
swift-ci
e14e2db475 Merge remote-tracking branch 'origin/master' into master-next 2018-06-11 14:09:23 -07:00
Arnold Schwaighofer
e8b5f1c892 CastOptimizer: A load store to the existential box is not valid on address only types
rdar://40949457
2018-06-11 11:17:04 -07:00
swift-ci
611bf8be6e Merge remote-tracking branch 'origin/master' into master-next 2018-06-07 07:29:41 -07:00
Arnold Schwaighofer
35c697c83d Merge pull request #17026 from aschwaighofer/wip_begin_apply_inlining
SILInliner: Initial support for begin_apply
2018-06-07 07:24:23 -07:00
swift-ci
b87ea23124 Merge remote-tracking branch 'origin/master' into master-next 2018-06-06 17:29:44 -07:00
Arnold Schwaighofer
dfec52b332 SILInliner: Initial support for begin_apply
rdar://35399839
2018-06-06 13:40:16 -07:00
Arnold Schwaighofer
fcd9adaece Cleanup unused variable 2018-06-06 12:23:11 -07:00
Erik Little
863f3a19ff Rename @effects to @_effects
@effects is too low a level, and not meant for general usage outside
the standard library. Therefore it deserves to be underscored like
other such attributes.
2018-06-06 12:53:03 -04:00
swift-ci
ef514d2353 Merge remote-tracking branch 'origin/master' into master-next 2018-06-05 12:10:01 -07:00
Raj Barik
c277c90be6 Reorganizing the code to find init_existential; Move them to Existential.cpp/h in order for other passes such as ExistentialSpecializer to use it apart from SILCombiner 2018-06-04 11:07:12 -07:00
Jordan Rose
73ee008bfd Merge remote-tracking branch 'origin/master' into master-next 2018-05-29 11:18:44 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Vedant Kumar
105a61e50d Use LLVM_DEBUG() instead of DEBUG()
Upstream has renamed the DEBUG() macro to LLVM_DEBUG. This updates swift
accordingly:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-05-24 13:10:45 -07:00
swift-ci
f80606acce Merge remote-tracking branch 'origin/master' into master-next 2018-05-19 17:29:42 -07:00
Slava Pestov
ebb1198d57 AST: There's no longer any reason to pass SubstitutionMap by const reference
SubstitutionMaps are now just a trivial pointer-sized value, so
pass them by value instead.

I did have to move a couple of functors from Type.h to SubstitutionMap.h
to resolve some issues with forward declarations.
2018-05-19 00:45:36 -07:00
swift-ci
476a155bfa Merge remote-tracking branch 'origin/master' into master-next 2018-05-16 14:30:09 -07:00
Ravi Kandhadai
9846342444 [SIL Diagnostics & Tests] Re-add diagnostics for detecting invalid conversions from
floating point literals to integers (<rdar://39730762>).

Add test cases for checking the correctness of the diagnostics.
Contains tests specific to x86 and non-x86 architectures.
2018-05-15 18:08:08 -07:00
swift-ci
4954361e7f Merge remote-tracking branch 'origin/master' into master-next 2018-05-15 10:29:41 -07:00