Commit Graph

29 Commits

Author SHA1 Message Date
Kavon Farvardin
1e28b0a312 SILGen: revise emission of UnreachableExpr
The prior emission strategy produced some scary SIL where
we have a copy of uninitialized memory:

```
  ignored_use %14
  %16 = alloc_stack $T
  unreachable

bb1:
  copy_addr [take] %16 to [init] %0
  dealloc_stack %16
```

I assume this was done to dodge the SILVerifier, which
will catch a take of an uninitialized address, had the
alloc_stack been in any reachable predecessor.

We already have a representation for an undefined value
in SIL, so I'd rather use that than try to sneak one
past the verifier.

This adjusted emission also is opaque values friendly,
as it doesn't assume the result value is an address.

resolves rdar://162239557
2025-10-09 10:38:54 -07:00
Joe Groff
df8ab6ee0b SILGen: Don't copy_addr [take] trivial address-only values.
This is a new case that comes up with `InlineArray`, since an `InlineArray`
with unknown count but known trivial element type is trivial but still
address-only due to its unknown size. We are inconsistent about whether
we emit formal copies or not of these values; they should generally
be unnecessary as long as the memory location of a value is sufficiently
long-lived, but the SIL verifier still reasonably considers a `[take]` as
an invalidation of the memory, even though at runtime a take is a no-op.
Since the take is unnecessary, we can just not take when we copy out of
a trivial address location. Fixes #84141 | rdar://160007939.
2025-09-12 11:44:41 -07:00
Slava Pestov
763f9c8923 SILGen: Fix RValue::elementsToBeAdded bookkeeping
This incorrect assert was added in 2013 and somehow it worked
until now.

Fixed rdar://problem/145478336.
2025-02-25 12:21:27 -05:00
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
Allan Shortlidge
f827e7c6d3 Tests: Remove -disable-availability-checking in variadic generics tests. 2024-10-20 15:37:15 -07:00
Nate Chandler
dff0b2efaa [SILGen] Allocs for VDs are var_decl.
Annotate alloc_stack instructions that correspond to VarDecls with the
var_decl flag.
2024-03-08 22:28:22 -08:00
John McCall
2d71c604ed Emit enum element arguments directly into the enum payload.
This generates significantly better code directly out of SILGen, at
the cost of having to reimplement a little bit of the argument-emission
logic to handle default arguments.  But it also neatly sidesteps the
problems we have with splitting tuple RValues when the tuple contains
a pack expansion, which will require some significant surgery to RValue
to fix.  That, in turn, fixes rdar://121489308.
2024-02-15 01:09:12 -05:00
John McCall
d3058cbf98 Fix expanded argument emission for tuple expressions in pack context.
Fixes #70187
2024-01-04 15:55:44 -05:00
Slava Pestov
770e6f98e3 AST: Correct '(each T).A' output for archetypes
isParameterPack() is always false for an archetype; we must test for a
PackArchetypeType here instead.
2024-01-02 15:41:13 -05:00
Nate Chandler
10ce0c6b16 [SILGen] Used move_value for lexical lets.
Instead of using begin_borrow [lexical] + copy_value.
2023-12-14 13:35:26 -08:00
John McCall
9b7123bad7 Handle pack expansion types when verifying lowered types in SIL
I don't like that this method exists, and I'd like to rip it out
in favor of expecting an opaque lowering, but I'm worried about
doing that this late in 5.9.

Fixes rdar://107290521
2023-06-15 16:33:40 -04:00
John McCall
43f4b9f3c8 Load pack elements in memberwise initializers if they're loadable
SILGen expects this of values before we enter general routines.

Fixes rdar://109911655
2023-06-14 21:29:21 -04:00
Slava Pestov
05daaae0fd ASTPrinter: Tweak PackExpansionType printing 2023-06-06 14:18:37 -04:00
Sophia Poirier
93864f6c15 [Variadic Generics] drop requirement of .element for tuple expansion rdar://107160966 2023-05-30 11:37:55 -04:00
Slava Pestov
e9e6a51c82 Unconditionally enable variadic generic types now that SE-0398 has been accepted 2023-05-15 23:32:52 -04:00
Slava Pestov
4318a36be6 Sema: Availability checking for variadic generic types 2023-05-12 22:50:25 -04:00
Slava Pestov
df5d531dc6 ASTPrinter: Fix printing of pack requirements
Also remove the flag for printing 'each' and make it always on.
2023-04-19 13:04:51 -04:00
John McCall
e609bdfb81 Walk into pack expansions in this verifier.
Fixes rdar://107664237
2023-04-05 16:58:49 -04:00
Nate Chandler
e436429f59 [Test] For typelowering lexicality verify fix.
Added test case that exhibits failure without
ff3ec19878 even when collection types
aren't eagermove.
2023-04-03 17:36:02 -07:00
John McCall
74420994d4 Teach ResultPlan to handle packs correctly when we're not emitting
into an Initialization.

rdar://107161241
2023-03-28 14:34:06 -04:00
John McCall
de283f8053 Make BlackHoleInitialization support pack initialization
Fixes rdar://107151145
2023-03-27 18:31:08 -04:00
John McCall
481f9c7362 Fix memberwise initializers for structs with variadic-tuple fields 2023-03-22 22:04:37 -04:00
John McCall
c032cc5408 Add a test case for the work in this PR.
My original test case here used a memberwise initializer, but those
use their own logic for binding and forward parameters which will
need to be updated separately.
2023-03-22 15:40:02 -04:00
Slava Pestov
c3a6bfb5bc SIL: Implement SILTypeSubstituter::hasSameShape() 2023-03-15 11:59:47 -04:00
Slava Pestov
3266a8254b SIL: Unwrap reference to value parameter packs in TypeConverter::getAbstractionPattern() 2023-03-13 19:04:15 -04:00
Holly Borla
3cca7880e9 [SILGen] Add a test case for materialized packs. 2023-03-10 18:19:24 -08:00
John McCall
239777aacb Fix parameter binding for tuples containing pack expansions
More missing infrastructure.  In this case, it's really *existing*
missing infrastructure, though; we should have been imploding tuples
this way all along, given that we're doing it in the first place.

I don't like that we're doing all these extra tuple copies.  I'm not
sure yet if they're just coming out of SILGen and eliminated immediately
after in practice; maybe so.  Still, it should be obvious that they're
unnecessary.
2023-03-09 02:28:29 -05:00
Holly Borla
fa3ffc6a44 [SILGen] Update a few callers of SubstitutionMap::get to use getSingletonPackExpansion,
and update variadic generics SILGen tests for the representation change.
2023-03-06 22:05:11 -08:00
John McCall
157be3420c Implement the callee side of returning a tuple containing a pack expansion.
This required quite a bit of infrastructure for emitting this kind of
tuple expression, although I'm not going to claim they really work yet;
in particular, I know the RValue constructor is going to try to explode
them, which it really shouldn't.

It also doesn't include the caller side of returns, for which I'll need
to teach ResultPlan to do the new abstraction-pattern walk.  But that's
next.
2023-03-06 04:26:18 -05:00