Commit Graph

2864 Commits

Author SHA1 Message Date
Michael Gottesman
e0fdce1fa3 [region-isolation] Convert TransferringOperand to be a bump allocated ptr type from a pointer type.
I need to start tracking the dynamic IsolationRegionInfo for the transferring
operand so I can ignore uses that are part of the same
IsolationRegionInfo. IsolationRegionInfo doesn't fit into a pointer, so just to
keep things the same, I am going to just allocate it.

This is an initial staging commit that tests out the bump ptr allocating without
expanding the type yet.
2024-03-21 14:16:20 -07:00
Erik Eckstein
16b59dbbff PredictableMemOpt: fix a crash, caused by a wrong instruction cast
Instead, bail if the cast does not succeed.

rdar://125166206
2024-03-21 18:49:08 +01:00
Nate Chandler
a0a1ff2a04 [MoveOnlyAddressChecker] Fix enum repr.
Change FieldSensitive's enum representation to allow distinguishing
among the elements with associated value.  Consider
`unchecked_take_enum_data_addr` to consume all other fields than that
taken.

rdar://125113258
2024-03-21 10:48:32 -07:00
Meghana Gupta
3ebef80261 Fix utilities that may see phis of mark_dependence [nonescaping] 2024-03-20 15:44:11 -07:00
Kuba Mracek
b642d771be [embedded] Compile-time (literal) KeyPaths for Embedded Swift
Enable KeyPath/AnyKeyPath/PartialKeyPath/WritableKeyPath in Embedded Swift, but
for compile-time use only:

- Add keypath optimizations into the mandatory optimizations pipeline
- Allow keypath optimizations to look through begin_borrow, to make them work
  even in OSSA.
- If a use of a KeyPath doesn't optimize away, diagnose in PerformanceDiagnostics
- Make UnsafePointer.pointer(to:) transparent to allow the keypath optimization
  to happen in the callers of UnsafePointer.pointer(to:).
2024-03-20 15:35:46 -07:00
Nate Chandler
53bffd2d41 [MoveOnlyAddressChecker] Handle takes of copyable.
Treat a take of a copyable value as a take.
2024-03-20 15:19:04 -07:00
Nate Chandler
4f6f8d9459 [NFC] MoveOnly: Map operand to list of ranges. 2024-03-20 12:52:57 -07:00
Nate Chandler
2ab2252233 [NFC] MoveOnly: Map inst to array of ranges. 2024-03-20 12:52:57 -07:00
Nate Chandler
ef6cde5474 [MoveOnlyPartialConsumption] Fix visibility check.
The implementation of isUsableFromInline asserts that the function not
be public, so check that it's not before calling it.
2024-03-20 12:52:57 -07:00
Nate Chandler
b6e8ecaa9f [NFC] MoveOnly: Used newly standard constructor. 2024-03-20 12:35:14 -07:00
Nate Chandler
a955a01cab [Gardening] MoveOnly: Replaced dyn_cast with isa. 2024-03-20 12:35:14 -07:00
Nate Chandler
1d3925afcc [Gardening] MoveOnly: Renamed variable. 2024-03-20 12:35:14 -07:00
Nate Chandler
8624f1342e [Gardening] MoveOnly: Annotated auto pointers. 2024-03-20 12:35:14 -07:00
Nate Chandler
0f0147dd97 [Gardening] MoveOnly: Alphabetized switch cases. 2024-03-20 12:35:13 -07:00
Nate Chandler
76348df0cf [MoveOnlyAddressChecker] Fix repr for consumes.
An instruction can consume multiple (discontiguous) fields.  Use a
SmallBitVector to track the fields consumed by an instruction rather
than a TypeTreeLeafRange.

rdar://125103951
2024-03-20 12:08:48 -07:00
Nate Chandler
b6f0b358ba [MoveOnly] Track inst-consumed bits in same SBV.
Previously, whenever an instruction was recorded as a final consume, a
new entry was added to finalBlockConsumes.  Here, this is changed to add
the new bits being consumed by the instruction to the preexisting
SmallBitVector, if there is one.
2024-03-20 11:58:25 -07:00
Nate Chandler
2b363c5bc3 [NFC] MoveOnly: Renamed nonconsumingUses.
The name `livenessUses` doesn't readily communicate the fact that those
uses are all non-consuming.
2024-03-20 11:51:30 -07:00
Joe Groff
dc4c874c49 Merge pull request #72452 from jckarter/pruned-liveness-try-apply-conditional-def
FieldSensitivePrunedLiveness: Handle conditionality of `try_apply` defs.
2024-03-20 07:43:42 -07:00
Joe Groff
1166f2e0d8 FieldSensitivePrunedLiveness: Handle conditionality of try_apply defs.
A `try_apply` with indirect out arguments is only a def for those arguments on
the success path. Model this by sinking the def-ness of the instruction into the
success branch of the try_apply, and introducing a new `DeadToLiveEdge` mode for
block liveness which stops propagation of use-before-def conditions into the
block that introduced the def. Fixes rdar://118567869.
2024-03-19 22:46:26 -07:00
Michael Gottesman
f02565719e Merge pull request #72435 from gottesmm/pr-89ce065b7f50a41a58d8fb358d0145913d8b53a3
[region-isolation] Convert more diagnostics from type isolation form to named variable form
2024-03-19 16:32:36 -07:00
Michael Gottesman
7368de2a20 [region-isolation] Remove variable_defined_here from named use after transfer error.
This is just a pseudo-why are these two things part of the same region error. I
am going to remove this for now and the proper form of this diagnostic will come
back when I land the region history functionality.
2024-03-19 13:19:08 -07:00
Andrew Trick
7da493498a Merge pull request #72407 from atrick/pointer-escape-bailout
Fix lifetime dependence in the presence of pointer escapes.
2024-03-19 11:40:38 -07:00
Andrew Trick
2e82db8e1b ClosureLifetimeFixup; emit mark_dependence [nonescaping].
It is safe to do so because the on_stack transformation already checks that the closure has a single known apply use.
2024-03-18 17:45:33 -07:00
Andrew Trick
aa208bbf91 Add SILType::containsNoEscapeFunction()
Add PartialApplyInst.hasNoescapeCapture
Add PartialApplyInst.mayEscape

Refactor DiagnoseInvalidEscapingCaptures. This may change functionality because tuples containing a noescape closure are now correctly recognized. Although I'm not sure such tupes can ever be captured directly.
2024-03-18 17:38:12 -07:00
Michael Gottesman
f796f11c97 [region-isolation] Rename ValueIsolationRegionInfo -> IsolationRegionInfo. 2024-03-18 12:24:34 -07:00
Michael Gottesman
afbcf85727 [region-isolation] Change named transfer non transferable error to use the dynamic merged IsolationRegionInfo found during dataflow.
I also eliminated the very basic "why is this task isolated" part of the warning
in favor of the larger, better, region history impl that I am going to land
soon. The diagnostic wasn't that good in the first place and also was fiddly. So
I removed it for now.

rdar://124960994
2024-03-18 12:13:36 -07:00
Michael Gottesman
f7d1f2acb9 [region-isolation] Define getIsolationRegionInfo(Element elt) on PartitionOpEvaluator.
This will let me look up the dynamic isolation region associated with \p elt
while performing dataflow.
2024-03-18 12:13:30 -07:00
Michael Gottesman
465bb230c4 [region-isolation] Rename callback handleFailure -> handleLocalUseAfterTransfer.
Now that we have other forms of error callbacks, having such a general name for
any specific failure is misleading and hinds intent.
2024-03-18 12:13:30 -07:00
Nate Chandler
73531d475a [MoveChecker] Fix visitor return.
The visitor returns false to indicate an unknown/unhandled instruction.
Previously it returned true as a fallback.  This resulted in aberrant
behavior: e.g., in the test case committed here, the try_apply was
deleted.
2024-03-15 14:03:30 -07:00
Ben Barham
cbcfc85777 Merge pull request #72323 from bnbarham/rename-startswith
Rename startswith to starts_with
2024-03-14 09:06:54 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Michael Gottesman
acca7353db [transferring] Make async let take a transferring result if its result is non-Sendable.
Some notes:

1. If the result is non-Sendable and we didn't infer something that is
transferring, we still emit the current sema error that says that one cannot
assign a non-Sendable value to an async let.

2. When region isolation is enabled, but transferring args and results are
disabled, we leave the async let semantics alone. This means that the async let
closure is still @Sendable and one cannot pass in non-Sendable values to it.
2024-03-13 15:30:54 -07:00
eeckstein
a24539171c Merge pull request #72265 from eeckstein/fix-mandatory-inlining
MandatoryInlining and ConstExpr: look through sendable function conversions
2024-03-13 18:52:43 +01:00
nate-chandler
197b1648fa Merge pull request #72272 from nate-chandler/noncopyable-bugs/20240312/2
[ConsumeAddrChecker] Check inout_aliasable arguments.
2024-03-13 07:00:00 -07:00
Erik Eckstein
4e61c5620c MandatoryInlining: look through sendable function conversions
Allows inlining of sendable transparent functions

rdar://124401627
2024-03-13 09:58:30 +01:00
Michael Gottesman
d72f267538 Merge pull request #72271 from gottesmm/pr-e9ccc43526e04bf00a21d49893c15ef4031898e8
[region-isolation] When inferring AST arg nums from SIL operand numbers, ignoring indirect operands.
2024-03-12 18:26:12 -07:00
Michael Gottesman
c6e24a7a46 Merge pull request #72264 from gottesmm/eliminate-rest-of-task-or-actor-isolated
[region-isolation] Eliminate most of the rest of the "task or actor" isolated error
2024-03-12 17:54:26 -07:00
Nate Chandler
862ee47c6b [ConsumeAddrChecker] Check inout_aliasable args.
Such values can be referenced in a `ConsumeExpr`, so the checker must
check them.  Furthermore it's legal to consume such values some of the
time.
2024-03-12 16:17:53 -07:00
nate-chandler
aac2051e68 Merge pull request #72257 from nate-chandler/noncopyable-bugs/20240312/1
[ConsumeAddrChecker] Check in_guaranteed arguments.
2024-03-12 14:49:00 -07:00
Michael Gottesman
4422eb5d56 [region-isolation] When inferring AST arg nums from SIL operand numbers, ignoring indirect operands.
Otherwise, we get off by one errors.

NOTE: I removed the assert that this originally hit since it is possible for us
to perhaps hit other issues and it would be better to just emit a suboptimal
error than crashing. With time, I will probably make it so if we miss we emit a
"compiler couldn't understand error".

rdar://124478890
2024-03-12 14:36:26 -07:00
Michael Gottesman
2ee1242304 [region-isolation] Give a proper named error for passing a never transferring values as a transferring argument
This eliminates a bunch of "task or actor isolated value transferred".

I also deleted some dead code.
2024-03-12 12:26:55 -07:00
Nate Chandler
cb3417eaf8 [ConsumeAddrChecker] Check in_guaranteed arguments
Such values could be referenced in a `ConsumeExpr`, so the checker must
check them.  Furthermore, it's legal to consume such values so long as
they aren't annotated `borrowing`.
2024-03-12 09:00:08 -07:00
Nate Chandler
1c023fd095 [ConsumeChecker] Check guaranteed arguments.
Such values could be referenced in a ConsumeExpr, so the checker must
check them.  Furthermore, it's legal to consume such values so long as
they aren't annotated `borrowing`.
2024-03-12 08:33:16 -07:00
Michael Gottesman
f440663cf1 Merge pull request #72247 from gottesmm/diagnostic-improvements
[region-isolation] Change "pass non-transferable non-sendable value as transferring parameter" error to use the variables name + some other small improvements
2024-03-11 22:25:18 -07:00
Michael Gottesman
aa9a2f6691 [region-isolation] Clean up the call passes self error to be the shorter "task or actor isolated value cannot be transferred".
We do not emit these very much anymore. I am just keeping it in place a bit
longer... eventually, this should just be an unknown pattern error since if a
user sees this it won't compile and we would rather then send it to us so we can
fix it.
2024-03-11 19:13:27 -07:00
Michael Gottesman
50712a1666 [region-isolation] Emit a standard short warning + long note when emitting a strongly transferring a structurally isolated value warning.
Specifically, instead of what I call an IsolationRegionInfo + Type error, e.x.:

> task-isolated value of type 'NonSendableType' passed as a strongly transferred parameter; later accesses could race

we use instead the standard warning of:

```swift
func transfer(_ x: transferring Type) {}

func test(_ x: Type) {
  transfer(x) // expected-warning {{transferring 'x' may cause a race}}
  // expected-note @-1 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
}
```

Implementation wise, I left in the old type diagnostic as a backup for now. With
time, I am going to want to eliminate it completely.
2024-03-11 19:13:27 -07:00
Erik Eckstein
4017501a4c re-instate: embedded: allow dead function elimination for de-serialized functions
This re-instates commit cc9e53bb08 with a fix for LLDB (rdar://124228107)

rdar://123772098
2024-03-11 15:38:00 +01:00
Michael Gottesman
75826c0509 Merge pull request #72222 from gottesmm/propagate-actor-information
[region-isolation] Propagate region information from the analysis into the diagnostic emitter and fix a bunch of issues on the way
2024-03-11 02:58:04 -07:00
Michael Gottesman
806cd7940e [region-isolation] Fix actor isolated parameters to get an actor isolated error instead of a task isolated error.
Now that we actually know the region that non transferrable things belong to, we
can use this information to give a better diagnostic here.

A really nice effect of this is that we now emit that actor isolated parameters
are actually actor isolated instead of task isolated.
2024-03-10 22:08:40 -07:00
Michael Gottesman
a5c8106e6a [region-isolation] Standardize on task-isolated instead of task isolated.
This matches actor-isolated as used in other parts of the compiler.
2024-03-10 22:08:40 -07:00