Commit Graph

15 Commits

Author SHA1 Message Date
Andrew Trick
56de2832d1 Remove a TODO from noimplicitcopy_trivial.swift 2023-09-08 13:24:23 -07:00
Andrew Trick
9c24933bd4 Fix compiler crashes with consuming and borrowing keywords.
Without this fix, the new 'consuming' and 'borrowing' keywords cannot
be used with trivial types. Which means, for example, they can't be
used in macro expansions that work on various types.

Fixes patterns like:

public func test1(i: consuming Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test2(i: borrowing Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test3(i: consuming Int) -> Int {
  takeClosure { i }
}

// Sadly, test4 is still incorrectly diagnosed.
public func test4(i: borrowing Int) -> Int {
  takeClosure { i }
}

Fixes rdar://112795074 (Crash compiling function that has a macro annotation and uses `consuming`)
2023-08-10 11:17:45 -07:00
Michael Gottesman
59c8cff917 [borrowing] Add support for borrowing/consuming copyable types to be a noimplicitcopy type.
rdar://108383660
2023-06-06 18:12:29 -04:00
Kavon Farvardin
03d2017a84 reword 'other consume here' to 'consumed again here'
this also fixes a bug where sometimes we simply emit
'consumed here' twice and other times we'd said 'other
consume here' for the same "consumed more than once"
message. so I went through and changed all of the 2nd
consumes into "consumed again".

rdar://109281444
2023-05-24 20:56:39 -07:00
Kavon Farvardin
71763a124e merge similar diagnostics together under a unified naming scheme for more consistent word tense
sil_movekillscopyablevalue_* and sil_moveonlychecker_* can share diagnostics.

rdar://109281444
2023-05-24 20:56:38 -07:00
Kavon Farvardin
667459ee75 tighten up consistency in terminology
- refer to a "consuming use" as simply a "consume", to reserve "use" for non-consuming uses.
- refer to "non-consuming uses" as just a "use".
- don't call it a "user defined deinit" and instead a "deinitializer" to match Sema
- be specific about what binding a closure is capturing that is preventing consumption.

rdar://109281444
2023-05-24 20:56:38 -07:00
Kavon Farvardin
31aa2f77e3 polish noncopyable types diagnostic wordings
- replaces "move-only" terminology with "noncopyable"
- replaces compiler jargon like "guaranteed parameters"
  and "lvalue" with corresponding language-level notions
- simplifies diagnostics about closures.

and probably more.

rdar://109281444
2023-05-24 20:56:36 -07:00
Michael Gottesman
9ae7ff30dd [move-only] Wire up emission of the location for non-consuming uses for objects and emit more precise errors for consuming use errors.
Specifically, previously if we emitted an error we just dumped all of the
consuming uses. Now instead for each consuming use that needs a copy, we perform
a search for a specific boundary use (consuming or non-consuming) that is
reachable from the former and emit a specialized error for it. Thus we emit for
the two consuming case the normal consumed twice error, and now for
non-consuming errors we emit the "use after consume" error.
2023-02-04 10:43:13 -08:00
Michael Gottesman
37024f1211 [noimplicitcopy] Enable sil-verify-all on no implicit copy tests.
rdar://104935849
2023-02-02 13:58:25 -08:00
Michael Gottesman
d909c8978e [no-implicit-copy] When accessing a field from a no-implicit-copy struct, unwrap it. Also do not run the move only borrow to destructure transform error.
The reason to do the first is to ensure that when I enable -sil-verify-all, we
do not have errors due to a copy_value of a move only type.

The reason to do the second thing is that:

1. If we have a move only type that is no implicit copy, I am in a subsequent
commit going to emit a type checker error saying that one cannot do this. When
we implement consuming/borrowing bindings/etc, we can make this looser if it
gets into the way.

2. If we have a copyable no implicit copy type, then any structural accesses
that we may want to do that would require a destructure must be to a copyable
type which is ok to copy as long as we do the unwrap from the first thing.

rdar://104929957
2023-02-01 14:48:45 -08:00
Michael Gottesman
e6ac700d75 [move-only] QoI: Fix up error notes from "{non,}consuming use" -> "{non,}consuming use here".
rdar://104926091
2023-02-01 12:05:02 -08:00
Michael Gottesman
885eb21d37 [noimplicitcopy] Changes to borrow+gep -> destructure transform to support noimplicitcopy. 2023-01-25 14:55:52 -08:00
Michael Gottesman
5c95b7a7d1 [move-only] Remove borrow of subvalue error from the move checker.
The reason why we are doing this is that we are really accessing a getter on the
type. The error would be necessarily done inside the getter where any
consumption would happen. So it shouldn't be on the move only value itself.
2022-07-25 16:09:55 -07:00
Michael Gottesman
f1182a73da [no-implicit-copy] Remove auto +1 param signature change called by noimplicit copy in favor of following normal convention.
I also added a bunch of tests for both the trivial/non-trivial case as well as
some docs to SIL.rst.
2022-07-19 16:39:03 -07:00
Michael Gottesman
167b08d008 [no-implicit-copy] Rename some tests to make it clearer that they are testing no implicit copy.
I am renaming this since as we add more true move only types to the compiler, it
may be confusing that these are testing no implicit copy and not true move only
types.
2022-06-30 22:22:27 -07:00