Commit Graph

20 Commits

Author SHA1 Message Date
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Nate Chandler
08a832b803 [AllocBoxToStack] Transfer var_decl flag.
As with the lexical flag, when creating an alloc_stack corresponding to
an alloc_box, transfer the var_decl flag from any begin_borrow users of
the box.
2024-03-08 22:28:22 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Andrew Trick
966df3585c Fix SILGen to emit fix_lifetime for inout-to-pointer conversion.
This fixes use-after-free miscompilation bugs that can occur when a
lifetime-optimized standard library type, like Dictionary or String is
converted to an UnsafePointer using implicit inout-to-pointer
conversion:

func ptrToDictionary(_: UnsafePointer<Dictionary<K, V>>) {}

func testDictionary() {
  var d: Dictionary = ...
  ptrToDictionary(&d)
}

func ptrToString(_: UnsafePointer<String>) {}

func testString() {
  var s: String = ...
  ptrToString(&s)
}

Address to pointer conversion must always be guarded by either a
mark_dependence or a fix_lifetime. Use fix_lifetime for call emission
in SILGen to limit the optimization impact to the narrow scope of the
pointer conversion.

This could negatively impact performance simply because SIL does not
provide a way to scope pointer conversion. fix_lifetime is
unnecessarilly conservative and prevents the elimination of dead
allocations.

rdar://117807309 (Fix SILGen to emit fix_lifetime for
inout-to-pointer conversion)
2023-11-01 11:34:25 -07:00
Erik Eckstein
4284dc10d0 Optimizer: implement the ObjectOutliner pass in Swift 2023-05-22 15:34:26 +02:00
Nate Chandler
979196cb16 [Test] For disabling destroy hoisting. 2022-03-17 12:06:53 -07:00
Andrew Trick
76b30e30f5 SILVerifier - allow rebind_memory token to cross functions
Remove a completely unnecessary assertion to handle reasonable use
cases.
2021-11-15 19:10:40 -08:00
Meghana Gupta
4c9cb0c768 Fix use-after-free in DestroyHoisting
Due to mismatch in the instructions handled in DestroyHoisting::getUsedLocationsOfInst
and MemoryLocations::analyzeLocationUsesRecursively, certain users of addresses
were not considered and the destroys were hoisted before valid uses causing use-after-frees
2021-08-25 13:07:21 -07:00
Erik Eckstein
71a642e51b stdlib, SIL optimizer: use the SIL copy-on-write representation in the Array types.
Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice.
The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array.
The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation".

The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state.

All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer object side-table indicates if the buffer is mutable or not.

Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.
2020-06-08 15:02:22 +02:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Brent Royal-Gordon
620f8743f8 Fix int literals which can clash with line numbers
test/SILOptimizer/pointer_conversion.swift’s arrayLiteralPromotion() subtest uses integer literals for 41, 42, 43, and 44. If swift-evolve shuffles a particular _internalInvariant() call in stdlib/public/core/BridgeStorage.swift to lines 41-44, the compiler will generate code which reuses the integer_literal instruction for the line number later in the test, causing this test to fail. This happens about once per 45 runs of swift-evolve.

This change negates the integer literals so they will never match a line number.
2019-01-14 11:17:26 -08:00
Mike Ash
49c3547449 Merge remote-tracking branch 'origin/master' into rename-conflicting-classes-and-methods 2018-09-21 15:52:38 -04:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Mike Ash
798edb9d0e [Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
2018-09-13 16:55:10 -04:00
Michael Gottesman
dde4f58625 [+0-all-args] Change emitBindOptional to use a switch_enum instead of a select_enum. 2018-03-15 17:28:57 -07:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Chris Lattner
de289752fe Implement a few silcombine transformations for arrays (#13652)
* Implement a few silcombine transformations for arrays

 - Useless existential_ref <-> class conversions.
 - mark_dependence_inst depending on uninteresting instructions.
 - release(init_existential_ref(x)) -> release(x) when hasOneUse(x)
 - Update COWArrayOpt to handle the new forms generated by this.

these aren't massive performance wins, but do shrink the size of SIL when
dealing with arrays.

* Generalize testcase to work on linux and on mac when checking stdlib is enabled.
2017-12-30 22:30:37 -08:00
Slava Pestov
2a0cb060f8 SILGen: Look up the callee method after evaluating arguments 2017-11-08 01:31:55 -08:00
Jordan Rose
eecb8b1f5f [test] Disable pointer_conversion.swift with an unoptimized stdlib.
I looked at trying to make the matches more flexible, but there are
actually some suspicious bits that I'm not so sure about. I'll just
disable the test for now.

rdar://problem/33531741
2017-07-26 10:48:26 -07:00
Jordan Rose
626cf21382 [test] More tests for array/string-to-optional-pointer conversions.
The array or string has to be kept alive past the call. John fixed
this back in 733915f but I want to make sure it doesn't regress.

rdar://problem/31325077 (originally fixed as rdar://problem/31542269,
also reported as SR-3231)
2017-07-21 19:38:32 -06:00