Commit Graph

815 Commits

Author SHA1 Message Date
swift-ci
b91640b044 Merge remote-tracking branch 'origin/master' into master-next 2017-04-10 08:08:43 -07:00
Arnold Schwaighofer
09246d3718 IRGen: Fix partial_apply of arguments that lower to empty values
We would run into an assertion during building the partial apply forwarding
thunk because we passed down a parameter convention of an empty argument
although we ignore it for the purpose of adding to the closure context.
However, the code path for the non-allocated closure context (0 or one capture)
would assert that there is only one convention.

Reconcile this by not adding the empty parameter to the convention array.

rdar://31487947
2017-04-08 08:17:30 -07:00
swift-ci
01b79011fe Merge remote-tracking branch 'origin/master' into master-next 2017-03-29 06:48:52 -07:00
practicalswift
91bc2d2993 [gardening] Remove comparison to false 2017-03-28 21:40:06 +02:00
Saleem Abdulrasool
15565c116a Adjust for SVN r298393 2017-03-22 07:44:03 -07:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00
Arnold Schwaighofer
ecb8b15261 IRGen: Fix partial_apply of instantiated generic return values
We might have to reabstract the return type.

SR-4253
2017-03-17 13:30:53 -07:00
John McCall
ec667cae55 Adopt ConstantInitBuilder in a few places. 2017-03-06 14:18:47 -05:00
Slava Pestov
0611d663b8 SIL: Remove SILType::getSwiftType() 2017-02-27 20:01:35 -08:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Slava Pestov
18550b171d IRGen: witness_method function values no longer carry witness table
This was an unnecessary complication and didn't make a lot of
logical sense, because we can recover the witness table from
substitutions when we call a @convention(witness_method) anyway.

Also, to fix materializeForSet for generic subscripts, I want the
materializeForSet *callback* of a protocol witness to have
@convention(witness_method), which requires representing such
functions as a single function pointer in IRGen.
2017-02-25 16:42:51 -08:00
Arnold Schwaighofer
fecec3cc07 Silence warning of disabled code
SR-4041
2017-02-22 17:21:25 -08:00
Slava Pestov
6e2f1f356b IRGen: Fix crash when emitting partial apply of concrete witness_method
The hasPolymorphicParameters() method always returns true for a
SILFunctionType with witness_method calling convention, because
we have to pass the type metadata for 'Self'.

However, it is possible for a witness_method to have no generic
signature, if we're directly calling a concrete witness method
thunk, as can happen after devirtualization.

In this case, we would crash if the witness_method was partially
applied. Handle this case.

This fixes a regression from the recent cleanup to have IRGen use
SubstitutionMap: <https://github.com/apple/swift/pull/7211>
2017-02-16 17:59:03 -08:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
Hugh Bellamy
cb3bdcc2a3 Merge pull request #7408 from hughbe/llvm-fallthrough
Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH
2017-02-13 17:39:59 +07:00
Slava Pestov
5296d02485 AST: More include-what-you-use gardening 2017-02-12 00:51:26 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
c90a77df31 IRGen: Use SubstitutionMap instead of ArrayRef<Substitution> in a few places
The crazy indexing logic is gone.
2017-02-03 19:55:41 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Han Sangjin
b8dd577693 [swiftc] Fixed for Cygwin
Fixed for the difference of Cygwin with other Windows variants (MSVC,
Itanium, MinGW).

- The platform name is renamed to "cygwin" from "windows" which is used
  for searching the standard libraries.

- The consideration for DLL storage class (DllExport/DllImport) is not
  required for Cygwin and MinGW. There is no problem when linking in
  these environment.

- Cygwin should use large memory model as default.(This may be changed
  if someone ports to 32bit)

- Cygwin and MinGW should use the autolink feature in the sameway of
  Linux due to the linker's limit.
2017-01-19 05:48:24 +09:00
Michael Gottesman
d944930591 Remove the deallocating convention.
This is dead code and can be re-added if it is needed. Right now though there
really isnt a ValueOwnershipKind that corresponds to deallocating and I do not
want to add a new ValueOwnershipKind for dead code.
2017-01-10 17:32:17 -08:00
AnnaZaks
1122ebd731 Merge pull request #6453 from apple/asan
[tsan] Do not report races coming from deinitializers and _Block_release
2017-01-06 11:50:28 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Anna Zaks
18c10c566f [tsan] Do not report races coming from deinitializers and _Block_release
TSan does not observe the guaranteed syncronization between the ref
count drop to zero and object destruction. This can lead to false positive
reports.

This patch adds an attribute to deinitializers to ignore memory accesses
at run time. It also moves the logic to add sanitizer attributes from
IRGenFunction to IRGenSILFunction, which means that the automatically
generated code such as _Block_release handler will not be instrumented
and the accesses made in them will be invisible to TSan.

Solves a problem similar to what's addressed in clang commit:
https://reviews.llvm.org/D25857
2017-01-05 10:26:25 -08:00
Arnold Schwaighofer
cd1037b799 IRGen: Allocate generic/resilient values on the stack instead of on the heap
Allocate buffers for local generic/resilient values on the stack. alloc_stack
instructions in the entry block are translated using a dynamic alloca
instruction with variables size. All other alloc_stack instructions in addition
use llvm's stacksave/restore instrinsics to reset the stack (they could be
executed multiple times and with varying sizes).
2016-12-20 07:24:02 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Erik Eckstein
ad1c079632 Mangling: support new mangling of partial apply forwarders in IRGen 2016-12-09 10:28:34 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
d50a31051b IRGen: Fix issues when partial applying methods on resilient value types
Fixes <rdar://problem/28673540>.
2016-10-17 18:10:37 -07:00
Joe Groff
aac85cb93f SIL: Introduce a 'closure' convention for unapplied invocation functions.
We don't want the machine calling conventions for closure invocation functions to necessarily be tied to the convention for normal thin functions or methods. NFC yet; for now, 'closure' follows the same behavior as the 'method' convention, but as part of partial_apply simplification it will be a requirement that partial_apply takes a @convention(closure) function and a box and produces a @convention(thick) function from them.
2016-10-17 15:55:04 -07:00
Arnold Schwaighofer
80ea1524d0 IRGen: Shuffle self value for witness method partial applications
We need to splice self inbetween the polymorphic arguments and the error
argument but before the self metadata and witness table arguments.

rdar://28302820
2016-09-16 15:17:20 -07:00
Arnold Schwaighofer
5f4a8ec8b7 Partial apply forwarder fix for going from single ref counted context to a generic argument
In the case we are forwarding from partial apply that captures a concrete ref
counted value to a generic function we need to use the swift retainable type
from the captured value rather than the type of the generic function we are
calling. The type of the generic argument is opaque and we can't allocate
storage for an opaque type.

rdar://24306823
2016-07-22 09:25:02 -07:00
Saleem Abdulrasool
7352392830 IRGen: add support for DLL Storage semantics
Add initial support for modelling DLL Storage semantics for global values.  This
is needed to support the indirect addressing mechanism used on Windows.
2016-07-06 18:03:57 -07:00
Adrian Prantl
935b702a07 Add an assertion to IRBuilder to prevent function calls with no debug location
It is not valid LLVM IR to have a function call without a location to an
inlinable function inside a function with debug info — this makes it impossible
to construct inline information.

This patch adds an assertion and fixes up several places across IRGen where
such a situation could happen.

rdar://problem/26955467
2016-06-27 19:04:51 -07:00
Joe Groff
22c4e08b96 IRGen: Fix TypeInfo for witness_method SIL values.
@convention(witness_method) values were changed to carry a pointer to their source witness table, but the type info wasn't changed to match. Fixing this fixes rdar://problem/26268544.
2016-06-14 10:22:37 -07:00
David Farler
aa86d1dd07 SwiftRemoteMirror: Fix crash emitting capture descriptors involving implicit self
When emitting capture descriptors for functions with a smaller number of parameters
than SIL parameters, the compiler can crash indexing into the heap layout's element
types, because the capture index underflows to UINT_MAX.

rdar://problem/26404583
2016-05-20 20:53:10 -07:00
Slava Pestov
bb8d1d3416 IRGen: Fixes for capture descriptor emission
- Fix caller/callee confusion, and use the right SIL function type
  for obtaining the generic signature.
- Correctly interpret the NecessaryBindings structure and the
  substitutions therein.
- Fix alignment for capture and builtin type descriptors
- Put capture descriptor typerefs in the correct section

Add new SIL-level tests to precisely trigger various scenarios.
2016-05-05 13:47:54 -07:00
John McCall
f944d9133a Teach LoadableTypeInfos how to add themselves to a SwiftAggLowering. NFC. 2016-05-03 11:14:16 -07:00
Slava Pestov
96218acf66 IRGen: Only emit capture descriptors if -enable-reflection-metadata frontend flag is passed in
Also, simplify the IRGen/reflection_metadata.swift test a bit; there's no
reason to split it up into two files.
2016-04-30 15:36:00 -07:00
David Farler
09d0cfee8d Hang closure capture descriptors from their heap metadata
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.

A closure capture descriptor has the following:

- The number of captures.
- The number of sources of metadata reachable from the closure.
  This is important for substituting generics at runtime since we
  can't know precisely what will get captured until we observe a
  closure.
- The number of types in the NecessaryBindings structure.
  This is a holding tank in a closure for sources of metadata that
  can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
  source of metadata for every generic argument needed to perform
  substitution at runtime.
  Key: The typeref for the generic parameter visible from the closure
  in the Swift source.
  Value: The metadata source, which describes how to crawl the heap from
  the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.

Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.

rdar://problem/24989531
2016-04-22 19:09:06 -07:00
Roman Levenstein
d8e28bb690 Handle the [nonatomic] attribute in IRGen and LLVM passes.
Properly lower reference counting SIL instructions with nonatomic attribute as invocations of corresponding non-atomic reference counting runtime functions.
2016-04-06 22:30:23 -07:00
John McCall
52cd8718de Split GenFunc.cpp in three: GenFunc for function types and blocks,
GenCall for function signatures, calls, and prologue/epilogue, and
GenBuiltin for builtin operations.

NFC.
2016-04-04 23:52:14 -07:00
Erik Eckstein
a47a62d644 A new onFastPath built-in.
It is a hint to the optimizer that the code, where this builtin is called, is on the fast path.
Specifically, the inliner takes it into account and increases the assumed benefit for code where the builtin is located.

Compared to the fastPath/slowPath builtins, this builtin can be placed into plain linear code and doesn't need to be used in conditions.
Compared to the @inline(__always) attribute, this builtin has also an effect on the caller function. Let's assume
	foo() calls bar() contains onFastPath
and both foo and bar are small functions. Then if bar gets inlined into foo, the builtin also increases the chances that foo gets inlined.
This would not be the case if @inline(__always) is used just for bar.
2016-03-31 12:53:44 -07:00
Arnold Schwaighofer
bdaea9be27 Add Builtin.unsafeGuaranteed and Builtin.unsafeGuaranteedEnd
These builtins can be used to denote a scope over which the parameter passed to
unsafeGuaranteed can be assume to be @guaranteed: That is there is another
reference that keeps the value alive.

  // Scope begin
  strong_retain %0 : $Foo
  %2 = builtin "unsafeGuaranteed"<Foo>(%0 : $Foo) : $(Foo, Builtin.Int8)
  %3 = tuple_extract %2 : $(Foo, Builtin.Int8), 0
  %4 = tuple_extract %2 : $(Foo, Builtin.Int8), 1
  %5 = class_method %3 : $Foo, #Foo.beep!1 : (Foo) -> () -> ()
  %6 = apply %5(%3) : $@convention(method) (@guaranteed Foo) -> ()
  strong_release %3 : $Foo
  %8 = builtin "unsafeGuaranteedEnd"(%4 : $Builtin.Int8) : $(
  // Scope end

is semantically equivalent to:

  sil @guaranteed_lifetime : $@convention(method) (@guaranteed Foo) -> () {
  bb(%3: $Foo):
    %5 = class_method %3 : $Foo, #Foo.beep!1 : (Foo) -> () -> ()
    %6 = apply %5(%3) : $@convention(method) (@guaranteed Foo) -> ()
  }

  ...

  // Scope begin
  apply @guaranteed_lifetime(%0)
  // Scope end
2016-03-27 06:47:16 -07:00
Michael Ilseman
47e73ad4f1 Merge branch 'master' of github.com:apple/swift into import-as-member 2016-03-23 17:01:47 -07:00
Joe Groff
281d8136cb IRGen: Handle nonmutating indirect parameters to C functions.
These come up now when C functions with `const Foo *` parameters are imported as members of Foo.
2016-03-21 12:37:16 -07:00
Vedant Kumar
dc11f8bf01 [Coverage] Re-apply "Respect function linkage in PGO name variables"
Fix a crash in emitBuiltinCall() which occurs because we drop function
linkage information when creating SILCoverageMaps.

This re-applies 45c7e4e86 with the MachO-specific checks in the test
case removed.
2016-03-17 22:44:35 -07:00
Vedant Kumar
c59b266f93 Revert "[Coverage] Respect function linkage in PGO name variables"
This reverts commit 45c7e4e861.

The IR CHECK lines in coverage.swift are flaky.
2016-03-17 18:21:32 -07:00
Vedant Kumar
45c7e4e861 [Coverage] Respect function linkage in PGO name variables
Fix a crash in emitBuiltinCall() which occurs because we drop function
linkage information when creating SILCoverageMaps.
2016-03-17 18:06:39 -07:00