Commit Graph

1703 Commits

Author SHA1 Message Date
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
a6dfe0ff88 [SIL] Use SubstitutionMap in KeyPathInst rather than SubstitutionList. 2018-05-03 00:05:21 -07:00
Arnold Schwaighofer
1f65ee25f6 Distinguish between withoutActuallyEscaping and passing @noescape
Objective C closures when reporting that a closure has escaped

rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
16c4d650e7 SIL: Allow is_escaping_closure on optional closure types
rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
678a99e76a Add a copy_block_without_escaping %block withoutEscaping %closure instruction
Mandatory pass will clean it up and replace it by a copy_block and
is_escaping/cond_fail/release combination on the %closure in follow-up
patches.

The instruction marks the dependence of a block on a closure that is
used as an 'withoutActuallyEscaping' sentinel.

rdar://39682865
2018-05-01 07:24:19 -07:00
Adrian Prantl
49b40e743d Zero-initialize uninitialized Dictionary variables for the debugger.
To avoid the debugger displaying garbage or having expressions crash
when inspecting an uninitialized dictionary variable, zero-initialize
the first word of the alloca at -Onone.

<rdar://problem/36619561>
2018-04-23 14:23:10 -07:00
Vedant Kumar
c94874460d [DebugInfo] Set the autogenerated bit to request recycled locations
IRGenDebugInfo expects to see an autogenerated bit before allowing reuse
of the last seen debug location for a new instruction.

rdar://28544248
(cherry picked from commit 5f6d8e8c8c)
2018-04-16 10:35:18 -07:00
Vedant Kumar
6b1372206a [DebugInfo] Remove a default location argument from setCurrentLoc
Having a default location of None doesn't seem to enhance readability.

(cherry picked from commit c3ba8ff1ff)
2018-04-16 10:35:18 -07:00
Andrew Trick
53a0676cc2 Revert "[DebugInfo] Set the autogenerated bit to request recycled locations" 2018-04-14 18:48:31 -07:00
Vedant Kumar
5f6d8e8c8c [DebugInfo] Set the autogenerated bit to request recycled locations
IRGenDebugInfo expects to see an autogenerated bit before allowing reuse
of the last seen debug location for a new instruction.

rdar://28544248
2018-04-13 14:38:54 -07:00
Vedant Kumar
c3ba8ff1ff [DebugInfo] Remove a default location argument from setCurrentLoc
Having a default location of None doesn't seem to enhance readability.
2018-04-13 14:38:54 -07:00
Joe Groff
a4aa054838 IRGen: Make type(of:) behavior consistent in ObjC bridged contexts.
When we use type(of: x) on a class in an ObjC bridged context, the optimizer turns this into a SIL `value_metatype @objc` operation, which is supposed to get the dynamic type of the object as an ObjC class. This was previously lowered by IRGen into a `object_getClass` call, which extracts the isa pointer from the object, but is inconsistent with the `-class` method in ObjC or with the Swift-native behavior, which both look through artificial subclasses, proxies, and so on. This inconsistency led to observably different behavior between debug and release builds and between ObjC-bridged and native entry points, so provide an alternative runtime entry point that replicates the behavior of getting a native Swift class. Fixes SR-7258.
2018-04-06 15:17:04 -07:00
Adrian Prantl
6632a200f2 Represent indirect function arguments in the DWARF expression instead of the type.
The current approach has several problems:

- Types that are not inout types but loadable may incorrectly get
  marked as inout types.

- When inout arguments get inlined or otherwise optimized LLDB cannot
  rely on the type to decide to dereference that value.

- One argument may get represented by different types in the same
  function depending on what code is generated for it.

Fixes rdar://problem/rdar://problem/39023374
2018-04-03 09:46:58 -07:00
Andrew Trick
02e4429dba Full IRGen support for begin_access [no_nested_conflict].
Suppress generation of the endAccess runtime call when the
begin_access was a "non-tracking" access.
2018-03-31 16:44:27 -07:00
Andrew Trick
14649ae49e Add IRGen support for begin_access [no_nested_conflict]. 2018-03-27 12:04:32 -07:00
Sho Ikeda
3eecb49c55 Merge pull request #15514 from ikesyo/irgen-using-over-typedef
[gardening][IRGen] Replace `typedef` with `using`
2018-03-27 22:50:36 +09:00
Slava Pestov
c31620d302 IRGen: Mangle generic signature and type for outlined thunks 2018-03-26 19:39:26 -07:00
Sho Ikeda
08644c1d8f [gardening][IRGen] Replace typedef with using 2018-03-27 09:06:33 +09:00
John McCall
a906f43329 Allow type metadata to be incomplete.
Most of the work of this patch is just propagating metadata states
throughout the system, especially local-type-data caching and
metadata-path resolution.  It took a few design revisions to get both
DynamicMetadataRequest and MetadataResponse to a shape that felt
right and seemed to make everything easier.

The design is laid out pretty clearly (I hope) in the comments on
DynamicMetadataRequest and MetadataResponse, so I'm not going to
belabor it again here.  Instead, I'll list out the work that's still
outstanding:

- I'm sure there are places we're asking for complete metadata where
  we could be asking for something weaker.

- I need to actually test the runtime behavior to verify that it's
  breaking the cycles it's supposed to, instead of just not regressing
  anything else.

- I need to add something to the runtime to actually force all the
  generic arguments of a generic type to be complete before reporting
  completion.  I think we can get away with this for now because all
  existing types construct themselves completely on the first request,
  but there might be a race condition there if another asks for the
  type argument, gets an abstract metadata, and constructs a type with
  it without ever needing it to be completed.

- Non-generic resilient types need to be switched over to an IRGen
  pattern that supports initialization suspension.

- We should probably space out the MetadataStates so that there's some
  space between Abstract and Complete.

- The runtime just calmly sits there, never making progress and
  permanently blocking any waiting threads, if you actually form an
  unresolvable metadata dependency cycle.  It is possible to set up such
  a thing in a way that Sema can't diagnose, and we should detect it at
  runtime.  I've set up some infrastructure so that it should be
  straightforward to diagnose this, but I haven't actually implemented
  the diagnostic yet.

- It's not clear to me that swift_checkMetadataState is really cheap
  enough that it doesn't make sense to use a cache for type-fulfilled
  metadata in associated type access functions.  Fortunately this is not
  ABI-affecting, so we can evaluate it anytime.

- Type layout really seems like a lot of code now that we sometimes
  need to call swift_checkMetadataState for generic arguments.  Maybe
  we can have the runtime do this by marking low bits or something, so
  that a TypeLayoutRef is actually either (1) a TypeLayout, (2) a known
  layout-complete metadata, or (3) a metadata of unknown state.  We could
  do that later with a flag, but we'll need to at least future-proof by
  allowing the runtime functions to return a MetadataDependency.
2018-03-26 12:18:04 -04:00
Vedant Kumar
3bdcb00b0f [IRGenSIL] Force early materialization of liverange-extended values
At -Onone, we may opt to extend the liverange of a value by inserting
fake uses of the value in blocks which postdominate its def. This keeps
values available throughout the entirety of a function when stepping
through it in a debugger.

This patch makes it so that we also insert a fake use at the start of a
value's lifetime. This forces early materialization of the value, i.e it
becomes available for inspection in a debugger as soon as it's defined.

This is useful when a value has no uses except fake uses. In such cases,
ISel may (correctly!) decide to materialize the value at the end of its
scope. This is really unintuitive and unhelpful for users, because you
need to be done stepping through the value's scope before you can
inspect it.

For the same reasons, forcing early materialization is also useful when
a value *does* have uses. Consider:

  let d = ...
  print("Here is the value of d: \(d)")

Without early materialization, if you set a breakpoint on the line
containing the print, you would not be able to inspect "d". That's
because "d" would be materialized right before string interpolation
happens, which is *after* the breakpoint PC.

rdar://38465084
2018-03-22 18:15:51 -07:00
Vedant Kumar
f98ab4a1c7 [IRGenSIL] Break up and simplify liverange extension logic, NFC
Split out the logic to emit lifetime-extending inline assembly gadgets
into emitLifetimeExtendingUse().
2018-03-22 16:01:46 -07:00
John McCall
aaa40ee82b Move metadata-accessing IRGen out of GenMeta. NFC.
Abstract type/heap metadata access goes into MetadataRequest.
Metadata access starting from a heap object goes into GenHeap.
Accessing various components of class metadata goes into GenClass
or MetadataLayout.
2018-03-18 23:53:11 -04:00
Joe Groff
c0629d2240 IRGen: Set CurSourceFile for SIL functions using the module's associated context.
SIL functions might be associated with decls from other source files whose symbols we can't necessarily locally link to. The module should be associated with the SourceFile that was compiled.
2018-03-13 14:20:52 -07:00
Joe Groff
0bd90e0f13 IRGen: Set IGM.CurSourceFile while emitting SILFunctions.
This makes it more likely we'll do optimizations that are currently scoped to same-SourceFile references, such as direct relative references or symbolic references in mangling, in codegen that gets triggered on behalf of a SILFunction. Should be NFC, aside from some tiny code size improvement.
2018-03-09 12:12:11 -08:00
Arnold Schwaighofer
5940796cc1 SIL: Add an is_escaping_closure instruction
Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
2018-03-07 08:56:00 -08:00
swift-ci
d468dcb108 Merge pull request #14767 from adrian-prantl/37720555 2018-02-21 13:10:45 -08:00
Adrian Prantl
9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
Vedant Kumar
132bb19274 [IRGen] Avoid generating mergeable traps
Factor out and reuse logic in the lowering of CondFailInst to emit
non-mergeable traps, everywhere we emit traps. This should address a
debugging quality issue with ambiguous ud2 instructions.

rdar://32772768
2018-02-20 13:40:40 -08:00
Adrian Prantl
3c96333929 Emit debug info shadow copies of the addresses of dynamic allocas.
Whan an alloca is dynamic, all FastISel can do is describe the
register in which the address of of the dynamic alloca is kept, and if
the value isn't used it will get kicked out by regalloc.

rdar://problem/36663932
2018-02-15 10:00:33 -08:00
Adrian Prantl
56d8a8dfe9 When generating debug info for AllocStackInst, make sure to describe the alloca.
This way an llvm.dbg.declare instrinsic is used, which is valid for
the entire lifetime of the alloca.

rdar://problem/36663932
2018-02-14 11:12:48 -08:00
Arnold Schwaighofer
a9fa8c9c2b Merge pull request #14514 from aschwaighofer/wip_closure_capture_abi_part2
WIP: Closure ABI - Make @noescape Swift closures trivial
2018-02-14 05:19:25 -08:00
Joe Shajrawi
102b6f0b61 Merge pull request #14587 from shajrawi/newinstr
Optimizer peephole for tagged BridgeObjects
2018-02-13 07:38:53 -08:00
Arnold Schwaighofer
882059674f IRGen: Support for trivial @noescape function types
- make @noescape function types trivial
- think_to_thick_function with @noescape result type
- Fix for getSwiftFunctionPointerCallee

Part of:
SR-5441
rdar://36116691
2018-02-13 04:19:59 -08:00
Joe Shajrawi
f732ea66ef Builtins: add ValueToBridgeObject instruction 2018-02-12 13:27:59 +02:00
Arnold Schwaighofer
d51053b003 Add convert_escape_to_noescape instruction for converting escaping to noescape functions
@noescape function types will eventually be trivial. A
convert_escape_to_noescape instruction does not take ownership of its
operand. It is a projection to the trivial value carried by the closure
-- both context and implementation function viewed as a trivial value.

A safe SIL program must ensure that the object that the project value is based
on is live beyond the last use of the trivial value. This will be
achieve by means of making the lifetimes dependent.

For example:

  %e = partial_apply [callee_guaranteed] %f(%z) : $@convention(thin) (Builtin.Int64) -> ()
  %n = convert_escape_to_noescape %e : $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
  %n2 = mark_dependence %n : $@noescape @callee_guaranteed () -> () on %e : $@callee_guaranteed () -> ()
  %f2 = function_ref @use : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %f2(%n2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  release_value %e : $@callee_guaranteed () -> ()

Note: This is not yet actually used.

Part of:
SR-5441
rdar://36116691
2018-02-06 18:01:23 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Davide Italiano
fa10866c38 [IRGenSIL] When emitting a shadow copy, honour the layout.
This code was ad-hoc trying to reconstruct the layout. Ask TypeInfo
instead, as it knows what's the right thing to do.
This allows to print field of classes nested inside classes correctly
in lldb (SR-6791).

<rdar://problem/36518505>
2018-01-24 13:20:26 -08:00
Slava Pestov
9b0f6fca53 IRGen: Emit class dispatch thunks in IRGen instead of SILGen
This allows us to re-use the same code for emitting protocol dispatch
thunks.
2018-01-15 22:38:16 -08:00
Slava Pestov
698881d5c6 IRGen: Protocol dispatch thunks
We want to be able to re-order existing protocol requirements
and add new protocol requirements with default implementations.

Enable this by wrapping the witness table lookup inside a
thunk and calling the thunk, instead of open-coding the
witness table lookup directly in client code.
2018-01-10 13:54:21 -08:00
Slava Pestov
3595c92da5 IRGen: Refactor emitWitnessMethodValue() 2018-01-10 13:52:32 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Chris Lattner
415cd50ba2 Reduce array abstraction on apple platforms dealing with literals (#13665)
* Reduce array abstraction on apple platforms dealing with literals

Part of the ongoing quest to reduce swift array literal abstraction
penalties: make the SIL optimizer able to eliminate bridging overhead
 when dealing with array literals.

Introduce a new classify_bridge_object SIL instruction to handle the
logic of extracting platform specific bits from a Builtin.BridgeObject
value that indicate whether it contains a ObjC tagged pointer object,
or a normal ObjC object. This allows the SIL optimizer to eliminate
these, which allows constant folding a ton of code. On the example
added to test/SILOptimizer/static_arrays.swift, this results in 4x
less SIL code, and also leads to a lot more commonality between linux
and apple platform codegen when passing an array literal.

This also introduces a couple of SIL combines for patterns that occur
in the array literal passing case.
2018-01-02 15:23:48 -08:00
Adrian Prantl
fdc9489d25 Zero-initialize uninitialized variables at -Onone.
This un-breaks the LLDB testsuite.

To make it unambiguous whether a `var` binding has been initialized,
zero-initialize the first pointer-sized field. LLDB uses this to
recognize to detect uninitizialized variables. This can be removed once
swiftc switches to @llvm.dbg.addr() intrinsics. This dead store will get
optimized away when optimizations are enabled.

<rdar://problem/36156857>
2017-12-21 13:18:03 -08:00
John McCall
1f3f33e67d Clean up the internal APIs around dynamic allocas to structurally
discourage accidental use of them.  Relatedly, fix several bugs
where we were accidentally using dynamic allocas.
2017-12-19 00:29:43 -05:00
John McCall
dfe119f86e Compute the BuiltinInfo for a builtin call to IRGenSIL; NFC.
The intention here is to make it easier to do specialized lowering
for specific builtin arguments.
2017-12-15 00:21:21 -05:00
Adrian Prantl
521de91ba7 Fix the debug info generated by the LoadableByAddress transformation.
And unbreak the LLDB testsuite.

This patch fixes three problems with the original implementation:
- Use SILBuilderWithScope instead of SILBuilder to avoid holes in the
  lexical scopes.
- Use an artificial location for stores to the alloca to avoid the debugger
  stopping before the variable is initialized.
- Recognize debug_value_addr instructions referring to an alloc_stack
  instruction to avoid introducing an extra indirection in the debug info.

rdar://problem/31975108
2017-12-02 16:48:34 -08:00
Slava Pestov
1f79af7504 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 16:26:43 -08:00
Arnold Schwaighofer
53bb5ea79b Merge pull request #13148 from apple/revert-13139-no-more-volatile-witness-method
Revert "SIL: Use objc_method instruction for Objective-C protocol method calls"
2017-11-29 12:15:53 -08:00
swift-ci
0d91b89948 Merge pull request #13145 from adrian-prantl/25772716 2017-11-29 11:59:45 -08:00
Arnold Schwaighofer
ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00